@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/slot-cli.js CHANGED
@@ -2,16 +2,34 @@
2
2
  // @bun
3
3
 
4
4
  // src/slot-cli.ts
5
- import process15 from "process";
5
+ import process19 from "process";
6
6
  // ../kit/src/args.ts
7
- import process5 from "process";
7
+ import process9 from "process";
8
8
  import { parseArgs } from "util";
9
9
 
10
10
  // ../kit/src/format.ts
11
- import process3 from "process";
11
+ import process7 from "process";
12
12
 
13
- // ../kit/src/style.ts
13
+ // ../kit/src/mode.ts
14
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";
15
33
 
16
34
  // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
17
35
  function x(s) {
@@ -274,21 +292,235 @@ function le(i = {}) {
274
292
  }
275
293
  var t = le();
276
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" },
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: "#" };
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
+
277
499
  // ../kit/src/style.ts
278
- function takesControlCodes(stream, env = process2.env) {
279
- 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";
280
502
  }
281
- function paint(stream, env = process2.env) {
503
+ function paint(stream, env = process6.env) {
282
504
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
283
505
  }
284
- var STATUSES = {
285
- passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
286
- failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
287
- running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
288
- queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
289
- skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
506
+ var STATUS_WORDS = {
507
+ passed: ["passed", "success", "succeeded", "ok"],
508
+ failed: ["failed", "failure", "error", "errored"],
509
+ running: ["running", "in_progress", "started", "holding"],
510
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
511
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
290
512
  };
291
- var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
513
+ var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
514
+ function statusOf(word) {
515
+ return STATUS_OF.get(word.toLowerCase());
516
+ }
517
+ function badge(word, stream, env = process6.env) {
518
+ const status = statusOf(word);
519
+ if (status === undefined || !takesControlCodes(stream, env))
520
+ return word;
521
+ const { theme } = activeTheme();
522
+ return tinted(paint(stream, env), theme.colors[status], env)(`${theme.glyphs[status]} ${word}`);
523
+ }
292
524
 
293
525
  // ../kit/src/format.ts
294
526
  var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
@@ -330,15 +562,18 @@ var ESCAPE = String.fromCharCode(27);
330
562
  function textWidth(text) {
331
563
  return Bun.stringWidth(text);
332
564
  }
333
- function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
565
+ function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
334
566
  const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
567
+ if (outputMode(stream, env) === "agent")
568
+ return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
569
+ `);
335
570
  const widths = [];
336
571
  for (const row of cells) {
337
572
  for (const [index, cell] of row.entries())
338
573
  widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
339
574
  }
340
575
  const shown = fit === undefined ? cells : narrow(cells, widths, fit);
341
- const colors = paint(process3.stdout);
576
+ const colors = paint(stream);
342
577
  const lines = shown.map((row) => row.map((cell, index) => {
343
578
  const width = widths[index] ?? 0;
344
579
  const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
@@ -346,7 +581,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
346
581
  return `${gap}${cell}`;
347
582
  return index === row.length - 1 ? cell : `${cell}${gap}`;
348
583
  }).join(" ").trimEnd());
349
- return lines.map((line, index) => header && index === 0 ? colors.bold(line) : line).join(`
584
+ const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
585
+ return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
350
586
  `);
351
587
  }
352
588
  function narrow(rows, widths, limit) {
@@ -365,32 +601,35 @@ function narrow(rows, widths, limit) {
365
601
  }
366
602
  return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
367
603
  }
604
+ function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
605
+ return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
606
+ }
368
607
  function printJson(value) {
369
- console.log(JSON.stringify(value, undefined, 2));
608
+ console.log(jsonText(value));
370
609
  }
371
610
 
372
611
  // ../kit/src/help.ts
373
- import process4 from "process";
612
+ import process8 from "process";
374
613
  var OPTIONAL = /\[[^\]]+\]/g;
375
614
  var USAGE_PREFIX = /^usage:\s*/i;
376
615
  var FULL_STOP = /\.$/;
377
- function usageLine(usage, colors = paint(process4.stdout)) {
616
+ function usageLine(usage, colors = paint(process8.stdout)) {
378
617
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
379
618
  }
380
- function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
619
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
381
620
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
382
621
  `);
383
622
  }
