@kaynooo/cli-probe 0.4.1 → 0.4.4
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/probe.js +428 -156
- package/package.json +5 -5
package/dist/probe.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
+
var __esm = (fn, res, err) => () => {
|
|
4
|
+
if (fn)
|
|
5
|
+
try {
|
|
6
|
+
res = fn(fn = 0);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
err = [e];
|
|
9
|
+
}
|
|
10
|
+
if (err)
|
|
11
|
+
throw err[0];
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
3
14
|
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import process15 from "process";
|
|
7
|
-
// ../kit/src/args.ts
|
|
8
|
-
import process9 from "process";
|
|
9
|
-
import { parseArgs } from "util";
|
|
10
|
-
|
|
11
|
-
// ../kit/src/format.ts
|
|
12
|
-
import process7 from "process";
|
|
13
|
-
|
|
14
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
15
|
-
var N = new Map;
|
|
16
|
-
var Nt = /\s+\S*$/;
|
|
17
|
-
var Y = /\s/;
|
|
18
|
-
function ko(t, e, r = "...") {
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
16
|
+
function Ao(t, e, r = "...") {
|
|
19
17
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
20
18
|
if (t.length <= e)
|
|
21
19
|
return t;
|
|
@@ -26,13 +24,22 @@ function ko(t, e, r = "...") {
|
|
|
26
24
|
c = c.trimEnd();
|
|
27
25
|
return s ? (c + n).slice(0, l) : c + n;
|
|
28
26
|
}
|
|
29
|
-
var
|
|
30
|
-
var
|
|
27
|
+
var N, Nt, Y, be, W;
|
|
28
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
29
|
+
N = new Map;
|
|
30
|
+
Nt = /\s+\S*$/;
|
|
31
|
+
Y = /\s/;
|
|
32
|
+
be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
33
|
+
W = new Map;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
37
|
+
var init_text = __esm(() => {
|
|
38
|
+
init_chunk_rkhsft4a();
|
|
39
|
+
});
|
|
31
40
|
|
|
32
41
|
// ../kit/src/mode.ts
|
|
33
42
|
import process2 from "process";
|
|
34
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
35
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
36
43
|
function isSet(value) {
|
|
37
44
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
38
45
|
}
|
|
@@ -46,12 +53,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
46
53
|
return "terminal";
|
|
47
54
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
48
55
|
}
|
|
56
|
+
var MODES, AGENT_VARIABLES;
|
|
57
|
+
var init_mode = __esm(() => {
|
|
58
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
59
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
60
|
+
});
|
|
49
61
|
|
|
50
|
-
//
|
|
51
|
-
import process6 from "process";
|
|
52
|
-
|
|
53
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
54
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
62
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
55
63
|
function b(r) {
|
|
56
64
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
57
65
|
if (!G2.test(e))
|
|
@@ -62,11 +70,6 @@ function b(r) {
|
|
|
62
70
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
63
71
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
64
72
|
}
|
|
65
|
-
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") => {
|
|
66
|
-
let [l, n, c] = b(r);
|
|
67
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
68
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
69
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
70
73
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
71
74
|
if (e.FORCE_COLOR !== undefined)
|
|
72
75
|
return h.has(e.FORCE_COLOR);
|
|
@@ -80,7 +83,7 @@ function f(r, e = []) {
|
|
|
80
83
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
81
84
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
82
85
|
return new Proxy(c, { get(t, i) {
|
|
83
|
-
let a =
|
|
86
|
+
let a = B[i];
|
|
84
87
|
if (Array.isArray(a)) {
|
|
85
88
|
let s = g.get(i);
|
|
86
89
|
if (s === undefined)
|
|
@@ -103,13 +106,21 @@ function f(r, e = []) {
|
|
|
103
106
|
function Fe(r = {}) {
|
|
104
107
|
return f(r);
|
|
105
108
|
}
|
|
106
|
-
var
|
|
109
|
+
var G2, B, h, o;
|
|
110
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
111
|
+
G2 = /^[a-f0-9]+$/i;
|
|
112
|
+
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") => {
|
|
113
|
+
let [l, n, c] = b(r);
|
|
114
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
115
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
116
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
117
|
+
o = Fe();
|
|
118
|
+
});
|
|
107
119
|
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
import process5 from "process";
|
|
120
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
121
|
+
var init_colors = __esm(() => {
|
|
122
|
+
init_chunk_x450vn3m();
|
|
123
|
+
});
|
|
113
124
|
|
|
114
125
|
// ../kit/src/config.ts
|
|
115
126
|
import { existsSync } from "fs";
|
|
@@ -125,6 +136,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
125
136
|
return;
|
|
126
137
|
}
|
|
127
138
|
}
|
|
139
|
+
var init_config = __esm(() => {
|
|
140
|
+
init_args();
|
|
141
|
+
});
|
|
128
142
|
|
|
129
143
|
// ../kit/src/user-config.ts
|
|
130
144
|
import { homedir } from "os";
|
|
@@ -137,36 +151,18 @@ function configBase(where = {}) {
|
|
|
137
151
|
function userConfigPath(bin, where = {}) {
|
|
138
152
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
139
153
|
}
|
|
154
|
+
var init_user_config = () => {};
|
|
140
155
|
|
|
141
156
|
// ../kit/src/theme.ts
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
147
|
-
bins: {},
|
|
148
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
149
|
-
};
|
|
150
|
-
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" };
|
|
151
|
-
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" };
|
|
152
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
153
|
-
var PRESETS = {
|
|
154
|
-
default: {},
|
|
155
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
156
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
157
|
-
ascii: { glyphs: ASCII }
|
|
158
|
-
};
|
|
159
|
-
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"]);
|
|
160
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
161
|
-
var CONTROL = /\p{Cc}/u;
|
|
162
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
163
|
-
var SPACES = /\s+/;
|
|
157
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
158
|
+
import { homedir as homedir2 } from "os";
|
|
159
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
160
|
+
import process5 from "process";
|
|
164
161
|
function isColorSpec(spec) {
|
|
165
162
|
if (typeof spec === "number")
|
|
166
163
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
167
164
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
168
165
|
}
|
|
169
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
170
166
|
function cubeLevel(channel) {
|
|
171
167
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
172
168
|
}
|
|
@@ -271,7 +267,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
271
267
|
function endsWalk(home) {
|
|
272
268
|
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
273
269
|
}
|
|
274
|
-
var warned = new Set;
|
|
275
270
|
function warnOnce(message) {
|
|
276
271
|
if (warned.has(message))
|
|
277
272
|
return;
|
|
@@ -308,8 +303,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
308
303
|
}
|
|
309
304
|
return { theme, sources, preset };
|
|
310
305
|
}
|
|
311
|
-
var current;
|
|
312
|
-
var currentKey = "";
|
|
313
306
|
function activeTheme() {
|
|
314
307
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
315
308
|
if (current === undefined || key !== currentKey) {
|
|
@@ -318,9 +311,38 @@ function activeTheme() {
|
|
|
318
311
|
}
|
|
319
312
|
return current;
|
|
320
313
|
}
|
|
314
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
315
|
+
var init_theme = __esm(() => {
|
|
316
|
+
init_config();
|
|
317
|
+
init_user_config();
|
|
318
|
+
ENDS = new Map;
|
|
319
|
+
DEFAULT = {
|
|
320
|
+
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" },
|
|
321
|
+
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" },
|
|
322
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
323
|
+
bins: {},
|
|
324
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
325
|
+
};
|
|
326
|
+
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" };
|
|
327
|
+
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" };
|
|
328
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
329
|
+
PRESETS = {
|
|
330
|
+
default: {},
|
|
331
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
332
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
333
|
+
ascii: { glyphs: ASCII }
|
|
334
|
+
};
|
|
335
|
+
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"]);
|
|
336
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
337
|
+
CONTROL = /\p{Cc}/u;
|
|
338
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
339
|
+
SPACES = /\s+/;
|
|
340
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
341
|
+
warned = new Set;
|
|
342
|
+
});
|
|
321
343
|
|
|
322
344
|
// ../kit/src/style.ts
|
|
323
|
-
|
|
345
|
+
import process6 from "process";
|
|
324
346
|
function takesControlCodes(stream, env = process6.env) {
|
|
325
347
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
326
348
|
}
|
|
@@ -340,17 +362,24 @@ function role(name, stream, env = process6.env) {
|
|
|
340
362
|
const colors = paint(stream, env);
|
|
341
363
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
342
364
|
}
|
|
343
|
-
var STATUS_WORDS
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
365
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
366
|
+
var init_style = __esm(() => {
|
|
367
|
+
init_colors();
|
|
368
|
+
init_mode();
|
|
369
|
+
init_theme();
|
|
370
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
371
|
+
STATUS_WORDS = {
|
|
372
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
373
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
374
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
375
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
376
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
377
|
+
};
|
|
378
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
379
|
+
});
|
|
351
380
|
|
|
352
381
|
// ../kit/src/format.ts
|
|
353
|
-
|
|
382
|
+
import process7 from "process";
|
|
354
383
|
function formatSeconds(total) {
|
|
355
384
|
let rest = Math.max(0, Math.round(total));
|
|
356
385
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -372,10 +401,8 @@ function upTo(text, separator) {
|
|
|
372
401
|
return end === -1 ? text : text.slice(0, end);
|
|
373
402
|
}
|
|
374
403
|
function truncate(text, width) {
|
|
375
|
-
return
|
|
404
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
376
405
|
}
|
|
377
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
378
|
-
var ESCAPE = String.fromCharCode(27);
|
|
379
406
|
function textWidth(text) {
|
|
380
407
|
return Bun.stringWidth(text);
|
|
381
408
|
}
|
|
@@ -424,14 +451,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
424
451
|
function printJson(value) {
|
|
425
452
|
console.log(jsonText(value));
|
|
426
453
|
}
|
|
454
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
455
|
+
var init_format = __esm(() => {
|
|
456
|
+
init_text();
|
|
457
|
+
init_mode();
|
|
458
|
+
init_style();
|
|
459
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
460
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
461
|
+
ESCAPE = String.fromCharCode(27);
|
|
462
|
+
});
|
|
427
463
|
|
|
428
464
|
// ../kit/src/help.ts
|
|
429
465
|
import process8 from "process";
|
|
430
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
431
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
432
|
-
var FULL_STOP = /\.$/;
|
|
433
466
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
434
|
-
|
|
467
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
468
|
+
`);
|
|
469
|
+
const blank = lines.indexOf("");
|
|
470
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
471
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
472
|
+
const colon = synopses[0].indexOf(": ");
|
|
473
|
+
const inline = synopses[0].slice(colon + 2);
|
|
474
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
475
|
+
if (colon !== -1)
|
|
476
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
477
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
478
|
+
`)}`;
|
|
479
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
480
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
481
|
+
return [head, ...lead, ...rest].join(`
|
|
482
|
+
`);
|
|
483
|
+
}
|
|
484
|
+
function prose(line, colors) {
|
|
485
|
+
if (colors.cyan("x") === "x")
|
|
486
|
+
return line;
|
|
487
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
435
488
|
}
|
|
436
489
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
437
490
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -466,7 +519,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
466
519
|
return [];
|
|
467
520
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
468
521
|
}
|
|
469
|
-
var MAX_INLINE_CHOICES = 24;
|
|
470
522
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
471
523
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
472
524
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -481,6 +533,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
481
533
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
482
534
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
483
535
|
}
|
|
536
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
537
|
+
var init_help = __esm(() => {
|
|
538
|
+
init_mode();
|
|
539
|
+
init_style();
|
|
540
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
541
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
542
|
+
FULL_STOP = /\.$/;
|
|
543
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
544
|
+
});
|
|
484
545
|
|
|
485
546
|
// ../kit/src/text.ts
|
|
486
547
|
function distance(a, b) {
|
|
@@ -508,9 +569,9 @@ function closest(name, names) {
|
|
|
508
569
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
509
570
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
510
571
|
}
|
|
572
|
+
var init_text2 = () => {};
|
|
573
|
+
|
|
511
574
|
// ../kit/src/input.ts
|
|
512
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
513
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
514
575
|
function duration(value, name, fallback, unit = "s") {
|
|
515
576
|
if (value === undefined)
|
|
516
577
|
return fallback;
|
|
@@ -520,40 +581,26 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
520
581
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
521
582
|
return ms;
|
|
522
583
|
}
|
|
584
|
+
var DURATION, UNIT_MS;
|
|
585
|
+
var init_input = __esm(() => {
|
|
586
|
+
init_args();
|
|
587
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
588
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
589
|
+
});
|
|
523
590
|
|
|
524
591
|
// ../kit/src/args.ts
|
|
525
|
-
|
|
592
|
+
import process9 from "process";
|
|
593
|
+
import { parseArgs } from "util";
|
|
526
594
|
function jsonOption(holds) {
|
|
527
595
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
528
596
|
}
|
|
529
|
-
class Exit extends Error {
|
|
530
|
-
code;
|
|
531
|
-
hint;
|
|
532
|
-
constructor(message, code, hint) {
|
|
533
|
-
super(message);
|
|
534
|
-
this.code = code;
|
|
535
|
-
this.hint = hint;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
597
|
function fail(message, code = 2, hint) {
|
|
539
598
|
throw new Exit(message, code, hint);
|
|
540
599
|
}
|
|
541
|
-
|
|
542
|
-
class UsageError extends Exit {
|
|
543
|
-
constructor(message, hint) {
|
|
544
|
-
super(message, 2, hint);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
600
|
function badUsage(message) {
|
|
548
601
|
throw new UsageError(message);
|
|
549
602
|
}
|
|
550
603
|
|
|
551
|
-
class HelpShown extends Exit {
|
|
552
|
-
constructor() {
|
|
553
|
-
super("help shown", 0);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
604
|
class Completing {
|
|
558
605
|
options;
|
|
559
606
|
positionals;
|
|
@@ -564,11 +611,6 @@ class Completing {
|
|
|
564
611
|
this.candidates = candidates;
|
|
565
612
|
}
|
|
566
613
|
}
|
|
567
|
-
var completion = { active: false };
|
|
568
|
-
var OUTPUT_OPTIONS = {
|
|
569
|
-
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
570
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
571
|
-
};
|
|
572
614
|
function applyOutput(color, plain, env = process9.env) {
|
|
573
615
|
const when = plain === true ? "never" : color ?? "auto";
|
|
574
616
|
if (when === "auto")
|
|
@@ -722,7 +764,6 @@ function parseError(error) {
|
|
|
722
764
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
723
765
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
724
766
|
}
|
|
725
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
726
767
|
function nearestOption(message, options, allowNegative) {
|
|
727
768
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
728
769
|
if (typed === undefined)
|
|
@@ -738,6 +779,62 @@ function nearestOption(message, options, allowNegative) {
|
|
|
738
779
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
739
780
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
740
781
|
}
|
|
782
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
783
|
+
var init_args = __esm(() => {
|
|
784
|
+
init_format();
|
|
785
|
+
init_help();
|
|
786
|
+
init_text2();
|
|
787
|
+
init_help();
|
|
788
|
+
init_input();
|
|
789
|
+
DASHES = /^-+/;
|
|
790
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
791
|
+
Exit = class Exit extends Error {
|
|
792
|
+
code;
|
|
793
|
+
hint;
|
|
794
|
+
[EXIT] = true;
|
|
795
|
+
constructor(message, code, hint) {
|
|
796
|
+
super(message);
|
|
797
|
+
this.code = code;
|
|
798
|
+
this.hint = hint;
|
|
799
|
+
}
|
|
800
|
+
static [Symbol.hasInstance](value) {
|
|
801
|
+
if (this !== Exit)
|
|
802
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
803
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
UsageError = class UsageError extends Exit {
|
|
807
|
+
constructor(message, hint) {
|
|
808
|
+
super(message, 2, hint);
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
HelpShown = class HelpShown extends Exit {
|
|
812
|
+
constructor() {
|
|
813
|
+
super("help shown", 0);
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
completion = { active: false };
|
|
817
|
+
OUTPUT_OPTIONS = {
|
|
818
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
819
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
820
|
+
};
|
|
821
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
// ../kit/src/folders.ts
|
|
825
|
+
var SKIPPED_FOLDERS;
|
|
826
|
+
var init_folders = __esm(() => {
|
|
827
|
+
init_user_config();
|
|
828
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
// src/probe.ts
|
|
832
|
+
import { isIP as isIP2 } from "net";
|
|
833
|
+
import process16 from "process";
|
|
834
|
+
|
|
835
|
+
// ../kit/src/index.ts
|
|
836
|
+
init_args();
|
|
837
|
+
|
|
741
838
|
// ../kit/src/argv.ts
|
|
742
839
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
743
840
|
import { resolve as resolve3 } from "path";
|
|
@@ -762,39 +859,163 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
762
859
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
763
860
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
764
861
|
}
|
|
862
|
+
// ../kit/src/chart.ts
|
|
863
|
+
init_format();
|
|
864
|
+
init_mode();
|
|
865
|
+
init_style();
|
|
866
|
+
init_theme();
|
|
867
|
+
// ../kit/src/ci.ts
|
|
868
|
+
init_args();
|
|
869
|
+
init_format();
|
|
870
|
+
|
|
765
871
|
// ../kit/src/progress.ts
|
|
872
|
+
init_format();
|
|
873
|
+
init_style();
|
|
874
|
+
init_theme();
|
|
766
875
|
var ESC = String.fromCharCode(27);
|
|
767
876
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
768
877
|
var RESET_STYLE = `${ESC}[0m`;
|
|
769
878
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
879
|
+
|
|
880
|
+
// ../kit/src/ci.ts
|
|
881
|
+
init_style();
|
|
882
|
+
|
|
883
|
+
// ../kit/src/tool.ts
|
|
884
|
+
init_format();
|
|
770
885
|
// ../kit/src/cli.ts
|
|
886
|
+
init_args();
|
|
771
887
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
772
888
|
import { dirname as dirname3, join as join5 } from "path";
|
|
773
|
-
import
|
|
889
|
+
import process14 from "process";
|
|
774
890
|
|
|
775
|
-
// ../kit/src/
|
|
891
|
+
// ../kit/src/askpass.ts
|
|
776
892
|
import process11 from "process";
|
|
893
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
894
|
+
async function askpassClient(argv) {
|
|
895
|
+
const socketPath = process11.env[SOCKET_VARIABLE];
|
|
896
|
+
if (socketPath === undefined)
|
|
897
|
+
return;
|
|
898
|
+
const request = { prompt: argv[0] ?? "", ...process11.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
899
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
900
|
+
let received = "";
|
|
901
|
+
try {
|
|
902
|
+
await Bun.connect({
|
|
903
|
+
unix: socketPath,
|
|
904
|
+
socket: {
|
|
905
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
906
|
+
`),
|
|
907
|
+
data: (_, chunk) => {
|
|
908
|
+
received += chunk.toString();
|
|
909
|
+
},
|
|
910
|
+
close: () => resolve(received),
|
|
911
|
+
error: () => resolve("")
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
} catch {
|
|
915
|
+
return 1;
|
|
916
|
+
}
|
|
917
|
+
const reply = await promise;
|
|
918
|
+
if (reply === "")
|
|
919
|
+
return 1;
|
|
920
|
+
const { answer } = JSON.parse(reply);
|
|
921
|
+
if (request.notice === true)
|
|
922
|
+
return 0;
|
|
923
|
+
if (answer === undefined)
|
|
924
|
+
return 1;
|
|
925
|
+
process11.stdout.write(`${answer}
|
|
926
|
+
`);
|
|
927
|
+
return 0;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// ../kit/src/completions.ts
|
|
931
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
932
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
933
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
934
|
+
set -l current (commandline -ct)
|
|
935
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
936
|
+
if test "$line" = __files__
|
|
937
|
+
__fish_complete_path $current
|
|
938
|
+
else
|
|
939
|
+
echo $line
|
|
940
|
+
end
|
|
941
|
+
end
|
|
942
|
+
end`;
|
|
943
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
944
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
945
|
+
local -a lines
|
|
946
|
+
COMPREPLY=()
|
|
947
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
948
|
+
for line in "\${lines[@]}"; do
|
|
949
|
+
if [[ $line == __files__ ]]; then
|
|
950
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
951
|
+
else
|
|
952
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
953
|
+
fi
|
|
954
|
+
done
|
|
955
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
956
|
+
}`;
|
|
957
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
958
|
+
local line
|
|
959
|
+
local -a described plain
|
|
960
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
961
|
+
if [[ $line == __files__ ]]; then
|
|
962
|
+
_files
|
|
963
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
964
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
965
|
+
else
|
|
966
|
+
plain+=("$line")
|
|
967
|
+
fi
|
|
968
|
+
done
|
|
969
|
+
(( \${#described} )) && _describe -V value described
|
|
970
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
971
|
+
return 0
|
|
972
|
+
}`;
|
|
973
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
974
|
+
if (shell === "fish")
|
|
975
|
+
return `${header}
|
|
976
|
+
${FISH_FUNCTION}
|
|
977
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
978
|
+
`).join("")}`;
|
|
979
|
+
if (shell === "bash")
|
|
980
|
+
return `${header}
|
|
981
|
+
${BASH_FUNCTION}
|
|
982
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
983
|
+
`;
|
|
984
|
+
return `${header}
|
|
985
|
+
${ZSH_FUNCTION}
|
|
986
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
987
|
+
`;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// ../kit/src/notify.ts
|
|
991
|
+
init_format();
|
|
992
|
+
init_mode();
|
|
993
|
+
import process12 from "process";
|
|
777
994
|
var NOTIFY_AFTER_MS = 1e4;
|
|
778
995
|
var CANCELLED = 130;
|
|
779
996
|
function base64(text) {
|
|
780
997
|
return Buffer.from(text).toString("base64");
|
|
781
998
|
}
|
|
782
|
-
function notification(title, body, env =
|
|
783
|
-
const id = `kit${
|
|
999
|
+
function notification(title, body, env = process12.env) {
|
|
1000
|
+
const id = `kit${process12.pid}`;
|
|
784
1001
|
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\\`];
|
|
785
1002
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
786
1003
|
}
|
|
787
|
-
function notifyEnd(command, code, ms, { stream =
|
|
1004
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
788
1005
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
789
1006
|
return;
|
|
790
1007
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
791
1008
|
}
|
|
792
1009
|
|
|
1010
|
+
// ../kit/src/cli.ts
|
|
1011
|
+
init_style();
|
|
1012
|
+
init_text2();
|
|
1013
|
+
|
|
793
1014
|
// ../kit/src/usage.ts
|
|
794
1015
|
import { appendFileSync, mkdirSync } from "fs";
|
|
795
1016
|
import { homedir as homedir3 } from "os";
|
|
796
1017
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
797
|
-
import
|
|
1018
|
+
import process13 from "process";
|
|
798
1019
|
|
|
799
1020
|
// ../kit/src/logs.ts
|
|
800
1021
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -808,14 +1029,14 @@ var usageError;
|
|
|
808
1029
|
function noteUsageError(message) {
|
|
809
1030
|
usageError = message;
|
|
810
1031
|
}
|
|
811
|
-
function stateHome(env =
|
|
1032
|
+
function stateHome(env = process13.env) {
|
|
812
1033
|
const dir = env.XDG_STATE_HOME;
|
|
813
1034
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
814
1035
|
}
|
|
815
|
-
function usagePath(env =
|
|
1036
|
+
function usagePath(env = process13.env) {
|
|
816
1037
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
817
1038
|
}
|
|
818
|
-
function usageRecorded(env =
|
|
1039
|
+
function usageRecorded(env = process13.env) {
|
|
819
1040
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
820
1041
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
821
1042
|
}
|
|
@@ -824,12 +1045,12 @@ function flagNames(argv) {
|
|
|
824
1045
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
825
1046
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
826
1047
|
}
|
|
827
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1048
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
828
1049
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
829
1050
|
usageError = undefined;
|
|
830
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1051
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
831
1052
|
}
|
|
832
|
-
function recordUsage(entry, env =
|
|
1053
|
+
function recordUsage(entry, env = process13.env) {
|
|
833
1054
|
if (!usageRecorded(env))
|
|
834
1055
|
return;
|
|
835
1056
|
try {
|
|
@@ -845,10 +1066,14 @@ var LEVEL_OPTIONS = {
|
|
|
845
1066
|
...OUTPUT_OPTIONS,
|
|
846
1067
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
847
1068
|
};
|
|
848
|
-
var TOP_OPTIONS = {
|
|
1069
|
+
var TOP_OPTIONS = {
|
|
1070
|
+
...LEVEL_OPTIONS,
|
|
1071
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1072
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1073
|
+
};
|
|
849
1074
|
function printError(prefix, message, hint, cause) {
|
|
850
|
-
const colors = paint(
|
|
851
|
-
const styled = takesControlCodes(
|
|
1075
|
+
const colors = paint(process14.stderr);
|
|
1076
|
+
const styled = takesControlCodes(process14.stderr);
|
|
852
1077
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
853
1078
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
854
1079
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -925,6 +1150,19 @@ async function leafCandidates(run, words) {
|
|
|
925
1150
|
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
926
1151
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
927
1152
|
}
|
|
1153
|
+
var COMPLETIONS = "--completions";
|
|
1154
|
+
function flagValue([flag = "", ...rest]) {
|
|
1155
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1156
|
+
}
|
|
1157
|
+
function printCompletionScript(name, args) {
|
|
1158
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1159
|
+
if (shell === undefined || args.length !== 1) {
|
|
1160
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1161
|
+
return 2;
|
|
1162
|
+
}
|
|
1163
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1164
|
+
return 0;
|
|
1165
|
+
}
|
|
928
1166
|
async function printCandidates(found) {
|
|
929
1167
|
for (const line of await found)
|
|
930
1168
|
console.log(line);
|
|
@@ -946,8 +1184,13 @@ function packageVersion(entry = Bun.main) {
|
|
|
946
1184
|
}
|
|
947
1185
|
}
|
|
948
1186
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1187
|
+
const answered = await askpassClient(argv);
|
|
1188
|
+
if (answered !== undefined)
|
|
1189
|
+
return answered;
|
|
949
1190
|
if (argv[0] === COMPLETE)
|
|
950
1191
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1192
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1193
|
+
return printCompletionScript(name, flagValue(argv));
|
|
951
1194
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
952
1195
|
console.log(version ?? packageVersion());
|
|
953
1196
|
return 0;
|
|
@@ -962,19 +1205,52 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
962
1205
|
notifyEnd(name, code, performance.now() - started);
|
|
963
1206
|
if (usage !== false) {
|
|
964
1207
|
try {
|
|
965
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1208
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
966
1209
|
} catch {}
|
|
967
1210
|
}
|
|
968
1211
|
return code;
|
|
969
1212
|
}
|
|
970
|
-
|
|
971
|
-
|
|
1213
|
+
|
|
1214
|
+
// ../kit/src/index.ts
|
|
1215
|
+
init_config();
|
|
1216
|
+
|
|
1217
|
+
// ../kit/src/excerpt.ts
|
|
1218
|
+
init_text2();
|
|
1219
|
+
|
|
1220
|
+
// ../kit/src/index.ts
|
|
1221
|
+
init_folders();
|
|
1222
|
+
init_format();
|
|
1223
|
+
|
|
1224
|
+
// ../kit/src/git.ts
|
|
1225
|
+
init_args();
|
|
1226
|
+
// ../kit/src/limit.ts
|
|
1227
|
+
init_args();
|
|
1228
|
+
|
|
1229
|
+
// ../kit/src/index.ts
|
|
1230
|
+
init_mode();
|
|
1231
|
+
|
|
1232
|
+
// ../kit/src/report.ts
|
|
1233
|
+
init_style();
|
|
1234
|
+
init_text2();
|
|
972
1235
|
// ../kit/src/secrets.ts
|
|
973
1236
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
974
1237
|
// ../kit/src/sessions.ts
|
|
975
1238
|
var {Glob } = globalThis.Bun;
|
|
976
1239
|
var SESSION_FILES = new Glob("*.json");
|
|
977
1240
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1241
|
+
|
|
1242
|
+
// ../kit/src/index.ts
|
|
1243
|
+
init_style();
|
|
1244
|
+
init_text2();
|
|
1245
|
+
init_theme();
|
|
1246
|
+
init_user_config();
|
|
1247
|
+
|
|
1248
|
+
// ../kit/src/watch.ts
|
|
1249
|
+
init_args();
|
|
1250
|
+
init_input();
|
|
1251
|
+
init_style();
|
|
1252
|
+
// ../kit/src/workspace-root.ts
|
|
1253
|
+
init_user_config();
|
|
978
1254
|
// src/analyze.ts
|
|
979
1255
|
var SOON_DAYS = 14;
|
|
980
1256
|
var MAX_HOPS = 10;
|
|
@@ -1481,14 +1757,10 @@ async function tlsInfo(host, port, { address, timeoutS = CONNECT_TIMEOUT } = {})
|
|
|
1481
1757
|
var LABEL_WIDTH = 13;
|
|
1482
1758
|
var USAGE = `probe [options] <url|domain>...: reports each site's negotiated HTTP version, redirect chain, timings, addresses, TLS and certificate, the headers worth knowing and what warrants a warning
|
|
1483
1759
|
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
Warns on a certificate with fewer than 14 days left or not trusted, and on an http:// twin that does not redirect to https (checked for a bare domain or an https URL on the default port).
|
|
1489
|
-
|
|
1490
|
-
--dns makes no HTTP request: it asks the system resolver, Cloudflare, Google, Quad9 and each nameserver of the host's zone for its A, AAAA and CNAME records with their TTL, and warns on a resolver answering otherwise than the zone's nameservers, a change not reached it yet.
|
|
1491
|
-
--cors <origin> sends the preflight a browser on that origin would send before a --method request carrying --cors-headers, and says whether the browser would go on, with each reason when it would not.`;
|
|
1760
|
+
A bare domain is tried over https first, then http, and redirects are followed hop by hop (at most ${MAX_HOPS}).
|
|
1761
|
+
Warns on a certificate with fewer than 14 days left or not trusted, and on an http:// twin that does not redirect to https.
|
|
1762
|
+
--dns makes no HTTP request and compares the records the system resolver, public resolvers and the zone's nameservers give.
|
|
1763
|
+
--cors <origin> sends the preflight a browser on that origin would send and says whether it would go on, with each reason when not.`;
|
|
1492
1764
|
var EXITS = [[0, "every site answered, warnings or not"], [1, "a site could not be reached, a CORS preflight was refused, or no resolver knows a name"], [2, "a usage error"]];
|
|
1493
1765
|
var OPTIONS = {
|
|
1494
1766
|
insecure: { type: "boolean", short: "k", description: "let curl go on with a certificate it does not trust" },
|
|
@@ -1582,9 +1854,9 @@ function ms2(value) {
|
|
|
1582
1854
|
return `${value}ms`;
|
|
1583
1855
|
}
|
|
1584
1856
|
function compact(report) {
|
|
1585
|
-
const { dim } = paint(
|
|
1857
|
+
const { dim } = paint(process16.stdout);
|
|
1586
1858
|
const redirects = report.chain.length - 1;
|
|
1587
|
-
const parts = [`${role("accent",
|
|
1859
|
+
const parts = [`${role("accent", process16.stdout)(versionLabel(report.version))} ${role("value", process16.stdout)(String(report.status))} ${role("path", process16.stdout)(report.url)}`, ms2(report.timings.total)];
|
|
1588
1860
|
const address = report.addresses.a[0] ?? report.addresses.aaaa[0];
|
|
1589
1861
|
if (redirects > 0)
|
|
1590
1862
|
parts.push(`${redirects} ${redirects === 1 ? "redirect" : "redirects"}`);
|
|
@@ -1593,14 +1865,14 @@ function compact(report) {
|
|
|
1593
1865
|
if (address !== undefined)
|
|
1594
1866
|
parts.push(address);
|
|
1595
1867
|
const line = parts.join(dim(" "));
|
|
1596
|
-
return report.warnings.length === 0 ? line : `${line} ${marked("warn", report.warnings.join("; "),
|
|
1868
|
+
return report.warnings.length === 0 ? line : `${line} ${marked("warn", report.warnings.join("; "), process16.stdout)}`;
|
|
1597
1869
|
}
|
|
1598
1870
|
function print(report) {
|
|
1599
|
-
const label = role("label",
|
|
1600
|
-
const value = role("value",
|
|
1601
|
-
const accent = role("accent",
|
|
1871
|
+
const label = role("label", process16.stdout);
|
|
1872
|
+
const value = role("value", process16.stdout);
|
|
1873
|
+
const accent = role("accent", process16.stdout);
|
|
1602
1874
|
const row = (name, text) => console.log(`${label(name.padEnd(LABEL_WIDTH))} ${text}`);
|
|
1603
|
-
console.log(`${accent(versionLabel(report.version))} ${value(String(report.status))} ${role("path",
|
|
1875
|
+
console.log(`${accent(versionLabel(report.version))} ${value(String(report.status))} ${role("path", process16.stdout)(report.url)}`);
|
|
1604
1876
|
console.log("");
|
|
1605
1877
|
if (report.chain.length > 1) {
|
|
1606
1878
|
console.log(table(report.chain.map((hop) => [String(hop.status), versionLabel(hop.version), ms2(hop.ms), hop.url]), { align: ["right", "left", "right", "left"] }));
|
|
@@ -1625,12 +1897,12 @@ function print(report) {
|
|
|
1625
1897
|
if (report.httpRedirect !== null)
|
|
1626
1898
|
row("http://", report.httpRedirect.toHttps ? `redirects to https (${report.httpRedirect.status})` : `answers ${report.httpRedirect.status}`);
|
|
1627
1899
|
for (const warning of report.warnings)
|
|
1628
|
-
console.log(marked("warn", warning,
|
|
1900
|
+
console.log(marked("warn", warning, process16.stdout));
|
|
1629
1901
|
}
|
|
1630
1902
|
function printDns(report) {
|
|
1631
|
-
const label = role("label",
|
|
1903
|
+
const label = role("label", process16.stdout);
|
|
1632
1904
|
const listed = (values) => values.length === 0 ? "-" : values.join(" ");
|
|
1633
|
-
console.log(`${role("path",
|
|
1905
|
+
console.log(`${role("path", process16.stdout)(report.target)} ${label(report.zone === null ? "no zone found" : `zone ${report.zone}`)}`);
|
|
1634
1906
|
console.log(table([
|
|
1635
1907
|
["RESOLVER", "SERVER", "A", "AAAA", "CNAME", "TTL"],
|
|
1636
1908
|
...report.answers.map((answer) => [
|
|
@@ -1641,9 +1913,9 @@ function printDns(report) {
|
|
|
1641
1913
|
])
|
|
1642
1914
|
], { header: true }));
|
|
1643
1915
|
if (report.agree)
|
|
1644
|
-
console.log(marked("ok", "every resolver gives the same answer",
|
|
1916
|
+
console.log(marked("ok", "every resolver gives the same answer", process16.stdout));
|
|
1645
1917
|
for (const warning of report.warnings)
|
|
1646
|
-
console.log(marked("warn", warning,
|
|
1918
|
+
console.log(marked("warn", warning, process16.stdout));
|
|
1647
1919
|
}
|
|
1648
1920
|
async function dnsMain(inputs, timeoutMs, json) {
|
|
1649
1921
|
const hosts = inputs.map((input) => {
|
|
@@ -1668,16 +1940,16 @@ async function dnsMain(inputs, timeoutMs, json) {
|
|
|
1668
1940
|
return reports.every(known) ? 0 : 1;
|
|
1669
1941
|
}
|
|
1670
1942
|
function printCors(report) {
|
|
1671
|
-
const label = role("label",
|
|
1943
|
+
const label = role("label", process16.stdout);
|
|
1672
1944
|
const { request } = report;
|
|
1673
1945
|
const asked = `from ${request.origin}, ${request.method}${request.headers.length === 0 ? "" : ` with ${request.headers.join(", ")}`}`;
|
|
1674
|
-
console.log(`${marked(report.allowed ? "ok" : "problem", report.allowed ? "allowed" : "refused",
|
|
1946
|
+
console.log(`${marked(report.allowed ? "ok" : "problem", report.allowed ? "allowed" : "refused", process16.stdout)} ${role("value", process16.stdout)(String(report.status))} ${role("path", process16.stdout)(report.url)} ${label(asked)}`);
|
|
1675
1947
|
for (const [name, value] of Object.entries(report.headers))
|
|
1676
1948
|
console.log(` ${label(name)} ${value}`);
|
|
1677
1949
|
for (const reason of report.reasons)
|
|
1678
|
-
console.log(marked("problem", reason,
|
|
1950
|
+
console.log(marked("problem", reason, process16.stdout));
|
|
1679
1951
|
for (const warning of report.warnings)
|
|
1680
|
-
console.log(marked("warn", warning,
|
|
1952
|
+
console.log(marked("warn", warning, process16.stdout));
|
|
1681
1953
|
}
|
|
1682
1954
|
async function corsMain(targets, request, { insecure, wire }, json) {
|
|
1683
1955
|
const reports = await Promise.all(targets.map(async ({ input, target }) => {
|
|
@@ -1694,7 +1966,7 @@ async function corsMain(targets, request, { insecure, wire }, json) {
|
|
|
1694
1966
|
} else {
|
|
1695
1967
|
for (const report of reports) {
|
|
1696
1968
|
if ("error" in report)
|
|
1697
|
-
console.error(marked("problem", report.error,
|
|
1969
|
+
console.error(marked("problem", report.error, process16.stderr));
|
|
1698
1970
|
else
|
|
1699
1971
|
printCors(report);
|
|
1700
1972
|
}
|
|
@@ -1742,12 +2014,12 @@ async function main(args) {
|
|
|
1742
2014
|
let first = true;
|
|
1743
2015
|
for (const report of reports) {
|
|
1744
2016
|
if ("error" in report) {
|
|
1745
|
-
console.error(marked("problem", report.error,
|
|
2017
|
+
console.error(marked("problem", report.error, process16.stderr));
|
|
1746
2018
|
} else if (values.verbose === true) {
|
|
1747
2019
|
if (!first)
|
|
1748
2020
|
console.log("");
|
|
1749
2021
|
if (reports.length > 1)
|
|
1750
|
-
console.log(role("label",
|
|
2022
|
+
console.log(role("label", process16.stdout)(report.target));
|
|
1751
2023
|
print(report);
|
|
1752
2024
|
} else {
|
|
1753
2025
|
console.log(compact(report));
|
|
@@ -1756,4 +2028,4 @@ async function main(args) {
|
|
|
1756
2028
|
}
|
|
1757
2029
|
return reports.some((report) => ("error" in report)) ? 1 : 0;
|
|
1758
2030
|
}
|
|
1759
|
-
|
|
2031
|
+
process16.exitCode = await runMain({ name: "probe", run: main });
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-probe",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.4",
|
|
5
5
|
"description": "probe: a site's HTTP version, redirect chain, timings, addresses, TLS certificate and notable headers in one call, with warnings.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://github.com/Kayno0o/cli/tree/main/packages/probe#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
11
|
+
"url": "git+https://github.com/Kayno0o/cli.git",
|
|
12
12
|
"directory": "packages/probe"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://
|
|
14
|
+
"bugs": "https://github.com/Kayno0o/cli/issues",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"cli",
|
|
17
17
|
"http",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"probe": "$npm_execpath src/probe.ts"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@kaynooo/cli-kit": "0.
|
|
38
|
+
"@kaynooo/cli-kit": "0.46.0"
|
|
39
39
|
}
|
|
40
40
|
}
|