@kaynooo/cli-base 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -2,13 +2,34 @@
2
2
  // @bun
3
3
 
4
4
  // src/cli.ts
5
- import process12 from "process";
5
+ import process14 from "process";
6
6
  // ../kit/src/args.ts
7
- import process4 from "process";
7
+ import process6 from "process";
8
8
  import { parseArgs } from "util";
9
9
 
10
- // ../kit/src/style.ts
10
+ // ../kit/src/format.ts
11
+ import process4 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 process3 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,26 @@ function le(i = {}) {
271
292
  }
272
293
  var t = le();
273
294
 
295
+ // ../kit/src/theme.ts
296
+ 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"]);
297
+ var MAX_FILE_BYTES = 64 * 1024;
298
+ var warned = new Set;
299
+
274
300
  // ../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";
301
+ function takesControlCodes(stream, env = process3.env) {
302
+ return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
277
303
  }
278
- function paint(stream, env = process2.env) {
304
+ function paint(stream, env = process3.env) {
279
305
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
280
306
  }
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 }
307
+ var STATUS_WORDS = {
308
+ passed: ["passed", "success", "succeeded", "ok"],
309
+ failed: ["failed", "failure", "error", "errored"],
310
+ running: ["running", "in_progress", "started", "holding"],
311
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
312
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
287
313
  };
288
- var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
314
+ var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
289
315
 
290
316
  // ../kit/src/format.ts
291
317
  function upTo(text, separator) {
@@ -293,32 +319,35 @@ function upTo(text, separator) {
293
319
  return end === -1 ? text : text.slice(0, end);
294
320
  }
295
321
  var ESCAPE = String.fromCharCode(27);
322
+ function jsonText(value, replacer, { stream = process4.stdout, env = process4.env } = {}) {
323
+ return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
324
+ }
296
325
  function printJson(value) {
297
- console.log(JSON.stringify(value, undefined, 2));
326
+ console.log(jsonText(value));
298
327
  }
299
328
 
300
329
  // ../kit/src/help.ts
301
- import process3 from "process";
330
+ import process5 from "process";
302
331
  var OPTIONAL = /\[[^\]]+\]/g;
303
332
  var USAGE_PREFIX = /^usage:\s*/i;
304
333
  var FULL_STOP = /\.$/;