384
- function exitRows(exits, colors = paint(process4.stdout)) {
623
+ function exitRows(exits, colors = paint(process8.stdout)) {
385
624
  if (exits.length === 0)
386
625
  return [];
387
626
  const width = Math.max(...exits.map(([code]) => String(code).length));
388
627
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
389
628
  }
390
- function replacesRows(replaces, colors = paint(process4.stdout)) {
391
- return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
629
+ function replacesRows(replaces, colors = paint(process8.stdout)) {
630
+ return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
392
631
  }
393
- function wantsHelpJson(env = process4.env) {
632
+ function wantsHelpJson(env = process8.env) {
394
633
  return env.KIT_HELP === "json";
395
634
  }
396
635
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -409,12 +648,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
409
648
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
410
649
  };
411
650
  }
412
- function exampleRows(examples, colors = paint(process4.stdout)) {
413
- if (examples.length === 0)
651
+ function exampleRows(examples, colors = paint(process8.stdout)) {
652
+ if (examples.length === 0 || outputMode() === "agent")
414
653
  return [];
415
654
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
416
655
  }
417
- function optionRows(options, colors = paint(process4.stdout)) {
656
+ function optionRows(options, colors = paint(process8.stdout)) {
418
657
  const rows = Object.entries(options).map(([name, option]) => {
419
658
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
420
659
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -516,7 +755,7 @@ var OUTPUT_OPTIONS = {
516
755
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
517
756
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
518
757
  };
519
- function applyOutput(color, plain, env = process5.env) {
758
+ function applyOutput(color, plain, env = process9.env) {
520
759
  const when = plain === true ? "never" : color ?? "auto";
521
760
  if (when === "auto")
522
761
  return;
@@ -686,11 +925,11 @@ function nearestOption(message, options, allowNegative) {
686
925
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
687
926
  }
688
927
  // ../kit/src/progress.ts
689
- import process7 from "process";
928
+ import process11 from "process";
690
929
 
691
930
  // ../kit/src/process.ts
692
931
  import { constants } from "os";
693
- import process6 from "process";
932
+ import process10 from "process";
694
933
  var KILL_GRACE_MS = 2000;
695
934
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
696
935
  function exitCodeOf(code, signal) {
@@ -712,7 +951,7 @@ function holdSignals(cleanup) {
712
951
  },
713
952
  release: () => {
714
953
  for (const signal of SIGNALS)
715
- process6.off(signal, onSignal);
954
+ process10.off(signal, onSignal);
716
955
  }
717
956
  };
718
957
  function onSignal(signal) {
@@ -725,10 +964,10 @@ function holdSignals(cleanup) {
725
964
  return;
726
965
  held.release();
727
966
  cleanup(signal);
728
- process6.kill(process6.pid, signal);
967
+ process10.kill(process10.pid, signal);
729
968
  }
730
969
  for (const signal of SIGNALS)
731
- process6.on(signal, onSignal);
970
+ process10.on(signal, onSignal);
732
971
  return held;
733
972
  }
734
973
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -742,7 +981,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
742
981
  return;
743
982
  try {
744
983
  if (grouped)
745
- process6.kill(-proc.pid, killing);
984
+ process10.kill(-proc.pid, killing);
746
985
  else
747
986
  proc.kill(killing);
748
987
  } catch {}
@@ -821,7 +1060,7 @@ var RESET_STYLE = `${ESC}[0m`;
821
1060
  var CTRL_C = 3;
822
1061
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
823
1062
  var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
824
- function liveRegion(render, stream = process7.stderr, env = process7.env) {
1063
+ function liveRegion(render, stream = process11.stderr, env = process11.env) {
825
1064
  if (!takesControlCodes(stream, env))
826
1065
  return { redraw: () => {
827
1066
  return;
@@ -862,11 +1101,11 @@ function liveRegion(render, stream = process7.stderr, env = process7.env) {
862
1101
  clear();
863
1102
  restore();
864
1103
  release();
865
- process7.off("exit", onExit);
1104
+ process11.off("exit", onExit);
866
1105
  signals.release();
867
1106
  }
868
1107
  timer.unref();
869
- process7.on("exit", onExit);
1108
+ process11.on("exit", onExit);
870
1109
  return {
871
1110
  redraw: draw,
872
1111
  print: (text) => {
@@ -905,14 +1144,14 @@ function cutToWidth(line, width) {
905
1144
  return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
906
1145
  }
907
1146
  function swallowInput() {
908
- const input = process7.stdin;
1147
+ const input = process11.stdin;
909
1148
  if (!input.isTTY)
910
1149
  return () => {
911
1150
  return;
912
1151
  };
913
1152
  const onData = (data) => {
914
1153
  if (data.includes(CTRL_C))
915
- process7.kill(process7.pid, "SIGINT");
1154
+ process11.kill(process11.pid, "SIGINT");
916
1155
  };
917
1156
  input.setRawMode(true);
918
1157
  input.on("data", onData);
@@ -928,7 +1167,7 @@ function swallowInput() {
928
1167
  };
929
1168
  }
930
1169
  function interceptOutput(clear) {
931
- const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process7.stdout, "write"], [process7.stderr, "write"]];
1170
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process11.stdout, "write"], [process11.stderr, "write"]];
932
1171
  const wrapped = targets.map(([target, name]) => {
933
1172
  const original = Reflect.get(target, name);
934
1173
  const wrapper = (...args) => {
@@ -946,42 +1185,42 @@ function interceptOutput(clear) {
946
1185
  };
947
1186
  }
948
1187
  // ../kit/src/cli.ts
949
- import { readFileSync, realpathSync } from "fs";
950
- import { dirname as dirname2, join as join3 } from "path";
951
- import process10 from "process";
1188
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
1189
+ import { dirname as dirname3, join as join6 } from "path";
1190
+ import process14 from "process";
952
1191
 
953
1192
  // ../kit/src/usage.ts
954
1193
  import { appendFileSync, mkdirSync } from "fs";
955
- import { homedir as homedir2 } from "os";
956
- import { dirname, isAbsolute, join as join2 } from "path";
957
- import process9 from "process";
1194
+ import { homedir as homedir4 } from "os";
1195
+ import { dirname as dirname2, isAbsolute, join as join5 } from "path";
1196
+ import process13 from "process";
958
1197
 
959
1198
  // ../kit/src/logs.ts
960
1199
  import { lstatSync, openSync } from "fs";
961
1200
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
962
- import { homedir, tmpdir } from "os";
963
- import { join } from "path";
964
- import process8 from "process";
1201
+ import { homedir as homedir3, tmpdir } from "os";
1202
+ import { join as join4 } from "path";
1203
+ import process12 from "process";
965
1204
  var DAY_MS = 24 * 60 * 60 * 1000;
966
1205
  var CLI_FOLDER = "kaynooo-cli";
967
1206
  function isPrivateDirectory(path) {
968
1207
  try {
969
1208
  const info = lstatSync(path, { throwIfNoEntry: false });
970
- return info !== undefined && info.isDirectory() && info.uid === (process8.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1209
+ return info !== undefined && info.isDirectory() && info.uid === (process12.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
971
1210
  } catch {
972
1211
  return false;
973
1212
  }
974
1213
  }
975
- async function privateLogDirectory(name, env = process8.env) {
1214
+ async function privateLogDirectory(name, env = process12.env) {
976
1215
  const runtime = env.XDG_RUNTIME_DIR;
977
- const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
978
- const path = join(base, name);
1216
+ const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
1217
+ const path = join4(base, name);
979
1218
  try {
980
1219
  await mkdir(path, { recursive: true, mode: 448 });
981
1220
  if (isPrivateDirectory(path))
982
1221
  return path;
983
1222
  } catch {}
984
- return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
1223
+ return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
985
1224
  }
986
1225
 
987
1226
  // ../kit/src/usage.ts
@@ -992,14 +1231,14 @@ var usageError;
992
1231
  function noteUsageError(message) {
993
1232
  usageError = message;
994
1233
  }
995
- function stateHome(env = process9.env) {
1234
+ function stateHome(env = process13.env) {
996
1235
  const dir = env.XDG_STATE_HOME;
997
- return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
1236
+ return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
998
1237
  }
999
- function usagePath(env = process9.env) {
1000
- return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
1238
+ function usagePath(env = process13.env) {
1239
+ return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1001
1240
  }
1002
- function usageRecorded(env = process9.env) {
1241
+ function usageRecorded(env = process13.env) {
1003
1242
  const off = env.KAYNOOO_CLI_NO_USAGE;
1004
1243
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1005
1244
  }
@@ -1013,12 +1252,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1013
1252
  usageError = undefined;
1014
1253
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1015
1254
  }
1016
- function recordUsage(entry, env = process9.env) {
1255
+ function recordUsage(entry, env = process13.env) {
1017
1256
  if (!usageRecorded(env))
1018
1257
  return;
1019
1258
  try {
1020
1259
  const path = usagePath(env);
1021
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
1260
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
1022
1261
  appendFileSync(path, `${JSON.stringify(entry)}
1023
1262
  `, { mode: 384 });
1024
1263
  } catch {}
@@ -1031,8 +1270,8 @@ var LEVEL_OPTIONS = {
1031
1270
  };
1032
1271
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1033
1272
  function printError(prefix, message, hint, cause) {
1034
- const colors = paint(process10.stderr);
1035
- const styled = takesControlCodes(process10.stderr);
1273
+ const colors = paint(process14.stderr);
1274
+ const styled = takesControlCodes(process14.stderr);
1036
1275
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1037
1276
  const under = (label, text, tint) => text === undefined ? "" : `
1038
1277
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1051,7 +1290,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
1051
1290
  const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
1052
1291
  const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
1053
1292
  const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
1054
- if (error instanceof UsageError)
1293
+ if (error instanceof Exit && error.code === 2)
1055
1294
  noteUsageError(error.message);
1056
1295
  const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
1057
1296
  report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
@@ -1115,17 +1354,17 @@ async function printCandidates(found) {
1115
1354
  return 0;
1116
1355
  }
1117
1356
  function packageVersion(entry = Bun.main) {
1118
- for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
1357
+ for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1119
1358
  try {
1120
- const { version } = JSON.parse(readFileSync(join3(dir, "package.json"), "utf8"));
1359
+ const { version } = JSON.parse(readFileSync2(join6(dir, "package.json"), "utf8"));
1121
1360
  if (typeof version === "string")
1122
1361
  return version;
1123
1362
  } catch {}
1124
- if (dirname2(dir) === dir)
1363
+ if (dirname3(dir) === dir)
1125
1364
  return "0.0.0";
1126
1365
  }
1127
1366
  }
1128
- async function runMain({ name, version, run, redact, usage }, argv = process10.argv.slice(2)) {
1367
+ async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
1129
1368
  if (argv[0] === COMPLETE)
1130
1369
  return printCandidates(leafCandidates(run, argv.slice(1)));
1131
1370
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1148,19 +1387,19 @@ async function runMain({ name, version, run, redact, usage }, argv = process10.a
1148
1387
  // ../kit/src/secrets.ts
1149
1388
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1150
1389
  // ../kit/src/sessions.ts
1151
- import { homedir as homedir3 } from "os";
1152
- import { join as join4 } from "path";
1153
- import process11 from "process";
1390
+ import { homedir as homedir5 } from "os";
1391
+ import { join as join7 } from "path";
1392
+ import process15 from "process";
1154
1393
  var {Glob } = globalThis.Bun;
1155
1394
  var SESSION_FILES = new Glob("*.json");
1156
1395
  var ACCOUNT_DIRS = new Glob("*/sessions");
1157
1396
  async function sessionDirs() {
1158
- const home = homedir3();
1159
- const dirs = new Set([join4(home, ".claude", "sessions")]);
1160
- if (process11.env.CLAUDE_CONFIG_DIR !== undefined)
1161
- dirs.add(join4(process11.env.CLAUDE_CONFIG_DIR, "sessions"));
1397
+ const home = homedir5();
1398
+ const dirs = new Set([join7(home, ".claude", "sessions")]);
1399
+ if (process15.env.CLAUDE_CONFIG_DIR !== undefined)
1400
+ dirs.add(join7(process15.env.CLAUDE_CONFIG_DIR, "sessions"));
1162
1401
  try {
1163
- for await (const dir of ACCOUNT_DIRS.scan({ cwd: join4(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1402
+ for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1164
1403
  dirs.add(dir);
1165
1404
  } catch {}
1166
1405
  return [...dirs];
@@ -1204,7 +1443,7 @@ async function liveSessions() {
1204
1443
  }
1205
1444
  async function currentSession(sessions) {
1206
1445
  const byPid = new Map(sessions.map((session) => [session.pid, session]));
1207
- let pid = process11.ppid;
1446
+ let pid = process15.ppid;
1208
1447
  for (let depth = 0;depth < 32 && pid > 1; depth++) {
1209
1448
  const session = byPid.get(pid);
1210
1449
  if (session !== undefined)
@@ -1217,20 +1456,20 @@ async function currentSession(sessions) {
1217
1456
  return;
1218
1457
  }
1219
1458
  // src/slot.ts
1220
- import { existsSync, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync2, rmSync } from "fs";
1459
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync3, rmSync } from "fs";
1221
1460
  import { availableParallelism } from "os";
1222
- import { join as join5 } from "path";
1223
- import process14 from "process";
1461
+ import { join as join8 } from "path";
1462
+ import process18 from "process";
1224
1463
 
1225
1464
  // src/flock.ts
1226
1465
  import { closeSync, constants as constants2, ftruncateSync, openSync as openSync2, writeSync } from "fs";
1227
- import process13 from "process";
1466
+ import process17 from "process";
1228
1467
  import { dlopen, FFIType } from "bun:ffi";
1229
1468
  var LOCK_EX = 2;
1230
1469
  var LOCK_NB = 4;
1231
1470
  var flock;
1232
1471
  function native() {
1233
- flock ??= dlopen(process13.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", { flock: { args: [FFIType.i32, FFIType.i32], returns: FFIType.i32 } }).symbols.flock;
1472
+ flock ??= dlopen(process17.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", { flock: { args: [FFIType.i32, FFIType.i32], returns: FFIType.i32 } }).symbols.flock;
1234
1473
  return flock;
1235
1474
  }
1236
1475
  function tryLock(path) {
@@ -1274,21 +1513,21 @@ function defaultSlots() {
1274
1513
  return Math.max(1, Math.floor(availableParallelism() / 2));
1275
1514
  }
1276
1515
  async function stateDir() {
1277
- const dir = process14.env.SLOT_DIR ?? await privateLogDirectory("slot");
1516
+ const dir = process18.env.SLOT_DIR ?? await privateLogDirectory("slot");
1278
1517
  for (const sub of ["slots", "locks", "waiters"])
1279
- mkdirSync2(join5(dir, sub), { recursive: true, mode: 448 });
1518
+ mkdirSync2(join8(dir, sub), { recursive: true, mode: 448 });
1280
1519
  return dir;
1281
1520
  }
1282
1521
  function readHolder(path) {
1283
1522
  try {
1284
- const holder = JSON.parse(readFileSync2(path, "utf8"));
1523
+ const holder = JSON.parse(readFileSync3(path, "utf8"));
1285
1524
  return typeof holder.pid === "number" && typeof holder.command === "string" ? { pid: holder.pid, command: holder.command, cwd: holder.cwd ?? "", since: holder.since ?? 0, ...holder.session === undefined ? {} : { session: holder.session }, ...holder.resource === undefined ? {} : { resource: holder.resource } } : undefined;
1286
1525
  } catch {
1287
1526
  return;
1288
1527
  }
1289
1528
  }
1290
1529
  function pathOf(dir, kind, name) {
1291
- return join5(dir, kind === "slot" ? "slots" : "locks", name);
1530
+ return join8(dir, kind === "slot" ? "slots" : "locks", name);
1292
1531
  }
1293
1532
  function candidates(dir, { kind, name, count }) {
1294
1533
  if (kind === "lock")
@@ -1316,7 +1555,7 @@ function waitingLine(dir, wanted) {
1316
1555
  }
1317
1556
  async function holderOf(command) {
1318
1557
  const session = await currentSession(await liveSessions());
1319
- return { pid: process14.pid, command: command.join(" "), cwd: process14.cwd(), since: Date.now(), ...session === undefined ? {} : { session: session.name } };
1558
+ return { pid: process18.pid, command: command.join(" "), cwd: process18.cwd(), since: Date.now(), ...session === undefined ? {} : { session: session.name } };
1320
1559
  }
1321
1560
  var waiterCount = 0;
1322
1561
  async function acquire(dir, resources, holder, deadline, timeoutMs) {
@@ -1342,7 +1581,7 @@ async function acquire(dir, resources, holder, deadline, timeoutMs) {
1342
1581
  held.release();
1343
1582
  const resource = busy.kind === "lock" ? `lock ${busy.name}` : "slot";
1344
1583
  if (waiter === undefined) {
1345
- const path = join5(dir, "waiters", `${process14.pid}-${waiterCount++}`);
1584
+ const path = join8(dir, "waiters", `${process18.pid}-${waiterCount++}`);
1346
1585
  const held = tryLock(path);
1347
1586
  if (held !== undefined) {
1348
1587
  writeHeld(held, JSON.stringify({ ...holder, resource }));
@@ -1383,7 +1622,7 @@ ${RUN_USAGE}`);
1383
1622
  const count = wholeNumber(values.slots, "slots", defaultSlots());
1384
1623
  const timeoutMs = duration(values.timeout, "timeout", Number.POSITIVE_INFINITY);
1385
1624
  const deadline = Date.now() + timeoutMs;
1386
- const holding = new Set((process14.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1625
+ const holding = new Set((process18.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1387
1626
  const wanted = [...locks.filter((name) => !holding.has(`lock:${name}`)).map((name) => ({ kind: "lock", name, count })), ...values["no-slot"] === true || holding.has("slot") ? [] : [{ kind: "slot", name: "", count }]];
1388
1627
  const signals = holdSignals(() => {
1389
1628
  return;
@@ -1398,7 +1637,7 @@ ${RUN_USAGE}`);
1398
1637
  const tokens = new Set([...holding, ...locks.map((name) => `lock:${name}`), ...wanted.some((resource) => resource.kind === "slot") ? ["slot"] : []]);
1399
1638
  let child;
1400
1639
  try {
1401
- child = Bun.spawn(rest, { stdio: ["inherit", "inherit", "inherit"], env: { ...process14.env, [HOLDING]: [...tokens].join(",") } });
1640
+ child = Bun.spawn(rest, { stdio: ["inherit", "inherit", "inherit"], env: { ...process18.env, [HOLDING]: [...tokens].join(",") } });
1402
1641
  } catch (error) {
1403
1642
  fail(`cannot run ${rest[0]}: ${error instanceof Error ? error.message : String(error)}`, 127);
1404
1643
  }
@@ -1412,10 +1651,10 @@ ${RUN_USAGE}`);
1412
1651
  }
1413
1652
  }
1414
1653
  function scan(dir, state, kind) {
1415
- const folder = join5(dir, kind);
1654
+ const folder = join8(dir, kind);
1416
1655
  const entries = [];
1417
- for (const name of existsSync(folder) ? readdirSync(folder) : []) {
1418
- const path = join5(folder, name);
1656
+ for (const name of existsSync3(folder) ? readdirSync(folder) : []) {
1657
+ const path = join8(folder, name);
1419
1658
  const probe = tryLock(path);
1420
1659
  if (probe !== undefined) {
1421
1660
  if (kind === "waiters")
@@ -1443,9 +1682,9 @@ async function listSlots(args) {
1443
1682
  }
1444
1683
  console.log(`slots: ${busy} of ${count} busy`);
1445
1684
  if (entries.length > 0)
1446
- console.log(table(entries.map((entry) => [entry.state, entry.resource, entry.session ?? `pid ${entry.pid}`, truncate(entry.command, COMMAND_WIDTH), entry.since === 0 ? "?" : formatAge(entry.since)])));
1685
+ console.log(table(entries.map((entry) => [badge(entry.state, process18.stdout), entry.resource, entry.session ?? `pid ${entry.pid}`, truncate(entry.command, COMMAND_WIDTH), entry.since === 0 ? "?" : formatAge(entry.since)])));
1447
1686
  return 0;
1448
1687
  }
1449
1688
 
1450
1689
  // src/slot-cli.ts
1451
- process15.exitCode = await runMain({ name: "slot", run: async (args) => args[0] === "ls" ? listSlots(args.slice(1)) : runSlotted(args) });
1690
+ process19.exitCode = await runMain({ name: "slot", run: async (args) => args[0] === "ls" ? listSlots(args.slice(1)) : runSlotted(args) });