@oked/sdk 0.6.24 → 0.6.26

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/README.md CHANGED
@@ -91,9 +91,9 @@ Returns `true` when `GET https://api.oked.ai/health` succeeds within 3 seconds.
91
91
 
92
92
  ### Helpers
93
93
 
94
- - `classify(toolName, toolInput)` returns a risk tier for a tool call. Pass `{ sandboxEnforced: false }` to ask (`review`) before an opaque runner (`cargo test`, `npm test`, `npm run`, `pytest`, `go test`, `make`, `./script.sh`, `node scripts/x.mjs`, `npx`). Omit the option, or pass `true`, and those commands stay `safe`. Claude Code sets this from sandbox settings. Other hosts omit it.
94
+ - `classify(toolName, toolInput)` returns a risk tier for a tool call. `review` and `high_stakes` wait for a person. `rm` of non-temp data, PowerShell `Remove-Item -Recurse`, `rmdir /s`, `rd /s`, `del /s`, `Format-Volume`, `format X:`, a drive root or `$HOME` / `%USERPROFILE%`, `git clean -fdx` and `find -delete` outside a temp or build directory, `git push --force`, and a `curl` GraphQL `volumeDelete` are `high_stakes`. A temp directory or `build` / `dist` / `.next` delete stays `warning`. `bash -c`, `sh -c`, `powershell -Command`, `pwsh -c`, and `cmd /c` are classified by the inner command. Pass `{ sandboxEnforced: false }` to ask (`review`) before an opaque runner (`cargo test`, `npm test`, `npm run`, `pytest`, `go test`, `make`, `./script.sh`, `node scripts/x.mjs`, `npx`). Omit the option, or pass `true`, and those commands stay `safe`. Claude Code sets this from sandbox settings. Other hosts omit it. The runner's child processes are not in the tool call: a `cargo test` that runs `rm -rf ~` is the runner, not the `rm`.
95
95
  - `describe(toolName, toolInput, ctx?)` returns a one-line description.
96
- - `describeFields(toolName, toolInput, ctx?)` returns the card fields.
96
+ - `describeFields(toolName, toolInput, ctx?)` returns the card fields. A production deploy (`vercel --prod`, `netlify deploy --prod`, `fly deploy`, and the same class) has kind `deploy`. The tier stays `high_stakes`. A preview deploy stays `review`.
97
97
 
98
98
  Full type definitions ship in the package (`dist/index.d.ts`).
99
99
 
@@ -1,4 +1,14 @@
1
1
  import type { RiskTier } from "./types.js";
