@kaynooo/cli-guard 0.14.4 → 0.14.5

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.
Files changed (2) hide show
  1. package/dist/cli.js +36 -8
  2. package/package.json +6 -6
package/dist/cli.js CHANGED
@@ -2700,6 +2700,33 @@ function printsTrackedEnv(program, args) {
2700
2700
  return rest.some((arg) => GIT_PATCH_FLAGS.has(arg));
2701
2701
  return !rest.some((arg) => GIT_NO_PATCH.has(arg));
2702
2702
  }
2703
+ var REDIRECT = /^(\d*|&)(>>|>&|>|<)(.*)$/;
2704
+ var BARE_REDIRECT = /^(?:\d*|&)(?:>>|>&|>|<)$/;
2705
+ var FD = /^\d$/;
2706
+ function withoutRedirects(words) {
2707
+ return words.filter((word, at) => !REDIRECT.test(word) && !BARE_REDIRECT.test(words[at - 1] ?? ""));
2708
+ }
2709
+ function resolveTarget(operator, to, target) {
2710
+ if (operator === ">&" && FD.test(to))
2711
+ return target[to] ?? "other";
2712
+ return to === "-" ? "/dev/null" : to;
2713
+ }
2714
+ function discardsStdout(words) {
2715
+ const target = { 1: "tty", 2: "tty" };
2716
+ for (let at = 0;at < words.length; at++) {
2717
+ const match = REDIRECT.exec(words[at] ?? "");
2718
+ if (match === null || match[2] === "<")
2719
+ continue;
2720
+ const [, fd = "", operator, written] = match;
2721
+ const to = written === "" ? words[++at] ?? "" : written;
2722
+ const resolved = resolveTarget(operator, to, target);
2723
+ if (fd === "&" || operator === ">&" && fd === "" && !FD.test(to))
2724
+ target[1] = target[2] = resolved;
2725
+ else
2726
+ target[fd === "" ? 1 : fd] = resolved;
2727
+ }
2728
+ return target[1] === "/dev/null";
2729
+ }
2703
2730
 
2704
2731
  // ../env/src/mask.ts
2705
2732
  var PLAIN_VALUE = /^(?:true|false|null|none|nil|yes|no|on|off|undefined)$/i;
@@ -2769,7 +2796,7 @@ var TEMPLATE = /\.(?:example|sample|template|dist|defaults)$/;
2769
2796
  var SKIPPED = ignoredFolders([".git", ".kay"]);
2770
2797
 
2771
2798
  // ../env/src/guard-paths.ts
2772
- var REDIRECT = /^\d*[<>]+&?/;
2799
+ var REDIRECT2 = /^\d*[<>]+&?/;
2773
2800
  var ENVRC = ".envrc";
2774
2801
  var PROC_ENVIRON = /^\/proc\/[^/]+\/environ$/;
2775
2802
  var ENV_SAMPLES = [".env", ".env.local", ".env.production", ".envrc"];
@@ -2810,7 +2837,7 @@ function reachesEnvFile(path) {
2810
2837
  return braceExpand(path).some((each) => isEnvFile(each) || globReachesEnv(each));
2811
2838
  }
2812
2839
  function targetOf(word) {
2813
- const bare = word.replace(REDIRECT, "");
2840
+ const bare = word.replace(REDIRECT2, "");
2814
2841
  return bare.includes("=") ? bare.slice(bare.indexOf("=") + 1) : bare;
2815
2842
  }
