@oked/sdk 0.6.24 → 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 +1 -1
- package/dist/classify.js +338 -38
- package/dist/describe.js +10 -5
- package/package.json +2 -2
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,
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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).
|
|
@@ -664,10 +670,12 @@ const EPHEMERAL_PATH_RE = /^(?:\/tmp\/|\/var\/tmp\/|\/var\/folders\/|\/private\/
|
|
|
664
670
|
// $TMP, $TEMP, ${TMPDIR}, and paths beneath them. Treated as ephemeral since
|
|
665
671
|
// we can't resolve the value but the intent is unambiguous.
|
|
666
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;
|
|
667
675
|
function isEphemeralPath(filePath) {
|
|
668
676
|
if (!filePath)
|
|
669
677
|
return false;
|
|
670
|
-
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);
|
|
671
679
|
}
|
|
672
680
|
// A shell variable assigned from `mktemp` / `mktemp -d` (optionally `export`ed)
|
|
673
681
|
// at the start of a stage: `EMPTYHOME=$(mktemp -d)`, `T=`mktemp``. Its value is a
|
|
@@ -775,10 +783,15 @@ function collectMktempVars(stage, into) {
|
|
|
775
783
|
function isEphemeralVar(target, vars) {
|
|
776
784
|
if (vars.size === 0)
|
|
777
785
|
return false;
|
|
778
|
-
|
|
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+)\}?([\\/].*)?$/);
|
|
779
792
|
if (!m || !vars.has(m[1]))
|
|
780
793
|
return false;
|
|
781
|
-
if (m[2] && m[2].split(
|
|
794
|
+
if (m[2] && m[2].split(/[/\\]/).includes(".."))
|
|
782
795
|
return false;
|
|
783
796
|
return true;
|
|
784
797
|
}
|
|
@@ -862,15 +875,18 @@ export function classify(toolName, toolInput, options) {
|
|
|
862
875
|
const filePath = toolInput.file_path;
|
|
863
876
|
return isSensitiveWritePath(filePath) ? "review" : "warning";
|
|
864
877
|
}
|
|
865
|
-
//
|
|
866
|
-
//
|
|
867
|
-
//
|
|
868
|
-
//
|
|
869
|
-
//
|
|
870
|
-
|
|
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")
|
|
871
886
|
return "safe";
|
|
872
|
-
// Bash commands need deeper analysis
|
|
873
|
-
|
|
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") {
|
|
874
890
|
return classifyBashCommand(toolInput.command, new Set(), sandboxEnforced);
|
|
875
891
|
}
|
|
876
892
|
// MCP tools: mcp__<server>__<tool>
|
|
@@ -1057,6 +1073,13 @@ const BUILD_OUTPUT_DIRS = new Set(["build", "dist", ".build", "DerivedData", ".n
|
|
|
1057
1073
|
// rm/trash whose every target is a relative path inside a build output folder
|
|
1058
1074
|
// (`rm -rf build/OKed.xcarchive dist`). An absolute path, `..`, a variable or a
|
|
1059
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
|
+
}
|
|
1060
1083
|
function isBuildOutputOnlyDeletion(command) {
|
|
1061
1084
|
const m = command.match(/^(?:rm|trash|trash-put)\b\s+(.+)$/s);
|
|
1062
1085
|
if (!m)
|
|
@@ -1064,10 +1087,7 @@ function isBuildOutputOnlyDeletion(command) {
|
|
|
1064
1087
|
const targets = splitArgs(m[1]).filter((a) => !a.startsWith("-") && !/^(?:\d|&)?>>?\S+$/.test(a));
|
|
1065
1088
|
if (targets.length === 0)
|
|
1066
1089
|
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
|
-
});
|
|
1090
|
+
return targets.every((a) => isBuildOutputPath(a));
|
|
1071
1091
|
}
|
|
1072
1092
|
/**
|
|
1073
1093
|
* Classifies a single stage that begins with one or more `NAME=value`
|
|
@@ -1241,6 +1261,9 @@ function classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced) {
|
|
|
1241
1261
|
return i;
|
|
1242
1262
|
};
|
|
1243
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;
|
|
1244
1267
|
let i = lead[0].length;
|
|
1245
1268
|
while (i < stage.length) {
|
|
1246
1269
|
while (i < stage.length && /\s/.test(stage[i]))
|
|
@@ -1251,7 +1274,10 @@ function classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced) {
|
|
|
1251
1274
|
i = readToken(i);
|
|
1252
1275
|
const tok = stage.slice(start, i);
|
|
1253
1276
|
if (!tok.startsWith("-")) {
|
|
1254
|
-
const
|
|
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);
|
|
1255
1281
|
return maxTier(floor, inner);
|
|
1256
1282
|
}
|
|
1257
1283
|
let value = "";
|
|
@@ -1267,6 +1293,9 @@ function classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced) {
|
|
|
1267
1293
|
}
|
|
1268
1294
|
if ((tok === "-c" || tok.startsWith("-c")) && /^alias\./i.test(value))
|
|
1269
1295
|
floor = "review";
|
|
1296
|
+
if (tok === "-C" && (isEphemeralPath(value) || isEphemeralVar(value, ephemeralVars) || /^\$\(\s*mktemp\b/.test(value))) {
|
|
1297
|
+
repoInTemp = true;
|
|
1298
|
+
}
|
|
1270
1299
|
}
|
|
1271
1300
|
return floor; // `git -C dir` with no subcommand prints help
|
|
1272
1301
|
}
|
|
@@ -1347,19 +1376,269 @@ function classifySshStage(stage, sandboxEnforced) {
|
|
|
1347
1376
|
}
|
|
1348
1377
|
return "review"; // only options / a bare host token → treat as remote access
|
|
1349
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
|
+
}
|
|
1350
1383
|
/**
|
|
1351
|
-
* `sh -c
|
|
1352
|
-
*
|
|
1353
|
-
*
|
|
1354
|
-
* when the shell
|
|
1355
|
-
*
|
|
1356
|
-
*
|
|
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.
|
|
1357
1391
|
*/
|
|
1358
1392
|
function classifyShellCStage(stage, sandboxEnforced) {
|
|
1359
|
-
const
|
|
1360
|
-
|
|
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
|
+
}
|
|
1443
|
+
return null;
|
|
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))
|
|
1361
1561
|
return null;
|
|
1362
|
-
|
|
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);
|
|
1363
1642
|
}
|
|
1364
1643
|
// A curl/wget whose target host is loopback (localhost, 127.0.0.0/8, 0.0.0.0,
|
|
1365
1644
|
// ::1). A request to a server on this machine is a LOCAL action, not an outward
|
|
@@ -1462,6 +1741,10 @@ function classifyBashCommand(command, ephemeralVars = new Set(), sandboxEnforced
|
|
|
1462
1741
|
// shell pass short-circuits to `safe` (e.g. an assignment-prefixed node -e).
|
|
1463
1742
|
const sql = findSqlInCommand(intact);
|
|
1464
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";
|
|
1465
1748
|
return maxTier(maxTier(sqlTier, pipesToShell ? "review" : "safe"), classifyStageShellEffects(stripped, ephemeralVars, sandboxEnforced));
|
|
1466
1749
|
}
|
|
1467
1750
|
/**
|
|
@@ -1739,6 +2022,11 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
|
|
|
1739
2022
|
// → warning; any non-temp target (or the temp root itself) → high_stakes.
|
|
1740
2023
|
// A delete word sitting in an argument (filename, branch name, echo text) is
|
|
1741
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";
|
|
1742
2030
|
if (isEphemeralOnlyDeletion(stage, ephemeralVars))
|
|
1743
2031
|
return "warning";
|
|
1744
2032
|
// `git -C repo …` / `git -c k=v …`: classify the subcommand without the
|
|
@@ -1746,13 +2034,18 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
|
|
|
1746
2034
|
const gitTier = classifyGitGlobalOptsStage(stage, ephemeralVars, sandboxEnforced);
|
|
1747
2035
|
if (gitTier !== null)
|
|
1748
2036
|
return gitTier;
|
|
2037
|
+
const winTier = classifyWindowsDestruction(stage, ephemeralVars);
|
|
2038
|
+
if (winTier)
|
|
2039
|
+
return winTier;
|
|
1749
2040
|
if (isBuildOutputOnlyDeletion(stage.replace(DELETE_LEAD, "")))
|
|
1750
2041
|
return "warning";
|
|
1751
2042
|
// rmdir removes only EMPTY folders (it fails on a folder with files), so no
|
|
1752
2043
|
// data is lost and `mkdir` undoes it: a reversible local change.
|
|
2044
|
+
// `rmdir /s` and `rmdir -Recurse` are recursive Windows deletes, handled above.
|
|
1753
2045
|
const deleteStage = stage.replace(DELETE_LEAD, "");
|
|
1754
2046
|
const rmdirArgs = deleteStage.match(/^(?:sudo\s+)?rmdir\b(.*)$/s)?.[1];
|
|
1755
|
-
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))
|
|
1756
2049
|
return "warning";
|
|
1757
2050
|
if (DELETE_COMMAND_RE.test(deleteStage))
|
|
1758
2051
|
return "high_stakes";
|
|
@@ -1776,6 +2069,14 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
|
|
|
1776
2069
|
return "review";
|
|
1777
2070
|
if (/^railway\s/.test(bareStage) && PREVIEW_FLAG_RE.test(bareStage))
|
|
1778
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";
|
|
1779
2080
|
for (const pattern of HIGH_STAKES_STAGE) {
|
|
1780
2081
|
if (pattern.test(bareStage))
|
|
1781
2082
|
return "high_stakes";
|
|
@@ -1820,11 +2121,10 @@ function classifyStageEffects(stage, ephemeralVars, sandboxEnforced) {
|
|
|
1820
2121
|
const sshTier = classifySshStage(stage, sandboxEnforced);
|
|
1821
2122
|
if (sshTier !== null)
|
|
1822
2123
|
return sshTier;
|
|
1823
|
-
// `sh -c
|
|
1824
|
-
//
|
|
1825
|
-
//
|
|
1826
|
-
//
|
|
1827
|
-
// 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.
|
|
1828
2128
|
const shellCTier = classifyShellCStage(stage, sandboxEnforced);
|
|
1829
2129
|
if (shellCTier !== null)
|
|
1830
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
|
-
|
|
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
|
|
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+\./;
|
|
@@ -1764,7 +1767,9 @@ function parseRmTargets(argsString) {
|
|
|
1764
1767
|
i++;
|
|
1765
1768
|
token = str.slice(start, i);
|
|
1766
1769
|
}
|
|
1767
|
-
|
|
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)) {
|
|
1768
1773
|
targets.push(token);
|
|
1769
1774
|
}
|
|
1770
1775
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oked/sdk",
|
|
3
|
-
"version": "0.6.
|
|
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.
|
|
48
|
+
"@oked/receipt-core": "0.6.25"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^26.6.5",
|