305
- function usageLine(usage, colors = paint(process3.stdout)) {
334
+ function usageLine(usage, colors = paint(process5.stdout)) {
306
335
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
307
336
  }
308
- function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces, exits = [] } = {}) {
337
+ function helpText(usage, options, colors = paint(process5.stdout), { examples = [], replaces, exits = [] } = {}) {
309
338
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
310
339
  `);
311
340
  }
312
- function exitRows(exits, colors = paint(process3.stdout)) {
341
+ function exitRows(exits, colors = paint(process5.stdout)) {
313
342
  if (exits.length === 0)
314
343
  return [];
315
344
  const width = Math.max(...exits.map(([code]) => String(code).length));
316
345
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
317
346
  }
318
- function replacesRows(replaces, colors = paint(process3.stdout)) {
319
- return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
347
+ function replacesRows(replaces, colors = paint(process5.stdout)) {
348
+ return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
320
349
  }
321
- function wantsHelpJson(env = process3.env) {
350
+ function wantsHelpJson(env = process5.env) {
322
351
  return env.KIT_HELP === "json";
323
352
  }
324
353
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -337,12 +366,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
337
366
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
338
367
  };
339
368
  }
340
- function exampleRows(examples, colors = paint(process3.stdout)) {
341
- if (examples.length === 0)
369
+ function exampleRows(examples, colors = paint(process5.stdout)) {
370
+ if (examples.length === 0 || outputMode() === "agent")
342
371
  return [];
343
372
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
344
373
  }
345
- function optionRows(options, colors = paint(process3.stdout)) {
374
+ function optionRows(options, colors = paint(process5.stdout)) {
346
375
  const rows = Object.entries(options).map(([name, option]) => {
347
376
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
348
377
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -389,7 +418,6 @@ var DASHES = /^-+/;
389
418
  function jsonOption(holds) {
390
419
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
391
420
  }
392
-
393
421
  class Exit extends Error {
394
422
  code;
395
423
  hint;
@@ -433,7 +461,7 @@ var OUTPUT_OPTIONS = {
433
461
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
434
462
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
435
463
  };
436
- function applyOutput(color, plain, env = process4.env) {
464
+ function applyOutput(color, plain, env = process6.env) {
437
465
  const when = plain === true ? "never" : color ?? "auto";
438
466
  if (when === "auto")
439
467
  return;
@@ -604,7 +632,7 @@ function nearestOption(message, options, allowNegative) {
604
632
  }
605
633
  // ../kit/src/process.ts
606
634
  import { constants } from "os";
607
- import process5 from "process";
635
+ import process7 from "process";
608
636
  var KILL_GRACE_MS = 2000;
609
637
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
610
638
  function exitCodeOf(code, signal) {
@@ -626,7 +654,7 @@ function holdSignals(cleanup) {
626
654
  },
627
655
  release: () => {
628
656
  for (const signal of SIGNALS)
629
- process5.off(signal, onSignal);
657
+ process7.off(signal, onSignal);
630
658
  }
631
659
  };
632
660
  function onSignal(signal) {
@@ -639,10 +667,10 @@ function holdSignals(cleanup) {
639
667
  return;
640
668
  held.release();
641
669
  cleanup(signal);
642
- process5.kill(process5.pid, signal);
670
+ process7.kill(process7.pid, signal);
643
671
  }
644
672
  for (const signal of SIGNALS)
645
- process5.on(signal, onSignal);
673
+ process7.on(signal, onSignal);
646
674
  return held;
647
675
  }
648
676
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -656,7 +684,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
656
684
  return;
657
685
  try {
658
686
  if (grouped)
659
- process5.kill(-proc.pid, killing);
687
+ process7.kill(-proc.pid, killing);
660
688
  else
661
689
  proc.kill(killing);
662
690
  } catch {}
@@ -732,13 +760,13 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
732
760
  // ../kit/src/cli.ts
733
761
  import { readFileSync, realpathSync } from "fs";
734
762
  import { dirname as dirname2, join as join2 } from "path";
735
- import process7 from "process";
763
+ import process9 from "process";
736
764
 
737
765
  // ../kit/src/usage.ts
738
766
  import { appendFileSync, mkdirSync } from "fs";
739
767
  import { homedir } from "os";
740
768
  import { dirname, isAbsolute, join } from "path";
741
- import process6 from "process";
769
+ import process8 from "process";
742
770
 
743
771
  // ../kit/src/logs.ts
744
772
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -752,14 +780,14 @@ var usageError;
752
780
  function noteUsageError(message) {
753
781
  usageError = message;
754
782
  }
755
- function stateHome(env = process6.env) {
783
+ function stateHome(env = process8.env) {
756
784
  const dir = env.XDG_STATE_HOME;
757
785
  return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
758
786
  }
759
- function usagePath(env = process6.env) {
787
+ function usagePath(env = process8.env) {
760
788
  return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
761
789
  }
762
- function usageRecorded(env = process6.env) {
790
+ function usageRecorded(env = process8.env) {
763
791
  const off = env.KAYNOOO_CLI_NO_USAGE;
764
792
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
765
793
  }
@@ -773,7 +801,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
773
801
  usageError = undefined;
774
802
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
775
803
  }
776
- function recordUsage(entry, env = process6.env) {
804
+ function recordUsage(entry, env = process8.env) {
777
805
  if (!usageRecorded(env))
778
806
  return;
779
807
  try {
@@ -864,8 +892,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
864
892
  `);
865
893
  }
