@kaynooo/cli-proc 0.7.5 → 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", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
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,14 +1243,62 @@ 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";
1263
+
1264
+ // ../kit/src/askpass.ts
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
+ }
899
1302
 
900
1303
  // ../kit/src/completions.ts
901
1304
  var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
@@ -958,28 +1361,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
958
1361
  }
959
1362
 
960
1363
  // ../kit/src/notify.ts
961
- import process12 from "process";
1364
+ init_format2();
1365
+ init_mode();
1366
+ import process13 from "process";
962
1367
  var NOTIFY_AFTER_MS = 1e4;
963
1368
  var CANCELLED = 130;
964
1369
  function base64(text) {
965
1370
  return Buffer.from(text).toString("base64");
966
1371
  }
967
- function notification(title, body, env = process12.env) {
968
- const id = `kit${process12.pid}`;
1372
+ function notification(title, body, env = process13.env) {
1373
+ const id = `kit${process13.pid}`;
969
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\\`];
970
1375
  return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
971
1376
  }
972
- function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
1377
+ function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
973
1378
  if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
974
1379
  return;
975
1380
  stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
976
1381
  }
977
1382
 
1383
+ // ../kit/src/cli.ts
1384
+ init_style();
1385
+ init_text2();
1386
+
978
1387
  // ../kit/src/usage.ts
979
1388
  import { appendFileSync, mkdirSync } from "fs";
980
1389
  import { homedir as homedir3 } from "os";
981
1390
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
982
- import process13 from "process";
1391
+ import process14 from "process";
983
1392
 
984
1393
  // ../kit/src/logs.ts
985
1394
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -993,14 +1402,14 @@ var usageError;
993
1402
  function noteUsageError(message) {
994
1403
  usageError = message;
995
1404
  }
996
- function stateHome(env = process13.env) {
1405
+ function stateHome(env = process14.env) {
997
1406
  const dir = env.XDG_STATE_HOME;
998
1407
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
999
1408
  }
1000
- function usagePath(env = process13.env) {
1409
+ function usagePath(env = process14.env) {
1001
1410
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
1002
1411
  }
1003
- function usageRecorded(env = process13.env) {
1412
+ function usageRecorded(env = process14.env) {
1004
1413
  const off = env.KAYNOOO_CLI_NO_USAGE;
1005
1414
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1006
1415
  }
@@ -1009,12 +1418,12 @@ function flagNames(argv) {
1009
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);
1010
1419
  return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
1011
1420
  }
1012
- function usageEntry(bin, command, argv, code, now = new Date) {
1421
+ function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
1013
1422
  const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
1014
1423
  usageError = undefined;
1015
- 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) } };
1016
1425
  }
1017
- function recordUsage(entry, env = process13.env) {
1426
+ function recordUsage(entry, env = process14.env) {
1018
1427
  if (!usageRecorded(env))
1019
1428
  return;
1020
1429
  try {
@@ -1108,8 +1517,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1108
1517
  `);
1109
1518
  }
