@oked/sdk 0.6.23 → 0.6.25

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,7 +91,7 @@ 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
96
  - `describeFields(toolName, toolInput, ctx?)` returns the card fields.
97
97
 
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).
@@ -607,6 +613,11 @@ function classifyGhApiStage(stage) {
607
613
  if (!/^gh\s+api\b/.test(stage))
608
614
  return null;
609
615
  const method = stage.match(/\s(?:-X|--method)(?:\s+|=)?([A-Za-z]+)\b/)?.[1]?.toUpperCase();
616
+ // A POST to `repos/<owner>/<repo>/pulls` opens a PR. It leaves the machine,
617
+ // but a PR can be closed, so it asks without Face ID.
618
+ if ((!method || method === "POST") && /\s['"]?\/?repos\/[\w.-]+\/[\w.-]+\/pulls['"]?(?:\s|$)/.test(stage)
619
+ && (method === "POST" || /\s(?:-f|-F|--field|--raw-field|--input)(?:\s|=)/.test(stage)))
620
+ return "review";
610
621
  if (method && method !== "GET" && method !== "HEAD")
611
622
  return "high_stakes";
612
623
  if (/^gh\s+api\s+graphql\b/.test(stage))
@@ -659,10 +670,12 @@ const EPHEMERAL_PATH_RE = /^(?:\/tmp\/|\/var\/tmp\/|\/var\/folders\/|\/private\/
659
670
  // $TMP, $TEMP, ${TMPDIR}, and paths beneath them. Treated as ephemeral since
660
671
  // we can't resolve the value but the intent is unambiguous.
661
672
  const TEMP_VAR_RE = /^\$\{?(?:TMPDIR|TMP|TEMP)\}?(?:\/|$)/;
673
+ // PowerShell `$env:TEMP\foo` and cmd `%TEMP%\foo`. Same idea as $TMPDIR.
674
+ const WIN_TEMP_VAR_RE = /^(?:\$\{?env:(?:TMPDIR|TMP|TEMP)\}?|%(?:TMPDIR|TMP|TEMP)%)(?:[\\/]|$)/i;
662
675
  function isEphemeralPath(filePath) {
663
676
  if (!filePath)
664
677
  return false;
665
- return TEMP_VAR_RE.test(filePath) || EPHEMERAL_PATH_RE.test(filePath);
678
+ return TEMP_VAR_RE.test(filePath) || WIN_TEMP_VAR_RE.test(filePath) || EPHEMERAL_PATH_RE.test(filePath);
666
679
  }
667
680
  // A shell variable assigned from `mktemp` / `mktemp -d` (optionally `export`ed)
668
681
  // at the start of a stage: `EMPTYHOME=$(mktemp -d)`, `T=`mktemp``. Its value is a
@@ -720,10 +733,23 @@ const CREATED_PATH = "path:";
720
733
  const TEMP_CWD = "cwd:temp";
721
734
  // An earlier stage exported a DATABASE_URL on this machine (see isLocalPrismaDeploy).
722
735
  const LOCAL_DB = "db:local";
736
+ // `pid:<NAME>`: an earlier stage set NAME to `$!`, the PID of a job this same
737
+ // command started in the background (`node mock.mjs & MP=$!`).
738
+ const BG_PID = "pid:";
739
+ // `kill $MP` (or `kill "${MP}"`) where an earlier stage set MP=$!: it stops only
740
+ // the background job that this same command started. Nothing outside the
741
+ // command is lost, so it is a reversible local change.
742
+ function isOwnJobKill(stage, vars) {
743
+ const m = stage.match(/^kill\s+(?:-\w+\s+)*"?\$\{?(\w+)\}?"?\s*(?:2>\s*\/dev\/null)?$/);
744
+ return !!m && vars.has(BG_PID + m[1]);
745
+ }
723
746
  function noteEphemeralEffects(stage, into) {
724
747
  const assign = stage.match(/^(?:export\s+)?(\w+)=("[^"$`]*"|'[^']*'|[^\s;&|$`'"()]+)$/);
725
748
  if (assign && isEphemeralPath(unquote(assign[2])))
726
749
  into.add(assign[1]);
750
+ const bgPid = stage.match(/(?:^|&\s*)(?:export\s+)?(\w+)=\$!$/);
751
+ if (bgPid)
752
+ into.add(BG_PID + bgPid[1]);
727
753
  for (const op of extractShellWriteOps(stage)) {
728
754
  if (op.kind === "create" || op.kind === "copy" || op.kind === "touch")
729
755
  into.add(CREATED_PATH + unquote(op.target));
@@ -757,10 +783,15 @@ function collectMktempVars(stage, into) {
757
783
  function isEphemeralVar(target, vars) {
758
784
  if (vars.size === 0)
759
785
  return false;
760
- const m = target.match(/^\$\{?(\w+)\}?(\/.*)?$/);
786
+ // `$home` / `$HOME` / `%USERPROFILE%` are the real profile. Windows PowerShell
787
+ // refuses `$home = <temp>` (HOME is constant) and the later Remove-Item still
788
+ // deletes the profile. Never treat those names as a temp binding.
789
+ if (isCatastrophicTarget(target))
790
+ return false;
791
+ const m = target.match(/^\$\{?(\w+)\}?([\\/].*)?$/);
761
792
  if (!m || !vars.has(m[1]))
762
793
  return false;
763
- if (m[2] && m[2].split("/").includes(".."))
794
+ if (m[2] && m[2].split(/[/\\]/).includes(".."))
764
795
  return false;
765
796
  return true;
766
797
  }
@@ -844,15 +875,18 @@ export function classify(toolName, toolInput, options) {
844
875
  const filePath = toolInput.file_path;
845
876
  return isSensitiveWritePath(filePath) ? "review" : "warning";
846
877
  }
847
- // Agent tool - safe. Launching a sub-agent is not itself a side effect, and
848
- // the sub-agent's own tool calls (Bash/Write/Edit/MCP) each fire their own
849
- // PreToolUse hook and get classified independently. Gating the launch on top
850
- // of that just double-prompts — once for the spawn, again for every real
851
- // action the sub-agent takes — so the launch auto-allows.
852
- if (toolName === "Agent")
878
+ // Launching a sub-agent is not itself a side effect. Claude Code runs
879
+ // settings PreToolUse hooks for each tool call the sub-agent makes (the
880
+ // payload includes agent_id and agent_type). Current Claude Code names that
881
+ // tool Agent. Older sessions and Cursor call it Task. The launch stays safe
882
+ // so it is not a second prompt on top of the real action.
883
+ // A command that never arrives as a tool call is invisible. A test runner
884
+ // or a script file can run rm inside the child. See isOpaqueCodeRunner.
885
+ if (toolName === "Agent" || toolName === "Task" || toolName === "Subagent")
853
886
  return "safe";
854
- // Bash commands need deeper analysis
855
- if (toolName === "Bash") {
887
+ // Bash commands need deeper analysis. Claude Code's PowerShell tool uses
888
+ // the same `command` field. On Windows without Git Bash it replaces Bash.
889
+ if (toolName === "Bash" || toolName === "PowerShell") {
856
890
  return classifyBashCommand(toolInput.command, new Set(), sandboxEnforced);
857
891
  }
858
892
  // MCP tools: mcp__<server>__<tool>
@@ -1039,6 +1073,13 @@ const BUILD_OUTPUT_DIRS = new Set(["build", "dist", ".build", "DerivedData", ".n
1039
1073
  // rm/trash whose every target is a relative path inside a build output folder
1040
1074
  // (`rm -rf build/OKed.xcarchive dist`). An absolute path, `..`, a variable or a
1041
1075
  // glob in the first segment can point anywhere, so it stays a real deletion.
1076
+ function isBuildOutputPath(target) {
1077
+ const parts = unquote(target).replace(/\\/g, "/").replace(/^(?:\.\/)+/, "").split("/");
1078
+ // An absolute path, a drive letter, or `..` can point outside the build tree.
1079
+ if (!parts[0] || parts[0].includes(":") || parts.includes(".."))
1080
+ return false;
1081
+ return BUILD_OUTPUT_DIRS.has(parts[0]);
1082
+ }
1042
1083
  function isBuildOutputOnlyDeletion(command) {
1043
1084
  const m = command.match(/^(?:rm|trash|trash-put)\b\s+(.+)$/s);
1044
1085
  if (!m)
@@ -1046,10 +1087,7 @@ function isBuildOutputOnlyDeletion(command) {
1046
1087
  const targets = splitArgs(m[1]).filter((a) => !a.startsWith("-") && !/^(?:\d|&)?>>?\S+$/.test(a));
1047
1088
  if (targets.length === 0)
1048
1089
  return false;
1049
- return targets.every((a) => {
1050
- const parts = unquote(a).replace(/^(?:\.\/)+/, "").split("/");
1051
- return BUILD_OUTPUT_DIRS.has(parts[0]) && !parts.includes("..");
1052
- });
1090
+ return targets.every((a) => isBuildOutputPath(a));
1053
1091
  }
1054
1092
  /**
1055
1093
  * Classifies a single stage that begins with one or more `NAME=value`
@@ -1223,6 +1261,9 @@ function classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced) {
1223
1261
  return i;
1224
1262
  };
1225
1263
  let floor = "safe";
1264
+ // `git -C /tmp/repo clean -fdx` cleans a throwaway repo. Remember that for
1265
+ // the subcommand without leaking TEMP_CWD into later stages of the caller.
1266
+ let repoInTemp = false;
1226
1267
  let i = lead[0].length;
1227
1268
  while (i < stage.length) {
1228
1269
  while (i < stage.length && /\s/.test(stage[i]))
@@ -1233,7 +1274,10 @@ function classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced) {
1233
1274
  i = readToken(i);
1234
1275
  const tok = stage.slice(start, i);
1235
1276
  if (!tok.startsWith("-")) {
1236
- const inner = classifyBashCommand(`git ${stage.slice(start).trim()}`, ephemeralVars, sandboxEnforced);
1277
+ const vars = new Set(ephemeralVars);
1278
+ if (repoInTemp)
1279
+ vars.add(TEMP_CWD);
1280
+ const inner = classifyBashCommand(`git ${stage.slice(start).trim()}`, vars, sandboxEnforced);
1237
1281
  return maxTier(floor, inner);
1238
1282
  }
1239
1283
  let value = "";
@@ -1249,6 +1293,9 @@ function classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced) {
1249
1293
  }
1250
1294
  if ((tok === "-c" || tok.startsWith("-c")) && /^alias\./i.test(value))
1251
1295
  floor = "review";
1296
+ if (tok === "-C" && (isEphemeralPath(value) || isEphemeralVar(value, ephemeralVars) || /^\$\(\s*mktemp\b/.test(value))) {
1297
+ repoInTemp = true;
1298
+ }
1252
1299
  }
1253
1300
  return floor; // `git -C dir` with no subcommand prints help
1254
1301
  }
@@ -1329,19 +1376,269 @@ function classifySshStage(stage, sandboxEnforced) {
1329
1376
  }
1330
1377
  return "review"; // only options / a bare host token → treat as remote access
1331
1378
  }
1379
+ const WRAPPED_SHELLS = new Set(["bash", "sh", "zsh", "ksh", "dash", "pwsh", "powershell", "cmd"]);
1380
+ function shellInvocationName(token) {
1381
+ return commandBase(unquote(token)).replace(/\.exe$/i, "").toLowerCase();
1382
+ }
1332
1383
  /**
1333
- * `sh -c '<shell>'` / `bash -c "<shell>"` (also zsh/ksh/dash, and combined flags
1334
- * like `-lc`) runs the quoted argument AS shell. Recurse on the body so its
1335
- * effect is classified by the same rules — mirrors classifySshStage. Only fires
1336
- * when the shell IS the stage's command; a `-c` flag on another tool (e.g.
1337
- * `grep -c`) is unaffected because the stage doesn't start with a shell name.
1338
- * Returns null if the stage isn't a `sh -c`-style invocation.
1384
+ * `sh -c`, `bash -c` (also zsh/ksh/dash, and combined flags like `-lc`),
1385
+ * `powershell -Command` / `pwsh -c`, and `cmd /c` run the following text as
1386
+ * a command. Recurse so a wipe inside the wrapper is classified by the same
1387
+ * rules. Only when the shell is the stage's command: `grep -c` is not a shell.
1388
+ * Returns null when this is not that shape (a script file stays for the
1389
+ * opaque-runner check). An encoded PowerShell command hides its body, so it
1390
+ * asks (`review`) rather than being treated as safe.
1339
1391
  */
1340
1392
  function classifyShellCStage(stage, sandboxEnforced) {
1341
- const m = stage.match(/^(?:bash|sh|zsh|ksh|dash)\b[^'"]*?\s-[A-Za-z]*c\s+(['"])([\s\S]*?)\1/);
1342
- if (!m)
1393
+ const args = splitArgs(stage);
1394
+ let i = args[0] === "sudo" ? 1 : 0;
1395
+ if (i >= args.length)
1396
+ return null;
1397
+ const name = shellInvocationName(args[i]);
1398
+ if (!WRAPPED_SHELLS.has(name))
1399
+ return null;
1400
+ i++;
1401
+ const run = (body) => {
1402
+ const inner = body.trim();
1403
+ if (!inner || inner === stage.trim())
1404
+ return null;
1405
+ return classifyBashCommand(inner, new Set(), sandboxEnforced);
1406
+ };
1407
+ if (name === "cmd") {
1408
+ while (i < args.length) {
1409
+ const a = args[i];
1410
+ const inline = /^\/[cd]:([\s\S]*)$/i.exec(a);
1411
+ if (inline)
1412
+ return run(inline[1]);
1413
+ if (/^\/[cd]$/i.test(a) || /^-[cd]$/i.test(a)) {
1414
+ const rest = args.slice(i + 1);
1415
+ if (rest.length === 0)
1416
+ return null;
1417
+ return run(rest.join(" "));
1418
+ }
1419
+ i++;
1420
+ }
1421
+ return null;
1422
+ }
1423
+ const ps = name === "powershell" || name === "pwsh";
1424
+ while (i < args.length) {
1425
+ const a = args[i];
1426
+ if (ps && /^-(?:encodedcommand|enc)$/i.test(a))
1427
+ return "review";
1428
+ if (/^-(?:command|c)$/i.test(a) || (!ps && /^-[A-Za-z]*c$/.test(a) && !a.startsWith("--"))) {
1429
+ const rest = args.slice(i + 1);
1430
+ if (rest.length === 0)
1431
+ return null;
1432
+ // powershell -Command takes the rest of the line. bash -c takes one argument.
1433
+ return run(ps ? rest.join(" ") : rest[0]);
1434
+ }
1435
+ if (/^-(?:file|inputformat|if|outputformat|of|executionpolicy|ep|version|workingdirectory|wd|configurationname)$/i.test(a)) {
1436
+ i += 2;
1437
+ continue;
1438
+ }
1439
+ if (a.startsWith("-")) {
1440
+ i++;
1441
+ continue;
1442
+ }
1343
1443
  return null;
1344
- return classifyBashCommand(m[2], new Set(), sandboxEnforced);
1444
+ }
1445
+ return null;
1446
+ }
1447
+ // A whole drive or the home directory. Deleting one of these is the failure
1448
+ // mode behind the public Windows wipes (Antigravity `rmdir /s /q d:\`, Codex
1449
+ // and Cursor quote bugs that collapsed a project path to `C:\` or `D:\`).
1450
+ function isCatastrophicTarget(raw) {
1451
+ let t = unquote(raw).trim().replace(/^\\\\\?\\/, "");
1452
+ if (!t)
1453
+ return false;
1454
+ if (t === "/" || t === "\\" || t === "~" || t === "~/" || t === "~\\")
1455
+ return true;
1456
+ if (/^\$\{?(?:home|env:home|env:userprofile)\}?[\\/]?$/i.test(t))
1457
+ return true;
1458
+ if (/^%(?:userprofile|home)%[\\/]?$/i.test(t))
1459
+ return true;
1460
+ if (/^[A-Za-z]:[\\/]?$/.test(t))
1461
+ return true;
1462
+ // 8.3 short name of a profile (`C:\Users\ALICE~1`), the Claude Code home wipe.
1463
+ if (/^[A-Za-z]:[\\/]Users[\\/][^\\/]+~\d+[\\/]?$/i.test(t))
1464
+ return true;
1465
+ return false;
1466
+ }
1467
+ function isCleanupTarget(target, vars) {
1468
+ const t = unquote(target);
1469
+ if (!t || isCatastrophicTarget(t))
1470
+ return false;
1471
+ if (isEphemeralPath(t) || isEphemeralVar(t, vars) || vars.has(CREATED_PATH + t))
1472
+ return true;
1473
+ if (vars.has(TEMP_CWD) && /^[\w.-][\w./\\-]*$/.test(t) && !t.split(/[/\\]/).includes(".."))
1474
+ return true;
1475
+ return isBuildOutputPath(t);
1476
+ }
1477
+ // `\"` between PowerShell and cmd. The backslash does not escape the quote,
1478
+ // and cmd then sees `\` (the current drive root) as its own argument. That is
1479
+ // openai/codex#57530 and the Cursor Remove-Item / rmdir reports. Do not treat
1480
+ // the visible folder (node_modules, build, Temp) as the real target.
1481
+ function isCollapsedWindowsDelete(stage) {
1482
+ if (!/\\"/.test(stage))
1483
+ return false;
1484
+ if (!/\b(?:Remove-Item|ri|rd|del|erase|rmdir|rm)\b/i.test(stage))
1485
+ return false;
1486
+ return /(?:-Recurse|\s\/s\b|\/s\/q\b|--recursive|-[A-Za-z]*[rR])/i.test(stage);
1487
+ }
1488
+ function isCmdRecurseFlag(arg) {
1489
+ return /^\/s(?:\/[qfa])*$/i.test(arg) || /^\/[qfa]*\/s(?:\/[qfa])*$/i.test(arg);
1490
+ }
1491
+ function isPsRecurseFlag(arg) {
1492
+ return /^-(?:r|re|rec|recu|recur|recurs|recurse)$/i.test(arg);
1493
+ }
1494
+ function windowsDeleteTargets(args) {
1495
+ const out = [];
1496
+ for (let i = 0; i < args.length; i++) {
1497
+ const a = args[i];
1498
+ if (isCmdRecurseFlag(a) || /^\/[qfa]$/i.test(a))
1499
+ continue;
1500
+ if (isPsRecurseFlag(a) || /^-(?:force|f|confirm|whatif|verbose|debug|ea)$/i.test(a))
1501
+ continue;
1502
+ const pathFlag = /^-(?:path|literalpath)$/i.exec(a);
1503
+ if (pathFlag) {
1504
+ if (args[i + 1])
1505
+ out.push(unquote(args[++i]));
1506
+ continue;
1507
+ }
1508
+ const inline = /^-(?:path|literalpath):(.+)$/i.exec(a);
1509
+ if (inline) {
1510
+ out.push(unquote(inline[1]));
1511
+ continue;
1512
+ }
1513
+ if (/^-(?:filter|include|exclude|erroraction|warningaction|informationaction|errorvariable|warningvariable|outvariable|outbuffer|pipelinevariable|credential|stream|confirm|informationvariable)$/i.test(a)) {
1514
+ i++;
1515
+ continue;
1516
+ }
1517
+ if (a.startsWith("-"))
1518
+ continue;
1519
+ if (/^(?:\d|&)?>>?\S+$/.test(a))
1520
+ continue;
1521
+ out.push(unquote(a));
1522
+ }
1523
+ return out;
1524
+ }
1525
+ function tierOfWindowsDelete(invocation, ephemeralVars) {
1526
+ const args = splitArgs(invocation);
1527
+ const cmd = (args[0] ?? "").replace(/\.exe$/i, "").toLowerCase();
1528
+ if (!/^(?:remove-item|ri|rd|del|erase|rmdir)$/.test(cmd))
1529
+ return null;
1530
+ const rest = args.slice(1);
1531
+ const recursive = rest.some((a) => isCmdRecurseFlag(a) || isPsRecurseFlag(a));
1532
+ const targets = windowsDeleteTargets(rest);
1533
+ if (targets.some((t) => isCatastrophicTarget(t)))
1534
+ return "high_stakes";
1535
+ if (!recursive) {
1536
+ // rmdir/rd without /s only remove empty directories. del, erase, and
1537
+ // Remove-Item delete the named files even without -Recurse.
1538
+ if (cmd === "rmdir" || cmd === "rd")
1539
+ return null;
1540
+ }
1541
+ if (targets.length === 0)
1542
+ return "high_stakes";
1543
+ if (targets.every((t) => isCleanupTarget(t, ephemeralVars)))
1544
+ return "warning";
1545
+ return "high_stakes";
1546
+ }
1547
+ // PowerShell and cmd deletes, including one nested after `{` (`if (…) { Remove-Item … }`).
1548
+ function classifyWindowsDestruction(stage, ephemeralVars) {
1549
+ const lead = stage.replace(DELETE_LEAD, "");
1550
+ const re = /(?:^|[\n`({;]|\$\()\s*((?:Remove-Item|ri|rd|del|erase|rmdir)\b[\s\S]*?)(?=$|[;|&\n}])/gi;
1551
+ let worst = null;
1552
+ for (const match of lead.matchAll(re)) {
1553
+ const tier = tierOfWindowsDelete(match[1], ephemeralVars);
1554
+ if (tier)
1555
+ worst = worst ? maxTier(worst, tier) : tier;
1556
+ }
1557
+ return worst;
1558
+ }
1559
+ function classifyFindDelete(stage, ephemeralVars) {
1560
+ if (!/^find\b/.test(stage) || !/(?:^|\s)-delete\b/.test(stage))
1561
+ return null;
1562
+ const paths = [];
1563
+ for (const arg of splitArgs(stage).slice(1)) {
1564
+ if (arg.startsWith("-"))
1565
+ break;
1566
+ paths.push(unquote(arg));
1567
+ }
1568
+ const targets = paths.length > 0 ? paths : ["."];
1569
+ if (targets.every((t) => isCleanupTarget(t, ephemeralVars)))
1570
+ return "warning";
1571
+ return "high_stakes";
1572
+ }
1573
+ function classifyGitCleanStage(stage, ephemeralVars) {
1574
+ const match = /^git\s+clean\b([\s\S]*)$/.exec(stage);
1575
+ if (!match)
1576
+ return null;
1577
+ const args = splitArgs(match[1]);
1578
+ let force = false;
1579
+ let dry = false;
1580
+ const paths = [];
1581
+ for (let i = 0; i < args.length; i++) {
1582
+ const arg = args[i];
1583
+ if (arg === "--") {
1584
+ paths.push(...args.slice(i + 1).map(unquote));
1585
+ break;
1586
+ }
1587
+ if (arg === "--force") {
1588
+ force = true;
1589
+ continue;
1590
+ }
1591
+ if (arg === "--dry-run" || arg === "--dryrun") {
1592
+ dry = true;
1593
+ continue;
1594
+ }
1595
+ if (arg === "--exclude" || arg === "-e") {
1596
+ i++;
1597
+ continue;
1598
+ }
1599
+ if (arg.startsWith("--exclude="))
1600
+ continue;
1601
+ if (arg.startsWith("--"))
1602
+ continue;
1603
+ if (arg.startsWith("-") && arg.length > 1) {
1604
+ const flags = arg.slice(1);
1605
+ if (flags.includes("n"))
1606
+ dry = true;
1607
+ if (flags.includes("f"))
1608
+ force = true;
1609
+ if (flags.includes("e"))
1610
+ i++;
1611
+ continue;
1612
+ }
1613
+ paths.push(unquote(arg));
1614
+ }
1615
+ if (!force || dry)
1616
+ return "safe";
1617
+ if (paths.length === 0)
1618
+ return ephemeralVars.has(TEMP_CWD) ? "warning" : "high_stakes";
1619
+ if (paths.every((p) => isCleanupTarget(p, ephemeralVars)))
1620
+ return "warning";
1621
+ return "high_stakes";
1622
+ }
1623
+ function isDiskFormat(stage) {
1624
+ if (/^format-volume\b/i.test(stage)) {
1625
+ // -WhatIf prints the plan and does not format.
1626
+ if (/(?:^|\s)-wh(?:a(?:t(?:i(?:f)?)?)?)?\b/i.test(stage))
1627
+ return false;
1628
+ return true;
1629
+ }
1630
+ // `format C:` / `format D: /q`. Not `npm run format`, `gofmt`, or `cargo fmt`.
1631
+ return /^format(?:\.com)?\s+[A-Za-z]:/i.test(stage);
1632
+ }
1633
+ // PocketOS: curl POST of a Railway GraphQL `volumeDelete` mutation. The body
1634
+ // is data for every other curl rule, so this looks for that mutation only.
1635
+ function isInfraVolumeDeleteCurl(command) {
1636
+ const stage = command.trim();
1637
+ if (!/^(?:(?:sudo|command)\s+)*(?:\w+=\S+\s+)*curl\b/.test(stage))
1638
+ return false;
1639
+ if (!/\bvolumeDelete\b/i.test(stage))
1640
+ return false;
1641
+ return /graphql|railway\.app|backboard\./i.test(stage);
1345
1642
  }
1346
1643
  // A curl/wget whose target host is loopback (localhost, 127.0.0.0/8, 0.0.0.0,
1347
1644
  // ::1). A request to a server on this machine is a LOCAL action, not an outward
@@ -1444,6 +1741,10 @@ function classifyBashCommand(command, ephemeralVars = new Set(), sandboxEnforced
1444
1741
  // shell pass short-circuits to `safe` (e.g. an assignment-prefixed node -e).
1445
1742
  const sql = findSqlInCommand(intact);
1446
1743
  const sqlTier = sql ? classifySqlSeverity(sql) : "safe";
1744
+ // GraphQL volumeDelete lives in the curl body, which the shell scan blanks.
1745
+ // Read it from the intact command. A normal POST stays review below.
1746
+ if (isInfraVolumeDeleteCurl(intact))
1747
+ return "high_stakes";
1447
1748
  return maxTier(maxTier(sqlTier, pipesToShell ? "review" : "safe"), classifyStageShellEffects(stripped, ephemeralVars, sandboxEnforced));
1448
1749
  }
1449
1750
  /**
@@ -1721,6 +2022,11 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
1721
2022
  // → warning; any non-temp target (or the temp root itself) → high_stakes.
1722
2023
  // A delete word sitting in an argument (filename, branch name, echo text) is
1723
2024
  // NOT a deletion — that's the false positive DELETE_COMMAND_RE avoids.
2025
+ // `\"` in a recursive delete is the PowerShell/cmd quoting collapse. The
2026
+ // visible path is not the path cmd will delete. Ask before temp/build
2027
+ // downgrades can hide it.
2028
+ if (isCollapsedWindowsDelete(stage))
2029
+ return "high_stakes";
1724
2030
  if (isEphemeralOnlyDeletion(stage, ephemeralVars))
1725
2031
  return "warning";
1726
2032
  // `git -C repo …` / `git -c k=v …`: classify the subcommand without the
@@ -1728,13 +2034,18 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
1728
2034
  const gitTier = classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced);
1729
2035
  if (gitTier !== null)
1730
2036
  return gitTier;
2037
+ const winTier = classifyWindowsDestruction(stage, ephemeralVars);
2038
+ if (winTier)
2039
+ return winTier;
1731
2040
  if (isBuildOutputOnlyDeletion(stage.replace(DELETE_LEAD, "")))
1732
2041
  return "warning";
1733
2042
  // rmdir removes only EMPTY folders (it fails on a folder with files), so no
1734
2043
  // data is lost and `mkdir` undoes it: a reversible local change.
2044
+ // `rmdir /s` and `rmdir -Recurse` are recursive Windows deletes, handled above.
1735
2045
  const deleteStage = stage.replace(DELETE_LEAD, "");
1736
2046
  const rmdirArgs = deleteStage.match(/^(?:sudo\s+)?rmdir\b(.*)$/s)?.[1];
1737
- if (rmdirArgs !== undefined && !DELETE_COMMAND_RE.test(rmdirArgs))
2047
+ if (rmdirArgs !== undefined && !DELETE_COMMAND_RE.test(rmdirArgs) &&
2048
+ !/(?:^|\s)\/s\b|(?:^|\s)-r(?:ecurse)?\b/i.test(rmdirArgs))
1738
2049
  return "warning";
1739
2050
  if (DELETE_COMMAND_RE.test(deleteStage))
1740
2051
  return "high_stakes";
@@ -1750,12 +2061,22 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
1750
2061
  if (/(?:^|\/)scratchpad\//.test(pattern) || EPHEMERAL_PATH_RE.test(pattern))
1751
2062
  return "warning";
1752
2063
  }
2064
+ if (isOwnJobKill(bareStage, ephemeralVars))
2065
+ return "warning";
1753
2066
  // Stopping a local dev server or a read-only watcher is review: it asks,
1754
2067
  // without Face ID.
1755
2068
  if (isRestartableKill(bareStage))
1756
2069
  return "review";
1757
2070
  if (/^railway\s/.test(bareStage) && PREVIEW_FLAG_RE.test(bareStage))
1758
2071
  return "safe";
2072
+ const findTier = classifyFindDelete(bareStage, ephemeralVars);
2073
+ if (findTier)
2074
+ return findTier;
2075
+ const gitCleanTier = classifyGitCleanStage(bareStage, ephemeralVars);
2076
+ if (gitCleanTier)
2077
+ return gitCleanTier;
2078
+ if (isDiskFormat(bareStage))
2079
+ return "high_stakes";
1759
2080
  for (const pattern of HIGH_STAKES_STAGE) {
1760
2081
  if (pattern.test(bareStage))
1761
2082
  return "high_stakes";
@@ -1800,11 +2121,10 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
1800
2121
  const sshTier = classifySshStage(stage, sandboxEnforced);
1801
2122
  if (sshTier !== null)
1802
2123
  return sshTier;
1803
- // `sh -c '<shell>'` / `bash -c "<shell>"` runs the quoted argument AS shell —
1804
- // recurse so its effect is classified by the same rules (mirrors ssh). This
1805
- // is why the command-position delete scan above can ignore quoted text: a real
1806
- // shell-out like `bash -c 'rm -rf /important'` is caught HERE, by re-running
1807
- // the body as a command, while `echo 'rm …'` (data) is not.
2124
+ // `sh -c` / `bash -c`, `powershell -Command` / `pwsh -c`, and `cmd /c` run
2125
+ // the following text as a command. Recurse so its effect is classified by
2126
+ // the same rules (mirrors ssh). A real shell-out like `bash -c 'rm -rf /important'`
2127
+ // or `cmd /c rmdir /s /q d:\` is caught here. `echo 'rm …'` is data, not a shell-out.
1808
2128
  const shellCTier = classifyShellCStage(stage, sandboxEnforced);
1809
2129
  if (shellCTier !== null)
1810
2130
  return shellCTier;
package/dist/describe.js CHANGED
@@ -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+\./;
@@ -555,6 +558,20 @@ function summarizeGh(cmd, cwd) {
555
558
  return { title: mutation ? "Change data via GitHub GraphQL API" : "Query GitHub GraphQL API", body: truncateBody(cmd), kind: mutation ? "http_post" : "http_get" };
556
559
  }
557
560
  const m2 = method ?? (/\s(?:-f|-F|--field|--raw-field|--input)(?:\s|=)/.test(args) ? "POST" : "GET");
561
+ // A POST to `repos/<owner>/<repo>/pulls` opens a PR: say so, like `gh pr create`.
562
+ const pulls = endpoint?.match(/^\/?repos\/([\w.-]+\/[\w.-]+)\/pulls$/);
563
+ if (pulls && m2 === "POST") {
564
+ const field = (k) => args.match(new RegExp(`\\s(?:-f|-F|--field|--raw-field)[\\s=]+${k}=(?:'([^']*)'|"((?:[^"\\\\]|\\\\.)*)"|([^\\s'"]+))`));
565
+ const val = (m) => m ? (m[1] ?? m[2] ?? m[3] ?? "") : undefined;
566
+ const head = val(field("head"));
567
+ const base = val(field("base"));
568
+ return {
569
+ title: `Create PR in ${pulls[1]}`,
570
+ target: head && base && !/[$`@]/.test(head + base) ? `${head} → ${base}` : undefined,
571
+ body: truncateBody(cmd),
572
+ kind: "git_pr_create",
573
+ };
574
+ }
558
575
  return {
559
576
  title: `${m2} request to GitHub API`,
560
577
  target: endpoint,
@@ -1750,7 +1767,9 @@ function parseRmTargets(argsString) {
1750
1767
  i++;
1751
1768
  token = str.slice(start, i);
1752
1769
  }
1753
- if (token && !token.startsWith("-")) {
1770
+ // cmd delete switches (`/s`, `/q`) are flags, not paths. A longer token
1771
+ // (`/src`) is a path and stays.
1772
+ if (token && !token.startsWith("-") && !/^\/[sqfa]$/i.test(token)) {
1754
1773
  targets.push(token);
1755
1774
  }
1756
1775
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/sdk",
3
- "version": "0.6.23",
3
+ "version": "0.6.25",
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.23"
48
+ "@oked/receipt-core": "0.6.25"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^26.6.5",