@kaynooo/cli-code 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,21 +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/cli.ts
5
- import process19 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 ct = /[aeiou]y$/;
15
- var N = new Map;
16
- var Ot = /(?:leaf|loaf|thief|wolf|half|calf|elf|sheaf|scarf|dwarf|hoof|wharf)$/;
17
- var Gt = /(?:knife|life|wife)$/;
18
- function K(t, e, { plural: r, zero: n = "singular" } = {}) {
15
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
16
+ function G(t, e, { plural: r, zero: n = "singular" } = {}) {
19
17
  if (e === 1 || e === 0 && n === "singular")
20
18
  return t;
21
19
  if (r !== undefined)
@@ -28,12 +26,10 @@ function K(t, e, { plural: r, zero: n = "singular" } = {}) {
28
26
  return `${t.slice(0, -1)}ves`;
29
27
  return Gt.test(t) ? `${t.slice(0, -2)}ves` : `${t}s`;
30
28
  }
31
- function go(t, e, { zero: r = "plural", ...n } = {}) {
32
- return `${t} ${K(e, t, { ...n, zero: r })}`;
29
+ function bo(t, e, { zero: r = "plural", ...n } = {}) {
30
+ return `${t} ${G(e, t, { ...n, zero: r })}`;
33
31
  }
34
- var Nt = /\s+\S*$/;
35
- var Y = /\s/;
36
- function ko(t, e, r = "...") {
32
+ function Ao(t, e, r = "...") {
37
33
  let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
38
34
  if (t.length <= e)
39
35
  return t;
@@ -44,13 +40,25 @@ function ko(t, e, r = "...") {
44
40
  c = c.trimEnd();
45
41
  return s ? (c + n).slice(0, l) : c + n;
46
42
  }
47
- 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));
48
- var z = new Map;
43
+ var ct, N, Ot, Gt, Nt, Y, be, W;
44
+ var init_chunk_rkhsft4a = __esm(() => {
45
+ ct = /[aeiou]y$/;
46
+ N = new Map;
47
+ Ot = /(?:leaf|loaf|thief|wolf|half|calf|elf|sheaf|scarf|dwarf|hoof|wharf)$/;
48
+ Gt = /(?:knife|life|wife)$/;
49
+ Nt = /\s+\S*$/;
50
+ Y = /\s/;
51
+ 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));
52
+ W = new Map;
53
+ });
54
+
55
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
56
+ var init_text = __esm(() => {
57
+ init_chunk_rkhsft4a();
58
+ });
49
59
 
50
60
  // ../kit/src/mode.ts
51
61
  import process2 from "process";
52
- var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
53
- var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
54
62
  function isSet(value) {
55
63
  return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
56
64
  }
@@ -64,14 +72,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
64
72
  return "terminal";
65
73
  return isSet(env.CI) ? "ci" : "pipe";
66
74
  }
75
+ var MODES, AGENT_VARIABLES;
76
+ var init_mode = __esm(() => {
77
+ MODES = new Set(["terminal", "ci", "agent", "pipe"]);
78
+ AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
79
+ });
67
80
 
68
- // ../kit/src/style.ts
69
- import { resolve as resolve3 } from "path";
70
- import process6 from "process";
71
- import { pathToFileURL } from "url";
72
-
73
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
74
- var G2 = /^[a-f0-9]+$/i;
81
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
75
82
  function b(r) {
76
83
  let e = r.startsWith("#") ? r.slice(1) : r;
77
84
  if (!G2.test(e))
@@ -82,11 +89,6 @@ function b(r) {
82
89
  throw Error(`Invalid hex color length: ${e.length}`);
83
90
  return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
84
91
  }
85
- 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") => {
86
- let [l, n, c] = b(r);
87
- return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
88
- }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
89
- var h = new Set(["", "1", "2", "3", "true"]);
90
92
  function C(r, e = globalThis.process?.env ?? {}) {
91
93
  if (e.FORCE_COLOR !== undefined)
92
94
  return h.has(e.FORCE_COLOR);
@@ -100,7 +102,7 @@ function f(r, e = []) {
100
102
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
101
103
  let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
102
104
  return new Proxy(c, { get(t, i) {
103
- let a = B2[i];
105
+ let a = B[i];
104
106
  if (Array.isArray(a)) {
105
107
  let s = g.get(i);
106
108
  if (s === undefined)
@@ -123,13 +125,21 @@ function f(r, e = []) {
123
125
  function Fe(r = {}) {
124
126
  return f(r);
125
127
  }
126
- var o = Fe();
128
+ var G2, B, h, o;
129
+ var init_chunk_x450vn3m = __esm(() => {
130
+ G2 = /^[a-f0-9]+$/i;
131
+ 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") => {
132
+ let [l, n, c] = b(r);
133
+ return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
134
+ }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
135
+ h = new Set(["", "1", "2", "3", "true"]);
136
+ o = Fe();
137
+ });
127
138
 
128
- // ../kit/src/theme.ts
129
- import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
130
- import { homedir as homedir2 } from "os";
131
- import { join as join3, resolve as resolve2 } from "path";
132
- import process5 from "process";
139
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
140
+ var init_colors = __esm(() => {
141
+ init_chunk_x450vn3m();
142
+ });
133
143
 
134
144
  // ../kit/src/config.ts
135
145
  import { existsSync } from "fs";
@@ -145,6 +155,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
145
155
  return;
146
156
  }
147
157
  }
158
+ var init_config = __esm(() => {
159
+ init_args();
160
+ });
148
161
 
149
162
  // ../kit/src/user-config.ts
150
163
  import { existsSync as existsSync2, readFileSync } from "fs";
@@ -180,36 +193,49 @@ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
180
193
  const value = readUserConfig(bin, where, legacy)[key];
181
194
  return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
182
195
  }
196
+ var init_user_config = () => {};
183
197
 
184
198
  // ../kit/src/theme.ts
185
- var ENDS = new Map;
186
- var DEFAULT = {
187
- 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" },
188
- 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" },
189
- accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
190
- bins: {},
191
- gradient: ["#c084fc", "#67e8f9"]
192
- };
193
- 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" };
194
- 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" };
195
- var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
196
- var PRESETS = {
197
- default: {},
198
- "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
199
- mono: { colors: MONO, accents: ["bold"], gradient: undefined },
200
- ascii: { glyphs: ASCII }
201
- };
202
- 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"]);
203
- var HEX = /^#[0-9a-f]{6}$/i;
204
- var CONTROL = /\p{Cc}/u;
205
- var MAX_FILE_BYTES = 64 * 1024;
206
- var SPACES = /\s+/;
199
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
200
+ import { homedir as homedir2 } from "os";
201
+ import { join as join3, resolve as resolve2 } from "path";
202
+ import process5 from "process";
203
+ function toLinear(channel) {
204
+ const value = channel / 255;
205
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
206
+ }
207
+ function toOklab(hex) {
208
+ const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
209
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
210
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
211
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
212
+ return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
213
+ }
214
+ function fromOklab([lightness, a, b]) {
215
+ const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
216
+ const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
217
+ const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
218
+ 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];
219
+ return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
220
+ }
221
+ function gradientAt(theme, ratio) {
222
+ if (theme.gradient === undefined)
223
+ return;
224
+ const key = theme.gradient.join();
225
+ let ends = ENDS.get(key);
226
+ if (ends === undefined) {
227
+ ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
228
+ ENDS.set(key, ends);
229
+ }
230
+ const at = Math.min(1, Math.max(0, ratio));
231
+ const [from, to] = ends;
232
+ return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
233
+ }
207
234
  function isColorSpec(spec) {
208
235
  if (typeof spec === "number")
209
236
  return Number.isInteger(spec) && spec >= 0 && spec <= 255;
210
237
  return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
211
238
  }
212
- var CUBE = [0, 95, 135, 175, 215, 255];
213
239
  function cubeLevel(channel) {
214
240
  return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
215
241
  }
@@ -234,6 +260,9 @@ function tinted(colors, spec, env = process5.env) {
234
260
  return chain[token] ?? chain;
235
261
  }, colors);
236
262
  }
