@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/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/cli.ts
5
- import process16 from "process";
5
+ import process20 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,34 +1478,41 @@ 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/audit.ts
1256
- import { existsSync as existsSync3, readdirSync, statSync } from "fs";
1508
+ import { existsSync as existsSync6, readdirSync, statSync as statSync2 } from "fs";
1257
1509
  import { readdir } from "fs/promises";
1258
- import { join as join5, relative, resolve } from "path";
1259
- import process12 from "process";
1510
+ import { join as join8, relative, resolve as resolve4 } from "path";
1511
+ import process16 from "process";
1260
1512
 
1261
1513
  // src/report.ts
1262
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
1263
- import { join as join4 } from "path";
1514
+ import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
1515
+ import { join as join7 } from "path";
1264
1516
  var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
1265
1517
  var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
1266
1518
  var GHSA = /GHSA-[\w-]+$/;
@@ -1304,7 +1556,7 @@ function findingsOf(audit, reaching, direct, level, ignore = []) {
1304
1556
  }
1305
1557
  function readManifest(path) {
1306
1558
  try {
1307
- return existsSync2(path) ? JSON.parse(readFileSync2(path, "utf8")) : {};
1559
+ return existsSync5(path) ? JSON.parse(readFileSync4(path, "utf8")) : {};
1308
1560
  } catch {
1309
1561
  return {};
1310
1562
  }
@@ -1316,9 +1568,9 @@ function namesIn(manifest) {
1316
1568
  });
1317
1569
  }