2
+ export interface ProductionDeployCard {
3
+ title: string;
4
+ target?: string;
5
+ }
6
+ /**
7
+ * A production deploy the tier logic already treats as high_stakes.
8
+ * Preview deploys, deletes, help, and dry runs return null.
9
+ * Calling this does not change the tier. describe() uses it for the card.
10
+ */
11
+ export declare function productionDeployCard(stage: string): ProductionDeployCard | null;
2
12
  /**
3
13
  * `sandboxEnforced: false` asks for `review` before an opaque code runner
4
14
  * (a test runner, package script, script file, or npx tool). `true` or omitted
package/dist/classify.js CHANGED
@@ -20,11 +20,15 @@ import { TIER_ORDER } from "./degraded.js";
20
20
  // curl POST/PUT/PATCH with an inline body, other cloud CLI writes
21
21
  // (create, update, upload, preview deploy, kubectl apply/exec).
22
22
  // Tier 4 - high_stakes: push + number matching. Destructive / irreversible /
23
- // external: rm of non-temp data, DROP/TRUNCATE/DELETE FROM,
24
- // git push --force / reset --hard / branch -D, mkfs / dd-to-device /
25
- // shutdown, curl DELETE / file upload / pay-or-send API, ssh/scp,
26
- // npm publish, kill, cloud and cluster deletes, terraform apply /
27
- // pulumi up, production deploys, Stripe CLI writes.
23
+ // external: rm of non-temp data, Windows recursive deletes
24
+ // (Remove-Item -Recurse, rmdir /s, rd /s, del /s), a drive root
25
+ // or home directory, Format-Volume / format X:, DROP/TRUNCATE/
26
+ // DELETE FROM, git push --force / reset --hard / clean -fd /
27
+ // branch -D, find -delete, mkfs / dd-to-device / shutdown,
28
+ // curl DELETE / file upload / pay-or-send API / GraphQL
29
+ // volumeDelete, ssh/scp, npm publish, kill, cloud and cluster
30
+ // deletes, terraform apply / pulumi up, production deploys,
31
+ // Stripe CLI writes.
28
32
  // Tools that are always safe (read-only, no side effects)
29
33
  const SAFE_TOOLS = new Set([
30
34
  "Read",
@@ -184,7 +188,8 @@ const HIGH_STAKES_COMMANDS = [
184
188
  // to `warning` in WARNING_COMMANDS below. Mirrors describe.ts force detection.
185
189
  /\bgit\s+push\b[^\n]*\s(?:--force(?:-with-lease)?|-f)\b/,
186
190
  /\bgit\s+reset\s+--hard\b/,
187
- /\bgit\s+clean\s+-f/,
191
+ // git clean -f is NOT here. It is per-stage (classifyGitCleanStage) so a
192
+ // dry run stays safe and a temp or build-output path stays a warning.
188
193
  /\bgit\s+checkout\s+--\s+\./,
189
194
  /\bgit\s+restore\s+--staged\s+\./,
190
195
  // NOTE: SQL severity (DROP/DELETE FROM/TRUNCATE/…) is intentionally NOT matched
@@ -233,7 +238,8 @@ const HIGH_STAKES_STAGE = [
233
238
  /^dd\b.*\bof=\/dev\//,
234
239
  /^shred\b/,
235
240
  /^truncate\b/, // `truncate -s 0 file` wipes contents
236
- /^find\b.*\s-delete\b/, // `find … -delete` removes matches
241
+ // `find … -delete` is per-stage (classifyFindDelete) so a temp or build
242
+ // path can stay a warning. A find of `.` or any other path stays high_stakes.
237
243
  // Power / system state.
238
244
  /^(shutdown|reboot|halt|poweroff)\b/,
239
245
  // Remote/outward file transfer (almost always a remote target).
@@ -598,6 +604,98 @@ function classifyCloudCliStage(stage) {
598
604
  }
599
605
  return null;
600
606
  }
607
+ /**
608
+ * A production deploy the tier logic already treats as high_stakes.
609
+ * Preview deploys, deletes, help, and dry runs return null.
610
+ * Calling this does not change the tier. describe() uses it for the card.
611
+ */
612
+ export function productionDeployCard(stage) {
613
+ let bare = stage.trim().replace(DELETE_LEAD, "");
614
+ bare = bare.replace(/^(?:\w+=\S+\s+)+/, "");
615
+ const args = splitArgs(bare.replace(CLI_RUNNER_RE, ""));
616
+ const tool = (args.shift() ?? "").replace(/^.*\//, "").replace(/(?<=.)@.*$/, "");
617
+ const sep = args.indexOf("--");
618
+ const head = sep === -1 ? args : args.slice(0, sep);
619
+ if (head.some((arg) => CLI_PREVIEW_ARG_RE.test(arg)))
620
+ return null;
621
+ if (cliPositionals(args)[0] === "help")
622
+ return null;
623
+ const flag = (names) => {
624
+ for (let i = 0; i < args.length; i++) {
625
+ const arg = args[i];
626
+ for (const name of names) {
627
+ if (arg === name && args[i + 1])
628
+ return args[i + 1];
629
+ if (arg.startsWith(`${name}=`))
630
+ return arg.slice(name.length + 1);
631
+ }
632
+ }
633
+ return undefined;
634
+ };
635
+ switch (tool) {
636
+ case "vercel": {
637
+ const [sub, op] = cliPositionals(args, VERCEL_VALUE_FLAGS);
638
+ const prod = args.some((arg, i) => arg === "--prod" || arg === "--target=production" ||
639
+ (arg === "--target" && args[i + 1] === "production"));
640
+ const path = sub !== undefined && sub !== "deploy" && !VERCEL_SUBCOMMANDS.has(sub);
641
+ if ((sub === undefined || sub === "deploy" || path) && prod) {
642
+ return { title: "Deploy to Vercel production", target: path ? sub : undefined };
643
+ }
644
+ if (sub === "redeploy" && prod)
645
+ return { title: "Redeploy on Vercel production" };
646
+ if (sub === "promote")
647
+ return { title: "Promote a Vercel deployment to production", target: op };
648
+ return null;
649
+ }
650
+ case "netlify": {
651
+ const words = cliPositionals(args, new Set(["--site", "--dir", "-d", "--auth", "--filter", "-a", "-s", "-m", "--message", "--alias"]));
652
+ const prod = args.some((arg) => /^(?:--prod|-p|--prodIfUnlocked|--prod-if-unlocked)$/.test(arg));
653
+ if (words[0] === "deploy" && prod)
654
+ return { title: "Deploy to Netlify production", target: flag(["--site", "-s"]) };
655
+ return null;
656
+ }
657
+ case "fly":
658
+ case "flyctl": {
659
+ const words = cliPositionals(args, new Set(["-a", "--app", "-c", "--config", "-r", "--region", "--image", "-t", "--access-token"]));
660
+ if (words[0] === "deploy")
661
+ return { title: "Deploy to Fly", target: flag(["-a", "--app"]) };
662
+ return null;
663
+ }
664
+ case "wrangler": {
665
+ const words = cliPositionals(args, new Set(["-c", "--config", "-e", "--env", "--name"]));
666
+ const name = flag(["--name"]);
667
+ if (words.includes("publish"))
668
+ return { title: "Publish with Wrangler", target: name };
669
+ if (words.includes("deploy"))
670
+ return { title: "Deploy with Wrangler", target: name };
671
+ return null;
672
+ }
673
+ case "firebase": {
674
+ const words = cliPositionals(args, new Set(["-P", "--project", "--only", "--except", "--token"]));
675
+ if (words[0] === "deploy")
676
+ return { title: "Deploy to Firebase", target: flag(["-P", "--project"]) };
677
+ return null;
678
+ }
679
+ case "serverless":
680
+ case "sls":
681
+ return cliPositionals(args)[0] === "deploy" ? { title: "Deploy with Serverless" } : null;
682
+ case "cdk":
683
+ return cliPositionals(args)[0] === "deploy" ? { title: "Deploy with AWS CDK" } : null;
684
+ case "gcloud": {
685
+ const words = cliPositionals(args, new Set(["--project", "--account", "--configuration", "--format", "--verbosity", "--impersonate-service-account"]));
686
+ const local = ["config", "auth", "components", "info", "init", "version", "topic"];
687
+ if (local.includes(words[0] ?? ""))
688
+ return null;
689
+ const verbs = words.slice(1);
690
+ const at = verbs.indexOf("deploy");
691
+ if (at === -1)
692
+ return null;
693
+ return { title: "Deploy with gcloud", target: verbs[at + 1] };
694
+ }
695
+ default:
696
+ return null;
697
+ }
698
+ }
601
699
  /**
602
700
  * `gh api` is curl for GitHub: a mutating method, or fields without a method
603
701
  * (gh then sends a POST), is an outward write like a curl POST. A GraphQL call
@@ -664,10 +762,12 @@ const EPHEMERAL_PATH_RE = /^(?:\/tmp\/|\/var\/tmp\/|\/var\/folders\/|\/private\/
664
762
  // $TMP, $TEMP, ${TMPDIR}, and paths beneath them. Treated as ephemeral since
665
763
  // we can't resolve the value but the intent is unambiguous.
666
764
  const TEMP_VAR_RE = /^\$\{?(?:TMPDIR|TMP|TEMP)\}?(?:\/|$)/;
765
+ // PowerShell `$env:TEMP\foo` and cmd `%TEMP%\foo`. Same idea as $TMPDIR.
766
+ const WIN_TEMP_VAR_RE = /^(?:\$\{?env:(?:TMPDIR|TMP|TEMP)\}?|%(?:TMPDIR|TMP|TEMP)%)(?:[\\/]|$)/i;
667
767
  function isEphemeralPath(filePath) {
668
768
  if (!filePath)
669
769
  return false;
670
- return TEMP_VAR_RE.test(filePath) || EPHEMERAL_PATH_RE.test(filePath);
770
+ return TEMP_VAR_RE.test(filePath) || WIN_TEMP_VAR_RE.test(filePath) || EPHEMERAL_PATH_RE.test(filePath);
671
771
  }
672
772
  // A shell variable assigned from `mktemp` / `mktemp -d` (optionally `export`ed)
673
773
  // at the start of a stage: `EMPTYHOME=$(mktemp -d)`, `T=`mktemp``. Its value is a
@@ -775,10 +875,15 @@ function collectMktempVars(stage, into) {
775
875
  function isEphemeralVar(target, vars) {
776
876
  if (vars.size === 0)
777
877
  return false;
778
- const m = target.match(/^\$\{?(\w+)\}?(\/.*)?$/);
878
+ // `$home` / `$HOME` / `%USERPROFILE%` are the real profile. Windows PowerShell
879
+ // refuses `$home = <temp>` (HOME is constant) and the later Remove-Item still
880
+ // deletes the profile. Never treat those names as a temp binding.
881
+ if (isCatastrophicTarget(target))
882
+ return false;
883
+ const m = target.match(/^\$\{?(\w+)\}?([\\/].*)?$/);
779
884
  if (!m || !vars.has(m[1]))
780
885
  return false;
781
- if (m[2] && m[2].split("/").includes(".."))
886
+ if (m[2] && m[2].split(/[/\\]/).includes(".."))
782
887
  return false;
783
888
  return true;
784
889
  }
@@ -862,15 +967,18 @@ export function classify(toolName, toolInput, options) {
862
967
  const filePath = toolInput.file_path;
863
968
  return isSensitiveWritePath(filePath) ? "review" : "warning";
864
969
  }
865
- // Agent tool - safe. Launching a sub-agent is not itself a side effect, and
866
- // the sub-agent's own tool calls (Bash/Write/Edit/MCP) each fire their own
867
- // PreToolUse hook and get classified independently. Gating the launch on top
868
- // of that just double-prompts — once for the spawn, again for every real
869
- // action the sub-agent takes — so the launch auto-allows.
870
- if (toolName === "Agent")
970
+ // Launching a sub-agent is not itself a side effect. Claude Code runs
971
+ // settings PreToolUse hooks for each tool call the sub-agent makes (the
972
+ // payload includes agent_id and agent_type). Current Claude Code names that
973
+ // tool Agent. Older sessions and Cursor call it Task. The launch stays safe
974
+ // so it is not a second prompt on top of the real action.
975
+ // A command that never arrives as a tool call is invisible. A test runner
976
+ // or a script file can run rm inside the child. See isOpaqueCodeRunner.
977
+ if (toolName === "Agent" || toolName === "Task" || toolName === "Subagent")
871
978
  return "safe";
872
- // Bash commands need deeper analysis
873
- if (toolName === "Bash") {
979
+ // Bash commands need deeper analysis. Claude Code's PowerShell tool uses
980
+ // the same `command` field. On Windows without Git Bash it replaces Bash.
981
+ if (toolName === "Bash" || toolName === "PowerShell") {
874
982
  return classifyBashCommand(toolInput.command, new Set(), sandboxEnforced);
875
983
  }
876
984
  // MCP tools: mcp__<server>__<tool>
@@ -1057,6 +1165,13 @@ const BUILD_OUTPUT_DIRS = new Set(["build", "dist", ".build", "DerivedData", ".n
1057
1165
  // rm/trash whose every target is a relative path inside a build output folder
1058
1166
  // (`rm -rf build/OKed.xcarchive dist`). An absolute path, `..`, a variable or a
1059
1167
  // glob in the first segment can point anywhere, so it stays a real deletion.
1168
+ function isBuildOutputPath(target) {
1169
+ const parts = unquote(target).replace(/\\/g, "/").replace(/^(?:\.\/)+/, "").split("/");
1170
+ // An absolute path, a drive letter, or `..` can point outside the build tree.
1171
+ if (!parts[0] || parts[0].includes(":") || parts.includes(".."))
1172
+ return false;
1173
+ return BUILD_OUTPUT_DIRS.has(parts[0]);
1174
+ }
1060
1175
  function isBuildOutputOnlyDeletion(command) {
1061
1176
  const m = command.match(/^(?:rm|trash|trash-put)\b\s+(.+)$/s);
1062
1177
  if (!m)
@@ -1064,10 +1179,7 @@ function isBuildOutputOnlyDeletion(command) {
1064
1179
  const targets = splitArgs(m[1]).filter((a) => !a.startsWith("-") && !/^(?:\d|&)?>>?\S+$/.test(a));
1065
1180
  if (targets.length === 0)
1066
1181
  return false;
1067
- return targets.every((a) => {
1068
- const parts = unquote(a).replace(/^(?:\.\/)+/, "").split("/");
1069
- return BUILD_OUTPUT_DIRS.has(parts[0]) && !parts.includes("..");
1070
- });
1182
+ return targets.every((a) => isBuildOutputPath(a));
1071
1183
  }
1072
1184
  /**
1073
1185
  * Classifies a single stage that begins with one or more `NAME=value`
@@ -1241,6 +1353,9 @@ function classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced) {
1241
1353
  return i;
1242
1354
  };
1243
1355
  let floor = "safe";
1356
+ // `git -C /tmp/repo clean -fdx` cleans a throwaway repo. Remember that for
1357
+ // the subcommand without leaking TEMP_CWD into later stages of the caller.
1358
+ let repoInTemp = false;
1244
1359
  let i = lead[0].length;
1245
1360
  while (i < stage.length) {
1246
1361
  while (i < stage.length && /\s/.test(stage[i]))
@@ -1251,7 +1366,10 @@ function classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced) {
1251
1366
  i = readToken(i);
1252
1367
  const tok = stage.slice(start, i);
1253
1368
  if (!tok.startsWith("-")) {
1254
- const inner = classifyBashCommand(`git ${stage.slice(start).trim()}`, ephemeralVars, sandboxEnforced);
1369
+ const vars = new Set(ephemeralVars);
1370
+ if (repoInTemp)
1371
+ vars.add(TEMP_CWD);
1372
+ const inner = classifyBashCommand(`git ${stage.slice(start).trim()}`, vars, sandboxEnforced);
1255
1373
  return maxTier(floor, inner);
1256
1374
  }
1257
1375
  let value = "";
@@ -1267,6 +1385,9 @@ function classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced) {
1267
1385
  }
1268
1386
  if ((tok === "-c" || tok.startsWith("-c")) && /^alias\./i.test(value))
1269
1387
  floor = "review";
1388
+ if (tok === "-C" && (isEphemeralPath(value) || isEphemeralVar(value, ephemeralVars) || /^\$\(\s*mktemp\b/.test(value))) {
1389
+ repoInTemp = true;
1390
+ }
1270
1391
  }
1271
1392
  return floor; // `git -C dir` with no subcommand prints help
1272
1393
  }
@@ -1347,19 +1468,269 @@ function classifySshStage(stage, sandboxEnforced) {
1347
1468
  }
1348
1469
  return "review"; // only options / a bare host token → treat as remote access
1349
1470
  }
1471
+ const WRAPPED_SHELLS = new Set(["bash", "sh", "zsh", "ksh", "dash", "pwsh", "powershell", "cmd"]);
1472
+ function shellInvocationName(token) {
1473
+ return commandBase(unquote(token)).replace(/\.exe$/i, "").toLowerCase();
1474
+ }
1350
1475
  /**
1351
- * `sh -c '<shell>'` / `bash -c "<shell>"` (also zsh/ksh/dash, and combined flags
1352
- * like `-lc`) runs the quoted argument AS shell. Recurse on the body so its
1353
- * effect is classified by the same rules — mirrors classifySshStage. Only fires
1354
- * when the shell IS the stage's command; a `-c` flag on another tool (e.g.
1355
- * `grep -c`) is unaffected because the stage doesn't start with a shell name.
1356
- * Returns null if the stage isn't a `sh -c`-style invocation.
1476
+ * `sh -c`, `bash -c` (also zsh/ksh/dash, and combined flags like `-lc`),
1477
+ * `powershell -Command` / `pwsh -c`, and `cmd /c` run the following text as
1478
+ * a command. Recurse so a wipe inside the wrapper is classified by the same
1479
+ * rules. Only when the shell is the stage's command: `grep -c` is not a shell.
1480
+ * Returns null when this is not that shape (a script file stays for the
1481
+ * opaque-runner check). An encoded PowerShell command hides its body, so it
1482
+ * asks (`review`) rather than being treated as safe.
1357
1483
  */
1358
1484
  function classifyShellCStage(stage, sandboxEnforced) {
1359
- const m = stage.match(/^(?:bash|sh|zsh|ksh|dash)\b[^'"]*?\s-[A-Za-z]*c\s+(['"])([\s\S]*?)\1/);
1360
- if (!m)
1485
+ const args = splitArgs(stage);
1486
+ let i = args[0] === "sudo" ? 1 : 0;
1487
+ if (i >= args.length)
1488
+ return null;
1489
+ const name = shellInvocationName(args[i]);
1490
+ if (!WRAPPED_SHELLS.has(name))
1491
+ return null;
1492
+ i++;
1493
+ const run = (body) => {
1494
+ const inner = body.trim();
1495
+ if (!inner || inner === stage.trim())
1496
+ return null;
1497
+ return classifyBashCommand(inner, new Set(), sandboxEnforced);
1498
+ };
1499
+ if (name === "cmd") {
1500
+ while (i < args.length) {
1501
+ const a = args[i];
1502
+ const inline = /^\/[cd]:([\s\S]*)$/i.exec(a);
1503
+ if (inline)
1504
+ return run(inline[1]);
1505
+ if (/^\/[cd]$/i.test(a) || /^-[cd]$/i.test(a)) {
1506
+ const rest = args.slice(i + 1);
1507
+ if (rest.length === 0)
1508
+ return null;
1509
+ return run(rest.join(" "));
1510
+ }
1511
+ i++;
1512
+ }
1513
+ return null;
1514
+ }
1515
+ const ps = name === "powershell" || name === "pwsh";
1516
+ while (i < args.length) {
1517
+ const a = args[i];
1518
+ if (ps && /^-(?:encodedcommand|enc)$/i.test(a))
1519
+ return "review";
1520
+ if (/^-(?:command|c)$/i.test(a) || (!ps && /^-[A-Za-z]*c$/.test(a) && !a.startsWith("--"))) {
1521
+ const rest = args.slice(i + 1);
1522
+ if (rest.length === 0)
1523
+ return null;
1524
+ // powershell -Command takes the rest of the line. bash -c takes one argument.
1525
+ return run(ps ? rest.join(" ") : rest[0]);
1526
+ }
1527
+ if (/^-(?:file|inputformat|if|outputformat|of|executionpolicy|ep|version|workingdirectory|wd|configurationname)$/i.test(a)) {
1528
+ i += 2;
1529
+ continue;
1530
+ }
1531
+ if (a.startsWith("-")) {
1532
+ i++;
1533
+ continue;
1534
+ }
1361
1535
  return null;
1362
- return classifyBashCommand(m[2], new Set(), sandboxEnforced);
1536
+ }
1537
+ return null;
1538
+ }
1539
+ // A whole drive or the home directory. Deleting one of these is the failure
1540
+ // mode behind the public Windows wipes (Antigravity `rmdir /s /q d:\`, Codex
1541
+ // and Cursor quote bugs that collapsed a project path to `C:\` or `D:\`).
1542
+ function isCatastrophicTarget(raw) {
1543
+ let t = unquote(raw).trim().replace(/^\\\\\?\\/, "");
1544
+ if (!t)
1545
+ return false;
1546
+ if (t === "/" || t === "\\" || t === "~" || t === "~/" || t === "~\\")
1547
+ return true;
1548
+ if (/^\$\{?(?:home|env:home|env:userprofile)\}?[\\/]?$/i.test(t))
1549
+ return true;
1550
+ if (/^%(?:userprofile|home)%[\\/]?$/i.test(t))
1551
+ return true;
1552
+ if (/^[A-Za-z]:[\\/]?$/.test(t))
1553
+ return true;
1554
+ // 8.3 short name of a profile (`C:\Users\ALICE~1`), the Claude Code home wipe.
1555
+ if (/^[A-Za-z]:[\\/]Users[\\/][^\\/]+~\d+[\\/]?$/i.test(t))
1556
+ return true;
1557
+ return false;
1558
+ }
1559
+ function isCleanupTarget(target, vars) {
1560
+ const t = unquote(target);
1561
+ if (!t || isCatastrophicTarget(t))
1562
+ return false;
1563
+ if (isEphemeralPath(t) || isEphemeralVar(t, vars) || vars.has(CREATED_PATH + t))
1564
+ return true;
1565
+ if (vars.has(TEMP_CWD) && /^[\w.-][\w./\\-]*$/.test(t) && !t.split(/[/\\]/).includes(".."))
1566
+ return true;
1567
+ return isBuildOutputPath(t);
1568
+ }
1569
+ // `\"` between PowerShell and cmd. The backslash does not escape the quote,
1570
+ // and cmd then sees `\` (the current drive root) as its own argument. That is
1571
+ // openai/codex#57530 and the Cursor Remove-Item / rmdir reports. Do not treat
1572
+ // the visible folder (node_modules, build, Temp) as the real target.
1573
+ function isCollapsedWindowsDelete(stage) {
1574
+ if (!/\\"/.test(stage))
1575
+ return false;
1576
+ if (!/\b(?:Remove-Item|ri|rd|del|erase|rmdir|rm)\b/i.test(stage))
1577
+ return false;
1578
+ return /(?:-Recurse|\s\/s\b|\/s\/q\b|--recursive|-[A-Za-z]*[rR])/i.test(stage);
1579
+ }
1580
+ function isCmdRecurseFlag(arg) {
1581
+ return /^\/s(?:\/[qfa])*$/i.test(arg) || /^\/[qfa]*\/s(?:\/[qfa])*$/i.test(arg);
1582
+ }
1583
+ function isPsRecurseFlag(arg) {
1584
+ return /^-(?:r|re|rec|recu|recur|recurs|recurse)$/i.test(arg);
1585
+ }
1586
+ function windowsDeleteTargets(args) {
1587
+ const out = [];
1588
+ for (let i = 0; i < args.length; i++) {
1589
+ const a = args[i];
1590
+ if (isCmdRecurseFlag(a) || /^\/[qfa]$/i.test(a))
1591
+ continue;
1592
+ if (isPsRecurseFlag(a) || /^-(?:force|f|confirm|whatif|verbose|debug|ea)$/i.test(a))
1593
+ continue;
1594
+ const pathFlag = /^-(?:path|literalpath)$/i.exec(a);
1595
+ if (pathFlag) {
1596
+ if (args[i + 1])
1597
+ out.push(unquote(args[++i]));
1598
+ continue;
1599
+ }
1600
+ const inline = /^-(?:path|literalpath):(.+)$/i.exec(a);
1601
+ if (inline) {
1602
+ out.push(unquote(inline[1]));
1603
+ continue;
1604
+ }
1605
+ if (/^-(?:filter|include|exclude|erroraction|warningaction|informationaction|errorvariable|warningvariable|outvariable|outbuffer|pipelinevariable|credential|stream|confirm|informationvariable)$/i.test(a)) {
1606
+ i++;
1607
+ continue;
1608
+ }
1609
+ if (a.startsWith("-"))
1610
+ continue;
1611
+ if (/^(?:\d|&)?>>?\S+$/.test(a))
1612
+ continue;
1613
+ out.push(unquote(a));
1614
+ }
1615
+ return out;
1616
+ }
1617
+ function tierOfWindowsDelete(invocation, ephemeralVars) {
1618
+ const args = splitArgs(invocation);
1619
+ const cmd = (args[0] ?? "").replace(/\.exe$/i, "").toLowerCase();
1620
+ if (!/^(?:remove-item|ri|rd|del|erase|rmdir)$/.test(cmd))
1621
+ return null;
1622
+ const rest = args.slice(1);
1623
+ const recursive = rest.some((a) => isCmdRecurseFlag(a) || isPsRecurseFlag(a));
1624
+ const targets = windowsDeleteTargets(rest);
1625
+ if (targets.some((t) => isCatastrophicTarget(t)))
1626
+ return "high_stakes";
1627
+ if (!recursive) {
1628
+ // rmdir/rd without /s only remove empty directories. del, erase, and
1629
+ // Remove-Item delete the named files even without -Recurse.
1630
+ if (cmd === "rmdir" || cmd === "rd")
1631
+ return null;
1632
+ }
1633
+ if (targets.length === 0)
1634
+ return "high_stakes";
1635
+ if (targets.every((t) => isCleanupTarget(t, ephemeralVars)))
1636
+ return "warning";
1637
+ return "high_stakes";
1638
+ }
1639
+ // PowerShell and cmd deletes, including one nested after `{` (`if (…) { Remove-Item … }`).
1640
+ function classifyWindowsDestruction(stage, ephemeralVars) {
1641
+ const lead = stage.replace(DELETE_LEAD, "");
1642
+ const re = /(?:^|[\n`({;]|\$\()\s*((?:Remove-Item|ri|rd|del|erase|rmdir)\b[\s\S]*?)(?=$|[;|&\n}])/gi;
1643
+ let worst = null;
1644
+ for (const match of lead.matchAll(re)) {
1645
+ const tier = tierOfWindowsDelete(match[1], ephemeralVars);
1646
+ if (tier)
1647
+ worst = worst ? maxTier(worst, tier) : tier;
1648
+ }
1649
+ return worst;
1650
+ }
1651
+ function classifyFindDelete(stage, ephemeralVars) {
1652
+ if (!/^find\b/.test(stage) || !/(?:^|\s)-delete\b/.test(stage))
1653
+ return null;
1654
+ const paths = [];
1655
+ for (const arg of splitArgs(stage).slice(1)) {
1656
+ if (arg.startsWith("-"))
1657
+ break;
1658
+ paths.push(unquote(arg));
1659
+ }
1660
+ const targets = paths.length > 0 ? paths : ["."];
1661
+ if (targets.every((t) => isCleanupTarget(t, ephemeralVars)))
1662
+ return "warning";
1663
+ return "high_stakes";
1664
+ }
1665
+ function classifyGitCleanStage(stage, ephemeralVars) {
1666
+ const match = /^git\s+clean\b([\s\S]*)$/.exec(stage);
1667
+ if (!match)
1668
+ return null;
1669
+ const args = splitArgs(match[1]);
1670
+ let force = false;
1671
+ let dry = false;
1672
+ const paths = [];
1673
+ for (let i = 0; i < args.length; i++) {
1674
+ const arg = args[i];
1675
+ if (arg === "--") {
1676
+ paths.push(...args.slice(i + 1).map(unquote));
1677
+ break;
1678
+ }
1679
+ if (arg === "--force") {
1680
+ force = true;
1681
+ continue;
1682
+ }
1683
+ if (arg === "--dry-run" || arg === "--dryrun") {
1684
+ dry = true;
1685
+ continue;
1686
+ }
1687
+ if (arg === "--exclude" || arg === "-e") {
1688
+ i++;
1689
+ continue;
1690
+ }
1691
+ if (arg.startsWith("--exclude="))
1692
+ continue;
1693
+ if (arg.startsWith("--"))
1694
+ continue;
1695
+ if (arg.startsWith("-") && arg.length > 1) {
1696
+ const flags = arg.slice(1);
1697
+ if (flags.includes("n"))
1698
+ dry = true;
1699
+ if (flags.includes("f"))
1700
+ force = true;
1701
+ if (flags.includes("e"))
1702
+ i++;
1703
+ continue;
1704
+ }
1705
+ paths.push(unquote(arg));
1706
+ }
1707
+ if (!force || dry)
1708
+ return "safe";
1709
+ if (paths.length === 0)
1710
+ return ephemeralVars.has(TEMP_CWD) ? "warning" : "high_stakes";
1711
+ if (paths.every((p) => isCleanupTarget(p, ephemeralVars)))
1712
+ return "warning";
1713
+ return "high_stakes";
1714
+ }
1715
+ function isDiskFormat(stage) {
1716
+ if (/^format-volume\b/i.test(stage)) {
1717
+ // -WhatIf prints the plan and does not format.
1718
+ if (/(?:^|\s)-wh(?:a(?:t(?:i(?:f)?)?)?)?\b/i.test(stage))
1719
+ return false;
1720
+ return true;
1721
+ }
1722
+ // `format C:` / `format D: /q`. Not `npm run format`, `gofmt`, or `cargo fmt`.
1723
+ return /^format(?:\.com)?\s+[A-Za-z]:/i.test(stage);
1724
+ }
1725
+ // PocketOS: curl POST of a Railway GraphQL `volumeDelete` mutation. The body
1726
+ // is data for every other curl rule, so this looks for that mutation only.
1727
+ function isInfraVolumeDeleteCurl(command) {
1728
+ const stage = command.trim();
1729
+ if (!/^(?:(?:sudo|command)\s+)*(?:\w+=\S+\s+)*curl\b/.test(stage))
1730
+ return false;
1731
+ if (!/\bvolumeDelete\b/i.test(stage))
1732
+ return false;
1733
+ return /graphql|railway\.app|backboard\./i.test(stage);
1363
1734
  }
1364
1735
  // A curl/wget whose target host is loopback (localhost, 127.0.0.0/8, 0.0.0.0,
1365
1736
  // ::1). A request to a server on this machine is a LOCAL action, not an outward
@@ -1462,6 +1833,10 @@ function classifyBashCommand(command, ephemeralVars = new Set(), sandboxEnforced
1462
1833
  // shell pass short-circuits to `safe` (e.g. an assignment-prefixed node -e).
1463
1834
  const sql = findSqlInCommand(intact);
1464
1835
  const sqlTier = sql ? classifySqlSeverity(sql) : "safe";
1836
+ // GraphQL volumeDelete lives in the curl body, which the shell scan blanks.
1837
+ // Read it from the intact command. A normal POST stays review below.
1838
+ if (isInfraVolumeDeleteCurl(intact))
1839
+ return "high_stakes";
1465
1840
  return maxTier(maxTier(sqlTier, pipesToShell ? "review" : "safe"), classifyStageShellEffects(stripped, ephemeralVars, sandboxEnforced));
1466
1841
  }
1467
1842
  /**
@@ -1739,6 +2114,11 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
1739
2114
  // → warning; any non-temp target (or the temp root itself) → high_stakes.
1740
2115
  // A delete word sitting in an argument (filename, branch name, echo text) is
1741
2116
  // NOT a deletion — that's the false positive DELETE_COMMAND_RE avoids.
2117
+ // `\"` in a recursive delete is the PowerShell/cmd quoting collapse. The
2118
+ // visible path is not the path cmd will delete. Ask before temp/build
2119
+ // downgrades can hide it.
2120
+ if (isCollapsedWindowsDelete(stage))
2121
+ return "high_stakes";
1742
2122
  if (isEphemeralOnlyDeletion(stage, ephemeralVars))
1743
2123
  return "warning";
1744
2124
  // `git -C repo …` / `git -c k=v …`: classify the subcommand without the
@@ -1746,13 +2126,18 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
1746
2126
  const gitTier = classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced);
1747
2127
  if (gitTier !== null)
1748
2128
  return gitTier;
2129
+ const winTier = classifyWindowsDestruction(stage, ephemeralVars);
2130
+ if (winTier)
2131
+ return winTier;
1749
2132
  if (isBuildOutputOnlyDeletion(stage.replace(DELETE_LEAD, "")))
1750
2133
  return "warning";
1751
2134
  // rmdir removes only EMPTY folders (it fails on a folder with files), so no
1752
2135
  // data is lost and `mkdir` undoes it: a reversible local change.
2136
+ // `rmdir /s` and `rmdir -Recurse` are recursive Windows deletes, handled above.
1753
2137
  const deleteStage = stage.replace(DELETE_LEAD, "");
1754
2138
  const rmdirArgs = deleteStage.match(/^(?:sudo\s+)?rmdir\b(.*)$/s)?.[1];
1755
- if (rmdirArgs !== undefined && !DELETE_COMMAND_RE.test(rmdirArgs))
2139
+ if (rmdirArgs !== undefined && !DELETE_COMMAND_RE.test(rmdirArgs) &&
2140
+ !/(?:^|\s)\/s\b|(?:^|\s)-r(?:ecurse)?\b/i.test(rmdirArgs))
1756
2141
  return "warning";
1757
2142
  if (DELETE_COMMAND_RE.test(deleteStage))
1758
2143
  return "high_stakes";
@@ -1776,6 +2161,14 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
1776
2161
  return "review";
1777
2162
  if (/^railway\s/.test(bareStage) && PREVIEW_FLAG_RE.test(bareStage))
1778
2163
  return "safe";
2164
+ const findTier = classifyFindDelete(bareStage, ephemeralVars);
2165
+ if (findTier)
2166
+ return findTier;
2167
+ const gitCleanTier = classifyGitCleanStage(bareStage, ephemeralVars);
2168
+ if (gitCleanTier)
2169
+ return gitCleanTier;
2170
+ if (isDiskFormat(bareStage))
2171
+ return "high_stakes";
1779
2172
  for (const pattern of HIGH_STAKES_STAGE) {
1780
2173
  if (pattern.test(bareStage))
1781
2174
  return "high_stakes";
@@ -1820,11 +2213,10 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
1820
2213
  const sshTier = classifySshStage(stage, sandboxEnforced);
1821
2214
  if (sshTier !== null)
1822
2215
  return sshTier;
1823
- // `sh -c '<shell>'` / `bash -c "<shell>"` runs the quoted argument AS shell —
1824
- // recurse so its effect is classified by the same rules (mirrors ssh). This
1825
- // is why the command-position delete scan above can ignore quoted text: a real
1826
- // shell-out like `bash -c 'rm -rf /important'` is caught HERE, by re-running
1827
- // the body as a command, while `echo 'rm …'` (data) is not.
2216
+ // `sh -c` / `bash -c`, `powershell -Command` / `pwsh -c`, and `cmd /c` run
2217
+ // the following text as a command. Recurse so its effect is classified by
2218
+ // the same rules (mirrors ssh). A real shell-out like `bash -c 'rm -rf /important'`
2219
+ // or `cmd /c rmdir /s /q d:\` is caught here. `echo 'rm …'` is data, not a shell-out.
1828
2220
  const shellCTier = classifyShellCStage(stage, sandboxEnforced);
1829
2221
  if (shellCTier !== null)
1830
2222
  return shellCTier;
package/dist/describe.js CHANGED
@@ -10,7 +10,7 @@
10
10
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
11
11
  import { homedir } from "node:os";
12
12
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
13
- import { blankTextCommandArgs, classify, classifyBashSteps, extractShellWriteOps, splitTopLevel, stripCodeHeredocBodies, stripInlineScriptBodies } from "./classify.js";
13
+ import { blankTextCommandArgs, classify, classifyBashSteps, extractShellWriteOps, productionDeployCard, splitTopLevel, stripCodeHeredocBodies, stripInlineScriptBodies } from "./classify.js";
14
14
  import { TIER_ORDER } from "./degraded.js";
15
15
  const BODY_PREVIEW_MAX = 200;
16
16
  const COMMAND_INLINE_MAX = 50;
@@ -252,8 +252,11 @@ function summarizeBash(command, sizeBytes, cwd, sandboxEnforced) {
252
252
  // a trailing `cd … && git status`) wouldn't match and the card fell back to
253
253
  // the generic "Run command". Match the shell text, so `rmdir` in a commit
254
254
  // message or a `--reason "…"` value is not a delete.
255
- const rmMatch = shellText(cmd).match(/\b(rm|trash|trash-put|rmdir)\s+(?:(-rf?|-fr|--recursive|-r)\s+)?([^\n]+)/);
256
- if (rmMatch && rmMatch[1] === "rmdir") {
255
+ const rmMatch = shellText(cmd).match(/\b(rm|trash|trash-put|rmdir|rd|del|erase|Remove-Item|ri)\s+(?:(-rf?|-fr|--recursive|-r)\s+)?([^\n]+)/i);
256
+ const winRecursive = rmMatch
257
+ ? /(?:^|\s)\/s\b|(?:^|\s)-Recurse\b|(?:^|\s)-r\b/i.test(rmMatch[3])
258
+ : false;
259
+ if (rmMatch && /^(?:rmdir|rd)$/i.test(rmMatch[1]) && !winRecursive) {
257
260
  // rmdir removes empty folders only.
258
261
  const vars = literalAssignments(cmd);
259
262
  const targets = parseRmTargets(rmMatch[3]).map((t) => shortenPath(stripQuotes(expandVars(t, vars))));
@@ -264,7 +267,7 @@ function summarizeBash(command, sizeBytes, cwd, sandboxEnforced) {
264
267
  if (rmMatch) {
265
268
  // Recursive only with an r/R flag: `rm -f x` deletes one file.
266
269
  const flags = (rmMatch[2] ? `${rmMatch[2]} ` : "") + rmMatch[3];
267
- const recursive = /(?:^|\s)(?:-[a-zA-Z]*[rR][a-zA-Z]*|--recursive)(?=\s|$)/.test(flags.split(/[;&|\n]/)[0]);
270
+ const recursive = winRecursive || /(?:^|\s)(?:-[a-zA-Z]*[rR][a-zA-Z]*|--recursive)(?=\s|$)/.test(flags.split(/[;&|\n]/)[0]);
268
271
  // `D=/some/dir; rm -f $D/x` shows the real path, not `$D/x`.
269
272
  const vars = literalAssignments(cmd);
270
273
  const targets = parseRmTargets(rmMatch[3]).map((t) => expandVars(t, vars));
@@ -334,7 +337,7 @@ function summarizeBash(command, sizeBytes, cwd, sandboxEnforced) {
334
337
  const GIT_RESET_RE = /\bgit\s+(?:-C\s+\S+\s+)?reset\s+--hard\b/;
335
338
  if (GIT_RESET_RE.test(cmd))
336
339
  return { title: `Hard reset${inRepo(GIT_RESET_RE)}, discard all local changes`, kind: "git_reset_hard" };
337
- const GIT_CLEAN_RE = /\bgit\s+(?:-C\s+\S+\s+)?clean\s+-f/;
340
+ const GIT_CLEAN_RE = /\bgit\s+(?:-C\s+\S+\s+)?clean\s+(?:-\S+\s+)*(?:--force|-[^\s]*f)/;
338
341
  if (GIT_CLEAN_RE.test(cmd))
339
342
  return { title: `Remove all untracked files${inRepo(GIT_CLEAN_RE)}`, kind: "git_clean" };
340
343
  const GIT_CHECKOUT_RE = /\bgit\s+(?:-C\s+\S+\s+)?checkout\s+--\s+\./;
@@ -446,6 +449,11 @@ function summarizeBash(command, sizeBytes, cwd, sandboxEnforced) {
446
449
  return { title: "Unpublish package from npm", kind: "npm_unpublish" };
447
450
  if (/\bnpx\s+.*\s+deploy\b/.test(shellText(cmd)))
448
451
  return { title: "Deploy via npx", body: truncateBody(cmd), kind: "npx_deploy" };
452
+ // Production deploys (vercel --prod, fly deploy, and the same class).
453
+ // The tier already comes from classify(). This only names the card.
454
+ const prodDeploy = productionDeployCard(cmd);
455
+ if (prodDeploy)
456
+ return { title: prodDeploy.title, target: prodDeploy.target, kind: "deploy" };
449
457
  // sudo / chmod (kill/pkill/killall are handled in command position above,
450
458
  // ahead of the compound catch-all).
451
459
  if (/\bsudo\b/.test(cmd)) {
@@ -1764,7 +1772,9 @@ function parseRmTargets(argsString) {
1764
1772
  i++;
1765
1773
  token = str.slice(start, i);
1766
1774
  }
1767
- if (token && !token.startsWith("-")) {
1775
+ // cmd delete switches (`/s`, `/q`) are flags, not paths. A longer token
1776
+ // (`/src`) is a path and stays.
1777
+ if (token && !token.startsWith("-") && !/^\/[sqfa]$/i.test(token)) {
1768
1778
  targets.push(token);
1769
1779
  }
1770
1780
  }
package/dist/kinds.d.ts CHANGED
@@ -6,5 +6,5 @@
6
6
  * pattern maps to a kind, so historical rows stay attributable to the
7
7
  * classifier that produced them.
8
8
  */
9
- export declare const CLASSIFIER_VERSION = "v3";
9
+ export declare const CLASSIFIER_VERSION = "v4";
10
10
  export type OperationKind = "file_create" | "file_append" | "file_edit" | "file_touch" | "file_copy" | "file_move" | "file_delete" | "sql_drop" | "sql_truncate" | "sql_alter" | "sql_create" | "sql_delete_rows" | "sql_delete_all_rows" | "sql_update_rows" | "sql_update_every_row" | "sql_insert" | "sql_query" | "sql_migrate" | "git_push" | "git_force_push" | "git_reset_hard" | "git_clean" | "git_checkout" | "git_restore" | "git_commit" | "git_pr_create" | "git_pr_merge" | "git_pr_write" | "gh_write" | "git_branch_delete" | "deploy" | "ssh_remote" | "http_get" | "http_post" | "http_put" | "http_delete" | "http_pipe_to_shell" | "docker_up" | "docker_down" | "docker_rm" | "docker_rmi" | "docker_prune" | "npm_install" | "npm_run" | "npm_test" | "npm_publish" | "npm_unpublish" | "npx_deploy" | "kill_process" | "sudo" | "chmod_777" | "email_send" | "email_delete" | "email_purge" | "payment_charge" | "payment_create" | "chat_message" | "mcp_delete" | "mcp_update" | "mcp_create" | "mcp_post" | "mcp_publish" | "mcp_send" | "mcp_submit_form" | "mcp_fill" | "mcp_submit" | "mcp_query" | "browser_navigate" | "browser_interact" | "browser_script" | "browser_dev_server" | "folder_access" | "session_control" | "session_housekeeping" | "session_start" | "simulator" | "script_run" | "worktree" | "schedule" | "agent_message" | "web_fetch" | "monitor" | "artifact" | "agent_launch" | "shell_pipeline" | "unknown_bash" | "unknown_tool";
package/dist/kinds.js CHANGED
@@ -6,4 +6,4 @@
6
6
  * pattern maps to a kind, so historical rows stay attributable to the
7
7
  * classifier that produced them.
8
8
  */
9
- export const CLASSIFIER_VERSION = "v3";
9
+ export const CLASSIFIER_VERSION = "v4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/sdk",
3
- "version": "0.6.24",
3
+ "version": "0.6.26",
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.24"
48
+ "@oked/receipt-core": "0.6.26"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^26.6.5",