2816
2843
  function namesEnvFile(word, previous, isGlob) {
@@ -3068,8 +3095,9 @@ function touchingPieces(command, options = {}) {
3068
3095
  const { program, args } = parseCommand(piece.command);
3069
3096
  if (readsEnv(piece, variables) || searchesEnv(program, args) || runnerReadsListedEnv(pieces, index, variables) || loopReadsListedEnv(pieces, index, variables))
3070
3097
  return true;
3071
- const isDump = dumpsContainerEnv(program, args) || dumpsEnvironment(program, args, tokenize(piece.command)) || options.hasTrackedEnv === true && printsTrackedEnv(program, args);
3072
- if (!isDump)
3098
+ const operands = withoutRedirects(args);
3099
+ const isDump = dumpsContainerEnv(program, operands) || dumpsEnvironment(program, operands, tokenize(piece.command)) || options.hasTrackedEnv === true && printsTrackedEnv(program, operands);
3100
+ if (!isDump || discardsStdout(tokenize(piece.command)))
3073
3101
  return false;
3074
3102
  for (let at = index;pieces[at]?.separator === "|"; at++) {
3075
3103
  const next = parseCommand(pieces[at + 1]?.command ?? "");
@@ -3415,8 +3443,8 @@ function mismatchFor(request, pinned) {
3415
3443
  }
3416
3444
 
3417
3445
  // ../pkg/src/added.ts
3418
- var REDIRECT2 = /^\d*[<>]/;
3419
- var BARE_REDIRECT = /^\d*(?:[<>]|>>)$/;
3446
+ var REDIRECT3 = /^\d*[<>]/;
3447
+ var BARE_REDIRECT2 = /^\d*(?:[<>]|>>)$/;
3420
3448
  var ADDS = {
3421
3449
  bun: new Set(["add", "a", "install", "i"]),
3422
3450
  npm: new Set([...NPM_INSTALLS, ...NPM_TEST_INSTALLS, "add"]),
@@ -3489,7 +3517,7 @@ function piecePackages(program, sub, args, rest) {
3489
3517
  return rest.flatMap((word, index) => isSkipped(word, rest[index - 1] ?? "", program) ? [] : registryName(word));
3490
3518
  }
3491
3519
  function isSkipped(word, previous, program = "") {
3492
- return word.startsWith("-") || REDIRECT2.test(word) || VALUE_FLAGS2.has(previous) || OWN_VALUE_FLAGS[program]?.has(previous) === true || BARE_REDIRECT.test(previous);
3520
+ return word.startsWith("-") || REDIRECT3.test(word) || VALUE_FLAGS2.has(previous) || OWN_VALUE_FLAGS[program]?.has(previous) === true || BARE_REDIRECT2.test(previous);
3493
3521
  }
3494
3522
  function registryName(word) {
3495
3523
  const at = word.indexOf("@", 1);
@@ -4743,7 +4771,7 @@ function checkPath(path) {
4743
4771
 
4744
4772
  // src/bins.ts
4745
4773
  var BINS = {
4746
- check: "`check`: runs the repo's check, typecheck, lint and test steps (package.json, composer.json and PHP tool configs, a Justfile, a Makefile) and prints only what failed, each full log saved to a file; a step runs inside the running compose service that mounts its folder (`--in <service>`, `--host`), never starting one; validate a change with it rather than chaining the scripts or `docker compose exec` by hand (`--only lint,test`, `--list`, `--slot`, `--failed` to re-run what failed last); `check --fix` runs its fixers and formatters instead (its fix, lint:fix and format scripts, php-cs-fixer, just fmt, go fmt, cargo fmt, ruff) and lists the files they changed.",
4774
+ check: "`check`: runs the repo's check, typecheck, lint, fmt:check and test steps (package.json, composer.json and PHP tool configs, a Justfile, a Makefile) and prints only what failed, each full log saved to a file; a step runs inside the running compose service that mounts its folder (`--in <service>`, `--host`), never starting one; validate a change with it rather than chaining the scripts or `docker compose exec` by hand (`--only lint,test`, `--list`, `--slot`, `--failed` to re-run what failed last); `check --fix` runs its fixers and formatters instead (its fix, lint:fix and fmt or format scripts, php-cs-fixer, just fmt, go fmt, cargo fmt, ruff) and lists the files they changed.",
4747
4775
  errs: "`errs [log]`, `errs -- <cmd>`: turns tsc, tsgo, eslint, bun check, bun test, vitest, playwright, phpunit, phpstan and php-cs-fixer output into one `file:line:col: message (rule)` line per error, counting the lines it did not recognise (`--json`); use it instead of reading raw type, lint or test logs.",
4748
4776
  db: '`db "<sql>"`: one read-only statement against the Postgres, MySQL or MariaDB in DATABASE_URL (`-e KEY` for another) or, without one, the compose project\'s running database service (`-s <service>`, `-c <container>` for any container, `-d <database>`), credentials never shown; a write runs on a database whose name ends in `_test` and is printed for the user to run otherwise; `db tables`, `db describe <table>`, `db dbs`; use it instead of `docker exec <container> psql` or `mysql`.',
4749
4777
  ev: "`ev`: .env files read and edited with values masked (`ev list`, `ev get KEY`, `ev grep <regex>`, `ev show <rev>:<file>`, `ev set`, `ev diff`, `ev missing`); `ev audit [dir]` finds env files others can read or git tracks, and compose files writing secrets out; `ev pins [dir]` lists the env vars reaching outside that the tests of an app leave unpinned; `ev redact` masks secrets in piped output, `<cmd> | ev redact`.",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-guard",
3
3
  "type": "module",
4
- "version": "0.14.4",
4
+ "version": "0.14.5",
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.13.4",
40
- "@kaynooo/cli-edit": "0.11.4",
41
- "@kaynooo/cli-env": "0.15.2",
42
- "@kaynooo/cli-git": "0.17.3",
43
- "@kaynooo/cli-kit": "0.46.1",
40
+ "@kaynooo/cli-edit": "0.11.5",
41
+ "@kaynooo/cli-env": "0.15.3",
42
+ "@kaynooo/cli-git": "0.18.2",
43
+ "@kaynooo/cli-kit": "0.46.2",
44
44
  "@kaynooo/cli-out": "0.14.8",
45
- "@kaynooo/cli-pkg": "0.17.3"
45
+ "@kaynooo/cli-pkg": "0.17.4"
46
46
  }
47
47
  }