@kaynooo/cli-guard 0.12.0 → 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 +19 -24
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -358,18 +358,14 @@ var FULL_STOP = /\.$/;
|
|
|
358
358
|
function usageLine(usage, colors = paint(process7.stdout)) {
|
|
359
359
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
360
360
|
}
|
|
361
|
-
function helpText(usage, options, colors = paint(process7.stdout), { examples = [],
|
|
362
|
-
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(`
|
|
363
363
|
`);
|
|
364
364
|
}
|
|
365
365
|
function exitRows(exits, colors = paint(process7.stdout)) {
|
|
366
366
|
if (exits.length === 0)
|
|
367
367
|
return [];
|
|
368
|
-
|
|
369
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
370
|
-
}
|
|
371
|
-
function replacesRows(replaces, colors = paint(process7.stdout)) {
|
|
372
|
-
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(", ")}`];
|
|
373
369
|
}
|
|
374
370
|
function wantsHelpJson(env = process7.env) {
|
|
375
371
|
return env.KIT_HELP === "json";
|
|
@@ -897,7 +893,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
897
893
|
header(colors, summary),
|
|
898
894
|
"",
|
|
899
895
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
900
|
-
...replacesRows(replaces, colors),
|
|
901
896
|
"",
|
|
902
897
|
...await commandRows(commands, colors),
|
|
903
898
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -3854,6 +3849,10 @@ var BINS = {
|
|
|
3854
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.",
|
|
3855
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`.",
|
|
3856
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.",
|
|
3857
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.",
|
|
3858
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.",
|
|
3859
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.",
|
|
@@ -3983,9 +3982,8 @@ var checkUsage = `guard check [options] [<command> | -]
|
|
|
3983
3982
|
|
|
3984
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).
|
|
3985
3984
|
Prints each broken rule with the route to take instead and exits 1, prints nothing and exits 0 when the command is clean.
|
|
3986
|
-
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
|
|
3987
|
-
|
|
3988
|
-
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"]];
|
|
3989
3987
|
var checkOptions = {
|
|
3990
3988
|
json: jsonOption("{violations, command, notes, packages} for a hook"),
|
|
3991
3989
|
cwd: { type: "string", description: "the directory the command runs in (default: here)" },
|
|
@@ -3994,9 +3992,8 @@ var checkOptions = {
|
|
|
3994
3992
|
};
|
|
3995
3993
|
var pathUsage = `guard path [--json] <path>...
|
|
3996
3994
|
|
|
3997
|
-
Checks the paths a file tool would read, edit or write: env files are refused
|
|
3998
|
-
|
|
3999
|
-
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"]];
|
|
4000
3997
|
var pathOptions = {
|
|
4001
3998
|
json: jsonOption("{violations} for a hook")
|
|
4002
3999
|
};
|
|
@@ -4004,9 +4001,8 @@ var hookUsage = `guard hook <${EVENTS.join("|")}>
|
|
|
4004
4001
|
|
|
4005
4002
|
Answers a Claude Code hook: reads the event JSON on stdin and prints the reply JSON, nothing when the call goes ahead untouched.
|
|
4006
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.
|
|
4007
|
-
A failure exits 1, which Claude Code reports without blocking the call
|
|
4008
|
-
|
|
4009
|
-
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)"]];
|
|
4010
4006
|
var MAX_READ = 1e6;
|
|
4011
4007
|
function readText(path) {
|
|
4012
4008
|
try {
|
|
@@ -4021,7 +4017,7 @@ function report2(violations) {
|
|
|
4021
4017
|
console.log(`${role("problem", process16.stdout)(rule)}: ${message}`);
|
|
4022
4018
|
}
|
|
4023
4019
|
async function check(args) {
|
|
4024
|
-
const parsed = parse(args, checkUsage, checkOptions);
|
|
4020
|
+
const parsed = parse(args, checkUsage, checkOptions, { exits: CHECK_EXITS });
|
|
4025
4021
|
const { values, positionals } = parsed;
|
|
4026
4022
|
if (positionals.length > 1)
|
|
4027
4023
|
fail(`give the command as one argument, quoted
|
|
@@ -4050,7 +4046,7 @@ ${note}`).join("")}`);
|
|
|
4050
4046
|
return verdict.violations.length > 0 ? 1 : 0;
|
|
4051
4047
|
}
|
|
4052
4048
|
function path(args) {
|
|
4053
|
-
const parsed = parse(args, pathUsage, pathOptions);
|
|
4049
|
+
const parsed = parse(args, pathUsage, pathOptions, { exits: PATH_EXITS });
|
|
4054
4050
|
if (parsed.positionals.length === 0)
|
|
4055
4051
|
fail(`give at least one path
|
|
4056
4052
|
|
|
@@ -4064,14 +4060,13 @@ ${pathUsage}`);
|
|
|
4064
4060
|
}
|
|
4065
4061
|
var rulesUsage = `guard rules [--json]
|
|
4066
4062
|
|
|
4067
|
-
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
|
|
4068
|
-
|
|
4069
|
-
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"]];
|
|
4070
4065
|
var rulesOptions = {
|
|
4071
4066
|
json: jsonOption("[{name, refuses, route, runs}]")
|
|
4072
4067
|
};
|
|
4073
4068
|
function rules(args) {
|
|
4074
|
-
const parsed = parse(args, rulesUsage, rulesOptions);
|
|
4069
|
+
const parsed = parse(args, rulesUsage, rulesOptions, { exits: RULES_EXITS });
|
|
4075
4070
|
if (parsed.values.json === true) {
|
|
4076
4071
|
console.log(JSON.stringify(RULES2));
|
|
4077
4072
|
return 0;
|
|
@@ -4105,7 +4100,7 @@ function machine() {
|
|
|
4105
4100
|
};
|
|
4106
4101
|
}
|
|
4107
4102
|
async function hookCommand(args) {
|
|
4108
|
-
const parsed = parse(args, hookUsage, {});
|
|
4103
|
+
const parsed = parse(args, hookUsage, {}, { exits: HOOK_EXITS });
|
|
4109
4104
|
const event = parsed.positionals[0] ?? "";
|
|
4110
4105
|
if (!EVENTS.includes(event))
|
|
4111
4106
|
fail(`unknown event ${event}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-guard",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.12.
|
|
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.10.
|
|
41
|
-
"@kaynooo/cli-env": "0.13.
|
|
42
|
-
"@kaynooo/cli-git": "0.15.
|
|
40
|
+
"@kaynooo/cli-edit": "0.10.1",
|
|
41
|
+
"@kaynooo/cli-env": "0.13.2",
|
|
42
|
+
"@kaynooo/cli-git": "0.15.1",
|
|
43
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
|
}
|