@kaynooo/cli-probe 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/probe.js +365 -323
- package/package.json +2 -2
package/dist/probe.js
CHANGED
|
@@ -1,317 +1,351 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
1
|
+
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/probe.ts
|
|
5
5
|
import { isIP as isIP2 } from "net";
|
|
6
|
-
import
|
|
6
|
+
import process13 from "process";
|
|
7
7
|
// ../kit/src/args.ts
|
|
8
|
-
import
|
|
8
|
+
import process9 from "process";
|
|
9
9
|
import { parseArgs } from "util";
|
|
10
10
|
|
|
11
11
|
// ../kit/src/format.ts
|
|
12
|
-
import
|
|
12
|
+
import process7 from "process";
|
|
13
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
14
|
+
var N = new Map;
|
|
15
|
+
var Nt = /\s+\S*$/;
|
|
16
|
+
var Y = /\s/;
|
|
17
|
+
function ko(t, e, r = "...") {
|
|
18
|
+
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
|
+
if (t.length <= e)
|
|
20
|
+
return t;
|
|
21
|
+
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
22
|
+
if (o && !Y.test(t[c.length] ?? " "))
|
|
23
|
+
c = c.replace(Nt, "") || c;
|
|
24
|
+
if (o)
|
|
25
|
+
c = c.trimEnd();
|
|
26
|
+
return s ? (c + n).slice(0, l) : c + n;
|
|
27
|
+
}
|
|
28
|
+
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));
|
|
29
|
+
var z = new Map;
|
|
30
|
+
// ../kit/src/mode.ts
|
|
31
|
+
import process2 from "process";
|
|
32
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
33
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
34
|
+
function isSet(value) {
|
|
35
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
36
|
+
}
|
|
37
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
38
|
+
const chosen = env.KIT_MODE;
|
|
39
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
40
|
+
return chosen;
|
|
41
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
42
|
+
return "agent";
|
|
43
|
+
if (stream.isTTY === true)
|
|
44
|
+
return "terminal";
|
|
45
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
46
|
+
}
|
|
13
47
|
|
|
14
48
|
// ../kit/src/style.ts
|
|
15
|
-
import
|
|
49
|
+
import process6 from "process";
|
|
16
50
|
|
|
17
|
-
// ../../node_modules/.bun/@kaynooo+utils@
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
52
|
+
var G2 = /^[a-f0-9]+$/i;
|
|
53
|
+
function b(r) {
|
|
54
|
+
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
55
|
+
if (!G2.test(e))
|
|
21
56
|
return [0, 0, 0];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
66
|
-
let n = (a) => {
|
|
67
|
-
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
68
|
-
return Math.round(255 * o);
|
|
69
|
-
};
|
|
70
|
-
return [n(5), n(3), n(1)];
|
|
71
|
-
}
|
|
72
|
-
function f(s) {
|
|
73
|
-
let [r, t, n] = s;
|
|
74
|
-
r /= 255, t /= 255, n /= 255;
|
|
75
|
-
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
|
|
76
|
-
if (o !== 0) {
|
|
77
|
-
if (a === r)
|
|
78
|
-
y = (t - n) / o + (t < n ? 6 : 0);
|
|
79
|
-
else if (a === t)
|
|
80
|
-
y = (n - r) / o + 2;
|
|
81
|
-
else
|
|
82
|
-
y = (r - t) / o + 4;
|
|
83
|
-
y /= 6;
|
|
84
|
-
}
|
|
85
|
-
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
86
|
-
}
|
|
87
|
-
function O(s) {
|
|
88
|
-
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
89
|
-
if (a === 1)
|
|
90
|
-
return [0, 0, 0, 100];
|
|
91
|
-
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
92
|
-
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
93
|
-
}
|
|
94
|
-
function v(s, r, t, n) {
|
|
95
|
-
return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
|
|
96
|
-
}
|
|
97
|
-
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
98
|
-
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
99
|
-
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
100
|
-
function T(s) {
|
|
101
|
-
let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
|
|
102
|
-
return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
|
|
57
|
+
if (e.length === 3 || e.length === 4)
|
|
58
|
+
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
59
|
+
if (e.length !== 6 && e.length !== 8)
|
|
60
|
+
throw Error(`Invalid hex color length: ${e.length}`);
|
|
61
|
+
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
62
|
+
}
|
|
63
|
+
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") => {
|
|
64
|
+
let [l, n, c] = b(r);
|
|
65
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
66
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
67
|
+
var h = new Set(["", "1", "2", "3", "true"]);
|
|
68
|
+
function C(r, e = globalThis.process?.env ?? {}) {
|
|
69
|
+
if (e.FORCE_COLOR !== undefined)
|
|
70
|
+
return h.has(e.FORCE_COLOR);
|
|
71
|
+
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
72
|
+
return false;
|
|
73
|
+
return r?.isTTY === true;
|
|
74
|
+
}
|
|
75
|
+
function f2(r, e = []) {
|
|
76
|
+
let l = "", n = "";
|
|
77
|
+
for (let t = 0, i = e.length;t < i; t++)
|
|
78
|
+
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
79
|
+
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
80
|
+
return new Proxy(c, { get(t, i) {
|
|
81
|
+
let a = B2[i];
|
|
82
|
+
if (Array.isArray(a)) {
|
|
83
|
+
let s = g.get(i);
|
|
84
|
+
if (s === undefined)
|
|
85
|
+
s = f2(r, [...e, a]), g.set(i, s);
|
|
86
|
+
return s;
|
|
87
|
+
}
|
|
88
|
+
if (typeof a === "function")
|
|
89
|
+
return (...s) => {
|
|
90
|
+
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
91
|
+
if (u === undefined) {
|
|
92
|
+
if (g.size >= 64)
|
|
93
|
+
g.clear();
|
|
94
|
+
u = f2(r, [...e, a(...s)]), g.set(y, u);
|
|
95
|
+
}
|
|
96
|
+
return u;
|
|
97
|
+
};
|
|
98
|
+
throw Error(`Unknown style: ${String(i)}`);
|
|
99
|
+
} });
|
|
103
100
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
return [u(o), u(y), u(c)];
|
|
101
|
+
function Fe2(r = {}) {
|
|
102
|
+
return f2(r);
|
|
107
103
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
var o2 = Fe2();
|
|
105
|
+
|
|
106
|
+
// ../kit/src/theme.ts
|
|
107
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
108
|
+
import { homedir as homedir2 } from "os";
|
|
109
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
110
|
+
import process5 from "process";
|
|
111
|
+
|
|
112
|
+
// ../kit/src/config.ts
|
|
113
|
+
import { existsSync } from "fs";
|
|
114
|
+
import { dirname, join, resolve } from "path";
|
|
115
|
+
import process3 from "process";
|
|
116
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
117
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
118
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
119
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
120
|
+
if (found !== undefined)
|
|
121
|
+
return found;
|
|
122
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
111
125
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
|
|
127
|
+
// ../kit/src/user-config.ts
|
|
128
|
+
import { homedir } from "os";
|
|
129
|
+
import { join as join2 } from "path";
|
|
130
|
+
import process4 from "process";
|
|
131
|
+
function configBase(where = {}) {
|
|
132
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
133
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
115
134
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
135
|
+
function userConfigPath(bin, where = {}) {
|
|
136
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
119
137
|
}
|
|
120
138
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
139
|
+
// ../kit/src/theme.ts
|
|
140
|
+
var ENDS = new Map;
|
|
141
|
+
var DEFAULT = {
|
|
142
|
+
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" },
|
|
143
|
+
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" },
|
|
144
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
145
|
+
bins: {},
|
|
146
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
147
|
+
};
|
|
148
|
+
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" };
|
|
149
|
+
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" };
|
|
150
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
151
|
+
var PRESETS = {
|
|
152
|
+
default: {},
|
|
153
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
154
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
155
|
+
ascii: { glyphs: ASCII }
|
|
156
|
+
};
|
|
157
|
+
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"]);
|
|
158
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
159
|
+
var CONTROL = /\p{Cc}/u;
|
|
160
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
161
|
+
var SPACES = /\s+/;
|
|
162
|
+
function isColorSpec(spec) {
|
|
163
|
+
if (typeof spec === "number")
|
|
164
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
165
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
166
|
+
}
|
|
167
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
168
|
+
function cubeLevel(channel) {
|
|
169
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
170
|
+
}
|
|
171
|
+
function nearest256(hex) {
|
|
172
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
173
|
+
const levels = rgb.map(cubeLevel);
|
|
174
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
175
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
176
|
+
const greyValue = 8 + grey * 10;
|
|
177
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
178
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
179
|
+
}
|
|
180
|
+
function hasTrueColor(env) {
|
|
181
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
182
|
+
}
|
|
183
|
+
function tinted(colors, spec, env = process5.env) {
|
|
184
|
+
if (typeof spec === "number")
|
|
185
|
+
return colors.ansi256(spec);
|
|
186
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
187
|
+
if (HEX.test(token))
|
|
188
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
189
|
+
return chain[token] ?? chain;
|
|
190
|
+
}, colors);
|
|
191
|
+
}
|
|
192
|
+
function isRecord(value) {
|
|
193
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
194
|
+
}
|
|
195
|
+
function readThemeFile(path, warn) {
|
|
196
|
+
try {
|
|
197
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
198
|
+
if (stat === undefined)
|
|
199
|
+
return;
|
|
200
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
201
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
202
|
+
return;
|
|
168
203
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
204
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
205
|
+
if (isRecord(parsed))
|
|
206
|
+
return parsed;
|
|
207
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
210
|
+
}
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
function applyPreset(theme, name, warn, where) {
|
|
214
|
+
if (name === undefined)
|
|
215
|
+
return;
|
|
216
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
217
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const preset = PRESETS[name];
|
|
221
|
+
Object.assign(theme.colors, preset.colors);
|
|
222
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
223
|
+
if (preset.accents !== undefined)
|
|
224
|
+
theme.accents = [...preset.accents];
|
|
225
|
+
if (Object.hasOwn(preset, "gradient"))
|
|
226
|
+
theme.gradient = preset.gradient;
|
|
227
|
+
return name;
|
|
228
|
+
}
|
|
229
|
+
function applyFile(theme, file, where, warn) {
|
|
230
|
+
if (isRecord(file.colors)) {
|
|
231
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
232
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
233
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
234
|
+
else if (!isColorSpec(value))
|
|
235
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
173
236
|
else
|
|
174
|
-
|
|
175
|
-
let [o, y, c] = C(t, n, a);
|
|
176
|
-
return new e(o, y, c, b);
|
|
237
|
+
theme.colors[key] = value;
|
|
177
238
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
239
|
+
}
|
|
240
|
+
if (isRecord(file.glyphs)) {
|
|
241
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
242
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
243
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
244
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
245
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
182
246
|
else
|
|
183
|
-
|
|
184
|
-
let [o, y, c] = M(t, n, a);
|
|
185
|
-
return new e(o, y, c, b);
|
|
247
|
+
theme.glyphs[key] = value;
|
|
186
248
|
}
|
|
187
|
-
throw Error("Invalid input");
|
|
188
249
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
case "hsva":
|
|
206
|
-
return [...f([this.r, this.g, this.b]), this.a];
|
|
207
|
-
case "cmyk":
|
|
208
|
-
return O([this.r, this.g, this.b]);
|
|
209
|
-
case "cmyka":
|
|
210
|
-
return [...O([this.r, this.g, this.b]), this.a];
|
|
211
|
-
case "oklch":
|
|
212
|
-
return d([this.r, this.g, this.b]);
|
|
213
|
-
case "oklcha":
|
|
214
|
-
return [...d([this.r, this.g, this.b]), this.a];
|
|
215
|
-
case "oklab":
|
|
216
|
-
return T([this.r, this.g, this.b]);
|
|
217
|
-
case "oklaba":
|
|
218
|
-
return [...T([this.r, this.g, this.b]), this.a];
|
|
219
|
-
default:
|
|
220
|
-
return [this.r, this.g, this.b];
|
|
250
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
251
|
+
theme.accents = [...file.accents];
|
|
252
|
+
else if (file.accents !== undefined)
|
|
253
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
254
|
+
if (file.gradient === null)
|
|
255
|
+
theme.gradient = undefined;
|
|
256
|
+
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
257
|
+
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
258
|
+
else if (file.gradient !== undefined)
|
|
259
|
+
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
260
|
+
if (isRecord(file.bins)) {
|
|
261
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
262
|
+
if (isColorSpec(value))
|
|
263
|
+
theme.bins[bin] = value;
|
|
264
|
+
else
|
|
265
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
221
266
|
}
|
|
222
267
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
268
|
+
}
|
|
269
|
+
function endsWalk(home) {
|
|
270
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
271
|
+
}
|
|
272
|
+
var warned = new Set;
|
|
273
|
+
function warnOnce(message) {
|
|
274
|
+
if (warned.has(message))
|
|
275
|
+
return;
|
|
276
|
+
warned.add(message);
|
|
277
|
+
console.error(`warning: theme ${message}`);
|
|
278
|
+
}
|
|
279
|
+
function isPath(chosen) {
|
|
280
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
281
|
+
}
|
|
282
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
283
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
284
|
+
const sources = [];
|
|
285
|
+
const chosen = env.KIT_THEME ?? "";
|
|
286
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
287
|
+
if (isPath(chosen))
|
|
288
|
+
wanted.push(resolve2(from, chosen));
|
|
289
|
+
const files = [];
|
|
290
|
+
for (const path of wanted) {
|
|
291
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
292
|
+
if (path !== undefined && file !== undefined)
|
|
293
|
+
files.push({ path, file });
|
|
226
294
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
295
|
+
let preset = "default";
|
|
296
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
297
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
298
|
+
} else {
|
|
299
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
300
|
+
if (named !== undefined)
|
|
301
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
230
302
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
303
|
+
for (const { path, file } of files) {
|
|
304
|
+
applyFile(theme, file, path, warn);
|
|
305
|
+
sources.push(path);
|
|
234
306
|
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
var
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
245
|
-
var b = new Set(["", "1", "2", "3", "true"]);
|
|
246
|
-
function h(i, n = globalThis.process?.env ?? {}) {
|
|
247
|
-
if (n.FORCE_COLOR !== undefined)
|
|
248
|
-
return b.has(n.FORCE_COLOR);
|
|
249
|
-
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
250
|
-
return false;
|
|
251
|
-
return i?.isTTY === true;
|
|
252
|
-
}
|
|
253
|
-
function d2(i, n, a) {
|
|
254
|
-
if (!h(a.stream ?? globalThis.process?.stdout, a.env))
|
|
255
|
-
return n;
|
|
256
|
-
let l = "", s = "";
|
|
257
|
-
for (let g = 0, y = i.length;g < y; g++) {
|
|
258
|
-
let [c, p] = i[g];
|
|
259
|
-
l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
|
|
307
|
+
return { theme, sources, preset };
|
|
308
|
+
}
|
|
309
|
+
var current;
|
|
310
|
+
var currentKey = "";
|
|
311
|
+
function activeTheme() {
|
|
312
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
313
|
+
if (current === undefined || key !== currentKey) {
|
|
314
|
+
current = loadTheme();
|
|
315
|
+
currentKey = key;
|
|
260
316
|
}
|
|
261
|
-
return
|
|
262
|
-
}
|
|
263
|
-
function u(i, n = []) {
|
|
264
|
-
return new Proxy((l) => d2(n, l, i), { get(l, s) {
|
|
265
|
-
let g = C2[s];
|
|
266
|
-
if (Array.isArray(g))
|
|
267
|
-
return u(i, [...n, g]);
|
|
268
|
-
if (typeof g === "function")
|
|
269
|
-
return (...y) => u(i, [...n, g(...y)]);
|
|
270
|
-
throw Error(`Unknown style: ${String(s)}`);
|
|
271
|
-
} });
|
|
317
|
+
return current;
|
|
272
318
|
}
|
|
273
|
-
function le(i = {}) {
|
|
274
|
-
return u(i);
|
|
275
|
-
}
|
|
276
|
-
var t = le();
|
|
277
319
|
|
|
278
320
|
// ../kit/src/style.ts
|
|
279
|
-
var
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
283
|
-
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
284
|
-
};
|
|
285
|
-
function takesControlCodes(stream, env = process2.env) {
|
|
286
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
321
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
322
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
323
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
287
324
|
}
|
|
288
|
-
function paint(stream, env =
|
|
289
|
-
return
|
|
325
|
+
function paint(stream, env = process6.env) {
|
|
326
|
+
return Fe2({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
290
327
|
}
|
|
291
|
-
function marked(mark, text, stream, detail, env =
|
|
328
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
292
329
|
const colors = paint(stream, env);
|
|
293
|
-
|
|
294
|
-
|
|
330
|
+
let head = MARK_WORDS[mark];
|
|
331
|
+
if (takesControlCodes(stream, env)) {
|
|
332
|
+
const { theme } = activeTheme();
|
|
333
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
334
|
+
}
|
|
295
335
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
296
336
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
var STATUSES = {
|
|
308
|
-
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
309
|
-
failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
|
|
310
|
-
running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
|
|
311
|
-
queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
|
|
312
|
-
skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
|
|
337
|
+
function role(name, stream, env = process6.env) {
|
|
338
|
+
const colors = paint(stream, env);
|
|
339
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
340
|
+
}
|
|
341
|
+
var STATUS_WORDS = {
|
|
342
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
343
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
344
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
345
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
346
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
313
347
|
};
|
|
314
|
-
var STATUS_OF = new Map(Object.entries(
|
|
348
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
315
349
|
|
|
316
350
|
// ../kit/src/format.ts
|
|
317
351
|
function upTo(text, separator) {
|
|
@@ -319,22 +353,25 @@ function upTo(text, separator) {
|
|
|
319
353
|
return end === -1 ? text : text.slice(0, end);
|
|
320
354
|
}
|
|
321
355
|
function truncate(text, width) {
|
|
322
|
-
return text
|
|
356
|
+
return ko(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
323
357
|
}
|
|
324
358
|
var LINE_BREAKS = /\s*\n\s*/g;
|
|
325
359
|
var ESCAPE = String.fromCharCode(27);
|
|
326
360
|
function textWidth(text) {
|
|
327
361
|
return Bun.stringWidth(text);
|
|
328
362
|
}
|
|
329
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
363
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
330
364
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
365
|
+
if (outputMode(stream, env) === "agent")
|
|
366
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
367
|
+
`);
|
|
331
368
|
const widths = [];
|
|
332
369
|
for (const row of cells) {
|
|
333
370
|
for (const [index, cell] of row.entries())
|
|
334
371
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
335
372
|
}
|
|
336
373
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
337
|
-
const colors = paint(
|
|
374
|
+
const colors = paint(stream);
|
|
338
375
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
339
376
|
const width = widths[index] ?? 0;
|
|
340
377
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -342,7 +379,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
342
379
|
return `${gap}${cell}`;
|
|
343
380
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
344
381
|
}).join(" ").trimEnd());
|
|
345
|
-
|
|
382
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
383
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
346
384
|
`);
|
|
347
385
|
}
|
|
348
386
|
function narrow(rows, widths, limit) {
|
|
@@ -361,32 +399,35 @@ function narrow(rows, widths, limit) {
|
|
|
361
399
|
}
|
|
362
400
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
363
401
|
}
|
|
402
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
403
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
404
|
+
}
|
|
364
405
|
function printJson(value) {
|
|
365
|
-
console.log(
|
|
406
|
+
console.log(jsonText(value));
|
|
366
407
|
}
|
|
367
408
|
|
|
368
409
|
// ../kit/src/help.ts
|
|
369
|
-
import
|
|
410
|
+
import process8 from "process";
|
|
370
411
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
371
412
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
372
413
|
var FULL_STOP = /\.$/;
|
|
373
|
-
function usageLine(usage, colors = paint(
|
|
414
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
374
415
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
375
416
|
}
|
|
376
|
-
function helpText(usage, options, colors = paint(
|
|
417
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
377
418
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
378
419
|
`);
|
|
379
420
|
}
|
|
380
|
-
function exitRows(exits, colors = paint(
|
|
421
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
381
422
|
if (exits.length === 0)
|
|
382
423
|
return [];
|
|
383
424
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
384
425
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
385
426
|
}
|
|
386
|
-
function replacesRows(replaces, colors = paint(
|
|
387
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
427
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
428
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
388
429
|
}
|
|
389
|
-
function wantsHelpJson(env =
|
|
430
|
+
function wantsHelpJson(env = process8.env) {
|
|
390
431
|
return env.KIT_HELP === "json";
|
|
391
432
|
}
|
|
392
433
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -405,12 +446,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
405
446
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
406
447
|
};
|
|
407
448
|
}
|
|
408
|
-
function exampleRows(examples, colors = paint(
|
|
409
|
-
if (examples.length === 0)
|
|
449
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
450
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
410
451
|
return [];
|
|
411
452
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
412
453
|
}
|
|
413
|
-
function optionRows(options, colors = paint(
|
|
454
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
414
455
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
415
456
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
416
457
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -459,7 +500,6 @@ var DASHES = /^-+/;
|
|
|
459
500
|
function jsonOption(holds) {
|
|
460
501
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
461
502
|
}
|
|
462
|
-
|
|
463
503
|
class Exit extends Error {
|
|
464
504
|
code;
|
|
465
505
|
hint;
|
|
@@ -503,7 +543,7 @@ var OUTPUT_OPTIONS = {
|
|
|
503
543
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
504
544
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
505
545
|
};
|
|
506
|
-
function applyOutput(color, plain, env =
|
|
546
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
507
547
|
const when = plain === true ? "never" : color ?? "auto";
|
|
508
548
|
if (when === "auto")
|
|
509
549
|
return;
|
|
@@ -678,15 +718,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
678
718
|
var RESET_STYLE = `${ESC}[0m`;
|
|
679
719
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
680
720
|
// ../kit/src/cli.ts
|
|
681
|
-
import { readFileSync, realpathSync } from "fs";
|
|
682
|
-
import { dirname as
|
|
683
|
-
import
|
|
721
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
722
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
723
|
+
import process11 from "process";
|
|
684
724
|
|
|
685
725
|
// ../kit/src/usage.ts
|
|
686
726
|
import { appendFileSync, mkdirSync } from "fs";
|
|
687
|
-
import { homedir } from "os";
|
|
688
|
-
import { dirname, isAbsolute, join } from "path";
|
|
689
|
-
import
|
|
727
|
+
import { homedir as homedir3 } from "os";
|
|
728
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
729
|
+
import process10 from "process";
|
|
690
730
|
|
|
691
731
|
// ../kit/src/logs.ts
|
|
692
732
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -700,14 +740,14 @@ var usageError;
|
|
|
700
740
|
function noteUsageError(message) {
|
|
701
741
|
usageError = message;
|
|
702
742
|
}
|
|
703
|
-
function stateHome(env =
|
|
743
|
+
function stateHome(env = process10.env) {
|
|
704
744
|
const dir = env.XDG_STATE_HOME;
|
|
705
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
745
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
706
746
|
}
|
|
707
|
-
function usagePath(env =
|
|
708
|
-
return
|
|
747
|
+
function usagePath(env = process10.env) {
|
|
748
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
709
749
|
}
|
|
710
|
-
function usageRecorded(env =
|
|
750
|
+
function usageRecorded(env = process10.env) {
|
|
711
751
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
712
752
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
713
753
|
}
|
|
@@ -721,12 +761,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
721
761
|
usageError = undefined;
|
|
722
762
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
723
763
|
}
|
|
724
|
-
function recordUsage(entry, env =
|
|
764
|
+
function recordUsage(entry, env = process10.env) {
|
|
725
765
|
if (!usageRecorded(env))
|
|
726
766
|
return;
|
|
727
767
|
try {
|
|
728
768
|
const path = usagePath(env);
|
|
729
|
-
mkdirSync(
|
|
769
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
730
770
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
731
771
|
`, { mode: 384 });
|
|
732
772
|
} catch {}
|
|
@@ -739,8 +779,8 @@ var LEVEL_OPTIONS = {
|
|
|
739
779
|
};
|
|
740
780
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
741
781
|
function printError(prefix, message, hint, cause) {
|
|
742
|
-
const colors = paint(
|
|
743
|
-
const styled = takesControlCodes(
|
|
782
|
+
const colors = paint(process11.stderr);
|
|
783
|
+
const styled = takesControlCodes(process11.stderr);
|
|
744
784
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
745
785
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
746
786
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -759,7 +799,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
759
799
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
760
800
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
761
801
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
762
|
-
if (error instanceof
|
|
802
|
+
if (error instanceof Exit && error.code === 2)
|
|
763
803
|
noteUsageError(error.message);
|
|
764
804
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
765
805
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
@@ -823,17 +863,17 @@ async function printCandidates(found) {
|
|
|
823
863
|
return 0;
|
|
824
864
|
}
|
|
825
865
|
function packageVersion(entry = Bun.main) {
|
|
826
|
-
for (let dir =
|
|
866
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
827
867
|
try {
|
|
828
|
-
const { version } = JSON.parse(
|
|
868
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
829
869
|
if (typeof version === "string")
|
|
830
870
|
return version;
|
|
831
871
|
} catch {}
|
|
832
|
-
if (
|
|
872
|
+
if (dirname3(dir) === dir)
|
|
833
873
|
return "0.0.0";
|
|
834
874
|
}
|
|
835
875
|
}
|
|
836
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
876
|
+
async function runMain({ name, version, run, redact, usage }, argv = process11.argv.slice(2)) {
|
|
837
877
|
if (argv[0] === COMPLETE)
|
|
838
878
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
839
879
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -853,6 +893,8 @@ async function runMain({ name, version, run, redact, usage }, argv = process7.ar
|
|
|
853
893
|
}
|
|
854
894
|
return code;
|
|
855
895
|
}
|
|
896
|
+
// ../kit/src/folders.ts
|
|
897
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
856
898
|
// ../kit/src/secrets.ts
|
|
857
899
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
858
900
|
// ../kit/src/sessions.ts
|
|
@@ -1274,9 +1316,9 @@ function ms2(value) {
|
|
|
1274
1316
|
return `${value}ms`;
|
|
1275
1317
|
}
|
|
1276
1318
|
function compact(report) {
|
|
1277
|
-
const { dim } = paint(
|
|
1319
|
+
const { dim } = paint(process13.stdout);
|
|
1278
1320
|
const redirects = report.chain.length - 1;
|
|
1279
|
-
const parts = [`${role("accent",
|
|
1321
|
+
const parts = [`${role("accent", process13.stdout)(versionLabel(report.version))} ${role("value", process13.stdout)(String(report.status))} ${role("path", process13.stdout)(report.url)}`, ms2(report.timings.total)];
|
|
1280
1322
|
const address = report.addresses.a[0] ?? report.addresses.aaaa[0];
|
|
1281
1323
|
if (redirects > 0)
|
|
1282
1324
|
parts.push(`${redirects} ${redirects === 1 ? "redirect" : "redirects"}`);
|
|
@@ -1285,14 +1327,14 @@ function compact(report) {
|
|
|
1285
1327
|
if (address !== undefined)
|
|
1286
1328
|
parts.push(address);
|
|
1287
1329
|
const line = parts.join(dim(" "));
|
|
1288
|
-
return report.warnings.length === 0 ? line : `${line} ${marked("warn", report.warnings.join("; "),
|
|
1330
|
+
return report.warnings.length === 0 ? line : `${line} ${marked("warn", report.warnings.join("; "), process13.stdout)}`;
|
|
1289
1331
|
}
|
|
1290
1332
|
function print(report) {
|
|
1291
|
-
const label = role("label",
|
|
1292
|
-
const value = role("value",
|
|
1293
|
-
const accent = role("accent",
|
|
1333
|
+
const label = role("label", process13.stdout);
|
|
1334
|
+
const value = role("value", process13.stdout);
|
|
1335
|
+
const accent = role("accent", process13.stdout);
|
|
1294
1336
|
const row = (name, text) => console.log(`${label(name.padEnd(LABEL_WIDTH))} ${text}`);
|
|
1295
|
-
console.log(`${accent(versionLabel(report.version))} ${value(String(report.status))} ${role("path",
|
|
1337
|
+
console.log(`${accent(versionLabel(report.version))} ${value(String(report.status))} ${role("path", process13.stdout)(report.url)}`);
|
|
1296
1338
|
console.log("");
|
|
1297
1339
|
if (report.chain.length > 1) {
|
|
1298
1340
|
console.log(table(report.chain.map((hop) => [String(hop.status), versionLabel(hop.version), ms2(hop.ms), hop.url]), { align: ["right", "left", "right", "left"] }));
|
|
@@ -1317,7 +1359,7 @@ function print(report) {
|
|
|
1317
1359
|
if (report.httpRedirect !== null)
|
|
1318
1360
|
row("http://", report.httpRedirect.toHttps ? `redirects to https (${report.httpRedirect.status})` : `answers ${report.httpRedirect.status}`);
|
|
1319
1361
|
for (const warning of report.warnings)
|
|
1320
|
-
console.log(marked("warn", warning,
|
|
1362
|
+
console.log(marked("warn", warning, process13.stdout));
|
|
1321
1363
|
}
|
|
1322
1364
|
async function main(args) {
|
|
1323
1365
|
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["<url|domain>..."], exits: EXITS, replaces: "the httpversion fish function, curl -sI chains and openssl s_client one-liners", examples: ["probe example.com", "probe https://example.com/path --json", ["probe a.test b.test", "one line each"], ['probe https://example.com --resolve example.com:203.0.113.7 -H "Host: example.com" --verbose', "a server before its DNS points at it"]] });
|
|
@@ -1345,12 +1387,12 @@ async function main(args) {
|
|
|
1345
1387
|
let first = true;
|
|
1346
1388
|
for (const report of reports) {
|
|
1347
1389
|
if ("error" in report) {
|
|
1348
|
-
console.error(marked("problem", report.error,
|
|
1390
|
+
console.error(marked("problem", report.error, process13.stderr));
|
|
1349
1391
|
} else if (values.verbose === true) {
|
|
1350
1392
|
if (!first)
|
|
1351
1393
|
console.log("");
|
|
1352
1394
|
if (reports.length > 1)
|
|
1353
|
-
console.log(role("label",
|
|
1395
|
+
console.log(role("label", process13.stdout)(report.target));
|
|
1354
1396
|
print(report);
|
|
1355
1397
|
} else {
|
|
1356
1398
|
console.log(compact(report));
|
|
@@ -1359,4 +1401,4 @@ async function main(args) {
|
|
|
1359
1401
|
}
|
|
1360
1402
|
return reports.some((report) => ("error" in report)) ? 1 : 0;
|
|
1361
1403
|
}
|
|
1362
|
-
|
|
1404
|
+
process13.exitCode = await runMain({ name: "probe", run: main });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-probe",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -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.36.0"
|
|
39
39
|
}
|
|
40
40
|
}
|