1318
1570
  function directDependencies(root, workspaces) {
1319
- const names = new Set(namesIn(readManifest(join4(root, "package.json"))));
1571
+ const names = new Set(namesIn(readManifest(join7(root, "package.json"))));
1320
1572
  for (const workspace of workspaces) {
1321
- for (const name of namesIn(readManifest(join4(root, workspace, "package.json"))))
1573
+ for (const name of namesIn(readManifest(join7(root, workspace, "package.json"))))
1322
1574
  names.add(name);
1323
1575
  }
1324
1576
  return names;
@@ -1330,8 +1582,8 @@ function workspacePatterns(field) {
1330
1582
  return Array.isArray(packages) ? packages : [];
1331
1583
  }
1332
1584
  function workspaceFolders(root, children) {
1333
- const patterns = workspacePatterns(readManifest(join4(root, "package.json")).workspaces);
1334
- return patterns.filter((pattern) => typeof pattern === "string").flatMap((pattern) => pattern.endsWith("/*") ? children(pattern.slice(0, -2)).map((name) => join4(pattern.slice(0, -2), name)) : [pattern]);
1585
+ const patterns = workspacePatterns(readManifest(join7(root, "package.json")).workspaces);
1586
+ return patterns.filter((pattern) => typeof pattern === "string").flatMap((pattern) => pattern.endsWith("/*") ? children(pattern.slice(0, -2)).map((name) => join7(pattern.slice(0, -2), name)) : [pattern]);
1335
1587
  }
1336
1588
 
1337
1589
  // src/audit.ts
@@ -1352,7 +1604,7 @@ var MAX_DEPTH = 3;
1352
1604
  var CONCURRENCY = 4;
1353
1605
  var AUDIT_MS = 60000;
1354
1606
  function holdsLock(dir) {
1355
- return existsSync3(join5(dir, "bun.lock")) || existsSync3(join5(dir, "bun.lockb"));
1607
+ return existsSync6(join8(dir, "bun.lock")) || existsSync6(join8(dir, "bun.lockb"));
1356
1608
  }
1357
1609
  async function findRepos(root) {
1358
1610
  if (holdsLock(root))
@@ -1368,7 +1620,7 @@ async function findRepos(root) {
1368
1620
  for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
1369
1621
  if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith("."))
1370
1622
  continue;
1371
- const path = join5(dir, entry.name);
1623
+ const path = join8(dir, entry.name);
1372
1624
  if (holdsLock(path))
1373
1625
  found.push(path);
1374
1626
  else if (depth < MAX_DEPTH)
@@ -1378,22 +1630,10 @@ async function findRepos(root) {
1378
1630
  await walk(root, 1);
1379
1631
  return found;
1380
1632
  }
1381
- async function pool(items, limit, task) {
1382
- const results = Array.from({ length: items.length });
1383
- let next = 0;
1384
- async function worker() {
1385
- while (next < items.length) {
1386
- const index = next++;
1387
- results[index] = await task(items[index]);
1388
- }
1389
- }
1390
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
1391
- return results;
1392
- }
1393
1633
  function children(root) {
1394
1634
  return (folder) => {
1395
1635
  try {
1396
- return readdirSync(join5(root, folder), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
1636
+ return readdirSync(join8(root, folder), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
1397
1637
  } catch {
1398
1638
  return [];
1399
1639
  }
@@ -1420,7 +1660,7 @@ function failure(ran) {
1420
1660
  `).at(-1) ?? `exit ${ran.code}`;
1421
1661
  }
1422
1662
  function tint(severity) {
1423
- const colors = paint(process12.stdout);
1663
+ const colors = paint(process16.stdout);
1424
1664
  if (severity === "critical" || severity === "high")
1425
1665
  return colors.red;
1426
1666
  return severity === "moderate" ? colors.yellow : colors.dim;
@@ -1437,8 +1677,8 @@ function rows(findings) {
1437
1677
  }
1438
1678
  async function audit(args) {
1439
1679
  const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], exits: EXITS, replaces: "a bun audit run in each repository and a read of every advisory to find what is worth fixing", examples: ["audit", "audit ~/Workspace --level high --prod"] });
1440
- const root = resolve(positionals[0] ?? ".");
1441
- if (!existsSync3(root) || !statSync(root).isDirectory())
1680
+ const root = resolve4(positionals[0] ?? ".");
1681
+ if (!existsSync6(root) || !statSync2(root).isDirectory())
1442
1682
  fail(`no folder ${root}`);
1443
1683
  const level = oneOf(values.level, "level", SEVERITIES);
1444
1684
  const paths = await findRepos(root);
@@ -1455,8 +1695,8 @@ async function audit(args) {
1455
1695
  return kept.some((each) => each.findings.length > 0) ? 1 : 0;
1456
1696
  }
1457
1697
  function show(audits, total) {
1458
- const label = role("label", process12.stdout);
1459
- const path = role("path", process12.stdout);
1698
+ const label = role("label", process16.stdout);
1699
+ const path = role("path", process16.stdout);
1460
1700
  const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
1461
1701
  if (flagged.length === 0) {
1462
1702
  console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
@@ -1470,18 +1710,18 @@ function show(audits, total) {
1470
1710
  }
1471
1711
 
1472
1712
  // src/repos.ts
1473
- import { existsSync as existsSync5, statSync as statSync2 } from "fs";
1474
- import { homedir as homedir3 } from "os";
1475
- import { join as join7, relative as relative2, resolve as resolve2 } from "path";
1476
- import process14 from "process";
1713
+ import { existsSync as existsSync8, statSync as statSync3 } from "fs";
1714
+ import { relative as relative2 } from "path";
1715
+ import process18 from "process";
1477
1716
 
1478
1717
  // src/repos-scan.ts
1479
- import { existsSync as existsSync4 } from "fs";
1718
+ import { existsSync as existsSync7 } from "fs";
1480
1719
  import { readdir as readdir2 } from "fs/promises";
1481
- import { basename, join as join6 } from "path";
1482
- import process13 from "process";
1720
+ import { basename, join as join9 } from "path";
1721
+ import process17 from "process";
1483
1722
  var MAX_DEPTH2 = 3;
1484
1723
  var CONCURRENCY2 = 8;
1724
+ var PACKAGE_CONCURRENCY = 4;
1485
1725
  var GIT_MS = 1e4;
1486
1726
  var FETCH_MS = 30000;
1487
1727
  var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
@@ -1500,7 +1740,7 @@ function reasonsOf(repo) {
1500
1740
  return reasons;
1501
1741
  }
1502
1742
  async function findRepos2(root, skip) {
1503
- if (existsSync4(join6(root, ".git")))
1743
+ if (existsSync7(join9(root, ".git")))
1504
1744
  return [root];
1505
1745
  const found = [];
1506
1746
  async function walk(dir, depth) {
@@ -1513,8 +1753,8 @@ async function findRepos2(root, skip) {
1513
1753
  for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
1514
1754
  if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".") || skip.has(entry.name))
1515
1755
  continue;
1516
- const path = join6(dir, entry.name);
1517
- if (existsSync4(join6(path, ".git")))
1756
+ const path = join9(dir, entry.name);
1757
+ if (existsSync7(join9(path, ".git")))
1518
1758
  found.push(path);
1519
1759
  else if (depth < MAX_DEPTH2)
1520
1760
  await walk(path, depth + 1);
@@ -1525,7 +1765,7 @@ async function findRepos2(root, skip) {
1525
1765
  }
1526
1766
  async function read(path, args, timeoutMs = GIT_MS) {
1527
1767
  try {
1528
- const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process13.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
1768
+ const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process17.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
1529
1769
  return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
1530
1770
  } catch {
1531
1771
  return;
@@ -1543,14 +1783,12 @@ async function packageReleases(path) {
1543
1783
  if (name !== undefined)
1544
1784
  names.add(name);
1545
1785
  }
1546
- const releases = [];
1547
- for (const name of [...names].toSorted()) {
1548
- const folder = [join6("packages", name), name].find((candidate) => existsSync4(join6(path, candidate)));
1786
+ const releases = await pool([...names].toSorted(), PACKAGE_CONCURRENCY, async (name) => {
1787
+ const folder = [join9("packages", name), name].find((candidate) => existsSync7(join9(path, candidate)));
1549
1788
  const tag = folder === undefined ? undefined : await read(path, ["describe", "--tags", "--abbrev=0", "--match", `${name}-v*`]);
1550
- if (folder !== undefined && tag !== undefined && tag !== "")
1551
- releases.push({ name, tag, unreleased: await commitsSince(path, tag, folder) });
1552
- }
1553
- return releases;
1789
+ return folder !== undefined && tag !== undefined && tag !== "" ? { name, tag, unreleased: await commitsSince(path, tag, folder) } : undefined;
1790
+ });
1791
+ return releases.filter((release) => release !== undefined);
1554
1792
  }
1555
1793
  async function inspect(path, fetch) {
1556
1794
  const fetched = fetch ? await read(path, ["fetch", "--quiet"], FETCH_MS) : "";
@@ -1604,7 +1842,7 @@ function firstLine(text) {
1604
1842
  }
1605
1843
  async function fastForward(path) {
1606
1844
  try {
1607
- const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process13.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
1845
+ const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process17.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
1608
1846
  if (ran.timedOut)
1609
1847
  return "timed out";
1610
1848
  return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
@@ -1612,21 +1850,9 @@ async function fastForward(path) {
1612
1850
  return error instanceof Error ? error.message : String(error);
1613
1851
  }
1614
1852
  }
1615
- async function pool2(items, limit, task) {
1616
- const results = new Array(items.length);
1617
- let next = 0;
1618
- async function worker() {
1619
- while (next < items.length) {
1620
- const index = next++;
1621
- results[index] = await task(items[index]);
1622
- }
1623
- }
1624
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
1625
- return results;
1626
- }
1627
1853
 
1628
1854
  // src/repos.ts
1629
- var USAGE2 = `repos [options] [root]: the git repositories under root (~/Workspace by default) that need attention, with their branch, dirty files, ahead/behind their upstream, linked worktrees and commits since their latest tag
1855
+ var USAGE2 = `repos [options] [root]: the git repositories under root (the configured workspace, ~/Workspace by default) that need attention, with their branch, dirty files, ahead/behind their upstream, linked worktrees and commits since their latest tag
1630
1856
 
1631
1857
  A repository with nothing to report is left out unless --all. A monorepo tagging its packages <folder>-v<version> counts the unreleased commits per package folder. The walk goes ${MAX_DEPTH2} levels deep, stops at a .git and skips node_modules, hidden folders and the names in "skip" of ~/.config/kaynooo-cli/repos.json.
1632
1858
 
@@ -1644,7 +1870,7 @@ var OPTIONS2 = {
1644
1870
  };
1645
1871
  async function skipped() {
1646
1872
  const file = userConfigReadPath("repos");
1647
- if (!existsSync5(file))
1873
+ if (!existsSync8(file))
1648
1874
  return new Set;
1649
1875
  try {
1650
1876
  const config = await Bun.file(file).json();
@@ -1658,21 +1884,46 @@ function releasedCell(repo) {
1658
1884
  return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
1659
1885
  return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
1660
1886
  }
1661
- function row(repo, shown) {
1662
- const tint = role("path", process14.stdout);
1887
+ function syncCell(repo, stream = process18.stdout) {
1888
+ const colors = paint(stream);
1663
1889
  const ahead = repo.ahead ?? 0;
1664
1890
  const behind = repo.behind ?? 0;
1665
- const sync = repo.upstream === null ? "no upstream" : [ahead > 0 ? `+${ahead}` : "", behind > 0 ? `-${behind}` : ""].filter(Boolean).join(" ") || "-";
1666
- return [tint(shown), repo.unreadable ? "? (unreadable)" : repo.branch, repo.dirty === 0 ? "-" : String(repo.dirty), sync, repo.worktrees === 0 ? "-" : String(repo.worktrees), releasedCell(repo)];
1891
+ if (repo.upstream === null)
1892
+ return colors.dim("no upstream");
1893
+ const parts = [ahead > 0 ? colors.green(`+${ahead}`) : "", behind > 0 ? colors.red(`-${behind}`) : ""].filter(Boolean);
1894
+ const diverged = takesControlCodes(stream) && ahead > 0 && behind > 0;
1895
+ return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
1896
+ }
1897
+ var DEFAULT_BRANCHES = new Set(["main", "master"]);
1898
+ function branchCell(repo, stream = process18.stdout) {
1899
+ const colors = paint(stream);
1900
+ if (repo.unreadable)
1901
+ return colors.red("? (unreadable)");
1902
+ if (repo.branch === "(detached)")
1903
+ return colors.yellow(repo.branch);
1904
+ return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
1905
+ }
1906
+ function row(repo, shown) {
1907
+ const colors = paint(process18.stdout);
1908
+ const tint = role("path", process18.stdout);
1909
+ const unreleased = releasedCell(repo);
1910
+ return [
1911
+ tint(shown),
1912
+ branchCell(repo),
1913
+ repo.dirty === 0 ? colors.dim("-") : colors.yellow(String(repo.dirty)),
1914
+ syncCell(repo),
1915
+ repo.worktrees === 0 ? colors.dim("-") : String(repo.worktrees),
1916
+ unreleased === "-" ? colors.dim("-") : colors.cyan(unreleased)
1917
+ ];
1667
1918
  }
1668
1919
  async function repos(args) {
1669
1920
  const { values, positionals } = parse(args, USAGE2, OPTIONS2, { positionals: ["[root]"], exits: EXITS2, replaces: "a cd, git status, git log and git tag loop over each repository of the workspace", examples: ["repos", "repos ~/Workspace --only unreleased --fetch", ["repos --only behind --pull", "fast-forward what is behind and clean"], ["repos --only dirty --path", "the paths, for xargs"]] });
1670
- const root = resolve2(positionals[0] ?? join7(homedir3(), "Workspace"));
1671
- if (!existsSync5(root) || !statSync2(root).isDirectory())
1921
+ const root = workspaceRoot({ given: positionals[0] });
1922
+ if (!existsSync8(root) || !statSync3(root).isDirectory())
1672
1923
  fail(`no folder ${root}`);
1673
1924
  const only = values.only === undefined ? undefined : oneOf(values.only, "only", REASONS);
1674
1925
  const paths = await findRepos2(root, await skipped());
1675
- const states = await pool2(paths, CONCURRENCY2, async (path) => inspect(path, values.fetch === true || values.pull === true));
1926
+ const states = await pool(paths, CONCURRENCY2, async (path) => inspect(path, values.fetch === true || values.pull === true));
1676
1927
  const keeps = (repo) => {
1677
1928
  const reasons = reasonsOf(repo);
1678
1929
  return only === undefined ? values.all === true || reasons.length > 0 || repo.unreadable : reasons.includes(only);
@@ -1686,12 +1937,12 @@ async function repos(args) {
1686
1937
  const blocker = pullBlocker(repo);
1687
1938
  const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
1688
1939
  if (blocker !== undefined) {
1689
- log(marked("note", `${repo.name} skipped`, process14.stdout, blocker));
1940
+ log(marked("note", `${repo.name} skipped`, process18.stdout, blocker));
1690
1941
  } else if (refused !== undefined) {
1691
1942
  failedPulls++;
1692
- log(marked("problem", `${repo.name} not pulled`, process14.stdout, refused));
1943
+ log(marked("problem", `${repo.name} not pulled`, process18.stdout, refused));
1693
1944
  } else {
1694
- log(marked("ok", `${repo.name} pulled`, process14.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
1945
+ log(marked("ok", `${repo.name} pulled`, process18.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
1695
1946
  states[index] = await inspect(repo.path, false);
1696
1947
  }
1697
1948
  }
@@ -1706,7 +1957,7 @@ async function repos(args) {
1706
1957
  printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
1707
1958
  return failedPulls > 0 ? 1 : 0;
1708
1959
  }
1709
- const label = role("label", process14.stdout);
1960
+ const label = role("label", process18.stdout);
1710
1961
  if (kept.length === 0) {
1711
1962
  console.log(label(`nothing needs attention in ${states.length} repositories`));
1712
1963
  return failedPulls > 0 ? 1 : 0;
@@ -1721,17 +1972,17 @@ async function repos(args) {
1721
1972
  }
1722
1973
 
1723
1974
  // src/sweep.ts
1724
- import { existsSync as existsSync8, statSync as statSync3 } from "fs";
1725
- import { homedir as homedir5 } from "os";
1726
- import { join as join11, relative as relative3, resolve as resolve3 } from "path";
1975
+ import { existsSync as existsSync11, statSync as statSync4 } from "fs";
1976
+ import { homedir as homedir6 } from "os";
1977
+ import { relative as relative3 } from "path";
1727
1978
 
1728
1979
  // ../kit/src/prompt.ts
1729
- import process15 from "process";
1980
+ import process19 from "process";
1730
1981
  var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|[\s\S]/giu;
1731
- var CONTROL = /^[\x00-\x1F\x7F]/;
1982
+ var CONTROL2 = /^[\x00-\x1F\x7F]/;
1732
1983
  var KEYS = { "\x1B[A": "up", "\x1BOA": "up", "\x1B[B": "down", "\x1BOB": "down", "\r": "enter", "\n": "enter", "\x03": "cancel", "\x1B": "cancel", "\x7F": "erase", "\b": "erase" };
1733
1984
  function readKeys(input) {
1734
- return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => KEYS[sequence] ?? (CONTROL.test(sequence) ? [] : [{ text: sequence }]));
1985
+ return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => KEYS[sequence] ?? (CONTROL2.test(sequence) ? [] : [{ text: sequence }]));
1735
1986
  }
1736
1987
  async function confirm(question, { default: fallback, ...settings } = {}) {
1737
1988
  let answered = fallback;
@@ -1755,9 +2006,9 @@ function asking(colors, question, typed, keys) {
1755
2006
  function answer(colors, question, state, picked) {
1756
2007
  return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
1757
2008
  }
1758
- async function ask(question, { hint, terminal = process15 }, render, press) {
2009
+ async function ask(question, { hint, terminal = process19 }, render, press) {
1759
2010
  const { stdin, stderr } = terminal;
1760
- if (stdin.isTTY !== true || stderr.isTTY !== true)
2011
+ if (!isInteractive(terminal))
1761
2012
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
1762
2013
  const colors = paint(stderr);
1763
2014
  let drawn = 0;
@@ -1806,31 +2057,22 @@ async function ask(question, { hint, terminal = process15 }, render, press) {
1806
2057
  }
1807
2058
 
1808
2059
  // src/apply.ts
1809
- import { existsSync as existsSync7 } from "fs";
2060
+ import { existsSync as existsSync10 } from "fs";
1810
2061
  import { lstat as lstat3, rm } from "fs/promises";
1811
- import { basename as basename3, join as join10 } from "path";
2062
+ import { basename as basename3, join as join12 } from "path";
1812
2063
 
1813
2064
  // src/sweep-scan.ts
1814
- import { existsSync as existsSync6 } from "fs";
2065
+ import { existsSync as existsSync9 } from "fs";
1815
2066
  import { lstat as lstat2, readdir as readdir4, realpath } from "fs/promises";
1816
- import { homedir as homedir4 } from "os";
1817
- import { basename as basename2, dirname as dirname3, join as join9 } from "path";
2067
+ import { homedir as homedir5 } from "os";
2068
+ import { basename as basename2, dirname as dirname5, join as join11 } from "path";
1818
2069
 
1819
2070
  // src/size.ts
1820
2071
  import { lstat, readdir as readdir3 } from "fs/promises";
1821
- import { join as join8 } from "path";
1822
- async function pooled(items, limit, work) {
1823
- const results = Array.from({ length: items.length });
1824
- let next = 0;
1825
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
1826
- while (next < items.length) {
1827
- const index = next++;
1828
- results[index] = await work(items[index]);
1829
- }
1830
- }));
1831
- return results;
1832
- }
2072
+ import { join as join10 } from "path";
1833
2073
  var FS_LIMIT = 32;
2074
+ var FIND_MS = 60000;
2075
+ var FIND_LINE = /^(\d+) (\S+) (\d+)$/gm;
1834
2076
  var waiting = [];
1835
2077
  var running = 0;
1836
2078
  async function gated(call) {
@@ -1844,7 +2086,7 @@ async function gated(call) {
1844
2086
  waiting.shift()?.();
1845
2087
  }
1846
2088
  }
1847
- async function sizeOf(folder) {
2089
+ async function walkSize(folder) {
1848
2090
  const seen = new Set;
1849
2091
  let total = 0;
1850
2092
  const visit = async (dir) => {
@@ -1855,7 +2097,7 @@ async function sizeOf(folder) {
1855
2097
  return;
1856
2098
  }
1857
2099
  await Promise.all(entries.map(async (entry) => {
1858
- const path = join8(dir, entry.name);
2100
+ const path = join10(dir, entry.name);
1859
2101
  if (entry.isDirectory())
1860
2102
  return visit(path);
1861
2103
  try {
@@ -1873,14 +2115,38 @@ async function sizeOf(folder) {
1873
2115
  await visit(folder);
1874
2116
  return total;
1875
2117
  }
2118
+ async function findSize(folder) {
2119
+ try {
2120
+ const ran = await runCommand(["find", "-P", folder, "(", "-type", "f", "-o", "-type", "l", ")", "-printf", "%n %D:%i %s\\n"], { timeoutMs: FIND_MS });
2121
+ const lines = [...ran.text.matchAll(FIND_LINE)];
2122
+ if (ran.timedOut || ran.code !== 0 && lines.length === 0)
2123
+ return;
2124
+ const seen = new Set;
2125
+ let total = 0;
2126
+ for (const [, links, id, bytes] of lines) {
2127
+ if (Number(links) > 1) {
2128
+ if (seen.has(id))
2129
+ continue;
2130
+ seen.add(id);
2131
+ }
2132
+ total += Number(bytes);
2133
+ }
2134
+ return total;
2135
+ } catch {
2136
+ return;
2137
+ }
2138
+ }
2139
+ async function sizeOf(folder) {
2140
+ return await findSize(folder) ?? await walkSize(folder);
2141
+ }
1876
2142
 
1877
2143
  // src/sweep-scan.ts
1878
2144
  var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target"]);
1879
2145
  var MAX_DEPTH3 = 3;
1880
2146
  var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit"]);
1881
2147
  var GLOBAL_CACHES = [".bun/install/cache", ".npm/_cacache", ".cache/pip", ".cache/uv", ".cache/ms-playwright", ".cache/puppeteer", ".cache/go-build", ".cache/typescript", ".cargo/registry"];
1882
- function isCachePath(path, home = homedir4()) {
1883
- return GLOBAL_CACHES.some((cache) => join9(home, cache) === path) || basename2(path) === ".cache" && basename2(dirname3(path)) === "node_modules";
2148
+ function isCachePath(path, home = homedir5()) {
2149
+ return GLOBAL_CACHES.some((cache) => join11(home, cache) === path) || basename2(path) === ".cache" && basename2(dirname5(path)) === "node_modules";
1884
2150
  }
1885
2151
  async function listing(dir) {
1886
2152
  try {
@@ -1891,7 +2157,7 @@ async function listing(dir) {
1891
2157
  }
1892
2158
  async function addGlobalCaches(found, home) {
1893
2159
  for (const cache of GLOBAL_CACHES) {
1894
- const path = join9(home, cache);
2160
+ const path = join11(home, cache);
1895
2161
  try {
1896
2162
  const stat = await lstat2(path);
1897
2163
  if (stat.isSymbolicLink())
@@ -1901,12 +2167,12 @@ async function addGlobalCaches(found, home) {
1901
2167
  } catch {}
1902
2168
  }
1903
2169
  }
1904
- async function findCandidates(root, home = homedir4(), withGlobal = true) {
2170
+ async function findCandidates(root, home = homedir5(), withGlobal = true) {
1905
2171
  const found = { candidates: [], skipped: [] };
1906
2172
  const visit = async (dir, depth) => {
1907
2173
  const entries = await listing(dir);
1908
2174
  for (const entry of entries) {
1909
- const path = join9(dir, entry.name);
2175
+ const path = join11(dir, entry.name);
1910
2176
  if (entry.name === ".git")
1911
2177
  continue;
1912
2178
  if (entry.name === ".worktrees" || entry.name === "worktrees" && basename2(dir) === ".claude") {
@@ -1916,13 +2182,13 @@ async function findCandidates(root, home = homedir4(), withGlobal = true) {
1916
2182
  }
1917
2183
  for (const worktree of await listing(path)) {
1918
2184
  if (worktree.isDirectory())
1919
- found.candidates.push({ path: join9(path, worktree.name), kind: "worktree" });
2185
+ found.candidates.push({ path: join11(path, worktree.name), kind: "worktree" });
1920
2186
  else if (worktree.isSymbolicLink())
1921
- found.skipped.push({ path: join9(path, worktree.name), reason: "symlink" });
2187
+ found.skipped.push({ path: join11(path, worktree.name), reason: "symlink" });
1922
2188
  }
1923
2189
  continue;
1924
2190
  }
1925
- if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" || existsSync6(join9(dir, "Cargo.toml")))) {
2191
+ if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" || existsSync9(join11(dir, "Cargo.toml")))) {
1926
2192
  if (entry.isSymbolicLink()) {
1927
2193
  found.skipped.push({ path, reason: "symlink" });
1928
2194
  } else if (entry.isDirectory()) {
@@ -1930,9 +2196,9 @@ async function findCandidates(root, home = homedir4(), withGlobal = true) {
1930
2196
  if (entry.name === "node_modules") {
1931
2197
  const cache = (await listing(path)).find((inner) => inner.name === ".cache");
1932
2198
  if (cache?.isSymbolicLink())
1933
- found.skipped.push({ path: join9(path, ".cache"), reason: "symlink" });
2199
+ found.skipped.push({ path: join11(path, ".cache"), reason: "symlink" });
1934
2200
  else if (cache?.isDirectory())
1935
- found.candidates.push({ path: join9(path, ".cache"), kind: "cache", inside: path });
2201
+ found.candidates.push({ path: join11(path, ".cache"), kind: "cache", inside: path });
1936
2202
  }
1937
2203
  }
1938
2204
  continue;
@@ -2003,12 +2269,12 @@ var worktreesOf = memo(async (repo) => {
2003
2269
  return branches;
2004
2270
  });
2005
2271
  async function judgeFolder(path, kind, inside) {
2006
- const parent = dirname3(path);
2272
+ const parent = dirname5(path);
2007
2273
  const name = basename2(path);
2008
2274
  const located = await toplevelOf(parent);
2009
2275
  if (located === "failed")
2010
2276
  return { skip: "git failed" };
2011
- if (existsSync6(join9(path, ".git")))
2277
+ if (existsSync9(join11(path, ".git")))
2012
2278
  return { skip: "holds a git repository" };
2013
2279
  if (located === "none")
2014
2280
  return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
@@ -2020,7 +2286,7 @@ async function judgeFolder(path, kind, inside) {
2020
2286
  return { entry: { path, kind, committedAt: await lastCommitOf(located.top), action: "remove", inside } };
2021
2287
  }
2022
2288
  async function judgeWorktree(path) {
2023
- const located = await toplevelOf(dirname3(path));
2289
+ const located = await toplevelOf(dirname5(path));
2024
2290
  if (located === "failed")
2025
2291
  return { skip: "git failed" };
2026
2292
  if (located === "none")
@@ -2059,7 +2325,7 @@ async function judge(candidate) {
2059
2325
  async function inspect2({ candidates, skipped }) {
2060
2326
  const entries = [];
2061
2327
  const rejected = [...skipped];
2062
- await pooled(candidates, 8, async (candidate) => {
2328
+ await pool(candidates, 8, async (candidate) => {
2063
2329
  const verdict = await judge(candidate);
2064
2330
  if ("skip" in verdict)
2065
2331
  rejected.push({ path: candidate.path, reason: verdict.skip });
@@ -2076,7 +2342,7 @@ async function removeFolder(entry) {
2076
2342
  const stat = await lstat3(entry.path);
2077
2343
  if (stat.isSymbolicLink() || !stat.isDirectory() || !(FOLDER_NAMES.has(basename3(entry.path)) || entry.kind === "cache" && isCachePath(entry.path)))
2078
2344
  return { path: entry.path, removed: false, error: "no longer a plain folder" };
2079
- if (existsSync7(join10(entry.path, ".git")))
2345
+ if (existsSync10(join12(entry.path, ".git")))
2080
2346
  return { path: entry.path, removed: false, error: "holds a git repository" };
2081
2347
  await rm(entry.path, { recursive: true, force: true });
2082
2348
  return { path: entry.path, removed: true };
@@ -2107,7 +2373,9 @@ async function applyAll(entries, done) {
2107
2373
  }
2108
2374
 
2109
2375
  // src/sweep.ts
2110
- var USAGE3 = `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_DEPTH3} levels down), largest first with the age of the repo's last commit; --only worktrees, folders or caches keeps one kind
2376
+ var LARGE = 100 * 1024 ** 2;
2377
+ var BIG = 1024 ** 3;
2378
+ var USAGE3 = `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_DEPTH3} levels down), largest first with the age of the repo's last commit; --only worktrees, folders or caches keeps one kind
2111
2379
 
2112
2380
  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.
2113
2381
 
@@ -2136,8 +2404,8 @@ async function sweep(args) {
2136
2404
  const { values, positionals } = parse(args, USAGE3, OPTIONS3, { 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"] });
2137
2405
  if (positionals.length > 1)
2138
2406
  badUsage("give one root");
2139
- const root = resolve3(positionals[0] ?? join11(homedir5(), "Workspace"));
2140
- if (!existsSync8(root) || !statSync3(root).isDirectory())
2407
+ const root = workspaceRoot({ given: positionals[0] });
2408
+ if (!existsSync11(root) || !statSync4(root).isDirectory())
2141
2409
  fail(`${root} is not a folder`);
2142
2410
  if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
2143
2411
  badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
@@ -2146,7 +2414,7 @@ async function sweep(args) {
2146
2414
  if (minBytes === undefined)
2147
2415
  badUsage(`--min takes a size such as 500K, 10M or 1G, not ${values.min}`);
2148
2416
  const now = Date.now();
2149
- const found = await findCandidates(root, homedir5(), positionals.length === 0 || values.only === "caches");
2417
+ const found = await findCandidates(root, homedir6(), positionals.length === 0 || values.only === "caches");
2150
2418
  const wanted = values.only === undefined ? found.candidates : found.candidates.filter((candidate) => candidate.kind === ONLY_KINDS[values.only]);
2151
2419
  const { entries: all, skipped } = await inspect2({ candidates: wanted, skipped: found.skipped });
2152
2420
  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));
@@ -2198,13 +2466,20 @@ function print(root, entries, skipped, reclaimable, now) {
2198
2466
  console.log("nothing to sweep");
2199
2467
  return;
2200
2468
  }
2201
- console.log(table([["size", "age", "what", "path", "note"], ...entries.map((entry) => [$e(entry.bytes), entry.committedAt === undefined ? "-" : formatAge(entry.committedAt, now), entry.kind, relative3(root, entry.path), entry.action === "keep" ? `kept: ${entry.reason}` : ""])], { header: true, align: ["right", "right", "left", "left", "left"] }));
2469
+ const colors = paint(process.stdout);
2470
+ const path = role("path", process.stdout);
2471
+ const sized = (bytes) => {
2472
+ if (bytes >= BIG)
2473
+ return colors.red($e(bytes));
2474
+ return bytes >= LARGE ? colors.yellow($e(bytes)) : $e(bytes);
2475
+ };
2476
+ 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(relative3(root, entry.path)), entry.action === "keep" ? colors.dim(`kept: ${entry.reason}`) : ""])], { header: true, align: ["right", "right", "left", "left", "left"] }));
2202
2477
  console.log(`
2203
2478
  ${$e(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (symlinks, tracked or not ignored by git)`}`);
2204
2479
  }
2205
2480
 
2206
2481
  // src/cli.ts
2207
- process16.exitCode = await runCli({
2482
+ process20.exitCode = await runCli({
2208
2483
  name: "ws",
2209
2484
  about: "the repositories under a root: the ones needing attention, the folders worth reclaiming and their known vulnerabilities",
2210
2485
  replaces: "a cd, git status and du loop over each repository of the workspace, and a bun audit run in each",