866
894
  function printError(prefix, message, hint, cause) {
867
- const colors = paint(process7.stderr);
868
- const styled = takesControlCodes(process7.stderr);
895
+ const colors = paint(process9.stderr);
896
+ const styled = takesControlCodes(process9.stderr);
869
897
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
870
898
  const under = (label, text, tint) => text === undefined ? "" : `
871
899
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -908,11 +936,11 @@ async function dispatch(level, typed, { version, redact }) {
908
936
  }
909
937
  }
910
938
  if (name === undefined && level.path.length > 1) {
911
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process7.stderr));
939
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stderr));
912
940
  return 2;
913
941
  }
914
942
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
915
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process7.stdout));
943
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stdout));
916
944
  return 0;
917
945
  }
918
946
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1039,7 +1067,7 @@ function packageVersion(entry = Bun.main) {
1039
1067
  return "0.0.0";
1040
1068
  }
1041
1069
  }
1042
- async function runCli(cli, argv = process7.argv.slice(2)) {
1070
+ async function runCli(cli, argv = process9.argv.slice(2)) {
1043
1071
  const version = cli.version ?? packageVersion();
1044
1072
  if (argv[0] === COMPLETE)
1045
1073
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
@@ -1066,7 +1094,7 @@ function commandPath(scope, argv) {
1066
1094
  }
1067
1095
  return path.length === 0 ? undefined : path.join(" ");
1068
1096
  }
1069
- async function runMain({ name, version, run, redact, usage }, argv = process7.argv.slice(2)) {
1097
+ async function runMain({ name, version, run, redact, usage }, argv = process9.argv.slice(2)) {
1070
1098
  if (argv[0] === COMPLETE)
1071
1099
  return printCandidates(leafCandidates(run, argv.slice(1)));
1072
1100
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1093,14 +1121,15 @@ var {Glob } = globalThis.Bun;
1093
1121
  var SESSION_FILES = new Glob("*.json");
1094
1122
  var ACCOUNT_DIRS = new Glob("*/sessions");
1095
1123
  // src/base.ts
1096
- import process10 from "process";
1124
+ import process12 from "process";
1097
1125
 
1098
1126
  // src/worktree.ts
1099
1127
  import { cpSync, existsSync, lstatSync, mkdirSync as mkdirSync2, mkdtempSync, readdirSync, realpathSync as realpathSync2, rmSync, symlinkSync, unlinkSync } from "fs";
1100
1128
  import { tmpdir } from "os";
1101
1129
  import { basename, dirname as dirname3, isAbsolute as isAbsolute2, join as join3, relative, resolve, sep } from "path";
1102
- import process9 from "process";
1130
+ import process11 from "process";
1103
1131
  var WHITESPACE = /\s/;
1132
+ var ORIGIN_PREFIX = /^origin\//;
1104
1133
  var ENV_FILE = /^\.env(?:\..+)?$/;
1105
1134
  var DEPENDENCIES = new Set(["node_modules", "vendor", ".venv"]);
1106
1135
  var TRAILING_SLASH = /\/$/;
@@ -1130,11 +1159,16 @@ async function resolveRef(root, ref) {
1130
1159
  fail(`no commit ${ref} in this repository`);
1131
1160
  return stdoutOf(ran);
1132
1161
  }
1162
+ async function defaultRemoteRef(root) {
1163
+ const head = await git2(["symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD"], root);
1164
+ return head.code === 0 && stdoutOf(head) !== "" ? stdoutOf(head) : "origin/main";
1165
+ }
1133
1166
  async function defaultProofRef(root) {
1134
1167
  const branch = await git2(["symbolic-ref", "--quiet", "--short", "HEAD"], root);
1135
- if (branch.code !== 0 || stdoutOf(branch) === "main")
1168
+ const remote = await defaultRemoteRef(root);
1169
+ if (branch.code !== 0 || stdoutOf(branch) === remote.replace(ORIGIN_PREFIX, ""))
1136
1170
  return "HEAD";
1137
- const base = await git2(["merge-base", "HEAD", "origin/main"], root);
1171
+ const base = await git2(["merge-base", "HEAD", remote], root);
1138
1172
  const head = await git2(["rev-parse", "HEAD"], root);
1139
1173
  return base.code === 0 && stdoutOf(base) !== stdoutOf(head) ? stdoutOf(base) : "HEAD";
1140
1174
  }
@@ -1249,7 +1283,7 @@ async function sweepStale(root) {
1249
1283
  continue;
1250
1284
  const path = join3(tmpdir(), name);
1251
1285
  const stat = lstatSync(path, { throwIfNoEntry: false });
1252
- if (stat?.isDirectory() === true && stat.uid === process9.getuid?.() && Date.now() - stat.mtimeMs > STALE_AFTER)
1286
+ if (stat?.isDirectory() === true && stat.uid === process11.getuid?.() && Date.now() - stat.mtimeMs > STALE_AFTER)
1253
1287
  rmSync(path, { recursive: true, force: true });
1254
1288
  }
1255
1289
  await git2(["worktree", "prune"], root);
@@ -1339,7 +1373,7 @@ ${USAGE}`);
1339
1373
  if (runsInContainer(given))
