@kaynooo/cli-git 0.17.0 → 0.17.2

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 (11) hide show
  1. package/README.md +1 -1
  2. package/dist/gb.js +1674 -1141
  3. package/dist/gc.js +1089 -159
  4. package/dist/gcl.js +1124 -174
  5. package/dist/gd.js +1100 -170
  6. package/dist/gf.js +1131 -175
  7. package/dist/gm.js +1686 -1155
  8. package/dist/gp.js +1110 -174
  9. package/dist/gst.js +1108 -178
  10. package/dist/gu.js +1097 -167
  11. package/package.json +2 -2
package/dist/gu.js CHANGED
@@ -1,22 +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/gu.ts
5
- import { mkdirSync as mkdirSync2, writeFileSync } from "fs";
6
- import { join as join7, resolve as resolve5 } from "path";
7
- import process19 from "process";
8
- // ../kit/src/args.ts
9
- import process9 from "process";
10
- import { parseArgs } from "util";
11
-
12
- // ../kit/src/format.ts
13
- import process7 from "process";
14
-
15
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
16
- var N = new Map;
17
- var Nt = /\s+\S*$/;
18
- var Y = /\s/;
19
- 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 = "...") {
20
17
  let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
21
18
  if (t.length <= e)
22
19
  return t;
@@ -27,13 +24,22 @@ function ko(t, e, r = "...") {
27
24
  c = c.trimEnd();
28
25
  return s ? (c + n).slice(0, l) : c + n;
29
26
  }
30
- 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));
31
- 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
+ });
32
40
 
33
41
  // ../kit/src/mode.ts
34
42
  import process2 from "process";
35
- var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
36
- var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
37
43
  function isSet(value) {
38
44
  return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
39
45
  }
@@ -50,12 +56,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
50
56
  function isInteractive(streams = process2) {
51
57
  return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
52
58
  }
59
+ var MODES, AGENT_VARIABLES;
60
+ var init_mode = __esm(() => {
61
+ MODES = new Set(["terminal", "ci", "agent", "pipe"]);
62
+ AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
63
+ });
53
64
 
54
- // ../kit/src/style.ts
55
- import process6 from "process";
56
-
57
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
58
- var G2 = /^[a-f0-9]+$/i;
65
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
59
66
  function b(r) {
60
67
  let e = r.startsWith("#") ? r.slice(1) : r;
61
68
  if (!G2.test(e))
@@ -66,11 +73,6 @@ function b(r) {
66
73
  throw Error(`Invalid hex color length: ${e.length}`);
67
74
  return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
68
75
  }
69
- 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") => {
70
- let [l, n, c] = b(r);
71
- return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
72
- }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
73
- var h = new Set(["", "1", "2", "3", "true"]);
74
76
  function C(r, e = globalThis.process?.env ?? {}) {
75
77
  if (e.FORCE_COLOR !== undefined)
76
78
  return h.has(e.FORCE_COLOR);
@@ -84,7 +86,7 @@ function f(r, e = []) {
84
86
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
85
87
  let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
86
88
  return new Proxy(c, { get(t, i) {
87
- let a = B2[i];
89
+ let a = B[i];
88
90
  if (Array.isArray(a)) {
89
91
  let s = g.get(i);
90
92
  if (s === undefined)
@@ -107,13 +109,21 @@ function f(r, e = []) {
107
109
  function Fe(r = {}) {
108
110
  return f(r);
109
111
  }
110
- var o = Fe();
112
+ var G2, B, h, o;
113
+ var init_chunk_x450vn3m = __esm(() => {
114
+ G2 = /^[a-f0-9]+$/i;
115
+ 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") => {
116
+ let [l, n, c] = b(r);
117
+ return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
118
+ }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
119
+ h = new Set(["", "1", "2", "3", "true"]);
120
+ o = Fe();
121
+ });
111
122
 
112
- // ../kit/src/theme.ts
113
- import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
114
- import { homedir as homedir2 } from "os";
115
- import { join as join3, resolve as resolve2 } from "path";
116
- import process5 from "process";
123
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
124
+ var init_colors = __esm(() => {
125
+ init_chunk_x450vn3m();
126
+ });
117
127
 
118
128
  // ../kit/src/config.ts
119
129
  import { existsSync } from "fs";
@@ -129,6 +139,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
129
139
  return;
130
140
  }
131
141
  }
142
+ var init_config = __esm(() => {
143
+ init_args();
144
+ });
132
145
 
133
146
  // ../kit/src/user-config.ts
134
147
  import { existsSync as existsSync2, readFileSync } from "fs";
@@ -160,13 +173,17 @@ function readUserConfig(bin, where = {}, legacy = []) {
160
173
  return {};
161
174
  }
162
175
  }
176
+ var init_user_config = () => {};
163
177
 
164
178
  // ../kit/src/theme.ts
179
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
180
+ import { homedir as homedir2 } from "os";
181
+ import { join as join3, resolve as resolve2 } from "path";
182
+ import process5 from "process";
165
183
  function toLinear(channel) {
166
184
  const value = channel / 255;
167
185
  return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
168
186
  }
169
- var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055)));
170
187
  function toOklab(hex) {
171
188
  const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
172
189
  const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
@@ -181,7 +198,6 @@ function fromOklab([lightness, a, b]) {
181
198
  const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
182
199
  return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
183
200
  }
184
- var ENDS = new Map;
185
201
  function gradientAt(theme, ratio) {
186
202
  if (theme.gradient === undefined)
187
203
  return;
@@ -195,33 +211,11 @@ function gradientAt(theme, ratio) {
195
211
  const [from, to] = ends;
196
212
  return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
197
213
  }
198
- var DEFAULT = {
199
- 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" },
200
- 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" },
201
- accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
202
- bins: {},
203
- gradient: ["#c084fc", "#67e8f9"]
204
- };
205
- 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" };
206
- 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" };
207
- var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
208
- var PRESETS = {
209
- default: {},
210
- "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
211
- mono: { colors: MONO, accents: ["bold"], gradient: undefined },
212
- ascii: { glyphs: ASCII }
213
- };
214
- 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"]);
215
- var HEX = /^#[0-9a-f]{6}$/i;
216
- var CONTROL = /\p{Cc}/u;
217
- var MAX_FILE_BYTES = 64 * 1024;
218
- var SPACES = /\s+/;
219
214
  function isColorSpec(spec) {
220
215
  if (typeof spec === "number")
221
216
  return Number.isInteger(spec) && spec >= 0 && spec <= 255;
222
217
  return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
223
218
  }
224
- var CUBE = [0, 95, 135, 175, 215, 255];
225
219
  function cubeLevel(channel) {
226
220
  return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
227
221
  }
@@ -329,7 +323,6 @@ function applyFile(theme, file, where, warn) {
329
323
  function endsWalk(home) {
330
324
  return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
331
325
  }
332
- var warned = new Set;
333
326
  function warnOnce(message) {
334
327
  if (warned.has(message))
335
328
  return;
@@ -366,8 +359,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
366
359
  }
367
360
  return { theme, sources, preset };
368
361
  }
369
- var current;
370
- var currentKey = "";
371
362
  function activeTheme() {
372
363
  const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
373
364
  if (current === undefined || key !== currentKey) {
@@ -376,9 +367,38 @@ function activeTheme() {
376
367
  }
377
368
  return current;
378
369
  }
370
+ var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055))), ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
371
+ var init_theme = __esm(() => {
372
+ init_config();
373
+ init_user_config();
374
+ ENDS = new Map;
375
+ DEFAULT = {
376
+ 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" },
377
+ 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" },
378
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
379
+ bins: {},
380
+ gradient: ["#c084fc", "#67e8f9"]
381
+ };
382
+ 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" };
383
+ 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" };
384
+ ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
385
+ PRESETS = {
386
+ default: {},
387
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
388
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
389
+ ascii: { glyphs: ASCII }
390
+ };
391
+ 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"]);
392
+ HEX = /^#[0-9a-f]{6}$/i;
393
+ CONTROL = /\p{Cc}/u;
394
+ MAX_FILE_BYTES = 64 * 1024;
395
+ SPACES = /\s+/;
396
+ CUBE = [0, 95, 135, 175, 215, 255];
397
+ warned = new Set;
398
+ });
379
399
 
