@kaynooo/cli-wait 0.7.0 → 0.9.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 +351 -107
  2. package/dist/slot-cli.js +348 -104
  3. package/package.json +2 -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", rule: "\u2500", corner: "\u256D" },
332
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
333
+ bins: {}
334
+ };
335
+ var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
336
+ var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
337
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
338
+ var PRESETS = {
339
+ default: {},
340
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
341
+ mono: { colors: MONO, accents: ["bold"] },
342
+ ascii: { glyphs: ASCII }
343
+ };
344
+ var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
345
+ var HEX = /^#[0-9a-f]{6}$/i;
346
+ var CONTROL = /\p{Cc}/u;
347
+ var MAX_FILE_BYTES = 64 * 1024;
348
+ var SPACES = /\s+/;
349
+ function isColorSpec(spec) {
350
+ if (typeof spec === "number")
351
+ return Number.isInteger(spec) && spec >= 0 && spec <= 255;
352
+ return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
353
+ }
354
+ var CUBE = [0, 95, 135, 175, 215, 255];
355
+ function cubeLevel(channel) {
356
+ return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
357
+ }
358
+ function nearest256(hex) {
359
+ const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
360
+ const levels = rgb.map(cubeLevel);
361
+ const cube = levels.map((level) => CUBE[level]);
362
+ const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
363
+ const greyValue = 8 + grey * 10;
364
+ const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
365
+ return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
366
+ }
367
+ function hasTrueColor(env) {
368
+ return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
369
+ }
370
+ function tinted(colors, spec, env = process5.env) {
371
+ if (typeof spec === "number")
372
+ return colors.ansi256(spec);
373
+ return spec.trim().split(SPACES).reduce((chain, token) => {
374
+ if (HEX.test(token))
375
+ return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
376
+ return chain[token] ?? chain;
377
+ }, colors);
378
+ }
379
+ function isRecord(value) {
380
+ return typeof value === "object" && value !== null && !Array.isArray(value);
381
+ }
382
+ function readThemeFile(path, warn) {
383
+ try {
384
+ const stat = statSync(path, { throwIfNoEntry: false });
385
+ if (stat === undefined)
386
+ return;
387
+ if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
388
+ warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
389
+ return;
390
+ }
391
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
392
+ if (isRecord(parsed))
393
+ return parsed;
394
+ warn(`${path} is not a JSON object, theme ignored`);
395
+ } catch (error) {
396
+ warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
397
+ }
398
+ return;
399
+ }
400
+ function applyPreset(theme, name, warn, where) {
401
+ if (name === undefined)
402
+ return;
403
+ if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
404
+ warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
405
+ return;
406
+ }
407
+ const preset = PRESETS[name];
408
+ Object.assign(theme.colors, preset.colors);
409
+ Object.assign(theme.glyphs, preset.glyphs);
410
+ if (preset.accents !== undefined)
411
+ theme.accents = [...preset.accents];
412
+ return name;
413
+ }
414
+ function applyFile(theme, file, where, warn) {
415
+ if (isRecord(file.colors)) {
416
+ for (const [key, value] of Object.entries(file.colors)) {
417
+ if (!Object.hasOwn(DEFAULT.colors, key))
418
+ warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
419
+ else if (!isColorSpec(value))
420
+ warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
421
+ else
422
+ theme.colors[key] = value;
423
+ }
424
+ }
425
+ if (isRecord(file.glyphs)) {
426
+ for (const [key, value] of Object.entries(file.glyphs)) {
427
+ if (!Object.hasOwn(DEFAULT.glyphs, key))
428
+ warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
429
+ else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
430
+ warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
431
+ else
432
+ theme.glyphs[key] = value;
433
+ }
434
+ }
435
+ if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
436
+ theme.accents = [...file.accents];
437
+ else if (file.accents !== undefined)
438
+ warn(`${where}: accents must be a non-empty list of colours`);
439
+ if (isRecord(file.bins)) {
440
+ for (const [bin, value] of Object.entries(file.bins)) {
441
+ if (isColorSpec(value))
442
+ theme.bins[bin] = value;
443
+ else
444
+ warn(`${where}: bin ${bin} has no valid colour`);
445
+ }
446
+ }
447
+ }
448
+ function endsWalk(home) {
449
+ return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
450
+ }
451
+ var warned = new Set;
452
+ function warnOnce(message) {
453
+ if (warned.has(message))
454
+ return;
455
+ warned.add(message);
456
+ console.error(`warning: theme ${message}`);
457
+ }
458
+ function isPath(chosen) {
459
+ return chosen.includes("/") || chosen.endsWith(".json");
460
+ }
461
+ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
462
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
463
+ const sources = [];
464
+ const chosen = env.KIT_THEME ?? "";
465
+ const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
466
+ if (isPath(chosen))
467
+ wanted.push(resolve2(from, chosen));
468
+ const files = [];
469
+ for (const path of wanted) {
470
+ const file = path === undefined ? undefined : readThemeFile(path, warn);
471
+ if (path !== undefined && file !== undefined)
472
+ files.push({ path, file });
473
+ }
474
+ let preset = "default";
475
+ if (chosen !== "" && !isPath(chosen)) {
476
+ preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
477
+ } else {
478
+ const named = files.findLast(({ file }) => file.preset !== undefined);
479
+ if (named !== undefined)
480
+ preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
481
+ }
482
+ for (const { path, file } of files) {
483
+ applyFile(theme, file, path, warn);
484
+ sources.push(path);
485
+ }
486
+ return { theme, sources, preset };
487
+ }
488
+ var current;
489
+ var currentKey = "";
490
+ function activeTheme() {
491
+ const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
492
+ if (current === undefined || key !== currentKey) {
493
+ current = loadTheme();
494
+ currentKey = key;
495
+ }
496
+ return current;
497
+ }
498
+
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("|")}>`;
@@ -472,7 +711,6 @@ var DASHES = /^-+/;
472
711
  function jsonOption(holds) {
473
712
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
474
713
  }
475
-
476
714
  class Exit extends Error {
477
715
  code;
478
716
  hint;
@@ -516,7 +754,7 @@ var OUTPUT_OPTIONS = {
516
754
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
517
755
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
518
756
  };
519
- function applyOutput(color, plain, env = process5.env) {
757
+ function applyOutput(color, plain, env = process9.env) {
520
758
  const when = plain === true ? "never" : color ?? "auto";
521
759
  if (when === "auto")
522
760
  return;
@@ -686,11 +924,11 @@ function nearestOption(message, options, allowNegative) {
686
924
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
687
925
  }
688
926
  // ../kit/src/progress.ts
689
- import process7 from "process";
927
+ import process11 from "process";
690
928
 
691
929
  // ../kit/src/process.ts
692
930
  import { constants } from "os";
693
- import process6 from "process";
931
+ import process10 from "process";
694
932
  var KILL_GRACE_MS = 2000;
695
933
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
696
934
  function exitCodeOf(code, signal) {
@@ -712,7 +950,7 @@ function holdSignals(cleanup) {
712
950
  },
713
951
  release: () => {
714
952
  for (const signal of SIGNALS)
715
- process6.off(signal, onSignal);
953
+ process10.off(signal, onSignal);
716
954
  }
717
955
  };
718
956
  function onSignal(signal) {
@@ -725,10 +963,10 @@ function holdSignals(cleanup) {
725
963
  return;
726
964
  held.release();
727
965
  cleanup(signal);
728
- process6.kill(process6.pid, signal);
966
+ process10.kill(process10.pid, signal);
729
967
  }
730
968
  for (const signal of SIGNALS)
731
- process6.on(signal, onSignal);
969
+ process10.on(signal, onSignal);
732
970
  return held;
733
971
  }
734
972
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -742,7 +980,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
742
980
  return;
743
981
  try {
744
982
  if (grouped)
745
- process6.kill(-proc.pid, killing);
983
+ process10.kill(-proc.pid, killing);
746
984
  else
747
985
  proc.kill(killing);
748
986
  } catch {}
@@ -821,7 +1059,7 @@ var RESET_STYLE = `${ESC}[0m`;
821
1059
  var CTRL_C = 3;
822
1060
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
823
1061
  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) {
1062
+ function liveRegion(render, stream = process11.stderr, env = process11.env) {
825
1063
  if (!takesControlCodes(stream, env))
826
1064
  return { redraw: () => {
827
1065
  return;
@@ -831,25 +1069,28 @@ function liveRegion(render, stream = process7.stderr, env = process7.env) {
831
1069
  } };
832
1070
  const write = stream.write.bind(stream);
833
1071
  let frame = 0;
834
- let drawn = 0;
1072
+ let drawn = [];
1073
+ const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
1074
+ const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
835
1075
  const clear = () => {
836
- if (drawn > 0)
837
- write(`${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}`);
838
- drawn = 0;
1076
+ if (drawn.length > 0)
1077
+ write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
1078
+ drawn = [];
839
1079
  };
840
1080
  const draw = () => {
841
- const width = (stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns) - 1;
1081
+ const width = columns() - 1;
842
1082
  const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
843
1083
  const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
844
1084
  if (lines.length === 0) {
845
1085
  clear();
846
1086
  return;
847
1087
  }
848
- write(`${drawn > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}` : CLEAR_LINE}${lines.join(`
1088
+ write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
849
1089
  `)}`);
