@kaynooo/cli-wait 0.12.0 → 0.12.4

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 +524 -172
  2. package/dist/slot-cli.js +510 -172
  3. package/package.json +5 -5
package/dist/slot-cli.js CHANGED
@@ -1,20 +1,19 @@
1
1
  #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
2
  // @bun
3
+ var __esm = (fn, res, err) => () => {
4
+ if (fn)
5
+ try {
6
+ res = fn(fn = 0);
7
+ } catch (e) {
8
+ err = [e];
9
+ }
10
+ if (err)
11
+ throw err[0];
12
+ return res;
13
+ };
3
14
 
4
- // src/slot-cli.ts
5
- import process21 from "process";
6
- // ../kit/src/args.ts
7
- import process9 from "process";
8
- import { parseArgs } from "util";
9
-
10
- // ../kit/src/format.ts
11
- import process7 from "process";
12
-
13
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
14
- var N = new Map;
15
- var Nt = /\s+\S*$/;
16
- var Y = /\s/;
17
- function ko(t, e, r = "...") {
15
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
16
+ function Ao(t, e, r = "...") {
18
17
  let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
19
18
  if (t.length <= e)
20
19
  return t;
@@ -25,13 +24,22 @@ function ko(t, e, r = "...") {
25
24
  c = c.trimEnd();
26
25
  return s ? (c + n).slice(0, l) : c + n;
27
26
  }
28
- var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
29
- var z = new Map;
27
+ var N, Nt, Y, be, W;
28
+ var init_chunk_rkhsft4a = __esm(() => {
29
+ N = new Map;
30
+ Nt = /\s+\S*$/;
31
+ Y = /\s/;
32
+ be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
33
+ W = new Map;
34
+ });
35
+
36
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
37
+ var init_text = __esm(() => {
38
+ init_chunk_rkhsft4a();
39
+ });
30
40
 
31
41
  // ../kit/src/mode.ts
32
42
  import process2 from "process";
33
- var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
34
- var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
35
43
  function isSet(value) {
36
44
  return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
37
45
  }
@@ -45,12 +53,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
45
53
  return "terminal";
46
54
  return isSet(env.CI) ? "ci" : "pipe";
47
55
  }
56
+ var MODES, AGENT_VARIABLES;
57
+ var init_mode = __esm(() => {
58
+ MODES = new Set(["terminal", "ci", "agent", "pipe"]);
59
+ AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
60
+ });
48
61
 
49
- // ../kit/src/style.ts
50
- import process6 from "process";
51
-
52
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
53
- var G2 = /^[a-f0-9]+$/i;
62
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
54
63
  function b(r) {
55
64
  let e = r.startsWith("#") ? r.slice(1) : r;
56
65
  if (!G2.test(e))
@@ -61,11 +70,6 @@ function b(r) {
61
70
  throw Error(`Invalid hex color length: ${e.length}`);
62
71
  return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
63
72
  }
64
- var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
65
- let [l, n, c] = b(r);
66
- return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
67
- }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
68
- var h = new Set(["", "1", "2", "3", "true"]);
69
73
  function C(r, e = globalThis.process?.env ?? {}) {
70
74
  if (e.FORCE_COLOR !== undefined)
71
75
  return h.has(e.FORCE_COLOR);
@@ -79,7 +83,7 @@ function f(r, e = []) {
79
83
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
80
84
  let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
81
85
  return new Proxy(c, { get(t, i) {
82
- let a = B2[i];
86
+ let a = B[i];
83
87
  if (Array.isArray(a)) {
84
88
  let s = g.get(i);
85
89
  if (s === undefined)
@@ -102,13 +106,21 @@ function f(r, e = []) {
102
106
  function Fe(r = {}) {
103
107
  return f(r);
104
108
  }
105
- var o = Fe();
109
+ var G2, B, h, o;
110
+ var init_chunk_x450vn3m = __esm(() => {
111
+ G2 = /^[a-f0-9]+$/i;
112
+ B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
113
+ let [l, n, c] = b(r);
114
+ return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
115
+ }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
116
+ h = new Set(["", "1", "2", "3", "true"]);
117
+ o = Fe();
118
+ });
106
119
 
107
- // ../kit/src/theme.ts
108
- import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
109
- import { homedir as homedir2 } from "os";
110
- import { join as join3, resolve as resolve2 } from "path";
111
- import process5 from "process";
120
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
121
+ var init_colors = __esm(() => {
122
+ init_chunk_x450vn3m();
123
+ });
112
124
 
113
125
  // ../kit/src/config.ts
114
126
  import { existsSync } from "fs";
@@ -124,15 +136,21 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
124
136
  return;
125
137
  }
126
138
  }
139
+ var init_config = __esm(() => {
140
+ init_args();
141
+ });
127
142
 
128
143
  // ../kit/src/user-config.ts
129
144
  import { existsSync as existsSync2, readFileSync } from "fs";
130
145
  import { homedir } from "os";
131
- import { join as join2 } from "path";
146
+ import { isAbsolute, join as join2 } from "path";
132
147
  import process4 from "process";
148
+ function xdgFolder(value, fallback) {
149
+ return value !== undefined && isAbsolute(value) ? value : fallback;
150
+ }
133
151
  function configBase(where = {}) {
134
152
  const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
135
- return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
153
+ return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
136
154
  }
137
155
  function userConfigPath(bin, where = {}) {
138
156
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
@@ -159,36 +177,18 @@ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
159
177
  const value = readUserConfig(bin, where, legacy)[key];
160
178
  return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
161
179
  }
180
+ var init_user_config = () => {};
162
181
 
163
182
  // ../kit/src/theme.ts
164
- var ENDS = new Map;
165
- var DEFAULT = {
166
- colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
167
- glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
168
- accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
169
- bins: {},
170
- gradient: ["#c084fc", "#67e8f9"]
171
- };
172
- var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
173
- var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
174
- var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
175
- var PRESETS = {
176
- default: {},
177
- "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
178
- mono: { colors: MONO, accents: ["bold"], gradient: undefined },
179
- ascii: { glyphs: ASCII }
180
- };
181
- 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"]);
182
- var HEX = /^#[0-9a-f]{6}$/i;
183
- var CONTROL = /\p{Cc}/u;
184
- var MAX_FILE_BYTES = 64 * 1024;
185
- var SPACES = /\s+/;
183
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
184
+ import { homedir as homedir2 } from "os";
185
+ import { join as join3, resolve as resolve2 } from "path";
186
+ import process5 from "process";
186
187
  function isColorSpec(spec) {
187
188
  if (typeof spec === "number")
188
189
  return Number.isInteger(spec) && spec >= 0 && spec <= 255;
189
190
  return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
190
191
  }
191
- var CUBE = [0, 95, 135, 175, 215, 255];
192
192
  function cubeLevel(channel) {
193
193
  return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
194
194
  }
@@ -293,7 +293,6 @@ function applyFile(theme, file, where, warn) {
293
293
  function endsWalk(home) {
294
294
  return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
295
295
  }
296
- var warned = new Set;
297
296
  function warnOnce(message) {
298
297
  if (warned.has(message))
299
298
  return;
@@ -330,8 +329,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
330
329
  }
331
330
  return { theme, sources, preset };
332
331
  }
333
- var current;
334
- var currentKey = "";
335
332
  function activeTheme() {
336
333
  const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
337
334
  if (current === undefined || key !== currentKey) {
@@ -340,9 +337,38 @@ function activeTheme() {
340
337
  }
341
338
  return current;
342
339
  }
340
+ var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
341
+ var init_theme = __esm(() => {
342
+ init_config();
343
+ init_user_config();
344
+ ENDS = new Map;
345
+ DEFAULT = {
346
+ colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
347
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
348
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
349
+ bins: {},
350
+ gradient: ["#c084fc", "#67e8f9"]
351
+ };
352
+ BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
353
+ MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
354
+ ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
355
+ PRESETS = {
356
+ default: {},
357
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
358
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
359
+ ascii: { glyphs: ASCII }
360
+ };
361
+ 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"]);
362
+ HEX = /^#[0-9a-f]{6}$/i;
363
+ CONTROL = /\p{Cc}/u;
364
+ MAX_FILE_BYTES = 64 * 1024;
365
+ SPACES = /\s+/;
366
+ CUBE = [0, 95, 135, 175, 215, 255];
367
+ warned = new Set;
368
+ });
343
369
 
344
370
  // ../kit/src/style.ts
345
- var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
371
+ import process6 from "process";
346
372
  function takesControlCodes(stream, env = process6.env) {
347
373
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
348
374
  }
@@ -361,14 +387,6 @@ function marked(mark, text, stream, detail, env = process6.env) {
361
387
  function problem(text, detail) {
362
388
  console.error(marked("problem", text, process6.stderr, detail));
363
389
  }
364
- var STATUS_WORDS = {
365
- passed: ["passed", "success", "succeeded", "ok"],
366
- failed: ["failed", "failure", "error", "errored"],
367
- running: ["running", "in_progress", "started", "holding"],
368
- queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
369
- skipped: ["skipped", "cancelled", "canceled", "manual"]
370
- };
371
- var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
372
390
  function statusOf(word) {
373
391
  return STATUS_OF.get(word.toLowerCase());
374
392
  }
@@ -379,9 +397,24 @@ function badge(word, stream, env = process6.env) {
379
397
  const { theme } = activeTheme();
380
398
  return tinted(paint(stream, env), theme.colors[status], env)(`${theme.glyphs[status]} ${word}`);
381
399
  }
400
+ var MARK_WORDS, STATUS_WORDS, STATUS_OF;
401
+ var init_style = __esm(() => {
402
+ init_colors();
403
+ init_mode();
404
+ init_theme();
405
+ MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
406
+ STATUS_WORDS = {
407
+ passed: ["passed", "success", "succeeded", "ok"],
408
+ failed: ["failed", "failure", "error", "errored"],
409
+ running: ["running", "in_progress", "started", "holding"],
410
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
411
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
412
+ };
413
+ STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
414
+ });
382
415
 
383
416
  // ../kit/src/format.ts
384
- var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
417
+ import process7 from "process";
385
418
  function formatSeconds(total) {
386
419
  let rest = Math.max(0, Math.round(total));
387
420
  const amounts = UNITS.map(([unit, size]) => {
@@ -413,10 +446,8 @@ function formatAge(date, now = Date.now()) {
413
446
  return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
414
447
  }
415
448
  function truncate(text, width) {
416
- return ko(text, width, { suffix: "\u2026", includeSuffix: true });
449
+ return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
417
450
  }
418
- var LINE_BREAKS = /\s*\n\s*/g;
419
- var ESCAPE = String.fromCharCode(27);
420
451
  function textWidth(text) {
421
452
  return Bun.stringWidth(text);
422
453
  }
@@ -465,14 +496,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
465
496
  function printJson(value) {
466
497
  console.log(jsonText(value));
467
498
  }
499
+ var UNITS, LINE_BREAKS, ESCAPE;
500
+ var init_format = __esm(() => {
501
+ init_text();
502
+ init_mode();
503
+ init_style();
504
+ UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
505
+ LINE_BREAKS = /\s*\n\s*/g;
506
+ ESCAPE = String.fromCharCode(27);
507
+ });
468
508
 
469
509
  // ../kit/src/help.ts
470
510
  import process8 from "process";
471
- var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
472
- var USAGE_PREFIX = /^usage:\s*/i;
473
- var FULL_STOP = /\.$/;
474
511
  function usageLine(usage, colors = paint(process8.stdout)) {
475
- return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
512
+ const lines = usage.replace(USAGE_PREFIX, "").split(`
513
+ `);
514
+ const blank = lines.indexOf("");
515
+ const synopses = blank === -1 ? lines : lines.slice(0, blank);
516
+ const details = blank === -1 ? [] : lines.slice(blank + 1);
517
+ const colon = synopses[0].indexOf(": ");
518
+ const inline = synopses[0].slice(colon + 2);
519
+ const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
520
+ if (colon !== -1)
521
+ synopses[0] = synopses[0].slice(0, colon);
522
+ const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
523
+ `)}`;
524
+ const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
525
+ const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
526
+ return [head, ...lead, ...rest].join(`
527
+ `);
528
+ }
529
+ function prose(line, colors) {
530
+ if (colors.cyan("x") === "x")
531
+ return line;
532
+ return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
476
533
  }
477
534
  function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
478
535
  return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
@@ -507,7 +564,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
507
564
  return [];
508
565
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
509
566
  }
510
- var MAX_INLINE_CHOICES = 24;
511
567
  function optionRows(options, colors = paint(process8.stdout)) {
512
568
  const rows = Object.entries(options).map(([name, option]) => {
513
569
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
@@ -522,6 +578,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
522
578
  const width = Math.max(0, ...rows.map((row) => row.width));
523
579
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
524
580
  }
581
+ var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
582
+ var init_help = __esm(() => {
583
+ init_mode();
584
+ init_style();
585
+ OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
586
+ USAGE_PREFIX = /^usage:\s*/i;
587
+ FULL_STOP = /\.$/;
588
+ PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
589
+ });
525
590
 
526
591
  // ../kit/src/text.ts
527
592
  function distance(a, b) {
@@ -549,8 +614,9 @@ function closest(name, names) {
549
614
  const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
550
615
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
551
616
  }
617
+ var init_text2 = () => {};
618
+
552
619
  // ../kit/src/input.ts
553
- var WHOLE = /^\d+$/;
554
620
  function wholeNumber(value, name, fallback, min = 1) {
555
621
  if (value === undefined)
556
622
  return fallback;
@@ -559,8 +625,6 @@ function wholeNumber(value, name, fallback, min = 1) {
559
625
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
560
626
  return number;
561
627
  }
562
- var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
563
- var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
564
628
  function duration(value, name, fallback, unit = "s") {
565
629
  if (value === undefined)
566
630
  return fallback;
@@ -570,40 +634,27 @@ function duration(value, name, fallback, unit = "s") {
570
634
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
571
635
  return ms;
572
636
  }
637
+ var WHOLE, DURATION, UNIT_MS;
638
+ var init_input = __esm(() => {
639
+ init_args();
640
+ WHOLE = /^\d+$/;
641
+ DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
642
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
643
+ });
573
644
 
574
645
  // ../kit/src/args.ts
575
- var DASHES = /^-+/;
646
+ import process9 from "process";
647
+ import { parseArgs } from "util";
576
648
  function jsonOption(holds) {
577
649
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
578
650
  }
579
- class Exit extends Error {
580
- code;
581
- hint;
582
- constructor(message, code, hint) {
583
- super(message);
584
- this.code = code;
585
- this.hint = hint;
586
- }
587
- }
588
651
  function fail(message, code = 2, hint) {
589
652
  throw new Exit(message, code, hint);
590
653
  }
591
-
592
- class UsageError extends Exit {
593
- constructor(message, hint) {
594
- super(message, 2, hint);
595
- }
596
- }
597
654
  function badUsage(message) {
598
655
  throw new UsageError(message);
599
656
  }
600
657
 
601
- class HelpShown extends Exit {
602
- constructor() {
603
- super("help shown", 0);
604
- }
605
- }
606
-
607
658
  class Completing {
608
659
  options;
609
660
  positionals;
@@ -614,11 +665,6 @@ class Completing {
614
665
  this.candidates = candidates;
615
666
  }
616
667
  }
617
- var completion = { active: false };
618
- var OUTPUT_OPTIONS = {
619
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
620
- plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
621
- };
622
668
  function applyOutput(color, plain, env = process9.env) {
623
669
  const when = plain === true ? "never" : color ?? "auto";
624
670
  if (when === "auto")
@@ -772,7 +818,6 @@ function parseError(error) {
772
818
  const message = upTo(error instanceof Error ? error.message : String(error), ". ");
773
819
  return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
774
820
  }
775
- var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
776
821
  function nearestOption(message, options, allowNegative) {
777
822
  const typed = UNKNOWN_OPTION.exec(message)?.[1];
778
823
  if (typed === undefined)
@@ -788,6 +833,61 @@ function nearestOption(message, options, allowNegative) {
788
833
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
789
834
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
790
835
  }
836
+ var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
837
+ var init_args = __esm(() => {
838
+ init_format();
839
+ init_help();
840
+ init_text2();
841
+ init_help();
842
+ init_input();
843
+ DASHES = /^-+/;
844
+ EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
845
+ Exit = class Exit extends Error {
846
+ code;
847
+ hint;
848
+ [EXIT] = true;
849
+ constructor(message, code, hint) {
850
+ super(message);
851
+ this.code = code;
852
+ this.hint = hint;
853
+ }
854
+ static [Symbol.hasInstance](value) {
855
+ if (this !== Exit)
856
+ return Function.prototype[Symbol.hasInstance].call(this, value);
857
+ return typeof value === "object" && value !== null && value[EXIT] === true;
858
+ }
859
+ };
860
+ UsageError = class UsageError extends Exit {
861
+ constructor(message, hint) {
862
+ super(message, 2, hint);
863
+ }
864
+ };
865
+ HelpShown = class HelpShown extends Exit {
866
+ constructor() {
867
+ super("help shown", 0);
868
+ }
869
+ };
870
+ completion = { active: false };
871
+ OUTPUT_OPTIONS = {
872
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
873
+ plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
874
+ };
875
+ UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
876
+ });
877
+
878
+ // ../kit/src/folders.ts
879
+ var SKIPPED_FOLDERS;
880
+ var init_folders = __esm(() => {
881
+ init_user_config();
882
+ SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
883
+ });
884
+
885
+ // src/slot-cli.ts
886
+ import process22 from "process";
887
+
888
+ // ../kit/src/index.ts
889
+ init_args();
890
+
791
891
  // ../kit/src/argv.ts
792
892
  import { readFileSync as readFileSync3, realpathSync } from "fs";
793
893
  import { resolve as resolve3 } from "path";
@@ -812,14 +912,26 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
812
912
  const after = at === -1 ? [] : cmdline.slice(at + 1);
813
913
  return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
814
914
  }
915
+ // ../kit/src/chart.ts
916
+ init_format();
917
+ init_mode();
918
+ init_style();
919
+ init_theme();
920
+ // ../kit/src/ci.ts
921
+ init_args();
922
+ init_format();
923
+
815
924
  // ../kit/src/progress.ts
925
+ init_format();
816
926
  import process12 from "process";
817
927
 
818
928
  // ../kit/src/process.ts
929
+ import { readFileSync as readFileSync4 } from "fs";
819
930
  import { constants } from "os";
820
931
  import process11 from "process";
821
932
  var KILL_GRACE_MS = 2000;
822
933
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
934
+ var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
823
935
  function exitCodeOf(code, signal) {
824
936
  if (code !== null)
825
937
  return code;
@@ -827,6 +939,21 @@ function exitCodeOf(code, signal) {
827
939
  return 128 + signal;
828
940
  return signal === null ? 129 : 128 + constants.signals[signal];
829
941
  }
942
+ function groupsOf(pid) {
943
+ try {
944
+ const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
945
+ const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
946
+ return { group: Number(fields[2]), foreground: Number(fields[5]) };
947
+ } catch {
948
+ return;
949
+ }
950
+ }
951
+ function heardTheTerminal(child) {
952
+ if (child.pid === undefined)
953
+ return false;
954
+ const own = groupsOf("self");
955
+ return own !== undefined && own.group === own.foreground && groupsOf(child.pid)?.group === own.group;
956
+ }
830
957
  function holdSignals(cleanup) {
831
958
  let received;
832
959
  let child;
@@ -845,7 +972,8 @@ function holdSignals(cleanup) {
845
972
  function onSignal(signal) {
846
973
  received = signal;
847
974
  if (child !== undefined) {
848
- child.kill(signal);
975
+ if (!GROUP_SIGNALS.has(signal) || !heardTheTerminal(child))
976
+ child.kill(signal);
849
977
  return;
850
978
  }
851
979
  if (cleanup === undefined)
@@ -858,10 +986,10 @@ function holdSignals(cleanup) {
858
986
  process11.on(signal, onSignal);
859
987
  return held;
860
988
  }
861
- async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
989
+ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
862
990
  const chunks = [];
863
991
  const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
864
- const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
992
+ const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
865
993
  const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
866
994
  const timers = [];
867
995
  const killGroup = (killing) => {
@@ -901,12 +1029,19 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
901
1029
  stop();
902
1030
  continue;
903
1031
  }
1032
+ if (state.truncated)
1033
+ continue;
1034
+ let kept = data;
904
1035
  if (state.kept + data.length > maxBytes) {
1036
+ let cut = maxBytes - state.kept;
1037
+ while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
1038
+ cut--;
1039
+ kept = data.subarray(0, cut);
905
1040
  state.truncated = true;
906
- continue;
907
1041
  }
908
- state.kept += data.length;
909
- chunks.push({ stream: name, data });
1042
+ state.kept += kept.length;
1043
+ if (kept.length > 0)
1044
+ chunks.push({ stream: name, data: kept });
910
1045
  }
911
1046
  };
912
1047
  try {
@@ -923,6 +1058,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
923
1058
  const joined = () => Buffer.concat(chunks.map(({ data }) => data));
924
1059
  let output;
925
1060
  let text;
1061
+ let stdout;
926
1062
  return {
927
1063
  code: exitCodeOf(proc.exitCode, proc.signalCode),
928
1064
  chunks,
@@ -933,11 +1069,16 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
933
1069
  },
934
1070
  get text() {
935
1071
  return text ??= (output ??= joined()).toString();
1072
+ },
1073
+ get stdout() {
1074
+ return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
936
1075
  }
937
1076
  };
938
1077
  }
939
1078
 
940
1079
  // ../kit/src/progress.ts
1080
+ init_style();
1081
+ init_theme();
941
1082
  var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
942
1083
  var FRAME_MS = 200;
943
1084
  var CLEAR_BELOW = "\r\x1B[J";
@@ -954,10 +1095,14 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
954
1095
  }, print: (text) => void stream.write(`${text}
955
1096
  `), stop: () => {
956
1097
  return;
1098
+ }, pause: () => () => {
1099
+ return;
957
1100
  } };
958
1101
  const write = stream.write.bind(stream);
959
1102
  let frame = 0;
960
1103
  let drawn = false;
1104
+ let paused = false;
1105
+ let stopped = false;
961
1106
  const columns = () => {
962
1107
  const now = stream.getWindowSize?.()[0] ?? stream.columns;
963
1108
  return now === undefined || now === 0 ? 80 : now;
@@ -968,6 +1113,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
968
1113
  drawn = false;
969
1114
  };
970
1115
  const draw = () => {
1116
+ if (paused)
1117
+ return;
971
1118
  const width = columns() - 1;
972
1119
  const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
973
1120
  const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
@@ -979,16 +1126,17 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
979
1126
  `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
980
1127
  drawn = true;
981
1128
  };
982
- const timer = setInterval(draw, FRAME_MS);
1129
+ let timer = setInterval(draw, FRAME_MS);
983
1130
  stream.on?.("resize", draw);
984
- const restore = interceptOutput(clear);
985
- const release = swallowInput();
1131
+ let restore = interceptOutput(clear);
1132
+ let release = swallowInput();
986
1133
  const onExit = () => {
987
1134
  clear();
988
1135
  release();
989
1136
  };
990
1137
  const signals = holdSignals(stop);
991
1138
  function stop() {
1139
+ stopped = true;
992
1140
  clearInterval(timer);
993
1141
  stream.off?.("resize", draw);
994
1142
  clear();
@@ -997,6 +1145,29 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
997
1145
  process12.off("exit", onExit);
998
1146
  signals.release();
999
1147
  }
1148
+ function pause() {
1149
+ if (paused || stopped)
1150
+ return () => {
1151
+ return;
1152
+ };
1153
+ paused = true;
1154
+ clearInterval(timer);
1155
+ stream.off?.("resize", draw);
1156
+ clear();
1157
+ restore();
1158
+ release();
1159
+ return () => {
1160
+ if (!paused || stopped)
1161
+ return;
1162
+ paused = false;
1163
+ timer = setInterval(draw, FRAME_MS);
1164
+ timer.unref();
1165
+ stream.on?.("resize", draw);
1166
+ restore = interceptOutput(clear);
1167
+ release = swallowInput();
1168
+ draw();
1169
+ };
1170
+ }
1000
1171
  timer.unref();
1001
1172
  process12.on("exit", onExit);
1002
1173
  return {
@@ -1007,7 +1178,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1007
1178
  `);
1008
1179
  draw();
1009
1180
  },
1010
- stop
1181
+ stop,
1182
+ pause
1011
1183
  };
1012
1184
  }
1013
1185
  function cutToWidth(line, width) {
@@ -1077,55 +1249,166 @@ function interceptOutput(clear) {
1077
1249
  }
1078
1250
  };
1079
1251
  }
1252
+
1253
+ // ../kit/src/ci.ts
1254
+ init_style();
1255
+
1256
+ // ../kit/src/tool.ts
1257
+ init_format();
1080
1258
  // ../kit/src/cli.ts
1081
- import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1259
+ init_args();
1260
+ import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
1082
1261
  import { dirname as dirname3, join as join6 } from "path";
1083
- import process16 from "process";
1262
+ import process17 from "process";
1084
1263
 
1085
- // ../kit/src/notify.ts
1264
+ // ../kit/src/askpass.ts
1086
1265
  import process13 from "process";
1266
+ var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1267
+ async function askpassClient(argv) {
1268
+ const socketPath = process13.env[SOCKET_VARIABLE];
1269
+ if (socketPath === undefined)
1270
+ return;
1271
+ const request = { prompt: argv[0] ?? "", ...process13.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
1272
+ const { promise, resolve } = Promise.withResolvers();
1273
+ let received = "";
1274
+ try {
1275
+ await Bun.connect({
1276
+ unix: socketPath,
1277
+ socket: {
1278
+ open: (socket) => void socket.write(`${JSON.stringify(request)}
1279
+ `),
1280
+ data: (_, chunk) => {
1281
+ received += chunk.toString();
1282
+ },
1283
+ close: () => resolve(received),
1284
+ error: () => resolve("")
1285
+ }
1286
+ });
1287
+ } catch {
1288
+ return 1;
1289
+ }
1290
+ const reply = await promise;
1291
+ if (reply === "")
1292
+ return 1;
1293
+ const { answer } = JSON.parse(reply);
1294
+ if (request.notice === true)
1295
+ return 0;
1296
+ if (answer === undefined)
1297
+ return 1;
1298
+ process13.stdout.write(`${answer}
1299
+ `);
1300
+ return 0;
1301
+ }
1302
+
1303
+ // ../kit/src/completions.ts
1304
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1305
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1306
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1307
+ set -l current (commandline -ct)
1308
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1309
+ if test "$line" = __files__
1310
+ __fish_complete_path $current
1311
+ else
1312
+ echo $line
1313
+ end
1314
+ end
1315
+ end`;
1316
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1317
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1318
+ local -a lines
1319
+ COMPREPLY=()
1320
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1321
+ for line in "\${lines[@]}"; do
1322
+ if [[ $line == __files__ ]]; then
1323
+ COMPREPLY+=($(compgen -f -- "$cur"))
1324
+ else
1325
+ words+="\${line%%$'\\t'*}"$'\\n'
1326
+ fi
1327
+ done
1328
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1329
+ }`;
1330
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1331
+ local line
1332
+ local -a described plain
1333
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1334
+ if [[ $line == __files__ ]]; then
1335
+ _files
1336
+ elif [[ $line == *$'\\t'* ]]; then
1337
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1338
+ else
1339
+ plain+=("$line")
1340
+ fi
1341
+ done
1342
+ (( \${#described} )) && _describe -V value described
1343
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1344
+ return 0
1345
+ }`;
1346
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1347
+ if (shell === "fish")
1348
+ return `${header}
1349
+ ${FISH_FUNCTION}
1350
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1351
+ `).join("")}`;
1352
+ if (shell === "bash")
1353
+ return `${header}
1354
+ ${BASH_FUNCTION}
1355
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1356
+ `;
1357
+ return `${header}
1358
+ ${ZSH_FUNCTION}
1359
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1360
+ `;
1361
+ }
1362
+
1363
+ // ../kit/src/notify.ts
1364
+ init_format();
1365
+ init_mode();
1366
+ import process14 from "process";
1087
1367
  var NOTIFY_AFTER_MS = 1e4;
1088
1368
  var CANCELLED = 130;
1089
1369
  function base64(text) {
1090
1370
  return Buffer.from(text).toString("base64");
1091
1371
  }
1092
- function notification(title, body, env = process13.env) {
1093
- const id = `kit${process13.pid}`;
1372
+ function notification(title, body, env = process14.env) {
1373
+ const id = `kit${process14.pid}`;
1094
1374
  const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
1095
1375
  return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
1096
1376
  }
1097
- function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
1377
+ function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
1098
1378
  if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
1099
1379
  return;
1100
1380
  stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
1101
1381
  }
1102
1382
 
1383
+ // ../kit/src/cli.ts
1384
+ init_style();
1385
+ init_text2();
1386
+
1103
1387
  // ../kit/src/usage.ts
1104
1388
  import { appendFileSync, mkdirSync } from "fs";
1105
1389
  import { homedir as homedir4 } from "os";
1106
- import { dirname as dirname2, isAbsolute, join as join5 } from "path";
1107
- import process15 from "process";
1390
+ import { dirname as dirname2, join as join5 } from "path";
1391
+ import process16 from "process";
1108
1392
 
1109
1393
  // ../kit/src/logs.ts
1394
+ init_user_config();
1110
1395
  import { lstatSync, openSync } from "fs";
1111
1396
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
1112
1397
  import { homedir as homedir3, tmpdir } from "os";
1113
1398
  import { join as join4 } from "path";
1114
- import process14 from "process";
1399
+ import process15 from "process";
1115
1400
  var DAY_MS = 24 * 60 * 60 * 1000;
1116
1401
  var CLI_FOLDER = "kaynooo-cli";
1117
1402
  function isPrivateDirectory(path) {
1118
1403
  try {
1119
1404
  const info = lstatSync(path, { throwIfNoEntry: false });
1120
- return info !== undefined && info.isDirectory() && info.uid === (process14.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1405
+ return info !== undefined && info.isDirectory() && info.uid === (process15.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1121
1406
  } catch {
1122
1407
  return false;
1123
1408
  }
1124
1409
  }
1125
- async function privateLogDirectory(name, env = process14.env) {
1126
- const runtime = env.XDG_RUNTIME_DIR;
1127
- const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
1128
- const path = join4(base, name);
1410
+ async function privateLogDirectory(name, env = process15.env) {
1411
+ const path = join4(xdgFolder(env.XDG_RUNTIME_DIR, join4(homedir3(), ".cache")), CLI_FOLDER, name);
1129
1412
  try {
1130
1413
  await mkdir(path, { recursive: true, mode: 448 });
1131
1414
  if (isPrivateDirectory(path))
@@ -1135,6 +1418,7 @@ async function privateLogDirectory(name, env = process14.env) {
1135
1418
  }
1136
1419
 
1137
1420
  // ../kit/src/usage.ts
1421
+ init_user_config();
1138
1422
  var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
1139
1423
  var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
1140
1424
  var LONGEST_NAME = 40;
@@ -1142,14 +1426,13 @@ var usageError;
1142
1426
  function noteUsageError(message) {
1143
1427
  usageError = message;
1144
1428
  }
1145
- function stateHome(env = process15.env) {
1146
- const dir = env.XDG_STATE_HOME;
1147
- return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
1429
+ function stateHome(env = process16.env) {
1430
+ return xdgFolder(env.XDG_STATE_HOME, join5(homedir4(), ".local", "state"));
1148
1431
  }
1149
- function usagePath(env = process15.env) {
1432
+ function usagePath(env = process16.env) {
1150
1433
  return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1151
1434
  }
1152
- function usageRecorded(env = process15.env) {
1435
+ function usageRecorded(env = process16.env) {
1153
1436
  const off = env.KAYNOOO_CLI_NO_USAGE;
1154
1437
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1155
1438
  }
@@ -1158,12 +1441,12 @@ function flagNames(argv) {
1158
1441
  const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
1159
1442
  return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
1160
1443
  }
1161
- function usageEntry(bin, command, argv, code, now = new Date) {
1444
+ function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
1162
1445
  const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
1163
1446
  usageError = undefined;
1164
- return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1447
+ return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
1165
1448
  }
1166
- function recordUsage(entry, env = process15.env) {
1449
+ function recordUsage(entry, env = process16.env) {
1167
1450
  if (!usageRecorded(env))
1168
1451
  return;
1169
1452
  try {
@@ -1179,10 +1462,14 @@ var LEVEL_OPTIONS = {
1179
1462
  ...OUTPUT_OPTIONS,
1180
1463
  help: { type: "boolean", short: "h", description: "show this help" }
1181
1464
  };
1182
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1465
+ var TOP_OPTIONS = {
1466
+ ...LEVEL_OPTIONS,
1467
+ version: { type: "boolean", short: "v", description: "print the version" },
1468
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1469
+ };
1183
1470
  function printError(prefix, message, hint, cause) {
1184
- const colors = paint(process16.stderr);
1185
- const styled = takesControlCodes(process16.stderr);
1471
+ const colors = paint(process17.stderr);
1472
+ const styled = takesControlCodes(process17.stderr);
1186
1473
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1187
1474
  const under = (label, text, tint) => text === undefined ? "" : `
1188
1475
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1259,6 +1546,19 @@ async function leafCandidates(run, words) {
1259
1546
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1260
1547
  return values === undefined ? [FILES] : values.map(candidateLine);
1261
1548
  }
1549
+ var COMPLETIONS = "--completions";
1550
+ function flagValue([flag = "", ...rest]) {
1551
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1552
+ }
1553
+ function printCompletionScript(name, args) {
1554
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1555
+ if (shell === undefined || args.length !== 1) {
1556
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1557
+ return 2;
1558
+ }
1559
+ console.log(completionScript(shell, [name]).trimEnd());
1560
+ return 0;
1561
+ }
1262
1562
  async function printCandidates(found) {
1263
1563
  for (const line of await found)
1264
1564
  console.log(line);
@@ -1271,7 +1571,7 @@ function packageVersion(entry = Bun.main) {
1271
1571
  } catch {}
1272
1572
  for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1273
1573
  try {
1274
- const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
1574
+ const { version } = JSON.parse(readFileSync5(join6(dir, "package.json"), "utf8"));
1275
1575
  if (typeof version === "string")
1276
1576
  return version;
1277
1577
  } catch {}
@@ -1280,8 +1580,13 @@ function packageVersion(entry = Bun.main) {
1280
1580
  }
1281
1581
  }
1282
1582
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1583
+ const answered = await askpassClient(argv);
1584
+ if (answered !== undefined)
1585
+ return answered;
1283
1586
  if (argv[0] === COMPLETE)
1284
1587
  return printCandidates(leafCandidates(run, argv.slice(1)));
1588
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1589
+ return printCompletionScript(name, flagValue(argv));
1285
1590
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1286
1591
  console.log(version ?? packageVersion());
1287
1592
  return 0;
@@ -1296,27 +1601,48 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
1296
1601
  notifyEnd(name, code, performance.now() - started);
1297
1602
  if (usage !== false) {
1298
1603
  try {
1299
- recordUsage(usageEntry(name, undefined, argv, code));
1604
+ recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
1300
1605
  } catch {}
1301
1606
  }
1302
1607
  return code;
1303
1608
  }
1304
- // ../kit/src/folders.ts
1305
- var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1609
+
1610
+ // ../kit/src/index.ts
1611
+ init_config();
1612
+
1613
+ // ../kit/src/excerpt.ts
1614
+ init_text2();
1615
+
1616
+ // ../kit/src/index.ts
1617
+ init_folders();
1618
+ init_format();
1619
+
1620
+ // ../kit/src/git.ts
1621
+ init_args();
1622
+ // ../kit/src/limit.ts
1623
+ init_args();
1624
+
1625
+ // ../kit/src/index.ts
1626
+ init_mode();
1627
+
1628
+ // ../kit/src/report.ts
1629
+ init_style();
1630
+ init_text2();
1306
1631
  // ../kit/src/secrets.ts
1307
1632
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1633
+ var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
1308
1634
  // ../kit/src/sessions.ts
1309
1635
  import { homedir as homedir5 } from "os";
1310
1636
  import { join as join7 } from "path";
1311
- import process17 from "process";
1637
+ import process18 from "process";
1312
1638
  var {Glob } = globalThis.Bun;
1313
1639
  var SESSION_FILES = new Glob("*.json");
1314
1640
  var ACCOUNT_DIRS = new Glob("*/sessions");
1315
1641
  async function sessionDirs() {
1316
1642
  const home = homedir5();
1317
1643
  const dirs = new Set([join7(home, ".claude", "sessions")]);
1318
- if (process17.env.CLAUDE_CONFIG_DIR !== undefined)
1319
- dirs.add(join7(process17.env.CLAUDE_CONFIG_DIR, "sessions"));
1644
+ if (process18.env.CLAUDE_CONFIG_DIR !== undefined)
1645
+ dirs.add(join7(process18.env.CLAUDE_CONFIG_DIR, "sessions"));
1320
1646
  try {
1321
1647
  for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1322
1648
  dirs.add(dir);
@@ -1362,7 +1688,7 @@ async function liveSessions() {
1362
1688
  }
1363
1689
  async function currentSession(sessions) {
1364
1690
  const byPid = new Map(sessions.map((session) => [session.pid, session]));
1365
- let pid = process17.ppid;
1691
+ let pid = process18.ppid;
1366
1692
  for (let depth = 0;depth < 32 && pid > 1; depth++) {
1367
1693
  const session = byPid.get(pid);
1368
1694
  if (session !== undefined)
@@ -1374,21 +1700,34 @@ async function currentSession(sessions) {
1374
1700
  }
1375
1701
  return;
1376
1702
  }
1703
+
1704
+ // ../kit/src/index.ts
1705
+ init_style();
1706
+ init_text2();
1707
+ init_theme();
1708
+ init_user_config();
1709
+
1710
+ // ../kit/src/watch.ts
1711
+ init_args();
1712
+ init_input();
1713
+ init_style();
1714
+ // ../kit/src/workspace-root.ts
1715
+ init_user_config();
1377
1716
  // src/slot.ts
1378
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync5, rmSync } from "fs";
1717
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync6, rmSync } from "fs";
1379
1718
  import { availableParallelism } from "os";
1380
1719
  import { join as join8 } from "path";
1381
- import process20 from "process";
1720
+ import process21 from "process";
1382
1721
 
1383
1722
  // src/flock.ts
1384
1723
  import { closeSync, constants as constants2, ftruncateSync, openSync as openSync2, writeSync } from "fs";
1385
- import process19 from "process";
1724
+ import process20 from "process";
1386
1725
  import { dlopen, FFIType } from "bun:ffi";
1387
1726
  var LOCK_EX = 2;
1388
1727
  var LOCK_NB = 4;
1389
1728
  var flock;
1390
1729
  function native() {
1391
- flock ??= dlopen(process19.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", { flock: { args: [FFIType.i32, FFIType.i32], returns: FFIType.i32 } }).symbols.flock;
1730
+ flock ??= dlopen(process20.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", { flock: { args: [FFIType.i32, FFIType.i32], returns: FFIType.i32 } }).symbols.flock;
1392
1731
  return flock;
1393
1732
  }
1394
1733
  function tryLock(path) {
@@ -1408,10 +1747,9 @@ function writeHeld(held, text) {
1408
1747
  var RUN_USAGE = `slot [options] -- <cmd>...: waits for a free machine-wide slot, then runs the command and exits with its code
1409
1748
  slot ls [--json]: lists who holds a slot or a lock and who waits for one (slot ls --help)
1410
1749
 
1411
- The slots and locks are shared by every session, worktree and shell of this user, so heavy jobs (phpunit, playwright, vue-tsc, eslint) queue instead of overloading the machine.
1412
- A slot or lock is freed the moment its holder ends, SIGKILL included, since the kernel drops it with the process.
1413
- A slotted command that runs slot again does not wait for a second slot, so wrapping both a script and the commands inside it cannot deadlock.
1414
- A first word \`ls\` always means the listing, so run the ls command as \`slot -n 4 -- ls\` or by its path.`;
1750
+ The slots and locks are shared by every session, worktree and shell of this user, so heavy jobs (phpunit, playwright, vue-tsc, eslint) queue instead of overloading the machine; one is freed the moment its holder ends, SIGKILL included.
1751
+ A slotted command that runs slot again does not wait for a second slot, so wrapping a script and the commands inside it cannot deadlock.
1752
+ A first word \`ls\` always means the listing: run the ls command as \`slot -n 4 -- ls\`.`;
1415
1753
  var RUN_EXITS = [[0, "the command did"], ["its own", "the code of a command that failed"], [2, "it timed out waiting for the slot or a usage error"], [127, "the command cannot be started"]];
1416
1754
  var LS_USAGE = `slot ls [options]: lists the slots and locks held, with the session, the command and how long ago it started, then who waits for one
1417
1755
 
@@ -1432,14 +1770,14 @@ function defaultSlots() {
1432
1770
  return Math.max(1, Math.floor(availableParallelism() / 2));
1433
1771
  }
1434
1772
  async function stateDir() {
1435
- const dir = process20.env.SLOT_DIR ?? await privateLogDirectory("slot");
1773
+ const dir = process21.env.SLOT_DIR ?? await privateLogDirectory("slot");
1436
1774
  for (const sub of ["slots", "locks", "waiters"])
1437
1775
  mkdirSync2(join8(dir, sub), { recursive: true, mode: 448 });
1438
1776
  return dir;
1439
1777
  }
1440
1778
  function readHolder(path) {
1441
1779
  try {
1442
- const holder = JSON.parse(readFileSync5(path, "utf8"));
1780
+ const holder = JSON.parse(readFileSync6(path, "utf8"));
1443
1781
  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;
1444
1782
  } catch {
1445
1783
  return;
@@ -1474,7 +1812,7 @@ function waitingLine(dir, wanted) {
1474
1812
  }
1475
1813
  async function holderOf(command) {
1476
1814
  const session = await currentSession(await liveSessions());
1477
- return { pid: process20.pid, command: command.join(" "), cwd: process20.cwd(), since: Date.now(), ...session === undefined ? {} : { session: session.name } };
1815
+ return { pid: process21.pid, command: command.join(" "), cwd: process21.cwd(), since: Date.now(), ...session === undefined ? {} : { session: session.name } };
1478
1816
  }
1479
1817
  var waiterCount = 0;
1480
1818
  async function acquire(dir, resources, holder, deadline, timeoutMs) {
@@ -1500,7 +1838,7 @@ async function acquire(dir, resources, holder, deadline, timeoutMs) {
1500
1838
  held.release();
1501
1839
  const resource = busy.kind === "lock" ? `lock ${busy.name}` : "slot";
1502
1840
  if (waiter === undefined) {
1503
- const path = join8(dir, "waiters", `${process20.pid}-${waiterCount++}`);
1841
+ const path = join8(dir, "waiters", `${process21.pid}-${waiterCount++}`);
1504
1842
  const held = tryLock(path);
1505
1843
  if (held !== undefined) {
1506
1844
  writeHeld(held, JSON.stringify({ ...holder, resource }));
@@ -1541,7 +1879,7 @@ ${RUN_USAGE}`);
1541
1879
  const count = wholeNumber(values.slots, "slots", defaultSlots());
1542
1880
  const timeoutMs = duration(values.timeout, "timeout", Number.POSITIVE_INFINITY);
1543
1881
  const deadline = Date.now() + timeoutMs;
1544
- const holding = new Set((process20.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1882
+ const holding = new Set((process21.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1545
1883
  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 }]];
1546
1884
  const signals = holdSignals(() => {
1547
1885
  return;
@@ -1556,7 +1894,7 @@ ${RUN_USAGE}`);
1556
1894
  const tokens = new Set([...holding, ...locks.map((name) => `lock:${name}`), ...wanted.some((resource) => resource.kind === "slot") ? ["slot"] : []]);
1557
1895
  let child;
1558
1896
  try {
1559
- child = Bun.spawn(rest, { stdio: ["inherit", "inherit", "inherit"], env: { ...process20.env, [HOLDING]: [...tokens].join(",") } });
1897
+ child = Bun.spawn(rest, { stdio: ["inherit", "inherit", "inherit"], env: { ...process21.env, [HOLDING]: [...tokens].join(",") } });
1560
1898
  } catch (error) {
1561
1899
  fail(`cannot run ${rest[0]}: ${error instanceof Error ? error.message : String(error)}`, 127);
1562
1900
  }
@@ -1599,11 +1937,11 @@ async function listSlots(args) {
1599
1937
  printJson({ slots: count, busy, entries });
1600
1938
  return 0;
1601
1939
  }
1602
- console.log(paint(process20.stdout).bold(`slots: ${busy} of ${count} busy`));
1940
+ console.log(paint(process21.stdout).bold(`slots: ${busy} of ${count} busy`));
1603
1941
  if (entries.length > 0)
1604
- console.log(table(entries.map((entry) => [badge(entry.state, process20.stdout), entry.resource, entry.session ?? `pid ${entry.pid}`, truncate(entry.command, COMMAND_WIDTH), entry.since === 0 ? "?" : formatAge(entry.since)])));
1942
+ console.log(table(entries.map((entry) => [badge(entry.state, process21.stdout), entry.resource, entry.session ?? `pid ${entry.pid}`, truncate(entry.command, COMMAND_WIDTH), entry.since === 0 ? "?" : formatAge(entry.since)])));
1605
1943
  return 0;
1606
1944
  }
1607
1945
 
1608
1946
  // src/slot-cli.ts
1609
- process21.exitCode = await runMain({ name: "slot", run: async (args) => args[0] === "ls" ? listSlots(args.slice(1)) : runSlotted(args) });
1947
+ process22.exitCode = await runMain({ name: "slot", run: async (args) => args[0] === "ls" ? listSlots(args.slice(1)) : runSlotted(args) });