@kaynooo/cli-guard 0.9.0 → 0.10.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 +68 -45
- package/package.json +8 -8
package/dist/cli.js
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
1
|
+
#!/usr/bin/env -S bun --no-env-file
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
5
|
import { appendFileSync as appendFileSync2, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync, statSync, writeFileSync } from "fs";
|
|
6
6
|
import { homedir as homedir2 } from "os";
|
|
7
7
|
import { dirname as dirname4 } from "path";
|
|
8
|
-
import
|
|
8
|
+
import process12 from "process";
|
|
9
9
|
// ../kit/src/args.ts
|
|
10
|
-
import
|
|
10
|
+
import process6 from "process";
|
|
11
11
|
import { parseArgs } from "util";
|
|
12
12
|
|
|
13
|
-
// ../kit/src/
|
|
13
|
+
// ../kit/src/mode.ts
|
|
14
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";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ../kit/src/style.ts
|
|
32
|
+
import process3 from "process";
|
|
15
33
|
|
|
16
34
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
17
35
|
function x(s) {
|
|
@@ -274,21 +292,26 @@ function le(i = {}) {
|
|
|
274
292
|
}
|
|
275
293
|
var t = le();
|
|
276
294
|
|
|
295
|
+
// ../kit/src/theme.ts
|
|
296
|
+
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
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
298
|
+
var warned = new Set;
|
|
299
|
+
|
|
277
300
|
// ../kit/src/style.ts
|
|
278
|
-
function takesControlCodes(stream, env =
|
|
279
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
301
|
+
function takesControlCodes(stream, env = process3.env) {
|
|
302
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
280
303
|
}
|
|
281
|
-
function paint(stream, env =
|
|
304
|
+
function paint(stream, env = process3.env) {
|
|
282
305
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
283
306
|
}
|
|
284
|
-
var
|
|
285
|
-
passed:
|
|
286
|
-
failed:
|
|
287
|
-
running:
|
|
288
|
-
queued:
|
|
289
|
-
skipped:
|
|
307
|
+
var STATUS_WORDS = {
|
|
308
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
309
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
310
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
311
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
312
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
290
313
|
};
|
|
291
|
-
var STATUS_OF = new Map(Object.entries(
|
|
314
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
292
315
|
|
|
293
316
|
// ../kit/src/format.ts
|
|
294
317
|
function upTo(text, separator) {
|
|
@@ -298,27 +321,27 @@ function upTo(text, separator) {
|
|
|
298
321
|
var ESCAPE = String.fromCharCode(27);
|
|
299
322
|
|
|
300
323
|
// ../kit/src/help.ts
|
|
301
|
-
import
|
|
324
|
+
import process4 from "process";
|
|
302
325
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
303
326
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
304
327
|
var FULL_STOP = /\.$/;
|
|
305
|
-
function usageLine(usage, colors = paint(
|
|
328
|
+
function usageLine(usage, colors = paint(process4.stdout)) {
|
|
306
329
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
307
330
|
}
|
|
308
|
-
function helpText(usage, options, colors = paint(
|
|
331
|
+
function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
309
332
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
310
333
|
`);
|
|
311
334
|
}
|
|
312
|
-
function exitRows(exits, colors = paint(
|
|
335
|
+
function exitRows(exits, colors = paint(process4.stdout)) {
|
|
313
336
|
if (exits.length === 0)
|
|
314
337
|
return [];
|
|
315
338
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
316
339
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
317
340
|
}
|
|
318
|
-
function replacesRows(replaces, colors = paint(
|
|
319
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
341
|
+
function replacesRows(replaces, colors = paint(process4.stdout)) {
|
|
342
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
320
343
|
}
|
|
321
|
-
function wantsHelpJson(env =
|
|
344
|
+
function wantsHelpJson(env = process4.env) {
|
|
322
345
|
return env.KIT_HELP === "json";
|
|
323
346
|
}
|
|
324
347
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -337,12 +360,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
337
360
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
338
361
|
};
|
|
339
362
|
}
|
|
340
|
-
function exampleRows(examples, colors = paint(
|
|
341
|
-
if (examples.length === 0)
|
|
363
|
+
function exampleRows(examples, colors = paint(process4.stdout)) {
|
|
364
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
342
365
|
return [];
|
|
343
366
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
344
367
|
}
|
|
345
|
-
function optionRows(options, colors = paint(
|
|
368
|
+
function optionRows(options, colors = paint(process4.stdout)) {
|
|
346
369
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
347
370
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
348
371
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -374,10 +397,10 @@ function closest(name, names) {
|
|
|
374
397
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
375
398
|
}
|
|
376
399
|
// ../kit/src/input.ts
|
|
377
|
-
import
|
|
400
|
+
import process5 from "process";
|
|
378
401
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
379
402
|
if (path === "-") {
|
|
380
|
-
if (
|
|
403
|
+
if (process5.stdin.isTTY)
|
|
381
404
|
fail(noStdin);
|
|
382
405
|
return Bun.stdin.text();
|
|
383
406
|
}
|
|
@@ -436,7 +459,7 @@ var OUTPUT_OPTIONS = {
|
|
|
436
459
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
437
460
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
438
461
|
};
|
|
439
|
-
function applyOutput(color, plain, env =
|
|
462
|
+
function applyOutput(color, plain, env = process6.env) {
|
|
440
463
|
const when = plain === true ? "never" : color ?? "auto";
|
|
441
464
|
if (when === "auto")
|
|
442
465
|
return;
|
|
@@ -607,7 +630,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
607
630
|
}
|
|
608
631
|
// ../kit/src/process.ts
|
|
609
632
|
import { constants } from "os";
|
|
610
|
-
import
|
|
633
|
+
import process7 from "process";
|
|
611
634
|
var KILL_GRACE_MS = 2000;
|
|
612
635
|
function exitCodeOf(code, signal) {
|
|
613
636
|
if (code !== null)
|
|
@@ -627,7 +650,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
627
650
|
return;
|
|
628
651
|
try {
|
|
629
652
|
if (grouped)
|
|
630
|
-
|
|
653
|
+
process7.kill(-proc.pid, killing);
|
|
631
654
|
else
|
|
632
655
|
proc.kill(killing);
|
|
633
656
|
} catch {}
|
|
@@ -703,13 +726,13 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
|
703
726
|
// ../kit/src/cli.ts
|
|
704
727
|
import { readFileSync, realpathSync } from "fs";
|
|
705
728
|
import { dirname as dirname2, join as join2 } from "path";
|
|
706
|
-
import
|
|
729
|
+
import process9 from "process";
|
|
707
730
|
|
|
708
731
|
// ../kit/src/usage.ts
|
|
709
732
|
import { appendFileSync, mkdirSync } from "fs";
|
|
710
733
|
import { homedir } from "os";
|
|
711
734
|
import { dirname, isAbsolute, join } from "path";
|
|
712
|
-
import
|
|
735
|
+
import process8 from "process";
|
|
713
736
|
|
|
714
737
|
// ../kit/src/logs.ts
|
|
715
738
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -723,14 +746,14 @@ var usageError;
|
|
|
723
746
|
function noteUsageError(message) {
|
|
724
747
|
usageError = message;
|
|
725
748
|
}
|
|
726
|
-
function stateHome(env =
|
|
749
|
+
function stateHome(env = process8.env) {
|
|
727
750
|
const dir = env.XDG_STATE_HOME;
|
|
728
751
|
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
729
752
|
}
|
|
730
|
-
function usagePath(env =
|
|
753
|
+
function usagePath(env = process8.env) {
|
|
731
754
|
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
732
755
|
}
|
|
733
|
-
function usageRecorded(env =
|
|
756
|
+
function usageRecorded(env = process8.env) {
|
|
734
757
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
735
758
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
736
759
|
}
|
|
@@ -744,7 +767,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
744
767
|
usageError = undefined;
|
|
745
768
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
746
769
|
}
|
|
747
|
-
function recordUsage(entry, env =
|
|
770
|
+
function recordUsage(entry, env = process8.env) {
|
|
748
771
|
if (!usageRecorded(env))
|
|
749
772
|
return;
|
|
750
773
|
try {
|
|
@@ -835,8 +858,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
835
858
|
`);
|
|
836
859
|
}
|
|
837
860
|
function printError(prefix, message, hint, cause) {
|
|
838
|
-
const colors = paint(
|
|
839
|
-
const styled = takesControlCodes(
|
|
861
|
+
const colors = paint(process9.stderr);
|
|
862
|
+
const styled = takesControlCodes(process9.stderr);
|
|
840
863
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
841
864
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
842
865
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -855,7 +878,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
855
878
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
856
879
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
857
880
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
858
|
-
if (error instanceof
|
|
881
|
+
if (error instanceof Exit && error.code === 2)
|
|
859
882
|
noteUsageError(error.message);
|
|
860
883
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
861
884
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
@@ -879,11 +902,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
879
902
|
}
|
|
880
903
|
}
|
|
881
904
|
if (name === undefined && level.path.length > 1) {
|
|
882
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
905
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stderr));
|
|
883
906
|
return 2;
|
|
884
907
|
}
|
|
885
908
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
886
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
909
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stdout));
|
|
887
910
|
return 0;
|
|
888
911
|
}
|
|
889
912
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1010,7 +1033,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1010
1033
|
return "0.0.0";
|
|
1011
1034
|
}
|
|
1012
1035
|
}
|
|
1013
|
-
async function runCli(cli, argv =
|
|
1036
|
+
async function runCli(cli, argv = process9.argv.slice(2)) {
|
|
1014
1037
|
const version = cli.version ?? packageVersion();
|
|
1015
1038
|
if (argv[0] === COMPLETE)
|
|
1016
1039
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -2608,7 +2631,7 @@ function wrap(command) {
|
|
|
2608
2631
|
// ../pkg/src/added.ts
|
|
2609
2632
|
import { existsSync, readdirSync, readFileSync as readFileSync2 } from "fs";
|
|
2610
2633
|
import { dirname as dirname3, join as join3 } from "path";
|
|
2611
|
-
import
|
|
2634
|
+
import process11 from "process";
|
|
2612
2635
|
var REDIRECT2 = /^\d*[<>]/;
|
|
2613
2636
|
var BARE_REDIRECT = /^\d*(?:[<>]|>>)$/;
|
|
2614
2637
|
var ADDS = {
|
|
@@ -2640,7 +2663,7 @@ function manifestName(folder) {
|
|
|
2640
2663
|
}
|
|
2641
2664
|
function ownPackages() {
|
|
2642
2665
|
const names = new Set;
|
|
2643
|
-
let folder =
|
|
2666
|
+
let folder = process11.cwd();
|
|
2644
2667
|
while (true) {
|
|
2645
2668
|
const name = manifestName(folder);
|
|
2646
2669
|
if (name !== undefined)
|
|
@@ -3932,7 +3955,7 @@ ${checkUsage}`);
|
|
|
3932
3955
|
const given = positionals[0] ?? "-";
|
|
3933
3956
|
const command = given === "-" ? await readInput("-", { noStdin: "give the command, or pipe it on stdin" }) : given;
|
|
3934
3957
|
const context = {
|
|
3935
|
-
cwd: values.cwd ??
|
|
3958
|
+
cwd: values.cwd ?? process12.cwd(),
|
|
3936
3959
|
home: homedir2(),
|
|
3937
3960
|
isPushAsked: values["push-asked"] === true,
|
|
3938
3961
|
canRewrite: true,
|
|
@@ -4018,7 +4041,7 @@ ${hookUsage}`, 1);
|
|
|
4018
4041
|
console.log(JSON.stringify(reply));
|
|
4019
4042
|
return 0;
|
|
4020
4043
|
}
|
|
4021
|
-
|
|
4044
|
+
process12.exitCode = await runCli({
|
|
4022
4045
|
name: "guard",
|
|
4023
4046
|
usage: false,
|
|
4024
4047
|
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.10.0",
|
|
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.11.0",
|
|
40
|
+
"@kaynooo/cli-edit": "0.7.0",
|
|
41
|
+
"@kaynooo/cli-env": "0.12.0",
|
|
42
|
+
"@kaynooo/cli-git": "0.9.0",
|
|
43
|
+
"@kaynooo/cli-kit": "0.22.0",
|
|
44
|
+
"@kaynooo/cli-out": "0.10.0",
|
|
45
|
+
"@kaynooo/cli-pkg": "0.8.1"
|
|
46
46
|
}
|
|
47
47
|
}
|