@kaynooo/cli-guard 0.11.1 → 0.12.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 +299 -100
- package/package.json +6 -6
package/dist/cli.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import { appendFileSync as appendFileSync2, existsSync as
|
|
6
|
-
import { homedir as
|
|
7
|
-
import { dirname as
|
|
8
|
-
import
|
|
5
|
+
import { appendFileSync as appendFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync6, rmSync, statSync as statSync2, writeFileSync } from "fs";
|
|
6
|
+
import { homedir as homedir4 } from "os";
|
|
7
|
+
import { dirname as dirname5 } from "path";
|
|
8
|
+
import process16 from "process";
|
|
9
9
|
// ../kit/src/args.ts
|
|
10
|
-
import
|
|
10
|
+
import process9 from "process";
|
|
11
11
|
import { parseArgs } from "util";
|
|
12
12
|
|
|
13
13
|
// ../kit/src/mode.ts
|
|
@@ -29,7 +29,7 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// ../kit/src/style.ts
|
|
32
|
-
import
|
|
32
|
+
import process6 from "process";
|
|
33
33
|
|
|
34
34
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
35
35
|
var G = /^[a-f0-9]+$/i;
|
|
@@ -86,28 +86,49 @@ function Fe(r = {}) {
|
|
|
86
86
|
}
|
|
87
87
|
var o = Fe();
|
|
88
88
|
|
|
89
|
+
// ../kit/src/theme.ts
|
|
90
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
91
|
+
import { homedir as homedir2 } from "os";
|
|
92
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
93
|
+
import process5 from "process";
|
|
94
|
+
|
|
95
|
+
// ../kit/src/config.ts
|
|
96
|
+
import { existsSync } from "fs";
|
|
97
|
+
import { dirname, join, resolve } from "path";
|
|
98
|
+
import process3 from "process";
|
|
99
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
100
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
101
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
102
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
103
|
+
if (found !== undefined)
|
|
104
|
+
return found;
|
|
105
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
89
110
|
// ../kit/src/user-config.ts
|
|
90
|
-
import { existsSync, readFileSync } from "fs";
|
|
111
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
91
112
|
import { homedir } from "os";
|
|
92
|
-
import { join } from "path";
|
|
93
|
-
import
|
|
113
|
+
import { join as join2 } from "path";
|
|
114
|
+
import process4 from "process";
|
|
94
115
|
function configBase(where = {}) {
|
|
95
|
-
const xdg = where.xdg ?? (where.home === undefined ?
|
|
96
|
-
return xdg !== undefined && xdg !== "" ? xdg :
|
|
116
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
117
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
97
118
|
}
|
|
98
119
|
function userConfigPath(bin, where = {}) {
|
|
99
|
-
return
|
|
120
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
100
121
|
}
|
|
101
122
|
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
102
123
|
const current = userConfigPath(bin, where);
|
|
103
|
-
if (
|
|
124
|
+
if (existsSync2(current))
|
|
104
125
|
return current;
|
|
105
126
|
const base = configBase(where);
|
|
106
|
-
return legacy.map((parts) =>
|
|
127
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
107
128
|
}
|
|
108
129
|
function readUserConfig(bin, where = {}, legacy = []) {
|
|
109
130
|
const path = userConfigReadPath(bin, legacy, where);
|
|
110
|
-
if (!
|
|
131
|
+
if (!existsSync2(path))
|
|
111
132
|
return {};
|
|
112
133
|
try {
|
|
113
134
|
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
@@ -123,17 +144,196 @@ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
|
123
144
|
|
|
124
145
|
// ../kit/src/theme.ts
|
|
125
146
|
var ENDS = new Map;
|
|
147
|
+
var DEFAULT = {
|
|
148
|
+
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" },
|
|
149
|
+
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" },
|
|
150
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
151
|
+
bins: {},
|
|
152
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
153
|
+
};
|
|
154
|
+
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" };
|
|
155
|
+
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" };
|
|
156
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
157
|
+
var PRESETS = {
|
|
158
|
+
default: {},
|
|
159
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
160
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
161
|
+
ascii: { glyphs: ASCII }
|
|
162
|
+
};
|
|
126
163
|
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"]);
|
|
164
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
165
|
+
var CONTROL = /\p{Cc}/u;
|
|
127
166
|
var MAX_FILE_BYTES = 64 * 1024;
|
|
167
|
+
var SPACES = /\s+/;
|
|
168
|
+
function isColorSpec(spec) {
|
|
169
|
+
if (typeof spec === "number")
|
|
170
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
171
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
172
|
+
}
|
|
173
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
174
|
+
function cubeLevel(channel) {
|
|
175
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
176
|
+
}
|
|
177
|
+
function nearest256(hex) {
|
|
178
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
179
|
+
const levels = rgb.map(cubeLevel);
|
|
180
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
181
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
182
|
+
const greyValue = 8 + grey * 10;
|
|
183
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
184
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
185
|
+
}
|
|
186
|
+
function hasTrueColor(env) {
|
|
187
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
188
|
+
}
|
|
189
|
+
function tinted(colors, spec, env = process5.env) {
|
|
190
|
+
if (typeof spec === "number")
|
|
191
|
+
return colors.ansi256(spec);
|
|
192
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
193
|
+
if (HEX.test(token))
|
|
194
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
195
|
+
return chain[token] ?? chain;
|
|
196
|
+
}, colors);
|
|
197
|
+
}
|
|
198
|
+
function isRecord(value) {
|
|
199
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
200
|
+
}
|
|
201
|
+
function readThemeFile(path, warn) {
|
|
202
|
+
try {
|
|
203
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
204
|
+
if (stat === undefined)
|
|
205
|
+
return;
|
|
206
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
207
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
211
|
+
if (isRecord(parsed))
|
|
212
|
+
return parsed;
|
|
213
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
216
|
+
}
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
function applyPreset(theme, name, warn, where) {
|
|
220
|
+
if (name === undefined)
|
|
221
|
+
return;
|
|
222
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
223
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const preset = PRESETS[name];
|
|
227
|
+
Object.assign(theme.colors, preset.colors);
|
|
228
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
229
|
+
if (preset.accents !== undefined)
|
|
230
|
+
theme.accents = [...preset.accents];
|
|
231
|
+
if (Object.hasOwn(preset, "gradient"))
|
|
232
|
+
theme.gradient = preset.gradient;
|
|
233
|
+
return name;
|
|
234
|
+
}
|
|
235
|
+
function applyFile(theme, file, where, warn) {
|
|
236
|
+
if (isRecord(file.colors)) {
|
|
237
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
238
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
239
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
240
|
+
else if (!isColorSpec(value))
|
|
241
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
242
|
+
else
|
|
243
|
+
theme.colors[key] = value;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (isRecord(file.glyphs)) {
|
|
247
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
248
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
249
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
250
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
251
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
252
|
+
else
|
|
253
|
+
theme.glyphs[key] = value;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
257
|
+
theme.accents = [...file.accents];
|
|
258
|
+
else if (file.accents !== undefined)
|
|
259
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
260
|
+
if (file.gradient === null)
|
|
261
|
+
theme.gradient = undefined;
|
|
262
|
+
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
263
|
+
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
264
|
+
else if (file.gradient !== undefined)
|
|
265
|
+
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
266
|
+
if (isRecord(file.bins)) {
|
|
267
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
268
|
+
if (isColorSpec(value))
|
|
269
|
+
theme.bins[bin] = value;
|
|
270
|
+
else
|
|
271
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function endsWalk(home) {
|
|
276
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
277
|
+
}
|
|
128
278
|
var warned = new Set;
|
|
279
|
+
function warnOnce(message) {
|
|
280
|
+
if (warned.has(message))
|
|
281
|
+
return;
|
|
282
|
+
warned.add(message);
|
|
283
|
+
console.error(`warning: theme ${message}`);
|
|
284
|
+
}
|
|
285
|
+
function isPath(chosen) {
|
|
286
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
287
|
+
}
|
|
288
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
289
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
290
|
+
const sources = [];
|
|
291
|
+
const chosen = env.KIT_THEME ?? "";
|
|
292
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
293
|
+
if (isPath(chosen))
|
|
294
|
+
wanted.push(resolve2(from, chosen));
|
|
295
|
+
const files = [];
|
|
296
|
+
for (const path of wanted) {
|
|
297
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
298
|
+
if (path !== undefined && file !== undefined)
|
|
299
|
+
files.push({ path, file });
|
|
300
|
+
}
|
|
301
|
+
let preset = "default";
|
|
302
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
303
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
304
|
+
} else {
|
|
305
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
306
|
+
if (named !== undefined)
|
|
307
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
308
|
+
}
|
|
309
|
+
for (const { path, file } of files) {
|
|
310
|
+
applyFile(theme, file, path, warn);
|
|
311
|
+
sources.push(path);
|
|
312
|
+
}
|
|
313
|
+
return { theme, sources, preset };
|
|
314
|
+
}
|
|
315
|
+
var current;
|
|
316
|
+
var currentKey = "";
|
|
317
|
+
function activeTheme() {
|
|
318
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
319
|
+
if (current === undefined || key !== currentKey) {
|
|
320
|
+
current = loadTheme();
|
|
321
|
+
currentKey = key;
|
|
322
|
+
}
|
|
323
|
+
return current;
|
|
324
|
+
}
|
|
129
325
|
|
|
130
326
|
// ../kit/src/style.ts
|
|
131
|
-
function takesControlCodes(stream, env =
|
|
327
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
132
328
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
133
329
|
}
|
|
134
|
-
function paint(stream, env =
|
|
330
|
+
function paint(stream, env = process6.env) {
|
|
135
331
|
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
136
332
|
}
|
|
333
|
+
function role(name, stream, env = process6.env) {
|
|
334
|
+
const colors = paint(stream, env);
|
|
335
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
336
|
+
}
|
|
137
337
|
var STATUS_WORDS = {
|
|
138
338
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
139
339
|
failed: ["failed", "failure", "error", "errored"],
|
|
@@ -151,27 +351,23 @@ function upTo(text, separator) {
|
|
|
151
351
|
var ESCAPE = String.fromCharCode(27);
|
|
152
352
|
|
|
153
353
|
// ../kit/src/help.ts
|
|
154
|
-
import
|
|
354
|
+
import process7 from "process";
|
|
155
355
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
156
356
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
157
357
|
var FULL_STOP = /\.$/;
|
|
158
|
-
function usageLine(usage, colors = paint(
|
|
358
|
+
function usageLine(usage, colors = paint(process7.stdout)) {
|
|
159
359
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
160
360
|
}
|
|
161
|
-
function helpText(usage, options, colors = paint(
|
|
162
|
-
return [usageLine(usage, colors),
|
|
361
|
+
function helpText(usage, options, colors = paint(process7.stdout), { examples = [], exits = [] } = {}) {
|
|
362
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
163
363
|
`);
|
|
164
364
|
}
|
|
165
|
-
function exitRows(exits, colors = paint(
|
|
365
|
+
function exitRows(exits, colors = paint(process7.stdout)) {
|
|
166
366
|
if (exits.length === 0)
|
|
167
367
|
return [];
|
|
168
|
-
|
|
169
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
170
|
-
}
|
|
171
|
-
function replacesRows(replaces, colors = paint(process5.stdout)) {
|
|
172
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
368
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
173
369
|
}
|
|
174
|
-
function wantsHelpJson(env =
|
|
370
|
+
function wantsHelpJson(env = process7.env) {
|
|
175
371
|
return env.KIT_HELP === "json";
|
|
176
372
|
}
|
|
177
373
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -190,12 +386,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
190
386
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
191
387
|
};
|
|
192
388
|
}
|
|
193
|
-
function exampleRows(examples, colors = paint(
|
|
389
|
+
function exampleRows(examples, colors = paint(process7.stdout)) {
|
|
194
390
|
if (examples.length === 0 || outputMode() === "agent")
|
|
195
391
|
return [];
|
|
196
392
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
197
393
|
}
|
|
198
|
-
function optionRows(options, colors = paint(
|
|
394
|
+
function optionRows(options, colors = paint(process7.stdout)) {
|
|
199
395
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
200
396
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
201
397
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -227,10 +423,10 @@ function closest(name, names) {
|
|
|
227
423
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
228
424
|
}
|
|
229
425
|
// ../kit/src/input.ts
|
|
230
|
-
import
|
|
426
|
+
import process8 from "process";
|
|
231
427
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
232
428
|
if (path === "-") {
|
|
233
|
-
if (
|
|
429
|
+
if (process8.stdin.isTTY)
|
|
234
430
|
fail(noStdin);
|
|
235
431
|
return Bun.stdin.text();
|
|
236
432
|
}
|
|
@@ -288,7 +484,7 @@ var OUTPUT_OPTIONS = {
|
|
|
288
484
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
289
485
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
290
486
|
};
|
|
291
|
-
function applyOutput(color, plain, env =
|
|
487
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
292
488
|
const when = plain === true ? "never" : color ?? "auto";
|
|
293
489
|
if (when === "auto")
|
|
294
490
|
return;
|
|
@@ -458,32 +654,32 @@ function nearestOption(message, options, allowNegative) {
|
|
|
458
654
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
459
655
|
}
|
|
460
656
|
// ../kit/src/argv.ts
|
|
461
|
-
import { readFileSync as
|
|
462
|
-
import { resolve } from "path";
|
|
463
|
-
import
|
|
657
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
658
|
+
import { resolve as resolve3 } from "path";
|
|
659
|
+
import process10 from "process";
|
|
464
660
|
function commandLine() {
|
|
465
661
|
try {
|
|
466
|
-
return
|
|
662
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
467
663
|
} catch {
|
|
468
664
|
return;
|
|
469
665
|
}
|
|
470
666
|
}
|
|
471
667
|
function realPath(word) {
|
|
472
668
|
try {
|
|
473
|
-
return realpathSync(
|
|
669
|
+
return realpathSync(resolve3(word));
|
|
474
670
|
} catch {
|
|
475
671
|
return;
|
|
476
672
|
}
|
|
477
673
|
}
|
|
478
|
-
function scriptArgs(argv =
|
|
674
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
479
675
|
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
480
|
-
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (
|
|
676
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
481
677
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
482
678
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
483
679
|
}
|
|
484
680
|
// ../kit/src/process.ts
|
|
485
681
|
import { constants } from "os";
|
|
486
|
-
import
|
|
682
|
+
import process11 from "process";
|
|
487
683
|
var KILL_GRACE_MS = 2000;
|
|
488
684
|
function exitCodeOf(code, signal) {
|
|
489
685
|
if (code !== null)
|
|
@@ -503,7 +699,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
503
699
|
return;
|
|
504
700
|
try {
|
|
505
701
|
if (grouped)
|
|
506
|
-
|
|
702
|
+
process11.kill(-proc.pid, killing);
|
|
507
703
|
else
|
|
508
704
|
proc.kill(killing);
|
|
509
705
|
} catch {}
|
|
@@ -577,15 +773,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
577
773
|
var RESET_STYLE = `${ESC}[0m`;
|
|
578
774
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
579
775
|
// ../kit/src/cli.ts
|
|
580
|
-
import { readFileSync as
|
|
581
|
-
import { dirname as
|
|
582
|
-
import
|
|
776
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
777
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
778
|
+
import process13 from "process";
|
|
583
779
|
|
|
584
780
|
// ../kit/src/usage.ts
|
|
585
781
|
import { appendFileSync, mkdirSync } from "fs";
|
|
586
|
-
import { homedir as
|
|
587
|
-
import { dirname, isAbsolute, join as
|
|
588
|
-
import
|
|
782
|
+
import { homedir as homedir3 } from "os";
|
|
783
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
784
|
+
import process12 from "process";
|
|
589
785
|
|
|
590
786
|
// ../kit/src/logs.ts
|
|
591
787
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -599,14 +795,14 @@ var usageError;
|
|
|
599
795
|
function noteUsageError(message) {
|
|
600
796
|
usageError = message;
|
|
601
797
|
}
|
|
602
|
-
function stateHome(env =
|
|
798
|
+
function stateHome(env = process12.env) {
|
|
603
799
|
const dir = env.XDG_STATE_HOME;
|
|
604
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
800
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
605
801
|
}
|
|
606
|
-
function usagePath(env =
|
|
607
|
-
return
|
|
802
|
+
function usagePath(env = process12.env) {
|
|
803
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
608
804
|
}
|
|
609
|
-
function usageRecorded(env =
|
|
805
|
+
function usageRecorded(env = process12.env) {
|
|
610
806
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
611
807
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
612
808
|
}
|
|
@@ -620,12 +816,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
620
816
|
usageError = undefined;
|
|
621
817
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
622
818
|
}
|
|
623
|
-
function recordUsage(entry, env =
|
|
819
|
+
function recordUsage(entry, env = process12.env) {
|
|
624
820
|
if (!usageRecorded(env))
|
|
625
821
|
return;
|
|
626
822
|
try {
|
|
627
823
|
const path = usagePath(env);
|
|
628
|
-
mkdirSync(
|
|
824
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
629
825
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
630
826
|
`, { mode: 384 });
|
|
631
827
|
} catch {}
|
|
@@ -697,7 +893,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
697
893
|
header(colors, summary),
|
|
698
894
|
"",
|
|
699
895
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
700
|
-
...replacesRows(replaces, colors),
|
|
701
896
|
"",
|
|
702
897
|
...await commandRows(commands, colors),
|
|
703
898
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -711,8 +906,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
711
906
|
`);
|
|
712
907
|
}
|
|
713
908
|
function printError(prefix, message, hint, cause) {
|
|
714
|
-
const colors = paint(
|
|
715
|
-
const styled = takesControlCodes(
|
|
909
|
+
const colors = paint(process13.stderr);
|
|
910
|
+
const styled = takesControlCodes(process13.stderr);
|
|
716
911
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
717
912
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
718
913
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -755,11 +950,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
755
950
|
}
|
|
756
951
|
}
|
|
757
952
|
if (name === undefined && level.path.length > 1) {
|
|
758
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
953
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
|
|
759
954
|
return 2;
|
|
760
955
|
}
|
|
761
956
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
762
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
957
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
|
|
763
958
|
return 0;
|
|
764
959
|
}
|
|
765
960
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -876,13 +1071,17 @@ async function printCandidates(found) {
|
|
|
876
1071
|
return 0;
|
|
877
1072
|
}
|
|
878
1073
|
function packageVersion(entry = Bun.main) {
|
|
879
|
-
|
|
1074
|
+
let resolved = entry;
|
|
1075
|
+
try {
|
|
1076
|
+
resolved = realpathSync2(entry);
|
|
1077
|
+
} catch {}
|
|
1078
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
880
1079
|
try {
|
|
881
|
-
const { version } = JSON.parse(
|
|
1080
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
882
1081
|
if (typeof version === "string")
|
|
883
1082
|
return version;
|
|
884
1083
|
} catch {}
|
|
885
|
-
if (
|
|
1084
|
+
if (dirname3(dir) === dir)
|
|
886
1085
|
return "0.0.0";
|
|
887
1086
|
}
|
|
888
1087
|
}
|
|
@@ -2492,9 +2691,9 @@ function wrap(command) {
|
|
|
2492
2691
|
}
|
|
2493
2692
|
|
|
2494
2693
|
// ../pkg/src/added.ts
|
|
2495
|
-
import { existsSync as
|
|
2496
|
-
import { dirname as
|
|
2497
|
-
import
|
|
2694
|
+
import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync5 } from "fs";
|
|
2695
|
+
import { dirname as dirname4, join as join6 } from "path";
|
|
2696
|
+
import process15 from "process";
|
|
2498
2697
|
var REDIRECT2 = /^\d*[<>]/;
|
|
2499
2698
|
var BARE_REDIRECT = /^\d*(?:[<>]|>>)$/;
|
|
2500
2699
|
var ADDS = {
|
|
@@ -2518,7 +2717,7 @@ var PUBLISH = /\b(?:ft|cli\.ts)\s+release\b|\b(?:bun|npm|pnpm|yarn)\s+publish\b|
|
|
|
2518
2717
|
var EXACT_SPEC = /^(?:@[^/]+\/)?[^@]+@\d+\.\d+\.\d+(?:[-+][\w.+-]+)?$/;
|
|
2519
2718
|
function manifestName(folder) {
|
|
2520
2719
|
try {
|
|
2521
|
-
const { name } = JSON.parse(
|
|
2720
|
+
const { name } = JSON.parse(readFileSync5(join6(folder, "package.json"), "utf8"));
|
|
2522
2721
|
return typeof name === "string" ? name : undefined;
|
|
2523
2722
|
} catch {
|
|
2524
2723
|
return;
|
|
@@ -2526,19 +2725,19 @@ function manifestName(folder) {
|
|
|
2526
2725
|
}
|
|
2527
2726
|
function ownPackages() {
|
|
2528
2727
|
const names = new Set;
|
|
2529
|
-
let folder =
|
|
2728
|
+
let folder = process15.cwd();
|
|
2530
2729
|
while (true) {
|
|
2531
2730
|
const name = manifestName(folder);
|
|
2532
2731
|
if (name !== undefined)
|
|
2533
2732
|
names.add(name);
|
|
2534
|
-
for (const member of
|
|
2535
|
-
const memberName = manifestName(
|
|
2733
|
+
for (const member of existsSync4(join6(folder, "packages")) ? readdirSync(join6(folder, "packages")) : []) {
|
|
2734
|
+
const memberName = manifestName(join6(folder, "packages", member));
|
|
2536
2735
|
if (memberName !== undefined)
|
|
2537
2736
|
names.add(memberName);
|
|
2538
2737
|
}
|
|
2539
|
-
if (
|
|
2738
|
+
if (existsSync4(join6(folder, ".git")) || dirname4(folder) === folder)
|
|
2540
2739
|
return names;
|
|
2541
|
-
folder =
|
|
2740
|
+
folder = dirname4(folder);
|
|
2542
2741
|
}
|
|
2543
2742
|
}
|
|
2544
2743
|
function specName(spec) {
|
|
@@ -3650,6 +3849,10 @@ var BINS = {
|
|
|
3650
3849
|
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
3850
|
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
3851
|
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.",
|
|
3852
|
+
gf: "`gf [--repos] [dir]...`: fetches with prune and fast-forwards the branch onto its upstream, saying what came in; a diverged branch or a tree the fast-forward would overwrite is refused untouched, `--no-pull` fetches only; use it instead of `git pull` and a git fetch per nested repository.",
|
|
3853
|
+
gcl: "`gcl <repo> [dir]`: clones a URL, scp address or owner/name into the workspace folder and prints the path, an existing clone being fetched instead; use it instead of git clone with the folder typed out.",
|
|
3854
|
+
gd: "`gd [path]...`: the tracked changes per file with added and removed lines, staged apart from unstaged, the patch of the paths given, `--staged`, `--ref <rev>`; use it instead of `git diff --stat` then `git diff <path>`.",
|
|
3855
|
+
gu: "`gu <path>...`: discards the unstaged changes of the paths after saving them as a patch, `--staged` unstages, `--commit` undoes the last unpushed commit keeping its changes staged; use it instead of git restore and git reset.",
|
|
3653
3856
|
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.",
|
|
3654
3857
|
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.",
|
|
3655
3858
|
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.",
|
|
@@ -3779,9 +3982,8 @@ var checkUsage = `guard check [options] [<command> | -]
|
|
|
3779
3982
|
|
|
3780
3983
|
Checks a shell command against the rules: remote machines, git (stash, whole-tree add and commit, push, tags), destructive commands (reset --hard, force push, rebase, broad rm), commit messages, SQL writes, env files, package managers and in-place edits (sed -i and replace scripts, pointed at sub).
|
|
3781
3984
|
Prints each broken rule with the route to take instead and exits 1, prints nothing and exits 0 when the command is clean.
|
|
3782
|
-
The command is read from stdin with - or when none is given; a rule may rewrite it instead (the pinned package manager, a noisy run through out), printed as \`runs as: <command
|
|
3783
|
-
|
|
3784
|
-
Exits 0 when the command is clean, 1 when a rule is broken, 2 on a usage error.`;
|
|
3985
|
+
The command is read from stdin with - or when none is given; a rule may rewrite it instead (the pinned package manager, a noisy run through out), printed as \`runs as: <command>\`.`;
|
|
3986
|
+
var CHECK_EXITS = [[0, "the command is clean"], [1, "a rule is broken"], [2, "a usage error"]];
|
|
3785
3987
|
var checkOptions = {
|
|
3786
3988
|
json: jsonOption("{violations, command, notes, packages} for a hook"),
|
|
3787
3989
|
cwd: { type: "string", description: "the directory the command runs in (default: here)" },
|
|
@@ -3790,9 +3992,8 @@ var checkOptions = {
|
|
|
3790
3992
|
};
|
|
3791
3993
|
var pathUsage = `guard path [--json] <path>...
|
|
3792
3994
|
|
|
3793
|
-
Checks the paths a file tool would read, edit or write: env files are refused
|
|
3794
|
-
|
|
3795
|
-
Exits 0 when every path is clean, 1 when one is refused, 2 on a usage error.`;
|
|
3995
|
+
Checks the paths a file tool would read, edit or write: env files are refused.`;
|
|
3996
|
+
var PATH_EXITS = [[0, "every path is clean"], [1, "one is refused"], [2, "a usage error"]];
|
|
3796
3997
|
var pathOptions = {
|
|
3797
3998
|
json: jsonOption("{violations} for a hook")
|
|
3798
3999
|
};
|
|
@@ -3800,24 +4001,23 @@ var hookUsage = `guard hook <${EVENTS.join("|")}>
|
|
|
3800
4001
|
|
|
3801
4002
|
Answers a Claude Code hook: reads the event JSON on stdin and prints the reply JSON, nothing when the call goes ahead untouched.
|
|
3802
4003
|
pre-tool-use refuses a Bash call breaking a rule, an install pkg refuses (or fails to check), and a file tool (Read, Edit, MultiEdit, Write, NotebookEdit, Grep, Glob) reaching an env file; user-prompt-submit remembers whether the prompt asked for a push; session-start lists the installed @kaynooo/cli-* bins.
|
|
3803
|
-
A failure exits 1, which Claude Code reports without blocking the call
|
|
3804
|
-
|
|
3805
|
-
Exits 0 when it answered, 1 on a failure or an unknown event (never 2, which would block the call).`;
|
|
4004
|
+
A failure exits 1, which Claude Code reports without blocking the call.`;
|
|
4005
|
+
var HOOK_EXITS = [[0, "it answered"], [1, "a failure or an unknown event (never 2, which would block the call)"]];
|
|
3806
4006
|
var MAX_READ = 1e6;
|
|
3807
4007
|
function readText(path) {
|
|
3808
4008
|
try {
|
|
3809
|
-
const stats =
|
|
3810
|
-
return stats?.isFile() === true && stats.size <= MAX_READ ?
|
|
4009
|
+
const stats = statSync2(path, { throwIfNoEntry: false });
|
|
4010
|
+
return stats?.isFile() === true && stats.size <= MAX_READ ? readFileSync6(path, "utf8") : null;
|
|
3811
4011
|
} catch {
|
|
3812
4012
|
return null;
|
|
3813
4013
|
}
|
|
3814
4014
|
}
|
|
3815
4015
|
function report2(violations) {
|
|
3816
4016
|
for (const { rule, message } of violations)
|
|
3817
|
-
console.log(`${rule}: ${message}`);
|
|
4017
|
+
console.log(`${role("problem", process16.stdout)(rule)}: ${message}`);
|
|
3818
4018
|
}
|
|
3819
4019
|
async function check(args) {
|
|
3820
|
-
const parsed = parse(args, checkUsage, checkOptions);
|
|
4020
|
+
const parsed = parse(args, checkUsage, checkOptions, { exits: CHECK_EXITS });
|
|
3821
4021
|
const { values, positionals } = parsed;
|
|
3822
4022
|
if (positionals.length > 1)
|
|
3823
4023
|
fail(`give the command as one argument, quoted
|
|
@@ -3826,14 +4026,14 @@ ${checkUsage}`);
|
|
|
3826
4026
|
const given = positionals[0] ?? "-";
|
|
3827
4027
|
const command = given === "-" ? await readInput("-", { noStdin: "give the command, or pipe it on stdin" }) : given;
|
|
3828
4028
|
const context = {
|
|
3829
|
-
cwd: values.cwd ??
|
|
3830
|
-
home:
|
|
4029
|
+
cwd: values.cwd ?? process16.cwd(),
|
|
4030
|
+
home: homedir4(),
|
|
3831
4031
|
isPushAsked: values["push-asked"] === true,
|
|
3832
4032
|
canRewrite: true,
|
|
3833
4033
|
canWrap: values["no-wrap"] !== true && Bun.which("out") !== null,
|
|
3834
4034
|
canSub: Bun.which("sub") !== null,
|
|
3835
4035
|
read: readText,
|
|
3836
|
-
exists:
|
|
4036
|
+
exists: existsSync5
|
|
3837
4037
|
};
|
|
3838
4038
|
const verdict = await checkCommand(command, context);
|
|
3839
4039
|
if (values.json === true)
|
|
@@ -3841,12 +4041,12 @@ ${checkUsage}`);
|
|
|
3841
4041
|
else
|
|
3842
4042
|
report2(verdict.violations);
|
|
3843
4043
|
if (values.json !== true && verdict.command !== command)
|
|
3844
|
-
console.log(
|
|
4044
|
+
console.log(`${role("label", process16.stdout)("runs as:")} ${verdict.command}${verdict.notes.map((note) => `
|
|
3845
4045
|
${note}`).join("")}`);
|
|
3846
4046
|
return verdict.violations.length > 0 ? 1 : 0;
|
|
3847
4047
|
}
|
|
3848
4048
|
function path(args) {
|
|
3849
|
-
const parsed = parse(args, pathUsage, pathOptions);
|
|
4049
|
+
const parsed = parse(args, pathUsage, pathOptions, { exits: PATH_EXITS });
|
|
3850
4050
|
if (parsed.positionals.length === 0)
|
|
3851
4051
|
fail(`give at least one path
|
|
3852
4052
|
|
|
@@ -3860,25 +4060,24 @@ ${pathUsage}`);
|
|
|
3860
4060
|
}
|
|
3861
4061
|
var rulesUsage = `guard rules [--json]
|
|
3862
4062
|
|
|
3863
|
-
Lists every rule \`guard check\` and \`guard hook\` apply: its name as a violation carries it, what it refuses, the route its refusal points at and where it runs
|
|
3864
|
-
|
|
3865
|
-
Exits 0 once it listed them.`;
|
|
4063
|
+
Lists every rule \`guard check\` and \`guard hook\` apply: its name as a violation carries it, what it refuses, the route its refusal points at and where it runs.`;
|
|
4064
|
+
var RULES_EXITS = [[0, "it listed them"]];
|
|
3866
4065
|
var rulesOptions = {
|
|
3867
4066
|
json: jsonOption("[{name, refuses, route, runs}]")
|
|
3868
4067
|
};
|
|
3869
4068
|
function rules(args) {
|
|
3870
|
-
const parsed = parse(args, rulesUsage, rulesOptions);
|
|
4069
|
+
const parsed = parse(args, rulesUsage, rulesOptions, { exits: RULES_EXITS });
|
|
3871
4070
|
if (parsed.values.json === true) {
|
|
3872
4071
|
console.log(JSON.stringify(RULES2));
|
|
3873
4072
|
return 0;
|
|
3874
4073
|
}
|
|
3875
4074
|
for (const rule of RULES2)
|
|
3876
|
-
console.log(`${rule.name.
|
|
4075
|
+
console.log(`${role("id", process16.stdout)(rule.name)}${" ".repeat(Math.max(0, 16 - rule.name.length))} ${rule.refuses}
|
|
3877
4076
|
${" ".repeat(16)} -> ${rule.route}${rule.runs === "hook" ? " (hook only)" : ""}`);
|
|
3878
4077
|
return 0;
|
|
3879
4078
|
}
|
|
3880
4079
|
function machine() {
|
|
3881
|
-
const home =
|
|
4080
|
+
const home = homedir4();
|
|
3882
4081
|
const stateDir = `${stateHome()}/guard`;
|
|
3883
4082
|
return {
|
|
3884
4083
|
home,
|
|
@@ -3886,9 +4085,9 @@ function machine() {
|
|
|
3886
4085
|
has: (bin) => Bun.which(bin) !== null,
|
|
3887
4086
|
run: async (argv, cwd) => runCommand(argv, { cwd }),
|
|
3888
4087
|
read: readText,
|
|
3889
|
-
exists:
|
|
4088
|
+
exists: existsSync5,
|
|
3890
4089
|
write: (path, text) => {
|
|
3891
|
-
mkdirSync2(
|
|
4090
|
+
mkdirSync2(dirname5(path), { recursive: true });
|
|
3892
4091
|
writeFileSync(path, text);
|
|
3893
4092
|
},
|
|
3894
4093
|
remove: (path) => rmSync(path, { force: true }),
|
|
@@ -3901,7 +4100,7 @@ function machine() {
|
|
|
3901
4100
|
};
|
|
3902
4101
|
}
|
|
3903
4102
|
async function hookCommand(args) {
|
|
3904
|
-
const parsed = parse(args, hookUsage, {});
|
|
4103
|
+
const parsed = parse(args, hookUsage, {}, { exits: HOOK_EXITS });
|
|
3905
4104
|
const event = parsed.positionals[0] ?? "";
|
|
3906
4105
|
if (!EVENTS.includes(event))
|
|
3907
4106
|
fail(`unknown event ${event}
|
|
@@ -3912,7 +4111,7 @@ ${hookUsage}`, 1);
|
|
|
3912
4111
|
console.log(JSON.stringify(reply));
|
|
3913
4112
|
return 0;
|
|
3914
4113
|
}
|
|
3915
|
-
|
|
4114
|
+
process16.exitCode = await runCli({
|
|
3916
4115
|
name: "guard",
|
|
3917
4116
|
usage: false,
|
|
3918
4117
|
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.12.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",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@kaynooo/cli-db": "0.12.1",
|
|
40
|
-
"@kaynooo/cli-edit": "0.
|
|
41
|
-
"@kaynooo/cli-env": "0.13.
|
|
42
|
-
"@kaynooo/cli-git": "0.
|
|
43
|
-
"@kaynooo/cli-kit": "0.38.
|
|
40
|
+
"@kaynooo/cli-edit": "0.10.1",
|
|
41
|
+
"@kaynooo/cli-env": "0.13.2",
|
|
42
|
+
"@kaynooo/cli-git": "0.15.1",
|
|
43
|
+
"@kaynooo/cli-kit": "0.38.2",
|
|
44
44
|
"@kaynooo/cli-out": "0.14.3",
|
|
45
|
-
"@kaynooo/cli-pkg": "0.
|
|
45
|
+
"@kaynooo/cli-pkg": "0.15.0"
|
|
46
46
|
}
|
|
47
47
|
}
|