@kaynooo/cli-base 0.6.0 → 0.8.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.
Files changed (3) hide show
  1. package/dist/cli.js +334 -95
  2. package/dist/proof-cli.js +332 -93
  3. package/package.json +2 -2
package/dist/proof-cli.js CHANGED
@@ -2,13 +2,34 @@
2
2
  // @bun
3
3
 
4
4
  // src/proof-cli.ts
5
- import process11 from "process";
5
+ import process16 from "process";
6
6
  // ../kit/src/args.ts
7
- import process4 from "process";
7
+ import process9 from "process";
8
8
  import { parseArgs } from "util";
9
9
 
10
- // ../kit/src/style.ts
10
+ // ../kit/src/format.ts
11
+ import process7 from "process";
12
+
13
+ // ../kit/src/mode.ts
11
14
  import process2 from "process";
15
+ var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
16
+ var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
17
+ function isSet(value) {
18
+ return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
19
+ }
20
+ function outputMode(stream = process2.stdout, env = process2.env) {
21
+ const chosen = env.KIT_MODE;
22
+ if (chosen !== undefined && MODES.has(chosen))
23
+ return chosen;
24
+ if (AGENT_VARIABLES.some((name) => isSet(env[name])))
25
+ return "agent";
26
+ if (stream.isTTY === true)
27
+ return "terminal";
28
+ return isSet(env.CI) ? "ci" : "pipe";
29
+ }
30
+
31
+ // ../kit/src/style.ts
32
+ import process6 from "process";
12
33
 
13
34
  // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