263
+ function shaded(theme, colors, glyph, cells, width, env = process5.env) {
264
+ return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
265
+ }
237
266
  function isRecord(value) {
238
267
  return typeof value === "object" && value !== null && !Array.isArray(value);
239
268
  }
@@ -314,7 +343,6 @@ function applyFile(theme, file, where, warn) {
314
343
  function endsWalk(home) {
315
344
  return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
316
345
  }
317
- var warned = new Set;
318
346
  function warnOnce(message) {
319
347
  if (warned.has(message))
320
348
  return;
@@ -351,8 +379,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
351
379
  }
352
380
  return { theme, sources, preset };
353
381
  }
354
- var current;
355
- var currentKey = "";
356
382
  function activeTheme() {
357
383
  const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
358
384
  if (current === undefined || key !== currentKey) {
@@ -361,9 +387,40 @@ function activeTheme() {
361
387
  }
362
388
  return current;
363
389
  }
390
+ 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 = "";
391
+ var init_theme = __esm(() => {
392
+ init_config();
393
+ init_user_config();
394
+ ENDS = new Map;
395
+ DEFAULT = {
396
+ 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" },
397
+ 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" },
398
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
399
+ bins: {},
400
+ gradient: ["#c084fc", "#67e8f9"]
401
+ };
402
+ 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" };
403
+ 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" };
404
+ ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
405
+ PRESETS = {
406
+ default: {},
407
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
408
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
409
+ ascii: { glyphs: ASCII }
410
+ };
411
+ 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"]);
412
+ HEX = /^#[0-9a-f]{6}$/i;
413
+ CONTROL = /\p{Cc}/u;
414
+ MAX_FILE_BYTES = 64 * 1024;
415
+ SPACES = /\s+/;
416
+ CUBE = [0, 95, 135, 175, 215, 255];
417
+ warned = new Set;
418
+ });
364
419
 
365
420
  // ../kit/src/style.ts
366
- var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
421
+ import { resolve as resolve3 } from "path";
422
+ import process6 from "process";
423
+ import { pathToFileURL } from "url";
367
424
  function takesControlCodes(stream, env = process6.env) {
368
425
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
369
426
  }
@@ -386,14 +443,6 @@ function role(name, stream, env = process6.env) {
386
443
  const colors = paint(stream, env);
387
444
  return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
388
445
  }
389
- var STATUS_WORDS = {
390
- passed: ["passed", "success", "succeeded", "ok"],
391
- failed: ["failed", "failure", "error", "errored"],
392
- running: ["running", "in_progress", "started", "holding"],
393
- queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
394
- skipped: ["skipped", "cancelled", "canceled", "manual"]
395
- };
396
- var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
397
446
  function header(bin, context, stream, env = process6.env) {
398
447
  if (!takesControlCodes(stream, env))
399
448
  return "";
@@ -420,9 +469,24 @@ function hyperlink(text, url, stream, env = process6.env) {
420
469
  function fileLink(text, path, stream, from = process6.cwd(), env = process6.env) {
421
470
  return hyperlink(text, pathToFileURL(resolve3(from, path)).href, stream, env);
422
471
  }
472
+ var MARK_WORDS, STATUS_WORDS, STATUS_OF;
473
+ var init_style = __esm(() => {
474
+ init_colors();
475
+ init_mode();
476
+ init_theme();
477
+ MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
478
+ STATUS_WORDS = {
479
+ passed: ["passed", "success", "succeeded", "ok"],
480
+ failed: ["failed", "failure", "error", "errored"],
481
+ running: ["running", "in_progress", "started", "holding"],
482
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
483
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
484
+ };
485
+ STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
486
+ });
423
487
 
424
488
  // ../kit/src/format.ts
425
- var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
489
+ import process7 from "process";
426
490
  function formatSeconds(total) {
427
491
  let rest = Math.max(0, Math.round(total));
428
492
  const amounts = UNITS.map(([unit, size]) => {
@@ -439,15 +503,16 @@ function formatSeconds(total) {
439
503
  function formatDuration(ms) {
440
504
  return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
441
505
  }
506
+ function formatElapsed(ms) {
507
+ return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
508
+ }
442
509
  function upTo(text, separator) {
443
510
  const end = text.indexOf(separator);
444
511
  return end === -1 ? text : text.slice(0, end);
445
512
  }
446
513
  function truncate(text, width) {
447
- return ko(text, width, { suffix: "\u2026", includeSuffix: true });
514
+ return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
448
515
  }
449
- var LINE_BREAKS = /\s*\n\s*/g;
450
- var ESCAPE = String.fromCharCode(27);
451
516
  function textWidth(text) {
452
517
  return Bun.stringWidth(text);
453
518
  }
@@ -496,12 +561,18 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
496
561
  function printJson(value) {
497
562
  console.log(jsonText(value));
498
563
  }
564
+ var UNITS, LINE_BREAKS, ESCAPE;
565
+ var init_format = __esm(() => {
566
+ init_text();
567
+ init_mode();
568
+ init_style();
569
+ UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
570
+ LINE_BREAKS = /\s*\n\s*/g;
571
+ ESCAPE = String.fromCharCode(27);
572
+ });
499
573
 
500
574
  // ../kit/src/help.ts
501
575
  import process8 from "process";
502
- var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
503
- var USAGE_PREFIX = /^usage:\s*/i;
504
- var FULL_STOP = /\.$/;
505
576
  function usageLine(usage, colors = paint(process8.stdout)) {
506
577
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
507
578
  }
@@ -538,7 +609,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
538
609
  return [];
539
610
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
540
611
  }
541
- var MAX_INLINE_CHOICES = 24;
542
612
  function optionRows(options, colors = paint(process8.stdout)) {
543
613
  const rows = Object.entries(options).map(([name, option]) => {
544
614
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
@@ -553,6 +623,14 @@ function optionRows(options, colors = paint(process8.stdout)) {
553
623
  const width = Math.max(0, ...rows.map((row) => row.width));
554
624
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
555
625
  }
626
+ var OPTIONAL, USAGE_PREFIX, FULL_STOP, MAX_INLINE_CHOICES = 24;
627
+ var init_help = __esm(() => {
628
+ init_mode();
629
+ init_style();
630
+ OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
631
+ USAGE_PREFIX = /^usage:\s*/i;
632
+ FULL_STOP = /\.$/;
633
+ });
556
634
 
557
635
  // ../kit/src/text.ts
558
636
  function distance(a, b) {
@@ -580,9 +658,10 @@ function closest(name, names) {
580
658
  const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
581
659
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
582
660
  }
661
+ var init_text2 = () => {};
662
+
583
663
  // ../kit/src/input.ts
584
664
  import { fstatSync } from "fs";
585
- var WHOLE = /^\d+$/;
586
665
  function wholeNumber(value, name, fallback, min = 1) {
587
666
  if (value === undefined)
588
667
  return fallback;
@@ -591,8 +670,6 @@ function wholeNumber(value, name, fallback, min = 1) {
591
670
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
592
671
  return number;
593
672
  }
594
- var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
595
- var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
596
673
  function duration(value, name, fallback, unit = "s") {
597
674
  if (value === undefined)
598
675
  return fallback;
@@ -606,40 +683,27 @@ function isStdinPiped() {
606
683
  const stat = fstatSync(0);
607
684
  return stat.isFIFO() || stat.isFile();
608
685
  }
686
+ var WHOLE, DURATION, UNIT_MS;
687
+ var init_input = __esm(() => {
688
+ init_args();
689
+ WHOLE = /^\d+$/;
690
+ DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
691
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
692
+ });
609
693
 
610
694
  // ../kit/src/args.ts
611
- var DASHES = /^-+/;
695
+ import process9 from "process";
696
+ import { parseArgs } from "util";
612
697
  function jsonOption(holds) {
613
698
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
614
699
  }
615
- class Exit extends Error {
616
- code;
617
- hint;
618
- constructor(message, code, hint) {
619
- super(message);
620
- this.code = code;
621
- this.hint = hint;
622
- }
623
- }
624
700
  function fail(message, code = 2, hint) {
625
701
  throw new Exit(message, code, hint);
626
702
  }
627
-
628
- class UsageError extends Exit {
629
- constructor(message, hint) {
630
- super(message, 2, hint);
631
- }
632
- }
633
703
  function badUsage(message) {
634
704
  throw new UsageError(message);
635
705
  }
636
706
 
637
- class HelpShown extends Exit {
638
- constructor() {
639
- super("help shown", 0);
640
- }
641
- }
642
-
643
707
  class Completing {
644
708
  options;
645
709
  positionals;
@@ -650,11 +714,6 @@ class Completing {
650
714
  this.candidates = candidates;
651
715
  }
652
716
  }
653
- var completion = { active: false };
654
- var OUTPUT_OPTIONS = {
655
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
656
- plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
657
- };
658
717
  function applyOutput(color, plain, env = process9.env) {
659
718
  const when = plain === true ? "never" : color ?? "auto";
660
719
  if (when === "auto")
@@ -808,7 +867,6 @@ function parseError(error) {
808
867
  const message = upTo(error instanceof Error ? error.message : String(error), ". ");
809
868
  return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
810
869
  }
811
- var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
812
870
  function nearestOption(message, options, allowNegative) {
813
871
  const typed = UNKNOWN_OPTION.exec(message)?.[1];
814
872
  if (typed === undefined)
@@ -824,6 +882,59 @@ function nearestOption(message, options, allowNegative) {
824
882
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
825
883
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
826
884
  }
885
+ var DASHES, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
886
+ var init_args = __esm(() => {
887
+ init_format();
888
+ init_help();
889
+ init_text2();
890
+ init_help();
891
+ init_input();
892
+ DASHES = /^-+/;
893
+ Exit = class Exit extends Error {
894
+ code;
895
+ hint;
896
+ constructor(message, code, hint) {
897
+ super(message);
898
+ this.code = code;
899
+ this.hint = hint;
900
+ }
901
+ };
902
+ UsageError = class UsageError extends Exit {
903
+ constructor(message, hint) {
904
+ super(message, 2, hint);
905
+ }
906
+ };
907
+ HelpShown = class HelpShown extends Exit {
908
+ constructor() {
909
+ super("help shown", 0);
910
+ }
911
+ };
912
+ completion = { active: false };
913
+ OUTPUT_OPTIONS = {
914
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
915
+ plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
916
+ };
917
+ UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
918
+ });
919
+
920
+ // ../kit/src/folders.ts
921
+ function ignoredFolders(extra = [], where = {}) {
922
+ const configured = readUserConfig("config", where).ignore;
923
+ const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
924
+ return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
925
+ }
926
+ var SKIPPED_FOLDERS;
927
+ var init_folders = __esm(() => {
928
+ init_user_config();
929
+ SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
930
+ });
931
+
932
+ // src/cli.ts
933
+ import process21 from "process";
934
+
935
+ // ../kit/src/index.ts
936
+ init_args();
937
+
827
938
  // ../kit/src/argv.ts
828
939
  import { readFileSync as readFileSync3, realpathSync } from "fs";
829
940
  import { resolve as resolve4 } from "path";
@@ -848,10 +959,24 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
848
959
  const after = at === -1 ? [] : cmdline.slice(at + 1);
849
960
  return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
850
961
  }
962
+ // ../kit/src/chart.ts
963
+ init_format();
964
+ init_mode();
965
+ init_style();
966
+ init_theme();
967
+ // ../kit/src/ci.ts
968
+ init_args();
969
+ init_format();
970
+
971
+ // ../kit/src/progress.ts
972
+ init_format();
973
+ import process12 from "process";
974
+
851
975
  // ../kit/src/process.ts
852
976
  import { constants } from "os";
853
977
  import process11 from "process";
854
978
  var KILL_GRACE_MS = 2000;
979
+ var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
855
980
  function exitCodeOf(code, signal) {
856
981
  if (code !== null)
857
982
  return code;
@@ -859,10 +984,41 @@ function exitCodeOf(code, signal) {
859
984
  return 128 + signal;
860
985
  return signal === null ? 129 : 128 + constants.signals[signal];
861
986
  }
862
- async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
987
+ function holdSignals(cleanup) {
988
+ let received;
989
+ let child;
990
+ const held = {
991
+ get signal() {
992
+ return received;
993
+ },
994
+ forward: (to) => {
995
+ child = to;
996
+ },
997
+ release: () => {
998
+ for (const signal of SIGNALS)
999
+ process11.off(signal, onSignal);
1000
+ }
1001
+ };
1002
+ function onSignal(signal) {
1003
+ received = signal;
1004
+ if (child !== undefined) {
1005
+ child.kill(signal);
1006
+ return;
1007
+ }
1008
+ if (cleanup === undefined)
1009
+ return;
1010
+ held.release();
1011
+ cleanup(signal);
1012
+ process11.kill(process11.pid, signal);
1013
+ }
1014
+ for (const signal of SIGNALS)
1015
+ process11.on(signal, onSignal);
1016
+ return held;
1017
+ }
1018
+ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
863
1019
  const chunks = [];
864
1020
  const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
865
- const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
1021
+ 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 } : {} });
866
1022
  const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
867
1023
  const timers = [];
868
1024
  const killGroup = (killing) => {
@@ -939,38 +1095,363 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
939
1095
  }
940
1096
 
941
1097
  // ../kit/src/progress.ts
1098
+ init_style();
1099
+ init_theme();
1100
+ var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
1101
+ var FRAME_MS = 200;
1102
+ var BAR_WIDTH = 20;
1103
+ var CLEAR_BELOW = "\r\x1B[J";
942
1104
  var ESC = String.fromCharCode(27);
943
1105
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
944
1106
  var RESET_STYLE = `${ESC}[0m`;
1107
+ var CTRL_C = 3;
945
1108
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
1109
+ var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
1110
+ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1111
+ if (!takesControlCodes(stream, env))
1112
+ return { redraw: () => {
1113
+ return;
1114
+ }, print: (text) => void stream.write(`${text}
1115
+ `), stop: () => {
1116
+ return;
1117
+ }, pause: () => () => {
1118
+ return;
1119
+ } };
1120
+ const write = stream.write.bind(stream);
1121
+ let frame = 0;
1122
+ let drawn = false;
1123
+ let paused = false;
1124
+ let stopped = false;
1125
+ const columns = () => {
1126
+ const now = stream.getWindowSize?.()[0] ?? stream.columns;
1127
+ return now === undefined || now === 0 ? 80 : now;
1128
+ };
1129
+ const clear = () => {
1130
+ if (drawn)
1131
+ write(CLEAR_BELOW);
1132
+ drawn = false;
1133
+ };
1134
+ const draw = () => {
1135
+ if (paused)
1136
+ return;
1137
+ const width = columns() - 1;
1138
+ const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
1139
+ const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
1140
+ if (lines.length === 0) {
1141
+ clear();
1142
+ return;
1143
+ }
1144
+ write(`${CLEAR_BELOW}${lines.join(`
1145
+ `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
1146
+ drawn = true;
1147
+ };
1148
+ let timer = setInterval(draw, FRAME_MS);
1149
+ stream.on?.("resize", draw);
1150
+ let restore = interceptOutput(clear);
1151
+ let release = swallowInput();
1152
+ const onExit = () => {
1153
+ clear();
1154
+ release();
1155
+ };
1156
+ const signals = holdSignals(stop);
1157
+ function stop() {
1158
+ stopped = true;
1159
+ clearInterval(timer);
1160
+ stream.off?.("resize", draw);
1161
+ clear();
1162
+ restore();
1163
+ release();
1164
+ process12.off("exit", onExit);
1165
+ signals.release();
1166
+ }
1167
+ function pause() {
1168
+ if (paused || stopped)
1169
+ return () => {
1170
+ return;
1171
+ };
1172
+ paused = true;
1173
+ clearInterval(timer);
1174
+ stream.off?.("resize", draw);
1175
+ clear();
1176
+ restore();
1177
+ release();
1178
+ return () => {
1179
+ if (!paused || stopped)
1180
+ return;
1181
+ paused = false;
1182
+ timer = setInterval(draw, FRAME_MS);
1183
+ timer.unref();
1184
+ stream.on?.("resize", draw);
1185
+ restore = interceptOutput(clear);
1186
+ release = swallowInput();
1187
+ draw();
1188
+ };
1189
+ }
1190
+ timer.unref();
1191
+ process12.on("exit", onExit);
1192
+ return {
1193
+ redraw: draw,
1194
+ print: (text) => {
1195
+ clear();
1196
+ write(`${text}
1197
+ `);
1198
+ draw();
1199
+ },
1200
+ stop,
1201
+ pause
1202
+ };
1203
+ }
1204
+ function progressLine(stream = process12.stderr, env = process12.env) {
1205
+ const colors = paint(stream, env);
1206
+ const write = stream.write.bind(stream);
1207
+ const begun = performance.now();
1208
+ let started = begun;
1209
+ let current;
1210
+ const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
1211
+ const end = (line) => {
1212
+ region.stop();
1213
+ write(`${line}
1214
+ `);
1215
+ };
1216
+ return {
1217
+ update: (progress) => {
1218
+ const step = current?.step;
1219
+ current = progress;
1220
+ if (progress.step !== step) {
1221
+ started = performance.now();
1222
+ region.redraw();
1223
+ }
1224
+ },
1225
+ stop: region.stop,
1226
+ pause: region.pause,
1227
+ done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
1228
+ failed: (text) => end(marked("problem", text, stream, undefined, env))
1229
+ };
1230
+ }
1231
+ function progressParts({ step, done, total, unit }, spinner, ms) {
1232
+ const { theme } = activeTheme();
1233
+ const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
1234
+ if (total !== undefined && total > 0) {
1235
+ const counted = Math.min(done ?? 0, total);
1236
+ const filled = Math.round(counted / total * BAR_WIDTH);
1237
+ parts.push({ text: " ", tint: () => plain }, { text: theme.glyphs.bar.repeat(filled), tint: (colors) => () => shaded(theme, colors, theme.glyphs.bar, filled, BAR_WIDTH) }, { text: theme.glyphs.bar.repeat(BAR_WIDTH - filled), tint: (colors) => colors.dim }, { text: ` ${counted}/${total}${unit === undefined ? "" : ` ${unit}`}`, tint: (colors) => colors.dim });
1238
+ }
1239
+ parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
1240
+ return parts;
1241
+ }
1242
+ function plain(text) {
1243
+ return text;
1244
+ }
1245
+ function tintedParts(parts, colors) {
1246
+ return parts.map(({ text, tint }) => tint(colors)(text)).join("");
1247
+ }
1248
+ function cutToWidth(line, width) {
1249
+ if (Bun.stringWidth(line) <= width)
1250
+ return line;
1251
+ let room = width;
1252
+ let kept = "";
1253
+ let index = 0;
1254
+ let linked = false;
1255
+ while (index < line.length) {
1256
+ ESCAPE_CODE.lastIndex = index;
1257
+ const escape = ESCAPE_CODE.exec(line);
1258
+ if (escape !== null) {
1259
+ kept += escape[0];
1260
+ linked ||= escape[0].startsWith(`${ESC}]`);
1261
+ index = ESCAPE_CODE.lastIndex;
1262
+ continue;
1263
+ }
1264
+ const char = String.fromCodePoint(line.codePointAt(index));
1265
+ const columns = Bun.stringWidth(char);
1266
+ if (columns > room)
1267
+ break;
1268
+ kept += char;
1269
+ room -= columns;
1270
+ index += char.length;
1271
+ }
1272
+ return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
1273
+ }
1274
+ function swallowInput() {
1275
+ const input = process12.stdin;
1276
+ if (!input.isTTY)
1277
+ return () => {
1278
+ return;
1279
+ };
1280
+ const onData = (data) => {
1281
+ if (data.includes(CTRL_C))
1282
+ process12.kill(process12.pid, "SIGINT");
1283
+ };
1284
+ input.setRawMode(true);
1285
+ input.on("data", onData);
1286
+ input.resume();
1287
+ let released = false;
1288
+ return () => {
1289
+ if (released)
1290
+ return;
1291
+ released = true;
1292
+ input.off("data", onData);
1293
+ input.pause();
1294
+ input.setRawMode(false);
1295
+ };
1296
+ }
1297
+ function interceptOutput(clear) {
1298
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
1299
+ const wrapped = targets.map(([target, name]) => {
1300
+ const original = Reflect.get(target, name);
1301
+ const wrapper = (...args) => {
1302
+ clear();
1303
+ return original.apply(target, args);
1304
+ };
1305
+ Reflect.set(target, name, wrapper);
1306
+ return { target, name, original, wrapper };
1307
+ });
1308
+ return () => {
1309
+ for (const { target, name, original, wrapper } of wrapped) {
1310
+ if (Reflect.get(target, name) === wrapper)
1311
+ Reflect.set(target, name, original);
1312
+ }
1313
+ };
1314
+ }
1315
+
1316
+ // ../kit/src/ci.ts
1317
+ init_style();
1318
+
1319
+ // ../kit/src/tool.ts
1320
+ init_format();
946
1321
  // ../kit/src/cli.ts
1322
+ init_args();
947
1323
  import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
948
1324
  import { dirname as dirname3, join as join5 } from "path";
949
- import process14 from "process";
1325
+ import process16 from "process";
1326
+
1327
+ // ../kit/src/askpass.ts
1328
+ import process13 from "process";
1329
+ var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1330
+ async function askpassClient(argv) {
1331
+ const socketPath = process13.env[SOCKET_VARIABLE];
1332
+ if (socketPath === undefined)
1333
+ return;
1334
+ const request = { prompt: argv[0] ?? "", ...process13.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
1335
+ const { promise, resolve } = Promise.withResolvers();
1336
+ let received = "";
1337
+ try {
1338
+ await Bun.connect({
1339
+ unix: socketPath,
1340
+ socket: {
1341
+ open: (socket) => void socket.write(`${JSON.stringify(request)}
1342
+ `),
1343
+ data: (_, chunk) => {
1344
+ received += chunk.toString();
1345
+ },
1346
+ close: () => resolve(received),
1347
+ error: () => resolve("")
1348
+ }
1349
+ });
1350
+ } catch {
1351
+ return 1;
1352
+ }
1353
+ const reply = await promise;
1354
+ if (reply === "")
1355
+ return 1;
1356
+ const { answer } = JSON.parse(reply);
1357
+ if (request.notice === true)
1358
+ return 0;
1359
+ if (answer === undefined)
1360
+ return 1;
1361
+ process13.stdout.write(`${answer}
1362
+ `);
1363
+ return 0;
1364
+ }
1365
+
1366
+ // ../kit/src/completions.ts
1367
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1368
+ 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'
1369
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1370
+ set -l current (commandline -ct)
1371
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1372
+ if test "$line" = __files__
1373
+ __fish_complete_path $current
1374
+ else
1375
+ echo $line
1376
+ end
1377
+ end
1378
+ end`;
1379
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1380
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1381
+ local -a lines
1382
+ COMPREPLY=()
1383
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1384
+ for line in "\${lines[@]}"; do
1385
+ if [[ $line == __files__ ]]; then
1386
+ COMPREPLY+=($(compgen -f -- "$cur"))
1387
+ else
1388
+ words+="\${line%%$'\\t'*}"$'\\n'
1389
+ fi
1390
+ done
1391
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1392
+ }`;
1393
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1394
+ local line
1395
+ local -a described plain
1396
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1397
+ if [[ $line == __files__ ]]; then
1398
+ _files
1399
+ elif [[ $line == *$'\\t'* ]]; then
1400
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1401
+ else
1402
+ plain+=("$line")
1403
+ fi
1404
+ done
1405
+ (( \${#described} )) && _describe -V value described
1406
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1407
+ return 0
1408
+ }`;
1409
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1410
+ if (shell === "fish")
1411
+ return `${header}
1412
+ ${FISH_FUNCTION}
1413
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1414
+ `).join("")}`;
1415
+ if (shell === "bash")
1416
+ return `${header}
1417
+ ${BASH_FUNCTION}
1418
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1419
+ `;
1420
+ return `${header}
1421
+ ${ZSH_FUNCTION}
1422
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1423
+ `;
1424
+ }
950
1425
 
951
1426
  // ../kit/src/notify.ts
952
- import process12 from "process";
1427
+ init_format();
1428
+ init_mode();
1429
+ import process14 from "process";
953
1430
  var NOTIFY_AFTER_MS = 1e4;
954
1431
  var CANCELLED = 130;
955
1432
  function base64(text) {
956
1433
  return Buffer.from(text).toString("base64");
957
1434
  }
958
- function notification(title, body, env = process12.env) {
959
- const id = `kit${process12.pid}`;
1435
+ function notification(title, body, env = process14.env) {
1436
+ const id = `kit${process14.pid}`;
960
1437
  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\\`];
961
1438
  return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
962
1439
  }
963
- function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
1440
+ function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
964
1441
  if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
965
1442
  return;
966
1443
  stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
967
1444
  }
968
1445
 
1446
+ // ../kit/src/cli.ts
1447
+ init_style();
1448
+ init_text2();
1449
+
969
1450
  // ../kit/src/usage.ts
970
1451
  import { appendFileSync, mkdirSync } from "fs";
971
1452
  import { homedir as homedir3 } from "os";
972
1453
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
973
- import process13 from "process";
1454
+ import process15 from "process";
974
1455
 
975
1456
  // ../kit/src/logs.ts
976
1457
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -984,14 +1465,14 @@ var usageError;
984
1465
  function noteUsageError(message) {
985
1466
  usageError = message;
986
1467
  }
987
- function stateHome(env = process13.env) {
1468
+ function stateHome(env = process15.env) {
988
1469
  const dir = env.XDG_STATE_HOME;
989
1470
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
990
1471
  }
991
- function usagePath(env = process13.env) {
1472
+ function usagePath(env = process15.env) {
992
1473
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
993
1474
  }
994
- function usageRecorded(env = process13.env) {
1475
+ function usageRecorded(env = process15.env) {
995
1476
  const off = env.KAYNOOO_CLI_NO_USAGE;
996
1477
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
997
1478
  }
@@ -1005,7 +1486,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1005
1486
  usageError = undefined;
1006
1487
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1007
1488
  }
1008
- function recordUsage(entry, env = process13.env) {
1489
+ function recordUsage(entry, env = process15.env) {
1009
1490
  if (!usageRecorded(env))
1010
1491
  return;
1011
1492
  try {
@@ -1021,7 +1502,11 @@ var LEVEL_OPTIONS = {
1021
1502
  ...OUTPUT_OPTIONS,
1022
1503
  help: { type: "boolean", short: "h", description: "show this help" }
1023
1504
  };
1024
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1505
+ var TOP_OPTIONS = {
1506
+ ...LEVEL_OPTIONS,
1507
+ version: { type: "boolean", short: "v", description: "print the version" },
1508
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1509
+ };
1025
1510
  async function commandRows(all, colors) {
1026
1511
  const commands = shown(all);
1027
1512
  const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
@@ -1095,8 +1580,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1095
1580
  `);
1096
1581
  }
1097
1582
  function printError(prefix, message, hint, cause) {
1098
- const colors = paint(process14.stderr);
1099
- const styled = takesControlCodes(process14.stderr);
1583
+ const colors = paint(process16.stderr);
1584
+ const styled = takesControlCodes(process16.stderr);
1100
1585
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1101
1586
  const under = (label, text, tint) => text === undefined ? "" : `
1102
1587
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1139,11 +1624,11 @@ async function dispatch(level, typed, { version, redact }) {
1139
1624
  }
1140
1625
  }
1141
1626
  if (name === undefined && level.path.length > 1) {
1142
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
1627
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stderr));
1143
1628
  return 2;
1144
1629
  }
1145
1630
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1146
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
1631
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stdout));
1147
1632
  return 0;
1148
1633
  }
1149
1634
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1254,6 +1739,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
1254
1739
  }
1255
1740
  return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
1256
1741
  }
1742
+ var COMPLETIONS = "--completions";
1743
+ function flagValue([flag = "", ...rest]) {
1744
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1745
+ }
1746
+ function printCompletionScript(name, args) {
1747
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1748
+ if (shell === undefined || args.length !== 1) {
1749
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1750
+ return 2;
1751
+ }
1752
+ console.log(completionScript(shell, [name]).trimEnd());
1753
+ return 0;
1754
+ }
1257
1755
  async function printCandidates(found) {
1258
1756
  for (const line of await found)
1259
1757
  console.log(line);
@@ -1276,8 +1774,13 @@ function packageVersion(entry = Bun.main) {
1276
1774
  }
1277
1775
  async function runCli(cli, argv = scriptArgs()) {
1278
1776
  const version = cli.version ?? packageVersion();
1777
+ const answered = await askpassClient(argv);
1778
+ if (answered !== undefined)
1779
+ return answered;
1279
1780
  if (argv[0] === COMPLETE)
1280
1781
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1782
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1783
+ return printCompletionScript(cli.name, flagValue(argv));
1281
1784
  const started = performance.now();
1282
1785
  const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
1283
1786
  const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
@@ -1304,36 +1807,21 @@ function commandPath(scope, argv) {
1304
1807
  }
1305
1808
  return path.length === 0 ? undefined : path.join(" ");
1306
1809
  }
1307
- async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1308
- if (argv[0] === COMPLETE)
1309
- return printCandidates(leafCandidates(run, argv.slice(1)));
1310
- if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1311
- console.log(version ?? packageVersion());
1312
- return 0;
1313
- }
1314
- let code;
1315
- const started = performance.now();
1316
- try {
1317
- code = await run(argv);
1318
- } catch (error) {
1319
- code = reportThrown(name, error, redact, wantsJson(argv));
1320
- }
1321
- notifyEnd(name, code, performance.now() - started);
1322
- if (usage !== false) {
1323
- try {
1324
- recordUsage(usageEntry(name, undefined, argv, code));
1325
- } catch {}
1326
- }
1327
- return code;
1328
- }
1329
- // ../kit/src/folders.ts
1330
- var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1331
- function ignoredFolders(extra = [], where = {}) {
1332
- const configured = readUserConfig("config", where).ignore;
1333
- const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
1334
- return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
1335
- }
1810
+
1811
+ // ../kit/src/index.ts
1812
+ init_config();
1813
+
1814
+ // ../kit/src/excerpt.ts
1815
+ init_text2();
1816
+
1817
+ // ../kit/src/index.ts
1818
+ init_folders();
1819
+ init_format();
1820
+
1821
+ // ../kit/src/git.ts
1822
+ init_args();
1336
1823
  // ../kit/src/limit.ts
1824
+ init_args();
1337
1825
  function limitOptions(fallback) {
1338
1826
  return {
1339
1827
  limit: { type: "string", short: "n", description: `show at most this many rows, the rest counted (${fallback})` },
@@ -1354,21 +1842,46 @@ function capped(rows, limit) {
1354
1842
  const more = rows.length - limit;
1355
1843
  return more > 0 ? { shown: rows.slice(0, limit), footer: moreFooter(more) } : { shown: [...rows], footer: undefined };
1356
1844
  }
1845
+
1846
+ // ../kit/src/index.ts
1847
+ init_mode();
1848
+
1849
+ // ../kit/src/report.ts
1850
+ init_style();
1851
+ init_text2();
1357
1852
  // ../kit/src/secrets.ts
1358
1853
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1359
1854
  // ../kit/src/sessions.ts
1360
1855
  var {Glob } = globalThis.Bun;
1361
1856
  var SESSION_FILES = new Glob("*.json");
1362
1857
  var ACCOUNT_DIRS = new Glob("*/sessions");
1858
+
1859
+ // ../kit/src/index.ts
1860
+ init_style();
1861
+ init_text2();
1862
+ init_theme();
1863
+ init_user_config();
1864
+
1865
+ // ../kit/src/watch.ts
1866
+ init_args();
1867
+ init_input();
1868
+ init_style();
1869
+ // ../kit/src/workspace-root.ts
1870
+ init_user_config();
1363
1871
  // src/hotspots.ts
1364
1872
  import { basename, join as join7 } from "path";
1365
- import process16 from "process";
1873
+ import process18 from "process";
1366
1874
 
1367
1875
  // src/churn.ts
1876
+ import { availableParallelism } from "os";
1368
1877
  var SOURCE = /\.(?:[cm]?[jt]sx?|vue|svelte|astro|kay|py|go|rs|rb|php|java|kt|swift|cs|c|cc|cpp|h|hpp|scala|dart|lua|sh|zsh|fish)$/;
1369
1878
  var TESTS = /(?:^|\/)(?:tests?|__tests__|spec|e2e|__mocks__|fixtures)\/|\.(?:test|spec|bench)\.[^/]+$|(?:^|\/)test_[^/]+$|_test\.(?:go|py)$/;
1370
1879
  var GENERATED = /(?:^|\/)(?:dist|build|out|generated|\.nuxt|\.output|\.next)\/|\.min\.[cm]?js$|\.d\.ts$|\.(?:generated|gen)\.[^/]+$|\.pb\.go$|\.snap$/;
1371
1880
  var LEADING_NEWLINE = /^\n/;
1881
+ var COMMITS_PER_RUN = 500;
1882
+ var MOST_RUNS = Math.max(1, Math.min(4, Math.floor(availableParallelism() / 2)));
1883
+ var COMMIT_START = 1;
1884
+ var LOG_FORMAT = ["--no-renames", "--numstat", "--format=%x01%ct%x02%ae", "-z"];
1372
1885
  var GENERATED_HEADER = /@generated|generated by|do not edit/i;
1373
1886
  var DECISION = /\b(?:if|elif|elsif|for|foreach|while|until|case|when|catch|except|rescue|match|guard|and|or)\b|&&|\|\||\?\?|\s\?(?![,):.?])/g;
1374
1887
  var COMMENT_OR_STRING = /(\/\*[\s\S]*?\*\/|\/\/[^\n]*|^[ \t]*#[^\n]*)|'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"|`(?:\\.|[^`\\])*`/gm;
@@ -1381,14 +1894,40 @@ function isGenerated(text) {
1381
1894
  function complexityOf(text) {
1382
1895
  return 1 + (text.replace(COMMENT_OR_STRING, (_, comment) => comment === undefined ? '""' : "").match(DECISION)?.length ?? 0);
1383
1896
  }
1384
- async function churnSince(cwd, since, { bulk, halfLifeMs, now = Date.now() }) {
1385
- const [log, top] = await Promise.all([runCommand(["git", "log", `--since=${since}`, "--no-renames", "--numstat", "--format=%x01%ct%x02%ae", "-z"], { cwd }), runCommand(["git", "rev-parse", "--show-prefix"], { cwd })]);
1386
- if (log.code !== 0 || top.code !== 0)
1897
+ async function readLog(cwd, commits, onProgress) {
1898
+ const runs = Math.min(MOST_RUNS, Math.ceil(commits.length / COMMITS_PER_RUN));
1899
+ const size = Math.ceil(commits.length / runs);
1900
+ let read = 0;
1901
+ const logs = await Promise.all(Array.from({ length: runs }, async (_, run) => runCommand(["git", "log", "--no-walk=unsorted", "--stdin", ...LOG_FORMAT], {
1902
+ cwd,
1903
+ input: `${commits.slice(run * size, (run + 1) * size).join(`
1904
+ `)}
1905
+ `,
1906
+ onChunk: ({ stream, data }) => {
1907
+ if (stream !== "stdout" || onProgress === undefined)
1908
+ return;
1909
+ for (const byte of data) {
1910
+ if (byte === COMMIT_START)
1911
+ read++;
1912
+ }
1913
+ onProgress(read, commits.length);
1914
+ }
1915
+ })));
1916
+ return logs.some((log) => log.code !== 0) ? undefined : logs.map((log) => log.text).join("");
1917
+ }
1918
+ async function churnSince(cwd, since, { bulk, halfLifeMs, now = Date.now(), onProgress }) {
1919
+ const [listed, top] = await Promise.all([runCommand(["git", "rev-list", `--since=${since}`, "HEAD"], { cwd }), runCommand(["git", "rev-parse", "--show-prefix"], { cwd })]);
1920
+ if (listed.code !== 0 || top.code !== 0)
1921
+ return;
1922
+ const commits = listed.text.split(`
1923
+ `).filter(Boolean);
1924
+ const log = commits.length === 0 ? "" : await readLog(cwd, commits, onProgress);
1925
+ if (log === undefined)
1387
1926
  return;
1388
1927
  const prefix = top.text.trim();
1389
1928
  const churn = new Map;
1390
1929
  const authors = new Map;
1391
- for (const commit of log.text.split("\x01").slice(1)) {
1930
+ for (const commit of log.split("\x01").slice(1)) {
1392
1931
  const [head = "", ...entries] = commit.split("\x00");
1393
1932
  const [stamp = "", author = ""] = head.split("\x02");
1394
1933
  const all = entries.map((entry) => entry.replace(LEADING_NEWLINE, "")).filter((entry) => entry !== "").map((entry) => {
@@ -1508,7 +2047,7 @@ var DEFAULT_BULK = configuredNumber("hotspots", "bulk", 25);
1508
2047
  var DAY_MS2 = 86400000;
1509
2048
  var DEFAULT_HALF_LIFE = "90d";
1510
2049
  var DEFAULT_COUNT = configuredNumber("hotspots", "limit", 20);
1511
- var USAGE = `hotspots [options] [dir]: ranks the source files under dir (here by default) by complexity times churn, the ones both hard to read and often edited first, honouring .gitignore
2050
+ var USAGE = `src hotspots [options] [dir]: ranks the source files under dir (here by default) by complexity times churn, the ones both hard to read and often edited first, honouring .gitignore
1512
2051
 
1513
2052
  Complexity is the count of decision points in the file (branches, loops, cases, catches, boolean operators, ternaries) plus one, churn the commits touching it since --since (${DEFAULT_SINCE}), score their product. A commit counts for less the older it is (half as much every --half-life, 0 for all alike) and a commit touching more than --bulk files, a format or rename sweep, is left out. --by-lines scores the lines changed instead of the commits. Each file also shows how many lines changed, its author count ("solo" when one author wrote every change) and its most complex declaration, found by indentation. Test files and generated or built files are left out unless --all.
1514
2053
 
@@ -1526,31 +2065,37 @@ var OPTIONS = {
1526
2065
  var HOT = 0.66;
1527
2066
  var WARM = 0.33;
1528
2067
  async function hotspots(args) {
1529
- const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[dir]"], replaces: "guessing which files are worth splitting first", examples: ["hotspots", 'hotspots src --since "3 months ago" --limit 10'] });
2068
+ const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[dir]"], replaces: "guessing which files are worth splitting first", examples: ["hotspots", 'src hotspots src --since "3 months ago" --limit 10'] });
1530
2069
  if (positionals.length > 1)
1531
2070
  badUsage("give one folder");
1532
2071
  const count = limitOf(values, DEFAULT_COUNT);
1533
- const cwd = process16.cwd();
2072
+ const cwd = process18.cwd();
1534
2073
  const bulk = Number(values.bulk ?? DEFAULT_BULK);
1535
2074
  if (!Number.isInteger(bulk) || bulk < 1)
1536
2075
  badUsage(`--bulk takes a number of files, not ${values.bulk}`);
1537
2076
  const halfLifeMs = values["half-life"] === "0" ? 0 : duration(values["half-life"], "half-life", 90 * DAY_MS2);
1538
- const churn = await churnSince(cwd, values.since ?? DEFAULT_SINCE, { bulk, halfLifeMs });
1539
- if (churn === undefined)
1540
- fail("not a git repository, churn comes from its log");
2077
+ const progress = progressLine();
1541
2078
  const ranked = [];
1542
- for (const path of await listFiles(positionals[0] === undefined ? [] : [positionals[0]], cwd)) {
1543
- const touched = churn.get(path);
1544
- if (touched === undefined || values.all !== true && !isCandidate(path))
1545
- continue;
1546
- const text = await readText(join7(cwd, path));
1547
- if (text === undefined || values.all !== true && isGenerated(text))
1548
- continue;
1549
- const complexity = complexityOf(text);
1550
- const worst = worstUnit(text, path);
1551
- ranked.push({ path, score: Math.round(complexity * (values["by-lines"] === true ? touched.linesWeight : touched.weight)), churn: touched.commits, recent: Math.round(touched.weight * 10) / 10, changed: touched.lines, authors: touched.authors, solo: touched.authors === 1, complexity, worst: worst === undefined ? undefined : { name: worst.name, line: worst.line, complexity: worst.complexity }, lines: text.split(`
2079
+ try {
2080
+ progress.update({ step: "reading the git log" });
2081
+ const churn = await churnSince(cwd, values.since ?? DEFAULT_SINCE, { bulk, halfLifeMs, onProgress: (done, total) => progress.update({ step: "reading the git log", done, total, unit: "commits" }) });
2082
+ if (churn === undefined)
2083
+ fail("not a git repository, churn comes from its log");
2084
+ const listed = (await listFiles(positionals[0] === undefined ? [] : [positionals[0]], cwd)).filter((path) => churn.has(path) && (values.all === true || isCandidate(path)));
2085
+ for (const [done, path] of listed.entries()) {
2086
+ progress.update({ step: "measuring the files", done, total: listed.length, unit: "files" });
2087
+ const touched = churn.get(path);
2088
+ const text = await readText(join7(cwd, path));
2089
+ if (text === undefined || values.all !== true && isGenerated(text))
2090
+ continue;
2091
+ const complexity = complexityOf(text);
2092
+ const worst = worstUnit(text, path);
2093
+ ranked.push({ path, score: Math.round(complexity * (values["by-lines"] === true ? touched.linesWeight : touched.weight)), churn: touched.commits, recent: Math.round(touched.weight * 10) / 10, changed: touched.lines, authors: touched.authors, solo: touched.authors === 1, complexity, worst: worst === undefined ? undefined : { name: worst.name, line: worst.line, complexity: worst.complexity }, lines: text.split(`
1552
2094
  `).length - (text.endsWith(`
1553
2095
  `) ? 1 : 0) });
2096
+ }
2097
+ } finally {
2098
+ progress.stop();
1554
2099
  }
1555
2100
  if (ranked.length === 0)
1556
2101
  fail("no file with commits in that window", 1);
@@ -1561,8 +2106,8 @@ async function hotspots(args) {
1561
2106
  printJson(shown);
1562
2107
  return 0;
1563
2108
  }
1564
- const colors = paint(process16.stdout);
1565
- const path = role("path", process16.stdout);
2109
+ const colors = paint(process18.stdout);
2110
+ const path = role("path", process18.stdout);
1566
2111
  const top = shown.reduce((highest, row) => Math.max(highest, row.score), 0);
1567
2112
  const heat = (score, text) => {
1568
2113
  if (top > 0 && score >= top * HOT)
@@ -1570,7 +2115,7 @@ async function hotspots(args) {
1570
2115
  return top > 0 && score >= top * WARM ? colors.yellow(text) : text;
1571
2116
  };
1572
2117
  printHeader("hotspots", `${basename(cwd)} \xB7 since ${values.since ?? DEFAULT_SINCE}`);
1573
- console.log(table([["rank", "score", "churn", "recent", "changed", "authors", "complexity", "lines", "file", "most complex declaration"], ...shown.map((row) => [colors.dim(String(row.rank)), heat(row.score, String(row.score)), ...[row.churn, row.recent, row.changed].map(String), row.solo ? colors.dim("1 solo") : String(row.authors), ...[row.complexity, row.lines].map(String), fileLink(path(row.path), row.path, process16.stdout, cwd), row.worst === undefined ? "" : `${row.worst.name} (${row.worst.complexity}, line ${row.worst.line})`])], { header: true, align: ["right", "right", "right", "right", "right", "right", "right", "right", "left", "left"] }));
2118
+ console.log(table([["rank", "score", "churn", "recent", "changed", "authors", "complexity", "lines", "file", "most complex declaration"], ...shown.map((row) => [colors.dim(String(row.rank)), heat(row.score, String(row.score)), ...[row.churn, row.recent, row.changed].map(String), row.solo ? colors.dim("1 solo") : String(row.authors), ...[row.complexity, row.lines].map(String), fileLink(path(row.path), row.path, process18.stdout, cwd), row.worst === undefined ? "" : `${row.worst.name} (${row.worst.complexity}, line ${row.worst.line})`])], { header: true, align: ["right", "right", "right", "right", "right", "right", "right", "right", "left", "left"] }));
1574
2119
  if (footer !== undefined)
1575
2120
  console.log(footer);
1576
2121
  return 0;
@@ -1579,7 +2124,8 @@ async function hotspots(args) {
1579
2124
  // src/peek.ts
1580
2125
  import { realpathSync as realpathSync3 } from "fs";
1581
2126
  import { isAbsolute as isAbsolute2, join as join8, relative as relative2, resolve as resolve5, sep } from "path";
1582
- import process17 from "process";
2127
+ import process19 from "process";
2128
+ init_text();
1583
2129
 
1584
2130
  // src/source.ts
1585
2131
  var LOCATION = /^(?:\.\/)?([^\s:()]+)(?::(\d+)(?::\d+)?|\((\d+),\d+\))(?=[:\s)]|$)/;
@@ -1756,14 +2302,14 @@ function locations(text) {
1756
2302
  }
1757
2303
 
1758
2304
  // src/peek.ts
1759
- var USAGE2 = `peek [options] <file[:from-to]>...: prints files or line spans with their line numbers, several in one call
2305
+ var USAGE2 = `src peek [options] <file[:from-to]>...: prints files or line spans with their line numbers, several in one call
1760
2306
 
1761
- peek src/a.ts:120-140 src/b.ts:1-40 the spans, src/a.ts:120 the one line, src/a.ts the whole file
1762
- peek --def <symbol> [path...] the whole declaration of the symbol, its comments included, --def again for more symbols
1763
- peek --refs <symbol> [path...] the lines naming the symbol, grouped by file, --defs-first printing its declarations before
1764
- peek --outline <file>... the declarations and class members, a Markdown file's headings
1765
- peek --around <regex> [-C 3] [path...] the lines around each match, overlapping ones merged
1766
- <output> | peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
2307
+ src peek src/a.ts:120-140 src/b.ts:1-40 the spans, src/a.ts:120 the one line, src/a.ts the whole file
2308
+ src peek --def <symbol> [path...] the whole declaration of the symbol, its comments included, --def again for more symbols
2309
+ src peek --refs <symbol> [path...] the lines naming the symbol, grouped by file, --defs-first printing its declarations before
2310
+ src peek --outline <file>... the declarations and class members, a Markdown file's headings
2311
+ src peek --around <regex> [-C 3] [path...] the lines around each match, overlapping ones merged
2312
+ <output> | src peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
1767
2313
  The paths default to the files git keeps here (.gitignore holds).
1768
2314
  --refs lists at most 100 lines and --around prints at most 20 spans, the count of the rest after them (--limit <n>, --full for all).
1769
2315
  --json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}] ({definitions, references} with --defs-first), --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given.`;
@@ -1788,13 +2334,13 @@ function cut(text) {
1788
2334
  return text.length > LONGEST_LINE ? `${text.slice(0, LONGEST_LINE - 1)}\u2026` : text;
1789
2335
  }
1790
2336
  async function readableRoot() {
1791
- const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process17.cwd() });
1792
- return realpathSync3(ran.code === 0 ? ran.text.trim() : process17.cwd());
2337
+ const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process19.cwd() });
2338
+ return realpathSync3(ran.code === 0 ? ran.text.trim() : process19.cwd());
1793
2339
  }
1794
2340
  async function isOutside(path) {
1795
2341
  let real;
1796
2342
  try {
1797
- real = realpathSync3(resolve5(process17.cwd(), path));
2343
+ real = realpathSync3(resolve5(process19.cwd(), path));
1798
2344
  } catch {
1799
2345
  return false;
1800
2346
  }
@@ -1808,7 +2354,7 @@ async function checkInside(path) {
1808
2354
  async function pipedSpans(text, context) {
1809
2355
  const spans = [];
1810
2356
  for (const [path, numbers] of locations(text)) {
1811
- const source = await isOutside(path) ? undefined : await readText(resolve5(process17.cwd(), path));
2357
+ const source = await isOutside(path) ? undefined : await readText(resolve5(process19.cwd(), path));
1812
2358
  if (source !== undefined)
1813
2359
  spans.push(...spansAround(path, source.replace(TRAILING_NEWLINE2, "").split(`
1814
2360
  `).length, numbers, context));
@@ -1817,7 +2363,7 @@ async function pipedSpans(text, context) {
1817
2363
  }
1818
2364
  async function textOf(path) {
1819
2365
  await checkInside(path);
1820
- const text = await readText(resolve5(process17.cwd(), path));
2366
+ const text = await readText(resolve5(process19.cwd(), path));
1821
2367
  if (text === undefined)
1822
2368
  fail(`cannot read ${path} (missing, binary or too large)`, 1);
1823
2369
  return text;
@@ -1869,14 +2415,14 @@ async function spanOf(target) {
1869
2415
  if (from < 1 || to < from)
1870
2416
  badUsage(`${target}: a span reads <file>:<from>-<to>, from 1 and from <= to`);
1871
2417
  if (from > count)
1872
- fail(`${path} has ${go(count, "line")}, ${target} starts past the end`, 1);
2418
+ fail(`${path} has ${bo(count, "line")}, ${target} starts past the end`, 1);
1873
2419
  return { path, from, to: Math.min(to, count) };
1874
2420
  }
1875
2421
  async function* sources(paths) {
1876
2422
  for (const path of paths)
1877
2423
  await checkInside(path);
1878
- for (const path of await listFiles(paths, process17.cwd())) {
1879
- const text = await readText(join8(process17.cwd(), path));
2424
+ for (const path of await listFiles(paths, process19.cwd())) {
2425
+ const text = await readText(join8(process19.cwd(), path));
1880
2426
  if (text !== undefined)
1881
2427
  yield { path, text };
1882
2428
  }
@@ -1900,7 +2446,7 @@ async function definitionsOf(symbols, paths) {
1900
2446
  return [...found.values()].flat();
1901
2447
  }
1902
2448
  async function peek(args) {
1903
- const { values, positionals } = parse(args, USAGE2, OPTIONS2, { exits: EXITS2, positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["peek --def parseArgs src", "a whole declaration"]] });
2449
+ const { values, positionals } = parse(args, USAGE2, OPTIONS2, { exits: EXITS2, positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["src peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["src peek --def parseArgs src", "a whole declaration"]] });
1904
2450
  const modes = [values.def?.length === 0 ? undefined : values.def, values.refs, values.outline, values.around].filter((mode) => mode !== undefined && mode !== false);
1905
2451
  const json = values.json === true;
1906
2452
  if (values["defs-first"] === true && values.refs === undefined)
@@ -1977,7 +2523,7 @@ async function peek(args) {
1977
2523
 
1978
2524
  // src/todo-scan.ts
1979
2525
  import { join as join9 } from "path";
1980
- import process18 from "process";
2526
+ import process20 from "process";
1981
2527
 
1982
2528
  // src/todo.ts
1983
2529
  var COMMENT = /(?<![:\w/])\/\/|\/\*|<!--|(?:^|\s)(?:#|--)(?=\s)|^\s*\*(?=\s|$)/;
@@ -2082,7 +2628,7 @@ async function lookUp(refs, cwd) {
2082
2628
  }
2083
2629
 
2084
2630
  // src/todo-scan.ts
2085
- var USAGE3 = `todo-scan [options] [path...]: lists the TODO, FIXME, HACK, XXX and owner/repo#N comments under the paths (here by default), each as <file>:<line>: <comment>, honouring .gitignore
2631
+ var USAGE3 = `src todo-scan [options] [path...]: lists the TODO, FIXME, HACK, XXX and owner/repo#N comments under the paths (here by default), each as <file>:<line>: <comment>, honouring .gitignore
2086
2632
 
2087
2633
  --older <duration> keeps only the comments whose line last changed longer ago than that (30d, 12w, 6m: git blame dates each one, a file git cannot blame is left out) and shows each one's age.
2088
2634
 
@@ -2105,8 +2651,8 @@ function printLines(lines, footer) {
2105
2651
  `));
2106
2652
  }
2107
2653
  async function todoScan(args) {
2108
- const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, positionals: ["[path...]"], replaces: "grep -rn TODO, then opening each issue it names", examples: ["todo-scan src", ["todo-scan --stale", "only the comments naming a closed issue"]] });
2109
- const cwd = process18.cwd();
2654
+ const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, positionals: ["[path...]"], replaces: "grep -rn TODO, then opening each issue it names", examples: ["src todo-scan src", ["src todo-scan --stale", "only the comments naming a closed issue"]] });
2655
+ const cwd = process20.cwd();
2110
2656
  const limit = limitOf(values, LIST_LIMIT);
2111
2657
  const found = [];
2112
2658
  for (const path of await listFiles(positionals, cwd)) {
@@ -2144,7 +2690,7 @@ async function todoScan(args) {
2144
2690
  }
2145
2691
 
2146
2692
  // src/cli.ts
2147
- process19.exitCode = await runCli({
2693
+ process21.exitCode = await runCli({
2148
2694
  name: "src",
2149
2695
  about: "reads and ranks the source of a folder: line spans, TODO comments and the files worth splitting",
2150
2696
  replaces: "sed -n N,Mp, grep -n chains and grep -rn TODO",