@kaynooo/cli-wait 0.6.1 → 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 +339 -100
  2. package/dist/slot-cli.js +335 -96
  3. package/package.json +3 -2
package/dist/cli.js CHANGED
@@ -2,17 +2,35 @@
2
2
  // @bun
3
3
 
4
4
  // src/cli.ts
5
- import { existsSync as existsSync3 } from "fs";
6
- import process14 from "process";
5
+ import { existsSync as existsSync5 } from "fs";
6
+ import process18 from "process";
7
7
  // ../kit/src/args.ts
8
- import process5 from "process";
8
+ import process9 from "process";
9
9
  import { parseArgs } from "util";
10
10
 
11
11
  // ../kit/src/format.ts
12
- import process3 from "process";
12
+ import process7 from "process";
13
13
 
14
- // ../kit/src/style.ts
14
+ // ../kit/src/mode.ts
15
15
  import process2 from "process";
16
+ var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
17
+ var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
18
+ function isSet(value) {
19
+ return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
20
+ }
21
+ function outputMode(stream = process2.stdout, env = process2.env) {
22
+ const chosen = env.KIT_MODE;
23
+ if (chosen !== undefined && MODES.has(chosen))
24
+ return chosen;
25
+ if (AGENT_VARIABLES.some((name) => isSet(env[name])))
26
+ return "agent";
27
+ if (stream.isTTY === true)
28
+ return "terminal";
29
+ return isSet(env.CI) ? "ci" : "pipe";
30
+ }
31
+
32
+ // ../kit/src/style.ts
33
+ import process6 from "process";
16
34
 
17
35
  // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