1340
1374
  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");
1341
1375
  const command = shellCommand(given);
1342
- const cwd = process10.cwd();
1376
+ const cwd = process12.cwd();
1343
1377
  const { root, prefix } = await checkout(cwd);
1344
1378
  const ref = parsed.values.ref ?? "HEAD";
1345
1379
  const sha = await resolveRef(root, ref);
@@ -1352,13 +1386,13 @@ ${USAGE}`);
1352
1386
  }
1353
1387
 
1354
1388
  // src/proof.ts
1355
- import process11 from "process";
1389
+ import process13 from "process";
1356
1390
  var USAGE2 = `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
1357
1391
 
1358
- 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.`;
1392
+ 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.`;
1359
1393
  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)"]];
1360
1394
  var OPTIONS2 = {
1361
- 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)" },
1395
+ 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)" },
1362
1396
  runs: { type: "string", short: "n", description: "run the command this many times now, every run must pass (1)" },
1363
1397
  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" },
1364
1398
  "no-link": { type: "boolean", description: "do not link the ignored env files, node_modules, vendor and .venv of the checkout" },
@@ -1402,7 +1436,7 @@ ${USAGE2}`);
1402
1436
  if (runsInContainer(given))
1403
1437
  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");
1404
1438
  const command = shellCommand(given);
1405
- const cwd = process11.cwd();
1439
+ const cwd = process13.cwd();
1406
1440
  const { root, prefix } = await checkout(cwd);
1407
1441
  const runs = wholeNumber(parsed.values.runs, "runs", 1, 1);
1408
1442
  const ref = parsed.values.ref ?? await defaultProofRef(root);
@@ -1448,7 +1482,7 @@ ${folded(shown.output)}`);
1448
1482
  }
1449
1483
 
1450
1484
  // src/cli.ts
