@kaynooo/cli-check 0.12.1 → 0.14.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/errs-cli.js CHANGED
@@ -2,16 +2,16 @@
2
2
  // @bun
3
3
 
4
4
  // src/errs-cli.ts
5
- import process15 from "process";
5
+ import process18 from "process";
6
6
  // ../kit/src/args.ts
7
- import process6 from "process";
7
+ import process9 from "process";
8
8
  import { parseArgs } from "util";
9
9
 
10
10
  // ../kit/src/format.ts
11
- import process3 from "process";
11
+ import process6 from "process";
12
12
 
13
13
  // ../kit/src/style.ts
14
- import process2 from "process";
14
+ import process5 from "process";
15
15
 
16
16
  // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
17
17
  function x(s) {
@@ -274,36 +274,232 @@ function le(i = {}) {
274
274
  }
275
275
  var t = le();
276
276
 
277
- // ../kit/src/style.ts
278
- var MARKS = {
279
- ok: { symbol: "\u2713", word: "ok:", paint: (colors) => colors.green },
280
- warn: { symbol: "!", word: "warning:", paint: (colors) => colors.yellow },
281
- problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
282
- note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
277
+ // ../kit/src/theme.ts
278
+ import { existsSync as existsSync2, readFileSync, statSync } from "fs";
279
+ import { homedir as homedir2 } from "os";
280
+ import { join as join3, resolve as resolve2 } from "path";
281
+ import process4 from "process";
282
+
283
+ // ../kit/src/config.ts
284
+ import { existsSync } from "fs";
285
+ import { dirname, join, resolve } from "path";
286
+ import process2 from "process";
287
+ function findUp(names, from = process2.cwd(), stop = () => false) {
288
+ const wanted = typeof names === "string" ? [names] : names;
289
+ for (let dir = resolve(from);; dir = dirname(dir)) {
290
+ const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
291
+ if (found !== undefined)
292
+ return found;
293
+ if (stop(dir) || dirname(dir) === dir)
294
+ return;
295
+ }
296
+ }
297
+
298
+ // ../kit/src/user-config.ts
299
+ import { homedir } from "os";
300
+ import { join as join2 } from "path";
301
+ import process3 from "process";
302
+ function configBase(where = {}) {
303
+ const xdg = where.xdg ?? (where.home === undefined ? process3.env.XDG_CONFIG_HOME : undefined);
304
+ return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
305
+ }
306
+ function userConfigPath(bin, where = {}) {
307
+ return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
308
+ }
309
+
310
+ // ../kit/src/theme.ts
311
+ var DEFAULT = {
312
+ 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" },
313
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
314
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
315
+ bins: {}
316
+ };
317
+ 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" };
318
+ 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" };
319
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
320
+ var PRESETS = {
321
+ default: {},
322
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
323
+ mono: { colors: MONO, accents: ["bold"] },
324
+ ascii: { glyphs: ASCII }
283
325
  };
284
- function takesControlCodes(stream, env = process2.env) {
326
+ 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"]);
327
+ var HEX = /^#[0-9a-f]{6}$/i;
328
+ var CONTROL = /\p{Cc}/u;
329
+ var MAX_FILE_BYTES = 64 * 1024;
330
+ var SPACES = /\s+/;
331
+ function isColorSpec(spec) {
332
+ if (typeof spec === "number")
333
+ return Number.isInteger(spec) && spec >= 0 && spec <= 255;
334
+ return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
335
+ }
336
+ function tinted(colors, spec) {
337
+ if (typeof spec === "number")
338
+ return colors.ansi256(spec);
339
+ return spec.trim().split(SPACES).reduce((chain, token) => HEX.test(token) ? chain.hex(token) : chain[token] ?? chain, colors);
340
+ }
341
+ function isRecord(value) {
342
+ return typeof value === "object" && value !== null && !Array.isArray(value);
343
+ }
344
+ function readThemeFile(path, warn) {
345
+ try {
346
+ const stat = statSync(path, { throwIfNoEntry: false });
347
+ if (stat === undefined)
348
+ return;
349
+ if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
350
+ warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
351
+ return;
352
+ }
353
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
354
+ if (isRecord(parsed))
355
+ return parsed;
356
+ warn(`${path} is not a JSON object, theme ignored`);
357
+ } catch (error) {
358
+ warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
359
+ }
360
+ return;
361
+ }
362
+ function applyPreset(theme, name, warn, where) {
363
+ if (name === undefined)
364
+ return;
365
+ if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
366
+ warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
367
+ return;
368
+ }
369
+ const preset = PRESETS[name];
370
+ Object.assign(theme.colors, preset.colors);
371
+ Object.assign(theme.glyphs, preset.glyphs);
372
+ if (preset.accents !== undefined)
373
+ theme.accents = [...preset.accents];
374
+ return name;
375
+ }
376
+ function applyFile(theme, file, where, warn) {
377
+ if (isRecord(file.colors)) {
378
+ for (const [key, value] of Object.entries(file.colors)) {
379
+ if (!Object.hasOwn(DEFAULT.colors, key))
380
+ warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
381
+ else if (!isColorSpec(value))
382
+ warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
383
+ else
384
+ theme.colors[key] = value;
385
+ }
386
+ }
387
+ if (isRecord(file.glyphs)) {
388
+ for (const [key, value] of Object.entries(file.glyphs)) {
389
+ if (!Object.hasOwn(DEFAULT.glyphs, key))
390
+ warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
391
+ else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
392
+ warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
393
+ else
394
+ theme.glyphs[key] = value;
395
+ }
396
+ }
397
+ if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
398
+ theme.accents = [...file.accents];
399
+ else if (file.accents !== undefined)
400
+ warn(`${where}: accents must be a non-empty list of colours`);
401
+ if (isRecord(file.bins)) {
402
+ for (const [bin, value] of Object.entries(file.bins)) {
403
+ if (isColorSpec(value))
404
+ theme.bins[bin] = value;
405
+ else
406
+ warn(`${where}: bin ${bin} has no valid colour`);
407
+ }
408
+ }
409
+ }
410
+ function endsWalk(home) {
411
+ return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
412
+ }
413
+ var warned = new Set;
414
+ function warnOnce(message) {
415
+ if (warned.has(message))
416
+ return;
417
+ warned.add(message);
418
+ console.error(`warning: theme ${message}`);
419
+ }
420
+ function isPath(chosen) {
421
+ return chosen.includes("/") || chosen.endsWith(".json");
422
+ }
423
+ function loadTheme({ env = process4.env, from = process4.cwd(), home = homedir2(), warn = warnOnce } = {}) {
424
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
425
+ const sources = [];
426
+ const chosen = env.KIT_THEME ?? "";
427
+ const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
428
+ if (isPath(chosen))
429
+ wanted.push(resolve2(from, chosen));
430
+ const files = [];
431
+ for (const path of wanted) {
432
+ const file = path === undefined ? undefined : readThemeFile(path, warn);
433
+ if (path !== undefined && file !== undefined)
434
+ files.push({ path, file });
435
+ }
436
+ let preset = "default";
437
+ if (chosen !== "" && !isPath(chosen)) {
438
+ preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
439
+ } else {
440
+ const named = files.findLast(({ file }) => file.preset !== undefined);
441
+ if (named !== undefined)
442
+ preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
443
+ }
444
+ for (const { path, file } of files) {
445
+ applyFile(theme, file, path, warn);
446
+ sources.push(path);
447
+ }
448
+ return { theme, sources, preset };
449
+ }
450
+ var current;
451
+ var currentKey = "";
452
+ function activeTheme() {
453
+ const key = `${process4.cwd()}\x00${process4.env.KIT_THEME ?? ""}\x00${process4.env.XDG_CONFIG_HOME ?? ""}`;
454
+ if (current === undefined || key !== currentKey) {
455
+ current = loadTheme();
456
+ currentKey = key;
457
+ }
458
+ return current;
459
+ }
460
+
461
+ // ../kit/src/style.ts
462
+ var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:" };
463
+ function takesControlCodes(stream, env = process5.env) {
285
464
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
286
465
  }
287
- function paint(stream, env = process2.env) {
466
+ function paint(stream, env = process5.env) {
288
467
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
289
468
  }
290
- function marked(mark, text, stream, detail, env = process2.env) {
469
+ function marked(mark, text, stream, detail, env = process5.env) {
291
470
  const colors = paint(stream, env);
292
- const { symbol, word, paint: tint } = MARKS[mark];
293
- const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
471
+ let head = MARK_WORDS[mark];
472
+ if (takesControlCodes(stream, env)) {
473
+ const { theme } = activeTheme();
474
+ head = tinted(colors.bold, theme.colors[mark])(theme.glyphs[mark]);
475
+ }
294
476
  return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
295
477
  }
296
478
  function warn(text, detail) {
297
- console.error(marked("warn", text, process2.stderr, detail));
298
- }
299
- var STATUSES = {
300
- passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
301
- failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
302
- running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
303
- queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
304
- skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
479
+ console.error(marked("warn", text, process5.stderr, detail));
480
+ }
481
+ function role(name, stream, env = process5.env) {
482
+ const colors = paint(stream, env);
483
+ return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name]) : colors;
484
+ }
485
+ var STATUS_WORDS = {
486
+ passed: ["passed", "success", "succeeded", "ok"],
487
+ failed: ["failed", "failure", "error", "errored"],
488
+ running: ["running", "in_progress", "started"],
489
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
490
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
305
491
  };
306
- var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
492
+ var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
493
+ function header(bin, context, stream, env = process5.env) {
494
+ if (!takesControlCodes(stream, env))
495
+ return "";
496
+ const colors = paint(stream, env);
497
+ const hash = [...bin].reduce((sum, char) => sum + char.charCodeAt(0), 0);
498
+ const { theme } = activeTheme();
499
+ const spec = theme.bins[bin] ?? theme.accents[hash % theme.accents.length];
500
+ const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec);
501
+ return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
502
+ }
307
503
 
