@kaynooo/cli-check 0.10.0 → 0.12.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,17 +2,16 @@
2
2
  // @bun
3
3
 
4
4
  // src/errs-cli.ts
5
- import process14 from "process";
6
-
5
+ import process15 from "process";
7
6
  // ../kit/src/args.ts
8
- import process5 from "process";
7
+ import process6 from "process";
9
8
  import { parseArgs } from "util";
10
9
 
11
10
  // ../kit/src/format.ts
12
- import process2 from "process";
11
+ import process3 from "process";
13
12
 
14
13
  // ../kit/src/style.ts
15
- import process from "process";
14
+ import process2 from "process";
16
15
 
17
16
  // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
18
17
  function x(s) {
@@ -282,20 +281,20 @@ var MARKS = {
282
281
  problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
283
282
  note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
284
283
  };
285
- function takesControlCodes(stream, env = process.env) {
284
+ function takesControlCodes(stream, env = process2.env) {
286
285
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
287
286
  }
288
- function paint(stream, env = process.env) {
287
+ function paint(stream, env = process2.env) {
289
288
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
290
289
  }
291
- function marked(mark, text, stream, detail, env = process.env) {
290
+ function marked(mark, text, stream, detail, env = process2.env) {
292
291
  const colors = paint(stream, env);
293
292
  const { symbol, word, paint: tint } = MARKS[mark];
294
293
  const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
295
294
  return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
296
295
  }
297
296
  function warn(text, detail) {
298
- console.error(marked("warn", text, process.stderr, detail));
297
+ console.error(marked("warn", text, process2.stderr, detail));
299
298
  }
300
299
  var STATUSES = {
301
300
  passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
@@ -344,7 +343,7 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
344
343
  widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
345
344
  }
346
345
  const shown = fit === undefined ? cells : narrow(cells, widths, fit);
347
- const colors = paint(process2.stdout);
346
+ const colors = paint(process3.stdout);
348
347
  const lines = shown.map((row) => row.map((cell, index) => {
349
348
  const width = widths[index] ?? 0;
350
349
  const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
@@ -376,24 +375,30 @@ function printJson(value) {
376
375
  }
377
376
 
378
377
  // ../kit/src/help.ts
379
- import process3 from "process";
378
+ import process4 from "process";
380
379
  var OPTIONAL = /\[[^\]]+\]/g;
381
380
  var USAGE_PREFIX = /^usage:\s*/i;
382
381
  var FULL_STOP = /\.$/;
383
- function usageLine(usage, colors = paint(process3.stdout)) {
382
+ function usageLine(usage, colors = paint(process4.stdout)) {
384
383
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
385
384
  }
386
- function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
387
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
385
+ function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
386
+ return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
388
387
  `);
389
388
  }
390
- function replacesRows(replaces, colors = paint(process3.stdout)) {
389
+ function exitRows(exits, colors = paint(process4.stdout)) {
390
+ if (exits.length === 0)
391
+ return [];
392
+ const width = Math.max(...exits.map(([code]) => String(code).length));
393
+ return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
394
+ }
395
+ function replacesRows(replaces, colors = paint(process4.stdout)) {
391
396
  return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
392
397
  }
393
- function wantsHelpJson(env = process3.env) {
398
+ function wantsHelpJson(env = process4.env) {
394
399
  return env.KIT_HELP === "json";
395
400
  }
396
- function description(usage, { examples = [], replaces } = {}) {
401
+ function description(usage, { examples = [], replaces, exits } = {}, options) {
397
402
  const lines = usage.replace(USAGE_PREFIX, "").split(`
398
403
  `);
399
404
  const first = lines[0];
@@ -404,15 +409,17 @@ function description(usage, { examples = [], replaces } = {}) {
404
409
  synopsis: colon === -1 ? first : first.slice(0, colon),
405
410
  summary: colon === -1 ? fallback : first.slice(colon + 2),
406
411
  ...replaces === undefined ? {} : { replaces },
407
- examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
412
+ examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
413
+ ...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
414
+ ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
408
415
  };
409
416
  }
410
- function exampleRows(examples, colors = paint(process3.stdout)) {
417
+ function exampleRows(examples, colors = paint(process4.stdout)) {
411
418
  if (examples.length === 0)
412
419
  return [];
413
420
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
414
421
  }
415
- function optionRows(options, colors = paint(process3.stdout)) {
422
+ function optionRows(options, colors = paint(process4.stdout)) {
416
423
  const rows = Object.entries(options).map(([name, option]) => {
417
424
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
418
425
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -447,7 +454,7 @@ function closest(name, names) {
447
454
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
448
455
  }
449
456
  // ../kit/src/input.ts
450
- import process4 from "process";
457
+ import process5 from "process";
451
458
  var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
452
459
  var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
453
460
  function duration(value, name, fallback, unit = "s") {
@@ -461,7 +468,7 @@ function duration(value, name, fallback, unit = "s") {
461
468
  }
462
469
  async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
463
470
  if (path === "-") {
464
- if (process4.stdin.isTTY)
471
+ if (process5.stdin.isTTY)
465
472
  fail(noStdin);
466
473
  return Bun.stdin.text();
467
474
  }
@@ -520,7 +527,7 @@ var OUTPUT_OPTIONS = {
520
527
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
521
528
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
522
529
  };
523
- function applyOutput(color, plain, env = process5.env) {
530
+ function applyOutput(color, plain, env = process6.env) {
524
531
  const when = plain === true ? "never" : color ?? "auto";
525
532
  if (when === "auto")
526
533
  return;
@@ -543,7 +550,7 @@ function parse(args, usage, options, settings = {}) {
543
550
  const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
544
551
  let parsed;
545
552
  try {
546
- parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
553
+ parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
547
554
  } catch (error) {
548
555
  const message = parseError(error);
549
556
  throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
@@ -551,7 +558,7 @@ function parse(args, usage, options, settings = {}) {
551
558
  const values = parsed.values;
552
559
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
553
560
  if (values.help === true) {
554
- console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
561
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
555
562
  throw new HelpShown;
556
563
  }
557
564
  checkChoices(parsed.values, all);
@@ -593,6 +600,18 @@ function listed(options, allowNegative) {
593
600
  return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
594
601
  }));
595
602
  }
603
+ function withAliases(args, options) {
604
+ const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
605
+ if (named.size === 0)
606
+ return args;
607
+ const separator = args.indexOf("--");
608
+ const own = separator === -1 ? args : args.slice(0, separator);
609
+ return [...own.map((arg) => {
610
+ const at = arg.indexOf("=");
611
+ const current = named.get(at === -1 ? arg : arg.slice(0, at));
612
+ return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
613
+ }), ...separator === -1 ? [] : args.slice(separator)];
614
+ }
596
615
  function withBare(args, options) {
597
616
  const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
598
617
  if (bare.size === 0)
@@ -679,7 +698,7 @@ function nearestOption(message, options, allowNegative) {
679
698
  }
680
699
  // ../kit/src/process.ts
681
700
  import { constants } from "os";
682
- import process6 from "process";
701
+ import process7 from "process";
683
702
  var KILL_GRACE_MS = 2000;
684
703
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
685
704
  function exitCodeOf(code, signal) {
@@ -701,7 +720,7 @@ function holdSignals(cleanup) {
701
720
  },
702
721
  release: () => {
703
722
  for (const signal of SIGNALS)
704
- process6.off(signal, onSignal);
723
+ process7.off(signal, onSignal);
705
724
  }
706
725
  };
707
726
  function onSignal(signal) {
@@ -714,10 +733,10 @@ function holdSignals(cleanup) {
714
733
  return;
715
734
  held.release();
716
735
  cleanup(signal);
717
- process6.kill(process6.pid, signal);
736
+ process7.kill(process7.pid, signal);
718
737
  }
719
738
  for (const signal of SIGNALS)
720
- process6.on(signal, onSignal);
739
+ process7.on(signal, onSignal);
721
740
  return held;
722
741
  }
723
742
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -731,7 +750,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
731
750
  return;
732
751
  try {
733
752
  if (grouped)
734
- process6.kill(-proc.pid, killing);
753
+ process7.kill(-proc.pid, killing);
735
754
  else
736
755
  proc.kill(killing);
737
756
  } catch {}
@@ -805,31 +824,33 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
805
824
  var RESET_STYLE = `${ESC}[0m`;
806
825
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
807
826
  // ../kit/src/cli.ts
808
- import process9 from "process";
827
+ import { readFileSync, realpathSync } from "fs";
828
+ import { dirname as dirname2, join as join3 } from "path";
829
+ import process10 from "process";
809
830
 
810
831
  // ../kit/src/usage.ts
811
832
  import { appendFileSync, mkdirSync } from "fs";
812
833
  import { homedir as homedir2 } from "os";
813
834
  import { dirname, isAbsolute, join as join2 } from "path";
814
- import process8 from "process";
835
+ import process9 from "process";
815
836
 
816
837
  // ../kit/src/logs.ts
817
838
  import { lstatSync, openSync } from "fs";
818
839
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
819
840
  import { homedir, tmpdir } from "os";
820
841
  import { join } from "path";
821
- import process7 from "process";
842
+ import process8 from "process";
822
843
  var DAY_MS = 24 * 60 * 60 * 1000;
823
844
  var CLI_FOLDER = "kaynooo-cli";
824
845
  function isPrivateDirectory(path) {
825
846
  try {
826
847
  const info = lstatSync(path, { throwIfNoEntry: false });
827
- return info !== undefined && info.isDirectory() && info.uid === (process7.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
848
+ return info !== undefined && info.isDirectory() && info.uid === (process8.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
828
849
  } catch {
829
850
  return false;
830
851
  }
831
852
  }
832
- async function privateLogDirectory(name, env = process7.env) {
853
+ async function privateLogDirectory(name, env = process8.env) {
833
854
  const runtime = env.XDG_RUNTIME_DIR;
834
855
  const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
835
856
  const path = join(base, name);
@@ -869,14 +890,14 @@ var usageError;
869
890
  function noteUsageError(message) {
870
891
  usageError = message;
871
892
  }
872
- function stateHome(env = process8.env) {
893
+ function stateHome(env = process9.env) {
873
894
  const dir = env.XDG_STATE_HOME;
874
895
  return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
875
896
  }
876
- function usagePath(env = process8.env) {
897
+ function usagePath(env = process9.env) {
877
898
  return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
878
899
  }
879
- function usageRecorded(env = process8.env) {
900
+ function usageRecorded(env = process9.env) {
880
901
  const off = env.KAYNOOO_CLI_NO_USAGE;
881
902
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
882
903
  }
@@ -890,7 +911,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
890
911
  usageError = undefined;
891
912
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
892
913
  }
893
- function recordUsage(entry, env = process8.env) {
914
+ function recordUsage(entry, env = process9.env) {
894
915
  if (!usageRecorded(env))
895
916
  return;
896
917
  try {
@@ -908,8 +929,8 @@ var LEVEL_OPTIONS = {
908
929
  };
909
930
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
910
931
  function printError(prefix, message, hint, cause) {
911
- const colors = paint(process9.stderr);
912
- const styled = takesControlCodes(process9.stderr);
932
+ const colors = paint(process10.stderr);
933
+ const styled = takesControlCodes(process10.stderr);
913
934
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
914
935
  const under = (label, text, tint) => text === undefined ? "" : `
915
936
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -991,11 +1012,22 @@ async function printCandidates(found) {
991
1012
  console.log(line);
992
1013
  return 0;
993
1014
  }
994
- async function runMain({ name, version, run, redact, usage }, argv = process9.argv.slice(2)) {
1015
+ function packageVersion(entry = Bun.main) {
1016
+ for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
1017
+ try {
1018
+ const { version } = JSON.parse(readFileSync(join3(dir, "package.json"), "utf8"));
1019
+ if (typeof version === "string")
1020
+ return version;
1021
+ } catch {}
1022
+ if (dirname2(dir) === dir)
1023
+ return "0.0.0";
1024
+ }
1025
+ }
1026
+ async function runMain({ name, version, run, redact, usage }, argv = process10.argv.slice(2)) {
995
1027
  if (argv[0] === COMPLETE)
996
1028
  return printCandidates(leafCandidates(run, argv.slice(1)));
997
1029
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
998
- console.log(version);
1030
+ console.log(version ?? packageVersion());
999
1031
  return 0;
1000
1032
  }
1001
1033
  let code;
@@ -1004,8 +1036,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process9.ar
1004
1036
  } catch (error) {
1005
1037
  code = reportThrown(name, error, redact, wantsJson(argv));
1006
1038
  }
1007
- if (usage !== false)
1008
- recordUsage(usageEntry(name, undefined, argv, code));
1039
+ if (usage !== false) {
1040
+ try {
1041
+ recordUsage(usageEntry(name, undefined, argv, code));
1042
+ } catch {}
1043
+ }
1009
1044
  return code;
1010
1045
  }
1011
1046
  // ../kit/src/secrets.ts
@@ -1015,17 +1050,17 @@ var {Glob } = globalThis.Bun;
1015
1050
  var SESSION_FILES = new Glob("*.json");
1016
1051
  var ACCOUNT_DIRS = new Glob("*/sessions");
1017
1052
  // package.json
1018
- var version = "0.10.0";
1053
+ var version = "0.12.0";
1019
1054
 
1020
1055
  // src/errs.ts
1021
1056
  import { relative as relative2 } from "path";
1022
- import process13 from "process";
1057
+ import process14 from "process";
1023
1058
 
1024
1059
  // src/compose.ts
1025
1060
  import { existsSync } from "fs";
1026
1061
  import { homedir as homedir3 } from "os";
1027
- import { basename, dirname as dirname2, join as join3, relative, resolve } from "path";
1028
- import process11 from "process";
1062
+ import { basename, dirname as dirname3, join as join4, relative, resolve } from "path";
1063
+ import process12 from "process";
1029
1064
 
1030
1065
  // ../kit/src/shell.ts
1031
1066
  var SEPARATORS = new Set([`
@@ -1036,13 +1071,16 @@ var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
1036
1071
  var SAFE_WORD = /^[\w@%+=:,./-]+$/;
1037
1072
  var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
1038
1073
  var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
1039
- var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh"]);
1040
- var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, "su", "runuser"]);
1074
+ var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "fish", "csh", "tcsh", "nu", "xonsh", "elvish", "pwsh", "powershell"]);
1075
+ var SCANNED_PROGRAMS = new Set(["su", "runuser", "flock"]);
1076
+ var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, ...SCANNED_PROGRAMS]);
1077
+ var POWERSHELL = new Set(["pwsh", "powershell"]);
1041
1078
  var SHELL_VALUE_OPTIONS = new Set(["-o", "-O", "--rcfile", "--init-file"]);
1079
+ var FISH_VALUE_OPTIONS = new Set(["-C", "--init-command"]);
1042
1080
  var PRINTERS = new Set(["echo", "printf"]);
1043
1081
  var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
1044
- function wrapper(short = "", long = [], operands = 0) {
1045
- return { short, long, operands };
1082
+ function wrapper(short = "", long = [], operands = 0, runsString = false) {
1083
+ return { short, long, operands, runsString };
1046
1084
  }
1047
1085
  var WRAPPERS = new Map([
1048
1086
  ["command", wrapper()],
@@ -1060,6 +1098,11 @@ var WRAPPERS = new Map([
1060
1098
  ["ionice", wrapper("cnpPu", ["--class", "--classdata", "--pid", "--pgid", "--uid"])],
1061
1099
  ["stdbuf", wrapper("ioe", ["--input", "--output", "--error"])],
1062
1100
  ["chroot", wrapper("", ["--userspec", "--groups"], 1)],
1101
+ ["watch", wrapper("n", ["--interval"], 0, true)],
1102
+ ["flock", wrapper("wE", ["--timeout", "--conflict-exit-code"], 1)],
1103
+ ["parallel", wrapper("jnNSaIPlLdTsC", ["--jobs", "--max-args", "--max-replace-args", "--sshlogin", "--arg-file", "--delimiter", "--colsep"], 0, true)],
1104
+ ["unbuffer", wrapper()],
1105
+ ["systemd-run", wrapper("puEMH", ["--property", "--unit", "--description", "--slice", "--setenv", "--machine", "--host", "--uid", "--gid", "--working-directory", "--nice", "--service-type"])],
1063
1106
  ["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])]
1064
1107
  ]);
1065
1108
  function shellQuote(word) {
@@ -1095,7 +1138,7 @@ function toolWords(program) {
1095
1138
  }
1096
1139
  async function readFiles(dir, names) {
1097
1140
  for (const name of names) {
1098
- const handle = Bun.file(join3(dir, name));
1141
+ const handle = Bun.file(join4(dir, name));
1099
1142
  if (await handle.exists())
1100
1143
  return { name, text: await handle.text() };
1101
1144
  }
@@ -1110,7 +1153,7 @@ async function variables(composeDir) {
1110
1153
  if (match !== null && !line.trimStart().startsWith("#"))
1111
1154
  env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
1112
1155
  }
1113
- for (const [key, value] of Object.entries(process11.env)) {
1156
+ for (const [key, value] of Object.entries(process12.env)) {
1114
1157
  if (value !== undefined)
1115
1158
  env[key] = value;
1116
1159
  }
@@ -1130,7 +1173,7 @@ function interpolate(text, env) {
1130
1173
  function bindSource(source, composeDir, env) {
1131
1174
  const path = interpolate(source, env);
1132
1175
  if (path.startsWith("~"))
1133
- return join3(homedir3(), path.slice(1));
1176
+ return join4(homedir3(), path.slice(1));
1134
1177
  if (path.startsWith("/"))
1135
1178
  return resolve(path);
1136
1179
  return path.startsWith(".") ? resolve(composeDir, path) : undefined;
@@ -1177,7 +1220,7 @@ async function composeFiles(composeDir, env) {
1177
1220
  for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
1178
1221
  const file = Bun.file(resolve(composeDir, name));
1179
1222
  if (!await file.exists())
1180
- fail(`COMPOSE_FILE names ${join3(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
1223
+ fail(`COMPOSE_FILE names ${join4(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
1181
1224
  files.push({ name, text: await file.text() });
1182
1225
  }
1183
1226
  return files;
@@ -1199,7 +1242,7 @@ async function readServices(composeDir) {
1199
1242
  try {
1200
1243
  parsed = parseServices(file.text, composeDir, env);
1201
1244
  } catch (error) {
1202
- fail(`cannot read ${join3(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
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");
1203
1246
  }
1204
1247
  for (const [name, extra] of parsed) {
1205
1248
  const known = services.get(name);
@@ -1211,11 +1254,11 @@ async function readServices(composeDir) {
1211
1254
  function climb(dir) {
1212
1255
  const folders = [dir];
1213
1256
  let current = dir;
1214
- while (!existsSync(join3(current, ".git")) && dirname2(current) !== current) {
1215
- current = dirname2(current);
1257
+ while (!existsSync(join4(current, ".git")) && dirname3(current) !== current) {
1258
+ current = dirname3(current);
1216
1259
  folders.push(current);
1217
1260
  }
1218
- return existsSync(join3(current, ".git")) ? folders : [dir];
1261
+ return existsSync(join4(current, ".git")) ? folders : [dir];
1219
1262
  }
1220
1263
  function containerPath(service, dir) {
1221
1264
  const holding = service.mounts.filter((mount) => {
@@ -1226,7 +1269,7 @@ function containerPath(service, dir) {
1226
1269
  if (deepest === undefined)
1227
1270
  return;
1228
1271
  const inside = relative(deepest.source, dir);
1229
- return inside === "" ? deepest.target : join3(deepest.target, inside);
1272
+ return inside === "" ? deepest.target : join4(deepest.target, inside);
1230
1273
  }
1231
1274
  var noticed = new Set;
1232
1275
  async function place(dir, program, { service, host } = {}) {
@@ -1246,7 +1289,7 @@ async function place(dir, program, { service, host } = {}) {
1246
1289
  fail(`--in ${service}: no compose project mounts ${dir}`);
1247
1290
  return;
1248
1291
  }
1249
- if (Bun.which("docker", { PATH: process11.env.PATH ?? "" }) === null) {
1292
+ if (Bun.which("docker", { PATH: process12.env.PATH ?? "" }) === null) {
1250
1293
  if (service !== undefined)
1251
1294
  fail(`--in ${service}: docker not found`);
1252
1295
  if (!noticed.has(found.composeDir)) {
@@ -1298,7 +1341,7 @@ class Stack {
1298
1341
  }
1299
1342
  static async running(composeDir) {
1300
1343
  try {
1301
- const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process11.env, timeoutMs: PS_TIMEOUT_MS });
1344
+ const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process12.env, timeoutMs: PS_TIMEOUT_MS });
1302
1345
  if (ran.code !== 0)
1303
1346
  return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
1304
1347
  `).at(-1) ?? `exit ${ran.code}`}`;
@@ -1639,7 +1682,8 @@ var bunCheck = (lines) => {
1639
1682
  return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
1640
1683
  };
1641
1684
  function bunCheckFields(block) {
1642
- const attributes = Object.fromEntries([...block.matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
1685
+ const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
1686
+ `)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
1643
1687
  return {
1644
1688
  file: attributes.file ?? "",
1645
1689
  line: attributes.line ?? "",
@@ -1955,21 +1999,42 @@ function parseErrors(output) {
1955
1999
  }
1956
2000
 
1957
2001
  // src/run.ts
1958
- import { mkdir as mkdir2, writeFile } from "fs/promises";
1959
- import { basename as basename2, join as join4 } from "path";
1960
- import process12 from "process";
2002
+ 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";
1961
2005
  var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
2006
+ var RESULTS_FILE = "results.json";
2007
+ var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
1962
2008
  async function logDirectory(cwd) {
1963
2009
  const root = await privateLogDirectory("check");
1964
2010
  await sweepLogs(root, LOG_MAX_AGE_MS);
1965
- const path = join4(root, `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-${Date.now().toString(36)}-${process12.pid}`);
2011
+ const path = join5(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process13.pid}`);
1966
2012
  await mkdir2(path, { mode: 448 });
1967
2013
  return path;
1968
2014
  }
2015
+ async function lastFailed(cwd) {
2016
+ const root = await privateLogDirectory("check");
2017
+ const prefix = runPrefix(cwd);
2018
+ let latest;
2019
+ for (const name of await readdir2(root)) {
2020
+ if (!name.startsWith(prefix))
2021
+ continue;
2022
+ const file = join5(root, name, RESULTS_FILE);
2023
+ try {
2024
+ const { mtimeMs } = await stat2(file);
2025
+ if (latest === undefined || mtimeMs > latest.time)
2026
+ latest = { time: mtimeMs, file };
2027
+ } catch {}
2028
+ }
2029
+ if (latest === undefined)
2030
+ return;
2031
+ const results = JSON.parse(await Bun.file(latest.file).text());
2032
+ return results.filter((result) => !result.ok).map((result) => result.name);
2033
+ }
1969
2034
  async function saveLog(output) {
1970
2035
  const root = await privateLogDirectory("errs");
1971
2036
  await sweepLogs(root);
1972
- const path = join4(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process12.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
2037
+ const path = join5(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process13.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
1973
2038
  await writeFile(path, output, { mode: 384, flag: "wx" });
1974
2039
  return path;
1975
2040
  }
@@ -1977,7 +2042,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
1977
2042
  const started = Date.now();
1978
2043
  const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
1979
2044
  cwd,
1980
- env: { ...process12.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
2045
+ env: { ...process13.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
1981
2046
  ...timeoutMs === undefined ? {} : { timeoutMs },
1982
2047
  ...held === undefined ? {} : { onStart: (child) => held.forward(child) }
1983
2048
  });
@@ -2048,7 +2113,7 @@ async function readInput2(command, run, settings, cwd) {
2048
2113
  const held = holdSignals();
2049
2114
  let ran;
2050
2115
  try {
2051
- ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process13.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
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) });
2052
2117
  } catch (error) {
2053
2118
  fail(`cannot run ${command[0]}: ${error instanceof Error ? error.message : String(error)}`);
2054
2119
  } finally {
@@ -2056,7 +2121,7 @@ async function readInput2(command, run, settings, cwd) {
2056
2121
  }
2057
2122
  return { text: stripAnsi(ran.text), log: await saveLog(ran.output), code: ran.code };
2058
2123
  }
2059
- async function errs(args, cwd = process13.cwd()) {
2124
+ async function errs(args, cwd = process14.cwd()) {
2060
2125
  const first = args[0];
2061
2126
  const bare = first !== undefined && !first.startsWith("-") && !await Bun.file(first).exists();
2062
2127
  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"]] });
@@ -2080,4 +2145,4 @@ ${usage2}`);
2080
2145
  }
2081
2146
 
2082
2147
  // src/errs-cli.ts
2083
- process14.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });
2148
+ process15.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });