@kaynooo/cli-proc 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/proc-cli.js CHANGED
@@ -1,19 +1,18 @@
1
- #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
- // @bun
3
-
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";
1
+ #!/bin/sh
2
+ // @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
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
+ };
12
14
 
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,48 +156,36 @@ 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";
147
- import { join as join2 } from "path";
165
+ import { isAbsolute, join as join2 } from "path";
148
166
  import process4 from "process";
167
+ function xdgFolder(value, fallback) {
168
+ return value !== undefined && isAbsolute(value) ? value : fallback;
169
+ }
149
170
  function configBase(where = {}) {
150
171
  const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
151
- return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
172
+ return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
152
173
  }
153
174
  function userConfigPath(bin, where = {}) {
154
175
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
155
176
  }
177
+ var init_user_config = () => {};
156
178
 
157
179
  // ../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+/;
180
+ import { existsSync as existsSync2, readFileSync, statSync } from "fs";
181
+ import { homedir as homedir2 } from "os";
182
+ import { join as join3, resolve as resolve2 } from "path";
183
+ import process5 from "process";
180
184
  function isColorSpec(spec) {
181
185
  if (typeof spec === "number")
182
186
  return Number.isInteger(spec) && spec >= 0 && spec <= 255;
183
187
  return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
184
188
  }
185
- var CUBE = [0, 95, 135, 175, 215, 255];
186
189
  function cubeLevel(channel) {
187
190
  return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
188
191
  }
@@ -287,7 +290,6 @@ function applyFile(theme, file, where, warn) {
287
290
  function endsWalk(home) {
288
291
  return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
289
292
  }
290
- var warned = new Set;
291
293
  function warnOnce(message) {
292
294
  if (warned.has(message))
293
295
  return;
@@ -324,8 +326,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
324
326
  }
325
327
  return { theme, sources, preset };
326
328
  }
327
- var current;
328
- var currentKey = "";
329
329
  function activeTheme() {
330
330
  const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
331
331
  if (current === undefined || key !== currentKey) {
@@ -334,9 +334,38 @@ function activeTheme() {
334
334
  }
335
335
  return current;
336
336
  }
337
+ var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
338
+ var init_theme = __esm(() => {
339
+ init_config();
340
+ init_user_config();
341
+ ENDS = new Map;
342
+ DEFAULT = {
343
+ 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" },
344
+ 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" },
345
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
346
+ bins: {},
347
+ gradient: ["#c084fc", "#67e8f9"]
348
+ };
349
+ 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" };
350
+ 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" };
351
+ ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
352
+ PRESETS = {
353
+ default: {},
354
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
355
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
356
+ ascii: { glyphs: ASCII }
357
+ };
358
+ 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"]);
359
+ HEX = /^#[0-9a-f]{6}$/i;
360
+ CONTROL = /\p{Cc}/u;
361
+ MAX_FILE_BYTES = 64 * 1024;
362
+ SPACES = /\s+/;
363
+ CUBE = [0, 95, 135, 175, 215, 255];
364
+ warned = new Set;
365
+ });
337
366
 
338
367
  // ../kit/src/style.ts
339
- var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
368
+ import process6 from "process";
340
369
  function takesControlCodes(stream, env = process6.env) {
341
370
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
342
371
  }
@@ -355,15 +384,23 @@ function marked(mark, text, stream, detail, env = process6.env) {
355
384
  function problem(text, detail) {
356
385
  console.error(marked("problem", text, process6.stderr, detail));
357
386
  }
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
387
+ var MARK_WORDS, STATUS_WORDS, STATUS_OF;
388
+ var init_style = __esm(() => {
389
+ init_colors();
390
+ init_mode();
391
+ init_theme();
392
+ MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
393
+ STATUS_WORDS = {
394
+ passed: ["passed", "success", "succeeded", "ok"],
395
+ failed: ["failed", "failure", "error", "errored"],
396
+ running: ["running", "in_progress", "started", "holding"],
397
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
398
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
399
+ };
400
+ STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
401
+ });
402
+
403
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
367
404
  function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
368
405
  let e = r === "si" ? 1000 : 1024;
369
406
  if (Math.abs(i) < e)
@@ -374,9 +411,17 @@ function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
374
411
  while (Math.round(Math.abs(i) * a) / a >= e && o < s.length - 1);
375
412
  return `${n ? y(n, { minimumFractionDigits: t, maximumFractionDigits: t }).format(i) : i.toFixed(t)} ${s[o]}`;
376
413
  }
414
+ var init_chunk_knqbxp56 = __esm(() => {
415
+ init_chunk_n6z2kk96();
416
+ });
417
+
418
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/format/index.js
419
+ var init_format = __esm(() => {
420
+ init_chunk_knqbxp56();
421
+ });
377
422
 
378
423
  // ../kit/src/format.ts
379
- var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
424
+ import process7 from "process";
380
425
  function formatSeconds(total) {
381
426
  let rest = Math.max(0, Math.round(total));
382
427
  const amounts = UNITS.map(([unit, size]) => {
@@ -398,10 +443,8 @@ function upTo(text, separator) {
398
443
  return end === -1 ? text : text.slice(0, end);
399
444
  }
400
445
  function truncate(text, width) {
401
- return ko(text, width, { suffix: "\u2026", includeSuffix: true });
446
+ return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
402
447
  }
403
- var LINE_BREAKS = /\s*\n\s*/g;
404
- var ESCAPE = String.fromCharCode(27);
405
448
  function textWidth(text) {
406
449
  return Bun.stringWidth(text);
407
450
  }
@@ -450,14 +493,41 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
450
493
  function printJson(value) {
451
494
  console.log(jsonText(value));
452
495
  }
496
+ var UNITS, LINE_BREAKS, ESCAPE;
497
+ var init_format2 = __esm(() => {
498
+ init_text();
499
+ init_mode();
500
+ init_style();
501
+ init_format();
502
+ UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
503
+ LINE_BREAKS = /\s*\n\s*/g;
504
+ ESCAPE = String.fromCharCode(27);
505
+ });
453
506
 
454
507
  // ../kit/src/help.ts
455
508
  import process8 from "process";
456
- var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
457
- var USAGE_PREFIX = /^usage:\s*/i;
458
- var FULL_STOP = /\.$/;
459
509
  function usageLine(usage, colors = paint(process8.stdout)) {
460
- return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
510
+ const lines = usage.replace(USAGE_PREFIX, "").split(`
511
+ `);
512
+ const blank = lines.indexOf("");
513
+ const synopses = blank === -1 ? lines : lines.slice(0, blank);
514
+ const details = blank === -1 ? [] : lines.slice(blank + 1);
515
+ const colon = synopses[0].indexOf(": ");
516
+ const inline = synopses[0].slice(colon + 2);
517
+ const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
518
+ if (colon !== -1)
519
+ synopses[0] = synopses[0].slice(0, colon);
520
+ const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
521
+ `)}`;
522
+ const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
523
+ const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
524
+ return [head, ...lead, ...rest].join(`
525
+ `);
526
+ }
527
+ function prose(line, colors) {
528
+ if (colors.cyan("x") === "x")
529
+ return line;
530
+ return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
461
531
  }
462
532
  function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
463
533
  return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
@@ -492,7 +562,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
492
562
  return [];
493
563
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
494
564
  }
495
- var MAX_INLINE_CHOICES = 24;
496
565
  function optionRows(options, colors = paint(process8.stdout)) {
497
566
  const rows = Object.entries(options).map(([name, option]) => {
498
567
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
@@ -507,6 +576,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
507
576
  const width = Math.max(0, ...rows.map((row) => row.width));
508
577
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
509
578
  }
579
+ var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
580
+ var init_help = __esm(() => {
581
+ init_mode();
582
+ init_style();
583
+ OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
584
+ USAGE_PREFIX = /^usage:\s*/i;
585
+ FULL_STOP = /\.$/;
586
+ PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
587
+ });
510
588
 
511
589
  // ../kit/src/text.ts
512
590
  function distance(a, b) {
@@ -534,8 +612,9 @@ function closest(name, names) {
534
612
  const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
535
613
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
536
614
  }
615
+ var init_text2 = () => {};
616
+
537
617
  // ../kit/src/input.ts
538
- var WHOLE = /^\d+$/;
539
618
  function wholeNumber(value, name, fallback, min = 1) {
540
619
  if (value === undefined)
541
620
  return fallback;
@@ -544,51 +623,47 @@ function wholeNumber(value, name, fallback, min = 1) {
544
623
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
545
624
  return number;
546
625
  }
547
- var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
548
- var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
626
+ function durationMs(text, unit) {
627
+ if (BARE_DURATION.test(text))
628
+ return Number(text) * UNIT_MS[unit];
629
+ if (!DURATION.test(text))
630
+ return 0;
631
+ let ms = 0;
632
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
633
+ ms += Number(amount) * UNIT_MS[part];
634
+ return ms;
635
+ }
549
636
  function duration(value, name, fallback, unit = "s") {
550
637
  if (value === undefined)
551
638
  return fallback;
552
- const match = DURATION.exec(value.trim());
553
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
639
+ const ms = durationMs(value.trim(), unit);
554
640
  if (ms < 1)
555
641
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
556
642
  return ms;
557
643
  }
644
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
645
+ var init_input = __esm(() => {
646
+ init_args();
647
+ WHOLE = /^\d+$/;
648
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
649
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
650
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
651
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
652
+ });
558
653
 
559
654
  // ../kit/src/args.ts
560
- var DASHES = /^-+/;
655
+ import process9 from "process";
656
+ import { parseArgs } from "util";
561
657
  function jsonOption(holds) {
562
658
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
563
659
  }
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
660
  function fail(message, code = 2, hint) {
574
661
  throw new Exit(message, code, hint);
575
662
  }
576
-
577
- class UsageError extends Exit {
578
- constructor(message, hint) {
579
- super(message, 2, hint);
580
- }
581
- }
582
663
  function badUsage(message) {
583
664
  throw new UsageError(message);
584
665
  }
585
666
 
586
- class HelpShown extends Exit {
587
- constructor() {
588
- super("help shown", 0);
589
- }
590
- }
591
-
592
667
  class Completing {
593
668
  options;
594
669
  positionals;
@@ -599,11 +674,6 @@ class Completing {
599
674
  this.candidates = candidates;
600
675
  }
601
676
  }
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
677
  function applyOutput(color, plain, env = process9.env) {
608
678
  const when = plain === true ? "never" : color ?? "auto";
609
679
  if (when === "auto")
@@ -757,7 +827,6 @@ function parseError(error) {
757
827
  const message = upTo(error instanceof Error ? error.message : String(error), ". ");
758
828
  return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
759
829
  }
760
- var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
761
830
  function nearestOption(message, options, allowNegative) {
762
831
  const typed = UNKNOWN_OPTION.exec(message)?.[1];
763
832
  if (typed === undefined)
@@ -773,6 +842,294 @@ function nearestOption(message, options, allowNegative) {
773
842
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
774
843
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
775
844
  }
845
+ var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
846
+ var init_args = __esm(() => {
847
+ init_format2();
848
+ init_help();
849
+ init_text2();
850
+ init_help();
851
+ init_input();
852
+ DASHES = /^-+/;
853
+ EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
854
+ Exit = class Exit extends Error {
855
+ code;
856
+ hint;
857
+ [EXIT] = true;
858
+ constructor(message, code, hint) {
859
+ super(message);
860
+ this.code = code;
861
+ this.hint = hint;
862
+ }
863
+ static [Symbol.hasInstance](value) {
864
+ if (this !== Exit)
865
+ return Function.prototype[Symbol.hasInstance].call(this, value);
866
+ return typeof value === "object" && value !== null && value[EXIT] === true;
867
+ }
868
+ };
869
+ UsageError = class UsageError extends Exit {
870
+ constructor(message, hint) {
871
+ super(message, 2, hint);
872
+ }
873
+ };
874
+ HelpShown = class HelpShown extends Exit {
875
+ constructor() {
876
+ super("help shown", 0);
877
+ }
878
+ };
879
+ completion = { active: false };
880
+ OUTPUT_OPTIONS = {
881
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
882
+ plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
883
+ };
884
+ UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
885
+ });
886
+
887
+ // ../kit/src/folders.ts
888
+ var SKIPPED_FOLDERS;
889
+ var init_folders = __esm(() => {
890
+ init_user_config();
891
+ SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
892
+ });
893
+
894
+ // ../kit/src/answers.ts
895
+ var init_answers = __esm(() => {
896
+ init_folders();
897
+ });
898
+
899
+ // ../kit/src/job.ts
900
+ import process19 from "process";
901
+ function stopJob() {
902
+ process19.kill(0, "SIGTSTP");
903
+ }
904
+ var init_job = () => {};
905
+
906
+ // ../kit/src/picker/line.ts
907
+ function isEditKey(key) {
908
+ return EDIT_KEYS.has(key);
909
+ }
910
+ var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS;
911
+ var init_line = __esm(() => {
912
+ EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
913
+ BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
914
+ FORWARD_KILLS = new Set(["killnext", "killend"]);
915
+ });
916
+
917
+ // ../kit/src/picker/score.ts
918
+ var BOUNDARY_AFTER, NONE;
919
+ var init_score = __esm(() => {
920
+ BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
921
+ NONE = Number.NEGATIVE_INFINITY;
922
+ });
923
+
924
+ // ../kit/src/picker/state.ts
925
+ function repeat(value, count) {
926
+ return Array.from({ length: count }).fill(value);
927
+ }
928
+ function parseKeys(input, paste = { active: false }, ctrls = []) {
929
+ const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
930
+ return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
931
+ const wheel = MOUSE.exec(sequence)?.[1];
932
+ if (wheel !== undefined)
933
+ return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
934
+ const named = codes.get(sequence);
935
+ const key = named === undefined ? KEYS[sequence] : { ctrl: named };
936
+ if (sequence === PASTE_START || sequence === PASTE_END) {
937
+ paste.active = sequence === PASTE_START;
938
+ return [];
939
+ }
940
+ if (paste.active && (sequence === "\r" || sequence === `
941
+ `))
942
+ return [];
943
+ if (key !== undefined)
944
+ return [key];
945
+ return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
946
+ });
947
+ }
948
+ var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
949
+ var init_state = __esm(() => {
950
+ init_text2();
951
+ init_line();
952
+ init_score();
953
+ IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
954
+ KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
955
+ MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
956
+ KEYS = {
957
+ "\x1B[A": "up",
958
+ "\x1BOA": "up",
959
+ "\x10": "up",
960
+ "\x1B[B": "down",
961
+ "\x1BOB": "down",
962
+ "\x0E": "down",
963
+ "\x1B[5~": "pageup",
964
+ "\x1B[6~": "pagedown",
965
+ "\x1B[H": "home",
966
+ "\x1B[1~": "home",
967
+ "\x1BOH": "home",
968
+ "\x1B[F": "end",
969
+ "\x1B[4~": "end",
970
+ "\x1BOF": "end",
971
+ "\r": "enter",
972
+ "\n": "enter",
973
+ "\x03": "cancel",
974
+ "\x1B": "cancel",
975
+ "\x1B[D": "left",
976
+ "\x1BOD": "left",
977
+ "\x1B[C": "right",
978
+ "\x1BOC": "right",
979
+ "\x1B[1;5D": "wordleft",
980
+ "\x1B[1;3D": "wordleft",
981
+ "\x1Bb": "wordleft",
982
+ "\x1B[1;5C": "wordright",
983
+ "\x1B[1;3C": "wordright",
984
+ "\x1Bf": "wordright",
985
+ "\x01": "linestart",
986
+ "\x05": "lineend",
987
+ "\x7F": "erase",
988
+ "\x1B[3~": "delete",
989
+ "\b": "killword",
990
+ "\x1B\x7F": "killword",
991
+ "\x1B[3;5~": "killnext",
992
+ "\x1Bd": "killnext",
993
+ "\x15": "clear",
994
+ "\v": "killend",
995
+ "\x17": "word",
996
+ "\x19": "yank",
997
+ "\x1A": "suspend",
998
+ "\t": "tab",
999
+ "\x1F": "help",
1000
+ "\x1BOP": "help",
1001
+ "\x1B[11~": "help"
1002
+ };
1003
+ });
1004
+
1005
+ // ../kit/src/redraw.ts
1006
+ function overwrite(lines, columns) {
1007
+ return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
1008
+ `);
1009
+ }
1010
+ function rowsTaken(lines, columns) {
1011
+ return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
1012
+ }
1013
+ var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
1014
+ var init_redraw = __esm(() => {
1015
+ init_format2();
1016
+ });
1017
+
1018
+ // ../kit/src/prompt.ts
1019
+ import process20 from "process";
1020
+ function readKeys(input, paste = { active: false }) {
1021
+ return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
1022
+ }
1023
+ async function confirm(question, { default: fallback, ...settings } = {}) {
1024
+ let answered = fallback;
1025
+ const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
1026
+ const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
1027
+ if (key === "cancel")
1028
+ return "cancel";
1029
+ if (key === "enter")
1030
+ return answered === undefined ? undefined : "enter";
1031
+ const letter = typeof key === "object" ? key.text.toLowerCase() : "";
1032
+ if (letter !== "y" && letter !== "n")
1033
+ return;
1034
+ answered = letter === "y";
1035
+ return "enter";
1036
+ });
1037
+ return accepted ? answered : undefined;
1038
+ }
1039
+ function asking(colors, question, typed, keys) {
1040
+ return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
1041
+ }
1042
+ function answer(colors, question, state, picked) {
1043
+ return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
1044
+ }
1045
+ async function ask(question, { hint, terminal = process20 }, render, press) {
1046
+ const { stdin, stderr } = terminal;
1047
+ if (!isInteractive(terminal))
1048
+ fail(`cannot ask "${question}" off a terminal`, 2, hint);
1049
+ const colors = paint(stderr);
1050
+ let current = "asking";
1051
+ let outcome;
1052
+ const columns = () => stderr.columns || 80;
1053
+ const draw = (state, last = false) => {
1054
+ const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
1055
+ const rows = rowsTaken(frame, columns());
1056
+ stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
1057
+ current = state;
1058
+ };
1059
+ const redraw = () => draw(current);
1060
+ const paste = { active: false };
1061
+ const stop = terminal.stop ?? (terminal === process20 ? stopJob : undefined);
1062
+ const suspend = () => {
1063
+ if (stop === undefined)
1064
+ return;
1065
+ stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
1066
+ stdin.setRawMode(false);
1067
+ stop();
1068
+ stdin.setRawMode(true);
1069
+ stderr.write("\x1B[?25l\x1B[?2004h");
1070
+ };
1071
+ try {
1072
+ stderr.on?.("resize", redraw);
1073
+ stdin.setRawMode(true);
1074
+ stdin.resume();
1075
+ stderr.write("\x1B[?25l\x1B[?2004h");
1076
+ draw("asking");
1077
+ return await new Promise((resolve) => {
1078
+ function onData(data) {
1079
+ for (const key of readKeys(data.toString(), paste)) {
1080
+ if (key === "suspend") {
1081
+ suspend();
1082
+ continue;
1083
+ }
1084
+ const pressed = press(key);
1085
+ if (pressed !== undefined) {
1086
+ settle(pressed);
1087
+ return;
1088
+ }
1089
+ }
1090
+ draw("asking");
1091
+ }
1092
+ function onEnd() {
1093
+ settle("cancel");
1094
+ }
1095
+ function settle(settled) {
1096
+ outcome = settled;
1097
+ stdin.off("data", onData);
1098
+ stdin.off("end", onEnd);
1099
+ resolve(settled === "enter");
1100
+ }
1101
+ stdin.on("data", onData);
1102
+ stdin.on("end", onEnd);
1103
+ });
1104
+ } finally {
1105
+ stderr.off?.("resize", redraw);
1106
+ draw(outcome ?? "cancel", true);
1107
+ stderr.write(`
1108
+ \x1B[?25h\x1B[?2004l`);
1109
+ stdin.setRawMode(false);
1110
+ stdin.pause();
1111
+ }
1112
+ }
1113
+ var PROMPT_KEYS;
1114
+ var init_prompt = __esm(() => {
1115
+ init_answers();
1116
+ init_args();
1117
+ init_format2();
1118
+ init_job();
1119
+ init_mode();
1120
+ init_line();
1121
+ init_state();
1122
+ init_redraw();
1123
+ init_style();
1124
+ PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
1125
+ });
1126
+
1127
+ // src/proc-cli.ts
1128
+ import process23 from "process";
1129
+
1130
+ // ../kit/src/index.ts
1131
+ init_args();
1132
+
776
1133
  // ../kit/src/argv.ts
777
1134
  import { readFileSync as readFileSync2, realpathSync } from "fs";
778
1135
  import { resolve as resolve3 } from "path";
@@ -797,10 +1154,23 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
797
1154
  const after = at === -1 ? [] : cmdline.slice(at + 1);
798
1155
  return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
799
1156
  }
1157
+ // ../kit/src/chart.ts
1158
+ init_format2();
1159
+ init_mode();
1160
+ init_style();
1161
+ init_theme();
1162
+ // ../kit/src/ci.ts
1163
+ init_args();
1164
+ init_format2();
1165
+
1166
+ // ../kit/src/progress.ts
1167
+ init_format2();
1168
+
800
1169
  // ../kit/src/process.ts
801
1170
  import { constants } from "os";
802
1171
  import process11 from "process";
803
1172
  var KILL_GRACE_MS = 2000;
1173
+ var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
804
1174
  function exitCodeOf(code, signal) {
805
1175
  if (code !== null)
806
1176
  return code;
@@ -808,10 +1178,10 @@ function exitCodeOf(code, signal) {
808
1178
  return 128 + signal;
809
1179
  return signal === null ? 129 : 128 + constants.signals[signal];
810
1180
  }
811
- async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
1181
+ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
812
1182
  const chunks = [];
813
1183
  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 } : {} });
1184
+ 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
1185
  const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
816
1186
  const timers = [];
817
1187
  const killGroup = (killing) => {
@@ -851,12 +1221,19 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
851
1221
  stop();
852
1222
  continue;
853
1223
  }
1224
+ if (state.truncated)
1225
+ continue;
1226
+ let kept = data;
854
1227
  if (state.kept + data.length > maxBytes) {
1228
+ let cut = maxBytes - state.kept;
1229
+ while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
1230
+ cut--;
1231
+ kept = data.subarray(0, cut);
855
1232
  state.truncated = true;
856
- continue;
857
1233
  }
858
- state.kept += data.length;
859
- chunks.push({ stream: name, data });
1234
+ state.kept += kept.length;
1235
+ if (kept.length > 0)
1236
+ chunks.push({ stream: name, data: kept });
860
1237
  }
861
1238
  };
862
1239
  try {
@@ -873,6 +1250,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
873
1250
  const joined = () => Buffer.concat(chunks.map(({ data }) => data));
874
1251
  let output;
875
1252
  let text;
1253
+ let stdout;
876
1254
  return {
877
1255
  code: exitCodeOf(proc.exitCode, proc.signalCode),
878
1256
  chunks,
@@ -883,19 +1261,70 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
883
1261
  },
884
1262
  get text() {
885
1263
  return text ??= (output ??= joined()).toString();
1264
+ },
1265
+ get stdout() {
1266
+ return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
886
1267
  }
887
1268
  };
888
1269
  }
889
1270
 
890
1271
  // ../kit/src/progress.ts
1272
+ init_style();
1273
+ init_theme();
891
1274
  var ESC = String.fromCharCode(27);
892
1275
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
893
1276
  var RESET_STYLE = `${ESC}[0m`;
894
1277
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
1278
+
1279
+ // ../kit/src/ci.ts
1280
+ init_style();
1281
+
1282
+ // ../kit/src/tool.ts
1283
+ init_format2();
895
1284
  // ../kit/src/cli.ts
1285
+ init_args();
896
1286
  import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
897
1287
  import { dirname as dirname3, join as join5 } from "path";
898
- import process14 from "process";
1288
+ import process15 from "process";
1289
+
1290
+ // ../kit/src/askpass.ts
1291
+ import process12 from "process";
1292
+ var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1293
+ async function askpassClient(argv) {
1294
+ const socketPath = process12.env[SOCKET_VARIABLE];
1295
+ if (socketPath === undefined)
1296
+ return;
1297
+ const request = { prompt: argv[0] ?? "", ...process12.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
1298
+ const { promise, resolve } = Promise.withResolvers();
1299
+ let received = "";
1300
+ try {
1301
+ await Bun.connect({
1302
+ unix: socketPath,
1303
+ socket: {
1304
+ open: (socket) => void socket.write(`${JSON.stringify(request)}
1305
+ `),
1306
+ data: (_, chunk) => {
1307
+ received += chunk.toString();
1308
+ },
1309
+ close: () => resolve(received),
1310
+ error: () => resolve("")
1311
+ }
1312
+ });
1313
+ } catch {
1314
+ return 1;
1315
+ }
1316
+ const reply = await promise;
1317
+ if (reply === "")
1318
+ return 1;
1319
+ const { answer } = JSON.parse(reply);
1320
+ if (request.notice === true)
1321
+ return 0;
1322
+ if (answer === undefined)
1323
+ return 1;
1324
+ process12.stdout.write(`${answer}
1325
+ `);
1326
+ return 0;
1327
+ }
899
1328
 
900
1329
  // ../kit/src/completions.ts
901
1330
  var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
@@ -958,34 +1387,42 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
958
1387
  }
959
1388
 
960
1389
  // ../kit/src/notify.ts
961
- import process12 from "process";
1390
+ init_format2();
1391
+ init_mode();
1392
+ import process13 from "process";
962
1393
  var NOTIFY_AFTER_MS = 1e4;
963
1394
  var CANCELLED = 130;
964
1395
  function base64(text) {
965
1396
  return Buffer.from(text).toString("base64");
966
1397
  }
967
- function notification(title, body, env = process12.env) {
968
- const id = `kit${process12.pid}`;
1398
+ function notification(title, body, env = process13.env) {
1399
+ const id = `kit${process13.pid}`;
969
1400
  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
1401
  return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
971
1402
  }
972
- function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
1403
+ function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
973
1404
  if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
974
1405
  return;
975
1406
  stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
976
1407
  }
977
1408
 
1409
+ // ../kit/src/cli.ts
1410
+ init_style();
1411
+ init_text2();
1412
+
978
1413
  // ../kit/src/usage.ts
979
1414
  import { appendFileSync, mkdirSync } from "fs";
980
1415
  import { homedir as homedir3 } from "os";
981
- import { dirname as dirname2, isAbsolute, join as join4 } from "path";
982
- import process13 from "process";
1416
+ import { dirname as dirname2, join as join4 } from "path";
1417
+ import process14 from "process";
983
1418
 
984
1419
  // ../kit/src/logs.ts
1420
+ init_user_config();
985
1421
  var DAY_MS = 24 * 60 * 60 * 1000;
986
1422
  var CLI_FOLDER = "kaynooo-cli";
987
1423
 
988
1424
  // ../kit/src/usage.ts
1425
+ init_user_config();
989
1426
  var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
990
1427
  var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
991
1428
  var LONGEST_NAME = 40;
@@ -993,14 +1430,13 @@ var usageError;
993
1430
  function noteUsageError(message) {
994
1431
  usageError = message;
995
1432
  }
996
- function stateHome(env = process13.env) {
997
- const dir = env.XDG_STATE_HOME;
998
- return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1433
+ function stateHome(env = process14.env) {
1434
+ return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
999
1435
  }
1000
- function usagePath(env = process13.env) {
1436
+ function usagePath(env = process14.env) {
1001
1437
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
1002
1438
  }
1003
- function usageRecorded(env = process13.env) {
1439
+ function usageRecorded(env = process14.env) {
1004
1440
  const off = env.KAYNOOO_CLI_NO_USAGE;
1005
1441
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1006
1442
  }
@@ -1009,12 +1445,12 @@ function flagNames(argv) {
1009
1445
  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
1446
  return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
1011
1447
  }
1012
- function usageEntry(bin, command, argv, code, now = new Date) {
1448
+ function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
1013
1449
  const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
1014
1450
  usageError = undefined;
1015
- return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1451
+ return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
1016
1452
  }
1017
- function recordUsage(entry, env = process13.env) {
1453
+ function recordUsage(entry, env = process14.env) {
1018
1454
  if (!usageRecorded(env))
1019
1455
  return;
1020
1456
  try {
@@ -1069,6 +1505,10 @@ function takeOutputFlags(argv) {
1069
1505
  async function resolveSummary(summary) {
1070
1506
  return typeof summary === "string" ? summary : summary();
1071
1507
  }
1508
+ function lookup({ commands, aliases }, word) {
1509
+ const name = aliases !== undefined && Object.hasOwn(aliases, word) ? aliases[word] ?? word : word;
1510
+ return Object.hasOwn(commands, name) ? commands[name] : undefined;
1511
+ }
1072
1512
  function scopeOf(commands, extra, aliases) {
1073
1513
  return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
1074
1514
  }
@@ -1108,8 +1548,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1108
1548
  `);
1109
1549
  }
1110
1550
  function printError(prefix, message, hint, cause) {
1111
- const colors = paint(process14.stderr);
1112
- const styled = takesControlCodes(process14.stderr);
1551
+ const colors = paint(process15.stderr);
1552
+ const styled = takesControlCodes(process15.stderr);
1113
1553
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1114
1554
  const under = (label, text, tint) => text === undefined ? "" : `
1115
1555
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1152,23 +1592,23 @@ async function dispatch(level, typed, { version, redact }) {
1152
1592
  }
1153
1593
  }
1154
1594
  if (name === undefined && level.path.length > 1) {
1155
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
1595
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
1156
1596
  return 2;
1157
1597
  }
1158
1598
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1159
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
1599
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
1160
1600
  return 0;
1161
1601
  }
1162
1602
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
1163
1603
  console.log(version);
1164
1604
  return 0;
1165
1605
  }
1166
- let command = level.commands[level.aliases?.[name] ?? name];
1606
+ let command = lookup(level, name);
1167
1607
  let rest = args;
1168
1608
  let ran = name;
1169
1609
  if (command === undefined && level.lazy.length > 0) {
1170
1610
  level = await expand(level, [...level.path.slice(1), ...argv]);
1171
- command = level.commands[level.aliases?.[name] ?? name];
1611
+ command = lookup(level, name);
1172
1612
  }
1173
1613
  if (command === undefined && level.defaultCommand !== undefined) {
1174
1614
  command = level.commands[level.defaultCommand];
@@ -1248,18 +1688,19 @@ async function leafCandidates(run, words) {
1248
1688
  async function candidates(scope, defaultCommand, words, before = []) {
1249
1689
  const [word = "", ...rest] = words;
1250
1690
  const listing = rest.length === 0 && !word.startsWith("-");
1251
- let { commands, aliases } = scope;
1252
- let command = commands[aliases?.[word] ?? word];
1691
+ let { commands } = scope;
1692
+ let command = lookup(scope, word);
1253
1693
  if (listing || command === undefined) {
1254
- ({ commands, aliases } = await expand(scope, [...before, ...words]));
1255
- command = commands[aliases?.[word] ?? word];
1694
+ const expanded = await expand(scope, [...before, ...words]);
1695
+ commands = expanded.commands;
1696
+ command = lookup(expanded, word);
1256
1697
  }
1257
1698
  if (listing) {
1258
1699
  const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
1259
1700
  const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
1260
1701
  const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
1261
1702
  const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
1262
- return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line) in commands))];
1703
+ return [...own, ...values.filter((line) => line !== FILES && !Object.hasOwn(commands, valueOf(line)))];
1263
1704
  }
1264
1705
  if (command === undefined) {
1265
1706
  const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
@@ -1302,6 +1743,9 @@ function packageVersion(entry = Bun.main) {
1302
1743
  }
1303
1744
  async function runCli(cli, argv = scriptArgs()) {
1304
1745
  const version = cli.version ?? packageVersion();
1746
+ const answered = await askpassClient(argv);
1747
+ if (answered !== undefined)
1748
+ return answered;
1305
1749
  if (argv[0] === COMPLETE)
1306
1750
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1307
1751
  if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
@@ -1312,7 +1756,7 @@ async function runCli(cli, argv = scriptArgs()) {
1312
1756
  notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
1313
1757
  if (cli.usage !== false) {
1314
1758
  try {
1315
- recordUsage(usageEntry(cli.name, command, argv, code));
1759
+ recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
1316
1760
  } catch {}
1317
1761
  }
1318
1762
  return code;
@@ -1321,8 +1765,7 @@ function commandPath(scope, argv) {
1321
1765
  const path = [];
1322
1766
  let level = scope;
1323
1767
  for (const word of argv.filter((each) => !each.startsWith("-"))) {
1324
- const name = level.aliases !== undefined && Object.hasOwn(level.aliases, word) ? level.aliases[word] ?? word : word;
1325
- const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
1768
+ const command = lookup(level, word);
1326
1769
  if (command === undefined)
1327
1770
  break;
1328
1771
  path.push(word);
@@ -1332,31 +1775,71 @@ function commandPath(scope, argv) {
1332
1775
  }
1333
1776
  return path.length === 0 ? undefined : path.join(" ");
1334
1777
  }
1335
- // ../kit/src/folders.ts
1336
- var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1778
+
1779
+ // ../kit/src/index.ts
1780
+ init_config();
1781
+
1782
+ // ../kit/src/excerpt.ts
1783
+ init_text2();
1784
+
1785
+ // ../kit/src/index.ts
1786
+ init_folders();
1787
+ init_format2();
1788
+
1789
+ // ../kit/src/git.ts
1790
+ init_args();
1791
+ // ../kit/src/limit.ts
1792
+ init_args();
1793
+
1794
+ // ../kit/src/index.ts
1795
+ init_mode();
1796
+
1797
+ // ../kit/src/report.ts
1798
+ init_style();
1799
+ init_text2();
1337
1800
  // ../kit/src/secrets.ts
1338
- var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
1801
+ var SECRET_PART = /token|secret|passw|passphrase|credential|private|dsn|apikey|accesskey|authorization|sess(?:ion)?id|connectionstring|key$/i;
1339
1802
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1340
1803
  var WORD_BREAKS = /[^a-zA-Z\d]+|(?<=[a-z\d])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/;
1804
+ var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
1805
+ function isSecretWord(word) {
1806
+ const lower = word.toLowerCase();
1807
+ return SECRET_WORDS.has(lower) || lower.endsWith("pass") && !NOT_PASSWORDS.has(lower);
1808
+ }
1341
1809
  function isSecretName(name) {
1342
- return SECRET_PART.test(name) || name.split(WORD_BREAKS).some((word) => SECRET_WORDS.has(word.toLowerCase()));
1810
+ return SECRET_PART.test(name) || name.split(WORD_BREAKS).some(isSecretWord);
1343
1811
  }
1344
1812
  // ../kit/src/sessions.ts
1345
1813
  var {Glob } = globalThis.Bun;
1346
1814
  var SESSION_FILES = new Glob("*.json");
1347
1815
  var ACCOUNT_DIRS = new Glob("*/sessions");
1348
1816
  // ../kit/src/size.ts
1349
- var SIZE = /^(\d+(?:\.\d+)?)\s*([kmgt]?)i?b?$/i;
1817
+ var SIZE = /^(\d+(?:\.\d+)?)\s*(?:([kmgt])i?b?|(b))?$/i;
1350
1818
  var POWERS = { "": 0, k: 1, m: 2, g: 3, t: 4 };
1351
1819
  function parseSize(text, bareUnit = 1) {
1352
1820
  const match = SIZE.exec(text.trim());
1353
1821
  if (match === null)
1354
1822
  return;
1355
- const suffix = match[2].toLowerCase();
1356
- return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
1823
+ const suffix = match[2]?.toLowerCase();
1824
+ let unit = bareUnit;
1825
+ if (match[3] !== undefined)
1826
+ unit = 1;
1827
+ else if (suffix !== undefined)
1828
+ unit = 1024 ** POWERS[suffix];
1829
+ return Math.round(Number(match[1]) * unit);
1357
1830
  }
1831
+
1832
+ // ../kit/src/index.ts
1833
+ init_style();
1834
+ init_text2();
1835
+ init_theme();
1836
+ init_user_config();
1837
+
1358
1838
  // ../kit/src/watch.ts
1359
- import process15 from "process";
1839
+ init_args();
1840
+ init_input();
1841
+ init_style();
1842
+ import process16 from "process";
1360
1843
  import { format } from "util";
1361
1844
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1362
1845
  var DEFAULT_SECONDS = 2;
@@ -1378,7 +1861,7 @@ function withoutWatch(args) {
1378
1861
  }
1379
1862
  return rest;
1380
1863
  }
1381
- async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1864
+ async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1382
1865
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1383
1866
  if (!takesControlCodes(stream))
1384
1867
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1386,12 +1869,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1386
1869
  for (let round = 0;round < rounds; round++) {
1387
1870
  const held = [];
1388
1871
  const { log, info } = console;
1389
- const write = process15.stdout.write.bind(process15.stdout);
1872
+ const write = process16.stdout.write.bind(process16.stdout);
1390
1873
  const hold = (...parts) => void held.push(`${format(...parts)}
1391
1874
  `);
1392
1875
  console.log = hold;
1393
1876
  console.info = hold;
1394
- process15.stdout.write = (text) => {
1877
+ process16.stdout.write = (text) => {
1395
1878
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1396
1879
  return true;
1397
1880
  };
@@ -1400,15 +1883,17 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1400
1883
  } finally {
1401
1884
  console.log = log;
1402
1885
  console.info = info;
1403
- process15.stdout.write = write;
1886
+ process16.stdout.write = write;
1404
1887
  }
1405
1888
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1406
1889
  await sleep(interval);
1407
1890
  }
1408
1891
  return code;
1409
1892
  }
1893
+ // ../kit/src/workspace-root.ts
1894
+ init_user_config();
1410
1895
  // src/pid.ts
1411
- import process17 from "process";
1896
+ import process18 from "process";
1412
1897
 
1413
1898
  // src/mask.ts
1414
1899
  import { basename } from "path";
@@ -1734,10 +2219,10 @@ async function userName(uid) {
1734
2219
  }
1735
2220
 
1736
2221
  // src/pid.ts
1737
- var usage2 = `proc pid <pid>
2222
+ 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
1738
2223
 
1739
- 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.
1740
- The environment is not shown unless --env is given, with every value that looks like a secret masked.`;
2224
+ Everything is read from \`/proc\`; what the calling user cannot read of another user's process is left out and named at the end.
2225
+ The environment is not shown unless --env is given, with every secret masked.`;
1741
2226
  var EXITS = [[0, "it showed the process"], [1, "no process has this pid"], [2, "a usage error"]];
1742
2227
  var DIGITS2 = /^\d+$/;
1743
2228
  var options = {
@@ -1810,7 +2295,7 @@ function limitLine(limits, name) {
1810
2295
  return limit === undefined ? "-" : `soft ${limit.soft}, hard ${limit.hard}`;
1811
2296
  }
1812
2297
  function render(info, showEnv) {
1813
- const colors = paint(process17.stdout);
2298
+ const colors = paint(process18.stdout);
1814
2299
  const memory = info.memory;
1815
2300
  const size = (bytes) => bytes === undefined ? "-" : tt(bytes);
1816
2301
  const rows = [
@@ -1864,213 +2349,8 @@ async function pid(args) {
1864
2349
 
1865
2350
  // src/ports.ts
1866
2351
  import { basename as basename2 } from "path";
1867
- import process20 from "process";
1868
-
1869
- // ../kit/src/prompt.ts
1870
- import process19 from "process";
1871
-
1872
- // ../kit/src/job.ts
1873
- import process18 from "process";
1874
- function stopJob() {
1875
- process18.kill(0, "SIGTSTP");
1876
- }
1877
-
1878
- // ../kit/src/picker/line.ts
1879
- var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
1880
- var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
1881
- var FORWARD_KILLS = new Set(["killnext", "killend"]);
1882
- function isEditKey(key) {
1883
- return EDIT_KEYS.has(key);
1884
- }
1885
-
1886
- // ../kit/src/picker/score.ts
1887
- var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
1888
- var NONE = Number.NEGATIVE_INFINITY;
1889
-
1890
- // ../kit/src/picker/state.ts
1891
- var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
1892
- var PASTE_START = "\x1B[200~";
1893
- var PASTE_END = "\x1B[201~";
1894
- var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1895
- var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
1896
- var WHEEL_LINES = 3;
1897
- var KEYS = {
1898
- "\x1B[A": "up",
1899
- "\x1BOA": "up",
1900
- "\x10": "up",
1901
- "\x1B[B": "down",
1902
- "\x1BOB": "down",
1903
- "\x0E": "down",
1904
- "\x1B[5~": "pageup",
1905
- "\x1B[6~": "pagedown",
1906
- "\x1B[H": "home",
1907
- "\x1B[1~": "home",
1908
- "\x1BOH": "home",
1909
- "\x1B[F": "end",
1910
- "\x1B[4~": "end",
1911
- "\x1BOF": "end",
1912
- "\r": "enter",
1913
- "\n": "enter",
1914
- "\x03": "cancel",
1915
- "\x1B": "cancel",
1916
- "\x1B[D": "left",
1917
- "\x1BOD": "left",
1918
- "\x1B[C": "right",
1919
- "\x1BOC": "right",
1920
- "\x1B[1;5D": "wordleft",
1921
- "\x1B[1;3D": "wordleft",
1922
- "\x1Bb": "wordleft",
1923
- "\x1B[1;5C": "wordright",
1924
- "\x1B[1;3C": "wordright",
1925
- "\x1Bf": "wordright",
1926
- "\x01": "linestart",
1927
- "\x05": "lineend",
1928
- "\x7F": "erase",
1929
- "\x1B[3~": "delete",
1930
- "\b": "killword",
1931
- "\x1B\x7F": "killword",
1932
- "\x1B[3;5~": "killnext",
1933
- "\x1Bd": "killnext",
1934
- "\x15": "clear",
1935
- "\v": "killend",
1936
- "\x17": "word",
1937
- "\x19": "yank",
1938
- "\x1A": "suspend",
1939
- "\t": "tab",
1940
- "\x1F": "help",
1941
- "\x1BOP": "help",
1942
- "\x1B[11~": "help"
1943
- };
1944
- function repeat(value, count) {
1945
- return Array.from({ length: count }).fill(value);
1946
- }
1947
- function parseKeys(input, paste = { active: false }, ctrls = []) {
1948
- const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
1949
- return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
1950
- const wheel = MOUSE.exec(sequence)?.[1];
1951
- if (wheel !== undefined)
1952
- return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
1953
- const named = codes.get(sequence);
1954
- const key = named === undefined ? KEYS[sequence] : { ctrl: named };
1955
- if (sequence === PASTE_START || sequence === PASTE_END) {
1956
- paste.active = sequence === PASTE_START;
1957
- return [];
1958
- }
1959
- if (paste.active && (sequence === "\r" || sequence === `
1960
- `))
1961
- return [];
1962
- if (key !== undefined)
1963
- return [key];
1964
- return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
1965
- });
1966
- }
1967
-
1968
- // ../kit/src/redraw.ts
1969
- var SYNC_START = "\x1B[?2026h";
1970
- var SYNC_END = "\x1B[?2026l";
1971
- function overwrite(lines, columns) {
1972
- return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
1973
- `);
1974
- }
1975
- function rowsTaken(lines, columns) {
1976
- return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
1977
- }
1978
-
1979
- // ../kit/src/prompt.ts
1980
- var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
1981
- function readKeys(input, paste = { active: false }) {
1982
- return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
1983
- }
1984
- async function confirm(question, { default: fallback, ...settings } = {}) {
1985
- let answered = fallback;
1986
- const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
1987
- const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
1988
- if (key === "cancel")
1989
- return "cancel";
1990
- if (key === "enter")
1991
- return answered === undefined ? undefined : "enter";
1992
- const letter = typeof key === "object" ? key.text.toLowerCase() : "";
1993
- if (letter !== "y" && letter !== "n")
1994
- return;
1995
- answered = letter === "y";
1996
- return "enter";
1997
- });
1998
- return accepted ? answered : undefined;
1999
- }
2000
- function asking(colors, question, typed, keys) {
2001
- return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
2002
- }
2003
- function answer(colors, question, state, picked) {
2004
- return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
2005
- }
2006
- async function ask(question, { hint, terminal = process19 }, render, press) {
2007
- const { stdin, stderr } = terminal;
2008
- if (!isInteractive(terminal))
2009
- fail(`cannot ask "${question}" off a terminal`, 2, hint);
2010
- const colors = paint(stderr);
2011
- let current = "asking";
2012
- let outcome;
2013
- const columns = () => stderr.columns || 80;
2014
- const draw = (state, last = false) => {
2015
- const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
2016
- const rows = rowsTaken(frame, columns());
2017
- stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
2018
- current = state;
2019
- };
2020
- const redraw = () => draw(current);
2021
- const paste = { active: false };
2022
- const stop = terminal.stop ?? (terminal === process19 ? stopJob : undefined);
2023
- const suspend = () => {
2024
- if (stop === undefined)
2025
- return;
2026
- stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
2027
- stdin.setRawMode(false);
2028
- stop();
2029
- stdin.setRawMode(true);
2030
- stderr.write("\x1B[?25l\x1B[?2004h");
2031
- };
2032
- try {
2033
- stderr.on?.("resize", redraw);
2034
- stdin.setRawMode(true);
2035
- stdin.resume();
2036
- stderr.write("\x1B[?25l\x1B[?2004h");
2037
- draw("asking");
2038
- return await new Promise((resolve) => {
2039
- function onData(data) {
2040
- for (const key of readKeys(data.toString(), paste)) {
2041
- if (key === "suspend") {
2042
- suspend();
2043
- continue;
2044
- }
2045
- const pressed = press(key);
2046
- if (pressed !== undefined) {
2047
- settle(pressed);
2048
- return;
2049
- }
2050
- }
2051
- draw("asking");
2052
- }
2053
- function onEnd() {
2054
- settle("cancel");
2055
- }
2056
- function settle(settled) {
2057
- outcome = settled;
2058
- stdin.off("data", onData);
2059
- stdin.off("end", onEnd);
2060
- resolve(settled === "enter");
2061
- }
2062
- stdin.on("data", onData);
2063
- stdin.on("end", onEnd);
2064
- });
2065
- } finally {
2066
- stderr.off?.("resize", redraw);
2067
- draw(outcome ?? "cancel", true);
2068
- stderr.write(`
2069
- \x1B[?25h\x1B[?2004l`);
2070
- stdin.setRawMode(false);
2071
- stdin.pause();
2072
- }
2073
- }
2352
+ import process21 from "process";
2353
+ init_prompt();
2074
2354
 
2075
2355
  // src/docker.ts
2076
2356
  var FORMAT = '{{.Names}}\t{{.Ports}}\t{{.Label "com.docker.compose.project"}}\t{{.Label "com.docker.compose.service"}}';
@@ -2148,11 +2428,10 @@ async function terminate(pids, { escalate, graceMs, signaller = realSignaller })
2148
2428
  }
2149
2429
 
2150
2430
  // src/ports.ts
2151
- var usage3 = `proc ports [port]
2431
+ var usage3 = `proc ports [port]: lists what listens on this machine, one row per port with its owning process, command and working directory
2152
2432
 
2153
- 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 -.
2154
- \`proc ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
2155
- \`proc 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.`;
2433
+ 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.
2434
+ \`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.`;
2156
2435
  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"]];
2157
2436
  var options2 = {
2158
2437
  json: jsonOption("[{ port, protocol, addresses, pid, command, cwd, container }]"),
@@ -2202,7 +2481,7 @@ function refusal(row, proc, guard) {
2202
2481
  return reason === undefined ? undefined : `pid ${row.pid} is ${reason}`;
2203
2482
  }
2204
2483
  function render2(rows) {
2205
- const colors = paint(process20.stdout);
2484
+ const colors = paint(process21.stdout);
2206
2485
  const cells = rows.map((row) => [
2207
2486
  colors.cyan(String(row.port)),
2208
2487
  row.protocol,
@@ -2214,7 +2493,7 @@ function render2(rows) {
2214
2493
  return table([["PORT", "PROTO", "ADDRESS", "PID", "COMMAND", "CWD"], ...cells], { header: true });
2215
2494
  }
2216
2495
  async function stop(port, rows, procs, values) {
2217
- const guard = { uid: process20.getuid?.() ?? -1, mine: new Set(ancestry(process20.pid, procs)) };
2496
+ const guard = { uid: process21.getuid?.() ?? -1, mine: new Set(ancestry(process21.pid, procs)) };
2218
2497
  const targets = new Map;
2219
2498
  for (const row of rows) {
2220
2499
  const reason = refusal(row, row.pid === undefined ? undefined : procs.get(row.pid), guard);
@@ -2227,7 +2506,7 @@ async function stop(port, rows, procs, values) {
2227
2506
  return 1;
2228
2507
  const names = [...targets].map(([pid, row]) => `${pid} (${truncate(row.command ?? "", 40)})`).join(", ");
2229
2508
  if (values.yes !== true) {
2230
- if (!process20.stdin.isTTY)
2509
+ if (!process21.stdin.isTTY)
2231
2510
  fail(`stopping ${names} needs a terminal to ask on: pass --yes`, 2);
2232
2511
  if (await confirm(`Stop ${names}?`, { default: false }) !== true)
2233
2512
  return 1;
@@ -2259,7 +2538,7 @@ async function ports(args) {
2259
2538
  badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
2260
2539
  if (values.kill === true && port === undefined)
2261
2540
  badUsage("--kill takes the port to free: proc ports <port> --kill");
2262
- const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process20.getuid?.())]);
2541
+ const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process21.getuid?.())]);
2263
2542
  const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
2264
2543
  const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
2265
2544
  const needsDocker = wanted.some((socket) => {
@@ -2280,14 +2559,14 @@ async function ports(args) {
2280
2559
  console.log(render2(rows));
2281
2560
  const unknown = rows.filter((row) => row.pid === undefined && row.container === undefined).length;
2282
2561
  if (unknown > 0)
2283
- console.error(paint(process20.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
2562
+ console.error(paint(process21.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
2284
2563
  return 0;
2285
2564
  }
2286
2565
 
2287
2566
  // src/procs.ts
2288
2567
  import { existsSync as existsSync3 } from "fs";
2289
2568
  import { homedir as homedir4 } from "os";
2290
- import process21 from "process";
2569
+ import process22 from "process";
2291
2570
 
2292
2571
  // src/select.ts
2293
2572
  import { basename as basename3, join as join6, relative } from "path";
@@ -2403,11 +2682,10 @@ function selectGroups(procs, options) {
2403
2682
  }
2404
2683
 
2405
2684
  // src/procs.ts
2406
- var usage4 = `proc procs
2685
+ var usage4 = `proc procs: lists the calling user's leftover or heavy dev processes, grouped by project folder, browser profile or command
2407
2686
 
2408
- 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.
2409
- 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.
2410
- \`--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.`;
2687
+ 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.
2688
+ \`--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.`;
2411
2689
  var EXITS3 = [[0, "it listed or stopped everything"], [1, "a process survived SIGKILL"], [2, "a usage error"]];
2412
2690
  var options3 = {
2413
2691
  json: jsonOption("{ groups: [{ origin, kind, count, rss, oldestSeconds, tools, orphans, pids, processes }], skipped }"),
@@ -2436,7 +2714,7 @@ function summary(group) {
2436
2714
  };
2437
2715
  }
2438
2716
  function render3(groups) {
2439
- const colors = paint(process21.stdout);
2717
+ const colors = paint(process22.stdout);
2440
2718
  const rows = groups.map((group) => [
2441
2719
  group.origin,
2442
2720
  String(group.members.length),
@@ -2464,9 +2742,9 @@ async function procs(args) {
2464
2742
  if (values.watch !== undefined)
2465
2743
  return watching(values.watch, async () => procs(withoutWatch(args)));
2466
2744
  const olderMs = values.older === undefined ? undefined : duration(values.older, "older", 0, "m");
2467
- const uid = process21.getuid?.() ?? -1;
2745
+ const uid = process22.getuid?.() ?? -1;
2468
2746
  const all = await snapshot("/proc", (owner) => owner === uid);
2469
- const mine = new Set(ancestry(process21.pid, new Map(all.map((proc) => [proc.pid, proc]))));
2747
+ const mine = new Set(ancestry(process22.pid, new Map(all.map((proc) => [proc.pid, proc]))));
2470
2748
  const { groups, protectedCount } = selectGroups(all, { guard: { uid, mine }, now: Date.now(), home: homedir4(), exists: existsSync3, minMem, olderMs });
2471
2749
  const pids = groups.flatMap((group) => group.members.map(({ proc }) => proc.pid));
2472
2750
  const show = (extra = {}) => {
@@ -2479,7 +2757,7 @@ async function procs(args) {
2479
2757
  if (values.kill !== true || pids.length === 0 || values.yes !== true) {
2480
2758
  show();
2481
2759
  if (values.json !== true && protectedCount > 0)
2482
- console.error(paint(process21.stderr).dim(`${protectedCount} more left out: shells, terminals and this command's ancestors are never touched`));
2760
+ console.error(paint(process22.stderr).dim(`${protectedCount} more left out: shells, terminals and this command's ancestors are never touched`));
2483
2761
  if (values.kill === true && pids.length > 0)
2484
2762
  console.error(`dry run: would stop ${pids.length} ${pids.length === 1 ? "process" : "processes"} (${pids.join(" ")}), pass --yes to do it`);
2485
2763
  return 0;
@@ -2495,7 +2773,7 @@ async function procs(args) {
2495
2773
  }
2496
2774
 
2497
2775
  // src/proc-cli.ts
2498
- process22.exitCode = await runCli({
2776
+ process23.exitCode = await runCli({
2499
2777
  name: "proc",
2500
2778
  about: "what a process is, who listens on a port and which dev processes are worth cleaning, read from /proc",
2501
2779
  replaces: "cat /proc/<pid>/..., ss -ltnp, lsof -i and pgrep -f one-liners",