380
400
  // ../kit/src/style.ts
381
- var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
401
+ import process6 from "process";
382
402
  function takesControlCodes(stream, env = process6.env) {
383
403
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
384
404
  }
@@ -398,17 +418,24 @@ function role(name, stream, env = process6.env) {
398
418
  const colors = paint(stream, env);
399
419
  return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
400
420
  }
401
- var STATUS_WORDS = {
402
- passed: ["passed", "success", "succeeded", "ok"],
403
- failed: ["failed", "failure", "error", "errored"],
404
- running: ["running", "in_progress", "started", "holding"],
405
- queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
406
- skipped: ["skipped", "cancelled", "canceled", "manual"]
407
- };
408
- var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
421
+ var MARK_WORDS, STATUS_WORDS, STATUS_OF;
422
+ var init_style = __esm(() => {
423
+ init_colors();
424
+ init_mode();
425
+ init_theme();
426
+ MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
427
+ STATUS_WORDS = {
428
+ passed: ["passed", "success", "succeeded", "ok"],
429
+ failed: ["failed", "failure", "error", "errored"],
430
+ running: ["running", "in_progress", "started", "holding"],
431
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
432
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
433
+ };
434
+ STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
435
+ });
409
436
 
410
437
  // ../kit/src/format.ts
411
- var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
438
+ import process7 from "process";
412
439
  function formatSeconds(total) {
413
440
  let rest = Math.max(0, Math.round(total));
414
441
  const amounts = UNITS.map(([unit, size]) => {
@@ -440,10 +467,8 @@ function formatAge(date, now = Date.now()) {
440
467
  return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
441
468
  }
442
469
  function truncate(text, width) {
443
- return ko(text, width, { suffix: "\u2026", includeSuffix: true });
470
+ return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
444
471
  }
445
- var LINE_BREAKS = /\s*\n\s*/g;
446
- var ESCAPE = String.fromCharCode(27);
447
472
  function textWidth(text) {
448
473
  return Bun.stringWidth(text);
449
474
  }
@@ -492,14 +517,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
492
517
  function printJson(value) {
493
518
  console.log(jsonText(value));
494
519
  }
520
+ var UNITS, LINE_BREAKS, ESCAPE;
521
+ var init_format = __esm(() => {
522
+ init_text();
523
+ init_mode();
524
+ init_style();
525
+ UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
526
+ LINE_BREAKS = /\s*\n\s*/g;
527
+ ESCAPE = String.fromCharCode(27);
528
+ });
495
529
 
496
530
  // ../kit/src/help.ts
497
531
  import process8 from "process";
498
- var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
499
- var USAGE_PREFIX = /^usage:\s*/i;
500
- var FULL_STOP = /\.$/;
501
532
  function usageLine(usage, colors = paint(process8.stdout)) {
502
- return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
533
+ const lines = usage.replace(USAGE_PREFIX, "").split(`
534
+ `);
535
+ const blank = lines.indexOf("");
536
+ const synopses = blank === -1 ? lines : lines.slice(0, blank);
537
+ const details = blank === -1 ? [] : lines.slice(blank + 1);
538
+ const colon = synopses[0].indexOf(": ");
539
+ const inline = synopses[0].slice(colon + 2);
540
+ const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
541
+ if (colon !== -1)
542
+ synopses[0] = synopses[0].slice(0, colon);
543
+ const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
544
+ `)}`;
545
+ const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
546
+ const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
547
+ return [head, ...lead, ...rest].join(`
548
+ `);
549
+ }
550
+ function prose(line, colors) {
551
+ if (colors.cyan("x") === "x")
552
+ return line;
553
+ return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
503
554
  }
504
555
  function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
505
556
  return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
@@ -534,7 +585,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
534
585
  return [];
535
586
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
536
587
  }
537
- var MAX_INLINE_CHOICES = 24;
538
588
  function optionRows(options, colors = paint(process8.stdout)) {
539
589
  const rows = Object.entries(options).map(([name, option]) => {
540
590
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
@@ -549,9 +599,17 @@ function optionRows(options, colors = paint(process8.stdout)) {
549
599
  const width = Math.max(0, ...rows.map((row) => row.width));
550
600
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
551
601
  }
602
+ var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
603
+ var init_help = __esm(() => {
604
+ init_mode();
605
+ init_style();
606
+ OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
607
+ USAGE_PREFIX = /^usage:\s*/i;
608
+ FULL_STOP = /\.$/;
609
+ PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
610
+ });
552
611
 
553
612
  // ../kit/src/text.ts
554
- var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
555
613
  function distance(a, b) {
556
614
  const left = [...a];
557
615
  const right = [...b];
@@ -577,8 +635,12 @@ function closest(name, names) {
577
635
  const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
578
636
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
579
637
  }
638
+ var ANSI;
639
+ var init_text2 = __esm(() => {
640
+ ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
641
+ });
642
+
580
643
  // ../kit/src/input.ts
581
- var WHOLE = /^\d+$/;
582
644
  function wholeNumber(value, name, fallback, min = 1) {
583
645
  if (value === undefined)
584
646
  return fallback;
@@ -587,8 +649,6 @@ function wholeNumber(value, name, fallback, min = 1) {
587
649
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
588
650
  return number;
589
651
  }
590
- var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
591
- var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
592
652
  function duration(value, name, fallback, unit = "s") {
593
653
  if (value === undefined)
594
654
  return fallback;
@@ -598,40 +658,27 @@ function duration(value, name, fallback, unit = "s") {
598
658
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
599
659
  return ms;
600
660
  }
661
+ var WHOLE, DURATION, UNIT_MS;
662
+ var init_input = __esm(() => {
663
+ init_args();
664
+ WHOLE = /^\d+$/;
665
+ DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
666
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
667
+ });
601
668
 
602
669
  // ../kit/src/args.ts
603
- var DASHES = /^-+/;
670
+ import process9 from "process";
671
+ import { parseArgs } from "util";
604
672
  function jsonOption(holds) {
605
673
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
606
674
  }
607
- class Exit extends Error {
608
- code;
609
- hint;
610
- constructor(message, code, hint) {
611
- super(message);
612
- this.code = code;
613
- this.hint = hint;
614
- }
615
- }
616
675
  function fail(message, code = 2, hint) {
617
676
  throw new Exit(message, code, hint);
618
677
  }
619
-
620
- class UsageError extends Exit {
621
- constructor(message, hint) {
622
- super(message, 2, hint);
623
- }
624
- }
625
678
  function badUsage(message) {
626
679
  throw new UsageError(message);
627
680
  }
628
681
 
629
- class HelpShown extends Exit {
630
- constructor() {
631
- super("help shown", 0);
632
- }
633
- }
634
-
635
682
  class Completing {
636
683
  options;
637
684
  positionals;
@@ -642,11 +689,6 @@ class Completing {
642
689
  this.candidates = candidates;
643
690
  }
644
691
  }
645
- var completion = { active: false };
646
- var OUTPUT_OPTIONS = {
647
- color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
648
- plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
649
- };
650
692
  function applyOutput(color, plain, env = process9.env) {
651
693
  const when = plain === true ? "never" : color ?? "auto";
652
694
  if (when === "auto")
@@ -800,7 +842,6 @@ function parseError(error) {
800
842
  const message = upTo(error instanceof Error ? error.message : String(error), ". ");
801
843
  return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
802
844
  }
803
- var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
804
845
  function nearestOption(message, options, allowNegative) {
805
846
  const typed = UNKNOWN_OPTION.exec(message)?.[1];
806
847
  if (typed === undefined)
@@ -816,6 +857,694 @@ function nearestOption(message, options, allowNegative) {
816
857
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
817
858
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
818
859
  }
860
+ var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
861
+ var init_args = __esm(() => {
862
+ init_format();
863
+ init_help();
864
+ init_text2();
865
+ init_help();
866
+ init_input();
867
+ DASHES = /^-+/;
868
+ EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
869
+ Exit = class Exit extends Error {
870
+ code;
871
+ hint;
872
+ [EXIT] = true;
873
+ constructor(message, code, hint) {
874
+ super(message);
875
+ this.code = code;
876
+ this.hint = hint;
877
+ }
878
+ static [Symbol.hasInstance](value) {
879
+ if (this !== Exit)
880
+ return Function.prototype[Symbol.hasInstance].call(this, value);
881
+ return typeof value === "object" && value !== null && value[EXIT] === true;
882
+ }
883
+ };
884
+ UsageError = class UsageError extends Exit {
885
+ constructor(message, hint) {
886
+ super(message, 2, hint);
887
+ }
888
+ };
889
+ HelpShown = class HelpShown extends Exit {
890
+ constructor() {
891
+ super("help shown", 0);
892
+ }
893
+ };
894
+ completion = { active: false };
895
+ OUTPUT_OPTIONS = {
896
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
897
+ plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
898
+ };
899
+ UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
900
+ });
901
+
902
+ // ../kit/src/folders.ts
903
+ import { homedir as homedir3 } from "os";
904
+ import { join as join4 } from "path";
905
+ import process13 from "process";
906
+ function cacheFolder({ home = homedir3(), env = process13.env } = {}) {
907
+ return env.XDG_CACHE_HOME ?? join4(home, ".cache");
908
+ }
909
+ var SKIPPED_FOLDERS;
910
+ var init_folders = __esm(() => {
911
+ init_user_config();
912
+ SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
913
+ });
914
+
915
+ // ../kit/src/answers.ts
916
+ import { mkdirSync, readFileSync as readFileSync4, writeFileSync } from "fs";
917
+ import { dirname as dirname2, join as join5 } from "path";
918
+ function answersFile() {
919
+ return join5(cacheFolder(), "kaynooo-cli", "answers.json");
920
+ }
921
+ function stored() {
922
+ try {
923
+ const parsed = JSON.parse(readFileSync4(answersFile(), "utf-8"));
924
+ if (typeof parsed !== "object" || parsed === null)
925
+ return {};
926
+ return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
927
+ } catch {
928
+ return {};
929
+ }
930
+ }
931
+ function earlierAnswers(key) {
932
+ return stored()[key] ?? [];
933
+ }
934
+ function rememberAnswer(key, answer) {
935
+ const all = stored();
936
+ const file = answersFile();
937
+ all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
938
+ try {
939
+ mkdirSync(dirname2(file), { recursive: true });
940
+ writeFileSync(file, JSON.stringify(all));
941
+ } catch {}
942
+ }
943
+ var KEPT = 50;
944
+ var init_answers = __esm(() => {
945
+ init_folders();
946
+ });
947
+
948
+ // ../kit/src/job.ts
949
+ import process14 from "process";
950
+ function stopJob() {
951
+ process14.kill(0, "SIGTSTP");
952
+ }
953
+ var init_job = () => {};
954
+
955
+ // ../kit/src/picker/line.ts
956
+ function isEditKey(key) {
957
+ return EDIT_KEYS.has(key);
958
+ }
959
+ function endsKills(key) {
960
+ return typeof key !== "object" && !isEditKey(key);
961
+ }
962
+ function isWord(char) {
963
+ return char !== undefined && WORD_CHARACTER.test(char);
964
+ }
965
+ function wordStart(chars, from) {
966
+ let at = from;
967
+ while (at > 0 && !isWord(chars[at - 1]))
968
+ at--;
969
+ while (at > 0 && isWord(chars[at - 1]))
970
+ at--;
971
+ return at;
972
+ }
973
+ function wordEnd(chars, from) {
974
+ let at = from;
975
+ while (at < chars.length && !isWord(chars[at]))
976
+ at++;
977
+ while (at < chars.length && isWord(chars[at]))
978
+ at++;
979
+ return at;
980
+ }
981
+ function spacedStart(chars, from) {
982
+ let at = from;
983
+ while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
984
+ at--;
985
+ while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
986
+ at--;
987
+ return at;
988
+ }
989
+ function cut(chars, from, to) {
990
+ return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
991
+ }
992
+ function insert(chars, at, text) {
993
+ const typed = [...text];
994
+ return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
995
+ }
996
+ function editLine(line, key) {
997
+ const { killed = "", chained = false } = line;
998
+ const chars = [...line.text];
999
+ const at = Math.min(Math.max(line.caret, 0), chars.length);
1000
+ const edited = edit(chars, at, key, killed);
1001
+ if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
1002
+ return line.killed === undefined ? edited : { ...edited, killed };
1003
+ const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
1004
+ if (taken === "")
1005
+ return { ...edited, killed, chained };
1006
+ if (!chained)
1007
+ return { ...edited, killed: taken, chained: true };
1008
+ return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
1009
+ }
1010
+ function edit(chars, at, key, killed) {
1011
+ const text = chars.join("");
1012
+ if (typeof key === "object")
1013
+ return insert(chars, at, key.text);
1014
+ switch (key) {
1015
+ case "left":
1016
+ return { text, caret: Math.max(at - 1, 0) };
1017
+ case "right":
1018
+ return { text, caret: Math.min(at + 1, chars.length) };
1019
+ case "wordleft":
1020
+ return { text, caret: wordStart(chars, at) };
1021
+ case "wordright":
1022
+ return { text, caret: wordEnd(chars, at) };
1023
+ case "linestart":
1024
+ return { text, caret: 0 };
1025
+ case "lineend":
1026
+ return { text, caret: chars.length };
1027
+ case "erase":
1028
+ return cut(chars, Math.max(at - 1, 0), at);
1029
+ case "delete":
1030
+ return cut(chars, at, Math.min(at + 1, chars.length));
1031
+ case "word":
1032
+ return cut(chars, spacedStart(chars, at), at);
1033
+ case "killword":
1034
+ return cut(chars, wordStart(chars, at), at);
1035
+ case "killnext":
1036
+ return cut(chars, at, wordEnd(chars, at));
1037
+ case "clear":
1038
+ return cut(chars, 0, at);
1039
+ case "killend":
1040
+ return cut(chars, at, chars.length);
1041
+ case "yank":
1042
+ return insert(chars, at, killed);
1043
+ }
1044
+ }
1045
+ function visible({ text, caret }, room) {
1046
+ const chars = [...text];
1047
+ const at = Math.min(Math.max(caret, 0), chars.length);
1048
+ const cells = at === chars.length ? [...chars, " "] : chars;
1049
+ const widths = cells.map((char) => Bun.stringWidth(char));
1050
+ const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
1051
+ const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
1052
+ let start = at;
1053
+ let end = at + 1;
1054
+ while (start > 0 && fits(start - 1, end))
1055
+ start--;
1056
+ while (end < cells.length && fits(start, end + 1))
1057
+ end++;
1058
+ const left = start > 0 ? "\u2026" : "";
1059
+ const right = end < cells.length ? "\u2026" : "";
1060
+ return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
1061
+ }
1062
+ var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
1063
+ var init_line = __esm(() => {
1064
+ EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
1065
+ BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
1066
+ FORWARD_KILLS = new Set(["killnext", "killend"]);
1067
+ WORD_CHARACTER = /[\p{L}\p{N}_]/u;
1068
+ SPACE = /\s/;
1069
+ });
1070
+
1071
+ // ../kit/src/picker/score.ts
1072
+ function startsWord(text, index) {
1073
+ if (index === 0)
1074
+ return true;
1075
+ const before = text[index - 1];
1076
+ return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
1077
+ }
1078
+ function fuzzy(query, text) {
1079
+ if (query === "")
1080
+ return { score: 0, positions: [] };
1081
+ const exact = query !== query.toLowerCase();
1082
+ const needle = exact ? query : query.toLowerCase();
1083
+ const haystack = exact ? text : text.toLowerCase();
1084
+ if (haystack.length !== text.length || needle.length > haystack.length)
1085
+ return;
1086
+ const width = haystack.length;
1087
+ const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
1088
+ const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
1089
+ for (let j = 0;j < needle.length; j++) {
1090
+ let run = NONE;
1091
+ let runAt = -1;
1092
+ for (let i = j;i < width; i++) {
1093
+ if (j > 0 && i - 2 >= j - 1) {
1094
+ const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
1095
+ if (candidate > run) {
1096
+ run = candidate;
1097
+ runAt = i - 2;
1098
+ }
1099
+ }
1100
+ if (haystack[i] !== needle[j])
1101
+ continue;
1102
+ const here = MATCH + (startsWord(text, i) ? BOUNDARY : 0) + (i === 0 ? PREFIX : 0);
1103
+ if (j === 0) {
1104
+ best[0][i] = here - i * GAP;
1105
+ continue;
1106
+ }
1107
+ const joined = best[j - 1][i - 1] + CONSECUTIVE;
1108
+ const skipped = run - (i - 1) * GAP;
1109
+ if (joined > NONE && joined >= skipped) {
1110
+ best[j][i] = joined + here;
1111
+ from[j][i] = i - 1;
1112
+ } else if (skipped > NONE) {
1113
+ best[j][i] = skipped + here;
1114
+ from[j][i] = runAt;
1115
+ }
1116
+ }
1117
+ }
1118
+ const last = best[needle.length - 1];
1119
+ let end = -1;
1120
+ for (let i = 0;i < width; i++) {
1121
+ if (last[i] > NONE && (end === -1 || last[i] > last[end]))
1122
+ end = i;
1123
+ }
1124
+ if (end === -1)
1125
+ return;
1126
+ const positions = [];
1127
+ for (let j = needle.length - 1, i = end;j >= 0; j--) {
1128
+ positions.unshift(i);
1129
+ i = from[j][i];
1130
+ }
1131
+ return { score: last[end], positions };
1132
+ }
1133
+ function rank(query, lines) {
1134
+ if (query === "")
1135
+ return lines.map((_, index) => ({ index, positions: [] }));
1136
+ const found = [];
1137
+ for (const [index, line] of lines.entries()) {
1138
+ const match = fuzzy(query, line);
1139
+ if (match !== undefined)
1140
+ found.push({ index, positions: match.positions, score: match.score });
1141
+ }
1142
+ return found.sort((a, b) => b.score - a.score || lines[a.index].length - lines[b.index].length || a.index - b.index);
1143
+ }
1144
+ var MATCH = 16, CONSECUTIVE = 12, BOUNDARY = 10, PREFIX = 8, GAP = 1, BOUNDARY_AFTER, UPPER, LOWER, NONE;
1145
+ var init_score = __esm(() => {
1146
+ BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
1147
+ UPPER = /\p{Lu}/u;
1148
+ LOWER = /\p{Ll}/u;
1149
+ NONE = Number.NEGATIVE_INFINITY;
1150
+ });
1151
+
1152
+ // ../kit/src/picker/state.ts
1153
+ function repeat(value, count) {
1154
+ return Array.from({ length: count }).fill(value);
1155
+ }
1156
+ function styled(line) {
1157
+ let text = "";
1158
+ const styles = [];
1159
+ let active = "";
1160
+ let colored = false;
1161
+ let last = 0;
1162
+ function add(chunk) {
1163
+ const flat = chunk.replace(CONTROL2, " ");
1164
+ text += flat;
1165
+ colored ||= active !== "" && flat !== "";
1166
+ styles.push(...repeat(active, flat.length));
1167
+ }
1168
+ for (const found of line.matchAll(ANSI)) {
1169
+ add(line.slice(last, found.index));
1170
+ last = found.index + found[0].length;
1171
+ if (SGR.test(found[0]))
1172
+ active = RESET.test(found[0]) ? "" : active + found[0];
1173
+ }
1174
+ add(line.slice(last));
1175
+ return { text, styles: colored ? styles : undefined };
1176
+ }
1177
+ function lay(rows, searched) {
1178
+ const parsed = rows.map((row) => row.cells.map(styled));
1179
+ const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
1180
+ return parsed.map((cells, at) => {
1181
+ let text = "";
1182
+ const styles = [];
1183
+ let colored = false;
1184
+ let searchEnd = 0;
1185
+ for (const [column, cell] of cells.entries()) {
1186
+ const last = column === cells.length - 1;
1187
+ const shown = cells.length > 1 && last ? cell.text.trimEnd() : cell.text;
1188
+ text += shown;
1189
+ colored ||= cell.styles !== undefined;
1190
+ styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
1191
+ if (column < searched)
1192
+ searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
1193
+ if (!last) {
1194
+ const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
1195
+ text += " ".repeat(pad);
1196
+ styles.push(...repeat("", pad));
1197
+ }
1198
+ }
1199
+ return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
1200
+ });
1201
+ }
1202
+ function parseKeys(input, paste = { active: false }, ctrls = []) {
1203
+ const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
1204
+ return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
1205
+ const wheel = MOUSE.exec(sequence)?.[1];
1206
+ if (wheel !== undefined)
1207
+ return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
1208
+ const named = codes.get(sequence);
1209
+ const key = named === undefined ? KEYS[sequence] : { ctrl: named };
1210
+ if (sequence === PASTE_START || sequence === PASTE_END) {
1211
+ paste.active = sequence === PASTE_START;
1212
+ return [];
1213
+ }
1214
+ if (paste.active && (sequence === "\r" || sequence === `
1215
+ `))
1216
+ return [];
1217
+ if (key !== undefined)
1218
+ return [key];
1219
+ return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
1220
+ });
1221
+ }
1222
+ function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
1223
+ const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, caret: [...query].length, killed: "", chained: false, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
1224
+ return withRows(state, rows);
1225
+ }
1226
+ function withRows(state, rows, header = state.header) {
1227
+ const cells = rows.map((row) => typeof row === "string" ? { hidden: [], cells: [row] } : row);
1228
+ const laid = lay(cells, state.searched);
1229
+ const searchable = laid.map((row) => row.searchable);
1230
+ const matches = rank(state.query, searchable);
1231
+ return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
1232
+ }
1233
+ function withQuery(state, key) {
1234
+ const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
1235
+ return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
1236
+ }
1237
+ function move(state, by) {
1238
+ return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
1239
+ }
1240
+ function highlighted(state) {
1241
+ return state.matches[state.cursor]?.index;
1242
+ }
1243
+ function press(state, key) {
1244
+ if (state.done !== undefined)
1245
+ return state;
1246
+ if (state.chained && endsKills(key))
1247
+ state = { ...state, chained: false };
1248
+ if (state.help)
1249
+ return { ...state, help: false };
1250
+ if (typeof key === "object") {
1251
+ if ("text" in key)
1252
+ return withQuery(state, key);
1253
+ return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
1254
+ }
1255
+ if (isEditKey(key))
1256
+ return withQuery(state, key);
1257
+ switch (key) {
1258
+ case "up":
1259
+ return move(state, -1);
1260
+ case "down":
1261
+ return move(state, 1);
1262
+ case "pageup":
1263
+ return move(state, -state.page);
1264
+ case "pagedown":
1265
+ return move(state, state.page);
1266
+ case "home":
1267
+ return move(state, -state.matches.length);
1268
+ case "end":
1269
+ return move(state, state.matches.length);
1270
+ case "cancel":
1271
+ return { ...state, done: "cancel" };
1272
+ case "help":
1273
+ return { ...state, help: true };
1274
+ case "suspend":
1275
+ return state;
1276
+ case "enter":
1277
+ return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
1278
+ case "tab": {
1279
+ const at = highlighted(state);
1280
+ if (!state.multi || at === undefined)
1281
+ return state;
1282
+ const marked = new Set(state.marked);
1283
+ if (!marked.delete(at))
1284
+ marked.add(at);
1285
+ return move({ ...state, marked }, 1);
1286
+ }
1287
+ }
1288
+ }
1289
+ function chosen(state) {
1290
+ if (state.marked.size > 0)
1291
+ return state.rows.filter((_, index) => state.marked.has(index));
1292
+ const at = highlighted(state);
1293
+ return at === undefined ? [] : [state.rows[at]];
1294
+ }
1295
+ var CONTROL2, IS_CONTROL, SGR, RESET, COLUMN_GAP = 2, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS, CTRL_KEY;
1296
+ var init_state = __esm(() => {
1297
+ init_text2();
1298
+ init_line();
1299
+ init_score();
1300
+ CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
1301
+ IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
1302
+ SGR = /^\x1B\[[0-9;]*m$/;
1303
+ RESET = /^\x1B\[0?m$/;
1304
+ KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1305
+ MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
1306
+ KEYS = {
1307
+ "\x1B[A": "up",
1308
+ "\x1BOA": "up",
1309
+ "\x10": "up",
1310
+ "\x1B[B": "down",
1311
+ "\x1BOB": "down",
1312
+ "\x0E": "down",
1313
+ "\x1B[5~": "pageup",
1314
+ "\x1B[6~": "pagedown",
1315
+ "\x1B[H": "home",
1316
+ "\x1B[1~": "home",
1317
+ "\x1BOH": "home",
1318
+ "\x1B[F": "end",
1319
+ "\x1B[4~": "end",
1320
+ "\x1BOF": "end",
1321
+ "\r": "enter",
1322
+ "\n": "enter",
1323
+ "\x03": "cancel",
1324
+ "\x1B": "cancel",
1325
+ "\x1B[D": "left",
1326
+ "\x1BOD": "left",
1327
+ "\x1B[C": "right",
1328
+ "\x1BOC": "right",
1329
+ "\x1B[1;5D": "wordleft",
1330
+ "\x1B[1;3D": "wordleft",
1331
+ "\x1Bb": "wordleft",
1332
+ "\x1B[1;5C": "wordright",
1333
+ "\x1B[1;3C": "wordright",
1334
+ "\x1Bf": "wordright",
1335
+ "\x01": "linestart",
1336
+ "\x05": "lineend",
1337
+ "\x7F": "erase",
1338
+ "\x1B[3~": "delete",
1339
+ "\b": "killword",
1340
+ "\x1B\x7F": "killword",
1341
+ "\x1B[3;5~": "killnext",
1342
+ "\x1Bd": "killnext",
1343
+ "\x15": "clear",
1344
+ "\v": "killend",
1345
+ "\x17": "word",
1346
+ "\x19": "yank",
1347
+ "\x1A": "suspend",
1348
+ "\t": "tab",
1349
+ "\x1F": "help",
1350
+ "\x1BOP": "help",
1351
+ "\x1B[11~": "help"
1352
+ };
1353
+ CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
1354
+ });
1355
+
1356
+ // ../kit/src/redraw.ts
1357
+ function overwrite(lines, columns) {
1358
+ return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
1359
+ `);
1360
+ }
1361
+ function rowsTaken(lines, columns) {
1362
+ return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
1363
+ }
1364
+ var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
1365
+ var init_redraw = __esm(() => {
1366
+ init_format();
1367
+ });
1368
+
1369
+ // ../kit/src/prompt.ts
1370
+ import process15 from "process";
1371
+ function readKeys(input, paste = { active: false }) {
1372
+ return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
1373
+ }
1374
+ function roomAfter(question, columns) {
1375
+ return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
1376
+ }
1377
+ function withCaret(colors, line, room, dim = false) {
1378
+ const { before, at, after } = visible(line, room);
1379
+ const tone = dim ? colors.dim : (text) => text;
1380
+ return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
1381
+ }
1382
+ function sharedStart(texts) {
1383
+ const [first = [], ...rest] = texts.map((text) => [...text]);
1384
+ let length = first.length;
1385
+ for (const chars of rest) {
1386
+ const differs = chars.findIndex((char, index) => char !== first[index]);
1387
+ length = Math.min(length, differs === -1 ? chars.length : differs);
1388
+ }
1389
+ return first.slice(0, length).join("");
1390
+ }
1391
+ function listed2(colors, found, columns) {
1392
+ const shared = sharedStart(found);
1393
+ const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
1394
+ const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
1395
+ const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
1396
+ return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
1397
+ }
1398
+ async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
1399
+ let line = { text: "", caret: 0 };
1400
+ let invalid;
1401
+ let completions = [];
1402
+ const remembered = history === undefined || mask ? undefined : history;
1403
+ const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
1404
+ let recalled = -1;
1405
+ let draft = line;
1406
+ const taken = () => line.text === "" ? fallback ?? "" : line.text;
1407
+ const shown = () => mask ? "*".repeat([...taken()].length) : taken();
1408
+ const accepted = await ask(question, settings, (colors, state, { columns }) => {
1409
+ if (state !== "asking")
1410
+ return [answer(colors, question, state, shown())];
1411
+ const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
1412
+ return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
1413
+ }, (key) => {
1414
+ if (key === "cancel")
1415
+ return "cancel";
1416
+ invalid = undefined;
1417
+ completions = [];
1418
+ if (line.chained === true && endsKills(key))
1419
+ line = { ...line, chained: false };
1420
+ if (key === "tab") {
1421
+ const chars = [...line.text];
1422
+ const before = chars.slice(0, line.caret).join("");
1423
+ const found = complete?.(before) ?? [];
1424
+ const filled = sharedStart(found);
1425
+ if ([...filled].length > [...before].length)
1426
+ line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
1427
+ else
1428
+ completions = found;
1429
+ return;
1430
+ }
1431
+ if (key === "enter") {
1432
+ invalid = validate?.(taken());
1433
+ return invalid === undefined ? "enter" : undefined;
1434
+ }
1435
+ if (key === "up" || key === "down") {
1436
+ const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
1437
+ if (recalled === -1)
1438
+ draft = line;
1439
+ recalled = to;
1440
+ const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
1441
+ line = { ...shown, killed: line.killed ?? "" };
1442
+ return;
1443
+ }
1444
+ const edit = { home: "linestart", end: "lineend" }[key] ?? key;
1445
+ if (typeof edit === "object" || isEditKey(edit))
1446
+ line = editLine(line, edit);
1447
+ return;
1448
+ });
1449
+ if (!accepted)
1450
+ return;
1451
+ if (remembered !== undefined && taken() !== "")
1452
+ rememberAnswer(remembered, taken());
1453
+ return taken();
1454
+ }
1455
+ function answer(colors, question, state, picked) {
1456
+ return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
1457
+ }
1458
+ async function ask(question, { hint, terminal = process15 }, render, press) {
1459
+ const { stdin, stderr } = terminal;
1460
+ if (!isInteractive(terminal))
1461
+ fail(`cannot ask "${question}" off a terminal`, 2, hint);
1462
+ const colors = paint(stderr);
1463
+ let current = "asking";
1464
+ let outcome;
1465
+ const columns = () => stderr.columns || 80;
1466
+ const draw = (state, last = false) => {
1467
+ const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
1468
+ const rows = rowsTaken(frame, columns());
1469
+ stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
1470
+ current = state;
1471
+ };
1472
+ const redraw = () => draw(current);
1473
+ const paste = { active: false };
1474
+ const stop = terminal.stop ?? (terminal === process15 ? stopJob : undefined);
1475
+ const suspend = () => {
1476
+ if (stop === undefined)
1477
+ return;
1478
+ stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
1479
+ stdin.setRawMode(false);
1480
+ stop();
1481
+ stdin.setRawMode(true);
1482
+ stderr.write("\x1B[?25l\x1B[?2004h");
1483
+ };
1484
+ try {
1485
+ stderr.on?.("resize", redraw);
1486
+ stdin.setRawMode(true);
1487
+ stdin.resume();
1488
+ stderr.write("\x1B[?25l\x1B[?2004h");
1489
+ draw("asking");
1490
+ return await new Promise((resolve) => {
1491
+ function onData(data) {
1492
+ for (const key of readKeys(data.toString(), paste)) {
1493
+ if (key === "suspend") {
1494
+ suspend();
1495
+ continue;
1496
+ }
1497
+ const pressed = press(key);
1498
+ if (pressed !== undefined) {
1499
+ settle(pressed);
1500
+ return;
1501
+ }
1502
+ }
1503
+ draw("asking");
1504
+ }
1505
+ function onEnd() {
1506
+ settle("cancel");
1507
+ }
1508
+ function settle(settled) {
1509
+ outcome = settled;
1510
+ stdin.off("data", onData);
1511
+ stdin.off("end", onEnd);
1512
+ resolve(settled === "enter");
1513
+ }
1514
+ stdin.on("data", onData);
1515
+ stdin.on("end", onEnd);
1516
+ });
1517
+ } finally {
1518
+ stderr.off?.("resize", redraw);
1519
+ draw(outcome ?? "cancel", true);
1520
+ stderr.write(`
1521
+ \x1B[?25h\x1B[?2004l`);
1522
+ stdin.setRawMode(false);
1523
+ stdin.pause();
1524
+ }
1525
+ }
1526
+ var PROMPT_KEYS, MAX_LISTED = 12;
1527
+ var init_prompt = __esm(() => {
1528
+ init_answers();
1529
+ init_args();
1530
+ init_format();
1531
+ init_job();
1532
+ init_mode();
1533
+ init_line();
1534
+ init_state();
1535
+ init_redraw();
1536
+ init_style();
1537
+ PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
1538
+ });
1539
+
1540
+ // src/gu.ts
1541
+ import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "fs";
1542
+ import { join as join10, resolve as resolve5 } from "path";
1543
+ import process23 from "process";
1544
+
1545
+ // ../kit/src/index.ts
1546
+ init_args();
1547
+
819
1548
  // ../kit/src/argv.ts
820
1549
  import { readFileSync as readFileSync3, realpathSync } from "fs";
821
1550
  import { resolve as resolve3 } from "path";
@@ -840,7 +1569,17 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
840
1569
  const after = at === -1 ? [] : cmdline.slice(at + 1);
841
1570
  return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
842
1571
  }
1572
+ // ../kit/src/chart.ts
1573
+ init_format();
1574
+ init_mode();
1575
+ init_style();
1576
+ init_theme();
1577
+ // ../kit/src/ci.ts
1578
+ init_args();
1579
+ init_format();
1580
+
843
1581
  // ../kit/src/progress.ts
1582
+ init_format();
844
1583
  import process12 from "process";
845
1584
 
846
1585
  // ../kit/src/process.ts
@@ -886,10 +1625,10 @@ function holdSignals(cleanup) {
886
1625
  process11.on(signal, onSignal);
887
1626
  return held;
888
1627
  }
889
- async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
1628
+ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
890
1629
  const chunks = [];
891
1630
  const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
892
- const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
1631
+ 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 } : {} });
893
1632
  const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
894
1633
  const timers = [];
895
1634
  const killGroup = (killing) => {
@@ -966,6 +1705,8 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
966
1705
  }
967
1706
 
968
1707
  // ../kit/src/progress.ts
1708
+ init_style();
1709
+ init_theme();
969
1710
  var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
970
1711
  var FRAME_MS = 200;
971
1712
  var BAR_WIDTH = 20;
@@ -983,10 +1724,14 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
983
1724
  }, print: (text) => void stream.write(`${text}
984
1725
  `), stop: () => {
985
1726
  return;
1727
+ }, pause: () => () => {
1728
+ return;
986
1729
  } };
987
1730
  const write = stream.write.bind(stream);
988
1731
  let frame = 0;
989
1732
  let drawn = false;
1733
+ let paused = false;
1734
+ let stopped = false;
990
1735
  const columns = () => {
991
1736
  const now = stream.getWindowSize?.()[0] ?? stream.columns;
992
1737
  return now === undefined || now === 0 ? 80 : now;
@@ -997,6 +1742,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
997
1742
  drawn = false;
998
1743
  };
999
1744
  const draw = () => {
1745
+ if (paused)
1746
+ return;
1000
1747
  const width = columns() - 1;
1001
1748
  const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
1002
1749
  const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
@@ -1008,16 +1755,17 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1008
1755
  `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
1009
1756
  drawn = true;
1010
1757
  };
1011
- const timer = setInterval(draw, FRAME_MS);
1758
+ let timer = setInterval(draw, FRAME_MS);
1012
1759
  stream.on?.("resize", draw);
1013
- const restore = interceptOutput(clear);
1014
- const release = swallowInput();
1760
+ let restore = interceptOutput(clear);
1761
+ let release = swallowInput();
1015
1762
  const onExit = () => {
1016
1763
  clear();
1017
1764
  release();
1018
1765
  };
1019
1766
  const signals = holdSignals(stop);
1020
1767
  function stop() {
1768
+ stopped = true;
1021
1769
  clearInterval(timer);
1022
1770
  stream.off?.("resize", draw);
1023
1771
  clear();
@@ -1026,6 +1774,29 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1026
1774
  process12.off("exit", onExit);
1027
1775
  signals.release();
1028
1776
  }
1777
+ function pause() {
1778
+ if (paused || stopped)
1779
+ return () => {
1780
+ return;
1781
+ };
1782
+ paused = true;
1783
+ clearInterval(timer);
1784
+ stream.off?.("resize", draw);
1785
+ clear();
1786
+ restore();
1787
+ release();
1788
+ return () => {
1789
+ if (!paused || stopped)
1790
+ return;
1791
+ paused = false;
1792
+ timer = setInterval(draw, FRAME_MS);
1793
+ timer.unref();
1794
+ stream.on?.("resize", draw);
1795
+ restore = interceptOutput(clear);
1796
+ release = swallowInput();
1797
+ draw();
1798
+ };
1799
+ }
1029
1800
  timer.unref();
1030
1801
  process12.on("exit", onExit);
1031
1802
  return {
@@ -1036,7 +1807,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1036
1807
  `);
1037
1808
  draw();
1038
1809
  },
1039
- stop
1810
+ stop,
1811
+ pause
1040
1812
  };
1041
1813
  }
1042
1814
  function progressLine(stream = process12.stderr, env = process12.env) {
@@ -1061,6 +1833,7 @@ function progressLine(stream = process12.stderr, env = process12.env) {
1061
1833
  }
1062
1834
  },
1063
1835
  stop: region.stop,
1836
+ pause: region.pause,
1064
1837
  done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
1065
1838
  failed: (text) => end(marked("problem", text, stream, undefined, env))
1066
1839
  };
@@ -1149,10 +1922,127 @@ function interceptOutput(clear) {
1149
1922
  }
1150
1923
  };
1151
1924
  }
1925
+
1926
+ // ../kit/src/ci.ts
1927
+ init_style();
1928
+
1929
+ // ../kit/src/tool.ts
1930
+ init_format();
1152
1931
  // ../kit/src/cli.ts
1153
- import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1154
- import { dirname as dirname3, join as join5 } from "path";
1155
- import process15 from "process";
1932
+ init_args();
1933
+ import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
1934
+ import { dirname as dirname4, join as join8 } from "path";
1935
+ import process19 from "process";
1936
+
1937
+ // ../kit/src/askpass.ts
1938
+ import { chmodSync, mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
1939
+ import { tmpdir } from "os";
1940
+ import { join as join6 } from "path";
1941
+ import process16 from "process";
1942
+ var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1943
+ var ECHOED = /username|yes\/no/i;
1944
+ var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1945
+ function askpass(pause = () => () => {
1946
+ return;
1947
+ }) {
1948
+ if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1949
+ return;
1950
+ const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1951
+ const socketPath = join6(dir, "socket");
1952
+ const script = join6(dir, "askpass");
1953
+ let turn = Promise.resolve();
1954
+ const answer = async ({ prompt, notice }) => {
1955
+ const resume = pause();
1956
+ try {
1957
+ if (notice === true) {
1958
+ process16.stderr.write(`${prompt.trim()}
1959
+ `);
1960
+ return {};
1961
+ }
1962
+ await Promise.resolve().then(() => init_prompt());
1963
+ return { answer: await input2(prompt.trim(), { mask: !ECHOED.test(prompt) }) };
1964
+ } finally {
1965
+ resume();
1966
+ }
1967
+ };
1968
+ const respond = async (socket, request) => {
1969
+ const { promise, resolve } = Promise.withResolvers();
1970
+ const previous = turn;
1971
+ let reply = {};
1972
+ turn = promise;
1973
+ await previous;
1974
+ try {
1975
+ reply = await answer(request);
1976
+ } catch {} finally {
1977
+ socket.end(`${JSON.stringify(reply)}
1978
+ `);
1979
+ resolve();
1980
+ }
1981
+ };
1982
+ const server = Bun.listen({
1983
+ unix: socketPath,
1984
+ socket: {
1985
+ open: (socket) => {
1986
+ socket.data = { buffered: "" };
1987
+ },
1988
+ data: (socket, chunk) => {
1989
+ const before = socket.data.buffered;
1990
+ socket.data.buffered += chunk.toString();
1991
+ if (before.includes(`
1992
+ `) || !socket.data.buffered.includes(`
1993
+ `))
1994
+ return;
1995
+ respond(socket, JSON.parse(socket.data.buffered));
1996
+ }
1997
+ }
1998
+ });
1999
+ writeFileSync2(script, `#!/bin/sh
2000
+ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no-env-file --config=/dev/null ${quoted(process16.argv[1])} "$@"
2001
+ `);
2002
+ chmodSync(script, 448);
2003
+ return {
2004
+ env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
2005
+ close: () => {
2006
+ server.stop(true);
2007
+ rmSync(dir, { recursive: true, force: true });
2008
+ }
2009
+ };
2010
+ }
2011
+ async function askpassClient(argv) {
2012
+ const socketPath = process16.env[SOCKET_VARIABLE];
2013
+ if (socketPath === undefined)
2014
+ return;
2015
+ const request = { prompt: argv[0] ?? "", ...process16.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
2016
+ const { promise, resolve } = Promise.withResolvers();
2017
+ let received = "";
2018
+ try {
2019
+ await Bun.connect({
2020
+ unix: socketPath,
2021
+ socket: {
2022
+ open: (socket) => void socket.write(`${JSON.stringify(request)}
2023
+ `),
2024
+ data: (_, chunk) => {
2025
+ received += chunk.toString();
2026
+ },
2027
+ close: () => resolve(received),
2028
+ error: () => resolve("")
2029
+ }
2030
+ });
2031
+ } catch {
2032
+ return 1;
2033
+ }
2034
+ const reply = await promise;
2035
+ if (reply === "")
2036
+ return 1;
2037
+ const { answer } = JSON.parse(reply);
2038
+ if (request.notice === true)
2039
+ return 0;
2040
+ if (answer === undefined)
2041
+ return 1;
2042
+ process16.stdout.write(`${answer}
2043
+ `);
2044
+ return 0;
2045
+ }
1156
2046
 
1157
2047
  // ../kit/src/completions.ts
1158
2048
  var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
@@ -1215,28 +2105,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
1215
2105
  }
1216
2106
 
1217
2107
  // ../kit/src/notify.ts
1218
- import process13 from "process";
2108
+ init_format();
2109
+ init_mode();
2110
+ import process17 from "process";
1219
2111
  var NOTIFY_AFTER_MS = 1e4;
1220
2112
  var CANCELLED = 130;
1221
2113
  function base64(text) {
1222
2114
  return Buffer.from(text).toString("base64");
1223
2115
  }
1224
- function notification(title, body, env = process13.env) {
1225
- const id = `kit${process13.pid}`;
2116
+ function notification(title, body, env = process17.env) {
2117
+ const id = `kit${process17.pid}`;
1226
2118
  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\\`];
1227
2119
  return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
1228
2120
  }
1229
- function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
2121
+ function notifyEnd(command, code, ms, { stream = process17.stderr, env = process17.env } = {}) {
1230
2122
  if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
1231
2123
  return;
1232
2124
  stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
1233
2125
  }
1234
2126
 
2127
+ // ../kit/src/cli.ts
2128
+ init_style();
2129
+ init_text2();
2130
+
1235
2131
  // ../kit/src/usage.ts
1236
- import { appendFileSync, mkdirSync } from "fs";
1237
- import { homedir as homedir3 } from "os";
1238
- import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1239
- import process14 from "process";
2132
+ import { appendFileSync, mkdirSync as mkdirSync2 } from "fs";
2133
+ import { homedir as homedir4 } from "os";
2134
+ import { dirname as dirname3, isAbsolute, join as join7 } from "path";
2135
+ import process18 from "process";
1240
2136
 
1241
2137
  // ../kit/src/logs.ts
1242
2138
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -1250,14 +2146,14 @@ var usageError;
1250
2146
  function noteUsageError(message) {
1251
2147
  usageError = message;
1252
2148
  }
1253
- function stateHome(env = process14.env) {
2149
+ function stateHome(env = process18.env) {
1254
2150
  const dir = env.XDG_STATE_HOME;
1255
- return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
2151
+ return dir !== undefined && isAbsolute(dir) ? dir : join7(homedir4(), ".local", "state");
1256
2152
  }
1257
- function usagePath(env = process14.env) {
1258
- return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
2153
+ function usagePath(env = process18.env) {
2154
+ return join7(stateHome(env), CLI_FOLDER, "usage.jsonl");
1259
2155
  }
1260
- function usageRecorded(env = process14.env) {
2156
+ function usageRecorded(env = process18.env) {
1261
2157
  const off = env.KAYNOOO_CLI_NO_USAGE;
1262
2158
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1263
2159
  }
@@ -1266,17 +2162,17 @@ function flagNames(argv) {
1266
2162
  const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
1267
2163
  return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
1268
2164
  }
1269
- function usageEntry(bin, command, argv, code, now = new Date) {
2165
+ function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
1270
2166
  const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
1271
2167
  usageError = undefined;
1272
- return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
2168
+ return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
1273
2169
  }
1274
- function recordUsage(entry, env = process14.env) {
2170
+ function recordUsage(entry, env = process18.env) {
1275
2171
  if (!usageRecorded(env))
1276
2172
  return;
1277
2173
  try {
1278
2174
  const path = usagePath(env);
1279
- mkdirSync(dirname2(path), { recursive: true, mode: 448 });
2175
+ mkdirSync2(dirname3(path), { recursive: true, mode: 448 });
1280
2176
  appendFileSync(path, `${JSON.stringify(entry)}
1281
2177
  `, { mode: 384 });
1282
2178
  } catch {}
@@ -1293,8 +2189,8 @@ var TOP_OPTIONS = {
1293
2189
  completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1294
2190
  };
1295
2191
  function printError(prefix, message, hint, cause) {
1296
- const colors = paint(process15.stderr);
1297
- const styled = takesControlCodes(process15.stderr);
2192
+ const colors = paint(process19.stderr);
2193
+ const styled = takesControlCodes(process19.stderr);
1298
2194
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1299
2195
  const under = (label, text, tint) => text === undefined ? "" : `
1300
2196
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1397,17 +2293,20 @@ function packageVersion(entry = Bun.main) {
1397
2293
  try {
1398
2294
  resolved = realpathSync2(entry);
1399
2295
  } catch {}
1400
- for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
2296
+ for (let dir = dirname4(resolved);; dir = dirname4(dir)) {
1401
2297
  try {
1402
- const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
2298
+ const { version } = JSON.parse(readFileSync5(join8(dir, "package.json"), "utf8"));
1403
2299
  if (typeof version === "string")
1404
2300
  return version;
1405
2301
  } catch {}
1406
- if (dirname3(dir) === dir)
2302
+ if (dirname4(dir) === dir)
1407
2303
  return "0.0.0";
1408
2304
  }
1409
2305
  }
1410
2306
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
2307
+ const answered = await askpassClient(argv);
2308
+ if (answered !== undefined)
2309
+ return answered;
1411
2310
  if (argv[0] === COMPLETE)
1412
2311
  return printCandidates(leafCandidates(run, argv.slice(1)));
1413
2312
  if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
@@ -1426,21 +2325,51 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
1426
2325
  notifyEnd(name, code, performance.now() - started);
1427
2326
  if (usage !== false) {
1428
2327
  try {
1429
- recordUsage(usageEntry(name, undefined, argv, code));
2328
+ recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
1430
2329
  } catch {}
1431
2330
  }
1432
2331
  return code;
1433
2332
  }
1434
- // ../kit/src/folders.ts
1435
- var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
2333
+
2334
+ // ../kit/src/index.ts
2335
+ init_config();
2336
+
2337
+ // ../kit/src/excerpt.ts
2338
+ init_text2();
2339
+
2340
+ // ../kit/src/index.ts
2341
+ init_folders();
2342
+ init_format();
2343
+
2344
+ // ../kit/src/git.ts
2345
+ init_args();
2346
+ // ../kit/src/limit.ts
2347
+ init_args();
2348
+
2349
+ // ../kit/src/index.ts
2350
+ init_mode();
2351
+
2352
+ // ../kit/src/report.ts
2353
+ init_style();
2354
+ init_text2();
1436
2355
  // ../kit/src/secrets.ts
1437
2356
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1438
2357
  // ../kit/src/sessions.ts
1439
2358
  var {Glob } = globalThis.Bun;
1440
2359
  var SESSION_FILES = new Glob("*.json");
1441
2360
  var ACCOUNT_DIRS = new Glob("*/sessions");
2361
+
2362
+ // ../kit/src/index.ts
2363
+ init_style();
2364
+ init_text2();
2365
+ init_theme();
2366
+ init_user_config();
2367
+
1442
2368
  // ../kit/src/watch.ts
1443
- import process16 from "process";
2369
+ init_args();
2370
+ init_input();
2371
+ init_style();
2372
+ import process20 from "process";
1444
2373
  import { format } from "util";
1445
2374
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1446
2375
  var DEFAULT_SECONDS = 2;
@@ -1462,7 +2391,7 @@ function withoutWatch(args) {
1462
2391
  }
1463
2392
  return rest;
1464
2393
  }
1465
- async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
2394
+ async function watching(value, step, stream = process20.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1466
2395
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1467
2396
  if (!takesControlCodes(stream))
1468
2397
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1470,12 +2399,12 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
1470
2399
  for (let round = 0;round < rounds; round++) {
1471
2400
  const held = [];
1472
2401
  const { log, info } = console;
1473
- const write = process16.stdout.write.bind(process16.stdout);
2402
+ const write = process20.stdout.write.bind(process20.stdout);
1474
2403
  const hold = (...parts) => void held.push(`${format(...parts)}
1475
2404
  `);
1476
2405
  console.log = hold;
1477
2406
  console.info = hold;
1478
- process16.stdout.write = (text) => {
2407
+ process20.stdout.write = (text) => {
1479
2408
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1480
2409
  return true;
1481
2410
  };
@@ -1484,7 +2413,7 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
1484
2413
  } finally {
1485
2414
  console.log = log;
1486
2415
  console.info = info;
1487
- process16.stdout.write = write;
2416
+ process20.stdout.write = write;
1488
2417
  }
1489
2418
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1490
2419
  await sleep(interval);
@@ -1492,21 +2421,22 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
1492
2421
  return code;
1493
2422
  }
1494
2423
  // ../kit/src/workspace-root.ts
1495
- import { homedir as homedir4 } from "os";
1496
- import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1497
- import process17 from "process";
2424
+ init_user_config();
2425
+ import { homedir as homedir5 } from "os";
2426
+ import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
2427
+ import process21 from "process";
1498
2428
  function expandHome(path, home) {
1499
2429
  if (path === "~")
1500
2430
  return home;
1501
- return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
2431
+ return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
1502
2432
  }
1503
2433
  function configured(env, home) {
1504
2434
  const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1505
2435
  return typeof folder === "string" && folder !== "" ? folder : undefined;
1506
2436
  }
1507
- function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
2437
+ function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
1508
2438
  const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1509
- return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
2439
+ return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
1510
2440
  }
1511
2441
  // src/git.ts
1512
2442
  async function git2(args, env) {
@@ -1518,15 +2448,15 @@ async function git2(args, env) {
1518
2448
  // src/gu.ts
1519
2449
  var USAGE = `gu <path>...: undoes changes to the paths given, keeping what it takes away
1520
2450
 
1521
- By default it discards the unstaged changes of the tracked paths, after saving them as a patch in the git folder (gu/<time>.patch) that \`git apply\` puts back. --staged unstages the paths and loses nothing. --commit undoes the last commit, its changes left staged, and refuses a commit that is already on the upstream or a merge.
1522
- Nothing is discarded without a path: gu alone is a usage error, never "everything". A path with no change is refused with nothing done.`;
2451
+ By default it discards the unstaged changes of the tracked paths, after saving them as a patch in the git folder (\`gu/<time>.patch\`) that \`git apply\` puts back. --staged unstages the paths. --commit undoes the last commit, its changes left staged, refusing one already on the upstream or a merge.
2452
+ Without a path it is a usage error, never "everything"; a path with no change is refused with nothing done.`;
1523
2453
  var EXITS = [[0, "it undid what was asked"], [1, "a path has no change, the commit is pushed or git refused"], [2, "a usage error or outside a git repository"]];
1524
2454
  var OPTIONS = {
1525
2455
  staged: { type: "boolean", short: "s", description: "unstage the paths, the working tree untouched" },
1526
2456
  commit: { type: "boolean", short: "c", description: "undo the last commit, keeping its changes staged" },
1527
2457
  json: jsonOption("{action, paths?, saved?, commit?} of what was undone, saved being the patch of a discard")
1528
2458
  };
1529
- var LITERAL = { ...process19.env, GIT_LITERAL_PATHSPECS: "1" };
2459
+ var LITERAL = { ...process23.env, GIT_LITERAL_PATHSPECS: "1" };
1530
2460
  var PLAIN_PATCH = ["--binary", "--no-ext-diff", "--no-textconv", "--no-color", "--no-relative", "--submodule=short", "--src-prefix=a/", "--dst-prefix=b/"];
1531
2461
  var NOT_A_REPOSITORY = /not a git repository/i;
1532
2462
  async function checked(args) {
@@ -1583,11 +2513,11 @@ async function main(argv) {
1583
2513
  return 0;
1584
2514
  }
1585
2515
  const patch = await checked(["diff", ...PLAIN_PATCH, "--", ...positionals]);
1586
- const folder = join7(resolve5((await checked(["rev-parse", "--git-dir"])).trim()), "gu");
1587
- const saved = join7(folder, `${new Date().toISOString().replaceAll(":", "-")}.patch`);
2516
+ const folder = join10(resolve5((await checked(["rev-parse", "--git-dir"])).trim()), "gu");
2517
+ const saved = join10(folder, `${new Date().toISOString().replaceAll(":", "-")}.patch`);
1588
2518
  const top = (await checked(["rev-parse", "--show-toplevel"])).trim();
1589
- mkdirSync2(folder, { recursive: true });
1590
- writeFileSync(saved, patch);
2519
+ mkdirSync3(folder, { recursive: true });
2520
+ writeFileSync3(saved, patch);
1591
2521
  const reverts = await git2(["-C", top, "apply", "--check", "--reverse", "--whitespace=nowarn", saved]);
1592
2522
  if (reverts.code !== 0)
1593
2523
  fail(`the patch saved to ${saved} would not put the change back, nothing discarded:
@@ -1599,4 +2529,4 @@ ${reverts.stderr.trim()}`, 1);
1599
2529
  console.log(`discarded ${paths.join(", ")}, saved to ${saved} (git apply puts it back)`);
1600
2530
  return 0;
1601
2531
  }
1602
- process19.exitCode = await runMain({ name: "gu", run: main });
2532
+ process23.exitCode = await runMain({ name: "gu", run: main });