1451
- process12.exitCode = await runCli({
1485
+ process14.exitCode = await runCli({
1452
1486
  name: "base",
1453
1487
  about: "runs a command at HEAD or another ref in a temporary worktree, the working tree untouched",
1454
1488
  replaces: "git stash, a test run, then git stash pop",
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 process13 from "process";
6
6
  // ../kit/src/args.ts
7
- import process4 from "process";
7
+ import process6 from "process";
8
8
  import { parseArgs } from "util";
9
9
 
10
- // ../kit/src/style.ts
10
+ // ../kit/src/format.ts
11
+ import process4 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 process3 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,26 @@ function le(i = {}) {
271
292
  }
272
293
  var t = le();
273
294
 
295
+ // ../kit/src/theme.ts
296
+ 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"]);
297
+ var MAX_FILE_BYTES = 64 * 1024;
298
+ var warned = new Set;
299
+
274
300
  // ../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";
301
+ function takesControlCodes(stream, env = process3.env) {
302
+ return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
277
303
  }
278
- function paint(stream, env = process2.env) {
304
+ function paint(stream, env = process3.env) {
279
305
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
280
306
  }
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 }
307
+ var STATUS_WORDS = {
308
+ passed: ["passed", "success", "succeeded", "ok"],
309
+ failed: ["failed", "failure", "error", "errored"],
310
+ running: ["running", "in_progress", "started", "holding"],
311
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
312
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
287
313
  };
288
- var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
314
+ var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
289
315
 
290
316
  // ../kit/src/format.ts
291
317
  function upTo(text, separator) {
@@ -293,32 +319,35 @@ function upTo(text, separator) {
293
319
  return end === -1 ? text : text.slice(0, end);
294
320
  }
295
321
  var ESCAPE = String.fromCharCode(27);
322
+ function jsonText(value, replacer, { stream = process4.stdout, env = process4.env } = {}) {
323
+ return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
324
+ }
296
325
  function printJson(value) {
297
- console.log(JSON.stringify(value, undefined, 2));
326
+ console.log(jsonText(value));
298
327
  }
299
328
 
300
329
  // ../kit/src/help.ts
301
- import process3 from "process";
330
+ import process5 from "process";
302
331
  var OPTIONAL = /\[[^\]]+\]/g;
303
332
  var USAGE_PREFIX = /^usage:\s*/i;
304
333
  var FULL_STOP = /\.$/;
305
- function usageLine(usage, colors = paint(process3.stdout)) {
334
+ function usageLine(usage, colors = paint(process5.stdout)) {
306
335
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
307
336
  }
308
- function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces, exits = [] } = {}) {
337
+ function helpText(usage, options, colors = paint(process5.stdout), { examples = [], replaces, exits = [] } = {}) {
309
338
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
310
339
  `);
311
340
  }
312
- function exitRows(exits, colors = paint(process3.stdout)) {
341
+ function exitRows(exits, colors = paint(process5.stdout)) {
313
342
  if (exits.length === 0)
314
343
  return [];
315
344
  const width = Math.max(...exits.map(([code]) => String(code).length));
316
345
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
317
346
  }
318
- function replacesRows(replaces, colors = paint(process3.stdout)) {
319
- return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
347
+ function replacesRows(replaces, colors = paint(process5.stdout)) {
348
+ return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
320
349
  }
321
- function wantsHelpJson(env = process3.env) {
350
+ function wantsHelpJson(env = process5.env) {
322
351
  return env.KIT_HELP === "json";
323
352
  }
324
353
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -337,12 +366,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
337
366
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
338
367
  };
339
368
  }
340
- function exampleRows(examples, colors = paint(process3.stdout)) {
341
- if (examples.length === 0)
369
+ function exampleRows(examples, colors = paint(process5.stdout)) {
370
+ if (examples.length === 0 || outputMode() === "agent")
342
371
  return [];
343
372
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
344
373
  }
345
- function optionRows(options, colors = paint(process3.stdout)) {
374
+ function optionRows(options, colors = paint(process5.stdout)) {
346
375
  const rows = Object.entries(options).map(([name, option]) => {
347
376
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
348
377
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -389,7 +418,6 @@ var DASHES = /^-+/;
389
418
  function jsonOption(holds) {
390
419
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
391
420
  }
392
-
393
421
  class Exit extends Error {
394
422
  code;
395
423
  hint;
@@ -433,7 +461,7 @@ var OUTPUT_OPTIONS = {
433
461
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
434
462
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
435
463
  };
436
- function applyOutput(color, plain, env = process4.env) {
464
+ function applyOutput(color, plain, env = process6.env) {
437
465
  const when = plain === true ? "never" : color ?? "auto";
438
466
  if (when === "auto")
439
467
  return;
@@ -604,7 +632,7 @@ function nearestOption(message, options, allowNegative) {
604
632
  }
605
633
  // ../kit/src/process.ts
606
634
  import { constants } from "os";
607
- import process5 from "process";
635
+ import process7 from "process";
608
636
  var KILL_GRACE_MS = 2000;
609
637
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
610
638
  function exitCodeOf(code, signal) {
@@ -626,7 +654,7 @@ function holdSignals(cleanup) {
626
654
  },
627
655
  release: () => {
628
656
  for (const signal of SIGNALS)
629
- process5.off(signal, onSignal);
657
+ process7.off(signal, onSignal);
630
658
  }
631
659
  };
632
660
  function onSignal(signal) {
@@ -639,10 +667,10 @@ function holdSignals(cleanup) {
639
667
  return;
640
668
  held.release();
641
669
  cleanup(signal);
642
- process5.kill(process5.pid, signal);
670
+ process7.kill(process7.pid, signal);
643
671
  }
644
672
  for (const signal of SIGNALS)
645
- process5.on(signal, onSignal);
673
+ process7.on(signal, onSignal);
646
674
  return held;
647
675
  }
648
676
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -656,7 +684,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
656
684
  return;
657
685
  try {
658
686
  if (grouped)
659
- process5.kill(-proc.pid, killing);
687
+ process7.kill(-proc.pid, killing);
660
688
  else
661
689
  proc.kill(killing);
662
690
  } catch {}
@@ -732,13 +760,13 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
732
760
  // ../kit/src/cli.ts
733
761
  import { readFileSync, realpathSync } from "fs";
734
762
  import { dirname as dirname2, join as join2 } from "path";
735
- import process7 from "process";
763
+ import process9 from "process";
736
764
 
737
765
  // ../kit/src/usage.ts
738
766
  import { appendFileSync, mkdirSync } from "fs";
739
767
  import { homedir } from "os";
740
768
  import { dirname, isAbsolute, join } from "path";
741
- import process6 from "process";
769
+ import process8 from "process";
742
770
 
743
771
  // ../kit/src/logs.ts
744
772
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -752,14 +780,14 @@ var usageError;
752
780
  function noteUsageError(message) {
753
781
  usageError = message;
754
782
  }
755
- function stateHome(env = process6.env) {
783
+ function stateHome(env = process8.env) {
756
784
  const dir = env.XDG_STATE_HOME;
757
785
  return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
758
786
  }
759
- function usagePath(env = process6.env) {
787
+ function usagePath(env = process8.env) {
760
788
  return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
761
789
  }
762
- function usageRecorded(env = process6.env) {
790
+ function usageRecorded(env = process8.env) {
763
791
  const off = env.KAYNOOO_CLI_NO_USAGE;
764
792
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
765
793
  }
@@ -773,7 +801,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
773
801
  usageError = undefined;
774
802
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
775
803
  }
776
- function recordUsage(entry, env = process6.env) {
804
+ function recordUsage(entry, env = process8.env) {
777
805
  if (!usageRecorded(env))
778
806
  return;
779
807
  try {
@@ -864,8 +892,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
864
892
  `);
865
893
  }
866
894
  function printError(prefix, message, hint, cause) {
867
- const colors = paint(process7.stderr);
868
- const styled = takesControlCodes(process7.stderr);
895
+ const colors = paint(process9.stderr);
896
+ const styled = takesControlCodes(process9.stderr);
869
897
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
870
898
  const under = (label, text, tint) => text === undefined ? "" : `
871
899
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -908,11 +936,11 @@ async function dispatch(level, typed, { version, redact }) {
908
936
  }
909
937
  }
910
938
  if (name === undefined && level.path.length > 1) {
911
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process7.stderr));
939
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stderr));
912
940
  return 2;
913
941
  }
914
942
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
915
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process7.stdout));
943
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stdout));
916
944
  return 0;
917
945
  }
918
946
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1039,7 +1067,7 @@ function packageVersion(entry = Bun.main) {
1039
1067
  return "0.0.0";
1040
1068
  }
1041
1069
  }
1042
- async function runCli(cli, argv = process7.argv.slice(2)) {
1070
+ async function runCli(cli, argv = process9.argv.slice(2)) {
1043
1071
  const version = cli.version ?? packageVersion();
1044
1072
  if (argv[0] === COMPLETE)
1045
1073
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
@@ -1066,7 +1094,7 @@ function commandPath(scope, argv) {
1066
1094
  }
1067
1095
  return path.length === 0 ? undefined : path.join(" ");
1068
1096
  }
1069
- async function runMain({ name, version, run, redact, usage }, argv = process7.argv.slice(2)) {
1097
+ async function runMain({ name, version, run, redact, usage }, argv = process9.argv.slice(2)) {
1070
1098
  if (argv[0] === COMPLETE)
1071
1099
  return printCandidates(leafCandidates(run, argv.slice(1)));
1072
1100
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1093,14 +1121,15 @@ var {Glob } = globalThis.Bun;
1093
1121
  var SESSION_FILES = new Glob("*.json");
1094
1122
  var ACCOUNT_DIRS = new Glob("*/sessions");
1095
1123
  // src/proof.ts
1096
- import process10 from "process";
1124
+ import process12 from "process";
1097
1125
 
1098
1126
  // src/worktree.ts
1099
1127
  import { cpSync, existsSync, lstatSync, mkdirSync as mkdirSync2, mkdtempSync, readdirSync, realpathSync as realpathSync2, rmSync, symlinkSync, unlinkSync } from "fs";
1100
1128
  import { tmpdir } from "os";
1101
1129
  import { basename, dirname as dirname3, isAbsolute as isAbsolute2, join as join3, relative, resolve, sep } from "path";
1102
- import process9 from "process";
1130
+ import process11 from "process";
1103
1131
  var WHITESPACE = /\s/;
1132
+ var ORIGIN_PREFIX = /^origin\//;
1104
1133
  var ENV_FILE = /^\.env(?:\..+)?$/;
1105
1134
  var DEPENDENCIES = new Set(["node_modules", "vendor", ".venv"]);
1106
1135
  var TRAILING_SLASH = /\/$/;
@@ -1130,11 +1159,16 @@ async function resolveRef(root, ref) {
1130
1159
  fail(`no commit ${ref} in this repository`);
1131
1160
  return stdoutOf(ran);
1132
1161
  }
1162
+ async function defaultRemoteRef(root) {
1163
+ const head = await git2(["symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD"], root);
1164
+ return head.code === 0 && stdoutOf(head) !== "" ? stdoutOf(head) : "origin/main";
1165
+ }
1133
1166
  async function defaultProofRef(root) {
1134
1167
  const branch = await git2(["symbolic-ref", "--quiet", "--short", "HEAD"], root);
1135
- if (branch.code !== 0 || stdoutOf(branch) === "main")
1168
+ const remote = await defaultRemoteRef(root);
1169
+ if (branch.code !== 0 || stdoutOf(branch) === remote.replace(ORIGIN_PREFIX, ""))
1136
1170
  return "HEAD";
1137
- const base = await git2(["merge-base", "HEAD", "origin/main"], root);
1171
+ const base = await git2(["merge-base", "HEAD", remote], root);
1138
1172
  const head = await git2(["rev-parse", "HEAD"], root);
1139
1173
  return base.code === 0 && stdoutOf(base) !== stdoutOf(head) ? stdoutOf(base) : "HEAD";
1140
1174
  }
@@ -1249,7 +1283,7 @@ async function sweepStale(root) {
1249
1283
  continue;
1250
1284
  const path = join3(tmpdir(), name);
1251
1285
  const stat = lstatSync(path, { throwIfNoEntry: false });
1252
- if (stat?.isDirectory() === true && stat.uid === process9.getuid?.() && Date.now() - stat.mtimeMs > STALE_AFTER)
1286
+ if (stat?.isDirectory() === true && stat.uid === process11.getuid?.() && Date.now() - stat.mtimeMs > STALE_AFTER)
1253
1287
  rmSync(path, { recursive: true, force: true });
1254
1288
  }
1255
1289
  await git2(["worktree", "prune"], root);
@@ -1322,10 +1356,10 @@ async function inWorktree(options, body) {
1322
1356
  // src/proof.ts
1323
1357
  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
1358
 
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.`;
1359
+ 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
1360
  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
1361
  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)" },
1362
+ 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
1363
  runs: { type: "string", short: "n", description: "run the command this many times now, every run must pass (1)" },
1330
1364
  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
1365
  "no-link": { type: "boolean", description: "do not link the ignored env files, node_modules, vendor and .venv of the checkout" },
@@ -1369,7 +1403,7 @@ ${USAGE}`);
1369
1403
  if (runsInContainer(given))
1370
1404
  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
1405
  const command = shellCommand(given);
1372
- const cwd = process10.cwd();
1406
+ const cwd = process12.cwd();
1373
1407
  const { root, prefix } = await checkout(cwd);
1374
1408
  const runs = wholeNumber(parsed.values.runs, "runs", 1, 1);
1375
1409
  const ref = parsed.values.ref ?? await defaultProofRef(root);
@@ -1415,4 +1449,4 @@ ${folded(shown.output)}`);
1415
1449
  }
1416
1450
 
1417
1451
  // src/proof-cli.ts
1418
- process11.exitCode = await runMain({ name: "proof", run: proof });
1452
+ process13.exitCode = await runMain({ name: "proof", run: proof });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-base",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.7.0",
5
5
  "description": "base: a command run at HEAD or another ref in a temporary worktree, the working tree left untouched.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -38,6 +38,6 @@
38
38
  "proof": "$npm_execpath src/proof-cli.ts"
39
39
  },
40
40
  "devDependencies": {
41
- "@kaynooo/cli-kit": "0.21.1"
41
+ "@kaynooo/cli-kit": "0.24.0"
42
42
  }
43
43
  }