@kaynooo/cli-proc 0.7.4 → 0.8.1

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/proc-cli.js CHANGED
@@ -1,19 +1,18 @@
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/proc-cli.ts
5
- import process22 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-n6z2kk96.js
14
- var r = new Map;
15
- var i = new Map;
16
- var l = new Map;
15
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-n6z2kk96.js
17
16
  function a(e, t, o) {
18
17
  return JSON.stringify([e ?? null, t ?? null, o]);
19
18
  }
@@ -23,12 +22,15 @@ function y(e, t) {
23
22
  n = new Intl.NumberFormat(e, t), i.set(o, n);
24
23
  return n;
25
24
  }
25
+ var r, i, l;
26
+ var init_chunk_n6z2kk96 = __esm(() => {
27
+ r = new Map;
28
+ i = new Map;
29
+ l = new Map;
30
+ });
26
31
 
27
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
28
- var N = new Map;
29
- var Nt = /\s+\S*$/;
30
- var Y = /\s/;
31
- function ko(t, e, r = "...") {
32
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
33
+ function Ao(t, e, r = "...") {
32
34
  let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
33
35
  if (t.length <= e)
34
36
  return t;
@@ -39,13 +41,22 @@ function ko(t, e, r = "...") {
39
41
  c = c.trimEnd();
40
42
  return s ? (c + n).slice(0, l) : c + n;
41
43
  }
42
- 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));
43
- var z = new Map;
44
+ var N, Nt, Y, be, W;
45
+ var init_chunk_rkhsft4a = __esm(() => {
46
+ N = new Map;
47
+ Nt = /\s+\S*$/;
48
+ Y = /\s/;
49
+ 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));
50
+ W = new Map;
51
+ });
52
+
53
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
54
+ var init_text = __esm(() => {
55
+ init_chunk_rkhsft4a();
56
+ });
44
57
 
45
58
  // ../kit/src/mode.ts
46
59
  import process2 from "process";
47
- var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
48
- var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
49
60
  function isSet(value) {
50
61
  return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
51
62
  }
@@ -62,12 +73,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
62
73
  function isInteractive(streams = process2) {
63
74
  return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
64
75
  }
76
+ var MODES, AGENT_VARIABLES;
77
+ var init_mode = __esm(() => {
78
+ MODES = new Set(["terminal", "ci", "agent", "pipe"]);
79
+ AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
80
+ });
65
81
 