850
- drawn = lines.length;
1090
+ drawn = lines.map((line) => Bun.stringWidth(line));
851
1091
  };
852
1092
  const timer = setInterval(draw, FRAME_MS);
1093
+ stream.on?.("resize", draw);
853
1094
  const restore = interceptOutput(clear);
854
1095
  const release = swallowInput();
855
1096
  const onExit = () => {
@@ -859,14 +1100,15 @@ function liveRegion(render, stream = process7.stderr, env = process7.env) {
859
1100
  const signals = holdSignals(stop);
860
1101
  function stop() {
861
1102
  clearInterval(timer);
1103
+ stream.off?.("resize", draw);
862
1104
  clear();
863
1105
  restore();
864
1106
  release();
865
- process7.off("exit", onExit);
1107
+ process11.off("exit", onExit);
866
1108
  signals.release();
867
1109
  }
868
1110
  timer.unref();
869
- process7.on("exit", onExit);
1111
+ process11.on("exit", onExit);
870
1112
  return {
871
1113
  redraw: draw,
872
1114
  print: (text) => {
@@ -905,14 +1147,14 @@ function cutToWidth(line, width) {
905
1147
  return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
906
1148
  }
907
1149
  function swallowInput() {
908
- const input = process7.stdin;
1150
+ const input = process11.stdin;
909
1151
  if (!input.isTTY)
910
1152
  return () => {
911
1153
  return;
912
1154
  };
913
1155
  const onData = (data) => {
914
1156
  if (data.includes(CTRL_C))
915
- process7.kill(process7.pid, "SIGINT");
1157
+ process11.kill(process11.pid, "SIGINT");
916
1158
  };
917
1159
  input.setRawMode(true);
918
1160
  input.on("data", onData);
@@ -928,7 +1170,7 @@ function swallowInput() {
928
1170
  };
929
1171
  }
930
1172
  function interceptOutput(clear) {
931
- const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process7.stdout, "write"], [process7.stderr, "write"]];
1173
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process11.stdout, "write"], [process11.stderr, "write"]];
932
1174
  const wrapped = targets.map(([target, name]) => {
933
1175
  const original = Reflect.get(target, name);
934
1176
  const wrapper = (...args) => {
@@ -946,42 +1188,42 @@ function interceptOutput(clear) {
946
1188
  };
947
1189
  }
948
1190
  // ../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";
1191
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
1192
+ import { dirname as dirname3, join as join6 } from "path";
1193
+ import process14 from "process";
952
1194
 
953
1195
  // ../kit/src/usage.ts
954
1196
  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";
1197
+ import { homedir as homedir4 } from "os";
1198
+ import { dirname as dirname2, isAbsolute, join as join5 } from "path";
1199
+ import process13 from "process";
958
1200
 
959
1201
  // ../kit/src/logs.ts
960
1202
  import { lstatSync, openSync } from "fs";
961
1203
  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";
1204
+ import { homedir as homedir3, tmpdir } from "os";
1205
+ import { join as join4 } from "path";
1206
+ import process12 from "process";
965
1207
  var DAY_MS = 24 * 60 * 60 * 1000;
966
1208
  var CLI_FOLDER = "kaynooo-cli";
967
1209
  function isPrivateDirectory(path) {
968
1210
  try {
969
1211
  const info = lstatSync(path, { throwIfNoEntry: false });
970
- return info !== undefined && info.isDirectory() && info.uid === (process8.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1212
+ return info !== undefined && info.isDirectory() && info.uid === (process12.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
971
1213
  } catch {
972
1214
  return false;
973
1215
  }
974
1216
  }
975
- async function privateLogDirectory(name, env = process8.env) {
1217
+ async function privateLogDirectory(name, env = process12.env) {
976
1218
  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);
1219
+ const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
1220
+ const path = join4(base, name);
979
1221
  try {
980
1222
  await mkdir(path, { recursive: true, mode: 448 });
981
1223
  if (isPrivateDirectory(path))
982
1224
  return path;
983
1225
  } catch {}
984
- return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
1226
+ return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
985
1227
  }
986
1228
 
987
1229
  // ../kit/src/usage.ts
@@ -992,14 +1234,14 @@ var usageError;
992
1234
  function noteUsageError(message) {
993
1235
  usageError = message;
994
1236
  }
995
- function stateHome(env = process9.env) {
1237
+ function stateHome(env = process13.env) {
996
1238
  const dir = env.XDG_STATE_HOME;
997
- return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
1239
+ return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
998
1240
  }
999
- function usagePath(env = process9.env) {
1000
- return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
1241
+ function usagePath(env = process13.env) {
1242
+ return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1001
1243
  }
1002
- function usageRecorded(env = process9.env) {
1244
+ function usageRecorded(env = process13.env) {
1003
1245
  const off = env.KAYNOOO_CLI_NO_USAGE;
1004
1246
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1005
1247
  }
@@ -1013,12 +1255,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1013
1255
  usageError = undefined;
1014
1256
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1015
1257
  }
1016
- function recordUsage(entry, env = process9.env) {
1258
+ function recordUsage(entry, env = process13.env) {
1017
1259
  if (!usageRecorded(env))
1018
1260
  return;
1019
1261
  try {
1020
1262
  const path = usagePath(env);
1021
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
1263
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
1022
1264
  appendFileSync(path, `${JSON.stringify(entry)}
1023
1265
  `, { mode: 384 });
1024
1266
  } catch {}
@@ -1031,8 +1273,8 @@ var LEVEL_OPTIONS = {
1031
1273
  };
1032
1274
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1033
1275
  function printError(prefix, message, hint, cause) {
1034
- const colors = paint(process10.stderr);
1035
- const styled = takesControlCodes(process10.stderr);
1276
+ const colors = paint(process14.stderr);
1277
+ const styled = takesControlCodes(process14.stderr);
1036
1278
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1037
1279
  const under = (label, text, tint) => text === undefined ? "" : `
1038
1280
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1115,17 +1357,17 @@ async function printCandidates(found) {
1115
1357
  return 0;
1116
1358
  }
1117
1359
  function packageVersion(entry = Bun.main) {
1118
- for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
1360
+ for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1119
1361
  try {
1120
- const { version } = JSON.parse(readFileSync(join3(dir, "package.json"), "utf8"));
1362
+ const { version } = JSON.parse(readFileSync2(join6(dir, "package.json"), "utf8"));
1121
1363
  if (typeof version === "string")
1122
1364
  return version;
1123
1365
  } catch {}
1124
- if (dirname2(dir) === dir)
1366
+ if (dirname3(dir) === dir)
1125
1367
  return "0.0.0";
1126
1368
  }
1127
1369
  }
1128
- async function runMain({ name, version, run, redact, usage }, argv = process10.argv.slice(2)) {
1370
+ async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
1129
1371
  if (argv[0] === COMPLETE)
1130
1372
  return printCandidates(leafCandidates(run, argv.slice(1)));
1131
1373
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1145,22 +1387,24 @@ async function runMain({ name, version, run, redact, usage }, argv = process10.a
1145
1387
  }
1146
1388
  return code;
1147
1389
  }
1390
+ // ../kit/src/folders.ts
1391
+ var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1148
1392
  // ../kit/src/secrets.ts
1149
1393
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1150
1394
  // ../kit/src/sessions.ts
1151
- import { homedir as homedir3 } from "os";
1152
- import { join as join4 } from "path";
1153
- import process11 from "process";
1395
+ import { homedir as homedir5 } from "os";
1396
+ import { join as join7 } from "path";
1397
+ import process15 from "process";
1154
1398
  var {Glob } = globalThis.Bun;
1155
1399
  var SESSION_FILES = new Glob("*.json");
1156
1400
  var ACCOUNT_DIRS = new Glob("*/sessions");
1157
1401
  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"));
1402
+ const home = homedir5();
1403
+ const dirs = new Set([join7(home, ".claude", "sessions")]);
1404
+ if (process15.env.CLAUDE_CONFIG_DIR !== undefined)
1405
+ dirs.add(join7(process15.env.CLAUDE_CONFIG_DIR, "sessions"));
1162
1406
  try {
1163
- for await (const dir of ACCOUNT_DIRS.scan({ cwd: join4(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1407
+ for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1164
1408
  dirs.add(dir);
1165
1409
  } catch {}
1166
1410
  return [...dirs];
@@ -1204,7 +1448,7 @@ async function liveSessions() {
1204
1448
  }
1205
1449
  async function currentSession(sessions) {
1206
1450
  const byPid = new Map(sessions.map((session) => [session.pid, session]));
1207
- let pid = process11.ppid;
1451
+ let pid = process15.ppid;
1208
1452
  for (let depth = 0;depth < 32 && pid > 1; depth++) {
1209
1453
  const session = byPid.get(pid);
1210
1454
  if (session !== undefined)
@@ -1217,20 +1461,20 @@ async function currentSession(sessions) {
1217
1461
  return;
1218
1462
  }
1219
1463
  // src/slot.ts
1220
- import { existsSync, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync2, rmSync } from "fs";
1464
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync3, rmSync } from "fs";
1221
1465
  import { availableParallelism } from "os";
1222
- import { join as join5 } from "path";
1223
- import process14 from "process";
1466
+ import { join as join8 } from "path";
1467
+ import process18 from "process";
1224
1468
 
1225
1469
  // src/flock.ts
1226
1470
  import { closeSync, constants as constants2, ftruncateSync, openSync as openSync2, writeSync } from "fs";
1227
- import process13 from "process";
1471
+ import process17 from "process";
1228
1472
  import { dlopen, FFIType } from "bun:ffi";
1229
1473
  var LOCK_EX = 2;
1230
1474
  var LOCK_NB = 4;
1231
1475
  var flock;
1232
1476
  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;
1477
+ flock ??= dlopen(process17.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", { flock: { args: [FFIType.i32, FFIType.i32], returns: FFIType.i32 } }).symbols.flock;
1234
1478
  return flock;
1235
1479
  }
1236
1480
  function tryLock(path) {
@@ -1274,21 +1518,21 @@ function defaultSlots() {
1274
1518
  return Math.max(1, Math.floor(availableParallelism() / 2));
1275
1519
  }
1276
1520
  async function stateDir() {
1277
- const dir = process14.env.SLOT_DIR ?? await privateLogDirectory("slot");
1521
+ const dir = process18.env.SLOT_DIR ?? await privateLogDirectory("slot");
1278
1522
  for (const sub of ["slots", "locks", "waiters"])
1279
- mkdirSync2(join5(dir, sub), { recursive: true, mode: 448 });
1523
+ mkdirSync2(join8(dir, sub), { recursive: true, mode: 448 });
1280
1524
  return dir;
1281
1525
  }
1282
1526
  function readHolder(path) {
1283
1527
  try {
1284
- const holder = JSON.parse(readFileSync2(path, "utf8"));
1528
+ const holder = JSON.parse(readFileSync3(path, "utf8"));
1285
1529
  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
1530
  } catch {
1287
1531
  return;
1288
1532
  }
1289
1533
  }
1290
1534
  function pathOf(dir, kind, name) {
1291
- return join5(dir, kind === "slot" ? "slots" : "locks", name);
1535
+ return join8(dir, kind === "slot" ? "slots" : "locks", name);
1292
1536
  }
1293
1537
  function candidates(dir, { kind, name, count }) {
1294
1538
  if (kind === "lock")
@@ -1316,7 +1560,7 @@ function waitingLine(dir, wanted) {
1316
1560
  }
1317
1561
  async function holderOf(command) {
1318
1562
  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 } };
1563
+ return { pid: process18.pid, command: command.join(" "), cwd: process18.cwd(), since: Date.now(), ...session === undefined ? {} : { session: session.name } };
1320
1564
  }
1321
1565
  var waiterCount = 0;
1322
1566
  async function acquire(dir, resources, holder, deadline, timeoutMs) {
@@ -1342,7 +1586,7 @@ async function acquire(dir, resources, holder, deadline, timeoutMs) {
1342
1586
  held.release();
1343
1587
  const resource = busy.kind === "lock" ? `lock ${busy.name}` : "slot";
1344
1588
  if (waiter === undefined) {
1345
- const path = join5(dir, "waiters", `${process14.pid}-${waiterCount++}`);
1589
+ const path = join8(dir, "waiters", `${process18.pid}-${waiterCount++}`);
1346
1590
  const held = tryLock(path);
1347
1591
  if (held !== undefined) {
1348
1592
  writeHeld(held, JSON.stringify({ ...holder, resource }));
@@ -1383,7 +1627,7 @@ ${RUN_USAGE}`);
1383
1627
  const count = wholeNumber(values.slots, "slots", defaultSlots());
1384
1628
  const timeoutMs = duration(values.timeout, "timeout", Number.POSITIVE_INFINITY);
1385
1629
  const deadline = Date.now() + timeoutMs;
1386
- const holding = new Set((process14.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1630
+ const holding = new Set((process18.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1387
1631
  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
1632
  const signals = holdSignals(() => {
1389
1633
  return;
@@ -1398,7 +1642,7 @@ ${RUN_USAGE}`);
1398
1642
  const tokens = new Set([...holding, ...locks.map((name) => `lock:${name}`), ...wanted.some((resource) => resource.kind === "slot") ? ["slot"] : []]);
1399
1643
  let child;
1400
1644
  try {
1401
- child = Bun.spawn(rest, { stdio: ["inherit", "inherit", "inherit"], env: { ...process14.env, [HOLDING]: [...tokens].join(",") } });
1645
+ child = Bun.spawn(rest, { stdio: ["inherit", "inherit", "inherit"], env: { ...process18.env, [HOLDING]: [...tokens].join(",") } });
1402
1646
  } catch (error) {
1403
1647
  fail(`cannot run ${rest[0]}: ${error instanceof Error ? error.message : String(error)}`, 127);
1404
1648
  }
@@ -1412,10 +1656,10 @@ ${RUN_USAGE}`);
1412
1656
  }
1413
1657
  }
1414
1658
  function scan(dir, state, kind) {
1415
- const folder = join5(dir, kind);
1659
+ const folder = join8(dir, kind);
1416
1660
  const entries = [];
1417
- for (const name of existsSync(folder) ? readdirSync(folder) : []) {
1418
- const path = join5(folder, name);
1661
+ for (const name of existsSync3(folder) ? readdirSync(folder) : []) {
1662
+ const path = join8(folder, name);
1419
1663
  const probe = tryLock(path);
1420
1664
  if (probe !== undefined) {
1421
1665
  if (kind === "waiters")
@@ -1441,11 +1685,11 @@ async function listSlots(args) {
1441
1685
  printJson({ slots: count, busy, entries });
1442
1686
  return 0;
1443
1687
  }
1444
- console.log(`slots: ${busy} of ${count} busy`);
1688
+ console.log(paint(process18.stdout).bold(`slots: ${busy} of ${count} busy`));
1445
1689
  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)])));
1690
+ 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
1691
  return 0;
1448
1692
  }
1449
1693
 
1450
1694
  // src/slot-cli.ts
1451
- process15.exitCode = await runMain({ name: "slot", run: async (args) => args[0] === "ls" ? listSlots(args.slice(1)) : runSlotted(args) });
1695
+ process19.exitCode = await runMain({ name: "slot", run: async (args) => args[0] === "ls" ? listSlots(args.slice(1)) : runSlotted(args) });