18
36
  function x(s) {
@@ -275,21 +293,235 @@ function le(i = {}) {
275
293
  }
276
294
  var t = le();
277
295
 
296
+ // ../kit/src/theme.ts
297
+ import { existsSync as existsSync2, readFileSync, statSync } from "fs";
298
+ import { homedir as homedir2 } from "os";
299
+ import { join as join3, resolve as resolve2 } from "path";
300
+ import process5 from "process";
301
+
302
+ // ../kit/src/config.ts
303
+ import { existsSync } from "fs";
304
+ import { dirname, join, resolve } from "path";
305
+ import process3 from "process";
306
+ function findUp(names, from = process3.cwd(), stop = () => false) {
307
+ const wanted = typeof names === "string" ? [names] : names;
308
+ for (let dir = resolve(from);; dir = dirname(dir)) {
309
+ const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
310
+ if (found !== undefined)
311
+ return found;
312
+ if (stop(dir) || dirname(dir) === dir)
313
+ return;
314
+ }
315
+ }
316
+
317
+ // ../kit/src/user-config.ts
318
+ import { homedir } from "os";
319
+ import { join as join2 } from "path";
320
+ import process4 from "process";
321
+ function configBase(where = {}) {
322
+ const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
323
+ return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
324
+ }
325
+ function userConfigPath(bin, where = {}) {
326
+ return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
327
+ }
328
+
329
+ // ../kit/src/theme.ts
330
+ var DEFAULT = {
331
+ 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" },
332
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
333
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
334
+ bins: {}
335
+ };
336
+ 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" };
337
+ 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" };
338
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
339
+ var PRESETS = {
340
+ default: {},
341
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
342
+ mono: { colors: MONO, accents: ["bold"] },
343
+ ascii: { glyphs: ASCII }
344
+ };
345
+ 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"]);
346
+ var HEX = /^#[0-9a-f]{6}$/i;
347
+ var CONTROL = /\p{Cc}/u;
348
+ var MAX_FILE_BYTES = 64 * 1024;
349
+ var SPACES = /\s+/;
350
+ function isColorSpec(spec) {
351
+ if (typeof spec === "number")
352
+ return Number.isInteger(spec) && spec >= 0 && spec <= 255;
353
+ return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
354
+ }
355
+ var CUBE = [0, 95, 135, 175, 215, 255];
356
+ function cubeLevel(channel) {
357
+ return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
358
+ }
359
+ function nearest256(hex) {
360
+ const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
361
+ const levels = rgb.map(cubeLevel);
362
+ const cube = levels.map((level) => CUBE[level]);
363
+ const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
364
+ const greyValue = 8 + grey * 10;
365
+ const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
366
+ return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
367
+ }
368
+ function hasTrueColor(env) {
369
+ return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
370
+ }
371
+ function tinted(colors, spec, env = process5.env) {
372
+ if (typeof spec === "number")
373
+ return colors.ansi256(spec);
374
+ return spec.trim().split(SPACES).reduce((chain, token) => {
375
+ if (HEX.test(token))
376
+ return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
377
+ return chain[token] ?? chain;
378
+ }, colors);
379
+ }
380
+ function isRecord(value) {
381
+ return typeof value === "object" && value !== null && !Array.isArray(value);
382
+ }
383
+ function readThemeFile(path, warn) {
384
+ try {
385
+ const stat = statSync(path, { throwIfNoEntry: false });
386
+ if (stat === undefined)
387
+ return;
388
+ if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
389
+ warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
390
+ return;
391
+ }
392
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
393
+ if (isRecord(parsed))
394
+ return parsed;
395
+ warn(`${path} is not a JSON object, theme ignored`);
396
+ } catch (error) {
397
+ warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
398
+ }
399
+ return;
400
+ }
401
+ function applyPreset(theme, name, warn, where) {
402
+ if (name === undefined)
403
+ return;
404
+ if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
405
+ warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
406
+ return;
407
+ }
408
+ const preset = PRESETS[name];
409
+ Object.assign(theme.colors, preset.colors);
410
+ Object.assign(theme.glyphs, preset.glyphs);
411
+ if (preset.accents !== undefined)
412
+ theme.accents = [...preset.accents];
413
+ return name;
414
+ }
415
+ function applyFile(theme, file, where, warn) {
416
+ if (isRecord(file.colors)) {
417
+ for (const [key, value] of Object.entries(file.colors)) {
418
+ if (!Object.hasOwn(DEFAULT.colors, key))
419
+ warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
420
+ else if (!isColorSpec(value))
421
+ warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
422
+ else
423
+ theme.colors[key] = value;
424
+ }
425
+ }
426
+ if (isRecord(file.glyphs)) {
427
+ for (const [key, value] of Object.entries(file.glyphs)) {
428
+ if (!Object.hasOwn(DEFAULT.glyphs, key))
429
+ warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
430
+ else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
431
+ warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
432
+ else
433
+ theme.glyphs[key] = value;
434
+ }
435
+ }
436
+ if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
437
+ theme.accents = [...file.accents];
438
+ else if (file.accents !== undefined)
439
+ warn(`${where}: accents must be a non-empty list of colours`);
440
+ if (isRecord(file.bins)) {
441
+ for (const [bin, value] of Object.entries(file.bins)) {
442
+ if (isColorSpec(value))
443
+ theme.bins[bin] = value;
444
+ else
445
+ warn(`${where}: bin ${bin} has no valid colour`);
446
+ }
447
+ }
448
+ }
449
+ function endsWalk(home) {
450
+ return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
451
+ }
452
+ var warned = new Set;
453
+ function warnOnce(message) {
454
+ if (warned.has(message))
455
+ return;
456
+ warned.add(message);
457
+ console.error(`warning: theme ${message}`);
458
+ }
459
+ function isPath(chosen) {
460
+ return chosen.includes("/") || chosen.endsWith(".json");
461
+ }
462
+ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
463
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
464
+ const sources = [];
465
+ const chosen = env.KIT_THEME ?? "";
466
+ const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
467
+ if (isPath(chosen))
468
+ wanted.push(resolve2(from, chosen));
469
+ const files = [];
470
+ for (const path of wanted) {
471
+ const file = path === undefined ? undefined : readThemeFile(path, warn);
472
+ if (path !== undefined && file !== undefined)
473
+ files.push({ path, file });
474
+ }
475
+ let preset = "default";
476
+ if (chosen !== "" && !isPath(chosen)) {
477
+ preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
478
+ } else {
479
+ const named = files.findLast(({ file }) => file.preset !== undefined);
480
+ if (named !== undefined)
481
+ preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
482
+ }
483
+ for (const { path, file } of files) {
484
+ applyFile(theme, file, path, warn);
485
+ sources.push(path);
486
+ }
487
+ return { theme, sources, preset };
488
+ }
489
+ var current;
490
+ var currentKey = "";
491
+ function activeTheme() {
492
+ const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
493
+ if (current === undefined || key !== currentKey) {
494
+ current = loadTheme();
495
+ currentKey = key;
496
+ }
497
+ return current;
498
+ }
499
+
278
500
  // ../kit/src/style.ts