66
- // ../kit/src/style.ts
67
- import process6 from "process";
68
-
69
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
70
- var G2 = /^[a-f0-9]+$/i;
82
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
71
83
  function b(r) {
72
84
  let e = r.startsWith("#") ? r.slice(1) : r;
73
85
  if (!G2.test(e))
@@ -78,11 +90,6 @@ function b(r) {
78
90
  throw Error(`Invalid hex color length: ${e.length}`);
79
91
  return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
80
92
  }
81
- 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") => {
82
- let [l, n, c] = b(r);
83
- return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
84
- }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
85
- var h = new Set(["", "1", "2", "3", "true"]);
86
93
  function C(r, e = globalThis.process?.env ?? {}) {
87
94
  if (e.FORCE_COLOR !== undefined)
88
95
  return h.has(e.FORCE_COLOR);
@@ -96,7 +103,7 @@ function f(r, e = []) {
96
103
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
97
104
  let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
98
105
  return new Proxy(c, { get(t, i) {
99
- let a = B2[i];
106
+ let a = B[i];
100
107
  if (Array.isArray(a)) {
101
108
  let s = g.get(i);
102
109
  if (s === undefined)
@@ -119,13 +126,21 @@ function f(r, e = []) {
119
126
  function Fe(r = {}) {
120
127
  return f(r);
121
128
  }
122
- var o = Fe();
129
+ var G2, B, h, o;
130
+ var init_chunk_x450vn3m = __esm(() => {
131
+ G2 = /^[a-f0-9]+$/i;
132
+ 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") => {
133
+ let [l, n, c] = b(r);
134
+ return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
135
+ }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
136
+ h = new Set(["", "1", "2", "3", "true"]);
137
+ o = Fe();
138
+ });
123
139
 
124
- // ../kit/src/theme.ts
125
- import { existsSync as existsSync2, readFileSync, statSync } from "fs";
126
- import { homedir as homedir2 } from "os";
127
- import { join as join3, resolve as resolve2 } from "path";
128
- import process5 from "process";
140
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
141
+ var init_colors = __esm(() => {
142
+ init_chunk_x450vn3m();
143
+ });
129
144
 
130
145
  // ../kit/src/config.ts
131
146
  import { existsSync } from "fs";
@@ -141,6 +156,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
141
156
  return;
142
157
  }
143
158
  }
159
+ var init_config = __esm(() => {
160
+ init_args();
161
+ });
144
162
 
145
163
  // ../kit/src/user-config.ts
146
164
  import { homedir } from "os";
@@ -153,36 +171,18 @@ function configBase(where = {}) {
153
171
  function userConfigPath(bin, where = {}) {
154
172
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
155
173
  }
174
+ var init_user_config = () => {};
156
175
 
157
176
  // ../kit/src/theme.ts
158
- var ENDS = new Map;
159
- var DEFAULT = {
160
- 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" },
161
- 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" },
162
- accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
163
- bins: {},
164
- gradient: ["#c084fc", "#67e8f9"]
165
- };
166
- 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" };
167
- 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" };
168
- var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
169
- var PRESETS = {
170
- default: {},
171
- "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
172
- mono: { colors: MONO, accents: ["bold"], gradient: undefined },
173
- ascii: { glyphs: ASCII }
174
- };
175
- 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"]);
176
- var HEX = /^#[0-9a-f]{6}$/i;
177
- var CONTROL = /\p{Cc}/u;
178
- var MAX_FILE_BYTES = 64 * 1024;
179
- var SPACES = /\s+/;
177
+ import { existsSync as existsSync2, readFileSync, statSync } from "fs";
178
+ import { homedir as homedir2 } from "os";
179
+ import { join as join3, resolve as resolve2 } from "path";
180
+ import process5 from "process";
180
181
  function isColorSpec(spec) {
181
182
  if (typeof spec === "number")
182
183
  return Number.isInteger(spec) && spec >= 0 && spec <= 255;
183
184
  return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
184
185
  }
185
- var CUBE = [0, 95, 135, 175, 215, 255];
186
186
  function cubeLevel(channel) {
187
187
  return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
188
188
  }
@@ -287,7 +287,6 @@ function applyFile(theme, file, where, warn) {
287
287
  function endsWalk(home) {
288
288
  return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
289
289
  }
290
- var warned = new Set;
291
290
  function warnOnce(message) {
292
291
  if (warned.has(message))
293
292
  return;
@@ -324,8 +323,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
324
323
  }
325
324
  return { theme, sources, preset };
326
325
  }
327
- var current;
328
- var currentKey = "";
329
326
  function activeTheme() {
330
327
  const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
331
328
  if (current === undefined || key !== currentKey) {
@@ -334,9 +331,38 @@ function activeTheme() {
334
331
  }
335
332
  return current;
336
333
  }
334
+ var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
335
+ var init_theme = __esm(() => {
336
+ init_config();
337
+ init_user_config();
338
+ ENDS = new Map;
339
+ DEFAULT = {
340
+ 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" },
341
+ 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" },
342
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
343
+ bins: {},
344
+ gradient: ["#c084fc", "#67e8f9"]
345
+ };
346
+ 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" };
347
+ 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" };
348
+ ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
349
+ PRESETS = {
350
+ default: {},
351
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
352
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
353
+ ascii: { glyphs: ASCII }
354
+ };
355
+ 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"]);
356
+ HEX = /^#[0-9a-f]{6}$/i;
357
+ CONTROL = /\p{Cc}/u;
358
+ MAX_FILE_BYTES = 64 * 1024;
359
+ SPACES = /\s+/;
360
+ CUBE = [0, 95, 135, 175, 215, 255];
361
+ warned = new Set;
362
+ });
337
363
 
338
364
  // ../kit/src/style.ts
339
- var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
365
+ import process6 from "process";
340
366
  function takesControlCodes(stream, env = process6.env) {
341
367
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
342
368
  }
@@ -355,15 +381,23 @@ function marked(mark, text, stream, detail, env = process6.env) {
355
381
  function problem(text, detail) {
356
382
  console.error(marked("problem", text, process6.stderr, detail));
357
383
  }
358
- var STATUS_WORDS = {
359
- passed: ["passed", "success", "succeeded", "ok"],
360
- failed: ["failed", "failure", "error", "errored"],
361
- running: ["running", "in_progress", "started", "holding"],
362
- queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
363
- skipped: ["skipped", "cancelled", "canceled", "manual"]
364
- };
365
- var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
366
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
384
+ var MARK_WORDS, STATUS_WORDS, STATUS_OF;
385
+ var init_style = __esm(() => {
386
+ init_colors();
387
+ init_mode();
388
+ init_theme();
389
+ MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
390
+ STATUS_WORDS = {
391
+ passed: ["passed", "success", "succeeded", "ok"],
392
+ failed: ["failed", "failure", "error", "errored"],
393
+ running: ["running", "in_progress", "started", "holding"],
394
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
395
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
396
+ };
397
+ STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
398
+ });
399
+
400
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
367
401
  function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
368
402
  let e = r === "si" ? 1000 : 1024;
369
403
  if (Math.abs(i) < e)
@@ -374,9 +408,17 @@ function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
374
408
  while (Math.round(Math.abs(i) * a) / a >= e && o < s.length - 1);
375
409
  return `${n ? y(n, { minimumFractionDigits: t, maximumFractionDigits: t }).format(i) : i.toFixed(t)} ${s[o]}`;
376
410
  }
411
+ var init_chunk_knqbxp56 = __esm(() => {
412
+ init_chunk_n6z2kk96();
413
+ });
414
+
415
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/format/index.js
416
+ var init_format = __esm(() => {
417
+ init_chunk_knqbxp56();
418
+ });
377
419
 
378
420
  // ../kit/src/format.ts
379
- var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
421
+ import process7 from "process";
380
422
  function formatSeconds(total) {
381
423
  let rest = Math.max(0, Math.round(total));
382
424
  const amounts = UNITS.map(([unit, size]) => {
@@ -398,10 +440,8 @@ function upTo(text, separator) {
398
440
  return end === -1 ? text : text.slice(0, end);
399
441
  }
400
442
  function truncate(text, width) {
401
- return ko(text, width, { suffix: "\u2026", includeSuffix: true });
443
+ return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
402
444
  }
403
- var LINE_BREAKS = /\s*\n\s*/g;
404
- var ESCAPE = String.fromCharCode(27);
405
445
  function textWidth(text) {
406
446
  return Bun.stringWidth(text);
407
447
  }
@@ -450,14 +490,41 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
450
490
  function printJson(value) {
451
491
  console.log(jsonText(value));
452
492
  }
493
+ var UNITS, LINE_BREAKS, ESCAPE;
494
+ var init_format2 = __esm(() => {
495
+ init_text();
496
+ init_mode();
497
+ init_style();
498
+ init_format();
499
+ UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
500
+ LINE_BREAKS = /\s*\n\s*/g;
501
+ ESCAPE = String.fromCharCode(27);
502
+ });
453
503
 
454
504
  // ../kit/src/help.ts
455
505
  import process8 from "process";
456
- var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
457
- var USAGE_PREFIX = /^usage:\s*/i;
458
- var FULL_STOP = /\.$/;
459
506
  function usageLine(usage, colors = paint(process8.stdout)) {
460
- return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
507
+ const lines = usage.replace(USAGE_PREFIX, "").split(`
508
+ `);
509
+ const blank = lines.indexOf("");
510
+ const synopses = blank === -1 ? lines : lines.slice(0, blank);
511
+ const details = blank === -1 ? [] : lines.slice(blank + 1);
512
+ const colon = synopses[0].indexOf(": ");
513
+ const inline = synopses[0].slice(colon + 2);
514
+ const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
515
+ if (colon !== -1)
516
+ synopses[0] = synopses[0].slice(0, colon);
517
+ const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
518
+ `)}`;
519
+ const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
520
+ const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
521
+ return [head, ...lead, ...rest].join(`
522
+ `);
523
+ }
524
+ function prose(line, colors) {
525
+ if (colors.cyan("x") === "x")
526
+ return line;
527
+ return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
461
528
  }
462
529
  function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
463
530
  return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
@@ -492,7 +559,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
492
559
  return [];
493
560
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
494
561
  }
495
- var MAX_INLINE_CHOICES = 24;
496
562
  function optionRows(options, colors = paint(process8.stdout)) {
497
563
  const rows = Object.entries(options).map(([name, option]) => {
498
564
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
@@ -507,6 +573,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
507
573
  const width = Math.max(0, ...rows.map((row) => row.width));
508
574
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
509
575
  }
576
+ var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
577
+ var init_help = __esm(() => {
578
+ init_mode();
579
+ init_style();
580
+ OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
581
+ USAGE_PREFIX = /^usage:\s*/i;
582
+ FULL_STOP = /\.$/;
583
+ PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
584
+ });
510
585
 
511
586
  // ../kit/src/text.ts
512
587
  function distance(a, b) {
@@ -534,8 +609,9 @@ function closest(name, names) {
534
609
  const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
535
610
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
536
611
  }
612
+ var init_text2 = () => {};
613
+
537
614
  // ../kit/src/input.ts
538
- var WHOLE = /^\d+$/;
539
615
  function wholeNumber(value, name, fallback, min = 1) {
540
616
  if (value === undefined)
541
617
  return fallback;
@@ -544,8 +620,6 @@ function wholeNumber(value, name, fallback, min = 1) {
544
620
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
545
621
  return number;
546
622
  }
547
- var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
548
- var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
549
623
  function duration(value, name, fallback, unit = "s") {
550
624
  if (value === undefined)
551
625
  return fallback;
@@ -555,40 +629,27 @@ function duration(value, name, fallback, unit = "s") {
555
629
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
556
630
  return ms;
557
631
  }
632
+ var WHOLE, DURATION, UNIT_MS;
633
+ var init_input = __esm(() => {
634
+ init_args();
635
+ WHOLE = /^\d+$/;
636
+ DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
637
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
638
+ });
558
639
 
559
640
  // ../kit/src/args.ts
560
- var DASHES = /^-+/;
641
+ import process9 from "process";
642
+ import { parseArgs } from "util";
561
643
  function jsonOption(holds) {
562
644
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
563
645
  }
564
- class Exit extends Error {
565
- code;
566
- hint;
567
- constructor(message, code, hint) {
568
- super(message);
569
- this.code = code;
570
- this.hint = hint;
571
- }
572
- }
573
646
  function fail(message, code = 2, hint) {
574
647
  throw new Exit(message, code, hint);
575
648
  }
576
-
577
- class UsageError extends Exit {
578
- constructor(message, hint) {
579
- super(message, 2, hint);
580
- }
581
- }
582
649
  function badUsage(message) {
583
650
  throw new UsageError(message);
584
651
  }
585
652
 
586
- class HelpShown extends Exit {
587
- constructor() {
588
- super("help shown", 0);
589
- }
590
- }
591
-
592
653
  class Completing {
593
654
  options;
594
655
  positionals;
@@ -599,11 +660,6 @@ class Completing {
599
660
  this.candidates = candidates;
600
661
  }
601
662
  }
602
- var completion = { active: false };
603
- var OUTPUT_OPTIONS = {
604
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
605
- plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
606
- };
607
663
  function applyOutput(color, plain, env = process9.env) {
608
664
  const when = plain === true ? "never" : color ?? "auto";
609
665
  if (when === "auto")
@@ -757,7 +813,6 @@ function parseError(error) {
757
813
  const message = upTo(error instanceof Error ? error.message : String(error), ". ");
758
814
  return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
759
815
  }
760
- var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
761
816
  function nearestOption(message, options, allowNegative) {
762
817
  const typed = UNKNOWN_OPTION.exec(message)?.[1];
763
818
  if (typed === undefined)
@@ -773,6 +828,294 @@ function nearestOption(message, options, allowNegative) {
773
828
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
774
829
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
775
830
  }
831
+ var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
832
+ var init_args = __esm(() => {
833
+ init_format2();
834
+ init_help();
835
+ init_text2();
836
+ init_help();
837
+ init_input();
838
+ DASHES = /^-+/;
839
+ EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
840
+ Exit = class Exit extends Error {
841
+ code;
842
+ hint;
843
+ [EXIT] = true;
844
+ constructor(message, code, hint) {
845
+ super(message);
846
+ this.code = code;
847
+ this.hint = hint;
848
+ }
849
+ static [Symbol.hasInstance](value) {
850
+ if (this !== Exit)
851
+ return Function.prototype[Symbol.hasInstance].call(this, value);
852
+ return typeof value === "object" && value !== null && value[EXIT] === true;
853
+ }
854
+ };
855
+ UsageError = class UsageError extends Exit {
856
+ constructor(message, hint) {
857
+ super(message, 2, hint);
858
+ }
859
+ };
860
+ HelpShown = class HelpShown extends Exit {
861
+ constructor() {
862
+ super("help shown", 0);
863
+ }
864
+ };
865
+ completion = { active: false };
866
+ OUTPUT_OPTIONS = {
867
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
868
+ plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
869
+ };
870
+ UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
871
+ });
872
+
873
+ // ../kit/src/folders.ts
874
+ var SKIPPED_FOLDERS;
875
+ var init_folders = __esm(() => {
876
+ init_user_config();
877
+ SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
878
+ });
879
+
880
+ // ../kit/src/answers.ts
881
+ var init_answers = __esm(() => {
882
+ init_folders();
883
+ });
884
+
885
+ // ../kit/src/job.ts
886
+ import process19 from "process";
887
+ function stopJob() {
888
+ process19.kill(0, "SIGTSTP");
889
+ }
890
+ var init_job = () => {};
891
+
892
+ // ../kit/src/picker/line.ts
893
+ function isEditKey(key) {
894
+ return EDIT_KEYS.has(key);
895
+ }
896
+ var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS;
897
+ var init_line = __esm(() => {
898
+ EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
899
+ BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
900
+ FORWARD_KILLS = new Set(["killnext", "killend"]);
901
+ });
902
+
903
+ // ../kit/src/picker/score.ts
904
+ var BOUNDARY_AFTER, NONE;
905
+ var init_score = __esm(() => {
906
+ BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
907
+ NONE = Number.NEGATIVE_INFINITY;
908
+ });
909
+
910
+ // ../kit/src/picker/state.ts
911
+ function repeat(value, count) {
912
+ return Array.from({ length: count }).fill(value);
913
+ }
914
+ function parseKeys(input, paste = { active: false }, ctrls = []) {
915
+ const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
916
+ return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
917
+ const wheel = MOUSE.exec(sequence)?.[1];
918
+ if (wheel !== undefined)
919
+ return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
920
+ const named = codes.get(sequence);
921
+ const key = named === undefined ? KEYS[sequence] : { ctrl: named };
922
+ if (sequence === PASTE_START || sequence === PASTE_END) {
923
+ paste.active = sequence === PASTE_START;
924
+ return [];
925
+ }
926
+ if (paste.active && (sequence === "\r" || sequence === `
927
+ `))
928
+ return [];
929
+ if (key !== undefined)
930
+ return [key];
931
+ return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
932
+ });
933
+ }
934
+ var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
935
+ var init_state = __esm(() => {
936
+ init_text2();
937
+ init_line();
938
+ init_score();
939
+ IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
940
+ KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
941
+ MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
942
+ KEYS = {
943
+ "\x1B[A": "up",
944
+ "\x1BOA": "up",
945
+ "\x10": "up",
946
+ "\x1B[B": "down",
947
+ "\x1BOB": "down",
948
+ "\x0E": "down",
949
+ "\x1B[5~": "pageup",
950
+ "\x1B[6~": "pagedown",
951
+ "\x1B[H": "home",
952
+ "\x1B[1~": "home",
953
+ "\x1BOH": "home",
954
+ "\x1B[F": "end",
955
+ "\x1B[4~": "end",
956
+ "\x1BOF": "end",
957
+ "\r": "enter",
958
+ "\n": "enter",
959
+ "\x03": "cancel",
960
+ "\x1B": "cancel",
961
+ "\x1B[D": "left",
962
+ "\x1BOD": "left",
963
+ "\x1B[C": "right",
964
+ "\x1BOC": "right",
965
+ "\x1B[1;5D": "wordleft",
966
+ "\x1B[1;3D": "wordleft",
967
+ "\x1Bb": "wordleft",
968
+ "\x1B[1;5C": "wordright",
969
+ "\x1B[1;3C": "wordright",
970
+ "\x1Bf": "wordright",
971
+ "\x01": "linestart",
972
+ "\x05": "lineend",
973
+ "\x7F": "erase",
974
+ "\x1B[3~": "delete",
975
+ "\b": "killword",
976
+ "\x1B\x7F": "killword",
977
+ "\x1B[3;5~": "killnext",
978
+ "\x1Bd": "killnext",
979
+ "\x15": "clear",
980
+ "\v": "killend",
981
+ "\x17": "word",
982
+ "\x19": "yank",
983
+ "\x1A": "suspend",
984
+ "\t": "tab",
985
+ "\x1F": "help",
986
+ "\x1BOP": "help",
987
+ "\x1B[11~": "help"
988
+ };
989
+ });
990
+
991
+ // ../kit/src/redraw.ts
992
+ function overwrite(lines, columns) {
993
+ return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
994
+ `);
995
+ }
996
+ function rowsTaken(lines, columns) {
997
+ return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
998
+ }
999
+ var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
1000
+ var init_redraw = __esm(() => {
1001
+ init_format2();
1002
+ });
1003
+
1004
+ // ../kit/src/prompt.ts
1005
+ import process20 from "process";
1006
+ function readKeys(input, paste = { active: false }) {
1007
+ return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
1008
+ }
1009
+ async function confirm(question, { default: fallback, ...settings } = {}) {
1010
+ let answered = fallback;
1011
+ const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
1012
+ const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
1013
+ if (key === "cancel")
1014
+ return "cancel";
1015
+ if (key === "enter")
1016
+ return answered === undefined ? undefined : "enter";
1017
+ const letter = typeof key === "object" ? key.text.toLowerCase() : "";
1018
+ if (letter !== "y" && letter !== "n")
1019
+ return;
1020
+ answered = letter === "y";
1021
+ return "enter";
1022
+ });
1023
+ return accepted ? answered : undefined;
1024
+ }
1025
+ function asking(colors, question, typed, keys) {
1026
+ return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
1027
+ }
1028
+ function answer(colors, question, state, picked) {
1029
+ return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
1030
+ }
1031
+ async function ask(question, { hint, terminal = process20 }, render, press) {
1032
+ const { stdin, stderr } = terminal;
1033
+ if (!isInteractive(terminal))
1034
+ fail(`cannot ask "${question}" off a terminal`, 2, hint);
1035
+ const colors = paint(stderr);
1036
+ let current = "asking";
1037
+ let outcome;
1038
+ const columns = () => stderr.columns || 80;
1039
+ const draw = (state, last = false) => {
1040
+ const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
1041
+ const rows = rowsTaken(frame, columns());
1042
+ stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
1043
+ current = state;
1044
+ };
1045
+ const redraw = () => draw(current);
1046
+ const paste = { active: false };
1047
+ const stop = terminal.stop ?? (terminal === process20 ? stopJob : undefined);
1048
+ const suspend = () => {
1049
+ if (stop === undefined)
1050
+ return;
1051
+ stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
1052
+ stdin.setRawMode(false);
1053
+ stop();
1054
+ stdin.setRawMode(true);
1055
+ stderr.write("\x1B[?25l\x1B[?2004h");
1056
+ };
1057
+ try {
1058
+ stderr.on?.("resize", redraw);
1059
+ stdin.setRawMode(true);
1060
+ stdin.resume();
1061
+ stderr.write("\x1B[?25l\x1B[?2004h");
1062
+ draw("asking");
1063
+ return await new Promise((resolve) => {
1064
+ function onData(data) {
1065
+ for (const key of readKeys(data.toString(), paste)) {
1066
+ if (key === "suspend") {
1067
+ suspend();
1068
+ continue;
1069
+ }
1070
+ const pressed = press(key);
1071
+ if (pressed !== undefined) {
1072
+ settle(pressed);
1073
+ return;
1074
+ }
1075
+ }
1076
+ draw("asking");
1077
+ }
1078
+ function onEnd() {
1079
+ settle("cancel");
1080
+ }
1081
+ function settle(settled) {
1082
+ outcome = settled;
1083
+ stdin.off("data", onData);
1084
+ stdin.off("end", onEnd);
1085
+ resolve(settled === "enter");
1086
+ }
1087
+ stdin.on("data", onData);
1088
+ stdin.on("end", onEnd);
1089
+ });
1090
+ } finally {
1091
+ stderr.off?.("resize", redraw);
1092
+ draw(outcome ?? "cancel", true);
1093
+ stderr.write(`
1094
+ \x1B[?25h\x1B[?2004l`);
1095
+ stdin.setRawMode(false);
1096
+ stdin.pause();
1097
+ }
1098
+ }
1099
+ var PROMPT_KEYS;
1100
+ var init_prompt = __esm(() => {
1101
+ init_answers();
1102
+ init_args();
1103
+ init_format2();
1104
+ init_job();
1105
+ init_mode();
1106
+ init_line();
1107
+ init_state();
1108
+ init_redraw();
1109
+ init_style();
1110
+ PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
1111
+ });
1112
+
1113
+ // src/proc-cli.ts
1114
+ import process23 from "process";
1115
+
1116
+ // ../kit/src/index.ts
1117
+ init_args();
1118
+
776
1119
  // ../kit/src/argv.ts
777
1120
  import { readFileSync as readFileSync2, realpathSync } from "fs";
778
1121
  import { resolve as resolve3 } from "path";
@@ -797,6 +1140,18 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
797
1140
  const after = at === -1 ? [] : cmdline.slice(at + 1);
798
1141
  return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
799
1142
  }
1143
+ // ../kit/src/chart.ts
1144
+ init_format2();
1145
+ init_mode();
1146
+ init_style();
1147
+ init_theme();
1148
+ // ../kit/src/ci.ts
1149
+ init_args();
1150
+ init_format2();
1151
+
1152
+ // ../kit/src/progress.ts
1153
+ init_format2();
1154
+
800
1155
  // ../kit/src/process.ts
801
1156
  import { constants } from "os";
802
1157
  import process11 from "process";
@@ -808,10 +1163,10 @@ function exitCodeOf(code, signal) {
808
1163
  return 128 + signal;
809
1164
  return signal === null ? 129 : 128 + constants.signals[signal];
810
1165
  }
811
- async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
1166
+ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
812
1167
  const chunks = [];
813
1168
  const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
814
- const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
1169
+ 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 } : {} });
815
1170
  const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
816
1171
  const timers = [];
817
1172
  const killGroup = (killing) => {
@@ -888,38 +1243,152 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
888
1243
  }
889
1244
 
890
1245
  // ../kit/src/progress.ts
1246
+ init_style();
1247
+ init_theme();
891
1248
  var ESC = String.fromCharCode(27);
892
1249
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
893
1250
  var RESET_STYLE = `${ESC}[0m`;
894
1251
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
1252
+
1253
+ // ../kit/src/ci.ts
1254
+ init_style();
1255
+
1256
+ // ../kit/src/tool.ts
1257
+ init_format2();
895
1258
  // ../kit/src/cli.ts
1259
+ init_args();
896
1260
  import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
897
1261
  import { dirname as dirname3, join as join5 } from "path";
898
- import process14 from "process";
1262
+ import process15 from "process";
899
1263
 
900
- // ../kit/src/notify.ts
1264
+ // ../kit/src/askpass.ts
901
1265
  import process12 from "process";
1266
+ var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1267
+ async function askpassClient(argv) {
1268
+ const socketPath = process12.env[SOCKET_VARIABLE];
1269
+ if (socketPath === undefined)
1270
+ return;
1271
+ const request = { prompt: argv[0] ?? "", ...process12.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
1272
+ const { promise, resolve } = Promise.withResolvers();
1273
+ let received = "";
1274
+ try {
1275
+ await Bun.connect({
1276
+ unix: socketPath,
1277
+ socket: {
1278
+ open: (socket) => void socket.write(`${JSON.stringify(request)}
1279
+ `),
1280
+ data: (_, chunk) => {
1281
+ received += chunk.toString();
1282
+ },
1283
+ close: () => resolve(received),
1284
+ error: () => resolve("")
1285
+ }
1286
+ });
1287
+ } catch {
1288
+ return 1;
1289
+ }
1290
+ const reply = await promise;
1291
+ if (reply === "")
1292
+ return 1;
1293
+ const { answer } = JSON.parse(reply);
1294
+ if (request.notice === true)
1295
+ return 0;
1296
+ if (answer === undefined)
1297
+ return 1;
1298
+ process12.stdout.write(`${answer}
1299
+ `);
1300
+ return 0;
1301
+ }
1302
+
1303
+ // ../kit/src/completions.ts
1304
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1305
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1306
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1307
+ set -l current (commandline -ct)
1308
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1309
+ if test "$line" = __files__
1310
+ __fish_complete_path $current
1311
+ else
1312
+ echo $line
1313
+ end
1314
+ end
1315
+ end`;
1316
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1317
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1318
+ local -a lines
1319
+ COMPREPLY=()
1320
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1321
+ for line in "\${lines[@]}"; do
1322
+ if [[ $line == __files__ ]]; then
1323
+ COMPREPLY+=($(compgen -f -- "$cur"))
1324
+ else
1325
+ words+="\${line%%$'\\t'*}"$'\\n'
1326
+ fi
1327
+ done
1328
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1329
+ }`;
1330
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1331
+ local line
1332
+ local -a described plain
1333
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1334
+ if [[ $line == __files__ ]]; then
1335
+ _files
1336
+ elif [[ $line == *$'\\t'* ]]; then
1337
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1338
+ else
1339
+ plain+=("$line")
1340
+ fi
1341
+ done
1342
+ (( \${#described} )) && _describe -V value described
1343
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1344
+ return 0
1345
+ }`;
1346
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1347
+ if (shell === "fish")
1348
+ return `${header}
1349
+ ${FISH_FUNCTION}
1350
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1351
+ `).join("")}`;
1352
+ if (shell === "bash")
1353
+ return `${header}
1354
+ ${BASH_FUNCTION}
1355
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1356
+ `;
1357
+ return `${header}
1358
+ ${ZSH_FUNCTION}
1359
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1360
+ `;
1361
+ }
1362
+
1363
+ // ../kit/src/notify.ts
1364
+ init_format2();
1365
+ init_mode();
1366
+ import process13 from "process";
902
1367
  var NOTIFY_AFTER_MS = 1e4;
903
1368
  var CANCELLED = 130;
904
1369
  function base64(text) {
905
1370
  return Buffer.from(text).toString("base64");
906
1371
  }
907
- function notification(title, body, env = process12.env) {
908
- const id = `kit${process12.pid}`;
1372
+ function notification(title, body, env = process13.env) {
1373
+ const id = `kit${process13.pid}`;
909
1374
  const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
910
1375
  return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
911
1376
  }
912
- function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
1377
+ function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
913
1378
  if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
914
1379
  return;
915
1380
  stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
916
1381
  }
917
1382
 
1383
+ // ../kit/src/cli.ts
1384
+ init_style();
1385
+ init_text2();
1386
+
918
1387
  // ../kit/src/usage.ts
919
1388
  import { appendFileSync, mkdirSync } from "fs";
920
1389
  import { homedir as homedir3 } from "os";
921
1390
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
922
- import process13 from "process";
1391
+ import process14 from "process";
923
1392
 
924
1393
  // ../kit/src/logs.ts
925
1394
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -933,14 +1402,14 @@ var usageError;
933
1402
  function noteUsageError(message) {
934
1403
  usageError = message;
935
1404
  }
936
- function stateHome(env = process13.env) {
1405
+ function stateHome(env = process14.env) {
937
1406
  const dir = env.XDG_STATE_HOME;
938
1407
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
939
1408
  }
940
- function usagePath(env = process13.env) {
1409
+ function usagePath(env = process14.env) {
941
1410
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
942
1411
  }
943
- function usageRecorded(env = process13.env) {
1412
+ function usageRecorded(env = process14.env) {
944
1413
  const off = env.KAYNOOO_CLI_NO_USAGE;
945
1414
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
946
1415
  }
@@ -949,12 +1418,12 @@ function flagNames(argv) {
949
1418
  const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
950
1419
  return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
951
1420
  }
952
- function usageEntry(bin, command, argv, code, now = new Date) {
1421
+ function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
953
1422
  const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
954
1423
  usageError = undefined;
955
- return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1424
+ return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
956
1425
  }
957
- function recordUsage(entry, env = process13.env) {
1426
+ function recordUsage(entry, env = process14.env) {
958
1427
  if (!usageRecorded(env))
959
1428
  return;
960
1429
  try {
@@ -970,7 +1439,11 @@ var LEVEL_OPTIONS = {
970
1439
  ...OUTPUT_OPTIONS,
971
1440
  help: { type: "boolean", short: "h", description: "show this help" }
972
1441
  };
973
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1442
+ var TOP_OPTIONS = {
1443
+ ...LEVEL_OPTIONS,
1444
+ version: { type: "boolean", short: "v", description: "print the version" },
1445
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1446
+ };
974
1447
  async function commandRows(all, colors) {
975
1448
  const commands = shown(all);
976
1449
  const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
@@ -1044,8 +1517,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1044
1517
  `);
1045
1518
  }
1046
1519
  function printError(prefix, message, hint, cause) {
1047
- const colors = paint(process14.stderr);
1048
- const styled = takesControlCodes(process14.stderr);
1520
+ const colors = paint(process15.stderr);
1521
+ const styled = takesControlCodes(process15.stderr);
1049
1522
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1050
1523
  const under = (label, text, tint) => text === undefined ? "" : `
1051
1524
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1088,11 +1561,11 @@ async function dispatch(level, typed, { version, redact }) {
1088
1561
  }
1089
1562
  }
1090
1563
  if (name === undefined && level.path.length > 1) {
1091
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
1564
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
1092
1565
  return 2;
1093
1566
  }
1094
1567
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1095
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
1568
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
1096
1569
  return 0;
1097
1570
  }
1098
1571
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1203,6 +1676,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
1203
1676
  }
1204
1677
  return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
1205
1678
  }
1679
+ var COMPLETIONS = "--completions";
1680
+ function flagValue([flag = "", ...rest]) {
1681
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1682
+ }
1683
+ function printCompletionScript(name, args) {
1684
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1685
+ if (shell === undefined || args.length !== 1) {
1686
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1687
+ return 2;
1688
+ }
1689
+ console.log(completionScript(shell, [name]).trimEnd());
1690
+ return 0;
1691
+ }
1206
1692
  async function printCandidates(found) {
1207
1693
  for (const line of await found)
1208
1694
  console.log(line);
@@ -1225,15 +1711,20 @@ function packageVersion(entry = Bun.main) {
1225
1711
  }
1226
1712
  async function runCli(cli, argv = scriptArgs()) {
1227
1713
  const version = cli.version ?? packageVersion();
1714
+ const answered = await askpassClient(argv);
1715
+ if (answered !== undefined)
1716
+ return answered;
1228
1717
  if (argv[0] === COMPLETE)
1229
1718
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1719
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1720
+ return printCompletionScript(cli.name, flagValue(argv));
1230
1721
  const started = performance.now();
1231
1722
  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 });
1232
1723
  const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
1233
1724
  notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
1234
1725
  if (cli.usage !== false) {
1235
1726
  try {
1236
- recordUsage(usageEntry(cli.name, command, argv, code));
1727
+ recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
1237
1728
  } catch {}
1238
1729
  }
1239
1730
  return code;
@@ -1253,30 +1744,28 @@ function commandPath(scope, argv) {
1253
1744
  }
1254
1745
  return path.length === 0 ? undefined : path.join(" ");
1255
1746
  }
1256
- async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1257
- if (argv[0] === COMPLETE)
1258
- return printCandidates(leafCandidates(run, argv.slice(1)));
1259
- if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1260
- console.log(version ?? packageVersion());
1261
- return 0;
1262
- }
1263
- let code;
1264
- const started = performance.now();
1265
- try {
1266
- code = await run(argv);
1267
- } catch (error) {
1268
- code = reportThrown(name, error, redact, wantsJson(argv));
1269
- }
1270
- notifyEnd(name, code, performance.now() - started);
1271
- if (usage !== false) {
1272
- try {
1273
- recordUsage(usageEntry(name, undefined, argv, code));
1274
- } catch {}
1275
- }
1276
- return code;
1277
- }
1278
- // ../kit/src/folders.ts
1279
- var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1747
+
1748
+ // ../kit/src/index.ts
1749
+ init_config();
1750
+
1751
+ // ../kit/src/excerpt.ts
1752
+ init_text2();
1753
+
1754
+ // ../kit/src/index.ts
1755
+ init_folders();
1756
+ init_format2();
1757
+
1758
+ // ../kit/src/git.ts
1759
+ init_args();
1760
+ // ../kit/src/limit.ts
1761
+ init_args();
1762
+
1763
+ // ../kit/src/index.ts
1764
+ init_mode();
1765
+
1766
+ // ../kit/src/report.ts
1767
+ init_style();
1768
+ init_text2();
1280
1769
  // ../kit/src/secrets.ts
1281
1770
  var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
1282
1771
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
@@ -1298,8 +1787,18 @@ function parseSize(text, bareUnit = 1) {
1298
1787
  const suffix = match[2].toLowerCase();
1299
1788
  return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
1300
1789
  }
1790
+
1791
+ // ../kit/src/index.ts
1792
+ init_style();
1793
+ init_text2();
1794
+ init_theme();
1795
+ init_user_config();
1796
+
1301
1797
  // ../kit/src/watch.ts
1302
- import process15 from "process";
1798
+ init_args();
1799
+ init_input();
1800
+ init_style();
1801
+ import process16 from "process";
1303
1802
  import { format } from "util";
1304
1803
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1305
1804
  var DEFAULT_SECONDS = 2;
@@ -1321,7 +1820,7 @@ function withoutWatch(args) {
1321
1820
  }
1322
1821
  return rest;
1323
1822
  }
1324
- async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1823
+ async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1325
1824
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1326
1825
  if (!takesControlCodes(stream))
1327
1826
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1329,12 +1828,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1329
1828
  for (let round = 0;round < rounds; round++) {
1330
1829
  const held = [];
1331
1830
  const { log, info } = console;
1332
- const write = process15.stdout.write.bind(process15.stdout);
1831
+ const write = process16.stdout.write.bind(process16.stdout);
1333
1832
  const hold = (...parts) => void held.push(`${format(...parts)}
1334
1833
  `);
1335
1834
  console.log = hold;
1336
1835
  console.info = hold;
1337
- process15.stdout.write = (text) => {
1836
+ process16.stdout.write = (text) => {
1338
1837
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1339
1838
  return true;
1340
1839
  };
@@ -1343,15 +1842,17 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1343
1842
  } finally {
1344
1843
  console.log = log;
1345
1844
  console.info = info;
1346
- process15.stdout.write = write;
1845
+ process16.stdout.write = write;
1347
1846
  }
1348
1847
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1349
1848
  await sleep(interval);
1350
1849
  }
1351
1850
  return code;
1352
1851
  }
1852
+ // ../kit/src/workspace-root.ts
1853
+ init_user_config();
1353
1854
  // src/pid.ts
1354
- import process17 from "process";
1855
+ import process18 from "process";
1355
1856
 
1356
1857
  // src/mask.ts
1357
1858
  import { basename } from "path";
@@ -1677,10 +2178,10 @@ async function userName(uid) {
1677
2178
  }
1678
2179
 
1679
2180
  // src/pid.ts
1680
- var usage2 = `pid <pid>
2181
+ var usage2 = `proc pid <pid>: shows what a process is, from its executable and command line to its parent chain, memory, open files, listening ports and cgroup
1681
2182
 
1682
- Shows what a process is: its executable, working directory, command line, parent chain up to init, user, start time and age, memory, open files and limits, the TCP and UDP ports it listens on and its cgroup. Everything is read from /proc; what the calling user cannot read of another user's process is left out and named at the end.
1683
- The environment is not shown unless --env is given, with every value that looks like a secret masked.`;
2183
+ Everything is read from \`/proc\`; what the calling user cannot read of another user's process is left out and named at the end.
2184
+ The environment is not shown unless --env is given, with every secret masked.`;
1684
2185
  var EXITS = [[0, "it showed the process"], [1, "no process has this pid"], [2, "a usage error"]];
1685
2186
  var DIGITS2 = /^\d+$/;
1686
2187
  var options = {
@@ -1753,7 +2254,7 @@ function limitLine(limits, name) {
1753
2254
  return limit === undefined ? "-" : `soft ${limit.soft}, hard ${limit.hard}`;
1754
2255
  }
1755
2256
  function render(info, showEnv) {
1756
- const colors = paint(process17.stdout);
2257
+ const colors = paint(process18.stdout);
1757
2258
  const memory = info.memory;
1758
2259
  const size = (bytes) => bytes === undefined ? "-" : tt(bytes);
1759
2260
  const rows = [
@@ -1787,9 +2288,9 @@ async function pid(args) {
1787
2288
  positionals: ["<pid>"],
1788
2289
  replaces: "cat /proc/<pid>/{cmdline,environ,limits}, readlink /proc/<pid>/{exe,cwd}, the fish pid function",
1789
2290
  examples: [
1790
- ["pid 4242", "executable, directory, command, parents, memory, limits and ports"],
1791
- ["pid 4242 --env", "with the environment, secrets masked"],
1792
- "pid 4242 --json"
2291
+ ["proc pid 4242", "executable, directory, command, parents, memory, limits and ports"],
2292
+ ["proc pid 4242 --env", "with the environment, secrets masked"],
2293
+ "proc pid 4242 --json"
1793
2294
  ]
1794
2295
  });
1795
2296
  const [given] = positionals;
@@ -1807,213 +2308,8 @@ async function pid(args) {
1807
2308
 
1808
2309
  // src/ports.ts
1809
2310
  import { basename as basename2 } from "path";
1810
- import process20 from "process";
1811
-
1812
- // ../kit/src/prompt.ts
1813
- import process19 from "process";
1814
-
1815
- // ../kit/src/job.ts
1816
- import process18 from "process";
1817
- function stopJob() {
1818
- process18.kill(0, "SIGTSTP");
1819
- }
1820
-
1821
- // ../kit/src/picker/line.ts
1822
- var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
1823
- var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
1824
- var FORWARD_KILLS = new Set(["killnext", "killend"]);
1825
- function isEditKey(key) {
1826
- return EDIT_KEYS.has(key);
1827
- }
1828
-
1829
- // ../kit/src/picker/score.ts
1830
- var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
1831
- var NONE = Number.NEGATIVE_INFINITY;
1832
-
1833
- // ../kit/src/picker/state.ts
1834
- var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
1835
- var PASTE_START = "\x1B[200~";
1836
- var PASTE_END = "\x1B[201~";
1837
- var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1838
- var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
1839
- var WHEEL_LINES = 3;
1840
- var KEYS = {
1841
- "\x1B[A": "up",
1842
- "\x1BOA": "up",
1843
- "\x10": "up",
1844
- "\x1B[B": "down",
1845
- "\x1BOB": "down",
1846
- "\x0E": "down",
1847
- "\x1B[5~": "pageup",
1848
- "\x1B[6~": "pagedown",
1849
- "\x1B[H": "home",
1850
- "\x1B[1~": "home",
1851
- "\x1BOH": "home",
1852
- "\x1B[F": "end",
1853
- "\x1B[4~": "end",
1854
- "\x1BOF": "end",
1855
- "\r": "enter",
1856
- "\n": "enter",
1857
- "\x03": "cancel",
1858
- "\x1B": "cancel",
1859
- "\x1B[D": "left",
1860
- "\x1BOD": "left",
1861
- "\x1B[C": "right",
1862
- "\x1BOC": "right",
1863
- "\x1B[1;5D": "wordleft",
1864
- "\x1B[1;3D": "wordleft",
1865
- "\x1Bb": "wordleft",
1866
- "\x1B[1;5C": "wordright",
1867
- "\x1B[1;3C": "wordright",
1868
- "\x1Bf": "wordright",
1869
- "\x01": "linestart",
1870
- "\x05": "lineend",
1871
- "\x7F": "erase",
1872
- "\x1B[3~": "delete",
1873
- "\b": "killword",
1874
- "\x1B\x7F": "killword",
1875
- "\x1B[3;5~": "killnext",
1876
- "\x1Bd": "killnext",
1877
- "\x15": "clear",
1878
- "\v": "killend",
1879
- "\x17": "word",
1880
- "\x19": "yank",
1881
- "\x1A": "suspend",
1882
- "\t": "tab",
1883
- "\x1F": "help",
1884
- "\x1BOP": "help",
1885
- "\x1B[11~": "help"
1886
- };
1887
- function repeat(value, count) {
1888
- return Array.from({ length: count }).fill(value);
1889
- }
1890
- function parseKeys(input, paste = { active: false }, ctrls = []) {
1891
- const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
1892
- return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
1893
- const wheel = MOUSE.exec(sequence)?.[1];
1894
- if (wheel !== undefined)
1895
- return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
1896
- const named = codes.get(sequence);
1897
- const key = named === undefined ? KEYS[sequence] : { ctrl: named };
1898
- if (sequence === PASTE_START || sequence === PASTE_END) {
1899
- paste.active = sequence === PASTE_START;
1900
- return [];
1901
- }
1902
- if (paste.active && (sequence === "\r" || sequence === `
1903
- `))
1904
- return [];
1905
- if (key !== undefined)
1906
- return [key];
1907
- return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
1908
- });
1909
- }
1910
-
1911
- // ../kit/src/redraw.ts
1912
- var SYNC_START = "\x1B[?2026h";
1913
- var SYNC_END = "\x1B[?2026l";
1914
- function overwrite(lines, columns) {
1915
- return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
1916
- `);
1917
- }
1918
- function rowsTaken(lines, columns) {
1919
- return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
1920
- }
1921
-
1922
- // ../kit/src/prompt.ts
1923
- var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
1924
- function readKeys(input, paste = { active: false }) {
1925
- return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
1926
- }
1927
- async function confirm(question, { default: fallback, ...settings } = {}) {
1928
- let answered = fallback;
1929
- const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
1930
- const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
1931
- if (key === "cancel")
1932
- return "cancel";
1933
- if (key === "enter")
1934
- return answered === undefined ? undefined : "enter";
1935
- const letter = typeof key === "object" ? key.text.toLowerCase() : "";
1936
- if (letter !== "y" && letter !== "n")
1937
- return;
1938
- answered = letter === "y";
1939
- return "enter";
1940
- });
1941
- return accepted ? answered : undefined;
1942
- }
1943
- function asking(colors, question, typed, keys) {
1944
- return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
1945
- }
1946
- function answer(colors, question, state, picked) {
1947
- return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
1948
- }
1949
- async function ask(question, { hint, terminal = process19 }, render, press) {
1950
- const { stdin, stderr } = terminal;
1951
- if (!isInteractive(terminal))
1952
- fail(`cannot ask "${question}" off a terminal`, 2, hint);
1953
- const colors = paint(stderr);
1954
- let current = "asking";
1955
- let outcome;
1956
- const columns = () => stderr.columns || 80;
1957
- const draw = (state, last = false) => {
1958
- const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
1959
- const rows = rowsTaken(frame, columns());
1960
- stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
1961
- current = state;
1962
- };
1963
- const redraw = () => draw(current);
1964
- const paste = { active: false };
1965
- const stop = terminal.stop ?? (terminal === process19 ? stopJob : undefined);
1966
- const suspend = () => {
1967
- if (stop === undefined)
1968
- return;
1969
- stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
1970
- stdin.setRawMode(false);
1971
- stop();
1972
- stdin.setRawMode(true);
1973
- stderr.write("\x1B[?25l\x1B[?2004h");
1974
- };
1975
- try {
1976
- stderr.on?.("resize", redraw);
1977
- stdin.setRawMode(true);
1978
- stdin.resume();
1979
- stderr.write("\x1B[?25l\x1B[?2004h");
1980
- draw("asking");
1981
- return await new Promise((resolve) => {
1982
- function onData(data) {
1983
- for (const key of readKeys(data.toString(), paste)) {
1984
- if (key === "suspend") {
1985
- suspend();
1986
- continue;
1987
- }
1988
- const pressed = press(key);
1989
- if (pressed !== undefined) {
1990
- settle(pressed);
1991
- return;
1992
- }
1993
- }
1994
- draw("asking");
1995
- }
1996
- function onEnd() {
1997
- settle("cancel");
1998
- }
1999
- function settle(settled) {
2000
- outcome = settled;
2001
- stdin.off("data", onData);
2002
- stdin.off("end", onEnd);
2003
- resolve(settled === "enter");
2004
- }
2005
- stdin.on("data", onData);
2006
- stdin.on("end", onEnd);
2007
- });
2008
- } finally {
2009
- stderr.off?.("resize", redraw);
2010
- draw(outcome ?? "cancel", true);
2011
- stderr.write(`
2012
- \x1B[?25h\x1B[?2004l`);
2013
- stdin.setRawMode(false);
2014
- stdin.pause();
2015
- }
2016
- }
2311
+ import process21 from "process";
2312
+ init_prompt();
2017
2313
 
2018
2314
  // src/docker.ts
2019
2315
  var FORMAT = '{{.Names}}\t{{.Ports}}\t{{.Label "com.docker.compose.project"}}\t{{.Label "com.docker.compose.service"}}';
@@ -2091,11 +2387,10 @@ async function terminate(pids, { escalate, graceMs, signaller = realSignaller })
2091
2387
  }
2092
2388
 
2093
2389
  // src/ports.ts
2094
- var usage3 = `ports [port]
2390
+ var usage3 = `proc ports [port]: lists what listens on this machine, one row per port with its owning process, command and working directory
2095
2391
 
2096
- Lists what listens on this machine, TCP and UDP over IPv4 and IPv6, one row per port with its bound address, the owning process, its command and its working directory. A port Docker publishes is held by docker-proxy, and shows as its compose project and service when docker is installed; the owner of a socket of another user cannot be read and shows as -.
2097
- \`ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
2098
- \`ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`;
2392
+ A port Docker publishes shows as its compose project and service; the owner of another user's socket shows as -. \`proc ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
2393
+ \`proc ports <port> --kill\` stops its owner, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`;
2099
2394
  var EXITS2 = [[0, "it listed or stopped"], [1, "nothing listens on the given port or the owner could not be stopped"], [2, "a usage error"]];
2100
2395
  var options2 = {
2101
2396
  json: jsonOption("[{ port, protocol, addresses, pid, command, cwd, container }]"),
@@ -2145,7 +2440,7 @@ function refusal(row, proc, guard) {
2145
2440
  return reason === undefined ? undefined : `pid ${row.pid} is ${reason}`;
2146
2441
  }
2147
2442
  function render2(rows) {
2148
- const colors = paint(process20.stdout);
2443
+ const colors = paint(process21.stdout);
2149
2444
  const cells = rows.map((row) => [
2150
2445
  colors.cyan(String(row.port)),
2151
2446
  row.protocol,
@@ -2157,7 +2452,7 @@ function render2(rows) {
2157
2452
  return table([["PORT", "PROTO", "ADDRESS", "PID", "COMMAND", "CWD"], ...cells], { header: true });
2158
2453
  }
2159
2454
  async function stop(port, rows, procs, values) {
2160
- const guard = { uid: process20.getuid?.() ?? -1, mine: new Set(ancestry(process20.pid, procs)) };
2455
+ const guard = { uid: process21.getuid?.() ?? -1, mine: new Set(ancestry(process21.pid, procs)) };
2161
2456
  const targets = new Map;
2162
2457
  for (const row of rows) {
2163
2458
  const reason = refusal(row, row.pid === undefined ? undefined : procs.get(row.pid), guard);
@@ -2170,7 +2465,7 @@ async function stop(port, rows, procs, values) {
2170
2465
  return 1;
2171
2466
  const names = [...targets].map(([pid, row]) => `${pid} (${truncate(row.command ?? "", 40)})`).join(", ");
2172
2467
  if (values.yes !== true) {
2173
- if (!process20.stdin.isTTY)
2468
+ if (!process21.stdin.isTTY)
2174
2469
  fail(`stopping ${names} needs a terminal to ask on: pass --yes`, 2);
2175
2470
  if (await confirm(`Stop ${names}?`, { default: false }) !== true)
2176
2471
  return 1;
@@ -2188,10 +2483,10 @@ async function ports(args) {
2188
2483
  positionals: ["[port]"],
2189
2484
  replaces: "ss -ltnp | grep, lsof -i, fuser -k and lookups of docker-proxy by hand",
2190
2485
  examples: [
2191
- ["ports", "every listening port with its owner"],
2192
- ["ports 3000", "who holds 3000, exit 1 when nobody does"],
2193
- ["ports 3000 --kill --yes", "stop it"],
2194
- "ports --json"
2486
+ ["proc ports", "every listening port with its owner"],
2487
+ ["proc ports 3000", "who holds 3000, exit 1 when nobody does"],
2488
+ ["proc ports 3000 --kill --yes", "stop it"],
2489
+ "proc ports --json"
2195
2490
  ]
2196
2491
  });
2197
2492
  if (values.watch !== undefined)
@@ -2201,8 +2496,8 @@ async function ports(args) {
2201
2496
  if (port !== undefined && port > 65535)
2202
2497
  badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
2203
2498
  if (values.kill === true && port === undefined)
2204
- badUsage("--kill takes the port to free: ports <port> --kill");
2205
- const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process20.getuid?.())]);
2499
+ badUsage("--kill takes the port to free: proc ports <port> --kill");
2500
+ const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process21.getuid?.())]);
2206
2501
  const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
2207
2502
  const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
2208
2503
  const needsDocker = wanted.some((socket) => {
@@ -2223,14 +2518,14 @@ async function ports(args) {
2223
2518
  console.log(render2(rows));
2224
2519
  const unknown = rows.filter((row) => row.pid === undefined && row.container === undefined).length;
2225
2520
  if (unknown > 0)
2226
- console.error(paint(process20.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
2521
+ console.error(paint(process21.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
2227
2522
  return 0;
2228
2523
  }
2229
2524
 
2230
2525
  // src/procs.ts
2231
2526
  import { existsSync as existsSync3 } from "fs";
2232
2527
  import { homedir as homedir4 } from "os";
2233
- import process21 from "process";
2528
+ import process22 from "process";
2234
2529
 
2235
2530
  // src/select.ts
2236
2531
  import { basename as basename3, join as join6, relative } from "path";
@@ -2346,11 +2641,10 @@ function selectGroups(procs, options) {
2346
2641
  }
2347
2642
 
2348
2643
  // src/procs.ts
2349
- var usage4 = `procs
2644
+ var usage4 = `proc procs: lists the calling user's leftover or heavy dev processes, grouped by project folder, browser profile or command
2350
2645
 
2351
- Lists the leftover or heavy processes of the calling user that are worth cleaning, grouped by origin: the project folder their working directory is in, a browser profile for a chromium and its helpers, else their command. Each group shows its process count, total resident memory and oldest age.
2352
- A process is listed when it is a dev tool (bun, node, vite, nuxt, next, chromium and chrome, playwright and webview browsers and their helpers, language servers, test runners) and either an orphan, reparented to init or to the user's systemd, or heavy (500M resident by default). The processes below a listed one, and those sharing a browser profile with it, are listed too, so a chromium whose main process was killed groups with its leftover helpers.
2353
- \`--kill\` is a dry run that names what it would stop unless --yes is given; it sends SIGTERM, then SIGKILL after --grace to what is still there. It never signals pid 1, shells, terminals, this command and its ancestors, or processes of other users.`;
2646
+ A process is listed when it is a dev tool (bun, node, vite, chromium, playwright, language servers, test runners) and either an orphan, reparented to init or to the user's systemd, or heavy (500M resident by default); the processes below it and those sharing its browser profile come with it.
2647
+ \`--kill\` is a dry run that names what it would stop unless --yes is given. It never signals pid 1, shells, terminals, this command and its ancestors, or processes of other users.`;
2354
2648
  var EXITS3 = [[0, "it listed or stopped everything"], [1, "a process survived SIGKILL"], [2, "a usage error"]];
2355
2649
  var options3 = {
2356
2650
  json: jsonOption("{ groups: [{ origin, kind, count, rss, oldestSeconds, tools, orphans, pids, processes }], skipped }"),
@@ -2379,7 +2673,7 @@ function summary(group) {
2379
2673
  };
2380
2674
  }
2381
2675
  function render3(groups) {
2382
- const colors = paint(process21.stdout);
2676
+ const colors = paint(process22.stdout);
2383
2677
  const rows = groups.map((group) => [
2384
2678
  group.origin,
2385
2679
  String(group.members.length),
@@ -2395,10 +2689,10 @@ async function procs(args) {
2395
2689
  exits: EXITS3,
2396
2690
  replaces: "pkill -f and pgrep -f one-liners (which match their own shell), ps aux | grep for leftover chromium, bun or vite processes",
2397
2691
  examples: [
2398
- ["procs", "leftover and heavy dev processes, by origin"],
2399
- ["procs --min-mem 1G --older 1h", "only the big ones that have run a while"],
2400
- ["procs --kill", "dry run: what would be stopped"],
2401
- "procs --kill --yes"
2692
+ ["proc procs", "leftover and heavy dev processes, by origin"],
2693
+ ["proc procs --min-mem 1G --older 1h", "only the big ones that have run a while"],
2694
+ ["proc procs --kill", "dry run: what would be stopped"],
2695
+ "proc procs --kill --yes"
2402
2696
  ]
2403
2697
  });
2404
2698
  const minMem = values["min-mem"] === undefined ? undefined : parseSize(values["min-mem"], 1024 ** 2);
@@ -2407,9 +2701,9 @@ async function procs(args) {
2407
2701
  if (values.watch !== undefined)
2408
2702
  return watching(values.watch, async () => procs(withoutWatch(args)));
2409
2703
  const olderMs = values.older === undefined ? undefined : duration(values.older, "older", 0, "m");
2410
- const uid = process21.getuid?.() ?? -1;
2704
+ const uid = process22.getuid?.() ?? -1;
2411
2705
  const all = await snapshot("/proc", (owner) => owner === uid);
2412
- const mine = new Set(ancestry(process21.pid, new Map(all.map((proc) => [proc.pid, proc]))));
2706
+ const mine = new Set(ancestry(process22.pid, new Map(all.map((proc) => [proc.pid, proc]))));
2413
2707
  const { groups, protectedCount } = selectGroups(all, { guard: { uid, mine }, now: Date.now(), home: homedir4(), exists: existsSync3, minMem, olderMs });
2414
2708
  const pids = groups.flatMap((group) => group.members.map(({ proc }) => proc.pid));
2415
2709
  const show = (extra = {}) => {
@@ -2422,7 +2716,7 @@ async function procs(args) {
2422
2716
  if (values.kill !== true || pids.length === 0 || values.yes !== true) {
2423
2717
  show();
2424
2718
  if (values.json !== true && protectedCount > 0)
2425
- console.error(paint(process21.stderr).dim(`${protectedCount} more left out: shells, terminals and this command's ancestors are never touched`));
2719
+ console.error(paint(process22.stderr).dim(`${protectedCount} more left out: shells, terminals and this command's ancestors are never touched`));
2426
2720
  if (values.kill === true && pids.length > 0)
2427
2721
  console.error(`dry run: would stop ${pids.length} ${pids.length === 1 ? "process" : "processes"} (${pids.join(" ")}), pass --yes to do it`);
2428
2722
  return 0;
@@ -2438,7 +2732,7 @@ async function procs(args) {
2438
2732
  }
2439
2733
 
2440
2734
  // src/proc-cli.ts
2441
- process22.exitCode = await runCli({
2735
+ process23.exitCode = await runCli({
2442
2736
  name: "proc",
2443
2737
  about: "what a process is, who listens on a port and which dev processes are worth cleaning, read from /proc",
2444
2738
  replaces: "cat /proc/<pid>/..., ss -ltnp, lsof -i and pgrep -f one-liners",