1110
1519
  function printError(prefix, message, hint, cause) {
1111
- const colors = paint(process14.stderr);
1112
- const styled = takesControlCodes(process14.stderr);
1520
+ const colors = paint(process15.stderr);
1521
+ const styled = takesControlCodes(process15.stderr);
1113
1522
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1114
1523
  const under = (label, text, tint) => text === undefined ? "" : `
1115
1524
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1152,11 +1561,11 @@ async function dispatch(level, typed, { version, redact }) {
1152
1561
  }
1153
1562
  }
1154
1563
  if (name === undefined && level.path.length > 1) {
1155
- 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));
1156
1565
  return 2;
1157
1566
  }
1158
1567
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1159
- 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));
1160
1569
  return 0;
1161
1570
  }
1162
1571
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1302,6 +1711,9 @@ function packageVersion(entry = Bun.main) {
1302
1711
  }
1303
1712
  async function runCli(cli, argv = scriptArgs()) {
1304
1713
  const version = cli.version ?? packageVersion();
1714
+ const answered = await askpassClient(argv);
1715
+ if (answered !== undefined)
1716
+ return answered;
1305
1717
  if (argv[0] === COMPLETE)
1306
1718
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1307
1719
  if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
@@ -1312,7 +1724,7 @@ async function runCli(cli, argv = scriptArgs()) {
1312
1724
  notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
1313
1725
  if (cli.usage !== false) {
1314
1726
  try {
1315
- recordUsage(usageEntry(cli.name, command, argv, code));
1727
+ recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
1316
1728
  } catch {}
1317
1729
  }
1318
1730
  return code;
@@ -1332,32 +1744,28 @@ function commandPath(scope, argv) {
1332
1744
  }
1333
1745
  return path.length === 0 ? undefined : path.join(" ");
1334
1746
  }
1335
- async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1336
- if (argv[0] === COMPLETE)
1337
- return printCandidates(leafCandidates(run, argv.slice(1)));
1338
- if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1339
- return printCompletionScript(name, flagValue(argv));
1340
- if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1341
- console.log(version ?? packageVersion());
1342
- return 0;
1343
- }
1344
- let code;
1345
- const started = performance.now();
1346
- try {
1347
- code = await run(argv);
1348
- } catch (error) {
1349
- code = reportThrown(name, error, redact, wantsJson(argv));
1350
- }
1351
- notifyEnd(name, code, performance.now() - started);
1352
- if (usage !== false) {
1353
- try {
1354
- recordUsage(usageEntry(name, undefined, argv, code));
1355
- } catch {}
1356
- }
1357
- return code;
1358
- }
1359
- // ../kit/src/folders.ts
1360
- 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();
1361
1769
  // ../kit/src/secrets.ts
1362
1770
  var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
1363
1771
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
@@ -1379,8 +1787,18 @@ function parseSize(text, bareUnit = 1) {
1379
1787
  const suffix = match[2].toLowerCase();
1380
1788
  return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
1381
1789
  }
1790
+
1791
+ // ../kit/src/index.ts
1792
+ init_style();
1793
+ init_text2();
1794
+ init_theme();
1795
+ init_user_config();
1796
+
1382
1797
  // ../kit/src/watch.ts
1383
- import process15 from "process";
1798
+ init_args();
1799
+ init_input();
1800
+ init_style();
1801
+ import process16 from "process";
1384
1802
  import { format } from "util";
1385
1803
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1386
1804
  var DEFAULT_SECONDS = 2;
@@ -1402,7 +1820,7 @@ function withoutWatch(args) {
1402
1820
  }
1403
1821
  return rest;
1404
1822
  }
1405
- 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) {
1406
1824
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1407
1825
  if (!takesControlCodes(stream))
1408
1826
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1410,12 +1828,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1410
1828
  for (let round = 0;round < rounds; round++) {
1411
1829
  const held = [];
1412
1830
  const { log, info } = console;
1413
- const write = process15.stdout.write.bind(process15.stdout);
1831
+ const write = process16.stdout.write.bind(process16.stdout);
1414
1832
  const hold = (...parts) => void held.push(`${format(...parts)}
1415
1833
  `);
1416
1834
  console.log = hold;
1417
1835
  console.info = hold;
1418
- process15.stdout.write = (text) => {
1836
+ process16.stdout.write = (text) => {
1419
1837
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1420
1838
  return true;
1421
1839
  };
@@ -1424,15 +1842,17 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1424
1842
  } finally {
1425
1843
  console.log = log;
1426
1844
  console.info = info;
1427
- process15.stdout.write = write;
1845
+ process16.stdout.write = write;
1428
1846
  }
1429
1847
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1430
1848
  await sleep(interval);
1431
1849
  }
1432
1850
  return code;
1433
1851
  }
1852
+ // ../kit/src/workspace-root.ts
1853
+ init_user_config();
1434
1854
  // src/pid.ts
1435
- import process17 from "process";
1855
+ import process18 from "process";
1436
1856
 
1437
1857
  // src/mask.ts
1438
1858
  import { basename } from "path";
@@ -1758,10 +2178,10 @@ async function userName(uid) {
1758
2178
  }
1759
2179
 
1760
2180
  // src/pid.ts
1761
- 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
1762
2182
 
1763
- 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.
1764
- 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.`;
1765
2185
  var EXITS = [[0, "it showed the process"], [1, "no process has this pid"], [2, "a usage error"]];
1766
2186
  var DIGITS2 = /^\d+$/;
1767
2187
  var options = {
@@ -1834,7 +2254,7 @@ function limitLine(limits, name) {
1834
2254
  return limit === undefined ? "-" : `soft ${limit.soft}, hard ${limit.hard}`;
1835
2255
  }
1836
2256
  function render(info, showEnv) {
1837
- const colors = paint(process17.stdout);
2257
+ const colors = paint(process18.stdout);
1838
2258
  const memory = info.memory;
1839
2259
  const size = (bytes) => bytes === undefined ? "-" : tt(bytes);
1840
2260
  const rows = [
@@ -1868,9 +2288,9 @@ async function pid(args) {
1868
2288
  positionals: ["<pid>"],
1869
2289
  replaces: "cat /proc/<pid>/{cmdline,environ,limits}, readlink /proc/<pid>/{exe,cwd}, the fish pid function",
1870
2290
  examples: [
1871
- ["pid 4242", "executable, directory, command, parents, memory, limits and ports"],
1872
- ["pid 4242 --env", "with the environment, secrets masked"],
1873
- "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"
1874
2294
  ]
1875
2295
  });
1876
2296
  const [given] = positionals;
@@ -1888,213 +2308,8 @@ async function pid(args) {
1888
2308
 
1889
2309
  // src/ports.ts
1890
2310
  import { basename as basename2 } from "path";
1891
- import process20 from "process";
1892
-
1893
- // ../kit/src/prompt.ts
1894
- import process19 from "process";
1895
-
1896
- // ../kit/src/job.ts
1897
- import process18 from "process";
1898
- function stopJob() {
1899
- process18.kill(0, "SIGTSTP");
1900
- }
1901
-
1902
- // ../kit/src/picker/line.ts
1903
- var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
1904
- var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
1905
- var FORWARD_KILLS = new Set(["killnext", "killend"]);
1906
- function isEditKey(key) {
1907
- return EDIT_KEYS.has(key);
1908
- }
1909
-
1910
- // ../kit/src/picker/score.ts
1911
- var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
1912
- var NONE = Number.NEGATIVE_INFINITY;
1913
-
1914
- // ../kit/src/picker/state.ts
1915
- var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
1916
- var PASTE_START = "\x1B[200~";
1917
- var PASTE_END = "\x1B[201~";
1918
- var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1919
- var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
1920
- var WHEEL_LINES = 3;
1921
- var KEYS = {
1922
- "\x1B[A": "up",
1923
- "\x1BOA": "up",
1924
- "\x10": "up",
1925
- "\x1B[B": "down",
1926
- "\x1BOB": "down",
1927
- "\x0E": "down",
1928
- "\x1B[5~": "pageup",
1929
- "\x1B[6~": "pagedown",
1930
- "\x1B[H": "home",
1931
- "\x1B[1~": "home",
1932
- "\x1BOH": "home",
1933
- "\x1B[F": "end",
1934
- "\x1B[4~": "end",
1935
- "\x1BOF": "end",
1936
- "\r": "enter",
1937
- "\n": "enter",
1938
- "\x03": "cancel",
1939
- "\x1B": "cancel",
1940
- "\x1B[D": "left",
1941
- "\x1BOD": "left",
1942
- "\x1B[C": "right",
1943
- "\x1BOC": "right",
1944
- "\x1B[1;5D": "wordleft",
1945
- "\x1B[1;3D": "wordleft",
1946
- "\x1Bb": "wordleft",
1947
- "\x1B[1;5C": "wordright",
1948
- "\x1B[1;3C": "wordright",
1949
- "\x1Bf": "wordright",
1950
- "\x01": "linestart",
1951
- "\x05": "lineend",
1952
- "\x7F": "erase",
1953
- "\x1B[3~": "delete",
1954
- "\b": "killword",
1955
- "\x1B\x7F": "killword",
1956
- "\x1B[3;5~": "killnext",
1957
- "\x1Bd": "killnext",
1958
- "\x15": "clear",
1959
- "\v": "killend",
1960
- "\x17": "word",
1961
- "\x19": "yank",
1962
- "\x1A": "suspend",
1963
- "\t": "tab",
1964
- "\x1F": "help",
1965
- "\x1BOP": "help",
1966
- "\x1B[11~": "help"
1967
- };
1968
- function repeat(value, count) {
1969
- return Array.from({ length: count }).fill(value);
1970
- }
1971
- function parseKeys(input, paste = { active: false }, ctrls = []) {
1972
- const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
1973
- return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
1974
- const wheel = MOUSE.exec(sequence)?.[1];
1975
- if (wheel !== undefined)
1976
- return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
1977
- const named = codes.get(sequence);
1978
- const key = named === undefined ? KEYS[sequence] : { ctrl: named };
1979
- if (sequence === PASTE_START || sequence === PASTE_END) {
1980
- paste.active = sequence === PASTE_START;
1981
- return [];
1982
- }
1983
- if (paste.active && (sequence === "\r" || sequence === `
1984
- `))
1985
- return [];
1986
- if (key !== undefined)
1987
- return [key];
1988
- return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
1989
- });
1990
- }
1991
-
1992
- // ../kit/src/redraw.ts
1993
- var SYNC_START = "\x1B[?2026h";
1994
- var SYNC_END = "\x1B[?2026l";
1995
- function overwrite(lines, columns) {
1996
- return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
1997
- `);
1998
- }
1999
- function rowsTaken(lines, columns) {
2000
- return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
2001
- }
2002
-
2003
- // ../kit/src/prompt.ts
2004
- var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
2005
- function readKeys(input, paste = { active: false }) {
2006
- return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
2007
- }
2008
- async function confirm(question, { default: fallback, ...settings } = {}) {
2009
- let answered = fallback;
2010
- const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
2011
- const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
2012
- if (key === "cancel")
2013
- return "cancel";
2014
- if (key === "enter")
2015
- return answered === undefined ? undefined : "enter";
2016
- const letter = typeof key === "object" ? key.text.toLowerCase() : "";
2017
- if (letter !== "y" && letter !== "n")
2018
- return;
2019
- answered = letter === "y";
2020
- return "enter";
2021
- });
2022
- return accepted ? answered : undefined;
2023
- }
2024
- function asking(colors, question, typed, keys) {
2025
- return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
2026
- }
2027
- function answer(colors, question, state, picked) {
2028
- return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
2029
- }
2030
- async function ask(question, { hint, terminal = process19 }, render, press) {
2031
- const { stdin, stderr } = terminal;
2032
- if (!isInteractive(terminal))
2033
- fail(`cannot ask "${question}" off a terminal`, 2, hint);
2034
- const colors = paint(stderr);
2035
- let current = "asking";
2036
- let outcome;
2037
- const columns = () => stderr.columns || 80;
2038
- const draw = (state, last = false) => {
2039
- const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
2040
- const rows = rowsTaken(frame, columns());
2041
- stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
2042
- current = state;
2043
- };
2044
- const redraw = () => draw(current);
2045
- const paste = { active: false };
2046
- const stop = terminal.stop ?? (terminal === process19 ? stopJob : undefined);
2047
- const suspend = () => {
2048
- if (stop === undefined)
2049
- return;
2050
- stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
2051
- stdin.setRawMode(false);
2052
- stop();
2053
- stdin.setRawMode(true);
2054
- stderr.write("\x1B[?25l\x1B[?2004h");
2055
- };
2056
- try {
2057
- stderr.on?.("resize", redraw);
2058
- stdin.setRawMode(true);
2059
- stdin.resume();
2060
- stderr.write("\x1B[?25l\x1B[?2004h");
2061
- draw("asking");
2062
- return await new Promise((resolve) => {
2063
- function onData(data) {
2064
- for (const key of readKeys(data.toString(), paste)) {
2065
- if (key === "suspend") {
2066
- suspend();
2067
- continue;
2068
- }
2069
- const pressed = press(key);
2070
- if (pressed !== undefined) {
2071
- settle(pressed);
2072
- return;
2073
- }
2074
- }
2075
- draw("asking");
2076
- }
2077
- function onEnd() {
2078
- settle("cancel");
2079
- }
2080
- function settle(settled) {
2081
- outcome = settled;
2082
- stdin.off("data", onData);
2083
- stdin.off("end", onEnd);
2084
- resolve(settled === "enter");
2085
- }
2086
- stdin.on("data", onData);
2087
- stdin.on("end", onEnd);
2088
- });
2089
- } finally {
2090
- stderr.off?.("resize", redraw);
2091
- draw(outcome ?? "cancel", true);
2092
- stderr.write(`
2093
- \x1B[?25h\x1B[?2004l`);
2094
- stdin.setRawMode(false);
2095
- stdin.pause();
2096
- }
2097
- }
2311
+ import process21 from "process";
2312
+ init_prompt();
2098
2313
 
2099
2314
  // src/docker.ts
2100
2315
  var FORMAT = '{{.Names}}\t{{.Ports}}\t{{.Label "com.docker.compose.project"}}\t{{.Label "com.docker.compose.service"}}';
@@ -2172,11 +2387,10 @@ async function terminate(pids, { escalate, graceMs, signaller = realSignaller })
2172
2387
  }
2173
2388
 
2174
2389
  // src/ports.ts
2175
- 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
2176
2391
 
2177
- 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 -.
2178
- \`ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
2179
- \`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.`;
2180
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"]];
2181
2395
  var options2 = {
2182
2396
  json: jsonOption("[{ port, protocol, addresses, pid, command, cwd, container }]"),
@@ -2226,7 +2440,7 @@ function refusal(row, proc, guard) {
2226
2440
  return reason === undefined ? undefined : `pid ${row.pid} is ${reason}`;
2227
2441
  }
2228
2442
  function render2(rows) {
2229
- const colors = paint(process20.stdout);
2443
+ const colors = paint(process21.stdout);
2230
2444
  const cells = rows.map((row) => [
2231
2445
  colors.cyan(String(row.port)),
2232
2446
  row.protocol,
@@ -2238,7 +2452,7 @@ function render2(rows) {
2238
2452
  return table([["PORT", "PROTO", "ADDRESS", "PID", "COMMAND", "CWD"], ...cells], { header: true });
2239
2453
  }
2240
2454
  async function stop(port, rows, procs, values) {
2241
- 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)) };
2242
2456
  const targets = new Map;
2243
2457
  for (const row of rows) {
2244
2458
  const reason = refusal(row, row.pid === undefined ? undefined : procs.get(row.pid), guard);
@@ -2251,7 +2465,7 @@ async function stop(port, rows, procs, values) {
2251
2465
  return 1;
2252
2466
  const names = [...targets].map(([pid, row]) => `${pid} (${truncate(row.command ?? "", 40)})`).join(", ");
2253
2467
  if (values.yes !== true) {
2254
- if (!process20.stdin.isTTY)
2468
+ if (!process21.stdin.isTTY)
2255
2469
  fail(`stopping ${names} needs a terminal to ask on: pass --yes`, 2);
2256
2470
  if (await confirm(`Stop ${names}?`, { default: false }) !== true)
2257
2471
  return 1;
@@ -2269,10 +2483,10 @@ async function ports(args) {
2269
2483
  positionals: ["[port]"],
2270
2484
  replaces: "ss -ltnp | grep, lsof -i, fuser -k and lookups of docker-proxy by hand",
2271
2485
  examples: [
2272
- ["ports", "every listening port with its owner"],
2273
- ["ports 3000", "who holds 3000, exit 1 when nobody does"],
2274
- ["ports 3000 --kill --yes", "stop it"],
2275
- "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"
2276
2490
  ]
2277
2491
  });
2278
2492
  if (values.watch !== undefined)
@@ -2282,8 +2496,8 @@ async function ports(args) {
2282
2496
  if (port !== undefined && port > 65535)
2283
2497
  badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
2284
2498
  if (values.kill === true && port === undefined)
2285
- badUsage("--kill takes the port to free: ports <port> --kill");
2286
- 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?.())]);
2287
2501
  const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
2288
2502
  const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
2289
2503
  const needsDocker = wanted.some((socket) => {
@@ -2304,14 +2518,14 @@ async function ports(args) {
2304
2518
  console.log(render2(rows));
2305
2519
  const unknown = rows.filter((row) => row.pid === undefined && row.container === undefined).length;
2306
2520
  if (unknown > 0)
2307
- 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 -`));
2308
2522
  return 0;
2309
2523
  }
2310
2524
 
2311
2525
  // src/procs.ts
2312
2526
  import { existsSync as existsSync3 } from "fs";
2313
2527
  import { homedir as homedir4 } from "os";
2314
- import process21 from "process";
2528
+ import process22 from "process";
2315
2529
 
2316
2530
  // src/select.ts
2317
2531
  import { basename as basename3, join as join6, relative } from "path";
@@ -2427,11 +2641,10 @@ function selectGroups(procs, options) {
2427
2641
  }
2428
2642
 
2429
2643
  // src/procs.ts
2430
- 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
2431
2645
 
2432
- 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.
2433
- 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.
2434
- \`--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.`;
2435
2648
  var EXITS3 = [[0, "it listed or stopped everything"], [1, "a process survived SIGKILL"], [2, "a usage error"]];
2436
2649
  var options3 = {
2437
2650
  json: jsonOption("{ groups: [{ origin, kind, count, rss, oldestSeconds, tools, orphans, pids, processes }], skipped }"),
@@ -2460,7 +2673,7 @@ function summary(group) {
2460
2673
  };
2461
2674
  }
2462
2675
  function render3(groups) {
2463
- const colors = paint(process21.stdout);
2676
+ const colors = paint(process22.stdout);
2464
2677
  const rows = groups.map((group) => [
2465
2678
  group.origin,
2466
2679
  String(group.members.length),
@@ -2476,10 +2689,10 @@ async function procs(args) {
2476
2689
  exits: EXITS3,
2477
2690
  replaces: "pkill -f and pgrep -f one-liners (which match their own shell), ps aux | grep for leftover chromium, bun or vite processes",
2478
2691
  examples: [
2479
- ["procs", "leftover and heavy dev processes, by origin"],
2480
- ["procs --min-mem 1G --older 1h", "only the big ones that have run a while"],
2481
- ["procs --kill", "dry run: what would be stopped"],
2482
- "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"
2483
2696
  ]
2484
2697
  });
2485
2698
  const minMem = values["min-mem"] === undefined ? undefined : parseSize(values["min-mem"], 1024 ** 2);
@@ -2488,9 +2701,9 @@ async function procs(args) {
2488
2701
  if (values.watch !== undefined)
2489
2702
  return watching(values.watch, async () => procs(withoutWatch(args)));
2490
2703
  const olderMs = values.older === undefined ? undefined : duration(values.older, "older", 0, "m");
2491
- const uid = process21.getuid?.() ?? -1;
2704
+ const uid = process22.getuid?.() ?? -1;
2492
2705
  const all = await snapshot("/proc", (owner) => owner === uid);
2493
- 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]))));
2494
2707
  const { groups, protectedCount } = selectGroups(all, { guard: { uid, mine }, now: Date.now(), home: homedir4(), exists: existsSync3, minMem, olderMs });
2495
2708
  const pids = groups.flatMap((group) => group.members.map(({ proc }) => proc.pid));
2496
2709
  const show = (extra = {}) => {
@@ -2503,7 +2716,7 @@ async function procs(args) {
2503
2716
  if (values.kill !== true || pids.length === 0 || values.yes !== true) {
2504
2717
  show();
2505
2718
  if (values.json !== true && protectedCount > 0)
2506
- 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`));
2507
2720
  if (values.kill === true && pids.length > 0)
2508
2721
  console.error(`dry run: would stop ${pids.length} ${pids.length === 1 ? "process" : "processes"} (${pids.join(" ")}), pass --yes to do it`);
2509
2722
  return 0;
@@ -2519,7 +2732,7 @@ async function procs(args) {
2519
2732
  }
2520
2733
 
2521
2734
  // src/proc-cli.ts
2522
- process22.exitCode = await runCli({
2735
+ process23.exitCode = await runCli({
2523
2736
  name: "proc",
2524
2737
  about: "what a process is, who listens on a port and which dev processes are worth cleaning, read from /proc",
2525
2738
  replaces: "cat /proc/<pid>/..., ss -ltnp, lsof -i and pgrep -f one-liners",