279
- function takesControlCodes(stream, env = process2.env) {
280
- return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
501
+ function takesControlCodes(stream, env = process6.env) {
502
+ return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
281
503
  }
282
- function paint(stream, env = process2.env) {
504
+ function paint(stream, env = process6.env) {
283
505
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
284
506
  }
285
- var STATUSES = {
286
- passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
287
- failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
288
- running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
289
- queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
290
- skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
507
+ var STATUS_WORDS = {
508
+ passed: ["passed", "success", "succeeded", "ok"],
509
+ failed: ["failed", "failure", "error", "errored"],
510
+ running: ["running", "in_progress", "started", "holding"],
511
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
512
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
291
513
  };
292
- var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
514
+ var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
515
+ function statusOf(word) {
516
+ return STATUS_OF.get(word.toLowerCase());
517
+ }
518
+ function badge(word, stream, env = process6.env) {
519
+ const status = statusOf(word);
520
+ if (status === undefined || !takesControlCodes(stream, env))
521
+ return word;
522
+ const { theme } = activeTheme();
523
+ return tinted(paint(stream, env), theme.colors[status], env)(`${theme.glyphs[status]} ${word}`);
524
+ }
293
525
 
294
526
  // ../kit/src/format.ts
295
527
  var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
@@ -331,15 +563,18 @@ var ESCAPE = String.fromCharCode(27);
331
563
  function textWidth(text) {
332
564
  return Bun.stringWidth(text);
333
565
  }
334
- function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
566
+ function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
335
567
  const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
568
+ if (outputMode(stream, env) === "agent")
569
+ return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
570
+ `);
336
571
  const widths = [];
337
572
  for (const row of cells) {
338
573
  for (const [index, cell] of row.entries())
339
574
  widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
340
575
  }
341
576
  const shown = fit === undefined ? cells : narrow(cells, widths, fit);
342
- const colors = paint(process3.stdout);
577
+ const colors = paint(stream);
343
578
  const lines = shown.map((row) => row.map((cell, index) => {
344
579
  const width = widths[index] ?? 0;
345
580
  const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
@@ -347,7 +582,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
347
582
  return `${gap}${cell}`;
348
583
  return index === row.length - 1 ? cell : `${cell}${gap}`;
349
584
  }).join(" ").trimEnd());
350
- return lines.map((line, index) => header && index === 0 ? colors.bold(line) : line).join(`
585
+ const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
586
+ return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
351
587
  `);
352
588
  }
353
589
  function narrow(rows, widths, limit) {
@@ -366,32 +602,35 @@ function narrow(rows, widths, limit) {
366
602
  }
367
603
  return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
368
604
  }
605
+ function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
606
+ return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
607
+ }
369
608
  function printJson(value) {
370
- console.log(JSON.stringify(value, undefined, 2));
609
+ console.log(jsonText(value));
371
610
  }
372
611
 
373
612
  // ../kit/src/help.ts
374
- import process4 from "process";
613
+ import process8 from "process";
375
614
  var OPTIONAL = /\[[^\]]+\]/g;
376
615
  var USAGE_PREFIX = /^usage:\s*/i;
377
616
  var FULL_STOP = /\.$/;
378
- function usageLine(usage, colors = paint(process4.stdout)) {
617
+ function usageLine(usage, colors = paint(process8.stdout)) {
379
618
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
380
619
  }
381
- function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
620
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
382
621
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
383
622
  `);
384
623
  }
385
- function exitRows(exits, colors = paint(process4.stdout)) {
624
+ function exitRows(exits, colors = paint(process8.stdout)) {
386
625
  if (exits.length === 0)
387
626
  return [];
388
627
  const width = Math.max(...exits.map(([code]) => String(code).length));
389
628
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
390
629
  }
391
- function replacesRows(replaces, colors = paint(process4.stdout)) {
392
- return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
630
+ function replacesRows(replaces, colors = paint(process8.stdout)) {
631
+ return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
393
632
  }
394
- function wantsHelpJson(env = process4.env) {
633
+ function wantsHelpJson(env = process8.env) {
395
634
  return env.KIT_HELP === "json";
396
635
  }
397
636
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -410,12 +649,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
410
649
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
411
650
  };
412
651
  }
413
- function exampleRows(examples, colors = paint(process4.stdout)) {
414
- if (examples.length === 0)
652
+ function exampleRows(examples, colors = paint(process8.stdout)) {
653
+ if (examples.length === 0 || outputMode() === "agent")
415
654
  return [];
416
655
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
417
656
  }
418
- function optionRows(options, colors = paint(process4.stdout)) {
657
+ function optionRows(options, colors = paint(process8.stdout)) {
419
658
  const rows = Object.entries(options).map(([name, option]) => {
420
659
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
421
660
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -517,7 +756,7 @@ var OUTPUT_OPTIONS = {
517
756
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
518
757
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
519
758
  };
520
- function applyOutput(color, plain, env = process5.env) {
759
+ function applyOutput(color, plain, env = process9.env) {
521
760
  const when = plain === true ? "never" : color ?? "auto";
522
761
  if (when === "auto")
523
762
  return;
@@ -687,11 +926,11 @@ function nearestOption(message, options, allowNegative) {
687
926
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
688
927
  }
689
928
  // ../kit/src/progress.ts
690
- import process7 from "process";
929
+ import process11 from "process";
691
930
 
692
931
  // ../kit/src/process.ts
693
932
  import { constants } from "os";
694
- import process6 from "process";
933
+ import process10 from "process";
695
934
  var KILL_GRACE_MS = 2000;
696
935
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
697
936
  function exitCodeOf(code, signal) {
@@ -713,7 +952,7 @@ function holdSignals(cleanup) {
713
952
  },
714
953
  release: () => {
715
954
  for (const signal of SIGNALS)
716
- process6.off(signal, onSignal);
955
+ process10.off(signal, onSignal);
717
956
  }
718
957
  };
719
958
  function onSignal(signal) {
@@ -726,10 +965,10 @@ function holdSignals(cleanup) {
726
965
  return;
727
966
  held.release();
728
967
  cleanup(signal);
729
- process6.kill(process6.pid, signal);
968
+ process10.kill(process10.pid, signal);
730
969
  }
731
970
  for (const signal of SIGNALS)
732
- process6.on(signal, onSignal);
971
+ process10.on(signal, onSignal);
733
972
  return held;
734
973
  }
735
974
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -743,7 +982,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
743
982
  return;
744
983
  try {
745
984
  if (grouped)
746
- process6.kill(-proc.pid, killing);
985
+ process10.kill(-proc.pid, killing);
747
986
  else
748
987
  proc.kill(killing);
749
988
  } catch {}
@@ -822,7 +1061,7 @@ var RESET_STYLE = `${ESC}[0m`;
822
1061
  var CTRL_C = 3;
823
1062
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
824
1063
  var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
825
- function liveRegion(render, stream = process7.stderr, env = process7.env) {
1064
+ function liveRegion(render, stream = process11.stderr, env = process11.env) {
826
1065
  if (!takesControlCodes(stream, env))
827
1066
  return { redraw: () => {
828
1067
  return;
@@ -863,11 +1102,11 @@ function liveRegion(render, stream = process7.stderr, env = process7.env) {
863
1102
  clear();
864
1103
  restore();
865
1104
  release();
866
- process7.off("exit", onExit);
1105
+ process11.off("exit", onExit);
867
1106
  signals.release();
868
1107
  }
869
1108
  timer.unref();
870
- process7.on("exit", onExit);
1109
+ process11.on("exit", onExit);
871
1110
  return {
872
1111
  redraw: draw,
873
1112
  print: (text) => {
@@ -906,14 +1145,14 @@ function cutToWidth(line, width) {
906
1145
  return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
907
1146
  }
908
1147
  function swallowInput() {
909
- const input = process7.stdin;
1148
+ const input = process11.stdin;
910
1149
  if (!input.isTTY)
911
1150
  return () => {
912
1151
  return;
913
1152
  };
914
1153
  const onData = (data) => {
915
1154
  if (data.includes(CTRL_C))
916
- process7.kill(process7.pid, "SIGINT");
1155
+ process11.kill(process11.pid, "SIGINT");
917
1156
  };
918
1157
  input.setRawMode(true);
919
1158
  input.on("data", onData);
@@ -929,7 +1168,7 @@ function swallowInput() {
929
1168
  };
930
1169
  }
931
1170
  function interceptOutput(clear) {
932
- const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process7.stdout, "write"], [process7.stderr, "write"]];
1171
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process11.stdout, "write"], [process11.stderr, "write"]];
933
1172
  const wrapped = targets.map(([target, name]) => {
934
1173
  const original = Reflect.get(target, name);
935
1174
  const wrapper = (...args) => {
@@ -947,42 +1186,42 @@ function interceptOutput(clear) {
947
1186
  };
948
1187
  }
949
1188
  // ../kit/src/cli.ts
950
- import { readFileSync, realpathSync } from "fs";
951
- import { dirname as dirname2, join as join3 } from "path";
952
- import process10 from "process";
1189
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
1190
+ import { dirname as dirname3, join as join6 } from "path";
1191
+ import process14 from "process";
953
1192
 
954
1193
  // ../kit/src/usage.ts
955
1194
  import { appendFileSync, mkdirSync } from "fs";
956
- import { homedir as homedir2 } from "os";
957
- import { dirname, isAbsolute, join as join2 } from "path";
958
- import process9 from "process";
1195
+ import { homedir as homedir4 } from "os";
1196
+ import { dirname as dirname2, isAbsolute, join as join5 } from "path";
1197
+ import process13 from "process";
959
1198
 
960
1199
  // ../kit/src/logs.ts
961
1200
  import { lstatSync, openSync } from "fs";
962
1201
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
963
- import { homedir, tmpdir } from "os";
964
- import { join } from "path";
965
- import process8 from "process";
1202
+ import { homedir as homedir3, tmpdir } from "os";
1203
+ import { join as join4 } from "path";
1204
+ import process12 from "process";
966
1205
  var DAY_MS = 24 * 60 * 60 * 1000;
967
1206
  var CLI_FOLDER = "kaynooo-cli";
968
1207
  function isPrivateDirectory(path) {
969
1208
  try {
970
1209
  const info = lstatSync(path, { throwIfNoEntry: false });
971
- return info !== undefined && info.isDirectory() && info.uid === (process8.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1210
+ return info !== undefined && info.isDirectory() && info.uid === (process12.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
972
1211
  } catch {
973
1212
  return false;
974
1213
  }
975
1214
  }
976
- async function privateLogDirectory(name, env = process8.env) {
1215
+ async function privateLogDirectory(name, env = process12.env) {
977
1216
  const runtime = env.XDG_RUNTIME_DIR;
978
- const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
979
- const path = join(base, name);
1217
+ const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
1218
+ const path = join4(base, name);
980
1219
  try {
981
1220
  await mkdir(path, { recursive: true, mode: 448 });
982
1221
  if (isPrivateDirectory(path))
983
1222
  return path;
984
1223
  } catch {}
985
- return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
1224
+ return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
986
1225
  }
987
1226
 
988
1227
  // ../kit/src/usage.ts
@@ -993,14 +1232,14 @@ var usageError;
993
1232
  function noteUsageError(message) {
994
1233
  usageError = message;
995
1234
  }
996
- function stateHome(env = process9.env) {
1235
+ function stateHome(env = process13.env) {
997
1236
  const dir = env.XDG_STATE_HOME;
998
- return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
1237
+ return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
999
1238
  }
1000
- function usagePath(env = process9.env) {
1001
- return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
1239
+ function usagePath(env = process13.env) {
1240
+ return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1002
1241
  }
1003
- function usageRecorded(env = process9.env) {
1242
+ function usageRecorded(env = process13.env) {
1004
1243
  const off = env.KAYNOOO_CLI_NO_USAGE;
1005
1244
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1006
1245
  }
@@ -1014,12 +1253,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1014
1253
  usageError = undefined;
1015
1254
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1016
1255
  }
1017
- function recordUsage(entry, env = process9.env) {
1256
+ function recordUsage(entry, env = process13.env) {
1018
1257
  if (!usageRecorded(env))
1019
1258
  return;
1020
1259
  try {
1021
1260
  const path = usagePath(env);
1022
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
1261
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
1023
1262
  appendFileSync(path, `${JSON.stringify(entry)}
1024
1263
  `, { mode: 384 });
1025
1264
  } catch {}
@@ -1032,8 +1271,8 @@ var LEVEL_OPTIONS = {
1032
1271
  };
1033
1272
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1034
1273
  function printError(prefix, message, hint, cause) {
1035
- const colors = paint(process10.stderr);
1036
- const styled = takesControlCodes(process10.stderr);
1274
+ const colors = paint(process14.stderr);
1275
+ const styled = takesControlCodes(process14.stderr);
1037
1276
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1038
1277
  const under = (label, text, tint) => text === undefined ? "" : `
1039
1278
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1052,7 +1291,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
1052
1291
  const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
1053
1292
  const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
1054
1293
  const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
1055
- if (error instanceof UsageError)
1294
+ if (error instanceof Exit && error.code === 2)
1056
1295
  noteUsageError(error.message);
1057
1296
  const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
1058
1297
  report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
@@ -1116,17 +1355,17 @@ async function printCandidates(found) {
1116
1355
  return 0;
1117
1356
  }
1118
1357
  function packageVersion(entry = Bun.main) {
1119
- for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
1358
+ for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1120
1359
  try {
1121
- const { version } = JSON.parse(readFileSync(join3(dir, "package.json"), "utf8"));
1360
+ const { version } = JSON.parse(readFileSync2(join6(dir, "package.json"), "utf8"));
1122
1361
  if (typeof version === "string")
1123
1362
  return version;
1124
1363
  } catch {}
1125
- if (dirname2(dir) === dir)
1364
+ if (dirname3(dir) === dir)
1126
1365
  return "0.0.0";
1127
1366
  }
1128
1367
  }
1129
- async function runMain({ name, version, run, redact, usage }, argv = process10.argv.slice(2)) {
1368
+ async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
1130
1369
  if (argv[0] === COMPLETE)
1131
1370
  return printCandidates(leafCandidates(run, argv.slice(1)));
1132
1371
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1149,19 +1388,19 @@ async function runMain({ name, version, run, redact, usage }, argv = process10.a
1149
1388
  // ../kit/src/secrets.ts
1150
1389
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1151
1390
  // ../kit/src/sessions.ts
1152
- import { homedir as homedir3 } from "os";
1153
- import { join as join4 } from "path";
1154
- import process11 from "process";
1391
+ import { homedir as homedir5 } from "os";
1392
+ import { join as join7 } from "path";
1393
+ import process15 from "process";
1155
1394
  var {Glob } = globalThis.Bun;
1156
1395
  var SESSION_FILES = new Glob("*.json");
1157
1396
  var ACCOUNT_DIRS = new Glob("*/sessions");
1158
1397
  async function sessionDirs() {
1159
- const home = homedir3();
1160
- const dirs = new Set([join4(home, ".claude", "sessions")]);
1161
- if (process11.env.CLAUDE_CONFIG_DIR !== undefined)
1162
- dirs.add(join4(process11.env.CLAUDE_CONFIG_DIR, "sessions"));
1398
+ const home = homedir5();
1399
+ const dirs = new Set([join7(home, ".claude", "sessions")]);
1400
+ if (process15.env.CLAUDE_CONFIG_DIR !== undefined)
1401
+ dirs.add(join7(process15.env.CLAUDE_CONFIG_DIR, "sessions"));
1163
1402
  try {
1164
- for await (const dir of ACCOUNT_DIRS.scan({ cwd: join4(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1403
+ for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1165
1404
  dirs.add(dir);
1166
1405
  } catch {}
1167
1406
  return [...dirs];
@@ -1205,7 +1444,7 @@ async function liveSessions() {
1205
1444
  }
1206
1445
  async function currentSession(sessions) {
1207
1446
  const byPid = new Map(sessions.map((session) => [session.pid, session]));
1208
- let pid = process11.ppid;
1447
+ let pid = process15.ppid;
1209
1448
  for (let depth = 0;depth < 32 && pid > 1; depth++) {
1210
1449
  const session = byPid.get(pid);
1211
1450
  if (session !== undefined)
@@ -1218,7 +1457,7 @@ async function currentSession(sessions) {
1218
1457
  return;
1219
1458
  }
1220
1459
  // src/conditions.ts
1221
- import { existsSync, statSync } from "fs";
1460
+ import { existsSync as existsSync3, statSync as statSync2 } from "fs";
1222
1461
  var TAIL = 20;
1223
1462
  var AROUND = 5;
1224
1463
  var CARRIAGE_RETURN = /\r$/;
@@ -1250,7 +1489,7 @@ class FileWatch {
1250
1489
  return this.failure !== undefined;
1251
1490
  }
1252
1491
  get exists() {
1253
- return existsSync(this.path);
1492
+ return existsSync3(this.path);
1254
1493
  }
1255
1494
  async poll() {
1256
1495
  const events = [];
@@ -1284,9 +1523,9 @@ class FileWatch {
1284
1523
  return this.recent;
1285
1524
  }
1286
1525
  async nextLines() {
1287
- if (!existsSync(this.path))
1526
+ if (!existsSync3(this.path))
1288
1527
  return;
1289
- const { size, dev, ino } = statSync(this.path);
1528
+ const { size, dev, ino } = statSync2(this.path);
1290
1529
  const replaced = this.identity !== undefined && (this.identity.dev !== dev || this.identity.ino !== ino);
1291
1530
  this.identity = { dev, ino };
1292
1531
  if (size < this.offset || replaced) {
@@ -1342,9 +1581,9 @@ async function urlCheck(url, timeout) {
1342
1581
  }
1343
1582
 
1344
1583
  // src/task.ts
1345
- import { existsSync as existsSync2, lstatSync as lstatSync2, readFileSync as readFileSync2, statSync as statSync2 } from "fs";
1346
- import { join as join5 } from "path";
1347
- import process13 from "process";
1584
+ import { existsSync as existsSync4, lstatSync as lstatSync2, readFileSync as readFileSync3, statSync as statSync3 } from "fs";
1585
+ import { join as join8 } from "path";
1586
+ import process17 from "process";
1348
1587
  var EXITED = /(?:^|\n)\[exited with code (-?\d+)\]\n*$/;
1349
1588
  var FAILURE = /\(fail\)|\berror:/i;
1350
1589
  var TASK_ID = /^[\w-]+$/;
@@ -1352,29 +1591,29 @@ var TAIL_BYTES = 256;
1352
1591
  var LONGEST_FAILURES = 30;
1353
1592
  var CARRIAGE_RETURN2 = /\r$/;
1354
1593
  function tasksRoot(env) {
1355
- return join5(env.CLAUDE_CODE_TMPDIR ?? env.TMPDIR ?? "/tmp", `claude-${process13.getuid?.() ?? 0}`);
1594
+ return join8(env.CLAUDE_CODE_TMPDIR ?? env.TMPDIR ?? "/tmp", `claude-${process17.getuid?.() ?? 0}`);
1356
1595
  }
1357
- function taskFile(task, env = process13.env) {
1596
+ function taskFile(task, env = process17.env) {
1358
1597
  if (task.includes("/") || task.endsWith(".output"))
1359
1598
  return task;
1360
1599
  if (!TASK_ID.test(task))
1361
1600
  return;
1362
1601
  const root = tasksRoot(env);
1363
- const found = existsSync2(root) ? [...new Bun.Glob(`*/*/tasks/${task}.output`).scanSync({ cwd: root, onlyFiles: false })] : [];
1364
- return found.length === 0 ? undefined : join5(root, found[0] ?? "");
1602
+ const found = existsSync4(root) ? [...new Bun.Glob(`*/*/tasks/${task}.output`).scanSync({ cwd: root, onlyFiles: false })] : [];
1603
+ return found.length === 0 ? undefined : join8(root, found[0] ?? "");
1365
1604
  }
1366
1605
  function isTranscript(path) {
1367
- return existsSync2(path) && lstatSync2(path).isSymbolicLink() && path.endsWith(".output");
1606
+ return existsSync4(path) && lstatSync2(path).isSymbolicLink() && path.endsWith(".output");
1368
1607
  }
1369
1608
  async function exitCode(path) {
1370
- if (!existsSync2(path))
1609
+ if (!existsSync4(path))
1371
1610
  return;
1372
- const size = statSync2(path).size;
1611
+ const size = statSync3(path).size;
1373
1612
  const found = EXITED.exec(await Bun.file(path).slice(Math.max(0, size - TAIL_BYTES), size).text());
1374
1613
  return found === null ? undefined : Number(found[1]);
1375
1614
  }
1376
1615
  async function taskEnd(path, lines) {
1377
- if (!existsSync2(path))
1616
+ if (!existsSync4(path))
1378
1617
  return { failures: [], tail: [] };
1379
1618
  const text = (await Bun.file(path).text()).replace(EXITED, "");
1380
1619
  const all = text.split(`
@@ -1387,7 +1626,7 @@ async function taskEnd(path, lines) {
1387
1626
  }
1388
1627
  function pidAlive(pid) {
1389
1628
  try {
1390
- process13.kill(pid, 0);
1629
+ process17.kill(pid, 0);
1391
1630
  } catch (error) {
1392
1631
  return error.code === "EPERM";
1393
1632
  }
@@ -1395,7 +1634,7 @@ function pidAlive(pid) {
1395
1634
  }
1396
1635
  function isZombie(pid) {
1397
1636
  try {
1398
- const stat = readFileSync2(`/proc/${pid}/stat`, "utf8");
1637
+ const stat = readFileSync3(`/proc/${pid}/stat`, "utf8");
1399
1638
  return stat.slice(stat.lastIndexOf(")") + 2, stat.lastIndexOf(")") + 3) === "Z";
1400
1639
  } catch {
1401
1640
  return false;
@@ -1471,14 +1710,14 @@ async function waitTask(args) {
1471
1710
  const path = taskFile(task);
1472
1711
  if (path === undefined)
1473
1712
  fail(`no background task ${task}: give the id a background Bash call returned, or the path of its .output file`);
1474
- if (!existsSync3(path))
1713
+ if (!existsSync5(path))
1475
1714
  fail(`no output file ${path}: ${task} is no background task of this machine`);
1476
1715
  if (isTranscript(path))
1477
1716
  fail(`${task} is a subagent, whose end its notification reports: waitfor task waits on a background Bash task`);
1478
1717
  const lines = wholeNumber(values.lines, "lines", 20);
1479
1718
  const timeout = duration(values.timeout, "timeout", 5 * 60000);
1480
1719
  const started = Date.now();
1481
- const { dim } = paint(process14.stderr);
1720
+ const { dim } = paint(process18.stderr);
1482
1721
  const region = values.quiet === true ? undefined : liveRegion((spinner) => [`${spinner} task ${task}: still running ${dim(formatElapsed(Date.now() - started))}`]);
1483
1722
  let code;
1484
1723
  try {
@@ -1549,7 +1788,7 @@ ${USAGE}`);
1549
1788
  let isPidLeft = pid !== undefined;
1550
1789
  let cmdLeft = values.cmd === undefined ? undefined : "not run yet";
1551
1790
  let cmdRanAt = 0;
1552
- const { dim } = paint(process14.stderr);
1791
+ const { dim } = paint(process18.stderr);
1553
1792
  const region = values.quiet === true ? undefined : liveRegion((spinner) => {
1554
1793
  const waited = dim(formatElapsed(Date.now() - started));
1555
1794
  const left = [
@@ -1640,4 +1879,4 @@ ${numbered(event.excerpt, event.line)}`);
1640
1879
  last lines of ${watch?.path}:
1641
1880
  ${numbered(lines)}`}`);
1642
1881
  }
1643
- process14.exitCode = await runMain({ name: "waitfor", run: main });
1882
+ process18.exitCode = await runMain({ name: "waitfor", run: main });