@kaynooo/cli-guard 0.7.1 → 0.7.2

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 +15 -5
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -933,7 +933,7 @@ var {Glob } = globalThis.Bun;
933
933
  var SESSION_FILES = new Glob("*.json");
934
934
  var ACCOUNT_DIRS = new Glob("*/sessions");
935
935
  // package.json
936
- var version = "0.7.1";
936
+ var version = "0.7.2";
937
937
 
938
938
  // ../kit/src/shell.ts
939
939
  var SEPARATORS = new Set([`
@@ -1728,7 +1728,15 @@ var SHOT_STACK = /\.worktrees\/[^/\s]+\/shot(?:\/|$)|--shot(?:-|$)/;
1728
1728
  var DEVICE_PATH = /^\/(?:dev|proc|sys)\//;
1729
1729
  var STDIN_PATHS = new Set(["-", "/dev/stdin"]);
1730
1730
  var SQL_WRITE = "Statements that write (INSERT, UPDATE, DELETE, DDL, migrations, fixtures) are handed over: list the exact command for the user to run. Only a clearly test-only database runs them directly.";
1731
- var SQL_UNREADABLE = "A file this SQL client is fed cannot be read here (missing, a device, or too large), so what it runs is unknown. Hand over the exact command for the user to run.";
1731
+ var SHELL_SYNTAX = /[$`]/;
1732
+ function sqlUnreadable(path) {
1733
+ let cause = "missing when the command is checked, or too large";
1734
+ if (DEVICE_PATH.test(path))
1735
+ cause = "a device";
1736
+ else if (SHELL_SYNTAX.test(path))
1737
+ cause = "its path holds a variable or substitution, which is not expanded here";
1738
+ return `The SQL client is fed ${path}, which cannot be read here (${cause}), so what it runs is unknown. Write the file with the file edit tool in its own call and give a literal path, or run it on a database named *_test; otherwise hand over the exact command for the user to run.`;
1739
+ }
1732
1740
  function hasWrite(statement) {
1733
1741
  return writes(statement, "postgres").length > 0 || writes(statement, "mysql").length > 0;
1734
1742
  }
@@ -1829,9 +1837,11 @@ async function sqlViolation(command, read) {
1829
1837
  const before = index === 0 ? null : parseCommand(pieces[index - 1]?.command ?? "");
1830
1838
  const isPiped = pieces[index - 1]?.separator === "|";
1831
1839
  const paths = input.files.filter((path) => !STDIN_PATHS.has(path));
1832
- const texts = await Promise.all([...paths, ...isPiped && before?.program === "cat" ? before.args.filter((arg) => !arg.startsWith("-")) : []].map(async (path) => fileText(path, read)));
1833
- if (texts.includes(null))
1834
- return SQL_UNREADABLE;
1840
+ const files = [...paths, ...isPiped && before?.program === "cat" ? before.args.filter((arg) => !arg.startsWith("-")) : []];
1841
+ const texts = await Promise.all(files.map(async (path) => fileText(path, read)));
1842
+ const unreadable = texts.indexOf(null);
1843
+ if (unreadable !== -1)
1844
+ return sqlUnreadable(files[unreadable] ?? "");
1835
1845
  const statements = [
1836
1846
  ...input.statements,
1837
1847
  ...piece.heredocs,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-guard",
3
3
  "type": "module",
4
- "version": "0.7.1",
4
+ "version": "0.7.2",
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,7 +36,7 @@
36
36
  "guard": "$npm_execpath src/cli.ts"
37
37
  },
38
38
  "devDependencies": {
39
- "@kaynooo/cli-db": "0.9.0",
39
+ "@kaynooo/cli-db": "0.9.1",
40
40
  "@kaynooo/cli-edit": "0.4.0",
41
41
  "@kaynooo/cli-env": "0.8.0",
42
42
  "@kaynooo/cli-git": "0.5.1",