@oked/sdk 0.6.9 → 0.6.10
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 +7 -1
- package/dist/classify.js +20 -4
- package/dist/describe.js +10 -3
- package/package.json +2 -2
package/dist/classify.d.ts
CHANGED
|
@@ -28,6 +28,9 @@ export interface ShellWriteOp {
|
|
|
28
28
|
* otherwise wreck classification). Only heredocs whose opener line invokes an
|
|
29
29
|
* interpreter (`psql <<EOF`, `node - <<EOF`, `cat <<EOF | bash`) keep their
|
|
30
30
|
* body, so SQL/code detection still runs. The opener line is always preserved.
|
|
31
|
+
* The closing delimiter line is kept too: without it, splitTopLevel cannot see
|
|
32
|
+
* where the heredoc ends and joins every later step (`; rm -rf …`) into the
|
|
33
|
+
* heredoc's step, where a delete or merge after `;` is not seen.
|
|
31
34
|
*/
|
|
32
35
|
export declare function stripHeredocBodies(command: string): string;
|
|
33
36
|
/**
|
|
@@ -35,8 +38,11 @@ export declare function stripHeredocBodies(command: string): string;
|
|
|
35
38
|
* scans only (the same policy as `-e`/`-c` bodies below). A Python script that
|
|
36
39
|
* edits a file whose text says "git push --force" or "npm publish" is not a
|
|
37
40
|
* force push or a publish. SQL detection still reads the intact body.
|
|
41
|
+
* `dropClose` also drops the closing delimiter line, for card text only.
|
|
38
42
|
*/
|
|
39
|
-
export declare function stripCodeHeredocBodies(command: string
|
|
43
|
+
export declare function stripCodeHeredocBodies(command: string, opts?: {
|
|
44
|
+
dropClose?: boolean;
|
|
45
|
+
}): string;
|
|
40
46
|
/**
|
|
41
47
|
* Blank the inside of quoted arguments of text commands, for the SHELL-pattern
|
|
42
48
|
* scans only, so `git commit -m "curl -d sends JSON"` or `grep "curl -X POST"`
|
package/dist/classify.js
CHANGED
|
@@ -235,6 +235,10 @@ const HIGH_STAKES_STAGE = [
|
|
|
235
235
|
/^git\s+branch\s+(?:-D|--delete)\b/,
|
|
236
236
|
/^git\s+tag\s+(?:-d|--delete)\b/,
|
|
237
237
|
/^git\s+stash\s+(?:drop|clear)\b/,
|
|
238
|
+
// Remote branch delete: it leaves the machine and removes the branch for
|
|
239
|
+
// everyone (`git push origin --delete feat`, `git push origin :feat`).
|
|
240
|
+
/^git\s+push\b.*\s(?:--delete|-d)\b/,
|
|
241
|
+
/^git\s+push\b.*\s\+?:[^\s:]+(?:\s|$)/,
|
|
238
242
|
// Process termination.
|
|
239
243
|
/^kill\b/,
|
|
240
244
|
/^pkill\b/,
|
|
@@ -1154,8 +1158,13 @@ function classifySqlSeverity(sql) {
|
|
|
1154
1158
|
// scannable. Detected as a command word at the start of the opener line or
|
|
1155
1159
|
// after a pipe / `&&` / `;` / `$(` / backtick.
|
|
1156
1160
|
const HEREDOC_INTERPRETER_RE = /(?:^|\||&&|;|\$\(|`)\s*(?:\w+=\S+\s+)*(?:sudo\s+)?(?:psql|mysql|mariadb|sqlite3?|node|python\d?|ruby|perl|deno|bun|bash|sh|zsh|ksh|fish)\b/;
|
|
1161
|
+
// Only the step that holds the heredoc reads its body. An interpreter in an
|
|
1162
|
+
// earlier step on the same line (`V=$(node -p '…'); cat > f <<'EOF'`) does not.
|
|
1163
|
+
// splitTopLevel keeps the opener and the rest of the line in the last step, so
|
|
1164
|
+
// a pipe after the opener (`cat <<EOF | bash`) still counts.
|
|
1157
1165
|
function openerFeedsInterpreter(line) {
|
|
1158
|
-
|
|
1166
|
+
const steps = splitTopLevel(line, { pipes: false });
|
|
1167
|
+
return HEREDOC_INTERPRETER_RE.test(steps[steps.length - 1] ?? line);
|
|
1159
1168
|
}
|
|
1160
1169
|
/**
|
|
1161
1170
|
* Removes heredoc *bodies* unless they're fed to an interpreter/DB/shell that
|
|
@@ -1166,6 +1175,9 @@ function openerFeedsInterpreter(line) {
|
|
|
1166
1175
|
* otherwise wreck classification). Only heredocs whose opener line invokes an
|
|
1167
1176
|
* interpreter (`psql <<EOF`, `node - <<EOF`, `cat <<EOF | bash`) keep their
|
|
1168
1177
|
* body, so SQL/code detection still runs. The opener line is always preserved.
|
|
1178
|
+
* The closing delimiter line is kept too: without it, splitTopLevel cannot see
|
|
1179
|
+
* where the heredoc ends and joins every later step (`; rm -rf …`) into the
|
|
1180
|
+
* heredoc's step, where a delete or merge after `;` is not seen.
|
|
1169
1181
|
*/
|
|
1170
1182
|
export function stripHeredocBodies(command) {
|
|
1171
1183
|
const lines = command.split("\n");
|
|
@@ -1184,7 +1196,7 @@ export function stripHeredocBodies(command) {
|
|
|
1184
1196
|
while (i < lines.length && lines[i].trim() !== delim)
|
|
1185
1197
|
i++; // drop body
|
|
1186
1198
|
if (i < lines.length)
|
|
1187
|
-
i
|
|
1199
|
+
out.push(lines[i++]); // keep the closing delimiter line
|
|
1188
1200
|
continue;
|
|
1189
1201
|
}
|
|
1190
1202
|
i++;
|
|
@@ -1199,8 +1211,9 @@ const CODE_HEREDOC_RE = /(?:^|\||&&|;|\$\(|`)\s*(?:\w+=\S+\s+)*(?:sudo\s+)?(?:ps
|
|
|
1199
1211
|
* scans only (the same policy as `-e`/`-c` bodies below). A Python script that
|
|
1200
1212
|
* edits a file whose text says "git push --force" or "npm publish" is not a
|
|
1201
1213
|
* force push or a publish. SQL detection still reads the intact body.
|
|
1214
|
+
* `dropClose` also drops the closing delimiter line, for card text only.
|
|
1202
1215
|
*/
|
|
1203
|
-
export function stripCodeHeredocBodies(command) {
|
|
1216
|
+
export function stripCodeHeredocBodies(command, opts = {}) {
|
|
1204
1217
|
const lines = command.split("\n");
|
|
1205
1218
|
const out = [];
|
|
1206
1219
|
let i = 0;
|
|
@@ -1213,8 +1226,11 @@ export function stripCodeHeredocBodies(command) {
|
|
|
1213
1226
|
i++;
|
|
1214
1227
|
while (i < lines.length && lines[i].trim() !== delim)
|
|
1215
1228
|
i++;
|
|
1216
|
-
if (i < lines.length)
|
|
1229
|
+
if (i < lines.length) {
|
|
1230
|
+
if (!opts.dropClose)
|
|
1231
|
+
out.push(lines[i]); // keep the closing line (see stripHeredocBodies)
|
|
1217
1232
|
i++;
|
|
1233
|
+
}
|
|
1218
1234
|
continue;
|
|
1219
1235
|
}
|
|
1220
1236
|
i++;
|
package/dist/describe.js
CHANGED
|
@@ -189,7 +189,7 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
189
189
|
const script = summarizeCodeHeredoc(cmd);
|
|
190
190
|
if (script)
|
|
191
191
|
return script;
|
|
192
|
-
cmd = stripCodeHeredocBodies(cmd);
|
|
192
|
+
cmd = stripCodeHeredocBodies(cmd, { dropClose: true });
|
|
193
193
|
// Text piped into a shell runs as a script that no step shows by name.
|
|
194
194
|
const toShell = cmd.match(/^(.*?)\|\s*(?:sudo\s+)?((?:ba|z|k|da)?sh)\b(?!\s+-n\b)/s);
|
|
195
195
|
if (toShell && !/\b(?:curl|wget)\b/.test(toShell[1]) && splitTopLevel(cmd, { pipes: false }).length === 1) {
|
|
@@ -258,6 +258,10 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
258
258
|
const after = cmd.match(/\bgit\s+push\b(.*)$/s)?.[1] ?? "";
|
|
259
259
|
const args = after.split(/\s+/).filter((a) => a && !a.startsWith("-"));
|
|
260
260
|
const [remote, branch] = args;
|
|
261
|
+
const deleted = /\s(?:--delete|-d)\b/.test(after) ? branch : branch?.match(/^\+?:([^\s:]+)$/)?.[1];
|
|
262
|
+
if (remote && deleted) {
|
|
263
|
+
return { title: "Delete remote Git branch", target: `${deleted} on ${remote}`, kind: "git_branch_delete" };
|
|
264
|
+
}
|
|
261
265
|
const target = remote && branch ? `${branch} → ${remote}` : remote || "current branch";
|
|
262
266
|
const forced = /\bgit\s+push\b[^\n]*\s(?:--force(?:-with-lease)?|-f)\b/.test(cmd);
|
|
263
267
|
return forced
|
|
@@ -535,7 +539,9 @@ function summarizeNpmPublish(cmd, cwd) {
|
|
|
535
539
|
else
|
|
536
540
|
flags[name] = value;
|
|
537
541
|
}
|
|
538
|
-
else if (positional === undefined) {
|
|
542
|
+
else if (positional === undefined && /^[\w.~/@-][\w.~/@+-]*$/.test(t)) {
|
|
543
|
+
// A folder or tarball. Quote and bracket leftovers from quoted data
|
|
544
|
+
// (`…publish\"]'`) are not a path.
|
|
539
545
|
positional = t;
|
|
540
546
|
}
|
|
541
547
|
}
|
|
@@ -545,7 +551,8 @@ function summarizeNpmPublish(cmd, cwd) {
|
|
|
545
551
|
const cds = [...before.matchAll(/(?:^|[\n;&|(])\s*cd\s+("[^"]+"|'[^']+'|\S+)/g)];
|
|
546
552
|
if (cds.length) {
|
|
547
553
|
const dir = stripQuotes(cds[cds.length - 1][1]);
|
|
548
|
-
|
|
554
|
+
// `cd $SP/pkg`: the variable is not known here, so the folder is not known.
|
|
555
|
+
baseDir = /[$`]/.test(dir) ? undefined : isAbsolute(dir) ? dir : baseDir ? resolve(baseDir, dir) : undefined;
|
|
549
556
|
}
|
|
550
557
|
const allWorkspaces = flags["--workspaces"] === true || flags["-ws"] === true;
|
|
551
558
|
let pkgDirs = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oked/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
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.10"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.13.10",
|