@kaynooo/cli-dev 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/dist/cli.js +146 -308
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,291 +1,112 @@
|
|
|
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/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process10 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process6 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
|
-
// ../kit/src/
|
|
11
|
-
import
|
|
10
|
+
// ../kit/src/format.ts
|
|
11
|
+
import process4 from "process";
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
function A(s) {
|
|
31
|
-
let [r, t, n, a] = s;
|
|
32
|
-
if (a)
|
|
33
|
-
return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
34
|
-
return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
|
|
35
|
-
}
|
|
36
|
-
function R(s, r, t) {
|
|
37
|
-
s = (s % 360 + 360) % 360, t /= 100;
|
|
38
|
-
let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
|
|
39
|
-
let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
|
|
40
|
-
return Math.round(255 * y);
|
|
41
|
-
};
|
|
42
|
-
return [a(0), a(8), a(4)];
|
|
43
|
-
}
|
|
44
|
-
function k(s) {
|
|
45
|
-
let [r, t, n] = s;
|
|
46
|
-
r /= 255, t /= 255, n /= 255;
|
|
47
|
-
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
|
|
48
|
-
if (a !== b) {
|
|
49
|
-
let u = a - b;
|
|
50
|
-
if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
|
|
51
|
-
o = (t - n) / u + (t < n ? 6 : 0);
|
|
52
|
-
else if (a === t)
|
|
53
|
-
o = (n - r) / u + 2;
|
|
54
|
-
else
|
|
55
|
-
o = (r - t) / u + 4;
|
|
56
|
-
o /= 6;
|
|
57
|
-
}
|
|
58
|
-
return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
|
|
59
|
-
}
|
|
60
|
-
function H(s, r, t) {
|
|
61
|
-
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
62
|
-
let n = (a) => {
|
|
63
|
-
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
64
|
-
return Math.round(255 * o);
|
|
65
|
-
};
|
|
66
|
-
return [n(5), n(3), n(1)];
|
|
67
|
-
}
|
|
68
|
-
function f(s) {
|
|
69
|
-
let [r, t, n] = s;
|
|
70
|
-
r /= 255, t /= 255, n /= 255;
|
|
71
|
-
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;
|
|
72
|
-
if (o !== 0) {
|
|
73
|
-
if (a === r)
|
|
74
|
-
y = (t - n) / o + (t < n ? 6 : 0);
|
|
75
|
-
else if (a === t)
|
|
76
|
-
y = (n - r) / o + 2;
|
|
77
|
-
else
|
|
78
|
-
y = (r - t) / o + 4;
|
|
79
|
-
y /= 6;
|
|
80
|
-
}
|
|
81
|
-
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
82
|
-
}
|
|
83
|
-
function O(s) {
|
|
84
|
-
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
85
|
-
if (a === 1)
|
|
86
|
-
return [0, 0, 0, 100];
|
|
87
|
-
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
88
|
-
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
89
|
-
}
|
|
90
|
-
function v(s, r, t, n) {
|
|
91
|
-
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))];
|
|
92
|
-
}
|
|
93
|
-
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
94
|
-
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
95
|
-
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
96
|
-
function T(s) {
|
|
97
|
-
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);
|
|
98
|
-
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)];
|
|
99
|
-
}
|
|
100
|
-
function M(s, r, t) {
|
|
101
|
-
let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
|
|
102
|
-
return [u(o), u(y), u(c)];
|
|
103
|
-
}
|
|
104
|
-
function d(s) {
|
|
105
|
-
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
106
|
-
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
107
|
-
}
|
|
108
|
-
function C(s, r, t) {
|
|
109
|
-
let n = t * Math.PI / 180;
|
|
110
|
-
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
111
|
-
}
|
|
112
|
-
function l(s) {
|
|
113
|
-
let r = s / 255;
|
|
114
|
-
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
13
|
+
// ../kit/src/mode.ts
|
|
14
|
+
import process2 from "process";
|
|
15
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
16
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
17
|
+
function isSet(value) {
|
|
18
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
19
|
+
}
|
|
20
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
21
|
+
const chosen = env.KIT_MODE;
|
|
22
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
23
|
+
return chosen;
|
|
24
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
25
|
+
return "agent";
|
|
26
|
+
if (stream.isTTY === true)
|
|
27
|
+
return "terminal";
|
|
28
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
115
29
|
}
|
|
116
30
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
g;
|
|
120
|
-
b;
|
|
121
|
-
a;
|
|
122
|
-
constructor(s, r, t, n = 1) {
|
|
123
|
-
this.r = s, this.g = r, this.b = t, this.a = n;
|
|
124
|
-
}
|
|
125
|
-
static from(s, r) {
|
|
126
|
-
if (s === "hex") {
|
|
127
|
-
let [t, n, a, b] = x(r);
|
|
128
|
-
return new e(t, n, a, b);
|
|
129
|
-
}
|
|
130
|
-
if (s === "rgb") {
|
|
131
|
-
if (Array.isArray(r)) {
|
|
132
|
-
let [o, y, c, u] = r;
|
|
133
|
-
return new e(o, y, c, u);
|
|
134
|
-
}
|
|
135
|
-
let { r: t, g: n, b: a, a: b } = r;
|
|
136
|
-
return new e(t, n, a, b);
|
|
137
|
-
}
|
|
138
|
-
if (s === "hsl") {
|
|
139
|
-
let t, n, a, b;
|
|
140
|
-
if (Array.isArray(r))
|
|
141
|
-
[t, n, a, b] = r;
|
|
142
|
-
else
|
|
143
|
-
({ h: t, s: n, l: a, a: b } = r);
|
|
144
|
-
let [o, y, c] = R(t, n, a);
|
|
145
|
-
return new e(o, y, c, b);
|
|
146
|
-
}
|
|
147
|
-
if (s === "hsv") {
|
|
148
|
-
let t, n, a, b;
|
|
149
|
-
if (Array.isArray(r))
|
|
150
|
-
[t, n, a, b] = r;
|
|
151
|
-
else
|
|
152
|
-
({ h: t, s: n, v: a, a: b } = r);
|
|
153
|
-
let [o, y, c] = H(t, n, a);
|
|
154
|
-
return new e(o, y, c, b);
|
|
155
|
-
}
|
|
156
|
-
if (s === "cmyk") {
|
|
157
|
-
let t, n, a, b, o;
|
|
158
|
-
if (Array.isArray(r))
|
|
159
|
-
[t, n, a, b, o] = r;
|
|
160
|
-
else
|
|
161
|
-
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
162
|
-
let [y, c, u] = v(t, n, a, b);
|
|
163
|
-
return new e(y, c, u, o);
|
|
164
|
-
}
|
|
165
|
-
if (s === "oklch") {
|
|
166
|
-
let t, n, a, b;
|
|
167
|
-
if (Array.isArray(r))
|
|
168
|
-
[t, n, a, b] = r;
|
|
169
|
-
else
|
|
170
|
-
({ l: t, c: n, h: a, a: b } = r);
|
|
171
|
-
let [o, y, c] = C(t, n, a);
|
|
172
|
-
return new e(o, y, c, b);
|
|
173
|
-
}
|
|
174
|
-
if (s === "oklab") {
|
|
175
|
-
let t, n, a, b;
|
|
176
|
-
if (Array.isArray(r))
|
|
177
|
-
[t, n, a, b] = r;
|
|
178
|
-
else
|
|
179
|
-
({ l: t, a: n, b: a, alpha: b } = r);
|
|
180
|
-
let [o, y, c] = M(t, n, a);
|
|
181
|
-
return new e(o, y, c, b);
|
|
182
|
-
}
|
|
183
|
-
throw Error("Invalid input");
|
|
184
|
-
}
|
|
185
|
-
to(s) {
|
|
186
|
-
switch (s) {
|
|
187
|
-
case "rgb":
|
|
188
|
-
return [this.r, this.g, this.b];
|
|
189
|
-
case "rgba":
|
|
190
|
-
return [this.r, this.g, this.b, this.a];
|
|
191
|
-
case "hex":
|
|
192
|
-
return A([this.r, this.g, this.b]);
|
|
193
|
-
case "hexa":
|
|
194
|
-
return A([this.r, this.g, this.b, this.a]);
|
|
195
|
-
case "hsl":
|
|
196
|
-
return k([this.r, this.g, this.b]);
|
|
197
|
-
case "hsla":
|
|
198
|
-
return [...k([this.r, this.g, this.b]), this.a];
|
|
199
|
-
case "hsv":
|
|
200
|
-
return f([this.r, this.g, this.b]);
|
|
201
|
-
case "hsva":
|
|
202
|
-
return [...f([this.r, this.g, this.b]), this.a];
|
|
203
|
-
case "cmyk":
|
|
204
|
-
return O([this.r, this.g, this.b]);
|
|
205
|
-
case "cmyka":
|
|
206
|
-
return [...O([this.r, this.g, this.b]), this.a];
|
|
207
|
-
case "oklch":
|
|
208
|
-
return d([this.r, this.g, this.b]);
|
|
209
|
-
case "oklcha":
|
|
210
|
-
return [...d([this.r, this.g, this.b]), this.a];
|
|
211
|
-
case "oklab":
|
|
212
|
-
return T([this.r, this.g, this.b]);
|
|
213
|
-
case "oklaba":
|
|
214
|
-
return [...T([this.r, this.g, this.b]), this.a];
|
|
215
|
-
default:
|
|
216
|
-
return [this.r, this.g, this.b];
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
getLuminance() {
|
|
220
|
-
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
221
|
-
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
222
|
-
}
|
|
223
|
-
contrastRatio(s) {
|
|
224
|
-
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
225
|
-
return (n + 0.05) / (a + 0.05);
|
|
226
|
-
}
|
|
227
|
-
bestContrastForeground() {
|
|
228
|
-
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
229
|
-
return t >= n ? s : r;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
31
|
+
// ../kit/src/style.ts
|
|
32
|
+
import process3 from "process";
|
|
232
33
|
|
|
233
|
-
// ../../node_modules/.bun/@kaynooo+utils@
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
34
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
35
|
+
var G = /^[a-f0-9]+$/i;
|
|
36
|
+
function b(r) {
|
|
37
|
+
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
38
|
+
if (!G.test(e))
|
|
39
|
+
return [0, 0, 0];
|
|
40
|
+
if (e.length === 3 || e.length === 4)
|
|
41
|
+
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
42
|
+
if (e.length !== 6 && e.length !== 8)
|
|
43
|
+
throw Error(`Invalid hex color length: ${e.length}`);
|
|
44
|
+
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
45
|
+
}
|
|
46
|
+
var B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
47
|
+
let [l, n, c] = b(r);
|
|
48
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
49
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
50
|
+
var h = new Set(["", "1", "2", "3", "true"]);
|
|
51
|
+
function C(r, e = globalThis.process?.env ?? {}) {
|
|
52
|
+
if (e.FORCE_COLOR !== undefined)
|
|
53
|
+
return h.has(e.FORCE_COLOR);
|
|
54
|
+
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
246
55
|
return false;
|
|
247
|
-
return
|
|
248
|
-
}
|
|
249
|
-
function
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (
|
|
263
|
-
return
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
56
|
+
return r?.isTTY === true;
|
|
57
|
+
}
|
|
58
|
+
function f(r, e = []) {
|
|
59
|
+
let l = "", n = "";
|
|
60
|
+
for (let t = 0, i = e.length;t < i; t++)
|
|
61
|
+
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
62
|
+
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
63
|
+
return new Proxy(c, { get(t, i) {
|
|
64
|
+
let a = B[i];
|
|
65
|
+
if (Array.isArray(a)) {
|
|
66
|
+
let s = g.get(i);
|
|
67
|
+
if (s === undefined)
|
|
68
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
69
|
+
return s;
|
|
70
|
+
}
|
|
71
|
+
if (typeof a === "function")
|
|
72
|
+
return (...s) => {
|
|
73
|
+
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
74
|
+
if (u === undefined) {
|
|
75
|
+
if (g.size >= 64)
|
|
76
|
+
g.clear();
|
|
77
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
78
|
+
}
|
|
79
|
+
return u;
|
|
80
|
+
};
|
|
81
|
+
throw Error(`Unknown style: ${String(i)}`);
|
|
267
82
|
} });
|
|
268
83
|
}
|
|
269
|
-
function
|
|
270
|
-
return
|
|
84
|
+
function Fe(r = {}) {
|
|
85
|
+
return f(r);
|
|
271
86
|
}
|
|
272
|
-
var
|
|
87
|
+
var o = Fe();
|
|
88
|
+
|
|
89
|
+
// ../kit/src/theme.ts
|
|
90
|
+
var ENDS = new Map;
|
|
91
|
+
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"]);
|
|
92
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
93
|
+
var warned = new Set;
|
|
273
94
|
|
|
274
95
|
// ../kit/src/style.ts
|
|
275
|
-
function takesControlCodes(stream, env =
|
|
276
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
277
|
-
}
|
|
278
|
-
function paint(stream, env =
|
|
279
|
-
return
|
|
280
|
-
}
|
|
281
|
-
var
|
|
282
|
-
passed:
|
|
283
|
-
failed:
|
|
284
|
-
running:
|
|
285
|
-
queued:
|
|
286
|
-
skipped:
|
|
96
|
+
function takesControlCodes(stream, env = process3.env) {
|
|
97
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
98
|
+
}
|
|
99
|
+
function paint(stream, env = process3.env) {
|
|
100
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
101
|
+
}
|
|
102
|
+
var STATUS_WORDS = {
|
|
103
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
104
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
105
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
106
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
107
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
287
108
|
};
|
|
288
|
-
var STATUS_OF = new Map(Object.entries(
|
|
109
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
289
110
|
|
|
290
111
|
// ../kit/src/format.ts
|
|
291
112
|
function upTo(text, separator) {
|
|
@@ -293,32 +114,35 @@ function upTo(text, separator) {
|
|
|
293
114
|
return end === -1 ? text : text.slice(0, end);
|
|
294
115
|
}
|
|
295
116
|
var ESCAPE = String.fromCharCode(27);
|
|
117
|
+
function jsonText(value, replacer, { stream = process4.stdout, env = process4.env } = {}) {
|
|
118
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
119
|
+
}
|
|
296
120
|
function printJson(value) {
|
|
297
|
-
console.log(
|
|
121
|
+
console.log(jsonText(value));
|
|
298
122
|
}
|
|
299
123
|
|
|
300
124
|
// ../kit/src/help.ts
|
|
301
|
-
import
|
|
125
|
+
import process5 from "process";
|
|
302
126
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
303
127
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
304
128
|
var FULL_STOP = /\.$/;
|
|
305
|
-
function usageLine(usage, colors = paint(
|
|
129
|
+
function usageLine(usage, colors = paint(process5.stdout)) {
|
|
306
130
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
307
131
|
}
|
|
308
|
-
function helpText(usage, options, colors = paint(
|
|
132
|
+
function helpText(usage, options, colors = paint(process5.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
309
133
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
310
134
|
`);
|
|
311
135
|
}
|
|
312
|
-
function exitRows(exits, colors = paint(
|
|
136
|
+
function exitRows(exits, colors = paint(process5.stdout)) {
|
|
313
137
|
if (exits.length === 0)
|
|
314
138
|
return [];
|
|
315
139
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
316
140
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
317
141
|
}
|
|
318
|
-
function replacesRows(replaces, colors = paint(
|
|
319
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
142
|
+
function replacesRows(replaces, colors = paint(process5.stdout)) {
|
|
143
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
320
144
|
}
|
|
321
|
-
function wantsHelpJson(env =
|
|
145
|
+
function wantsHelpJson(env = process5.env) {
|
|
322
146
|
return env.KIT_HELP === "json";
|
|
323
147
|
}
|
|
324
148
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -337,12 +161,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
337
161
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
338
162
|
};
|
|
339
163
|
}
|
|
340
|
-
function exampleRows(examples, colors = paint(
|
|
341
|
-
if (examples.length === 0)
|
|
164
|
+
function exampleRows(examples, colors = paint(process5.stdout)) {
|
|
165
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
342
166
|
return [];
|
|
343
167
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
344
168
|
}
|
|
345
|
-
function optionRows(options, colors = paint(
|
|
169
|
+
function optionRows(options, colors = paint(process5.stdout)) {
|
|
346
170
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
347
171
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
348
172
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -394,7 +218,6 @@ var DASHES = /^-+/;
|
|
|
394
218
|
function jsonOption(holds) {
|
|
395
219
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
396
220
|
}
|
|
397
|
-
|
|
398
221
|
class Exit extends Error {
|
|
399
222
|
code;
|
|
400
223
|
hint;
|
|
@@ -438,7 +261,7 @@ var OUTPUT_OPTIONS = {
|
|
|
438
261
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
439
262
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
440
263
|
};
|
|
441
|
-
function applyOutput(color, plain, env =
|
|
264
|
+
function applyOutput(color, plain, env = process6.env) {
|
|
442
265
|
const when = plain === true ? "never" : color ?? "auto";
|
|
443
266
|
if (when === "auto")
|
|
444
267
|
return;
|
|
@@ -607,6 +430,25 @@ function nearestOption(message, options, allowNegative) {
|
|
|
607
430
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
608
431
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
609
432
|
}
|
|
433
|
+
// ../kit/src/process.ts
|
|
434
|
+
var CLIPBOARDS = [["wl-copy"], ["xclip", "-selection", "clipboard"], ["xsel", "--clipboard", "--input"], ["pbcopy"], ["clip.exe"]];
|
|
435
|
+
async function copyText(text, which = Bun.which) {
|
|
436
|
+
for (const [command, ...args] of CLIPBOARDS) {
|
|
437
|
+
const found = which(command);
|
|
438
|
+
if (found !== null && await pipeInto([found, ...args], text))
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
async function pipeInto(argv, text) {
|
|
444
|
+
try {
|
|
445
|
+
const copy = Bun.spawn(argv, { stdin: new Blob([text]), stdout: "ignore", stderr: "ignore" });
|
|
446
|
+
return await copy.exited === 0;
|
|
447
|
+
} catch {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
610
452
|
// ../kit/src/progress.ts
|
|
611
453
|
var ESC = String.fromCharCode(27);
|
|
612
454
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
@@ -615,13 +457,13 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
|
615
457
|
// ../kit/src/cli.ts
|
|
616
458
|
import { readFileSync, realpathSync } from "fs";
|
|
617
459
|
import { dirname as dirname2, join as join2 } from "path";
|
|
618
|
-
import
|
|
460
|
+
import process8 from "process";
|
|
619
461
|
|
|
620
462
|
// ../kit/src/usage.ts
|
|
621
463
|
import { appendFileSync, mkdirSync } from "fs";
|
|
622
464
|
import { homedir } from "os";
|
|
623
465
|
import { dirname, isAbsolute, join } from "path";
|
|
624
|
-
import
|
|
466
|
+
import process7 from "process";
|
|
625
467
|
|
|
626
468
|
// ../kit/src/logs.ts
|
|
627
469
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -635,14 +477,14 @@ var usageError;
|
|
|
635
477
|
function noteUsageError(message) {
|
|
636
478
|
usageError = message;
|
|
637
479
|
}
|
|
638
|
-
function stateHome(env =
|
|
480
|
+
function stateHome(env = process7.env) {
|
|
639
481
|
const dir = env.XDG_STATE_HOME;
|
|
640
482
|
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
641
483
|
}
|
|
642
|
-
function usagePath(env =
|
|
484
|
+
function usagePath(env = process7.env) {
|
|
643
485
|
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
644
486
|
}
|
|
645
|
-
function usageRecorded(env =
|
|
487
|
+
function usageRecorded(env = process7.env) {
|
|
646
488
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
647
489
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
648
490
|
}
|
|
@@ -656,7 +498,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
656
498
|
usageError = undefined;
|
|
657
499
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
658
500
|
}
|
|
659
|
-
function recordUsage(entry, env =
|
|
501
|
+
function recordUsage(entry, env = process7.env) {
|
|
660
502
|
if (!usageRecorded(env))
|
|
661
503
|
return;
|
|
662
504
|
try {
|
|
@@ -747,8 +589,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
747
589
|
`);
|
|
748
590
|
}
|
|
749
591
|
function printError(prefix, message, hint, cause) {
|
|
750
|
-
const colors = paint(
|
|
751
|
-
const styled = takesControlCodes(
|
|
592
|
+
const colors = paint(process8.stderr);
|
|
593
|
+
const styled = takesControlCodes(process8.stderr);
|
|
752
594
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
753
595
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
754
596
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -767,7 +609,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
767
609
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
768
610
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
769
611
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
770
|
-
if (error instanceof
|
|
612
|
+
if (error instanceof Exit && error.code === 2)
|
|
771
613
|
noteUsageError(error.message);
|
|
772
614
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
773
615
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
@@ -791,11 +633,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
791
633
|
}
|
|
792
634
|
}
|
|
793
635
|
if (name === undefined && level.path.length > 1) {
|
|
794
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
636
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process8.stderr));
|
|
795
637
|
return 2;
|
|
796
638
|
}
|
|
797
639
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
798
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
640
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process8.stdout));
|
|
799
641
|
return 0;
|
|
800
642
|
}
|
|
801
643
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -922,7 +764,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
922
764
|
return "0.0.0";
|
|
923
765
|
}
|
|
924
766
|
}
|
|
925
|
-
async function runCli(cli, argv =
|
|
767
|
+
async function runCli(cli, argv = process8.argv.slice(2)) {
|
|
926
768
|
const version = cli.version ?? packageVersion();
|
|
927
769
|
if (argv[0] === COMPLETE)
|
|
928
770
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -949,6 +791,8 @@ function commandPath(scope, argv) {
|
|
|
949
791
|
}
|
|
950
792
|
return path.length === 0 ? undefined : path.join(" ");
|
|
951
793
|
}
|
|
794
|
+
// ../kit/src/folders.ts
|
|
795
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
952
796
|
// ../kit/src/secrets.ts
|
|
953
797
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
954
798
|
// ../kit/src/sessions.ts
|
|
@@ -1197,21 +1041,15 @@ async function bytesInput(argument, what) {
|
|
|
1197
1041
|
return fail(`give ${what} as an argument or pipe it on stdin`, 2);
|
|
1198
1042
|
return new Uint8Array(await Bun.stdin.arrayBuffer());
|
|
1199
1043
|
}
|
|
1200
|
-
async function copyToClipboard(text) {
|
|
1201
|
-
if (Bun.which("wl-copy") === null)
|
|
1202
|
-
return false;
|
|
1203
|
-
const copy = Bun.spawn(["wl-copy"], { stdin: new Blob([text]), stdout: "ignore", stderr: "ignore" });
|
|
1204
|
-
return await copy.exited === 0;
|
|
1205
|
-
}
|
|
1206
1044
|
function printRows(rows) {
|
|
1207
|
-
const { cyan } = paint(
|
|
1045
|
+
const { cyan } = paint(process10.stdout);
|
|
1208
1046
|
const width = Math.max(...rows.map(([label]) => label.length));
|
|
1209
1047
|
for (const [label, value] of rows)
|
|
1210
1048
|
console.log(`${cyan(label.padEnd(width))} ${value}`);
|
|
1211
1049
|
}
|
|
1212
1050
|
var PASSWORD_USAGE = `dev password [length] [format] [-b|--bcrypt [password]]: a random password of <length> bytes (default ${DEFAULT_LENGTH}) as hex, base64 (default) or base64url
|
|
1213
1051
|
|
|
1214
|
-
Printed on stdout and copied to the clipboard
|
|
1052
|
+
Printed on stdout and copied to the clipboard when a tool for it (wl-copy, xclip, xsel, pbcopy) exists (the copy is said on stderr). With --bcrypt it is the bcrypt hash (cost 10) that prints: of the password given, or of a generated one, which then prints on stderr and is the one copied. Bun writes bcrypt as $2b$, the hash prints with the $2y$ prefix htpasswd -B writes, the one Apache, nginx and traefik basic auth all accept.
|
|
1215
1053
|
Exits 0 when it printed the password or hash, 2 on a usage error.`;
|
|
1216
1054
|
var PASSWORD_OPTIONS = {
|
|
1217
1055
|
bcrypt: { type: "string", short: "b", optional: { bare: "" }, description: "print the bcrypt hash of the password given, or of a generated one" },
|
|
@@ -1233,13 +1071,13 @@ async function password(args) {
|
|
|
1233
1071
|
const given = values.bcrypt === undefined || values.bcrypt === "" ? undefined : values.bcrypt;
|
|
1234
1072
|
const secret = given ?? generatePassword(bytes, format);
|
|
1235
1073
|
const hash = values.bcrypt === undefined ? undefined : await bcryptHash(secret);
|
|
1236
|
-
const copied = values["no-copy"] === true ? false : await
|
|
1074
|
+
const copied = values["no-copy"] === true ? false : await copyText(given === undefined ? secret : hash ?? secret);
|
|
1237
1075
|
if (values.json === true) {
|
|
1238
1076
|
printJson({ ...hash === undefined ? {} : { hash }, ...given === undefined ? { password: secret } : {}, format, bytes, copied });
|
|
1239
1077
|
return 0;
|
|
1240
1078
|
}
|
|
1241
1079
|
if (copied)
|
|
1242
|
-
console.error(paint(
|
|
1080
|
+
console.error(paint(process10.stderr).dim("copied to clipboard"));
|
|
1243
1081
|
if (hash !== undefined && given === undefined)
|
|
1244
1082
|
console.error(secret);
|
|
1245
1083
|
console.log(hash ?? secret);
|
|
@@ -1267,7 +1105,7 @@ async function jwt(args) {
|
|
|
1267
1105
|
printJson({ header: decoded.header, payload: decoded.payload, claims, signatureBytes: decoded.signatureBytes });
|
|
1268
1106
|
return 0;
|
|
1269
1107
|
}
|
|
1270
|
-
const { bold } = paint(
|
|
1108
|
+
const { bold } = paint(process10.stdout);
|
|
1271
1109
|
console.log(`${bold("header")}
|
|
1272
1110
|
${JSON.stringify(decoded.header, null, 2)}
|
|
1273
1111
|
|
|
@@ -1421,7 +1259,7 @@ async function hash(args) {
|
|
|
1421
1259
|
return 0;
|
|
1422
1260
|
}
|
|
1423
1261
|
if (import.meta.main) {
|
|
1424
|
-
|
|
1262
|
+
process10.exitCode = await runCli({
|
|
1425
1263
|
name: "dev",
|
|
1426
1264
|
about: "small developer utilities: passwords and bcrypt hashes, JWTs, timestamps, UUIDs, base64, URLs and file hashes",
|
|
1427
1265
|
replaces: "openssl rand, htpasswd, jwt.io, date -d, uuidgen, base64, sha256sum and one-off scripts for each",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-dev",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"description": "dev: small developer utilities in one bin: random passwords and bcrypt hashes, JWT decoding, timestamps, UUIDs and ULIDs, base64, URL parts and file hashes.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"dev": "$npm_execpath src/cli.ts"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@kaynooo/cli-kit": "0.
|
|
39
|
+
"@kaynooo/cli-kit": "0.35.0"
|
|
40
40
|
}
|
|
41
41
|
}
|