308
504
  // ../kit/src/format.ts
309
505
  var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
@@ -335,7 +531,7 @@ var ESCAPE = String.fromCharCode(27);
335
531
  function textWidth(text) {
336
532
  return Bun.stringWidth(text);
337
533
  }
338
- function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
534
+ function table(rows, { cellWidth, header = false, align = [], fit, stream = process6.stdout } = {}) {
339
535
  const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
340
536
  const widths = [];
341
537
  for (const row of cells) {
@@ -343,7 +539,7 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
343
539
  widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
344
540
  }
345
541
  const shown = fit === undefined ? cells : narrow(cells, widths, fit);
346
- const colors = paint(process3.stdout);
542
+ const colors = paint(stream);
347
543
  const lines = shown.map((row) => row.map((cell, index) => {
348
544
  const width = widths[index] ?? 0;
349
545
  const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
@@ -351,7 +547,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
351
547
  return `${gap}${cell}`;
352
548
  return index === row.length - 1 ? cell : `${cell}${gap}`;
353
549
  }).join(" ").trimEnd());
354
- return lines.map((line, index) => header && index === 0 ? colors.bold(line) : line).join(`
550
+ const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
551
+ return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
355
552
  `);
356
553
  }
357
554
  function narrow(rows, widths, limit) {
@@ -375,27 +572,27 @@ function printJson(value) {
375
572
  }
376
573
 
377
574
  // ../kit/src/help.ts
378
- import process4 from "process";
575
+ import process7 from "process";
379
576
  var OPTIONAL = /\[[^\]]+\]/g;