14
35
  function x(s) {
@@ -271,21 +292,229 @@ function le(i = {}) {
271
292
  }
272
293
  var t = le();
273
294
 
295
+ // ../kit/src/theme.ts
296
+ import { existsSync as existsSync2, readFileSync, statSync } from "fs";
297
+ import { homedir as homedir2 } from "os";
298
+ import { join as join3, resolve as resolve2 } from "path";
299
+ import process5 from "process";
300
+
301
+ // ../kit/src/config.ts
302
+ import { existsSync } from "fs";
303
+ import { dirname, join, resolve } from "path";
304
+ import process3 from "process";
305
+ function findUp(names, from = process3.cwd(), stop = () => false) {
306
+ const wanted = typeof names === "string" ? [names] : names;
307
+ for (let dir = resolve(from);; dir = dirname(dir)) {
308
+ const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
309
+ if (found !== undefined)
310
+ return found;
311
+ if (stop(dir) || dirname(dir) === dir)
312
+ return;
313
+ }
314
+ }
315
+
316
+ // ../kit/src/user-config.ts
317
+ import { homedir } from "os";
318
+ import { join as join2 } from "path";
319
+ import process4 from "process";
320
+ function configBase(where = {}) {
321
+ const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
322
+ return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
323
+ }
324
+ function userConfigPath(bin, where = {}) {
325
+ return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
326
+ }
327
+
328
+ // ../kit/src/theme.ts
329
+ var DEFAULT = {
330
+ 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" },
331
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D" },
332
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
333
+ bins: {}
334
+ };
335
+ 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" };
336
+ 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" };
337
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
338
+ var PRESETS = {
339
+ default: {},
340
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
341
+ mono: { colors: MONO, accents: ["bold"] },
342
+ ascii: { glyphs: ASCII }
343
+ };
344
+ 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"]);
345
+ var HEX = /^#[0-9a-f]{6}$/i;
346
+ var CONTROL = /\p{Cc}/u;
347
+ var MAX_FILE_BYTES = 64 * 1024;
348
+ var SPACES = /\s+/;
349
+ function isColorSpec(spec) {
350
+ if (typeof spec === "number")
351
+ return Number.isInteger(spec) && spec >= 0 && spec <= 255;
352
+ return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
353
+ }
354
+ var CUBE = [0, 95, 135, 175, 215, 255];
355
+ function cubeLevel(channel) {
356
+ return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
357
+ }
358
+ function nearest256(hex) {
359
+ const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
360
+ const levels = rgb.map(cubeLevel);
361
+ const cube = levels.map((level) => CUBE[level]);
362
+ const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
363
+ const greyValue = 8 + grey * 10;
364
+ const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
365
+ return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
366
+ }
367
+ function hasTrueColor(env) {
368
+ return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
369
+ }
370
+ function tinted(colors, spec, env = process5.env) {
371
+ if (typeof spec === "number")
372
+ return colors.ansi256(spec);
373
+ return spec.trim().split(SPACES).reduce((chain, token) => {
374
+ if (HEX.test(token))
375
+ return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
376
+ return chain[token] ?? chain;
377
+ }, colors);
378
+ }
379
+ function isRecord(value) {
380
+ return typeof value === "object" && value !== null && !Array.isArray(value);
381
+ }
382
+ function readThemeFile(path, warn) {
383
+ try {
384
+ const stat = statSync(path, { throwIfNoEntry: false });
385
+ if (stat === undefined)
386
+ return;
387
+ if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
388
+ warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
389
+ return;
390
+ }
391
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
392
+ if (isRecord(parsed))
393
+ return parsed;
394
+ warn(`${path} is not a JSON object, theme ignored`);
395
+ } catch (error) {
396
+ warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
397
+ }
398
+ return;
399
+ }
400
+ function applyPreset(theme, name, warn, where) {
401
+ if (name === undefined)
402
+ return;
403
+ if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
404
+ warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
405
+ return;
406
+ }
407
+ const preset = PRESETS[name];
408
+ Object.assign(theme.colors, preset.colors);
409
+ Object.assign(theme.glyphs, preset.glyphs);
410
+ if (preset.accents !== undefined)
411
+ theme.accents = [...preset.accents];
412
+ return name;
413
+ }
414
+ function applyFile(theme, file, where, warn) {
415
+ if (isRecord(file.colors)) {
416
+ for (const [key, value] of Object.entries(file.colors)) {
417
+ if (!Object.hasOwn(DEFAULT.colors, key))
418
+ warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
419
+ else if (!isColorSpec(value))
420
+ warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
421
+ else
422
+ theme.colors[key] = value;
423
+ }
424
+ }
425
+ if (isRecord(file.glyphs)) {
426
+ for (const [key, value] of Object.entries(file.glyphs)) {
427
+ if (!Object.hasOwn(DEFAULT.glyphs, key))
428
+ warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
429
+ else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
430
+ warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
431
+ else
432
+ theme.glyphs[key] = value;
433
+ }
434
+ }
435
+ if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
436
+ theme.accents = [...file.accents];
437
+ else if (file.accents !== undefined)
438
+ warn(`${where}: accents must be a non-empty list of colours`);
439
+ if (isRecord(file.bins)) {
440
+ for (const [bin, value] of Object.entries(file.bins)) {
441
+ if (isColorSpec(value))
442
+ theme.bins[bin] = value;
443
+ else
444
+ warn(`${where}: bin ${bin} has no valid colour`);
445
+ }
446
+ }
447
+ }
448
+ function endsWalk(home) {
449
+ return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
450
+ }
451
+ var warned = new Set;
452
+ function warnOnce(message) {
453
+ if (warned.has(message))
454
+ return;
455
+ warned.add(message);
456
+ console.error(`warning: theme ${message}`);
457
+ }
458
+ function isPath(chosen) {
459
+ return chosen.includes("/") || chosen.endsWith(".json");
460
+ }
461
+ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
462
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
463
+ const sources = [];
464
+ const chosen = env.KIT_THEME ?? "";
465
+ const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
466
+ if (isPath(chosen))
467
+ wanted.push(resolve2(from, chosen));
468
+ const files = [];
469
+ for (const path of wanted) {
470
+ const file = path === undefined ? undefined : readThemeFile(path, warn);
471
+ if (path !== undefined && file !== undefined)
472
+ files.push({ path, file });
473
+ }
474
+ let preset = "default";
475
+ if (chosen !== "" && !isPath(chosen)) {
476
+ preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
477
+ } else {
478
+ const named = files.findLast(({ file }) => file.preset !== undefined);
479
+ if (named !== undefined)
480
+ preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
481
+ }
482
+ for (const { path, file } of files) {
483
+ applyFile(theme, file, path, warn);
484
+ sources.push(path);
485
+ }
486
+ return { theme, sources, preset };
487
+ }
488
+ var current;
489
+ var currentKey = "";
490
+ function activeTheme() {
491
+ const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
492
+ if (current === undefined || key !== currentKey) {
493
+ current = loadTheme();
494
+ currentKey = key;
495
+ }
496
+ return current;
497
+ }
498
+
274
499
  // ../kit/src/style.ts
