@oked/sdk 0.6.7 → 0.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classify.d.ts +15 -0
- package/dist/classify.js +218 -7
- package/dist/describe.js +184 -23
- package/dist/kinds.d.ts +1 -1
- package/package.json +2 -2
package/dist/classify.d.ts
CHANGED
|
@@ -30,6 +30,21 @@ export interface ShellWriteOp {
|
|
|
30
30
|
* body, so SQL/code detection still runs. The opener line is always preserved.
|
|
31
31
|
*/
|
|
32
32
|
export declare function stripHeredocBodies(command: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Drop the bodies of heredocs fed to a code interpreter, for the SHELL-pattern
|
|
35
|
+
* scans only (the same policy as `-e`/`-c` bodies below). A Python script that
|
|
36
|
+
* edits a file whose text says "git push --force" or "npm publish" is not a
|
|
37
|
+
* force push or a publish. SQL detection still reads the intact body.
|
|
38
|
+
*/
|
|
39
|
+
export declare function stripCodeHeredocBodies(command: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Blank the inside of quoted arguments of text commands, for the SHELL-pattern
|
|
42
|
+
* scans only, so `git commit -m "curl -d sends JSON"` or `grep "curl -X POST"`
|
|
43
|
+
* is not read as a POST. A step that pipes into a command that runs its input
|
|
44
|
+
* (`echo '…' | sh`) keeps its text. A pipe into a reader (`grep "…" | head`)
|
|
45
|
+
* does not run the text, so the text is blanked.
|
|
46
|
+
*/
|
|
47
|
+
export declare function blankTextCommandArgs(command: string): string;
|
|
33
48
|
export declare function stripInlineScriptBodies(command: string): string;
|
|
34
49
|
/**
|
|
35
50
|
* Blank the interior of quoted curl request bodies, keeping the quotes and the
|
package/dist/classify.js
CHANGED
|
@@ -143,6 +143,29 @@ const DELETE_LEAD = /^(?:(?:sudo|command|exec|builtin|time|nice|xargs|then|do|el
|
|
|
143
143
|
// { ). Deliberately NOT after `;`/`|`/`&`/a quote, so a delete word sitting in
|
|
144
144
|
// quoted DATA (echo text, a commit message) doesn't match.
|
|
145
145
|
const DELETE_COMMAND_RE = /(?:^|[\n`({]|\$\()\s*(?:rm|rmdir|trash|trash-put)\b/;
|
|
146
|
+
const NPX_DEPLOY_RE = /\bnpx\s+.*\s+deploy\b/;
|
|
147
|
+
/**
|
|
148
|
+
* `prisma migrate deploy` against a DATABASE_URL on this machine (localhost,
|
|
149
|
+
* 127.0.0.1, ::1) set in the same command: it changes a local test database,
|
|
150
|
+
* not a live one, so the `npx … deploy` rule does not apply. Without a local
|
|
151
|
+
* DATABASE_URL in the command the URL comes from the environment, which can be
|
|
152
|
+
* production, so the rule still applies.
|
|
153
|
+
*/
|
|
154
|
+
function isLocalPrismaDeploy(command) {
|
|
155
|
+
if (!/\bprisma\s+migrate\s+deploy\b/.test(command))
|
|
156
|
+
return false;
|
|
157
|
+
const urls = [...command.matchAll(/DATABASE_URL=["']?([a-z]+:\/\/[^\s"';&|]+)/g)].map((m) => m[1]);
|
|
158
|
+
if (urls.length === 0)
|
|
159
|
+
return false;
|
|
160
|
+
return urls.every((u) => {
|
|
161
|
+
try {
|
|
162
|
+
return ["localhost", "127.0.0.1", "[::1]"].includes(new URL(u).hostname);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
146
169
|
// Bash commands classified as high stakes (destructive, irreversible, external).
|
|
147
170
|
// Scanned on the FULL command (some patterns, e.g. download|shell, span a pipe).
|
|
148
171
|
// File deletion lives in DELETE_PATTERNS (per-stage) instead, see above.
|
|
@@ -172,7 +195,7 @@ const HIGH_STAKES_COMMANDS = [
|
|
|
172
195
|
/\bcurl\s+.*\|\s*(bash|sh|zsh)\b/,
|
|
173
196
|
/\bnpm\s+publish\b/,
|
|
174
197
|
/\bnpm\s+unpublish\b/,
|
|
175
|
-
|
|
198
|
+
NPX_DEPLOY_RE,
|
|
176
199
|
// NOTE: ssh is intentionally NOT a blanket high_stakes here. ssh is a
|
|
177
200
|
// transport — the real effect is whatever runs on the remote host — so it's
|
|
178
201
|
// classified by its remote command in classifySshStage (a read-only remote
|
|
@@ -302,6 +325,8 @@ const WARNING_COMMANDS = [
|
|
|
302
325
|
// high_stakes in the full scan above and wins before reaching here.
|
|
303
326
|
/^git\s+push\b/,
|
|
304
327
|
/^gh\s+pr\s+create\b/,
|
|
328
|
+
// Prisma migrations reach here only for a local database (see isLocalPrismaDeploy).
|
|
329
|
+
/^(?:\w+=\S+\s+)*npx\s+prisma\s+migrate\s+deploy\b/,
|
|
305
330
|
// Package installs always mutate node_modules and run dependency postinstall
|
|
306
331
|
// scripts — a known local mutation worth an audit line.
|
|
307
332
|
/^npm\s+(install|ci|i|update|upgrade|rebuild|prune|dedupe)\b/,
|
|
@@ -331,6 +356,70 @@ function isEphemeralPath(filePath) {
|
|
|
331
356
|
// binding declared in an earlier one. Safe because the whole binding is visible
|
|
332
357
|
// in this single inspected command string — no environment-resolution guess.
|
|
333
358
|
const MKTEMP_ASSIGN_RE = /^(?:export\s+|declare\s+|local\s+|readonly\s+)?(\w+)=["']?(?:\$\(|`)\s*mktemp\b/;
|
|
359
|
+
// Process names and command lines of local dev servers and dev tooling: Node
|
|
360
|
+
// and Python app servers, bundlers, package-manager scripts, and Node scripts.
|
|
361
|
+
const DEV_PROCESS_RE = /\b(?:node|nodemon|tsx|ts-node|vite|next|nuxt|astro|remix|webpack(?:-dev-server)?|esbuild|parcel|turbo|npm|pnpm|yarn|bun|deno|wrangler|miniflare|uvicorn|gunicorn|flask|runserver|rails|puma|http\.server|http-server|live-server|serve|hugo|jekyll|storybook|expo|metro)\b|\.(?:[cm]?js|tsx?)\b/;
|
|
362
|
+
/**
|
|
363
|
+
* A kill of a local dev server: `pkill -f "tsx src/main.ts"`, `killall node`,
|
|
364
|
+
* `kill $(pgrep -f vite)`, or a kill of whatever listens on a port
|
|
365
|
+
* (`kill $(lsof -t -iTCP:3000 -sTCP:LISTEN)`). Oren chose `review` (no Face
|
|
366
|
+
* ID) for these on 2026-10-18. A bare `kill <pid>` names no process, so it
|
|
367
|
+
* stays high stakes.
|
|
368
|
+
*/
|
|
369
|
+
function isDevServerKill(stage) {
|
|
370
|
+
const pkill = stage.match(/^pkill\s+(.+)$/);
|
|
371
|
+
if (pkill) {
|
|
372
|
+
const args = splitArgs(pkill[1]).filter((a) => !a.startsWith("-") || a === "-f");
|
|
373
|
+
const pattern = unquote(args[args.indexOf("-f") + 1] ?? args[args.length - 1] ?? "");
|
|
374
|
+
return DEV_PROCESS_RE.test(pattern);
|
|
375
|
+
}
|
|
376
|
+
const killall = stage.match(/^killall\s+(.+)$/);
|
|
377
|
+
if (killall) {
|
|
378
|
+
const names = splitArgs(killall[1]).filter((a) => !a.startsWith("-")).map(unquote);
|
|
379
|
+
return names.length > 0 && names.every((n) => DEV_PROCESS_RE.test(n));
|
|
380
|
+
}
|
|
381
|
+
const kill = stage.match(/^kill\s+(?:-\w+\s+)*\$\((.+)\)\s*(?:2>\/dev\/null)?$/);
|
|
382
|
+
if (kill) {
|
|
383
|
+
const inner = kill[1].trim();
|
|
384
|
+
if (/^lsof\b/.test(inner) && /-i\s*(?:tcp|TCP|udp)?:?\d+|-iTCP:\d+/.test(inner))
|
|
385
|
+
return true;
|
|
386
|
+
const pg = inner.match(/^pgrep\s+(?:-\w+\s+)*(?:-f\s+)?(.+)$/);
|
|
387
|
+
if (pg)
|
|
388
|
+
return DEV_PROCESS_RE.test(unquote(pg[1].trim()));
|
|
389
|
+
}
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
// Entries in the ephemeral set that are not variable names: `path:<p>` is a
|
|
393
|
+
// file an earlier stage created, `cwd:temp` means the shell is in a temp dir.
|
|
394
|
+
const CREATED_PATH = "path:";
|
|
395
|
+
const TEMP_CWD = "cwd:temp";
|
|
396
|
+
// An earlier stage exported a DATABASE_URL on this machine (see isLocalPrismaDeploy).
|
|
397
|
+
const LOCAL_DB = "db:local";
|
|
398
|
+
function noteEphemeralEffects(stage, into) {
|
|
399
|
+
const assign = stage.match(/^(?:export\s+)?(\w+)=("[^"$`]*"|'[^']*'|[^\s;&|$`'"()]+)$/);
|
|
400
|
+
if (assign && isEphemeralPath(unquote(assign[2])))
|
|
401
|
+
into.add(assign[1]);
|
|
402
|
+
for (const op of extractShellWriteOps(stage)) {
|
|
403
|
+
if (op.kind === "create" || op.kind === "copy" || op.kind === "touch")
|
|
404
|
+
into.add(CREATED_PATH + unquote(op.target));
|
|
405
|
+
}
|
|
406
|
+
const dbUrl = stage.match(/^(?:export\s+)?DATABASE_URL=["']?([a-z]+:\/\/[^\s"';&|]+)["']?$/);
|
|
407
|
+
if (dbUrl) {
|
|
408
|
+
if (isLocalPrismaDeploy(`DATABASE_URL=${dbUrl[1]} prisma migrate deploy`))
|
|
409
|
+
into.add(LOCAL_DB);
|
|
410
|
+
else
|
|
411
|
+
into.delete(LOCAL_DB);
|
|
412
|
+
}
|
|
413
|
+
const cd = stage.match(/^cd\s+(.+)$/);
|
|
414
|
+
if (cd) {
|
|
415
|
+
const dir = unquote(cd[1].trim());
|
|
416
|
+
const temp = /^"?\$\(\s*mktemp\b/.test(cd[1].trim()) || isEphemeralPath(dir) || isEphemeralVar(dir, into);
|
|
417
|
+
if (temp)
|
|
418
|
+
into.add(TEMP_CWD);
|
|
419
|
+
else
|
|
420
|
+
into.delete(TEMP_CWD);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
334
423
|
function collectMktempVars(stage, into) {
|
|
335
424
|
const m = stage.match(MKTEMP_ASSIGN_RE);
|
|
336
425
|
if (m)
|
|
@@ -583,12 +672,14 @@ function isEphemeralOnlyDeletion(command, ephemeralVars = new Set()) {
|
|
|
583
672
|
const m = command.match(/^(?:sudo\s+)?(?:rm|rmdir|trash|trash-put)\b\s+(.+)$/s);
|
|
584
673
|
if (!m)
|
|
585
674
|
return false;
|
|
586
|
-
|
|
675
|
+
// A redirect (`2>/dev/null`) is not a target.
|
|
676
|
+
const targets = splitArgs(m[1]).filter((a) => !a.startsWith("-") && !/^(?:\d|&)?>>?\S+$/.test(a));
|
|
587
677
|
if (targets.length === 0)
|
|
588
678
|
return false;
|
|
589
679
|
return targets.every((a) => {
|
|
590
680
|
const t = unquote(a);
|
|
591
|
-
return isEphemeralPath(t) || isEphemeralVar(t, ephemeralVars)
|
|
681
|
+
return isEphemeralPath(t) || isEphemeralVar(t, ephemeralVars) || ephemeralVars.has(CREATED_PATH + t) ||
|
|
682
|
+
(ephemeralVars.has(TEMP_CWD) && /^[\w.-][\w./-]*$/.test(t) && !t.split("/").includes(".."));
|
|
592
683
|
});
|
|
593
684
|
}
|
|
594
685
|
/**
|
|
@@ -856,7 +947,7 @@ function classifyBashCommand(command, ephemeralVars = new Set()) {
|
|
|
856
947
|
// surface via `intact` — that is the accepted shell-only-opacity
|
|
857
948
|
// trade-off; see classifyStageShellEffects.)
|
|
858
949
|
const intact = stripHeredocBodies(command).trim();
|
|
859
|
-
const stripped = stripCurlDataBodies(stripInlineScriptBodies(intact)).trim();
|
|
950
|
+
const stripped = blankTextCommandArgs(stripCurlDataBodies(stripInlineScriptBodies(stripCodeHeredocBodies(intact)))).trim();
|
|
860
951
|
// High-stakes scan on the FULL (body-stripped) command, before any splitting.
|
|
861
952
|
// These patterns use \b and several intentionally span an operator (e.g.
|
|
862
953
|
// `curl … | bash`, `wget … | sh` — download-and-execute), so they have to be
|
|
@@ -865,9 +956,19 @@ function classifyBashCommand(command, ephemeralVars = new Set()) {
|
|
|
865
956
|
// deletion is NOT here — it's per-stage below so the ephemeral-temp downgrade
|
|
866
957
|
// can run.)
|
|
867
958
|
for (const pattern of HIGH_STAKES_COMMANDS) {
|
|
959
|
+
if (pattern === NPX_DEPLOY_RE && (isLocalPrismaDeploy(stripped) ||
|
|
960
|
+
(ephemeralVars.has(LOCAL_DB) && /\bprisma\s+migrate\s+deploy\b/.test(stripped))))
|
|
961
|
+
continue;
|
|
868
962
|
if (pattern.test(stripped))
|
|
869
963
|
return "high_stakes";
|
|
870
964
|
}
|
|
965
|
+
// Text piped into a shell (`echo '…' | sh`, `printf … | bash`) runs as code
|
|
966
|
+
// that no stage shows on its own. At least `review`; a known high-stakes
|
|
967
|
+
// pattern above (curl | sh) already returned.
|
|
968
|
+
const pipesToShell = splitTopLevel(stripped, { pipes: false }).some((step) => {
|
|
969
|
+
const parts = splitTopLevel(step);
|
|
970
|
+
return parts.length > 1 && parts.slice(1).some((p) => /^(?:sudo\s+)?(?:ba|z|k|da)?sh\b(?!\s+-n\b)/.test(p));
|
|
971
|
+
});
|
|
871
972
|
// Compound commands: split on top-level `|`, `||`, `&&`, `;` and take the
|
|
872
973
|
// highest tier. Split the body-INTACT view so each stage keeps its SQL
|
|
873
974
|
// visible; recursion re-derives both views per stage. (Blanking a script body
|
|
@@ -882,7 +983,17 @@ function classifyBashCommand(command, ephemeralVars = new Set()) {
|
|
|
882
983
|
const vars = new Set(ephemeralVars);
|
|
883
984
|
for (const stage of stages)
|
|
884
985
|
collectMktempVars(stage, vars);
|
|
885
|
-
|
|
986
|
+
// Throwaway paths that only EARLIER stages make known: a file an earlier
|
|
987
|
+
// stage created (`cat > _smoke.mjs <<EOF … ; rm _smoke.mjs`), a variable set
|
|
988
|
+
// to a literal temp path (`W=/tmp/wt; rm -rf $W`), and a `cd` into a temp
|
|
989
|
+
// dir (relative paths then live in it). Gathered in order, so a delete
|
|
990
|
+
// before the create still counts as a real delete.
|
|
991
|
+
let worst = pipesToShell ? "review" : "safe";
|
|
992
|
+
for (const stage of stages) {
|
|
993
|
+
worst = maxTier(worst, classifyBashCommand(stage, vars));
|
|
994
|
+
noteEphemeralEffects(stripHeredocBodies(stage), vars);
|
|
995
|
+
}
|
|
996
|
+
return worst;
|
|
886
997
|
}
|
|
887
998
|
// ---- single stage from here ----
|
|
888
999
|
// SQL severity from the body-INTACT view: an interpreter wrapper (python -c,
|
|
@@ -891,7 +1002,7 @@ function classifyBashCommand(command, ephemeralVars = new Set()) {
|
|
|
891
1002
|
// shell pass short-circuits to `safe` (e.g. an assignment-prefixed node -e).
|
|
892
1003
|
const sql = findSqlInCommand(intact);
|
|
893
1004
|
const sqlTier = sql ? classifySqlSeverity(sql) : "safe";
|
|
894
|
-
return maxTier(sqlTier, classifyStageShellEffects(stripped, ephemeralVars));
|
|
1005
|
+
return maxTier(maxTier(sqlTier, pipesToShell ? "review" : "safe"), classifyStageShellEffects(stripped, ephemeralVars));
|
|
895
1006
|
}
|
|
896
1007
|
/**
|
|
897
1008
|
* Shell-effect classification of a SINGLE, already-body-stripped stage. No SQL
|
|
@@ -906,13 +1017,29 @@ function classifyStageShellEffects(stage, ephemeralVars = new Set()) {
|
|
|
906
1017
|
// NOT a deletion — that's the false positive DELETE_COMMAND_RE avoids.
|
|
907
1018
|
if (isEphemeralOnlyDeletion(stage, ephemeralVars))
|
|
908
1019
|
return "warning";
|
|
909
|
-
|
|
1020
|
+
// rmdir removes only EMPTY folders (it fails on a folder with files), so no
|
|
1021
|
+
// data is lost and `mkdir` undoes it: a reversible local change.
|
|
1022
|
+
const deleteStage = stage.replace(DELETE_LEAD, "");
|
|
1023
|
+
const rmdirArgs = deleteStage.match(/^(?:sudo\s+)?rmdir\b(.*)$/s)?.[1];
|
|
1024
|
+
if (rmdirArgs !== undefined && !DELETE_COMMAND_RE.test(rmdirArgs))
|
|
1025
|
+
return "warning";
|
|
1026
|
+
if (DELETE_COMMAND_RE.test(deleteStage))
|
|
910
1027
|
return "high_stakes";
|
|
911
1028
|
// Destructive/irreversible single commands, matched at stage start with any
|
|
912
1029
|
// leading `sudo ` stripped (so `sudo mkfs …` is still caught, but the word
|
|
913
1030
|
// can't fire inside an argument). These don't span pipes, so `^`-anchoring is
|
|
914
1031
|
// precise and avoids prose false-positives.
|
|
915
1032
|
const bareStage = stage.replace(/^sudo\s+/, "");
|
|
1033
|
+
// Stopping a process whose command line names a temp or scratchpad path (a
|
|
1034
|
+
// test database or server the session started there) is local cleanup.
|
|
1035
|
+
if (/^pkill\s+(?:-\w+\s+)*-f\s+/.test(bareStage)) {
|
|
1036
|
+
const pattern = unquote(splitArgs(bareStage.replace(/^pkill\s+(?:-\w+\s+)*-f\s+/, ""))[0] ?? "");
|
|
1037
|
+
if (/(?:^|\/)scratchpad\//.test(pattern) || EPHEMERAL_PATH_RE.test(pattern))
|
|
1038
|
+
return "warning";
|
|
1039
|
+
}
|
|
1040
|
+
// Stopping a local dev server is review: it asks, without Face ID.
|
|
1041
|
+
if (isDevServerKill(bareStage))
|
|
1042
|
+
return "review";
|
|
916
1043
|
for (const pattern of HIGH_STAKES_STAGE) {
|
|
917
1044
|
if (pattern.test(bareStage))
|
|
918
1045
|
return "high_stakes";
|
|
@@ -927,6 +1054,10 @@ function classifyStageShellEffects(stage, ephemeralVars = new Set()) {
|
|
|
927
1054
|
return isLoopbackHttpStage(stage) ? "warning" : "high_stakes";
|
|
928
1055
|
}
|
|
929
1056
|
}
|
|
1057
|
+
// `DATABASE_URL=<local> npx prisma migrate deploy`: the assignment prefix
|
|
1058
|
+
// below would classify the bare `npx … deploy` without its local URL.
|
|
1059
|
+
if (/^(?:\w+=\S+\s+)*npx\s+prisma\s+migrate\s+deploy\b/.test(bareStage) && isLocalPrismaDeploy(bareStage))
|
|
1060
|
+
return "warning";
|
|
930
1061
|
const ghApiTier = classifyGhApiStage(bareStage);
|
|
931
1062
|
if (ghApiTier !== null)
|
|
932
1063
|
return ghApiTier;
|
|
@@ -1060,6 +1191,71 @@ export function stripHeredocBodies(command) {
|
|
|
1060
1191
|
}
|
|
1061
1192
|
return out.join("\n");
|
|
1062
1193
|
}
|
|
1194
|
+
// Interpreters (not shells) whose heredoc body is code: `python3 - <<'EOF'`,
|
|
1195
|
+
// `node - <<EOF`, `psql <<SQL`. Shell heredocs (`bash <<EOF`) stay scannable.
|
|
1196
|
+
const CODE_HEREDOC_RE = /(?:^|\||&&|;|\$\(|`)\s*(?:\w+=\S+\s+)*(?:sudo\s+)?(?:psql|mysql|mariadb|sqlite3?|node|python\d?(?:\.\d+)?|ruby|perl|deno|bun)\b[^\n|;&]*<</;
|
|
1197
|
+
/**
|
|
1198
|
+
* Drop the bodies of heredocs fed to a code interpreter, for the SHELL-pattern
|
|
1199
|
+
* scans only (the same policy as `-e`/`-c` bodies below). A Python script that
|
|
1200
|
+
* edits a file whose text says "git push --force" or "npm publish" is not a
|
|
1201
|
+
* force push or a publish. SQL detection still reads the intact body.
|
|
1202
|
+
*/
|
|
1203
|
+
export function stripCodeHeredocBodies(command) {
|
|
1204
|
+
const lines = command.split("\n");
|
|
1205
|
+
const out = [];
|
|
1206
|
+
let i = 0;
|
|
1207
|
+
while (i < lines.length) {
|
|
1208
|
+
const line = lines[i];
|
|
1209
|
+
out.push(line);
|
|
1210
|
+
const openers = [...line.matchAll(/<<-?\s*(["']?)([A-Za-z_][A-Za-z0-9_]*)\1/g)];
|
|
1211
|
+
if (openers.length > 0 && CODE_HEREDOC_RE.test(line)) {
|
|
1212
|
+
const delim = openers[openers.length - 1][2];
|
|
1213
|
+
i++;
|
|
1214
|
+
while (i < lines.length && lines[i].trim() !== delim)
|
|
1215
|
+
i++;
|
|
1216
|
+
if (i < lines.length)
|
|
1217
|
+
i++;
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
i++;
|
|
1221
|
+
}
|
|
1222
|
+
return out.join("\n");
|
|
1223
|
+
}
|
|
1224
|
+
// Commands whose quoted arguments are text, never run: a commit message, a
|
|
1225
|
+
// search pattern, a PR body, printed text. `gh api` is left out: its fields are
|
|
1226
|
+
// a request payload (a GraphQL mutation, for example).
|
|
1227
|
+
const TEXT_ARG_COMMAND_RE = /^(?:\w+=(?:"[^"]*"|'[^']*'|\S+)\s+)*(?:git|grep|egrep|fgrep|rg|echo|printf|gh(?!\s+api\b))\b/;
|
|
1228
|
+
// A script file run by node/tsx/bun (`node scripts/x.mjs …`), not inline code
|
|
1229
|
+
// (`node -e`). Its quoted long-option values (`--reason "…"`) are text. Its
|
|
1230
|
+
// quoted positional arguments keep their text, because the script may run them.
|
|
1231
|
+
const SCRIPT_FILE_STEP_RE = /^(?:\\\s+)?(?:\w+=(?:"[^"]*"|'[^']*'|\S+)\s+)*(?:node|tsx|bun)\s+(?!-)\S+\.[cm]?[jt]s(?:\s|$)/;
|
|
1232
|
+
const LONG_OPTION_QUOTED_VALUE_RE = /(--[\w-]+(?:=|\s+))('[^']*'|"(?:[^"\\]|\\.)*")/g;
|
|
1233
|
+
// Commands that run the text piped into them as code.
|
|
1234
|
+
const RUNS_PIPED_TEXT_RE = /^(?:sudo\s+)?(?:(?:ba|z|k|da)?sh|xargs|eval|source|\.|node|deno|bun|python\d?(?:\.\d+)?|ruby|perl|psql|mysql|mariadb|sqlite3?)\b/;
|
|
1235
|
+
/**
|
|
1236
|
+
* Blank the inside of quoted arguments of text commands, for the SHELL-pattern
|
|
1237
|
+
* scans only, so `git commit -m "curl -d sends JSON"` or `grep "curl -X POST"`
|
|
1238
|
+
* is not read as a POST. A step that pipes into a command that runs its input
|
|
1239
|
+
* (`echo '…' | sh`) keeps its text. A pipe into a reader (`grep "…" | head`)
|
|
1240
|
+
* does not run the text, so the text is blanked.
|
|
1241
|
+
*/
|
|
1242
|
+
export function blankTextCommandArgs(command) {
|
|
1243
|
+
return splitTopLevel(command, { pipes: false })
|
|
1244
|
+
.map((step) => {
|
|
1245
|
+
if (SCRIPT_FILE_STEP_RE.test(step)) {
|
|
1246
|
+
if (splitTopLevel(step).slice(1).some((p) => RUNS_PIPED_TEXT_RE.test(p)))
|
|
1247
|
+
return step;
|
|
1248
|
+
return step.replace(LONG_OPTION_QUOTED_VALUE_RE, (_m, opt, q) => opt + q[0] + " ".repeat(Math.max(0, q.length - 2)) + q[0]);
|
|
1249
|
+
}
|
|
1250
|
+
if (!TEXT_ARG_COMMAND_RE.test(step))
|
|
1251
|
+
return step;
|
|
1252
|
+
if (splitTopLevel(step).slice(1).some((p) => RUNS_PIPED_TEXT_RE.test(p)))
|
|
1253
|
+
return step;
|
|
1254
|
+
// A quoted redirect target (`>> "$HOME/.ssh/authorized_keys"`) is a path, not text.
|
|
1255
|
+
return step.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, (q, at) => /[<>]\s*$/.test(step.slice(0, at)) ? q : q[0] + " ".repeat(Math.max(0, q.length - 2)) + q[0]);
|
|
1256
|
+
})
|
|
1257
|
+
.join("\n");
|
|
1258
|
+
}
|
|
1063
1259
|
// Interpreters whose inline `-e`/`-c`/`--eval` (and perl/deno one-liner) body is
|
|
1064
1260
|
// opaque CODE — not shell. We blank that body before the SHELL-pattern scans so
|
|
1065
1261
|
// tokens embedded as code or data (`rm`, `curl -d`, a `>` redirect) don't trip a
|
|
@@ -1489,6 +1685,21 @@ function classifyMcpTool(toolName, toolInput = {}) {
|
|
|
1489
1685
|
}
|
|
1490
1686
|
if (parts.length === 3 && isClaudeDocsWrite(parts[1] || "", tool, toolInput))
|
|
1491
1687
|
return "warning";
|
|
1688
|
+
// The desktop app's iOS Simulator: a local test device. Looking at it is
|
|
1689
|
+
// safe; taps, typing and installing a local build change only the
|
|
1690
|
+
// simulator, like page clicks in the built-in browser, so they are logged.
|
|
1691
|
+
if (parts.includes("Claude_Code_iOS_Simulator")) {
|
|
1692
|
+
if (tool === "control") {
|
|
1693
|
+
const action = toolInput.action;
|
|
1694
|
+
if (action === "screenshot" || action === "attach" || action === "detach")
|
|
1695
|
+
return "safe";
|
|
1696
|
+
if (["tap", "swipe", "touch_path", "touch2_path", "text", "button", "open_url", "launch"].includes(action))
|
|
1697
|
+
return "warning";
|
|
1698
|
+
return "review";
|
|
1699
|
+
}
|
|
1700
|
+
if (tool === "build")
|
|
1701
|
+
return "warning";
|
|
1702
|
+
}
|
|
1492
1703
|
const browserServer = parts.slice(1, -1).find((p) => BROWSER_MCP_SERVERS.has(p));
|
|
1493
1704
|
if (browserServer)
|
|
1494
1705
|
return classifyBrowserTool(tool, toolInput, browserServer);
|
package/dist/describe.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
11
11
|
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
12
|
-
import { classify, extractShellWriteOps, splitTopLevel } from "./classify.js";
|
|
12
|
+
import { blankTextCommandArgs, classify, extractShellWriteOps, splitTopLevel, stripCodeHeredocBodies, stripInlineScriptBodies } from "./classify.js";
|
|
13
13
|
import { TIER_ORDER } from "./degraded.js";
|
|
14
14
|
const BODY_PREVIEW_MAX = 200;
|
|
15
15
|
const COMMAND_INLINE_MAX = 50;
|
|
@@ -100,8 +100,10 @@ function summarizeMutatingCurl(command) {
|
|
|
100
100
|
return null;
|
|
101
101
|
// Read flags from the curl/wget step only: a `--json` or `-d` on another step
|
|
102
102
|
// (`gh pr view --json state`, `unzip -d dir`) is not this request's body.
|
|
103
|
+
// Quoted text of git, grep and echo is not a request (a commit message that
|
|
104
|
+
// says "curl -d" is not a POST): look for curl in the blanked view.
|
|
103
105
|
const steps = splitTopLevel(command);
|
|
104
|
-
const step = steps.find((s) => /\b(?:curl|wget)\b/.test(s) && isMutatingCurlStep(s));
|
|
106
|
+
const step = steps.find((s) => /\b(?:curl|wget)\b/.test(blankTextCommandArgs(s)) && isMutatingCurlStep(s));
|
|
105
107
|
if (!step)
|
|
106
108
|
return null;
|
|
107
109
|
const cmd = ` ${step}`;
|
|
@@ -168,7 +170,7 @@ function extractCurlPayload(cmd) {
|
|
|
168
170
|
return parts.length ? parts.join("\n") : undefined;
|
|
169
171
|
}
|
|
170
172
|
function summarizeBash(command, sizeBytes, cwd) {
|
|
171
|
-
|
|
173
|
+
let cmd = (command || "").trim();
|
|
172
174
|
if (!cmd)
|
|
173
175
|
return { title: "Run empty command", kind: "unknown_bash" };
|
|
174
176
|
const compound = summarizeCompoundBash(cmd, sizeBytes, cwd);
|
|
@@ -181,6 +183,18 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
181
183
|
const sql = findSqlInCommand(cmd);
|
|
182
184
|
if (sql)
|
|
183
185
|
return summarizeSql(sql, cmd);
|
|
186
|
+
// A Python or Node script fed by a heredoc is code: show it as a script, and
|
|
187
|
+
// read the rest of the command without the script body, so its text
|
|
188
|
+
// ("npm publish", "git push --force") does not name the card.
|
|
189
|
+
const script = summarizeCodeHeredoc(cmd);
|
|
190
|
+
if (script)
|
|
191
|
+
return script;
|
|
192
|
+
cmd = stripCodeHeredocBodies(cmd);
|
|
193
|
+
// Text piped into a shell runs as a script that no step shows by name.
|
|
194
|
+
const toShell = cmd.match(/^(.*?)\|\s*(?:sudo\s+)?((?:ba|z|k|da)?sh)\b(?!\s+-n\b)/s);
|
|
195
|
+
if (toShell && !/\b(?:curl|wget)\b/.test(toShell[1]) && splitTopLevel(cmd, { pipes: false }).length === 1) {
|
|
196
|
+
return { title: `Run text as a ${toShell[2]} script`, body: truncateBody(cmd), kind: "shell_pipeline" };
|
|
197
|
+
}
|
|
184
198
|
// A mutating curl/wget (POST/PUT/DELETE, or a request body) is described
|
|
185
199
|
// BEFORE shell-write detection. In a compound command the outward request is
|
|
186
200
|
// the headline operation, while a `> log` redirect is incidental — otherwise
|
|
@@ -201,11 +215,24 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
201
215
|
// `(.+)$`: without the `m` flag `$` only reaches end-of-string, so a `rm` on
|
|
202
216
|
// an interior line of a multi-line script (e.g. `rm "$WT/node_modules"` before
|
|
203
217
|
// a trailing `cd … && git status`) wouldn't match and the card fell back to
|
|
204
|
-
// the generic "Run command".
|
|
205
|
-
|
|
218
|
+
// the generic "Run command". Match the shell text, so `rmdir` in a commit
|
|
219
|
+
// message or a `--reason "…"` value is not a delete.
|
|
220
|
+
const rmMatch = shellText(cmd).match(/\b(rm|trash|trash-put|rmdir)\s+(?:(-rf?|-fr|--recursive|-r)\s+)?([^\n]+)/);
|
|
221
|
+
if (rmMatch && rmMatch[1] === "rmdir") {
|
|
222
|
+
// rmdir removes empty folders only.
|
|
223
|
+
const vars = literalAssignments(cmd);
|
|
224
|
+
const targets = parseRmTargets(rmMatch[3]).map((t) => shortenPath(stripQuotes(expandVars(t, vars))));
|
|
225
|
+
return targets.length <= 1
|
|
226
|
+
? { title: "Delete empty folder", target: targets[0], kind: "file_delete" }
|
|
227
|
+
: { title: `Delete ${targets.length} empty folders`, target: targets.join("\n"), kind: "file_delete" };
|
|
228
|
+
}
|
|
206
229
|
if (rmMatch) {
|
|
207
|
-
|
|
208
|
-
const
|
|
230
|
+
// Recursive only with an r/R flag: `rm -f x` deletes one file.
|
|
231
|
+
const flags = (rmMatch[2] ? `${rmMatch[2]} ` : "") + rmMatch[3];
|
|
232
|
+
const recursive = /(?:^|\s)(?:-[a-zA-Z]*[rR][a-zA-Z]*|--recursive)(?=\s|$)/.test(flags.split(/[;&|\n]/)[0]);
|
|
233
|
+
// `D=/some/dir; rm -f $D/x` shows the real path, not `$D/x`.
|
|
234
|
+
const vars = literalAssignments(cmd);
|
|
235
|
+
const targets = parseRmTargets(rmMatch[3]).map((t) => expandVars(t, vars));
|
|
209
236
|
if (targets.length <= 1) {
|
|
210
237
|
const target = targets[0] || "files";
|
|
211
238
|
const sqlExt = !recursive && /\.sql$/i.test(target);
|
|
@@ -225,7 +252,7 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
225
252
|
};
|
|
226
253
|
}
|
|
227
254
|
// git
|
|
228
|
-
if (/\bgit\s+push\b/.test(cmd)) {
|
|
255
|
+
if (/\bgit\s+push\b/.test(shellText(cmd))) {
|
|
229
256
|
// Parse the remote + branch ignoring flags (-u, --force, --set-upstream, …)
|
|
230
257
|
// so `git push -u origin feat` renders "feat → origin", not "origin → -u".
|
|
231
258
|
const after = cmd.match(/\bgit\s+push\b(.*)$/s)?.[1] ?? "";
|
|
@@ -237,6 +264,19 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
237
264
|
? { title: "Force push", target, kind: "git_force_push" }
|
|
238
265
|
: { title: "Push", target, kind: "git_push" };
|
|
239
266
|
}
|
|
267
|
+
const branchDelete = cmd.match(/\bgit\s+branch\s+(?:-D|--delete\s+--force|-d|--delete)\s+([^\s;&|]+)/);
|
|
268
|
+
if (branchDelete) {
|
|
269
|
+
const forced = /\bgit\s+branch\s+(?:-D|--delete\s+--force)\b/.test(cmd);
|
|
270
|
+
return {
|
|
271
|
+
title: "Delete local Git branch",
|
|
272
|
+
target: branchDelete[1],
|
|
273
|
+
annotation: forced ? "even if not merged" : undefined,
|
|
274
|
+
kind: "git_branch_delete",
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const prisma = summarizePrismaDeploy(cmd);
|
|
278
|
+
if (prisma)
|
|
279
|
+
return prisma;
|
|
240
280
|
if (/\bgit\s+reset\s+--hard\b/.test(cmd))
|
|
241
281
|
return { title: "Hard reset — discard all local changes", kind: "git_reset_hard" };
|
|
242
282
|
if (/\bgit\s+clean\s+-f/.test(cmd))
|
|
@@ -250,7 +290,8 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
250
290
|
// message is a command substitution / heredoc — `-m "$(cat <<'EOF' … )"` —
|
|
251
291
|
// since that has no clean inline title to extract.
|
|
252
292
|
const m = cmd.match(/-m\s+["']([^"'$]+)["']/);
|
|
253
|
-
|
|
293
|
+
// The subject line only: a multi-line message made a multi-line title.
|
|
294
|
+
return m ? { title: `Git commit "${truncate(m[1].split("\n")[0].trim(), 60)}"`, kind: "git_commit" } : { title: "Git commit", kind: "git_commit" };
|
|
254
295
|
}
|
|
255
296
|
const gh = summarizeGh(cmd);
|
|
256
297
|
if (gh)
|
|
@@ -303,11 +344,7 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
303
344
|
// so "kill" inside echo text (e.g. "killing it") doesn't mislabel.
|
|
304
345
|
const killM = cmd.match(/(?:^|[\n;&|`({]|\$\(|\b(?:sudo|then|do|else|command|xargs)\s+)\s*(killall|pkill|kill)\b/);
|
|
305
346
|
if (killM) {
|
|
306
|
-
return {
|
|
307
|
-
title: killM[1].toLowerCase() === "kill" ? "Kill process" : "Kill processes",
|
|
308
|
-
body: truncateBody(cmd),
|
|
309
|
-
kind: "kill_process",
|
|
310
|
-
};
|
|
347
|
+
return { ...killTarget(cmd.slice((killM.index ?? 0) + killM[0].length - killM[1].length)), body: truncateBody(cmd), kind: "kill_process" };
|
|
311
348
|
}
|
|
312
349
|
// Multi-step pipeline
|
|
313
350
|
if (/&&|\|\||;/.test(cmd))
|
|
@@ -343,9 +380,9 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
343
380
|
return { title: "Install npm dependencies", kind: "npm_install" };
|
|
344
381
|
if (/\bnpm\s+test\b/.test(cmd))
|
|
345
382
|
return { title: "Run npm tests", kind: "npm_test" };
|
|
346
|
-
if (/\bnpm\s+unpublish\b/.test(cmd))
|
|
383
|
+
if (/\bnpm\s+unpublish\b/.test(shellText(cmd)))
|
|
347
384
|
return { title: "Unpublish package from npm", kind: "npm_unpublish" };
|
|
348
|
-
if (/\bnpx\s+.*\s+deploy\b/.test(cmd))
|
|
385
|
+
if (/\bnpx\s+.*\s+deploy\b/.test(shellText(cmd)))
|
|
349
386
|
return { title: "Deploy via npx", body: truncateBody(cmd), kind: "npx_deploy" };
|
|
350
387
|
// sudo / chmod (kill/pkill/killall are handled in command position above,
|
|
351
388
|
// ahead of the compound catch-all).
|
|
@@ -383,12 +420,17 @@ function summarizeCompoundBash(cmd, sizeBytes, cwd) {
|
|
|
383
420
|
if (TIER_ORDER[classify("Bash", { command: cmd })] !== top)
|
|
384
421
|
return null;
|
|
385
422
|
const lead = rank.indexOf(top);
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const
|
|
423
|
+
// Variables set by earlier steps (`D=/dir; rm $D/x`) show as their values.
|
|
424
|
+
const vars = literalAssignments(cmd);
|
|
425
|
+
const step = expandVars(steps[lead], vars);
|
|
426
|
+
// npm publish reads the package.json a preceding `cd` points at; prisma reads
|
|
427
|
+
// a DATABASE_URL an earlier step exported.
|
|
428
|
+
const r = (/\bnpm\s+publish\b/.test(step) && summarizeNpmPublish(cmd, cwd)) ||
|
|
429
|
+
summarizePrismaDeploy(/\bprisma\s+migrate\s+deploy\b/.test(step) ? cmd : "") ||
|
|
430
|
+
summarizeBash(step, sizeBytes, cwd);
|
|
389
431
|
const also = [...new Set(steps
|
|
390
432
|
.filter((_, i) => i !== lead && rank[i] >= TIER_ORDER.review)
|
|
391
|
-
.map((s) => describeStep(s, cwd)))].filter((t) => t !== describeStep(step, cwd));
|
|
433
|
+
.map((s) => describeStep(expandVars(s, vars), cwd)))].filter((t) => t !== describeStep(step, cwd));
|
|
392
434
|
// The body shows the steps that need approval, not the setup and polling
|
|
393
435
|
// around them; the footnote says there are other steps.
|
|
394
436
|
const risky = steps.filter((_, i) => rank[i] >= TIER_ORDER.review);
|
|
@@ -469,9 +511,11 @@ function summarizeGh(cmd) {
|
|
|
469
511
|
* Name/version come from the package.json the publish will read: the cwd,
|
|
470
512
|
* adjusted by a preceding `cd`, a `--workspace`, or a folder argument.
|
|
471
513
|
*/
|
|
514
|
+
const NPM_PUBLISH_STEP_RE = /(?:^|[\n;&|(]|\$\()\s*(?:\w+=\S+\s+)*(?:sudo\s+)?npm\s+publish\b([^\n;&|)]*)/;
|
|
472
515
|
function summarizeNpmPublish(cmd, cwd) {
|
|
473
|
-
const m = cmd.match(
|
|
474
|
-
|
|
516
|
+
const m = cmd.match(NPM_PUBLISH_STEP_RE);
|
|
517
|
+
// `grep "verify\|npm publish" x | head` searches for the words, it does not publish.
|
|
518
|
+
if (!m || !NPM_PUBLISH_STEP_RE.test(shellText(cmd)))
|
|
475
519
|
return null;
|
|
476
520
|
const tokens = m[1].trim().split(/\s+/).filter(Boolean).map(stripQuotes);
|
|
477
521
|
const flags = {};
|
|
@@ -646,7 +690,11 @@ const INTERPRETER_CONSUMER_RE = /(?:^|\||&&|;|\$\(|`)\s*(?:\w+=\S+\s+)*(?:sudo\s
|
|
|
646
690
|
// words but no .execute()-style call and no DB library cannot run SQL: it is
|
|
647
691
|
// text processing (a Python script that edits a source file whose comments
|
|
648
692
|
// say "DELETE FROM", for example), so it must not be shown as a SQL statement.
|
|
649
|
-
|
|
693
|
+
//
|
|
694
|
+
// The library must be loaded (import, require, from, use), not only named: a
|
|
695
|
+
// script that edits describe.ts, whose text says "psql" and "sqlite3", or a
|
|
696
|
+
// schema.prisma file, names a library without using one.
|
|
697
|
+
const DB_LIBRARY_RE = /(?:\bimport\s+|\bfrom\s+)['"]?(?:sqlite3|better-sqlite3|psycopg2?|psycopg|pymysql|MySQLdb|mysql2?|sqlalchemy|duckdb|knex|pg|@prisma\/client)\b|\brequire\(\s*['"](?:sqlite3|better-sqlite3|pg|mysql2?|knex|duckdb|@prisma\/client)['"]|\bnew\s+PrismaClient\b|\buse\s+DBI\b|\bSequel\.connect\b|\bsqlite3\.connect\s*\(|\bpsycopg2?\.connect\s*\(/;
|
|
650
698
|
// SQL to run from an interpreter body (node -e, python -c, `python - <<EOF`).
|
|
651
699
|
function sqlFromInterpreterBody(body) {
|
|
652
700
|
if (!SQL_KEYWORDS_RE.test(body))
|
|
@@ -1227,6 +1275,27 @@ function summarizeMcp(toolName, input) {
|
|
|
1227
1275
|
/** Desktop app tools whose name alone does not say what they do. */
|
|
1228
1276
|
function summarizeDesktopApp(server, tool, input) {
|
|
1229
1277
|
const str = (v) => (typeof v === "string" && v.trim() ? v.trim() : undefined);
|
|
1278
|
+
if (server === "Claude_Code_iOS_Simulator" && tool === "control")
|
|
1279
|
+
return summarizeSimulator(input);
|
|
1280
|
+
if (server === "scheduled-tasks") {
|
|
1281
|
+
const name = str(input.title) ?? str(input.taskId);
|
|
1282
|
+
const when = str(input.cronExpression) ? `cron ${str(input.cronExpression)}` : str(input.fireAt) ? `once at ${str(input.fireAt)}` : undefined;
|
|
1283
|
+
const verb = { create_scheduled_task: "Create a scheduled task", update_scheduled_task: "Change a scheduled task",
|
|
1284
|
+
run_scheduled_task: "Run a scheduled task now", delete_scheduled_task: "Delete a scheduled task" }[tool];
|
|
1285
|
+
if (verb) {
|
|
1286
|
+
const change = tool === "update_scheduled_task"
|
|
1287
|
+
? [input.prompt !== undefined ? "prompt" : "", when ? "schedule" : "", input.enabled === false ? "pause" : input.enabled === true ? "resume" : ""].filter(Boolean).join(", ")
|
|
1288
|
+
: "";
|
|
1289
|
+
return {
|
|
1290
|
+
title: verb,
|
|
1291
|
+
target: name,
|
|
1292
|
+
annotation: [when, change ? `changes: ${change}` : ""].filter(Boolean).join(" · ") || undefined,
|
|
1293
|
+
body: str(input.prompt),
|
|
1294
|
+
footnote: tool === "create_scheduled_task" ? "Claude runs this prompt on its own on this schedule" : undefined,
|
|
1295
|
+
kind: "schedule",
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1230
1299
|
if (server === "ccd_turn" && tool === "update_plan") {
|
|
1231
1300
|
return { title: "Update the task list in the Claude app", kind: "session_housekeeping" };
|
|
1232
1301
|
}
|
|
@@ -1245,6 +1314,27 @@ function summarizeDesktopApp(server, tool, input) {
|
|
|
1245
1314
|
}
|
|
1246
1315
|
return null;
|
|
1247
1316
|
}
|
|
1317
|
+
/** The desktop app's iOS Simulator tool: one `control` tool, many actions. */
|
|
1318
|
+
function summarizeSimulator(input) {
|
|
1319
|
+
const a = typeof input.action === "string" ? input.action : "";
|
|
1320
|
+
const at = typeof input.x === "number" && typeof input.y === "number" ? `(${input.x}, ${input.y})` : undefined;
|
|
1321
|
+
const titles = {
|
|
1322
|
+
attach: "Show the iOS Simulator panel", detach: "Close the iOS Simulator panel", screenshot: "Take an iOS Simulator screenshot",
|
|
1323
|
+
launch: "Install and open an app in the iOS Simulator", tap: "Tap in the iOS Simulator", swipe: "Swipe in the iOS Simulator",
|
|
1324
|
+
touch_path: "Drag in the iOS Simulator", touch2_path: "Pinch or rotate in the iOS Simulator", text: "Type text in the iOS Simulator",
|
|
1325
|
+
button: "Press a button in the iOS Simulator", open_url: "Open a link in the iOS Simulator",
|
|
1326
|
+
};
|
|
1327
|
+
const target = a === "launch" ? (typeof input.bundle_id === "string" ? input.bundle_id : typeof input.app_path === "string" ? shortenPath(input.app_path) : undefined)
|
|
1328
|
+
: a === "open_url" ? input.url
|
|
1329
|
+
: a === "button" ? input.name
|
|
1330
|
+
: at;
|
|
1331
|
+
return {
|
|
1332
|
+
title: titles[a] ?? `Use the iOS Simulator${a ? ` (${a})` : ""}`,
|
|
1333
|
+
target,
|
|
1334
|
+
body: a === "text" && typeof input.text === "string" ? input.text : undefined,
|
|
1335
|
+
kind: "simulator",
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1248
1338
|
function identifyTarget(input) {
|
|
1249
1339
|
const id = input.id ?? input.name ?? input.path ?? input.target ?? input.repo ?? input.repository ?? null;
|
|
1250
1340
|
if (id == null)
|
|
@@ -1568,6 +1658,77 @@ function parseRmTargets(argsString) {
|
|
|
1568
1658
|
}
|
|
1569
1659
|
return targets;
|
|
1570
1660
|
}
|
|
1661
|
+
/** What a kill stops: a pattern, process names, a port, or process ids. */
|
|
1662
|
+
function killTarget(step) {
|
|
1663
|
+
const line = step.split(/\n|;|&&|\|\|/)[0].trim();
|
|
1664
|
+
const words = (s) => (s.match(/'[^']*'|"[^"]*"|\S+/g) ?? []).map((w) => w.replace(/^['"]|['"]$/g, ""));
|
|
1665
|
+
if (/^pkill\b/.test(line)) {
|
|
1666
|
+
const w = words(line.replace(/\|.*$/, "")).slice(1).filter((x) => !/^-(?!f$)/.test(x));
|
|
1667
|
+
const f = w.indexOf("-f");
|
|
1668
|
+
return { title: "Stop processes matching", target: (f >= 0 ? w[f + 1] : w[w.length - 1]) || undefined };
|
|
1669
|
+
}
|
|
1670
|
+
if (/^killall\b/.test(line)) {
|
|
1671
|
+
return { title: "Stop processes named", target: words(line).slice(1).filter((x) => !x.startsWith("-")).join(", ") || undefined };
|
|
1672
|
+
}
|
|
1673
|
+
const port = line.match(/lsof\b[^)]*?-i\s*(?:tcp|TCP|udp)?:?(\d+)|-iTCP:(\d+)/);
|
|
1674
|
+
if (port)
|
|
1675
|
+
return { title: "Stop the process on port", target: port[1] ?? port[2] };
|
|
1676
|
+
const pg = line.match(/\$\(\s*pgrep\s+(?:-\w+\s+)*(?:-f\s+)?(['"]?)(.+?)\1\s*\)/);
|
|
1677
|
+
if (pg)
|
|
1678
|
+
return { title: "Stop processes matching", target: pg[2] };
|
|
1679
|
+
const pids = words(line).slice(1).filter((x) => /^\d+$/.test(x));
|
|
1680
|
+
if (pids.length)
|
|
1681
|
+
return { title: pids.length === 1 ? "Stop process" : "Stop processes", target: `PID ${pids.join(", ")}` };
|
|
1682
|
+
return { title: "Stop processes" };
|
|
1683
|
+
}
|
|
1684
|
+
/** `python3 - <<'EOF' … EOF` (one step): "Run a Python script" with the script as the body. */
|
|
1685
|
+
function summarizeCodeHeredoc(cmd) {
|
|
1686
|
+
if (splitTopLevel(cmd).length > 1)
|
|
1687
|
+
return null;
|
|
1688
|
+
const m = cmd.match(/^(?:\w+=\S+\s+)*(?:sudo\s+)?(node|python\d?(?:\.\d+)?|ruby|perl|deno|bun)\b[^\n]*<<-?\s*(["']?)([A-Za-z_]\w*)\2[^\n]*\n([\s\S]*?)\n\s*\3\s*$/);
|
|
1689
|
+
if (!m)
|
|
1690
|
+
return null;
|
|
1691
|
+
const lang = m[1].startsWith("python") ? "Python" : m[1] === "node" ? "Node" : m[1].charAt(0).toUpperCase() + m[1].slice(1);
|
|
1692
|
+
const files = [...m[4].matchAll(/(?:open|readFileSync|writeFileSync|Path)\(\s*['"]([^'"]+)['"]/g)].map((f) => f[1]);
|
|
1693
|
+
const edits = /\.write\(|writeFileSync|write_text\(/.test(m[4]);
|
|
1694
|
+
return {
|
|
1695
|
+
title: edits && files.length ? `Edit file with a ${lang} script` : `Run a ${lang} script`,
|
|
1696
|
+
target: files.length ? [...new Set(files)].map(shortenPath).join("\n") : undefined,
|
|
1697
|
+
body: truncateBody(m[4]),
|
|
1698
|
+
kind: edits ? "file_edit" : "script_run",
|
|
1699
|
+
};
|
|
1700
|
+
}
|
|
1701
|
+
/** `prisma migrate deploy`: which database, from a DATABASE_URL set in the command. */
|
|
1702
|
+
function summarizePrismaDeploy(cmd) {
|
|
1703
|
+
if (!/\bprisma\s+migrate\s+deploy\b/.test(shellText(cmd)))
|
|
1704
|
+
return null;
|
|
1705
|
+
const url = cmd.match(/DATABASE_URL=["']?([a-z]+:\/\/[^\s"';&|]+)/)?.[1];
|
|
1706
|
+
let db;
|
|
1707
|
+
if (url) {
|
|
1708
|
+
try {
|
|
1709
|
+
const u = new URL(url);
|
|
1710
|
+
db = `${u.hostname}${u.port ? `:${u.port}` : ""}${u.pathname}`;
|
|
1711
|
+
}
|
|
1712
|
+
catch { /* keep undefined */ }
|
|
1713
|
+
}
|
|
1714
|
+
return { title: "Apply Prisma database migrations", target: db, annotation: db ? undefined : "to the database in DATABASE_URL", kind: "sql_migrate" };
|
|
1715
|
+
}
|
|
1716
|
+
/** The command as the shell runs it: quoted text arguments and inline script
|
|
1717
|
+
* bodies (`node -e '…'`) blanked, so words in them do not name the card. */
|
|
1718
|
+
function shellText(cmd) {
|
|
1719
|
+
return blankTextCommandArgs(stripInlineScriptBodies(cmd));
|
|
1720
|
+
}
|
|
1721
|
+
/** `NAME=value` assignments with a literal value (no `$(…)`, no backticks), in order. */
|
|
1722
|
+
function literalAssignments(cmd) {
|
|
1723
|
+
const vars = new Map();
|
|
1724
|
+
const re = /(?:^|[;&|\n(]\s*)(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=("[^"$`]*"|'[^']*'|[^\s;&|$`'"()]+)(?=[\s;&|)]|$)/g;
|
|
1725
|
+
for (const m of cmd.matchAll(re))
|
|
1726
|
+
vars.set(m[1], m[2].replace(/^["']|["']$/g, ""));
|
|
1727
|
+
return vars;
|
|
1728
|
+
}
|
|
1729
|
+
function expandVars(token, vars) {
|
|
1730
|
+
return token.replace(/\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?/g, (whole, name) => vars.get(name) ?? whole);
|
|
1731
|
+
}
|
|
1571
1732
|
function stripQuotes(s) {
|
|
1572
1733
|
return s.replace(/^['"]|['"]$/g, "");
|
|
1573
1734
|
}
|
package/dist/kinds.d.ts
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* classifier that produced them.
|
|
8
8
|
*/
|
|
9
9
|
export declare const CLASSIFIER_VERSION = "v3";
|
|
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" | "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" | "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" | "worktree" | "schedule" | "agent_message" | "web_fetch" | "monitor" | "artifact" | "agent_launch" | "shell_pipeline" | "unknown_bash" | "unknown_tool";
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oked/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "OKed SDK - human approval layer for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@oked/receipt-core": "0.6.
|
|
48
|
+
"@oked/receipt-core": "0.6.9"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.13.10",
|