380
577
  var USAGE_PREFIX = /^usage:\s*/i;
381
578
  var FULL_STOP = /\.$/;
382
- function usageLine(usage, colors = paint(process4.stdout)) {
579
+ function usageLine(usage, colors = paint(process7.stdout)) {
383
580
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
384
581
  }
385
- function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
582
+ function helpText(usage, options, colors = paint(process7.stdout), { examples = [], replaces, exits = [] } = {}) {
386
583
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
387
584
  `);
388
585
  }
389
- function exitRows(exits, colors = paint(process4.stdout)) {
586
+ function exitRows(exits, colors = paint(process7.stdout)) {
390
587
  if (exits.length === 0)
391
588
  return [];
392
589
  const width = Math.max(...exits.map(([code]) => String(code).length));
393
590
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
394
591
  }
395
- function replacesRows(replaces, colors = paint(process4.stdout)) {
592
+ function replacesRows(replaces, colors = paint(process7.stdout)) {
396
593
  return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
397
594
  }
398
- function wantsHelpJson(env = process4.env) {
595
+ function wantsHelpJson(env = process7.env) {
399
596
  return env.KIT_HELP === "json";
400
597
  }
401
598
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -414,12 +611,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
414
611
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
415
612
  };
416
613
  }
417
- function exampleRows(examples, colors = paint(process4.stdout)) {
614
+ function exampleRows(examples, colors = paint(process7.stdout)) {
418
615
  if (examples.length === 0)
419
616
  return [];
420
617
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
421
618
  }
422
- function optionRows(options, colors = paint(process4.stdout)) {
619
+ function optionRows(options, colors = paint(process7.stdout)) {
423
620
  const rows = Object.entries(options).map(([name, option]) => {
424
621
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
425
622
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -454,7 +651,7 @@ function closest(name, names) {
454
651
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
455
652
  }
456
653
  // ../kit/src/input.ts
457
- import process5 from "process";
654
+ import process8 from "process";
458
655
  var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
459
656
  var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
460
657
  function duration(value, name, fallback, unit = "s") {
@@ -468,7 +665,7 @@ function duration(value, name, fallback, unit = "s") {
468
665
  }
469
666
  async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
470
667
  if (path === "-") {
471
- if (process5.stdin.isTTY)
668
+ if (process8.stdin.isTTY)
472
669
  fail(noStdin);
473
670
  return Bun.stdin.text();
474
671
  }
@@ -527,7 +724,7 @@ var OUTPUT_OPTIONS = {
527
724
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
528
725
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
529
726
  };
530
- function applyOutput(color, plain, env = process6.env) {
727
+ function applyOutput(color, plain, env = process9.env) {
531
728
  const when = plain === true ? "never" : color ?? "auto";
532
729
  if (when === "auto")
533
730
  return;
@@ -698,7 +895,7 @@ function nearestOption(message, options, allowNegative) {
698
895
  }
699
896
  // ../kit/src/process.ts
700
897
  import { constants } from "os";
701
- import process7 from "process";
898
+ import process10 from "process";
702
899
  var KILL_GRACE_MS = 2000;
703
900
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
704
901
  function exitCodeOf(code, signal) {
@@ -720,7 +917,7 @@ function holdSignals(cleanup) {
720
917
  },
721
918
  release: () => {
722
919
  for (const signal of SIGNALS)
723
- process7.off(signal, onSignal);
920
+ process10.off(signal, onSignal);
724
921
  }
725
922
  };
726
923
  function onSignal(signal) {
@@ -733,10 +930,10 @@ function holdSignals(cleanup) {
733
930
  return;
734
931
  held.release();
735
932
  cleanup(signal);
736
- process7.kill(process7.pid, signal);
933
+ process10.kill(process10.pid, signal);
737
934
  }
738
935
  for (const signal of SIGNALS)
739
- process7.on(signal, onSignal);
936
+ process10.on(signal, onSignal);
740
937
  return held;
741
938
  }
742
939
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -750,7 +947,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
750
947
  return;
751
948
  try {
752
949
  if (grouped)
753
- process7.kill(-proc.pid, killing);
950
+ process10.kill(-proc.pid, killing);
754
951
  else
755
952
  proc.kill(killing);
756
953
  } catch {}
@@ -824,42 +1021,42 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
824
1021
  var RESET_STYLE = `${ESC}[0m`;
825
1022
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
826
1023
  // ../kit/src/cli.ts
827
- import { readFileSync, realpathSync } from "fs";
828
- import { dirname as dirname2, join as join3 } from "path";
829
- import process10 from "process";
1024
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
1025
+ import { dirname as dirname3, join as join6 } from "path";
1026
+ import process13 from "process";
830
1027
 
831
1028
  // ../kit/src/usage.ts
832
1029
  import { appendFileSync, mkdirSync } from "fs";
833
- import { homedir as homedir2 } from "os";
834
- import { dirname, isAbsolute, join as join2 } from "path";
835
- import process9 from "process";
1030
+ import { homedir as homedir4 } from "os";
1031
+ import { dirname as dirname2, isAbsolute, join as join5 } from "path";
1032
+ import process12 from "process";
836
1033
 
837
1034
  // ../kit/src/logs.ts
838
1035
  import { lstatSync, openSync } from "fs";
839
1036
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
840
- import { homedir, tmpdir } from "os";
841
- import { join } from "path";
842
- import process8 from "process";
1037
+ import { homedir as homedir3, tmpdir } from "os";
1038
+ import { join as join4 } from "path";
1039
+ import process11 from "process";
843
1040
  var DAY_MS = 24 * 60 * 60 * 1000;
844
1041
  var CLI_FOLDER = "kaynooo-cli";
845
1042
  function isPrivateDirectory(path) {
846
1043
  try {
847
1044
  const info = lstatSync(path, { throwIfNoEntry: false });
848
- return info !== undefined && info.isDirectory() && info.uid === (process8.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1045
+ return info !== undefined && info.isDirectory() && info.uid === (process11.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
849
1046
  } catch {
850
1047
  return false;
851
1048
  }
852
1049
  }
853
- async function privateLogDirectory(name, env = process8.env) {
1050
+ async function privateLogDirectory(name, env = process11.env) {
854
1051
  const runtime = env.XDG_RUNTIME_DIR;
855
- const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
856
- const path = join(base, name);
1052
+ const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
1053
+ const path = join4(base, name);
857
1054
  try {
858
1055
  await mkdir(path, { recursive: true, mode: 448 });
859
1056
  if (isPrivateDirectory(path))
860
1057
  return path;
861
1058
  } catch {}
862
- return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
1059
+ return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
863
1060
  }
864
1061
  async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
865
1062
  let names;
@@ -869,7 +1066,7 @@ async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
869
1066
  return;
870
1067
  }
871
1068
  for (const name of names) {
872
- const path = join(dir, name);
1069
+ const path = join4(dir, name);
873
1070
  try {
874
1071
  const info = await stat(path);
875
1072
  if (info.isDirectory())
@@ -890,14 +1087,14 @@ var usageError;
890
1087
  function noteUsageError(message) {
891
1088
  usageError = message;
892
1089
  }
893
- function stateHome(env = process9.env) {
1090
+ function stateHome(env = process12.env) {
894
1091
  const dir = env.XDG_STATE_HOME;
895
- return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
1092
+ return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
896
1093
  }
897
- function usagePath(env = process9.env) {
898
- return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
1094
+ function usagePath(env = process12.env) {
1095
+ return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
899
1096
  }
900
- function usageRecorded(env = process9.env) {
1097
+ function usageRecorded(env = process12.env) {
901
1098
  const off = env.KAYNOOO_CLI_NO_USAGE;
902
1099
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
903
1100
  }
@@ -911,12 +1108,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
911
1108
  usageError = undefined;
912
1109
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
913
1110
  }
914
- function recordUsage(entry, env = process9.env) {
1111
+ function recordUsage(entry, env = process12.env) {
915
1112
  if (!usageRecorded(env))
916
1113
  return;
917
1114
  try {
918
1115
  const path = usagePath(env);
919
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
1116
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
920
1117
  appendFileSync(path, `${JSON.stringify(entry)}
921
1118
  `, { mode: 384 });
922
1119
  } catch {}
@@ -929,8 +1126,8 @@ var LEVEL_OPTIONS = {
929
1126
  };
930
1127
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
931
1128
  function printError(prefix, message, hint, cause) {
932
- const colors = paint(process10.stderr);
933
- const styled = takesControlCodes(process10.stderr);
1129
+ const colors = paint(process13.stderr);
1130
+ const styled = takesControlCodes(process13.stderr);
934
1131
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
935
1132
  const under = (label, text, tint) => text === undefined ? "" : `
936
1133
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -949,7 +1146,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
949
1146
  const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
950
1147
  const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
951
1148
  const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
952
- if (error instanceof UsageError)
1149
+ if (error instanceof Exit && error.code === 2)
953
1150
  noteUsageError(error.message);
954
1151
  const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
955
1152
  report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
@@ -1013,17 +1210,17 @@ async function printCandidates(found) {
1013
1210
  return 0;
1014
1211
  }
1015
1212
  function packageVersion(entry = Bun.main) {
1016
- for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
1213
+ for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1017
1214
  try {
1018
- const { version } = JSON.parse(readFileSync(join3(dir, "package.json"), "utf8"));
1215
+ const { version } = JSON.parse(readFileSync2(join6(dir, "package.json"), "utf8"));
1019
1216
  if (typeof version === "string")
1020
1217
  return version;
1021
1218
  } catch {}
1022
- if (dirname2(dir) === dir)
1219
+ if (dirname3(dir) === dir)
1023
1220
  return "0.0.0";
1024
1221
  }
1025
1222
  }
1026
- async function runMain({ name, version, run, redact, usage }, argv = process10.argv.slice(2)) {
1223
+ async function runMain({ name, version, run, redact, usage }, argv = process13.argv.slice(2)) {
1027
1224
  if (argv[0] === COMPLETE)
1028
1225
  return printCandidates(leafCandidates(run, argv.slice(1)));
1029
1226
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1050,17 +1247,17 @@ var {Glob } = globalThis.Bun;
1050
1247
  var SESSION_FILES = new Glob("*.json");
1051
1248
  var ACCOUNT_DIRS = new Glob("*/sessions");
1052
1249
  // package.json
1053
- var version = "0.12.1";
1250
+ var version = "0.14.0";
1054
1251
 
1055
1252
  // src/errs.ts
1056
1253
  import { relative as relative2 } from "path";
1057
- import process14 from "process";
1254
+ import process17 from "process";
1058
1255
 
1059
1256
  // src/compose.ts
1060
- import { existsSync } from "fs";
1061
- import { homedir as homedir3 } from "os";
1062
- import { basename, dirname as dirname3, join as join4, relative, resolve } from "path";
1063
- import process12 from "process";
1257
+ import { existsSync as existsSync3 } from "fs";
1258
+ import { homedir as homedir5 } from "os";
1259
+ import { basename, dirname as dirname4, join as join7, relative, resolve as resolve3 } from "path";
1260
+ import process15 from "process";
1064
1261
 
1065
1262
  // ../kit/src/shell.ts
1066
1263
  var SEPARATORS = new Set([`
@@ -1138,7 +1335,7 @@ function toolWords(program) {
1138
1335
  }
1139
1336
  async function readFiles(dir, names) {
1140
1337
  for (const name of names) {
1141
- const handle = Bun.file(join4(dir, name));
1338
+ const handle = Bun.file(join7(dir, name));
1142
1339
  if (await handle.exists())
1143
1340
  return { name, text: await handle.text() };
1144
1341
  }
@@ -1153,7 +1350,7 @@ async function variables(composeDir) {
1153
1350
  if (match !== null && !line.trimStart().startsWith("#"))
1154
1351
  env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
1155
1352
  }
1156
- for (const [key, value] of Object.entries(process12.env)) {
1353
+ for (const [key, value] of Object.entries(process15.env)) {
1157
1354
  if (value !== undefined)
1158
1355
  env[key] = value;
1159
1356
  }
@@ -1173,10 +1370,10 @@ function interpolate(text, env) {
1173
1370
  function bindSource(source, composeDir, env) {
1174
1371
  const path = interpolate(source, env);
1175
1372
  if (path.startsWith("~"))
1176
- return join4(homedir3(), path.slice(1));
1373
+ return join7(homedir5(), path.slice(1));
1177
1374
  if (path.startsWith("/"))
1178
- return resolve(path);
1179
- return path.startsWith(".") ? resolve(composeDir, path) : undefined;
1375
+ return resolve3(path);
1376
+ return path.startsWith(".") ? resolve3(composeDir, path) : undefined;
1180
1377
  }
1181
1378
  function mountsOf(volumes, composeDir, env) {
1182
1379
  if (!Array.isArray(volumes))
@@ -1218,9 +1415,9 @@ async function composeFiles(composeDir, env) {
1218
1415
  const files = [];
1219
1416
  const separator = env.COMPOSE_PATH_SEPARATOR;
1220
1417
  for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
1221
- const file = Bun.file(resolve(composeDir, name));
1418
+ const file = Bun.file(resolve3(composeDir, name));
1222
1419
  if (!await file.exists())
1223
- fail(`COMPOSE_FILE names ${join4(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
1420
+ fail(`COMPOSE_FILE names ${join7(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
1224
1421
  files.push({ name, text: await file.text() });
1225
1422
  }
1226
1423
  return files;
@@ -1242,7 +1439,7 @@ async function readServices(composeDir) {
1242
1439
  try {
1243
1440
  parsed = parseServices(file.text, composeDir, env);
1244
1441
  } catch (error) {
1245
- fail(`cannot read ${join4(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
1442
+ fail(`cannot read ${join7(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
1246
1443
  }
1247
1444
  for (const [name, extra] of parsed) {
1248
1445
  const known = services.get(name);
@@ -1254,11 +1451,11 @@ async function readServices(composeDir) {
1254
1451
  function climb(dir) {
1255
1452
  const folders = [dir];
1256
1453
  let current = dir;
1257
- while (!existsSync(join4(current, ".git")) && dirname3(current) !== current) {
1258
- current = dirname3(current);
1454
+ while (!existsSync3(join7(current, ".git")) && dirname4(current) !== current) {
1455
+ current = dirname4(current);
1259
1456
  folders.push(current);
1260
1457
  }
1261
- return existsSync(join4(current, ".git")) ? folders : [dir];
1458
+ return existsSync3(join7(current, ".git")) ? folders : [dir];
1262
1459
  }
1263
1460
  function containerPath(service, dir) {
1264
1461
  const holding = service.mounts.filter((mount) => {
@@ -1269,7 +1466,7 @@ function containerPath(service, dir) {
1269
1466
  if (deepest === undefined)
1270
1467
  return;
1271
1468
  const inside = relative(deepest.source, dir);
1272
- return inside === "" ? deepest.target : join4(deepest.target, inside);
1469
+ return inside === "" ? deepest.target : join7(deepest.target, inside);
1273
1470
  }
1274
1471
  var noticed = new Set;
1275
1472
  async function place(dir, program, { service, host } = {}) {
@@ -1289,7 +1486,7 @@ async function place(dir, program, { service, host } = {}) {
1289
1486
  fail(`--in ${service}: no compose project mounts ${dir}`);
1290
1487
  return;
1291
1488
  }
1292
- if (Bun.which("docker", { PATH: process12.env.PATH ?? "" }) === null) {
1489
+ if (Bun.which("docker", { PATH: process15.env.PATH ?? "" }) === null) {
1293
1490
  if (service !== undefined)
1294
1491
  fail(`--in ${service}: docker not found`);
1295
1492
  if (!noticed.has(found.composeDir)) {
@@ -1341,7 +1538,7 @@ class Stack {
1341
1538
  }
1342
1539
  static async running(composeDir) {
1343
1540
  try {
1344
- const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process12.env, timeoutMs: PS_TIMEOUT_MS });
1541
+ const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process15.env, timeoutMs: PS_TIMEOUT_MS });
1345
1542
  if (ran.code !== 0)
1346
1543
  return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
1347
1544
  `).at(-1) ?? `exit ${ran.code}`}`;
@@ -2000,15 +2197,15 @@ function parseErrors(output) {
2000
2197
 
2001
2198
  // src/run.ts
2002
2199
  import { mkdir as mkdir2, readdir as readdir2, stat as stat2, writeFile } from "fs/promises";
2003
- import { basename as basename2, join as join5 } from "path";
2004
- import process13 from "process";
2200
+ import { basename as basename2, join as join8 } from "path";
2201
+ import process16 from "process";
2005
2202
  var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
2006
2203
  var RESULTS_FILE = "results.json";
2007
2204
  var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
2008
2205
  async function logDirectory(cwd) {
2009
2206
  const root = await privateLogDirectory("check");
2010
2207
  await sweepLogs(root, LOG_MAX_AGE_MS);
2011
- const path = join5(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process13.pid}`);
2208
+ const path = join8(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process16.pid}`);
2012
2209
  await mkdir2(path, { mode: 448 });
2013
2210
  return path;
2014
2211
  }
@@ -2019,7 +2216,7 @@ async function lastFailed(cwd) {
2019
2216
  for (const name of await readdir2(root)) {
2020
2217
  if (!name.startsWith(prefix))
2021
2218
  continue;
2022
- const file = join5(root, name, RESULTS_FILE);
2219
+ const file = join8(root, name, RESULTS_FILE);
2023
2220
  try {
2024
2221
  const { mtimeMs } = await stat2(file);
2025
2222
  if (latest === undefined || mtimeMs > latest.time)
@@ -2034,7 +2231,7 @@ async function lastFailed(cwd) {
2034
2231
  async function saveLog(output) {
2035
2232
  const root = await privateLogDirectory("errs");
2036
2233
  await sweepLogs(root);
2037
- const path = join5(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process13.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
2234
+ const path = join8(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process16.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
2038
2235
  await writeFile(path, output, { mode: 384, flag: "wx" });
2039
2236
  return path;
2040
2237
  }
@@ -2042,7 +2239,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
2042
2239
  const started = Date.now();
2043
2240
  const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
2044
2241
  cwd,
2045
- env: { ...process13.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
2242
+ env: { ...process16.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
2046
2243
  ...timeoutMs === undefined ? {} : { timeoutMs },
2047
2244
  ...held === undefined ? {} : { onStart: (child) => held.forward(child) }
2048
2245
  });
@@ -2058,14 +2255,17 @@ function outcomeJson(name, command, logFile, outcome, service) {
2058
2255
  return { name, command, ...service === undefined ? {} : { in: service }, ok: outcome.ok, ms: outcome.ms, log: logFile, ...outcome.timedOut === true ? { timedOut: true } : {}, ...outcome.ok ? {} : { failed: failureExcerpt(outcome.output) } };
2059
2256
  }
2060
2257
  function printOutcome(name, width, command, logFile, outcome) {
2258
+ const colors = paint(process16.stdout);
2259
+ const path = role("path", process16.stdout);
2260
+ const took = colors.dim(formatDuration(outcome.ms));
2061
2261
  if (outcome.ok) {
2062
- console.log(`ok ${name.padEnd(width)} ${formatDuration(outcome.ms)} ${logFile}`);
2262
+ console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
2063
2263
  return;
2064
2264
  }
2065
- const label = outcome.timedOut === true ? "TIME " : "FAIL ";
2066
- console.log(`${label} ${name.padEnd(width)} ${formatDuration(outcome.ms)} ${command} ${logFile}`);
2265
+ const label = outcome.timedOut === true ? colors.bold(colors.yellow("TIME ")) : colors.bold(colors.red("FAIL "));
2266
+ console.log(`${label} ${name.padEnd(width)} ${took} ${colors.dim(command)} ${path(logFile)}`);
2067
2267
  if (outcome.timedOut === true)
2068
- console.log(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`);
2268
+ console.log(colors.yellow(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`));
2069
2269
  console.log(failureExcerpt(outcome.output).split(`
2070
2270
  `).map((line) => ` ${line}`.trimEnd()).join(`
2071
2271
  `));
@@ -2113,7 +2313,7 @@ async function readInput2(command, run, settings, cwd) {
2113
2313
  const held = holdSignals();
2114
2314
  let ran;
2115
2315
  try {
2116
- ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process14.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
2316
+ ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process17.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
2117
2317
  } catch (error) {
2118
2318
  fail(`cannot run ${command[0]}: ${error instanceof Error ? error.message : String(error)}`);
2119
2319
  } finally {
@@ -2121,7 +2321,7 @@ async function readInput2(command, run, settings, cwd) {
2121
2321
  }
2122
2322
  return { text: stripAnsi(ran.text), log: await saveLog(ran.output), code: ran.code };
2123
2323
  }
2124
- async function errs(args, cwd = process14.cwd()) {
2324
+ async function errs(args, cwd = process17.cwd()) {
2125
2325
  const first = args[0];
2126
2326
  const bare = first !== undefined && !first.startsWith("-") && !await Bun.file(first).exists();
2127
2327
  const parsed = parse(bare ? [] : args, usage2, options, { rest: true, replaces: "reading raw tsc, eslint, phpunit, phpstan or playwright logs, or grepping a test summary out of them", examples: [["errs -- bun run check", "the type errors of a run"], ["bun test 2>&1 | errs", "the failed tests from stdin"], ["errs -- vendor/bin/phpunit", "each failed PHP test with its file and line"]] });
@@ -2145,4 +2345,4 @@ ${usage2}`);
2145
2345
  }
2146
2346
 
2147
2347
  // src/errs-cli.ts
2148
- process15.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });
2348
+ process18.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });