@kaynooo/cli-probe 0.2.1 → 0.4.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/README.md +17 -2
- package/dist/probe.js +688 -339
- package/package.json +2 -2
package/dist/probe.js
CHANGED
|
@@ -1,317 +1,353 @@
|
|
|
1
|
-
#!/usr/bin/env -S bun --no-env-file
|
|
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 process14 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
13
|
|
|
14
|
-
//
|
|
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 = "...") {
|
|
19
|
+
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
20
|
+
if (t.length <= e)
|
|
21
|
+
return t;
|
|
22
|
+
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
23
|
+
if (o && !Y.test(t[c.length] ?? " "))
|
|
24
|
+
c = c.replace(Nt, "") || c;
|
|
25
|
+
if (o)
|
|
26
|
+
c = c.trimEnd();
|
|
27
|
+
return s ? (c + n).slice(0, l) : c + n;
|
|
28
|
+
}
|
|
29
|
+
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));
|
|
30
|
+
var z = new Map;
|
|
31
|
+
|
|
32
|
+
// ../kit/src/mode.ts
|
|
15
33
|
import process2 from "process";
|
|
34
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
35
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
36
|
+
function isSet(value) {
|
|
37
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
38
|
+
}
|
|
39
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
40
|
+
const chosen = env.KIT_MODE;
|
|
41
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
42
|
+
return chosen;
|
|
43
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
44
|
+
return "agent";
|
|
45
|
+
if (stream.isTTY === true)
|
|
46
|
+
return "terminal";
|
|
47
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ../kit/src/style.ts
|
|
51
|
+
import process6 from "process";
|
|
16
52
|
|
|
17
|
-
// ../../node_modules/.bun/@kaynooo+utils@
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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;
|
|
55
|
+
function b(r) {
|
|
56
|
+
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
57
|
+
if (!G2.test(e))
|
|
21
58
|
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)];
|
|
59
|
+
if (e.length === 3 || e.length === 4)
|
|
60
|
+
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
61
|
+
if (e.length !== 6 && e.length !== 8)
|
|
62
|
+
throw Error(`Invalid hex color length: ${e.length}`);
|
|
63
|
+
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
64
|
+
}
|
|
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
|
+
function C(r, e = globalThis.process?.env ?? {}) {
|
|
71
|
+
if (e.FORCE_COLOR !== undefined)
|
|
72
|
+
return h.has(e.FORCE_COLOR);
|
|
73
|
+
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
74
|
+
return false;
|
|
75
|
+
return r?.isTTY === true;
|
|
76
|
+
}
|
|
77
|
+
function f(r, e = []) {
|
|
78
|
+
let l = "", n = "";
|
|
79
|
+
for (let t = 0, i = e.length;t < i; t++)
|
|
80
|
+
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
81
|
+
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
82
|
+
return new Proxy(c, { get(t, i) {
|
|
83
|
+
let a = B2[i];
|
|
84
|
+
if (Array.isArray(a)) {
|
|
85
|
+
let s = g.get(i);
|
|
86
|
+
if (s === undefined)
|
|
87
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
88
|
+
return s;
|
|
89
|
+
}
|
|
90
|
+
if (typeof a === "function")
|
|
91
|
+
return (...s) => {
|
|
92
|
+
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
93
|
+
if (u === undefined) {
|
|
94
|
+
if (g.size >= 64)
|
|
95
|
+
g.clear();
|
|
96
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
97
|
+
}
|
|
98
|
+
return u;
|
|
99
|
+
};
|
|
100
|
+
throw Error(`Unknown style: ${String(i)}`);
|
|
101
|
+
} });
|
|
103
102
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
return [u(o), u(y), u(c)];
|
|
103
|
+
function Fe(r = {}) {
|
|
104
|
+
return f(r);
|
|
107
105
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
var o = Fe();
|
|
107
|
+
|
|
108
|
+
// ../kit/src/theme.ts
|
|
109
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
110
|
+
import { homedir as homedir2 } from "os";
|
|
111
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
112
|
+
import process5 from "process";
|
|
113
|
+
|
|
114
|
+
// ../kit/src/config.ts
|
|
115
|
+
import { existsSync } from "fs";
|
|
116
|
+
import { dirname, join, resolve } from "path";
|
|
117
|
+
import process3 from "process";
|
|
118
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
119
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
120
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
121
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
122
|
+
if (found !== undefined)
|
|
123
|
+
return found;
|
|
124
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
111
127
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
128
|
+
|
|
129
|
+
// ../kit/src/user-config.ts
|
|
130
|
+
import { homedir } from "os";
|
|
131
|
+
import { join as join2 } from "path";
|
|
132
|
+
import process4 from "process";
|
|
133
|
+
function configBase(where = {}) {
|
|
134
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
135
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
115
136
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
137
|
+
function userConfigPath(bin, where = {}) {
|
|
138
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
119
139
|
}
|
|
120
140
|
|
|
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
|
-
|
|
141
|
+
// ../kit/src/theme.ts
|
|
142
|
+
var ENDS = new Map;
|
|
143
|
+
var DEFAULT = {
|
|
144
|
+
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" },
|
|
145
|
+
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" },
|
|
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+/;
|
|
164
|
+
function isColorSpec(spec) {
|
|
165
|
+
if (typeof spec === "number")
|
|
166
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
167
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
168
|
+
}
|
|
169
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
170
|
+
function cubeLevel(channel) {
|
|
171
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
172
|
+
}
|
|
173
|
+
function nearest256(hex) {
|
|
174
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
175
|
+
const levels = rgb.map(cubeLevel);
|
|
176
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
177
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
178
|
+
const greyValue = 8 + grey * 10;
|
|
179
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
180
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
181
|
+
}
|
|
182
|
+
function hasTrueColor(env) {
|
|
183
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
184
|
+
}
|
|
185
|
+
function tinted(colors, spec, env = process5.env) {
|
|
186
|
+
if (typeof spec === "number")
|
|
187
|
+
return colors.ansi256(spec);
|
|
188
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
189
|
+
if (HEX.test(token))
|
|
190
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
191
|
+
return chain[token] ?? chain;
|
|
192
|
+
}, colors);
|
|
193
|
+
}
|
|
194
|
+
function isRecord(value) {
|
|
195
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
196
|
+
}
|
|
197
|
+
function readThemeFile(path, warn) {
|
|
198
|
+
try {
|
|
199
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
200
|
+
if (stat === undefined)
|
|
201
|
+
return;
|
|
202
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
203
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
204
|
+
return;
|
|
168
205
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
206
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
207
|
+
if (isRecord(parsed))
|
|
208
|
+
return parsed;
|
|
209
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
212
|
+
}
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
function applyPreset(theme, name, warn, where) {
|
|
216
|
+
if (name === undefined)
|
|
217
|
+
return;
|
|
218
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
219
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const preset = PRESETS[name];
|
|
223
|
+
Object.assign(theme.colors, preset.colors);
|
|
224
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
225
|
+
if (preset.accents !== undefined)
|
|
226
|
+
theme.accents = [...preset.accents];
|
|
227
|
+
if (Object.hasOwn(preset, "gradient"))
|
|
228
|
+
theme.gradient = preset.gradient;
|
|
229
|
+
return name;
|
|
230
|
+
}
|
|
231
|
+
function applyFile(theme, file, where, warn) {
|
|
232
|
+
if (isRecord(file.colors)) {
|
|
233
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
234
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
235
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
236
|
+
else if (!isColorSpec(value))
|
|
237
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
173
238
|
else
|
|
174
|
-
|
|
175
|
-
let [o, y, c] = C(t, n, a);
|
|
176
|
-
return new e(o, y, c, b);
|
|
239
|
+
theme.colors[key] = value;
|
|
177
240
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
241
|
+
}
|
|
242
|
+
if (isRecord(file.glyphs)) {
|
|
243
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
244
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
245
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
246
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
247
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
182
248
|
else
|
|
183
|
-
|
|
184
|
-
let [o, y, c] = M(t, n, a);
|
|
185
|
-
return new e(o, y, c, b);
|
|
249
|
+
theme.glyphs[key] = value;
|
|
186
250
|
}
|
|
187
|
-
throw Error("Invalid input");
|
|
188
251
|
}
|
|
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];
|
|
252
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
253
|
+
theme.accents = [...file.accents];
|
|
254
|
+
else if (file.accents !== undefined)
|
|
255
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
256
|
+
if (file.gradient === null)
|
|
257
|
+
theme.gradient = undefined;
|
|
258
|
+
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
259
|
+
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
260
|
+
else if (file.gradient !== undefined)
|
|
261
|
+
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
262
|
+
if (isRecord(file.bins)) {
|
|
263
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
264
|
+
if (isColorSpec(value))
|
|
265
|
+
theme.bins[bin] = value;
|
|
266
|
+
else
|
|
267
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
221
268
|
}
|
|
222
269
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
270
|
+
}
|
|
271
|
+
function endsWalk(home) {
|
|
272
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
273
|
+
}
|
|
274
|
+
var warned = new Set;
|
|
275
|
+
function warnOnce(message) {
|
|
276
|
+
if (warned.has(message))
|
|
277
|
+
return;
|
|
278
|
+
warned.add(message);
|
|
279
|
+
console.error(`warning: theme ${message}`);
|
|
280
|
+
}
|
|
281
|
+
function isPath(chosen) {
|
|
282
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
283
|
+
}
|
|
284
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
285
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
286
|
+
const sources = [];
|
|
287
|
+
const chosen = env.KIT_THEME ?? "";
|
|
288
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
289
|
+
if (isPath(chosen))
|
|
290
|
+
wanted.push(resolve2(from, chosen));
|
|
291
|
+
const files = [];
|
|
292
|
+
for (const path of wanted) {
|
|
293
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
294
|
+
if (path !== undefined && file !== undefined)
|
|
295
|
+
files.push({ path, file });
|
|
226
296
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
297
|
+
let preset = "default";
|
|
298
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
299
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
300
|
+
} else {
|
|
301
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
302
|
+
if (named !== undefined)
|
|
303
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
230
304
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
305
|
+
for (const { path, file } of files) {
|
|
306
|
+
applyFile(theme, file, path, warn);
|
|
307
|
+
sources.push(path);
|
|
234
308
|
}
|
|
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}`;
|
|
309
|
+
return { theme, sources, preset };
|
|
310
|
+
}
|
|
311
|
+
var current;
|
|
312
|
+
var currentKey = "";
|
|
313
|
+
function activeTheme() {
|
|
314
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
315
|
+
if (current === undefined || key !== currentKey) {
|
|
316
|
+
current = loadTheme();
|
|
317
|
+
currentKey = key;
|
|
260
318
|
}
|
|
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
|
-
} });
|
|
272
|
-
}
|
|
273
|
-
function le(i = {}) {
|
|
274
|
-
return u(i);
|
|
319
|
+
return current;
|
|
275
320
|
}
|
|
276
|
-
var t = le();
|
|
277
321
|
|
|
278
322
|
// ../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";
|
|
323
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
324
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
325
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
287
326
|
}
|
|
288
|
-
function paint(stream, env =
|
|
289
|
-
return
|
|
327
|
+
function paint(stream, env = process6.env) {
|
|
328
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
290
329
|
}
|
|
291
|
-
function marked(mark, text, stream, detail, env =
|
|
330
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
292
331
|
const colors = paint(stream, env);
|
|
293
|
-
|
|
294
|
-
|
|
332
|
+
let head = MARK_WORDS[mark];
|
|
333
|
+
if (takesControlCodes(stream, env)) {
|
|
334
|
+
const { theme } = activeTheme();
|
|
335
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
336
|
+
}
|
|
295
337
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
296
338
|
}
|
|
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 }
|
|
339
|
+
function role(name, stream, env = process6.env) {
|
|
340
|
+
const colors = paint(stream, env);
|
|
341
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
342
|
+
}
|
|
343
|
+
var STATUS_WORDS = {
|
|
344
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
345
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
346
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
347
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
348
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
313
349
|
};
|
|
314
|
-
var STATUS_OF = new Map(Object.entries(
|
|
350
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
315
351
|
|
|
316
352
|
// ../kit/src/format.ts
|
|
317
353
|
function upTo(text, separator) {
|
|
@@ -319,22 +355,25 @@ function upTo(text, separator) {
|
|
|
319
355
|
return end === -1 ? text : text.slice(0, end);
|
|
320
356
|
}
|
|
321
357
|
function truncate(text, width) {
|
|
322
|
-
return text
|
|
358
|
+
return ko(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
323
359
|
}
|
|
324
360
|
var LINE_BREAKS = /\s*\n\s*/g;
|
|
325
361
|
var ESCAPE = String.fromCharCode(27);
|
|
326
362
|
function textWidth(text) {
|
|
327
363
|
return Bun.stringWidth(text);
|
|
328
364
|
}
|
|
329
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
365
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
330
366
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
367
|
+
if (outputMode(stream, env) === "agent")
|
|
368
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
369
|
+
`);
|
|
331
370
|
const widths = [];
|
|
332
371
|
for (const row of cells) {
|
|
333
372
|
for (const [index, cell] of row.entries())
|
|
334
373
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
335
374
|
}
|
|
336
375
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
337
|
-
const colors = paint(
|
|
376
|
+
const colors = paint(stream);
|
|
338
377
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
339
378
|
const width = widths[index] ?? 0;
|
|
340
379
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -342,7 +381,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
342
381
|
return `${gap}${cell}`;
|
|
343
382
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
344
383
|
}).join(" ").trimEnd());
|
|
345
|
-
|
|
384
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
385
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
346
386
|
`);
|
|
347
387
|
}
|
|
348
388
|
function narrow(rows, widths, limit) {
|
|
@@ -361,32 +401,35 @@ function narrow(rows, widths, limit) {
|
|
|
361
401
|
}
|
|
362
402
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
363
403
|
}
|
|
404
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
405
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
406
|
+
}
|
|
364
407
|
function printJson(value) {
|
|
365
|
-
console.log(
|
|
408
|
+
console.log(jsonText(value));
|
|
366
409
|
}
|
|
367
410
|
|
|
368
411
|
// ../kit/src/help.ts
|
|
369
|
-
import
|
|
412
|
+
import process8 from "process";
|
|
370
413
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
371
414
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
372
415
|
var FULL_STOP = /\.$/;
|
|
373
|
-
function usageLine(usage, colors = paint(
|
|
416
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
374
417
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
375
418
|
}
|
|
376
|
-
function helpText(usage, options, colors = paint(
|
|
419
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
377
420
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
378
421
|
`);
|
|
379
422
|
}
|
|
380
|
-
function exitRows(exits, colors = paint(
|
|
423
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
381
424
|
if (exits.length === 0)
|
|
382
425
|
return [];
|
|
383
426
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
384
427
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
385
428
|
}
|
|
386
|
-
function replacesRows(replaces, colors = paint(
|
|
387
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
429
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
430
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
388
431
|
}
|
|
389
|
-
function wantsHelpJson(env =
|
|
432
|
+
function wantsHelpJson(env = process8.env) {
|
|
390
433
|
return env.KIT_HELP === "json";
|
|
391
434
|
}
|
|
392
435
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -405,12 +448,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
405
448
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
406
449
|
};
|
|
407
450
|
}
|
|
408
|
-
function exampleRows(examples, colors = paint(
|
|
409
|
-
if (examples.length === 0)
|
|
451
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
452
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
410
453
|
return [];
|
|
411
454
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
412
455
|
}
|
|
413
|
-
function optionRows(options, colors = paint(
|
|
456
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
414
457
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
415
458
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
416
459
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -459,7 +502,6 @@ var DASHES = /^-+/;
|
|
|
459
502
|
function jsonOption(holds) {
|
|
460
503
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
461
504
|
}
|
|
462
|
-
|
|
463
505
|
class Exit extends Error {
|
|
464
506
|
code;
|
|
465
507
|
hint;
|
|
@@ -503,7 +545,7 @@ var OUTPUT_OPTIONS = {
|
|
|
503
545
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
504
546
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
505
547
|
};
|
|
506
|
-
function applyOutput(color, plain, env =
|
|
548
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
507
549
|
const when = plain === true ? "never" : color ?? "auto";
|
|
508
550
|
if (when === "auto")
|
|
509
551
|
return;
|
|
@@ -672,21 +714,45 @@ function nearestOption(message, options, allowNegative) {
|
|
|
672
714
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
673
715
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
674
716
|
}
|
|
717
|
+
// ../kit/src/argv.ts
|
|
718
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
719
|
+
import { resolve as resolve3 } from "path";
|
|
720
|
+
import process10 from "process";
|
|
721
|
+
function commandLine() {
|
|
722
|
+
try {
|
|
723
|
+
return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
724
|
+
} catch {
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
function realPath(word) {
|
|
729
|
+
try {
|
|
730
|
+
return realpathSync(resolve3(word));
|
|
731
|
+
} catch {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
736
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
737
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
738
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
739
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
740
|
+
}
|
|
675
741
|
// ../kit/src/progress.ts
|
|
676
742
|
var ESC = String.fromCharCode(27);
|
|
677
743
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
678
744
|
var RESET_STYLE = `${ESC}[0m`;
|
|
679
745
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
680
746
|
// ../kit/src/cli.ts
|
|
681
|
-
import { readFileSync, realpathSync } from "fs";
|
|
682
|
-
import { dirname as
|
|
683
|
-
import
|
|
747
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
748
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
749
|
+
import process12 from "process";
|
|
684
750
|
|
|
685
751
|
// ../kit/src/usage.ts
|
|
686
752
|
import { appendFileSync, mkdirSync } from "fs";
|
|
687
|
-
import { homedir } from "os";
|
|
688
|
-
import { dirname, isAbsolute, join } from "path";
|
|
689
|
-
import
|
|
753
|
+
import { homedir as homedir3 } from "os";
|
|
754
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
755
|
+
import process11 from "process";
|
|
690
756
|
|
|
691
757
|
// ../kit/src/logs.ts
|
|
692
758
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -700,14 +766,14 @@ var usageError;
|
|
|
700
766
|
function noteUsageError(message) {
|
|
701
767
|
usageError = message;
|
|
702
768
|
}
|
|
703
|
-
function stateHome(env =
|
|
769
|
+
function stateHome(env = process11.env) {
|
|
704
770
|
const dir = env.XDG_STATE_HOME;
|
|
705
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
771
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
706
772
|
}
|
|
707
|
-
function usagePath(env =
|
|
708
|
-
return
|
|
773
|
+
function usagePath(env = process11.env) {
|
|
774
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
709
775
|
}
|
|
710
|
-
function usageRecorded(env =
|
|
776
|
+
function usageRecorded(env = process11.env) {
|
|
711
777
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
712
778
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
713
779
|
}
|
|
@@ -721,12 +787,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
721
787
|
usageError = undefined;
|
|
722
788
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
723
789
|
}
|
|
724
|
-
function recordUsage(entry, env =
|
|
790
|
+
function recordUsage(entry, env = process11.env) {
|
|
725
791
|
if (!usageRecorded(env))
|
|
726
792
|
return;
|
|
727
793
|
try {
|
|
728
794
|
const path = usagePath(env);
|
|
729
|
-
mkdirSync(
|
|
795
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
730
796
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
731
797
|
`, { mode: 384 });
|
|
732
798
|
} catch {}
|
|
@@ -739,8 +805,8 @@ var LEVEL_OPTIONS = {
|
|
|
739
805
|
};
|
|
740
806
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
741
807
|
function printError(prefix, message, hint, cause) {
|
|
742
|
-
const colors = paint(
|
|
743
|
-
const styled = takesControlCodes(
|
|
808
|
+
const colors = paint(process12.stderr);
|
|
809
|
+
const styled = takesControlCodes(process12.stderr);
|
|
744
810
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
745
811
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
746
812
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -759,7 +825,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
759
825
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
760
826
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
761
827
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
762
|
-
if (error instanceof
|
|
828
|
+
if (error instanceof Exit && error.code === 2)
|
|
763
829
|
noteUsageError(error.message);
|
|
764
830
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
765
831
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
@@ -784,24 +850,24 @@ function candidateLine(candidate) {
|
|
|
784
850
|
}
|
|
785
851
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
786
852
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
787
|
-
|
|
853
|
+
const typed = [];
|
|
788
854
|
let at = 0;
|
|
789
855
|
while (at < before.length) {
|
|
790
856
|
const word = before[at];
|
|
791
857
|
if (word === "--") {
|
|
792
|
-
|
|
858
|
+
typed.push(...before.slice(at + 1));
|
|
793
859
|
break;
|
|
794
860
|
}
|
|
795
861
|
if (!word.startsWith("-"))
|
|
796
|
-
|
|
862
|
+
typed.push(word);
|
|
797
863
|
else if (takesValue(word))
|
|
798
864
|
at++;
|
|
799
865
|
at++;
|
|
800
866
|
}
|
|
801
867
|
const last = positionals.at(-1);
|
|
802
|
-
if (
|
|
803
|
-
return positionals[
|
|
804
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
868
|
+
if (typed.length < positionals.length)
|
|
869
|
+
return { name: positionals[typed.length], typed };
|
|
870
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
805
871
|
}
|
|
806
872
|
async function leafCandidates(run, words) {
|
|
807
873
|
const completing = await completingOf(run);
|
|
@@ -809,12 +875,12 @@ async function leafCandidates(run, words) {
|
|
|
809
875
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
810
876
|
const flag = words.at(-2);
|
|
811
877
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
878
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
812
879
|
if (option?.type === "string") {
|
|
813
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
880
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
814
881
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
815
882
|
}
|
|
816
|
-
const
|
|
817
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
883
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
818
884
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
819
885
|
}
|
|
820
886
|
async function printCandidates(found) {
|
|
@@ -823,17 +889,17 @@ async function printCandidates(found) {
|
|
|
823
889
|
return 0;
|
|
824
890
|
}
|
|
825
891
|
function packageVersion(entry = Bun.main) {
|
|
826
|
-
for (let dir =
|
|
892
|
+
for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
|
|
827
893
|
try {
|
|
828
|
-
const { version } = JSON.parse(
|
|
894
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
829
895
|
if (typeof version === "string")
|
|
830
896
|
return version;
|
|
831
897
|
} catch {}
|
|
832
|
-
if (
|
|
898
|
+
if (dirname3(dir) === dir)
|
|
833
899
|
return "0.0.0";
|
|
834
900
|
}
|
|
835
901
|
}
|
|
836
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
902
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
837
903
|
if (argv[0] === COMPLETE)
|
|
838
904
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
839
905
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -853,6 +919,8 @@ async function runMain({ name, version, run, redact, usage }, argv = process7.ar
|
|
|
853
919
|
}
|
|
854
920
|
return code;
|
|
855
921
|
}
|
|
922
|
+
// ../kit/src/folders.ts
|
|
923
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
856
924
|
// ../kit/src/secrets.ts
|
|
857
925
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
858
926
|
// ../kit/src/sessions.ts
|
|
@@ -1082,6 +1150,185 @@ function warningsOf(input) {
|
|
|
1082
1150
|
return warnings;
|
|
1083
1151
|
}
|
|
1084
1152
|
|
|
1153
|
+
// src/cors.ts
|
|
1154
|
+
var SIMPLE_METHODS = new Set(["GET", "HEAD", "POST"]);
|
|
1155
|
+
var NORMALIZED_METHODS = new Set(["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"]);
|
|
1156
|
+
var SAFELISTED_HEADERS = new Set(["accept", "accept-language", "content-language"]);
|
|
1157
|
+
var LIST = /\s*,\s*/;
|
|
1158
|
+
var HOSTED_SCHEME = /^[a-z][a-z0-9+.-]*:\/\/[^/]/i;
|
|
1159
|
+
function listOf(value) {
|
|
1160
|
+
return value === undefined ? [] : value.trim().split(LIST).filter((item) => item !== "");
|
|
1161
|
+
}
|
|
1162
|
+
function methodOf(input) {
|
|
1163
|
+
return NORMALIZED_METHODS.has(input.toUpperCase()) ? input.toUpperCase() : input;
|
|
1164
|
+
}
|
|
1165
|
+
function requestedHeaders(value) {
|
|
1166
|
+
return listOf(value).map((name) => name.toLowerCase()).filter((name) => !SAFELISTED_HEADERS.has(name));
|
|
1167
|
+
}
|
|
1168
|
+
function originOf(input) {
|
|
1169
|
+
if (input === "null")
|
|
1170
|
+
return input;
|
|
1171
|
+
if (!HOSTED_SCHEME.test(input) || !URL.canParse(input))
|
|
1172
|
+
return;
|
|
1173
|
+
const url = new URL(input);
|
|
1174
|
+
return url.origin === "null" ? `${url.protocol}//${url.host}` : url.origin;
|
|
1175
|
+
}
|
|
1176
|
+
function corsVerdict(status, headers, request) {
|
|
1177
|
+
const reasons = [];
|
|
1178
|
+
const warnings = [];
|
|
1179
|
+
const origin = headers["access-control-allow-origin"];
|
|
1180
|
+
const credentials = headers["access-control-allow-credentials"] === "true";
|
|
1181
|
+
const methods = listOf(headers["access-control-allow-methods"]);
|
|
1182
|
+
const allowedHeaders = new Set(listOf(headers["access-control-allow-headers"]).map((name) => name.toLowerCase()));
|
|
1183
|
+
if (status < 200 || status > 299)
|
|
1184
|
+
reasons.push(`the preflight answered ${status}, a browser wants a 2xx`);
|
|
1185
|
+
if (origin === undefined)
|
|
1186
|
+
reasons.push("no access-control-allow-origin");
|
|
1187
|
+
else if (origin !== "*" && origin !== request.origin)
|
|
1188
|
+
reasons.push(`access-control-allow-origin is ${origin}, not ${request.origin}`);
|
|
1189
|
+
const { method } = request;
|
|
1190
|
+
if (!SIMPLE_METHODS.has(method) && !methods.includes("*") && !methods.includes(method))
|
|
1191
|
+
reasons.push(methods.length === 0 ? `no access-control-allow-methods, which ${method} needs` : `access-control-allow-methods (${methods.join(", ")}) does not list ${method}`);
|
|
1192
|
+
const missing = request.headers.map((name) => name.toLowerCase()).filter((name) => !allowedHeaders.has(name) && (name === "authorization" || !allowedHeaders.has("*")));
|
|
1193
|
+
if (missing.length > 0)
|
|
1194
|
+
reasons.push(`access-control-allow-headers does not cover ${missing.join(", ")}`);
|
|
1195
|
+
if (credentials && (origin === "*" || methods.includes("*") || allowedHeaders.has("*")))
|
|
1196
|
+
warnings.push("access-control-allow-credentials comes with a * wildcard, which a request with cookies or auth does not get");
|
|
1197
|
+
if (origin === request.origin && !listOf(headers.vary).some((name) => name.toLowerCase() === "origin" || name === "*"))
|
|
1198
|
+
warnings.push("if the origin is echoed back from the request, vary lacks origin: a cache may hand this answer to another origin");
|
|
1199
|
+
const shown = Object.fromEntries(Object.entries(headers).filter(([name]) => name.startsWith("access-control-") || name === "vary"));
|
|
1200
|
+
return { allowed: reasons.length === 0, reasons, warnings, headers: shown };
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
// src/dns.ts
|
|
1204
|
+
import { Resolver } from "dns/promises";
|
|
1205
|
+
var TIMEOUT_MS = 3000;
|
|
1206
|
+
var PUBLIC_RESOLVERS = [
|
|
1207
|
+
{ name: "cloudflare", address: "1.1.1.1" },
|
|
1208
|
+
{ name: "google", address: "8.8.8.8" },
|
|
1209
|
+
{ name: "quad9", address: "9.9.9.9" }
|
|
1210
|
+
];
|
|
1211
|
+
function resolverFor(server, timeoutMs) {
|
|
1212
|
+
const resolver = new Resolver({ timeout: timeoutMs, tries: 1 });
|
|
1213
|
+
if (server.address !== undefined)
|
|
1214
|
+
resolver.setServers([server.address]);
|
|
1215
|
+
return resolver;
|
|
1216
|
+
}
|
|
1217
|
+
function failureOf(error) {
|
|
1218
|
+
const code = error.code;
|
|
1219
|
+
return code === "ETIMEOUT" || code === "ECONNREFUSED" ? "no answer" : String(error.message ?? error);
|
|
1220
|
+
}
|
|
1221
|
+
async function settled(query) {
|
|
1222
|
+
try {
|
|
1223
|
+
return await query;
|
|
1224
|
+
} catch (error) {
|
|
1225
|
+
const code = error.code;
|
|
1226
|
+
if (code === "ENOTFOUND" || code === "ENODATA")
|
|
1227
|
+
return [];
|
|
1228
|
+
throw error;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
function network(timeoutMs = TIMEOUT_MS, upstream = PUBLIC_RESOLVERS[0]) {
|
|
1232
|
+
return {
|
|
1233
|
+
servers: (server) => server.address ?? resolverFor(server, timeoutMs).getServers().join(", "),
|
|
1234
|
+
async records(server, host) {
|
|
1235
|
+
const resolver = resolverFor(server, timeoutMs);
|
|
1236
|
+
try {
|
|
1237
|
+
const [a, aaaa, cname] = await Promise.all([settled(resolver.resolve4(host, { ttl: true })), settled(resolver.resolve6(host, { ttl: true })), settled(resolver.resolveCname(host))]);
|
|
1238
|
+
const ttls = [...a, ...aaaa].map((record) => record.ttl);
|
|
1239
|
+
return { a: a.map((record) => record.address).sort(), aaaa: aaaa.map((record) => record.address).sort(), cname: cname.map((target) => target.toLowerCase()), ttl: ttls.length === 0 ? null : Math.min(...ttls) };
|
|
1240
|
+
} catch (error) {
|
|
1241
|
+
return { a: [], aaaa: [], cname: [], ttl: null, error: failureOf(error) };
|
|
1242
|
+
}
|
|
1243
|
+
},
|
|
1244
|
+
async nameservers(zone) {
|
|
1245
|
+
const resolver = resolverFor(upstream, timeoutMs);
|
|
1246
|
+
const [nameservers, alias] = await Promise.all([settled(resolver.resolveNs(zone)), settled(resolver.resolveCname(zone))]);
|
|
1247
|
+
return alias.length > 0 ? [] : nameservers;
|
|
1248
|
+
},
|
|
1249
|
+
async addressOf(host) {
|
|
1250
|
+
return (await settled(resolverFor(upstream, timeoutMs).resolve4(host)))[0];
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
var NO_ZONE = "no zone with nameservers was found for this name";
|
|
1255
|
+
var ZONE_LOOKUP_FAILED = "the zone of this name could not be looked up, so no nameserver was asked";
|
|
1256
|
+
async function zoneOf(host, client) {
|
|
1257
|
+
const labels = host.split(".");
|
|
1258
|
+
for (let at = 0;at < labels.length - 1; at++) {
|
|
1259
|
+
const zone = labels.slice(at).join(".");
|
|
1260
|
+
const nameservers = await failingToNothing(client.nameservers(zone));
|
|
1261
|
+
if (nameservers === undefined)
|
|
1262
|
+
return { problem: ZONE_LOOKUP_FAILED };
|
|
1263
|
+
if (nameservers.length > 0)
|
|
1264
|
+
return { zone, nameservers: nameservers.sort() };
|
|
1265
|
+
}
|
|
1266
|
+
return { problem: NO_ZONE };
|
|
1267
|
+
}
|
|
1268
|
+
async function failingToNothing(query) {
|
|
1269
|
+
try {
|
|
1270
|
+
return await query;
|
|
1271
|
+
} catch {
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
function sameFamily(mine, theirs) {
|
|
1276
|
+
if (mine.length === 0 || theirs.length === 0)
|
|
1277
|
+
return mine.length === theirs.length;
|
|
1278
|
+
const other = new Set(theirs);
|
|
1279
|
+
return mine.some((address) => other.has(address));
|
|
1280
|
+
}
|
|
1281
|
+
function sameAnswer(one, other) {
|
|
1282
|
+
if (one.error !== undefined || other.error !== undefined)
|
|
1283
|
+
return one.error === other.error;
|
|
1284
|
+
if (one.cname.length > 0 || other.cname.length > 0)
|
|
1285
|
+
return one.cname.join().toLowerCase() === other.cname.join().toLowerCase();
|
|
1286
|
+
return sameFamily(one.a, other.a) && sameFamily(one.aaaa, other.aaaa);
|
|
1287
|
+
}
|
|
1288
|
+
var TRAILING_DOT = /\.$/;
|
|
1289
|
+
async function dnsReport(target, host, client = network()) {
|
|
1290
|
+
const name = host.replace(TRAILING_DOT, "").toLowerCase();
|
|
1291
|
+
const found = await zoneOf(name, client);
|
|
1292
|
+
const authoritative = await Promise.all(("nameservers" in found ? found.nameservers : []).map(async (nameserver) => {
|
|
1293
|
+
const address = await failingToNothing(client.addressOf(nameserver));
|
|
1294
|
+
return address === undefined ? undefined : { name: nameserver, address };
|
|
1295
|
+
}));
|
|
1296
|
+
const asked = [
|
|
1297
|
+
...[{ name: "system" }, ...PUBLIC_RESOLVERS].map((server) => ({ server, authoritative: false })),
|
|
1298
|
+
...authoritative.filter((server) => server !== undefined).map((server) => ({ server, authoritative: true }))
|
|
1299
|
+
];
|
|
1300
|
+
const answers = await Promise.all(asked.map(async ({ server, authoritative }) => ({ resolver: server.name, server: client.servers(server), authoritative, ...await client.records(server, name) })));
|
|
1301
|
+
return { target, zone: "zone" in found ? found.zone : null, answers, ...verdictOf(answers, "problem" in found ? found.problem : undefined) };
|
|
1302
|
+
}
|
|
1303
|
+
function verdictOf(answers, zoneProblem) {
|
|
1304
|
+
const warnings = zoneProblem === undefined ? [] : [zoneProblem];
|
|
1305
|
+
const answered = answers.filter((answer) => answer.error !== "no answer");
|
|
1306
|
+
const reference = answered.filter((answer) => answer.authoritative);
|
|
1307
|
+
const truth = reference[0] ?? answered[0];
|
|
1308
|
+
const agree = truth === undefined || answered.every((answer) => sameAnswer(answer, truth));
|
|
1309
|
+
if (reference.some((answer) => !sameAnswer(answer, reference[0])))
|
|
1310
|
+
warnings.push("the zone's own nameservers disagree: one of them has not taken the last change yet");
|
|
1311
|
+
for (const answer of answers) {
|
|
1312
|
+
if (answer.error === "no answer")
|
|
1313
|
+
warnings.push(`${answer.resolver} did not answer`);
|
|
1314
|
+
}
|
|
1315
|
+
if (agree)
|
|
1316
|
+
return { agree, warnings };
|
|
1317
|
+
if (reference.length === 0) {
|
|
1318
|
+
warnings.push(`the resolvers disagree, with no nameserver of the zone to tell which is right: ${answered.filter((answer) => !sameAnswer(answer, truth)).map((answer) => answer.resolver).join(", ")} differ from ${truth.resolver}`);
|
|
1319
|
+
return { agree, warnings };
|
|
1320
|
+
}
|
|
1321
|
+
const stale = answered.filter((answer) => !answer.authoritative && !reference.some((ns) => sameAnswer(answer, ns)));
|
|
1322
|
+
for (const answer of stale) {
|
|
1323
|
+
const until = answer.ttl === null || answer.cname.length > 0 ? "" : `, cached for up to ${answer.ttl}s more`;
|
|
1324
|
+
warnings.push(answer.resolver === "system" ? `the system resolver answers differently from the zone's nameservers${until}: \`sudo resolvectl flush-caches\` drops its copy` : `${answer.resolver} answers differently from the zone's nameservers${until}: the change has not reached it yet`);
|
|
1325
|
+
}
|
|
1326
|
+
return { agree, warnings };
|
|
1327
|
+
}
|
|
1328
|
+
function known(report) {
|
|
1329
|
+
return report.answers.some((answer) => answer.error === undefined && answer.a.length + answer.aaaa.length + answer.cname.length > 0);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1085
1332
|
// src/net.ts
|
|
1086
1333
|
import { lookup } from "dns/promises";
|
|
1087
1334
|
import { isIP } from "net";
|
|
@@ -1115,11 +1362,13 @@ function curlResolve(url, resolve) {
|
|
|
1115
1362
|
return [];
|
|
1116
1363
|
return ["--resolve", `${parsed.hostname}:${portOf(parsed)}:${isIP(address) === 6 ? `[${address}]` : address}`];
|
|
1117
1364
|
}
|
|
1118
|
-
async function runCurl(url, { http3: wantsH3, insecure, get, headers = [], resolve, timeoutS = MAX_TIME }) {
|
|
1365
|
+
async function runCurl(url, { http3: wantsH3, insecure, get, method, headers = [], resolve, timeoutS = MAX_TIME }) {
|
|
1119
1366
|
const args = ["-sS", "-o", "/dev/null", "--connect-timeout", String(Math.min(CONNECT_TIMEOUT, timeoutS)), "--max-time", String(timeoutS), "--write-out", WRITE_OUT, ...curlResolve(url, resolve)];
|
|
1120
1367
|
for (const header of headers)
|
|
1121
1368
|
args.push("-H", header);
|
|
1122
|
-
if (
|
|
1369
|
+
if (method !== undefined)
|
|
1370
|
+
args.push("-X", method);
|
|
1371
|
+
else if (!get)
|
|
1123
1372
|
args.push("-I");
|
|
1124
1373
|
if (wantsH3)
|
|
1125
1374
|
args.push("--http3");
|
|
@@ -1141,6 +1390,10 @@ async function curlHop(url, options) {
|
|
|
1141
1390
|
result = await runCurl(url, { ...options, get: true });
|
|
1142
1391
|
return result;
|
|
1143
1392
|
}
|
|
1393
|
+
async function curlPreflight(url, request, options) {
|
|
1394
|
+
const asked = [`Origin: ${request.origin}`, `Access-Control-Request-Method: ${request.method}`, ...request.headers.length > 0 ? [`Access-Control-Request-Headers: ${request.headers.join(", ")}`] : []];
|
|
1395
|
+
return runCurl(url, { ...options, headers: [...options.headers ?? [], ...asked], http3: false, get: true, method: "OPTIONS" });
|
|
1396
|
+
}
|
|
1144
1397
|
async function addressesOf(host, resolve) {
|
|
1145
1398
|
const bare = resolve?.get(host) ?? host.replace(BRACKETS, "");
|
|
1146
1399
|
const family = isIP(bare);
|
|
@@ -1184,15 +1437,22 @@ By default one line per target: the HTTP version, status, final URL, total time,
|
|
|
1184
1437
|
A bare domain is tried over https first and over http when that fails. Redirects are followed hop by hop (at most ${MAX_HOPS}), each hop's status and HTTP version listed. HTTP/3 is spoken only when the installed curl lists it, otherwise it is reported from alt-svc. The certificate is read even when it is not trusted, and --insecure also lets curl go on with it.
|
|
1185
1438
|
-H adds a header to every request, --resolve host:ip reaches a host at that address instead of the DNS answer (the certificate and the Host header stay the host's), both repeatable.
|
|
1186
1439
|
|
|
1187
|
-
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)
|
|
1188
|
-
|
|
1440
|
+
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).
|
|
1441
|
+
|
|
1442
|
+
--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.
|
|
1443
|
+
--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.`;
|
|
1444
|
+
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"]];
|
|
1189
1445
|
var OPTIONS = {
|
|
1190
1446
|
insecure: { type: "boolean", short: "k", description: "let curl go on with a certificate it does not trust" },
|
|
1191
1447
|
header: { type: "string", short: "H", multiple: true, description: "a `Name: value` header sent with every request, repeatable" },
|
|
1192
1448
|
resolve: { type: "string", multiple: true, description: "host:ip, reach the host at that address instead of the DNS answer, repeatable" },
|
|
1193
|
-
timeout: { type: "string", short: "t", description: "longest one request may take (20s): 5s, 1m, a bare number in seconds" },
|
|
1449
|
+
timeout: { type: "string", short: "t", description: "longest one request may take (20s, 3s for a DNS query): 5s, 1m, a bare number in seconds" },
|
|
1194
1450
|
verbose: { type: "boolean", description: "the whole table for each target instead of one line" },
|
|
1195
|
-
|
|
1451
|
+
dns: { type: "boolean", description: "compare what each resolver and the zone's nameservers answer for the host, no HTTP request", conflicts: ["cors", "header", "resolve", "insecure", "verbose"] },
|
|
1452
|
+
cors: { type: "string", description: "the origin a browser would call from: whether its CORS preflight lets the request through", conflicts: ["dns", "verbose"] },
|
|
1453
|
+
method: { type: "string", description: "with --cors, the method of the request the preflight asks for (POST)" },
|
|
1454
|
+
"cors-headers": { type: "string", description: "with --cors, the headers it carries, comma separated, empty for none (content-type)" },
|
|
1455
|
+
json: jsonOption("one object per target {target, url, version, status, chain, timings, addresses, tls, certificate, headers, cdn, offers, httpRedirect, warnings}, an array of them for several targets (an unreachable one is {target, error}); with --dns {target, zone, answers, agree, warnings}, with --cors {target, url, status, request, allowed, reasons, warnings, headers}")
|
|
1196
1456
|
};
|
|
1197
1457
|
var BRACKETS2 = /^\[|\]$/g;
|
|
1198
1458
|
var HEADER_LINE = /^[\w!#$%&'*+.^`|~-]+:/;
|
|
@@ -1274,9 +1534,9 @@ function ms2(value) {
|
|
|
1274
1534
|
return `${value}ms`;
|
|
1275
1535
|
}
|
|
1276
1536
|
function compact(report) {
|
|
1277
|
-
const { dim } = paint(
|
|
1537
|
+
const { dim } = paint(process14.stdout);
|
|
1278
1538
|
const redirects = report.chain.length - 1;
|
|
1279
|
-
const parts = [`${role("accent",
|
|
1539
|
+
const parts = [`${role("accent", process14.stdout)(versionLabel(report.version))} ${role("value", process14.stdout)(String(report.status))} ${role("path", process14.stdout)(report.url)}`, ms2(report.timings.total)];
|
|
1280
1540
|
const address = report.addresses.a[0] ?? report.addresses.aaaa[0];
|
|
1281
1541
|
if (redirects > 0)
|
|
1282
1542
|
parts.push(`${redirects} ${redirects === 1 ? "redirect" : "redirects"}`);
|
|
@@ -1285,14 +1545,14 @@ function compact(report) {
|
|
|
1285
1545
|
if (address !== undefined)
|
|
1286
1546
|
parts.push(address);
|
|
1287
1547
|
const line = parts.join(dim(" "));
|
|
1288
|
-
return report.warnings.length === 0 ? line : `${line} ${marked("warn", report.warnings.join("; "),
|
|
1548
|
+
return report.warnings.length === 0 ? line : `${line} ${marked("warn", report.warnings.join("; "), process14.stdout)}`;
|
|
1289
1549
|
}
|
|
1290
1550
|
function print(report) {
|
|
1291
|
-
const label = role("label",
|
|
1292
|
-
const value = role("value",
|
|
1293
|
-
const accent = role("accent",
|
|
1551
|
+
const label = role("label", process14.stdout);
|
|
1552
|
+
const value = role("value", process14.stdout);
|
|
1553
|
+
const accent = role("accent", process14.stdout);
|
|
1294
1554
|
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",
|
|
1555
|
+
console.log(`${accent(versionLabel(report.version))} ${value(String(report.status))} ${role("path", process14.stdout)(report.url)}`);
|
|
1296
1556
|
console.log("");
|
|
1297
1557
|
if (report.chain.length > 1) {
|
|
1298
1558
|
console.log(table(report.chain.map((hop) => [String(hop.status), versionLabel(hop.version), ms2(hop.ms), hop.url]), { align: ["right", "left", "right", "left"] }));
|
|
@@ -1317,16 +1577,98 @@ function print(report) {
|
|
|
1317
1577
|
if (report.httpRedirect !== null)
|
|
1318
1578
|
row("http://", report.httpRedirect.toHttps ? `redirects to https (${report.httpRedirect.status})` : `answers ${report.httpRedirect.status}`);
|
|
1319
1579
|
for (const warning of report.warnings)
|
|
1320
|
-
console.log(marked("warn", warning,
|
|
1580
|
+
console.log(marked("warn", warning, process14.stdout));
|
|
1581
|
+
}
|
|
1582
|
+
function printDns(report) {
|
|
1583
|
+
const label = role("label", process14.stdout);
|
|
1584
|
+
const listed = (values) => values.length === 0 ? "-" : values.join(" ");
|
|
1585
|
+
console.log(`${role("path", process14.stdout)(report.target)} ${label(report.zone === null ? "no zone found" : `zone ${report.zone}`)}`);
|
|
1586
|
+
console.log(table([
|
|
1587
|
+
["RESOLVER", "SERVER", "A", "AAAA", "CNAME", "TTL"],
|
|
1588
|
+
...report.answers.map((answer) => [
|
|
1589
|
+
answer.authoritative ? `${answer.resolver} (ns)` : answer.resolver,
|
|
1590
|
+
answer.server,
|
|
1591
|
+
...answer.error === undefined ? [listed(answer.a), listed(answer.aaaa), listed(answer.cname)] : [answer.error, "", ""],
|
|
1592
|
+
answer.ttl === null ? "-" : `${answer.ttl}s`
|
|
1593
|
+
])
|
|
1594
|
+
], { header: true }));
|
|
1595
|
+
if (report.agree)
|
|
1596
|
+
console.log(marked("ok", "every resolver gives the same answer", process14.stdout));
|
|
1597
|
+
for (const warning of report.warnings)
|
|
1598
|
+
console.log(marked("warn", warning, process14.stdout));
|
|
1599
|
+
}
|
|
1600
|
+
async function dnsMain(inputs, timeoutMs, json) {
|
|
1601
|
+
const hosts = inputs.map((input) => {
|
|
1602
|
+
const host = parseTarget(input)?.url.hostname;
|
|
1603
|
+
if (host === undefined)
|
|
1604
|
+
badUsage(`not a URL or domain: ${input}`);
|
|
1605
|
+
if (isIP2(host.replace(BRACKETS2, "")) !== 0)
|
|
1606
|
+
badUsage(`--dns takes a name, not the address ${input}`);
|
|
1607
|
+
return { input, host };
|
|
1608
|
+
});
|
|
1609
|
+
const client = network(timeoutMs);
|
|
1610
|
+
const reports = await Promise.all(hosts.map(async ({ input, host }) => dnsReport(input, host, client)));
|
|
1611
|
+
if (json) {
|
|
1612
|
+
printJson(reports.length === 1 ? reports[0] : reports);
|
|
1613
|
+
} else {
|
|
1614
|
+
for (const [at, report] of reports.entries()) {
|
|
1615
|
+
if (at > 0)
|
|
1616
|
+
console.log("");
|
|
1617
|
+
printDns(report);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
return reports.every(known) ? 0 : 1;
|
|
1621
|
+
}
|
|
1622
|
+
function printCors(report) {
|
|
1623
|
+
const label = role("label", process14.stdout);
|
|
1624
|
+
const { request } = report;
|
|
1625
|
+
const asked = `from ${request.origin}, ${request.method}${request.headers.length === 0 ? "" : ` with ${request.headers.join(", ")}`}`;
|
|
1626
|
+
console.log(`${marked(report.allowed ? "ok" : "problem", report.allowed ? "allowed" : "refused", process14.stdout)} ${role("value", process14.stdout)(String(report.status))} ${role("path", process14.stdout)(report.url)} ${label(asked)}`);
|
|
1627
|
+
for (const [name, value] of Object.entries(report.headers))
|
|
1628
|
+
console.log(` ${label(name)} ${value}`);
|
|
1629
|
+
for (const reason of report.reasons)
|
|
1630
|
+
console.log(marked("problem", reason, process14.stdout));
|
|
1631
|
+
for (const warning of report.warnings)
|
|
1632
|
+
console.log(marked("warn", warning, process14.stdout));
|
|
1633
|
+
}
|
|
1634
|
+
async function corsMain(targets, request, { insecure, wire }, json) {
|
|
1635
|
+
const reports = await Promise.all(targets.map(async ({ input, target }) => {
|
|
1636
|
+
const { hop, errormsg } = await curlPreflight(target.url.href, request, { ...wire, insecure });
|
|
1637
|
+
if (hop === undefined)
|
|
1638
|
+
return { target: input, error: `could not reach ${target.url.host}: ${errormsg ?? "no response"}` };
|
|
1639
|
+
return { target: input, url: hop.url, status: hop.status, request, ...corsVerdict(hop.status, hop.headers, request) };
|
|
1640
|
+
}));
|
|
1641
|
+
const [only] = reports;
|
|
1642
|
+
if (reports.length === 1 && only !== undefined && "error" in only)
|
|
1643
|
+
fail(only.error, 1);
|
|
1644
|
+
if (json) {
|
|
1645
|
+
printJson(reports.length === 1 ? only : reports);
|
|
1646
|
+
} else {
|
|
1647
|
+
for (const report of reports) {
|
|
1648
|
+
if ("error" in report)
|
|
1649
|
+
console.error(marked("problem", report.error, process14.stderr));
|
|
1650
|
+
else
|
|
1651
|
+
printCors(report);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return reports.every((report) => ("allowed" in report) && report.allowed) ? 0 : 1;
|
|
1321
1655
|
}
|
|
1322
1656
|
async function main(args) {
|
|
1323
|
-
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["<url|domain>..."], exits: EXITS, replaces: "the httpversion fish function, curl -sI chains
|
|
1657
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["<url|domain>..."], exits: EXITS, replaces: "the httpversion fish function, curl -sI chains, openssl s_client and dig @server 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"], ["probe --dns example.com", "whether a DNS change has reached every resolver"], ["probe --cors https://app.example.com --method PUT --cors-headers content-type,authorization https://api.example.com/items", "whether the browser would let the call through"]] });
|
|
1658
|
+
if (values.cors === undefined) {
|
|
1659
|
+
if (values.method !== undefined)
|
|
1660
|
+
badUsage("--method goes with --cors");
|
|
1661
|
+
if (values["cors-headers"] !== undefined)
|
|
1662
|
+
badUsage("--cors-headers goes with --cors");
|
|
1663
|
+
}
|
|
1324
1664
|
const headers = values.header ?? [];
|
|
1325
1665
|
for (const header of headers) {
|
|
1326
1666
|
if (!HEADER_LINE.test(header))
|
|
1327
1667
|
badUsage(`-H takes "Name: value", not ${header}`);
|
|
1328
1668
|
}
|
|
1329
1669
|
const timeoutMs = values.timeout === undefined ? undefined : duration(values.timeout, "timeout", 0, "s");
|
|
1670
|
+
if (values.dns === true)
|
|
1671
|
+
return dnsMain(positionals, timeoutMs, values.json === true);
|
|
1330
1672
|
const wire = { headers, resolve: resolvesOf(values.resolve ?? []), ...timeoutMs === undefined ? {} : { timeoutS: timeoutMs / 1000 } };
|
|
1331
1673
|
const targets = positionals.map((input) => {
|
|
1332
1674
|
const target = parseTarget(input);
|
|
@@ -1334,6 +1676,13 @@ async function main(args) {
|
|
|
1334
1676
|
badUsage(`not a URL or domain: ${input}`);
|
|
1335
1677
|
return { input, target };
|
|
1336
1678
|
});
|
|
1679
|
+
if (values.cors !== undefined) {
|
|
1680
|
+
const origin = originOf(values.cors);
|
|
1681
|
+
if (origin === undefined)
|
|
1682
|
+
badUsage(`--cors takes an origin such as https://app.example.com, not ${values.cors}`);
|
|
1683
|
+
const request = { origin, method: methodOf(values.method ?? "POST"), headers: requestedHeaders(values["cors-headers"] ?? "content-type") };
|
|
1684
|
+
return corsMain(targets, request, { insecure: values.insecure === true, wire }, values.json === true);
|
|
1685
|
+
}
|
|
1337
1686
|
const reports = await Promise.all(targets.map(async ({ input, target }) => probe(target, input, { insecure: values.insecure === true, wire })));
|
|
1338
1687
|
const [only] = reports;
|
|
1339
1688
|
if (reports.length === 1 && only !== undefined && "error" in only)
|
|
@@ -1345,12 +1694,12 @@ async function main(args) {
|
|
|
1345
1694
|
let first = true;
|
|
1346
1695
|
for (const report of reports) {
|
|
1347
1696
|
if ("error" in report) {
|
|
1348
|
-
console.error(marked("problem", report.error,
|
|
1697
|
+
console.error(marked("problem", report.error, process14.stderr));
|
|
1349
1698
|
} else if (values.verbose === true) {
|
|
1350
1699
|
if (!first)
|
|
1351
1700
|
console.log("");
|
|
1352
1701
|
if (reports.length > 1)
|
|
1353
|
-
console.log(role("label",
|
|
1702
|
+
console.log(role("label", process14.stdout)(report.target));
|
|
1354
1703
|
print(report);
|
|
1355
1704
|
} else {
|
|
1356
1705
|
console.log(compact(report));
|
|
@@ -1359,4 +1708,4 @@ async function main(args) {
|
|
|
1359
1708
|
}
|
|
1360
1709
|
return reports.some((report) => ("error" in report)) ? 1 : 0;
|
|
1361
1710
|
}
|
|
1362
|
-
|
|
1711
|
+
process14.exitCode = await runMain({ name: "probe", run: main });
|