@oked/sdk 0.6.8 → 0.6.9

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.
@@ -40,8 +40,9 @@ export declare function stripCodeHeredocBodies(command: string): string;
40
40
  /**
41
41
  * Blank the inside of quoted arguments of text commands, for the SHELL-pattern
42
42
  * scans only, so `git commit -m "curl -d sends JSON"` or `grep "curl -X POST"`
43
- * is not read as a POST. A step that pipes on (`echo '…' | sh`) keeps its text,
44
- * because the next command may run it.
43
+ * is not read as a POST. A step that pipes into a command that runs its input
44
+ * (`echo '…' | sh`) keeps its text. A pipe into a reader (`grep "…" | head`)
45
+ * does not run the text, so the text is blanked.
45
46
  */
46
47
  export declare function blankTextCommandArgs(command: string): string;
47
48
  export declare function stripInlineScriptBodies(command: string): string;
package/dist/classify.js CHANGED
@@ -672,7 +672,8 @@ function isEphemeralOnlyDeletion(command, ephemeralVars = new Set()) {
672
672
  const m = command.match(/^(?:sudo\s+)?(?:rm|rmdir|trash|trash-put)\b\s+(.+)$/s);
673
673
  if (!m)
674
674
  return false;
675
- const targets = splitArgs(m[1]).filter((a) => !a.startsWith("-"));
675
+ // A redirect (`2>/dev/null`) is not a target.
676
+ const targets = splitArgs(m[1]).filter((a) => !a.startsWith("-") && !/^(?:\d|&)?>>?\S+$/.test(a));
676
677
  if (targets.length === 0)
677
678
  return false;
678
679
  return targets.every((a) => {
@@ -1016,7 +1017,13 @@ function classifyStageShellEffects(stage, ephemeralVars = new Set()) {
1016
1017
  // NOT a deletion — that's the false positive DELETE_COMMAND_RE avoids.
1017
1018
  if (isEphemeralOnlyDeletion(stage, ephemeralVars))
1018
1019
  return "warning";
1019
- if (DELETE_COMMAND_RE.test(stage.replace(DELETE_LEAD, "")))
1020
+ // rmdir removes only EMPTY folders (it fails on a folder with files), so no
1021
+ // data is lost and `mkdir` undoes it: a reversible local change.
1022
+ const deleteStage = stage.replace(DELETE_LEAD, "");
1023
+ const rmdirArgs = deleteStage.match(/^(?:sudo\s+)?rmdir\b(.*)$/s)?.[1];
1024
+ if (rmdirArgs !== undefined && !DELETE_COMMAND_RE.test(rmdirArgs))
1025
+ return "warning";
1026
+ if (DELETE_COMMAND_RE.test(deleteStage))
1020
1027
  return "high_stakes";
1021
1028
  // Destructive/irreversible single commands, matched at stage start with any
1022
1029
  // leading `sudo ` stripped (so `sudo mkfs …` is still caught, but the word
@@ -1218,16 +1225,31 @@ export function stripCodeHeredocBodies(command) {
1218
1225
  // search pattern, a PR body, printed text. `gh api` is left out: its fields are
1219
1226
  // a request payload (a GraphQL mutation, for example).
1220
1227
  const TEXT_ARG_COMMAND_RE = /^(?:\w+=(?:"[^"]*"|'[^']*'|\S+)\s+)*(?:git|grep|egrep|fgrep|rg|echo|printf|gh(?!\s+api\b))\b/;
1228
+ // A script file run by node/tsx/bun (`node scripts/x.mjs …`), not inline code
1229
+ // (`node -e`). Its quoted long-option values (`--reason "…"`) are text. Its
1230
+ // quoted positional arguments keep their text, because the script may run them.
1231
+ const SCRIPT_FILE_STEP_RE = /^(?:\\\s+)?(?:\w+=(?:"[^"]*"|'[^']*'|\S+)\s+)*(?:node|tsx|bun)\s+(?!-)\S+\.[cm]?[jt]s(?:\s|$)/;
1232
+ const LONG_OPTION_QUOTED_VALUE_RE = /(--[\w-]+(?:=|\s+))('[^']*'|"(?:[^"\\]|\\.)*")/g;
1233
+ // Commands that run the text piped into them as code.
1234
+ const RUNS_PIPED_TEXT_RE = /^(?:sudo\s+)?(?:(?:ba|z|k|da)?sh|xargs|eval|source|\.|node|deno|bun|python\d?(?:\.\d+)?|ruby|perl|psql|mysql|mariadb|sqlite3?)\b/;
1221
1235
  /**
1222
1236
  * Blank the inside of quoted arguments of text commands, for the SHELL-pattern
1223
1237
  * scans only, so `git commit -m "curl -d sends JSON"` or `grep "curl -X POST"`
1224
- * is not read as a POST. A step that pipes on (`echo '…' | sh`) keeps its text,
1225
- * because the next command may run it.
1238
+ * is not read as a POST. A step that pipes into a command that runs its input
1239
+ * (`echo '…' | sh`) keeps its text. A pipe into a reader (`grep "…" | head`)
1240
+ * does not run the text, so the text is blanked.
1226
1241
  */
1227
1242
  export function blankTextCommandArgs(command) {
1228
1243
  return splitTopLevel(command, { pipes: false })
1229
1244
  .map((step) => {
1230
- if (!TEXT_ARG_COMMAND_RE.test(step) || splitTopLevel(step).length > 1)
1245
+ if (SCRIPT_FILE_STEP_RE.test(step)) {
1246
+ if (splitTopLevel(step).slice(1).some((p) => RUNS_PIPED_TEXT_RE.test(p)))
1247
+ return step;
1248
+ return step.replace(LONG_OPTION_QUOTED_VALUE_RE, (_m, opt, q) => opt + q[0] + " ".repeat(Math.max(0, q.length - 2)) + q[0]);
1249
+ }
1250
+ if (!TEXT_ARG_COMMAND_RE.test(step))
1251
+ return step;
1252
+ if (splitTopLevel(step).slice(1).some((p) => RUNS_PIPED_TEXT_RE.test(p)))
1231
1253
  return step;
1232
1254
  // A quoted redirect target (`>> "$HOME/.ssh/authorized_keys"`) is a path, not text.
1233
1255
  return step.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, (q, at) => /[<>]\s*$/.test(step.slice(0, at)) ? q : q[0] + " ".repeat(Math.max(0, q.length - 2)) + q[0]);
package/dist/describe.js CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { existsSync, readFileSync, readdirSync } from "node:fs";
11
11
  import { basename, isAbsolute, join, resolve } from "node:path";
12
- import { blankTextCommandArgs, classify, extractShellWriteOps, splitTopLevel, stripCodeHeredocBodies } from "./classify.js";
12
+ import { blankTextCommandArgs, classify, extractShellWriteOps, splitTopLevel, stripCodeHeredocBodies, stripInlineScriptBodies } from "./classify.js";
13
13
  import { TIER_ORDER } from "./degraded.js";
14
14
  const BODY_PREVIEW_MAX = 200;
15
15
  const COMMAND_INLINE_MAX = 50;
@@ -215,15 +215,24 @@ function summarizeBash(command, sizeBytes, cwd) {
215
215
  // `(.+)$`: without the `m` flag `$` only reaches end-of-string, so a `rm` on
216
216
  // an interior line of a multi-line script (e.g. `rm "$WT/node_modules"` before
217
217
  // a trailing `cd … && git status`) wouldn't match and the card fell back to
218
- // the generic "Run command".
219
- const rmMatch = cmd.match(/\b(?:rm|trash|trash-put|rmdir)\s+(?:(-rf?|-fr|--recursive|-r)\s+)?([^\n]+)/);
218
+ // the generic "Run command". Match the shell text, so `rmdir` in a commit
219
+ // message or a `--reason "…"` value is not a delete.
220
+ const rmMatch = shellText(cmd).match(/\b(rm|trash|trash-put|rmdir)\s+(?:(-rf?|-fr|--recursive|-r)\s+)?([^\n]+)/);
221
+ if (rmMatch && rmMatch[1] === "rmdir") {
222
+ // rmdir removes empty folders only.
223
+ const vars = literalAssignments(cmd);
224
+ const targets = parseRmTargets(rmMatch[3]).map((t) => shortenPath(stripQuotes(expandVars(t, vars))));
225
+ return targets.length <= 1
226
+ ? { title: "Delete empty folder", target: targets[0], kind: "file_delete" }
227
+ : { title: `Delete ${targets.length} empty folders`, target: targets.join("\n"), kind: "file_delete" };
228
+ }
220
229
  if (rmMatch) {
221
230
  // Recursive only with an r/R flag: `rm -f x` deletes one file.
222
- const flags = (rmMatch[1] ? `${rmMatch[1]} ` : "") + rmMatch[2];
231
+ const flags = (rmMatch[2] ? `${rmMatch[2]} ` : "") + rmMatch[3];
223
232
  const recursive = /(?:^|\s)(?:-[a-zA-Z]*[rR][a-zA-Z]*|--recursive)(?=\s|$)/.test(flags.split(/[;&|\n]/)[0]);
224
233
  // `D=/some/dir; rm -f $D/x` shows the real path, not `$D/x`.
225
234
  const vars = literalAssignments(cmd);
226
- const targets = parseRmTargets(rmMatch[2]).map((t) => expandVars(t, vars));
235
+ const targets = parseRmTargets(rmMatch[3]).map((t) => expandVars(t, vars));
227
236
  if (targets.length <= 1) {
228
237
  const target = targets[0] || "files";
229
238
  const sqlExt = !recursive && /\.sql$/i.test(target);
@@ -243,7 +252,7 @@ function summarizeBash(command, sizeBytes, cwd) {
243
252
  };
244
253
  }
245
254
  // git
246
- if (/\bgit\s+push\b/.test(cmd)) {
255
+ if (/\bgit\s+push\b/.test(shellText(cmd))) {
247
256
  // Parse the remote + branch ignoring flags (-u, --force, --set-upstream, …)
248
257
  // so `git push -u origin feat` renders "feat → origin", not "origin → -u".
249
258
  const after = cmd.match(/\bgit\s+push\b(.*)$/s)?.[1] ?? "";
@@ -371,9 +380,9 @@ function summarizeBash(command, sizeBytes, cwd) {
371
380
  return { title: "Install npm dependencies", kind: "npm_install" };
372
381
  if (/\bnpm\s+test\b/.test(cmd))
373
382
  return { title: "Run npm tests", kind: "npm_test" };
374
- if (/\bnpm\s+unpublish\b/.test(cmd))
383
+ if (/\bnpm\s+unpublish\b/.test(shellText(cmd)))
375
384
  return { title: "Unpublish package from npm", kind: "npm_unpublish" };
376
- if (/\bnpx\s+.*\s+deploy\b/.test(cmd))
385
+ if (/\bnpx\s+.*\s+deploy\b/.test(shellText(cmd)))
377
386
  return { title: "Deploy via npx", body: truncateBody(cmd), kind: "npx_deploy" };
378
387
  // sudo / chmod (kill/pkill/killall are handled in command position above,
379
388
  // ahead of the compound catch-all).
@@ -502,9 +511,11 @@ function summarizeGh(cmd) {
502
511
  * Name/version come from the package.json the publish will read: the cwd,
503
512
  * adjusted by a preceding `cd`, a `--workspace`, or a folder argument.
504
513
  */
514
+ const NPM_PUBLISH_STEP_RE = /(?:^|[\n;&|(]|\$\()\s*(?:\w+=\S+\s+)*(?:sudo\s+)?npm\s+publish\b([^\n;&|)]*)/;
505
515
  function summarizeNpmPublish(cmd, cwd) {
506
- const m = cmd.match(/(?:^|[\n;&|(]|\$\()\s*(?:\w+=\S+\s+)*(?:sudo\s+)?npm\s+publish\b([^\n;&|)]*)/);
507
- if (!m)
516
+ const m = cmd.match(NPM_PUBLISH_STEP_RE);
517
+ // `grep "verify\|npm publish" x | head` searches for the words, it does not publish.
518
+ if (!m || !NPM_PUBLISH_STEP_RE.test(shellText(cmd)))
508
519
  return null;
509
520
  const tokens = m[1].trim().split(/\s+/).filter(Boolean).map(stripQuotes);
510
521
  const flags = {};
@@ -1689,7 +1700,7 @@ function summarizeCodeHeredoc(cmd) {
1689
1700
  }
1690
1701
  /** `prisma migrate deploy`: which database, from a DATABASE_URL set in the command. */
1691
1702
  function summarizePrismaDeploy(cmd) {
1692
- if (!/\bprisma\s+migrate\s+deploy\b/.test(cmd))
1703
+ if (!/\bprisma\s+migrate\s+deploy\b/.test(shellText(cmd)))
1693
1704
  return null;
1694
1705
  const url = cmd.match(/DATABASE_URL=["']?([a-z]+:\/\/[^\s"';&|]+)/)?.[1];
1695
1706
  let db;
@@ -1702,6 +1713,11 @@ function summarizePrismaDeploy(cmd) {
1702
1713
  }
1703
1714
  return { title: "Apply Prisma database migrations", target: db, annotation: db ? undefined : "to the database in DATABASE_URL", kind: "sql_migrate" };
1704
1715
  }
1716
+ /** The command as the shell runs it: quoted text arguments and inline script
1717
+ * bodies (`node -e '…'`) blanked, so words in them do not name the card. */
1718
+ function shellText(cmd) {
1719
+ return blankTextCommandArgs(stripInlineScriptBodies(cmd));
1720
+ }
1705
1721
  /** `NAME=value` assignments with a literal value (no `$(…)`, no backticks), in order. */
1706
1722
  function literalAssignments(cmd) {
1707
1723
  const vars = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/sdk",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "OKed SDK - human approval layer for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -45,7 +45,7 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@oked/receipt-core": "0.6.8"
48
+ "@oked/receipt-core": "0.6.9"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^22.13.10",