275
- function takesControlCodes(stream, env = process2.env) {
276
- return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
500
+ function takesControlCodes(stream, env = process6.env) {
501
+ return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
277
502
  }
278
- function paint(stream, env = process2.env) {
503
+ function paint(stream, env = process6.env) {
279
504
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
280
505
  }
281
- var STATUSES = {
282
- passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
283
- failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
284
- running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
285
- queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
286
- skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
506
+ function role(name, stream, env = process6.env) {
507
+ const colors = paint(stream, env);
508
+ return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
509
+ }
510
+ var STATUS_WORDS = {
511
+ passed: ["passed", "success", "succeeded", "ok"],
512
+ failed: ["failed", "failure", "error", "errored"],
513
+ running: ["running", "in_progress", "started", "holding"],
514
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
515
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
287
516
  };
288
- var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
517
+ var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
289
518
 
290
519
  // ../kit/src/format.ts
291
520
  function upTo(text, separator) {
@@ -293,32 +522,35 @@ function upTo(text, separator) {
293
522
  return end === -1 ? text : text.slice(0, end);
294
523
  }
295
524
  var ESCAPE = String.fromCharCode(27);
525
+ function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
526
+ return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
527
+ }
296
528
  function printJson(value) {
297
- console.log(JSON.stringify(value, undefined, 2));
529
+ console.log(jsonText(value));
298
530
  }
299
531
 
300
532
  // ../kit/src/help.ts
301
- import process3 from "process";
533
+ import process8 from "process";
302
534
  var OPTIONAL = /\[[^\]]+\]/g;
303
535
  var USAGE_PREFIX = /^usage:\s*/i;
304
536
  var FULL_STOP = /\.$/;
305
- function usageLine(usage, colors = paint(process3.stdout)) {
537
+ function usageLine(usage, colors = paint(process8.stdout)) {
306
538
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
307
539
  }
308
- function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces, exits = [] } = {}) {
540
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
309
541
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
310
542
  `);
311
543
  }
312
- function exitRows(exits, colors = paint(process3.stdout)) {
544
+ function exitRows(exits, colors = paint(process8.stdout)) {
313
545
  if (exits.length === 0)
314
546
  return [];
315
547
  const width = Math.max(...exits.map(([code]) => String(code).length));
316
548
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
317
549
  }
318
- function replacesRows(replaces, colors = paint(process3.stdout)) {
319
- return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
550
+ function replacesRows(replaces, colors = paint(process8.stdout)) {
551
+ return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
320
552
  }
321
- function wantsHelpJson(env = process3.env) {
553
+ function wantsHelpJson(env = process8.env) {
322
554
  return env.KIT_HELP === "json";
323
555
  }
324
556
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -337,12 +569,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
337
569
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
338
570
  };
339
571
  }
340
- function exampleRows(examples, colors = paint(process3.stdout)) {
341
- if (examples.length === 0)
572
+ function exampleRows(examples, colors = paint(process8.stdout)) {
573
+ if (examples.length === 0 || outputMode() === "agent")
342
574
  return [];
343
575
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
344
576
  }
345
- function optionRows(options, colors = paint(process3.stdout)) {
577
+ function optionRows(options, colors = paint(process8.stdout)) {
346
578
  const rows = Object.entries(options).map(([name, option]) => {
347
579
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
348
580
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -389,7 +621,6 @@ var DASHES = /^-+/;
389
621
  function jsonOption(holds) {
390
622
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
391
623
  }
392
-
393
624
  class Exit extends Error {
394
625
  code;
395
626
  hint;
@@ -433,7 +664,7 @@ var OUTPUT_OPTIONS = {
433
664
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
434
665
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
435
666
  };
436
- function applyOutput(color, plain, env = process4.env) {
667
+ function applyOutput(color, plain, env = process9.env) {
437
668
  const when = plain === true ? "never" : color ?? "auto";
438
669
  if (when === "auto")
439
670
  return;
@@ -604,7 +835,7 @@ function nearestOption(message, options, allowNegative) {
604
835
  }
605
836
  // ../kit/src/process.ts
606
837
  import { constants } from "os";
607
- import process5 from "process";
838
+ import process10 from "process";
608
839
  var KILL_GRACE_MS = 2000;
609
840
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
610
841
  function exitCodeOf(code, signal) {
@@ -626,7 +857,7 @@ function holdSignals(cleanup) {
626
857
  },
627
858
  release: () => {
628
859
  for (const signal of SIGNALS)
629
- process5.off(signal, onSignal);
860
+ process10.off(signal, onSignal);
630
861
  }
631
862
  };
632
863
  function onSignal(signal) {
@@ -639,10 +870,10 @@ function holdSignals(cleanup) {
639
870
  return;
640
871
  held.release();
641
872
  cleanup(signal);
642
- process5.kill(process5.pid, signal);
873
+ process10.kill(process10.pid, signal);
643
874
  }
644
875
  for (const signal of SIGNALS)
645
- process5.on(signal, onSignal);
876
+ process10.on(signal, onSignal);
646
877
  return held;
647
878
  }
648
879
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -656,7 +887,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
656
887
  return;
657
888
  try {
658
889
  if (grouped)
659
- process5.kill(-proc.pid, killing);
890
+ process10.kill(-proc.pid, killing);
660
891
  else
661
892
  proc.kill(killing);
662
893
  } catch {}
@@ -730,15 +961,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
730
961
  var RESET_STYLE = `${ESC}[0m`;
731
962
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
732
963
  // ../kit/src/cli.ts
733
- import { readFileSync, realpathSync } from "fs";
734
- import { dirname as dirname2, join as join2 } from "path";
735
- import process7 from "process";
964
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
965
+ import { dirname as dirname3, join as join5 } from "path";
966
+ import process12 from "process";
736
967
 
737
968
  // ../kit/src/usage.ts
738
969
  import { appendFileSync, mkdirSync } from "fs";
739
- import { homedir } from "os";
740
- import { dirname, isAbsolute, join } from "path";
741
- import process6 from "process";
970
+ import { homedir as homedir3 } from "os";
971
+ import { dirname as dirname2, isAbsolute, join as join4 } from "path";
972
+ import process11 from "process";
742
973
 
743
974
  // ../kit/src/logs.ts
744
975
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -752,14 +983,14 @@ var usageError;
752
983
  function noteUsageError(message) {
753
984
  usageError = message;
754
985
  }
755
- function stateHome(env = process6.env) {
986
+ function stateHome(env = process11.env) {
756
987
  const dir = env.XDG_STATE_HOME;
757
- return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
988
+ return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
758
989
  }
759
- function usagePath(env = process6.env) {
760
- return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
990
+ function usagePath(env = process11.env) {
991
+ return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
761
992
  }
762
- function usageRecorded(env = process6.env) {
993
+ function usageRecorded(env = process11.env) {
763
994
  const off = env.KAYNOOO_CLI_NO_USAGE;
764
995
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
765
996
  }
@@ -773,12 +1004,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
773
1004
  usageError = undefined;
774
1005
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
775
1006
  }
776
- function recordUsage(entry, env = process6.env) {
1007
+ function recordUsage(entry, env = process11.env) {
777
1008
  if (!usageRecorded(env))
778
1009
  return;
779
1010
  try {
780
1011
  const path = usagePath(env);
781
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
1012
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
782
1013
  appendFileSync(path, `${JSON.stringify(entry)}
783
1014
  `, { mode: 384 });
784
1015
  } catch {}
@@ -864,8 +1095,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
864
1095
  `);
865
1096
  }
866
1097
  function printError(prefix, message, hint, cause) {
867
- const colors = paint(process7.stderr);
868
- const styled = takesControlCodes(process7.stderr);
1098
+ const colors = paint(process12.stderr);
1099
+ const styled = takesControlCodes(process12.stderr);
869
1100
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
870
1101
  const under = (label, text, tint) => text === undefined ? "" : `
871
1102
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -908,11 +1139,11 @@ async function dispatch(level, typed, { version, redact }) {
908
1139
  }
909
1140
  }
910
1141
  if (name === undefined && level.path.length > 1) {
911
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process7.stderr));
1142
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stderr));
912
1143
  return 2;
913
1144
  }
914
1145
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
915
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process7.stdout));
1146
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stdout));
916
1147
  return 0;
917
1148
  }
918
1149
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1029,17 +1260,17 @@ async function printCandidates(found) {
1029
1260
  return 0;
1030
1261
  }
1031
1262
  function packageVersion(entry = Bun.main) {
1032
- for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
1263
+ for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1033
1264
  try {
1034
- const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
1265
+ const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
1035
1266
  if (typeof version === "string")
1036
1267
  return version;
1037
1268
  } catch {}
1038
- if (dirname2(dir) === dir)
1269
+ if (dirname3(dir) === dir)
1039
1270
  return "0.0.0";
1040
1271
  }
1041
1272
  }
1042
- async function runCli(cli, argv = process7.argv.slice(2)) {
1273
+ async function runCli(cli, argv = process12.argv.slice(2)) {
1043
1274
  const version = cli.version ?? packageVersion();
1044
1275
  if (argv[0] === COMPLETE)
1045
1276
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
@@ -1066,7 +1297,7 @@ function commandPath(scope, argv) {
1066
1297
  }
1067
1298
  return path.length === 0 ? undefined : path.join(" ");
1068
1299
  }
1069
- async function runMain({ name, version, run, redact, usage }, argv = process7.argv.slice(2)) {
1300
+ async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
1070
1301
  if (argv[0] === COMPLETE)
1071
1302
  return printCandidates(leafCandidates(run, argv.slice(1)));
1072
1303
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1086,6 +1317,8 @@ async function runMain({ name, version, run, redact, usage }, argv = process7.ar
1086
1317
  }
1087
1318
  return code;
1088
1319
  }
1320
+ // ../kit/src/folders.ts
1321
+ var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1089
1322
  // ../kit/src/secrets.ts
1090
1323
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1091
1324
  // ../kit/src/sessions.ts
@@ -1093,14 +1326,15 @@ var {Glob } = globalThis.Bun;
1093
1326
  var SESSION_FILES = new Glob("*.json");
1094
1327
  var ACCOUNT_DIRS = new Glob("*/sessions");
1095
1328
  // src/proof.ts
1096
- import process10 from "process";
1329
+ import process15 from "process";
1097
1330
 
1098
1331
  // src/worktree.ts
1099
- import { cpSync, existsSync, lstatSync, mkdirSync as mkdirSync2, mkdtempSync, readdirSync, realpathSync as realpathSync2, rmSync, symlinkSync, unlinkSync } from "fs";
1332
+ import { cpSync, existsSync as existsSync3, lstatSync, mkdirSync as mkdirSync2, mkdtempSync, readdirSync, realpathSync as realpathSync2, rmSync, symlinkSync, unlinkSync } from "fs";
1100
1333
  import { tmpdir } from "os";
1101
- import { basename, dirname as dirname3, isAbsolute as isAbsolute2, join as join3, relative, resolve, sep } from "path";
1102
- import process9 from "process";
1334
+ import { basename, dirname as dirname4, isAbsolute as isAbsolute2, join as join6, relative, resolve as resolve3, sep } from "path";
1335
+ import process14 from "process";
1103
1336
  var WHITESPACE = /\s/;
1337
+ var ORIGIN_PREFIX = /^origin\//;
1104
1338
  var ENV_FILE = /^\.env(?:\..+)?$/;
1105
1339
  var DEPENDENCIES = new Set(["node_modules", "vendor", ".venv"]);
1106
1340
  var TRAILING_SLASH = /\/$/;
@@ -1130,32 +1364,37 @@ async function resolveRef(root, ref) {
1130
1364
  fail(`no commit ${ref} in this repository`);
1131
1365
  return stdoutOf(ran);
1132
1366
  }
1367
+ async function defaultRemoteRef(root) {
1368
+ const head = await git2(["symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD"], root);
1369
+ return head.code === 0 && stdoutOf(head) !== "" ? stdoutOf(head) : "origin/main";
1370
+ }
1133
1371
  async function defaultProofRef(root) {
1134
1372
  const branch = await git2(["symbolic-ref", "--quiet", "--short", "HEAD"], root);
1135
- if (branch.code !== 0 || stdoutOf(branch) === "main")
1373
+ const remote = await defaultRemoteRef(root);
1374
+ if (branch.code !== 0 || stdoutOf(branch) === remote.replace(ORIGIN_PREFIX, ""))
1136
1375
  return "HEAD";
1137
- const base = await git2(["merge-base", "HEAD", "origin/main"], root);
1376
+ const base = await git2(["merge-base", "HEAD", remote], root);
1138
1377
  const head = await git2(["rev-parse", "HEAD"], root);
1139
1378
  return base.code === 0 && stdoutOf(base) !== stdoutOf(head) ? stdoutOf(base) : "HEAD";
1140
1379
  }
1141
1380
  function keptPaths(root, cwd, paths) {
1142
1381
  const realRoot = realpathSync2(root);
1143
1382
  return paths.map((path) => {
1144
- const absolute = resolve(cwd, path);
1145
- if (!existsSync(dirname3(absolute)))
1383
+ const absolute = resolve3(cwd, path);
1384
+ if (!existsSync3(dirname4(absolute)))
1146
1385
  fail(`--keep ${path}: no such file`);
1147
- const inRepo = relative(realRoot, join3(realpathSync2(dirname3(absolute)), basename(absolute)));
1386
+ const inRepo = relative(realRoot, join6(realpathSync2(dirname4(absolute)), basename(absolute)));
1148
1387
  if (inRepo === "" || inRepo === ".." || inRepo.startsWith(PARENT) || isAbsolute2(inRepo))
1149
1388
  fail(`--keep ${path} is outside the repository`);
1150
- if (!existsSync(absolute))
1389
+ if (!existsSync3(absolute))
1151
1390
  fail(`--keep ${path}: no such file`);
1152
1391
  return inRepo;
1153
1392
  });
1154
1393
  }
1155
1394
  function checkNoSymlink(dir, path) {
1156
1395
  let current = dir;
1157
- for (const part of dirname3(path).split(sep)) {
1158
- current = join3(current, part);
1396
+ for (const part of dirname4(path).split(sep)) {
1397
+ current = join6(current, part);
1159
1398
  if (lstatSync(current, { throwIfNoEntry: false })?.isSymbolicLink() === true)
1160
1399
  fail(`--keep ${path} goes through the symlink ${relative(dir, current)} of the ref, which would write outside the worktree`);
1161
1400
  }
@@ -1171,10 +1410,10 @@ async function linkedEntries(root) {
1171
1410
  }).map((entry) => entry.replace(TRAILING_SLASH, ""));
1172
1411
  }
1173
1412
  async function addWorktree(root, sha) {
1174
- const dir = join3(mkdtempSync(join3(tmpdir(), "base-")), basename(root));
1413
+ const dir = join6(mkdtempSync(join6(tmpdir(), "base-")), basename(root));
1175
1414
  const ran = await git2(["worktree", "add", "--detach", dir, sha], root);
1176
1415
  if (ran.code !== 0) {
1177
- rmSync(dirname3(dir), { recursive: true, force: true });
1416
+ rmSync(dirname4(dir), { recursive: true, force: true });
1178
1417
  fail(`git worktree add failed:
1179
1418
  ${ran.text.trim()}`);
1180
1419
  }
@@ -1183,41 +1422,41 @@ ${ran.text.trim()}`);
1183
1422
  function copyKept(root, dir, paths) {
1184
1423
  for (const path of paths) {
1185
1424
  checkNoSymlink(dir, path);
1186
- const target = join3(dir, path);
1425
+ const target = join6(dir, path);
1187
1426
  rmSync(target, { recursive: true, force: true });
1188
- mkdirSync2(dirname3(target), { recursive: true });
1189
- cpSync(join3(root, path), target, { recursive: true });
1427
+ mkdirSync2(dirname4(target), { recursive: true });
1428
+ cpSync(join6(root, path), target, { recursive: true });
1190
1429
  }
1191
1430
  }
1192
1431
  function linkEntries(root, dir, entries) {
1193
1432
  const links = [];
1194
1433
  for (const entry of entries) {
1195
- const link = join3(dir, entry);
1196
- if (existsSync(link))
1434
+ const link = join6(dir, entry);
1435
+ if (existsSync3(link))
1197
1436
  continue;
1198
- mkdirSync2(dirname3(link), { recursive: true });
1437
+ mkdirSync2(dirname4(link), { recursive: true });
1199
1438
  if (basename(entry) === "node_modules" && hasWorkspaceLinks(root, entry)) {
1200
1439
  links.push(...linkModules(root, dir, entry));
1201
1440
  continue;
1202
1441
  }
1203
- symlinkSync(join3(root, entry), link);
1442
+ symlinkSync(join6(root, entry), link);
1204
1443
  links.push(link);
1205
1444
  }
1206
1445
  return links;
1207
1446
  }
1208
1447
  function moduleLinks(root, folder) {
1209
1448
  const found = [];
1210
- for (const entry of readdirSync(join3(root, folder), { withFileTypes: true })) {
1449
+ for (const entry of readdirSync(join6(root, folder), { withFileTypes: true })) {
1211
1450
  if (entry.isSymbolicLink())
1212
- found.push({ path: join3(folder, entry.name), name: entry.name });
1451
+ found.push({ path: join6(folder, entry.name), name: entry.name });
1213
1452
  else if (entry.isDirectory() && entry.name.startsWith("@"))
1214
- found.push(...moduleLinks(root, join3(folder, entry.name)));
1453
+ found.push(...moduleLinks(root, join6(folder, entry.name)));
1215
1454
  }
1216
1455
  return found;
1217
1456
  }
1218
1457
  function workspaceTarget(root, path) {
1219
1458
  try {
1220
- const inRepo = relative(realpathSync2(root), realpathSync2(join3(root, path)));
1459
+ const inRepo = relative(realpathSync2(root), realpathSync2(join6(root, path)));
1221
1460
  return inRepo === "" || inRepo.startsWith(PARENT) || inRepo.split(sep).includes("node_modules") ? undefined : inRepo;
1222
1461
  } catch {
1223
1462
  return;
@@ -1228,16 +1467,16 @@ function hasWorkspaceLinks(root, folder) {
1228
1467
  }
1229
1468
  function linkModules(root, dir, folder) {
1230
1469
  const links = [];
1231
- mkdirSync2(join3(dir, folder), { recursive: true });
1232
- for (const entry of readdirSync(join3(root, folder), { withFileTypes: true })) {
1233
- const path = join3(folder, entry.name);
1234
- const link = join3(dir, path);
1470
+ mkdirSync2(join6(dir, folder), { recursive: true });
1471
+ for (const entry of readdirSync(join6(root, folder), { withFileTypes: true })) {
1472
+ const path = join6(folder, entry.name);
1473
+ const link = join6(dir, path);
1235
1474
  if (entry.isDirectory() && entry.name.startsWith("@")) {
1236
1475
  links.push(...linkModules(root, dir, path));
1237
1476
  continue;
1238
1477
  }
1239
1478
  const workspace = entry.isSymbolicLink() ? workspaceTarget(root, path) : undefined;
1240
- symlinkSync(workspace === undefined ? join3(root, path) : join3(dir, workspace), link);
1479
+ symlinkSync(workspace === undefined ? join6(root, path) : join6(dir, workspace), link);
1241
1480
  links.push(link);
1242
1481
  }
1243
1482
  return links;
@@ -1247,9 +1486,9 @@ async function sweepStale(root) {
1247
1486
  for (const name of readdirSync(tmpdir())) {
1248
1487
  if (!BASE_DIR.test(name))
1249
1488
  continue;
1250
- const path = join3(tmpdir(), name);
1489
+ const path = join6(tmpdir(), name);
1251
1490
  const stat = lstatSync(path, { throwIfNoEntry: false });
1252
- if (stat?.isDirectory() === true && stat.uid === process9.getuid?.() && Date.now() - stat.mtimeMs > STALE_AFTER)
1491
+ if (stat?.isDirectory() === true && stat.uid === process14.getuid?.() && Date.now() - stat.mtimeMs > STALE_AFTER)
1253
1492
  rmSync(path, { recursive: true, force: true });
1254
1493
  }
1255
1494
  await git2(["worktree", "prune"], root);
@@ -1260,7 +1499,7 @@ async function removeWorktree(root, dir, links) {
1260
1499
  unlinkSync(link);
1261
1500
  }
1262
1501
  await git2(["worktree", "remove", "--force", dir], root);
1263
- rmSync(dirname3(dir), { recursive: true, force: true });
1502
+ rmSync(dirname4(dir), { recursive: true, force: true });
1264
1503
  await git2(["worktree", "prune"], root);
1265
1504
  }
1266
1505
  function shellCommand(given) {
@@ -1308,8 +1547,8 @@ async function inWorktree(options, body) {
1308
1547
  try {
1309
1548
  copyKept(root, dir, kept);
1310
1549
  links = link ? linkEntries(root, dir, await linkedEntries(root)) : [];
1311
- const runDir = join3(dir, prefix);
1312
- if (!existsSync(runDir))
1550
+ const runDir = join6(dir, prefix);
1551
+ if (!existsSync3(runDir))
1313
1552
  fail(`${prefix} does not exist at ${ref}`);
1314
1553
  return await body(runDir, signals);
1315
1554
  } finally {
@@ -1322,10 +1561,10 @@ async function inWorktree(options, body) {
1322
1561
  // src/proof.ts
1323
1562
  var USAGE = `proof [--ref <rev>] [--runs <n>] [--keep <path>...] [--no-link] [--json] -- <command> [args...]: runs the command at HEAD or another ref in a temporary worktree, then in the working tree, to show that a test fails before a change and passes after it
1324
1563
 
1325
- The ref defaults to the merge base with origin/main when HEAD is on a branch ahead of it, else HEAD. --runs <n> runs the command n times now, for a flaky test, and every run must pass.`;
1564
+ The ref defaults to the merge base with the default branch of origin (origin/main unless origin/HEAD names another) when HEAD is on a branch ahead of it, else HEAD. --runs <n> runs the command n times now, for a flaky test, and every run must pass.`;
1326
1565
  var EXITS = [[0, "the command fails before and passes in every run now"], [1, "it passes before too, fails in any run now, or passes before and fails now"], [2, "a usage error, an unknown ref, a command that cannot start or ends with exit 126, 127 or a signal"], [130, "interrupted (128 plus the signal)"]];
1327
1566
  var OPTIONS = {
1328
- ref: { type: "string", short: "r", description: "the commit to run before at (default: the merge base with origin/main on a branch ahead of it, else HEAD)" },
1567
+ ref: { type: "string", short: "r", description: "the commit to run before at (default: the merge base with the default branch of origin on a branch ahead of it, else HEAD)" },
1329
1568
  runs: { type: "string", short: "n", description: "run the command this many times now, every run must pass (1)" },
1330
1569
  keep: { type: "string", short: "k", multiple: true, description: "a working-tree file or folder copied over to the ref, such as the new test, repeatable" },
1331
1570
  "no-link": { type: "boolean", description: "do not link the ignored env files, node_modules, vendor and .venv of the checkout" },
@@ -1369,7 +1608,7 @@ ${USAGE}`);
1369
1608
  if (runsInContainer(given))
1370
1609
  fail("a container of the compose project mounts the main checkout, not the temporary worktree, so the command would not run at the ref: run the tool on the host, or check the ref out by hand");
1371
1610
  const command = shellCommand(given);
1372
- const cwd = process10.cwd();
1611
+ const cwd = process15.cwd();
1373
1612
  const { root, prefix } = await checkout(cwd);
1374
1613
  const runs = wholeNumber(parsed.values.runs, "runs", 1, 1);
1375
1614
  const ref = parsed.values.ref ?? await defaultProofRef(root);
@@ -1404,7 +1643,7 @@ ${folded(run.output)}`}`);
1404
1643
  printJson({ outcome, proved, ref, sha, before: { code: before.code, output: before.output }, now: { code: now.code, output: now.output }, runs: nowRuns.map((run) => ({ code: run.code })) });
1405
1644
  return proved ? 0 : 1;
1406
1645
  }
1407
- console.log(message);
1646
+ console.log(role(proved ? "ok" : "problem", process15.stdout)(message));
1408
1647
  if (runs > 1)
1409
1648
  console.log(`now: ${codes.map((code, i) => `run ${i + 1} ${code === 0 ? "passed" : `failed (exit ${code})`}`).join(", ")}`);
1410
1649
  const shown = side === "before" ? before : now;
@@ -1415,4 +1654,4 @@ ${folded(shown.output)}`);
1415
1654
  }
1416
1655
 
1417
1656
  // src/proof-cli.ts
1418
- process11.exitCode = await runMain({ name: "proof", run: proof });
1657
+ process16.exitCode = await runMain({ name: "proof", run: proof });