@kaynooo/cli-guard 0.10.0 → 0.11.1
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 +203 -332
- package/package.json +8 -8
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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 { appendFileSync as appendFileSync2, existsSync as
|
|
6
|
-
import { homedir as
|
|
5
|
+
import { appendFileSync as appendFileSync2, existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync5, rmSync, statSync, writeFileSync } from "fs";
|
|
6
|
+
import { homedir as homedir3 } from "os";
|
|
7
7
|
import { dirname as dirname4 } from "path";
|
|
8
|
-
import
|
|
8
|
+
import process14 from "process";
|
|
9
9
|
// ../kit/src/args.ts
|
|
10
|
-
import
|
|
10
|
+
import process7 from "process";
|
|
11
11
|
import { parseArgs } from "util";
|
|
12
12
|
|
|
13
13
|
// ../kit/src/mode.ts
|
|
@@ -29,280 +29,110 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// ../kit/src/style.ts
|
|
32
|
-
import
|
|
32
|
+
import process4 from "process";
|
|
33
33
|
|
|
34
|
-
// ../../node_modules/.bun/@kaynooo+utils@
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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))
|
|
38
39
|
return [0, 0, 0];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
83
|
-
let n = (a) => {
|
|
84
|
-
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
85
|
-
return Math.round(255 * o);
|
|
86
|
-
};
|
|
87
|
-
return [n(5), n(3), n(1)];
|
|
88
|
-
}
|
|
89
|
-
function f(s) {
|
|
90
|
-
let [r, t, n] = s;
|
|
91
|
-
r /= 255, t /= 255, n /= 255;
|
|
92
|
-
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;
|
|
93
|
-
if (o !== 0) {
|
|
94
|
-
if (a === r)
|
|
95
|
-
y = (t - n) / o + (t < n ? 6 : 0);
|
|
96
|
-
else if (a === t)
|
|
97
|
-
y = (n - r) / o + 2;
|
|
98
|
-
else
|
|
99
|
-
y = (r - t) / o + 4;
|
|
100
|
-
y /= 6;
|
|
101
|
-
}
|
|
102
|
-
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
103
|
-
}
|
|
104
|
-
function O(s) {
|
|
105
|
-
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
106
|
-
if (a === 1)
|
|
107
|
-
return [0, 0, 0, 100];
|
|
108
|
-
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
109
|
-
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
110
|
-
}
|
|
111
|
-
function v(s, r, t, n) {
|
|
112
|
-
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))];
|
|
113
|
-
}
|
|
114
|
-
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
115
|
-
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
116
|
-
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
117
|
-
function T(s) {
|
|
118
|
-
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);
|
|
119
|
-
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)];
|
|
120
|
-
}
|
|
121
|
-
function M(s, r, t) {
|
|
122
|
-
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)));
|
|
123
|
-
return [u(o), u(y), u(c)];
|
|
124
|
-
}
|
|
125
|
-
function d(s) {
|
|
126
|
-
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
127
|
-
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
128
|
-
}
|
|
129
|
-
function C(s, r, t) {
|
|
130
|
-
let n = t * Math.PI / 180;
|
|
131
|
-
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
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")
|
|
55
|
+
return false;
|
|
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)}`);
|
|
82
|
+
} });
|
|
132
83
|
}
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
84
|
+
function Fe(r = {}) {
|
|
85
|
+
return f(r);
|
|
136
86
|
}
|
|
87
|
+
var o = Fe();
|
|
137
88
|
|
|
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
|
-
return new e(o, y, c, b);
|
|
167
|
-
}
|
|
168
|
-
if (s === "hsv") {
|
|
169
|
-
let t, n, a, b;
|
|
170
|
-
if (Array.isArray(r))
|
|
171
|
-
[t, n, a, b] = r;
|
|
172
|
-
else
|
|
173
|
-
({ h: t, s: n, v: a, a: b } = r);
|
|
174
|
-
let [o, y, c] = H(t, n, a);
|
|
175
|
-
return new e(o, y, c, b);
|
|
176
|
-
}
|
|
177
|
-
if (s === "cmyk") {
|
|
178
|
-
let t, n, a, b, o;
|
|
179
|
-
if (Array.isArray(r))
|
|
180
|
-
[t, n, a, b, o] = r;
|
|
181
|
-
else
|
|
182
|
-
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
183
|
-
let [y, c, u] = v(t, n, a, b);
|
|
184
|
-
return new e(y, c, u, o);
|
|
185
|
-
}
|
|
186
|
-
if (s === "oklch") {
|
|
187
|
-
let t, n, a, b;
|
|
188
|
-
if (Array.isArray(r))
|
|
189
|
-
[t, n, a, b] = r;
|
|
190
|
-
else
|
|
191
|
-
({ l: t, c: n, h: a, a: b } = r);
|
|
192
|
-
let [o, y, c] = C(t, n, a);
|
|
193
|
-
return new e(o, y, c, b);
|
|
194
|
-
}
|
|
195
|
-
if (s === "oklab") {
|
|
196
|
-
let t, n, a, b;
|
|
197
|
-
if (Array.isArray(r))
|
|
198
|
-
[t, n, a, b] = r;
|
|
199
|
-
else
|
|
200
|
-
({ l: t, a: n, b: a, alpha: b } = r);
|
|
201
|
-
let [o, y, c] = M(t, n, a);
|
|
202
|
-
return new e(o, y, c, b);
|
|
203
|
-
}
|
|
204
|
-
throw Error("Invalid input");
|
|
205
|
-
}
|
|
206
|
-
to(s) {
|
|
207
|
-
switch (s) {
|
|
208
|
-
case "rgb":
|
|
209
|
-
return [this.r, this.g, this.b];
|
|
210
|
-
case "rgba":
|
|
211
|
-
return [this.r, this.g, this.b, this.a];
|
|
212
|
-
case "hex":
|
|
213
|
-
return A([this.r, this.g, this.b]);
|
|
214
|
-
case "hexa":
|
|
215
|
-
return A([this.r, this.g, this.b, this.a]);
|
|
216
|
-
case "hsl":
|
|
217
|
-
return k([this.r, this.g, this.b]);
|
|
218
|
-
case "hsla":
|
|
219
|
-
return [...k([this.r, this.g, this.b]), this.a];
|
|
220
|
-
case "hsv":
|
|
221
|
-
return f([this.r, this.g, this.b]);
|
|
222
|
-
case "hsva":
|
|
223
|
-
return [...f([this.r, this.g, this.b]), this.a];
|
|
224
|
-
case "cmyk":
|
|
225
|
-
return O([this.r, this.g, this.b]);
|
|
226
|
-
case "cmyka":
|
|
227
|
-
return [...O([this.r, this.g, this.b]), this.a];
|
|
228
|
-
case "oklch":
|
|
229
|
-
return d([this.r, this.g, this.b]);
|
|
230
|
-
case "oklcha":
|
|
231
|
-
return [...d([this.r, this.g, this.b]), this.a];
|
|
232
|
-
case "oklab":
|
|
233
|
-
return T([this.r, this.g, this.b]);
|
|
234
|
-
case "oklaba":
|
|
235
|
-
return [...T([this.r, this.g, this.b]), this.a];
|
|
236
|
-
default:
|
|
237
|
-
return [this.r, this.g, this.b];
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
getLuminance() {
|
|
241
|
-
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
242
|
-
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
243
|
-
}
|
|
244
|
-
contrastRatio(s) {
|
|
245
|
-
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
246
|
-
return (n + 0.05) / (a + 0.05);
|
|
247
|
-
}
|
|
248
|
-
bestContrastForeground() {
|
|
249
|
-
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
250
|
-
return t >= n ? s : r;
|
|
89
|
+
// ../kit/src/user-config.ts
|
|
90
|
+
import { existsSync, readFileSync } from "fs";
|
|
91
|
+
import { homedir } from "os";
|
|
92
|
+
import { join } from "path";
|
|
93
|
+
import process3 from "process";
|
|
94
|
+
function configBase(where = {}) {
|
|
95
|
+
const xdg = where.xdg ?? (where.home === undefined ? process3.env.XDG_CONFIG_HOME : undefined);
|
|
96
|
+
return xdg !== undefined && xdg !== "" ? xdg : join(where.home ?? homedir(), ".config");
|
|
97
|
+
}
|
|
98
|
+
function userConfigPath(bin, where = {}) {
|
|
99
|
+
return join(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
100
|
+
}
|
|
101
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
102
|
+
const current = userConfigPath(bin, where);
|
|
103
|
+
if (existsSync(current))
|
|
104
|
+
return current;
|
|
105
|
+
const base = configBase(where);
|
|
106
|
+
return legacy.map((parts) => join(base, ...parts)).find((path) => existsSync(path)) ?? current;
|
|
107
|
+
}
|
|
108
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
109
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
110
|
+
if (!existsSync(path))
|
|
111
|
+
return {};
|
|
112
|
+
try {
|
|
113
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
114
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
115
|
+
} catch {
|
|
116
|
+
return {};
|
|
251
117
|
}
|
|
252
118
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
var o = 49;
|
|
257
|
-
var f2 = "\x1B[";
|
|
258
|
-
var C2 = { 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, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
|
|
259
|
-
let [a, l, s] = e.from("hex", i).to("rgb");
|
|
260
|
-
return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
|
|
261
|
-
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
262
|
-
var b = new Set(["", "1", "2", "3", "true"]);
|
|
263
|
-
function h(i, n = globalThis.process?.env ?? {}) {
|
|
264
|
-
if (n.FORCE_COLOR !== undefined)
|
|
265
|
-
return b.has(n.FORCE_COLOR);
|
|
266
|
-
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
267
|
-
return false;
|
|
268
|
-
return i?.isTTY === true;
|
|
269
|
-
}
|
|
270
|
-
function d2(i, n, a) {
|
|
271
|
-
if (!h(a.stream ?? globalThis.process?.stdout, a.env))
|
|
272
|
-
return n;
|
|
273
|
-
let l = "", s = "";
|
|
274
|
-
for (let g = 0, y = i.length;g < y; g++) {
|
|
275
|
-
let [c, p] = i[g];
|
|
276
|
-
l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
|
|
277
|
-
}
|
|
278
|
-
return l + n + s;
|
|
279
|
-
}
|
|
280
|
-
function u(i, n = []) {
|
|
281
|
-
return new Proxy((l) => d2(n, l, i), { get(l, s) {
|
|
282
|
-
let g = C2[s];
|
|
283
|
-
if (Array.isArray(g))
|
|
284
|
-
return u(i, [...n, g]);
|
|
285
|
-
if (typeof g === "function")
|
|
286
|
-
return (...y) => u(i, [...n, g(...y)]);
|
|
287
|
-
throw Error(`Unknown style: ${String(s)}`);
|
|
288
|
-
} });
|
|
289
|
-
}
|
|
290
|
-
function le(i = {}) {
|
|
291
|
-
return u(i);
|
|
119
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
120
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
121
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
292
122
|
}
|
|
293
|
-
var t = le();
|
|
294
123
|
|
|
295
124
|
// ../kit/src/theme.ts
|
|
125
|
+
var ENDS = new Map;
|
|
296
126
|
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"]);
|
|
297
127
|
var MAX_FILE_BYTES = 64 * 1024;
|
|
298
128
|
var warned = new Set;
|
|
299
129
|
|
|
300
130
|
// ../kit/src/style.ts
|
|
301
|
-
function takesControlCodes(stream, env =
|
|
131
|
+
function takesControlCodes(stream, env = process4.env) {
|
|
302
132
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
303
133
|
}
|
|
304
|
-
function paint(stream, env =
|
|
305
|
-
return
|
|
134
|
+
function paint(stream, env = process4.env) {
|
|
135
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
306
136
|
}
|
|
307
137
|
var STATUS_WORDS = {
|
|
308
138
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
@@ -321,27 +151,27 @@ function upTo(text, separator) {
|
|
|
321
151
|
var ESCAPE = String.fromCharCode(27);
|
|
322
152
|
|
|
323
153
|
// ../kit/src/help.ts
|
|
324
|
-
import
|
|
154
|
+
import process5 from "process";
|
|
325
155
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
326
156
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
327
157
|
var FULL_STOP = /\.$/;
|
|
328
|
-
function usageLine(usage, colors = paint(
|
|
158
|
+
function usageLine(usage, colors = paint(process5.stdout)) {
|
|
329
159
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
330
160
|
}
|
|
331
|
-
function helpText(usage, options, colors = paint(
|
|
161
|
+
function helpText(usage, options, colors = paint(process5.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
332
162
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
333
163
|
`);
|
|
334
164
|
}
|
|
335
|
-
function exitRows(exits, colors = paint(
|
|
165
|
+
function exitRows(exits, colors = paint(process5.stdout)) {
|
|
336
166
|
if (exits.length === 0)
|
|
337
167
|
return [];
|
|
338
168
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
339
169
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
340
170
|
}
|
|
341
|
-
function replacesRows(replaces, colors = paint(
|
|
171
|
+
function replacesRows(replaces, colors = paint(process5.stdout)) {
|
|
342
172
|
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
343
173
|
}
|
|
344
|
-
function wantsHelpJson(env =
|
|
174
|
+
function wantsHelpJson(env = process5.env) {
|
|
345
175
|
return env.KIT_HELP === "json";
|
|
346
176
|
}
|
|
347
177
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -360,12 +190,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
360
190
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
361
191
|
};
|
|
362
192
|
}
|
|
363
|
-
function exampleRows(examples, colors = paint(
|
|
193
|
+
function exampleRows(examples, colors = paint(process5.stdout)) {
|
|
364
194
|
if (examples.length === 0 || outputMode() === "agent")
|
|
365
195
|
return [];
|
|
366
196
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
367
197
|
}
|
|
368
|
-
function optionRows(options, colors = paint(
|
|
198
|
+
function optionRows(options, colors = paint(process5.stdout)) {
|
|
369
199
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
370
200
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
371
201
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -397,10 +227,10 @@ function closest(name, names) {
|
|
|
397
227
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
398
228
|
}
|
|
399
229
|
// ../kit/src/input.ts
|
|
400
|
-
import
|
|
230
|
+
import process6 from "process";
|
|
401
231
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
402
232
|
if (path === "-") {
|
|
403
|
-
if (
|
|
233
|
+
if (process6.stdin.isTTY)
|
|
404
234
|
fail(noStdin);
|
|
405
235
|
return Bun.stdin.text();
|
|
406
236
|
}
|
|
@@ -415,7 +245,6 @@ var DASHES = /^-+/;
|
|
|
415
245
|
function jsonOption(holds) {
|
|
416
246
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
417
247
|
}
|
|
418
|
-
|
|
419
248
|
class Exit extends Error {
|
|
420
249
|
code;
|
|
421
250
|
hint;
|
|
@@ -459,7 +288,7 @@ var OUTPUT_OPTIONS = {
|
|
|
459
288
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
460
289
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
461
290
|
};
|
|
462
|
-
function applyOutput(color, plain, env =
|
|
291
|
+
function applyOutput(color, plain, env = process7.env) {
|
|
463
292
|
const when = plain === true ? "never" : color ?? "auto";
|
|
464
293
|
if (when === "auto")
|
|
465
294
|
return;
|
|
@@ -628,9 +457,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
628
457
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
629
458
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
630
459
|
}
|
|
460
|
+
// ../kit/src/argv.ts
|
|
461
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
462
|
+
import { resolve } from "path";
|
|
463
|
+
import process8 from "process";
|
|
464
|
+
function commandLine() {
|
|
465
|
+
try {
|
|
466
|
+
return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
467
|
+
} catch {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
function realPath(word) {
|
|
472
|
+
try {
|
|
473
|
+
return realpathSync(resolve(word));
|
|
474
|
+
} catch {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function scriptArgs(argv = process8.argv.slice(2), cmdline = commandLine(), script = process8.argv[1]) {
|
|
479
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
480
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve(word) === script || realPath(word) === target));
|
|
481
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
482
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
483
|
+
}
|
|
631
484
|
// ../kit/src/process.ts
|
|
632
485
|
import { constants } from "os";
|
|
633
|
-
import
|
|
486
|
+
import process9 from "process";
|
|
634
487
|
var KILL_GRACE_MS = 2000;
|
|
635
488
|
function exitCodeOf(code, signal) {
|
|
636
489
|
if (code !== null)
|
|
@@ -650,7 +503,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
650
503
|
return;
|
|
651
504
|
try {
|
|
652
505
|
if (grouped)
|
|
653
|
-
|
|
506
|
+
process9.kill(-proc.pid, killing);
|
|
654
507
|
else
|
|
655
508
|
proc.kill(killing);
|
|
656
509
|
} catch {}
|
|
@@ -724,15 +577,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
724
577
|
var RESET_STYLE = `${ESC}[0m`;
|
|
725
578
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
726
579
|
// ../kit/src/cli.ts
|
|
727
|
-
import { readFileSync, realpathSync } from "fs";
|
|
728
|
-
import { dirname as dirname2, join as
|
|
729
|
-
import
|
|
580
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
581
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
582
|
+
import process11 from "process";
|
|
730
583
|
|
|
731
584
|
// ../kit/src/usage.ts
|
|
732
585
|
import { appendFileSync, mkdirSync } from "fs";
|
|
733
|
-
import { homedir } from "os";
|
|
734
|
-
import { dirname, isAbsolute, join } from "path";
|
|
735
|
-
import
|
|
586
|
+
import { homedir as homedir2 } from "os";
|
|
587
|
+
import { dirname, isAbsolute, join as join2 } from "path";
|
|
588
|
+
import process10 from "process";
|
|
736
589
|
|
|
737
590
|
// ../kit/src/logs.ts
|
|
738
591
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -746,14 +599,14 @@ var usageError;
|
|
|
746
599
|
function noteUsageError(message) {
|
|
747
600
|
usageError = message;
|
|
748
601
|
}
|
|
749
|
-
function stateHome(env =
|
|
602
|
+
function stateHome(env = process10.env) {
|
|
750
603
|
const dir = env.XDG_STATE_HOME;
|
|
751
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
604
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
|
|
752
605
|
}
|
|
753
|
-
function usagePath(env =
|
|
754
|
-
return
|
|
606
|
+
function usagePath(env = process10.env) {
|
|
607
|
+
return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
755
608
|
}
|
|
756
|
-
function usageRecorded(env =
|
|
609
|
+
function usageRecorded(env = process10.env) {
|
|
757
610
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
758
611
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
759
612
|
}
|
|
@@ -767,7 +620,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
767
620
|
usageError = undefined;
|
|
768
621
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
769
622
|
}
|
|
770
|
-
function recordUsage(entry, env =
|
|
623
|
+
function recordUsage(entry, env = process10.env) {
|
|
771
624
|
if (!usageRecorded(env))
|
|
772
625
|
return;
|
|
773
626
|
try {
|
|
@@ -858,8 +711,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
858
711
|
`);
|
|
859
712
|
}
|
|
860
713
|
function printError(prefix, message, hint, cause) {
|
|
861
|
-
const colors = paint(
|
|
862
|
-
const styled = takesControlCodes(
|
|
714
|
+
const colors = paint(process11.stderr);
|
|
715
|
+
const styled = takesControlCodes(process11.stderr);
|
|
863
716
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
864
717
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
865
718
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -902,11 +755,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
902
755
|
}
|
|
903
756
|
}
|
|
904
757
|
if (name === undefined && level.path.length > 1) {
|
|
905
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
758
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stderr));
|
|
906
759
|
return 2;
|
|
907
760
|
}
|
|
908
761
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
909
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
762
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stdout));
|
|
910
763
|
return 0;
|
|
911
764
|
}
|
|
912
765
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -962,24 +815,24 @@ function candidateLine(candidate) {
|
|
|
962
815
|
}
|
|
963
816
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
964
817
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
965
|
-
|
|
818
|
+
const typed = [];
|
|
966
819
|
let at = 0;
|
|
967
820
|
while (at < before.length) {
|
|
968
821
|
const word = before[at];
|
|
969
822
|
if (word === "--") {
|
|
970
|
-
|
|
823
|
+
typed.push(...before.slice(at + 1));
|
|
971
824
|
break;
|
|
972
825
|
}
|
|
973
826
|
if (!word.startsWith("-"))
|
|
974
|
-
|
|
827
|
+
typed.push(word);
|
|
975
828
|
else if (takesValue(word))
|
|
976
829
|
at++;
|
|
977
830
|
at++;
|
|
978
831
|
}
|
|
979
832
|
const last = positionals.at(-1);
|
|
980
|
-
if (
|
|
981
|
-
return positionals[
|
|
982
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
833
|
+
if (typed.length < positionals.length)
|
|
834
|
+
return { name: positionals[typed.length], typed };
|
|
835
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
983
836
|
}
|
|
984
837
|
async function leafCandidates(run, words) {
|
|
985
838
|
const completing = await completingOf(run);
|
|
@@ -987,12 +840,12 @@ async function leafCandidates(run, words) {
|
|
|
987
840
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
988
841
|
const flag = words.at(-2);
|
|
989
842
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
843
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
990
844
|
if (option?.type === "string") {
|
|
991
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
845
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
992
846
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
993
847
|
}
|
|
994
|
-
const
|
|
995
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
848
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
996
849
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
997
850
|
}
|
|
998
851
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1023,9 +876,9 @@ async function printCandidates(found) {
|
|
|
1023
876
|
return 0;
|
|
1024
877
|
}
|
|
1025
878
|
function packageVersion(entry = Bun.main) {
|
|
1026
|
-
for (let dir = dirname2(
|
|
879
|
+
for (let dir = dirname2(realpathSync2(entry));; dir = dirname2(dir)) {
|
|
1027
880
|
try {
|
|
1028
|
-
const { version } = JSON.parse(
|
|
881
|
+
const { version } = JSON.parse(readFileSync3(join3(dir, "package.json"), "utf8"));
|
|
1029
882
|
if (typeof version === "string")
|
|
1030
883
|
return version;
|
|
1031
884
|
} catch {}
|
|
@@ -1033,7 +886,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1033
886
|
return "0.0.0";
|
|
1034
887
|
}
|
|
1035
888
|
}
|
|
1036
|
-
async function runCli(cli, argv =
|
|
889
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1037
890
|
const version = cli.version ?? packageVersion();
|
|
1038
891
|
if (argv[0] === COMPLETE)
|
|
1039
892
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1060,6 +913,13 @@ function commandPath(scope, argv) {
|
|
|
1060
913
|
}
|
|
1061
914
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1062
915
|
}
|
|
916
|
+
// ../kit/src/folders.ts
|
|
917
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
918
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
919
|
+
const configured = readUserConfig("config", where).ignore;
|
|
920
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
921
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
922
|
+
}
|
|
1063
923
|
// ../kit/src/secrets.ts
|
|
1064
924
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1065
925
|
// ../kit/src/sessions.ts
|
|
@@ -2127,7 +1987,7 @@ function printsTrackedEnv(program, args) {
|
|
|
2127
1987
|
// ../env/src/files.ts
|
|
2128
1988
|
var ENV_FILE = /^(?:\.env(?:\..+)?|.+\.env|\.envrc)$/;
|
|
2129
1989
|
var TEMPLATE = /\.(?:example|sample|template|dist|defaults)$/;
|
|
2130
|
-
var SKIPPED =
|
|
1990
|
+
var SKIPPED = ignoredFolders([".git", ".kay"]);
|
|
2131
1991
|
|
|
2132
1992
|
// ../env/src/guard-paths.ts
|
|
2133
1993
|
var REDIRECT = /^\d*[<>]+&?/;
|
|
@@ -2498,7 +2358,10 @@ function commitMessageViolation(message) {
|
|
|
2498
2358
|
}
|
|
2499
2359
|
|
|
2500
2360
|
// ../out/src/fold.ts
|
|
2501
|
-
var FOLD_LINES = 150;
|
|
2361
|
+
var FOLD_LINES = configuredNumber("out", "lines", 150);
|
|
2362
|
+
var HEAD = configuredNumber("out", "head", 40);
|
|
2363
|
+
var TAIL = configuredNumber("out", "tail", 60);
|
|
2364
|
+
var MAX_WIDTH = configuredNumber("out", "width", 300);
|
|
2502
2365
|
|
|
2503
2366
|
// ../out/src/wrap.ts
|
|
2504
2367
|
var ASSIGNMENT4 = /^\w+=/;
|
|
@@ -2629,9 +2492,9 @@ function wrap(command) {
|
|
|
2629
2492
|
}
|
|
2630
2493
|
|
|
2631
2494
|
// ../pkg/src/added.ts
|
|
2632
|
-
import { existsSync, readdirSync, readFileSync as
|
|
2633
|
-
import { dirname as dirname3, join as
|
|
2634
|
-
import
|
|
2495
|
+
import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync4 } from "fs";
|
|
2496
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
2497
|
+
import process13 from "process";
|
|
2635
2498
|
var REDIRECT2 = /^\d*[<>]/;
|
|
2636
2499
|
var BARE_REDIRECT = /^\d*(?:[<>]|>>)$/;
|
|
2637
2500
|
var ADDS = {
|
|
@@ -2655,7 +2518,7 @@ var PUBLISH = /\b(?:ft|cli\.ts)\s+release\b|\b(?:bun|npm|pnpm|yarn)\s+publish\b|
|
|
|
2655
2518
|
var EXACT_SPEC = /^(?:@[^/]+\/)?[^@]+@\d+\.\d+\.\d+(?:[-+][\w.+-]+)?$/;
|
|
2656
2519
|
function manifestName(folder) {
|
|
2657
2520
|
try {
|
|
2658
|
-
const { name } = JSON.parse(
|
|
2521
|
+
const { name } = JSON.parse(readFileSync4(join4(folder, "package.json"), "utf8"));
|
|
2659
2522
|
return typeof name === "string" ? name : undefined;
|
|
2660
2523
|
} catch {
|
|
2661
2524
|
return;
|
|
@@ -2663,17 +2526,17 @@ function manifestName(folder) {
|
|
|
2663
2526
|
}
|
|
2664
2527
|
function ownPackages() {
|
|
2665
2528
|
const names = new Set;
|
|
2666
|
-
let folder =
|
|
2529
|
+
let folder = process13.cwd();
|
|
2667
2530
|
while (true) {
|
|
2668
2531
|
const name = manifestName(folder);
|
|
2669
2532
|
if (name !== undefined)
|
|
2670
2533
|
names.add(name);
|
|
2671
|
-
for (const member of
|
|
2672
|
-
const memberName = manifestName(
|
|
2534
|
+
for (const member of existsSync2(join4(folder, "packages")) ? readdirSync(join4(folder, "packages")) : []) {
|
|
2535
|
+
const memberName = manifestName(join4(folder, "packages", member));
|
|
2673
2536
|
if (memberName !== undefined)
|
|
2674
2537
|
names.add(memberName);
|
|
2675
2538
|
}
|
|
2676
|
-
if (
|
|
2539
|
+
if (existsSync2(join4(folder, ".git")) || dirname3(folder) === folder)
|
|
2677
2540
|
return names;
|
|
2678
2541
|
folder = dirname3(folder);
|
|
2679
2542
|
}
|
|
@@ -2864,9 +2727,14 @@ var STAGE_BY_PATH = `Stage by path: the tree carries unrelated work and peer ses
|
|
|
2864
2727
|
var STASH = "Never `git stash`: a pop with nothing saved applies someone else's old stash. To prove a test fails without your change, `proof --keep <test> -- <cmd>` runs it at HEAD in a temporary worktree and again here; `base -- <cmd>` runs any command at HEAD (`--ref <rev>` another commit), the working tree untouched. To set edits aside before a cherry-pick, a rebase or a checkout, commit them with `gc` first, or do the other work in `git worktree add`.";
|
|
2865
2728
|
var ADD_ALL = `\`git add\` over the whole tree is refused. ${STAGE_BY_PATH}`;
|
|
2866
2729
|
var COMMIT_ALL = `\`git commit -a\` stages the whole tree and is refused. ${STAGE_BY_PATH}`;
|
|
2867
|
-
var PUSH = "`git push`
|
|
2730
|
+
var PUSH = "`git push` and `gp` run only when the user asked for a push in their latest prompt: say the commit is ready and let them ask.";
|
|
2868
2731
|
var CONFIG_OVERRIDE = "Never set git config that runs a program or defines a command (`-c alias.*`, `--config-env`, `core.sshCommand`, `core.hooksPath`, `core.pager`, credential helpers, `git config alias.*`): it sidesteps every rule here. Run the git command itself.";
|
|
2869
2732
|
var TAGS_APART = "A tag goes out with its branch in one `git push --atomic origin <branch> <tag>`, never a separate `git push --tags`.";
|
|
2733
|
+
function gitCommandOf(program, args) {
|
|
2734
|
+
if (program === "gp")
|
|
2735
|
+
return { name: "push", rest: args.includes("--") ? args.slice(args.indexOf("--") + 1) : [] };
|
|
2736
|
+
return program === "git" ? subcommandOf(args) : undefined;
|
|
2737
|
+
}
|
|
2870
2738
|
function subcommandOf(args) {
|
|
2871
2739
|
for (let i = 0;i < args.length; i++) {
|
|
2872
2740
|
const arg = args[i] ?? "";
|
|
@@ -2936,11 +2804,12 @@ function gitViolation(command, isPushAsked = false) {
|
|
|
2936
2804
|
const { program, args, assignments } = parseCommand(piece.command);
|
|
2937
2805
|
if (assignments.some((assignment) => RISKY_ENV.test(assignment)))
|
|
2938
2806
|
return CONFIG_OVERRIDE;
|
|
2939
|
-
|
|
2807
|
+
const git = gitCommandOf(program, args);
|
|
2808
|
+
if (git === undefined)
|
|
2940
2809
|
continue;
|
|
2941
|
-
if (overridesConfig(args))
|
|
2810
|
+
if (program === "git" && overridesConfig(args))
|
|
2942
2811
|
return CONFIG_OVERRIDE;
|
|
2943
|
-
const { name, rest } =
|
|
2812
|
+
const { name, rest } = git;
|
|
2944
2813
|
if (name === "config" && rest.length > 1 && rest.some((arg) => RISKY_CONFIG.test(arg)) && !rest.some((arg) => READS_CONFIG.has(arg)))
|
|
2945
2814
|
return CONFIG_OVERRIDE;
|
|
2946
2815
|
if (name === "stash" && !READ_ONLY_STASH.has(rest[0] ?? ""))
|
|
@@ -3224,10 +3093,10 @@ function destructiveViolation(command) {
|
|
|
3224
3093
|
const { program, args } = parseCommand(piece.command);
|
|
3225
3094
|
if (program === "rm" && removesBroadly(args))
|
|
3226
3095
|
return BROAD_RM;
|
|
3227
|
-
|
|
3096
|
+
const git = gitCommandOf(program, args);
|
|
3097
|
+
if (git === undefined)
|
|
3228
3098
|
continue;
|
|
3229
|
-
const
|
|
3230
|
-
const violation = gitDestructive(name, rest);
|
|
3099
|
+
const violation = gitDestructive(git.name, git.rest);
|
|
3231
3100
|
if (violation !== null)
|
|
3232
3101
|
return violation;
|
|
3233
3102
|
}
|
|
@@ -3777,8 +3646,10 @@ var BINS = {
|
|
|
3777
3646
|
sub: "`sub --from <text> --to <text> <file>...`: replaces text, writing nothing unless each match count is as expected (1, `-n N`, `--all`), `--regex`, `--dry-run --diff`; multi-line text goes as SEARCH/REPLACE blocks on stdin from a quoted heredoc (`sub <file> <<'EOF'`, see `sub --help`), no escaping; use it instead of sed -i, a bun -e or python editor.",
|
|
3778
3647
|
base: "`base [--ref <rev>] [--keep <path>...] -- <cmd>`: runs a command at HEAD (or a ref) in a temporary worktree, removed afterwards, ignored env files and node_modules/vendor linked; use it instead of git stash to see whether a test fails without your change (`--keep` the new test).",
|
|
3779
3648
|
proof: "`proof [--ref <rev>] [--keep <path>...] -- <cmd>`: runs the command at HEAD (or a ref) in a temporary worktree, then in the working tree, and exits 0 only when it fails before and passes now, printing the failing side's output; use it to prove a new test fails without your change (`--keep` the test).",
|
|
3780
|
-
gst: "`gst [--log N]`: branch, upstream, changed counts and HEAD in one line, then the changed paths by staged, unstaged and untracked; use it instead of `git status --short` and `git log --oneline`.",
|
|
3649
|
+
gst: "`gst [--log N]`: branch, upstream, changed counts and HEAD in one line, then the changed paths by staged, unstaged and untracked, `gst --repos` one line per repository nested below; use it instead of `git status --short` and `git log --oneline`.",
|
|
3781
3650
|
gc: "`gc <title> [-m <line>]... [--ticket <line>]... -- <path>...`: commits exactly those paths, refusing with nothing staged when the message breaks a commit rule, a path has no change or other files are already staged; use it instead of chaining git add, status and commit.",
|
|
3651
|
+
gp: "`gp [--repos] [dir]...`: pushes the current branch when it is ahead of its upstream, with `-u` to origin when it has none, `--repos` every repository nested below too, `--dry-run` saying what would go, flags for git push after `--`; only when the user asked for a push, like `git push`.",
|
|
3652
|
+
gb: "`gb [branch]`: switches to a branch, a remote one getting its tracking branch, `gb -c <name>` creating one; without a terminal it lists the branches (`--json`), with how each stands against its upstream and whether it is merged.",
|
|
3782
3653
|
waitfor: "`waitfor --file <log> --until <regex> [--fail <regex>]`, `--port <n>`, `--url <url>`, `--pid <n>` (`-t 5m`): waits until the line shows, the port listens, the URL answers 2xx or the process exits, exits 1 on a --fail line with the lines around it, 2 on a timeout with the last lines; `waitfor task <id>` waits for a background Bash task and prints its exit code, last lines and failure lines; use it instead of sleep and tail, `until ! pgrep -f` or polling loops.",
|
|
3783
3654
|
slot: "`slot [-l <lock>] -- <cmd>`: waits for one of the machine-wide slots shared by every session (half the CPUs), then runs the command; `--lock <name>` also holds a named lock for what must not run twice (a shared test database), `slot ls` lists holders and waiters; run heavy jobs (phpunit, playwright, vue-tsc, a full test suite) through it instead of a flock wrapper.",
|
|
3784
3655
|
gl: "`gl ci [ref]` waits for the GitLab pipeline covering a commit and prints each failed job's tests (exit 0/1/2), `gl runs`, `gl logs <pipeline> [-j job] [--full]`; use it instead of `glab ci` or `glab api .../pipelines/<id>/jobs` polled in a sleep loop.",
|
|
@@ -3936,12 +3807,12 @@ var MAX_READ = 1e6;
|
|
|
3936
3807
|
function readText(path) {
|
|
3937
3808
|
try {
|
|
3938
3809
|
const stats = statSync(path, { throwIfNoEntry: false });
|
|
3939
|
-
return stats?.isFile() === true && stats.size <= MAX_READ ?
|
|
3810
|
+
return stats?.isFile() === true && stats.size <= MAX_READ ? readFileSync5(path, "utf8") : null;
|
|
3940
3811
|
} catch {
|
|
3941
3812
|
return null;
|
|
3942
3813
|
}
|
|
3943
3814
|
}
|
|
3944
|
-
function
|
|
3815
|
+
function report2(violations) {
|
|
3945
3816
|
for (const { rule, message } of violations)
|
|
3946
3817
|
console.log(`${rule}: ${message}`);
|
|
3947
3818
|
}
|
|
@@ -3955,20 +3826,20 @@ ${checkUsage}`);
|
|
|
3955
3826
|
const given = positionals[0] ?? "-";
|
|
3956
3827
|
const command = given === "-" ? await readInput("-", { noStdin: "give the command, or pipe it on stdin" }) : given;
|
|
3957
3828
|
const context = {
|
|
3958
|
-
cwd: values.cwd ??
|
|
3959
|
-
home:
|
|
3829
|
+
cwd: values.cwd ?? process14.cwd(),
|
|
3830
|
+
home: homedir3(),
|
|
3960
3831
|
isPushAsked: values["push-asked"] === true,
|
|
3961
3832
|
canRewrite: true,
|
|
3962
3833
|
canWrap: values["no-wrap"] !== true && Bun.which("out") !== null,
|
|
3963
3834
|
canSub: Bun.which("sub") !== null,
|
|
3964
3835
|
read: readText,
|
|
3965
|
-
exists:
|
|
3836
|
+
exists: existsSync3
|
|
3966
3837
|
};
|
|
3967
3838
|
const verdict = await checkCommand(command, context);
|
|
3968
3839
|
if (values.json === true)
|
|
3969
3840
|
console.log(JSON.stringify(verdict));
|
|
3970
3841
|
else
|
|
3971
|
-
|
|
3842
|
+
report2(verdict.violations);
|
|
3972
3843
|
if (values.json !== true && verdict.command !== command)
|
|
3973
3844
|
console.log(`runs as: ${verdict.command}${verdict.notes.map((note) => `
|
|
3974
3845
|
${note}`).join("")}`);
|
|
@@ -3984,7 +3855,7 @@ ${pathUsage}`);
|
|
|
3984
3855
|
if (parsed.values.json === true)
|
|
3985
3856
|
console.log(JSON.stringify({ violations }));
|
|
3986
3857
|
else
|
|
3987
|
-
|
|
3858
|
+
report2(violations);
|
|
3988
3859
|
return violations.length > 0 ? 1 : 0;
|
|
3989
3860
|
}
|
|
3990
3861
|
var rulesUsage = `guard rules [--json]
|
|
@@ -4007,7 +3878,7 @@ ${" ".repeat(16)} -> ${rule.route}${rule.runs === "hook" ? " (hook only)" : ""}`
|
|
|
4007
3878
|
return 0;
|
|
4008
3879
|
}
|
|
4009
3880
|
function machine() {
|
|
4010
|
-
const home =
|
|
3881
|
+
const home = homedir3();
|
|
4011
3882
|
const stateDir = `${stateHome()}/guard`;
|
|
4012
3883
|
return {
|
|
4013
3884
|
home,
|
|
@@ -4015,7 +3886,7 @@ function machine() {
|
|
|
4015
3886
|
has: (bin) => Bun.which(bin) !== null,
|
|
4016
3887
|
run: async (argv, cwd) => runCommand(argv, { cwd }),
|
|
4017
3888
|
read: readText,
|
|
4018
|
-
exists:
|
|
3889
|
+
exists: existsSync3,
|
|
4019
3890
|
write: (path, text) => {
|
|
4020
3891
|
mkdirSync2(dirname4(path), { recursive: true });
|
|
4021
3892
|
writeFileSync(path, text);
|
|
@@ -4041,7 +3912,7 @@ ${hookUsage}`, 1);
|
|
|
4041
3912
|
console.log(JSON.stringify(reply));
|
|
4042
3913
|
return 0;
|
|
4043
3914
|
}
|
|
4044
|
-
|
|
3915
|
+
process14.exitCode = await runCli({
|
|
4045
3916
|
name: "guard",
|
|
4046
3917
|
usage: false,
|
|
4047
3918
|
about: "the safety rules a Claude Code Bash call is held to, each refusal naming the route",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-guard",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.1",
|
|
5
5
|
"description": "guard: the safety rules a Claude Code Bash call is held to (git, remote machines, SQL writes, env files, package managers, commit messages), each refusal naming the route.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"guard": "$npm_execpath src/cli.ts"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@kaynooo/cli-db": "0.
|
|
40
|
-
"@kaynooo/cli-edit": "0.
|
|
41
|
-
"@kaynooo/cli-env": "0.
|
|
42
|
-
"@kaynooo/cli-git": "0.
|
|
43
|
-
"@kaynooo/cli-kit": "0.
|
|
44
|
-
"@kaynooo/cli-out": "0.
|
|
45
|
-
"@kaynooo/cli-pkg": "0.
|
|
39
|
+
"@kaynooo/cli-db": "0.12.1",
|
|
40
|
+
"@kaynooo/cli-edit": "0.9.1",
|
|
41
|
+
"@kaynooo/cli-env": "0.13.1",
|
|
42
|
+
"@kaynooo/cli-git": "0.13.1",
|
|
43
|
+
"@kaynooo/cli-kit": "0.38.1",
|
|
44
|
+
"@kaynooo/cli-out": "0.14.3",
|
|
45
|
+
"@kaynooo/cli-pkg": "0.13.3"
|
|
46
46
|
}
|
|
47
47
|
}
|