@oked/sdk 0.6.9 → 0.6.11
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 +142 -32
- 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
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* from the `fields` payload. `describe()` returns just the title for
|
|
8
8
|
* backwards-compatible single-line consumers (audit logs, SMS).
|
|
9
9
|
*/
|
|
10
|
-
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
11
|
-
import {
|
|
10
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
12
13
|
import { blankTextCommandArgs, classify, extractShellWriteOps, splitTopLevel, stripCodeHeredocBodies, stripInlineScriptBodies } from "./classify.js";
|
|
13
14
|
import { TIER_ORDER } from "./degraded.js";
|
|
14
15
|
const BODY_PREVIEW_MAX = 200;
|
|
@@ -189,7 +190,7 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
189
190
|
const script = summarizeCodeHeredoc(cmd);
|
|
190
191
|
if (script)
|
|
191
192
|
return script;
|
|
192
|
-
cmd = stripCodeHeredocBodies(cmd);
|
|
193
|
+
cmd = stripCodeHeredocBodies(cmd, { dropClose: true });
|
|
193
194
|
// Text piped into a shell runs as a script that no step shows by name.
|
|
194
195
|
const toShell = cmd.match(/^(.*?)\|\s*(?:sudo\s+)?((?:ba|z|k|da)?sh)\b(?!\s+-n\b)/s);
|
|
195
196
|
if (toShell && !/\b(?:curl|wget)\b/.test(toShell[1]) && splitTopLevel(cmd, { pipes: false }).length === 1) {
|
|
@@ -251,24 +252,43 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
251
252
|
kind: "file_delete",
|
|
252
253
|
};
|
|
253
254
|
}
|
|
254
|
-
// git
|
|
255
|
-
|
|
255
|
+
// git. Each card names the repo: the folder the command runs in (after a
|
|
256
|
+
// `cd` or `git -C`), shown as owner/name from its origin remote.
|
|
257
|
+
const gitCmd = cmd.replace(GIT_C_RE, "git ");
|
|
258
|
+
const repoAt = (re) => gitRepoFor(cmd, re, cwd);
|
|
259
|
+
const inRepo = (re) => {
|
|
260
|
+
const repo = repoAt(re);
|
|
261
|
+
return repo ? ` in ${repo.name}` : "";
|
|
262
|
+
};
|
|
263
|
+
if (/\bgit\s+push\b/.test(shellText(gitCmd))) {
|
|
256
264
|
// Parse the remote + branch ignoring flags (-u, --force, --set-upstream, …)
|
|
257
265
|
// so `git push -u origin feat` renders "feat → origin", not "origin → -u".
|
|
258
|
-
|
|
266
|
+
// The arguments end at a quote or a separator: `node x '["git push origin
|
|
267
|
+
// main","git push …"]'` pushes main, not `main","git`.
|
|
268
|
+
const after = gitCmd.match(/\bgit\s+push\b([^\n;&|"'`)]*)/)?.[1] ?? "";
|
|
259
269
|
const args = after.split(/\s+/).filter((a) => a && !a.startsWith("-"));
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
const
|
|
270
|
+
const repo = repoAt(/\bgit\s+(?:-C\s+\S+\s+)?push\b/);
|
|
271
|
+
const remote = args[0] ?? (repo?.remotes.has("origin") ? "origin" : undefined);
|
|
272
|
+
const branch = args[1] ?? (args[0] === undefined ? repo?.branch : undefined);
|
|
273
|
+
const dest = remote ? repoSlug(repo?.remotes.get(remote)) ?? remote : undefined;
|
|
274
|
+
// Name the local repo when the remote did not.
|
|
275
|
+
const annotation = repo && dest !== repo.name && !(remote && repo.remotes.has(remote)) ? `in ${repo.name}` : undefined;
|
|
276
|
+
const deleted = /\s(?:--delete|-d)\b/.test(after) ? args[1] : args[1]?.match(/^\+?:([^\s:]+)$/)?.[1];
|
|
277
|
+
if (dest && deleted) {
|
|
278
|
+
return { title: "Delete remote Git branch", target: `${deleted} on ${dest}`, annotation, kind: "git_branch_delete" };
|
|
279
|
+
}
|
|
280
|
+
const target = dest && branch ? `${branch} → ${dest}` : dest || "current branch";
|
|
281
|
+
const forced = /\bgit\s+push\b[^\n]*\s(?:--force(?:-with-lease)?|-f)\b/.test(gitCmd);
|
|
263
282
|
return forced
|
|
264
|
-
? { title: "Force push", target, kind: "git_force_push" }
|
|
265
|
-
: { title: "Push", target, kind: "git_push" };
|
|
283
|
+
? { title: "Force push", target, annotation, kind: "git_force_push" }
|
|
284
|
+
: { title: "Push", target, annotation, kind: "git_push" };
|
|
266
285
|
}
|
|
267
|
-
const
|
|
286
|
+
const BRANCH_DELETE_RE = /\bgit\s+(?:-C\s+\S+\s+)?branch\s+(?:-D|--delete\s+--force|-d|--delete)\s+([^\s;&|]+)/;
|
|
287
|
+
const branchDelete = cmd.match(BRANCH_DELETE_RE);
|
|
268
288
|
if (branchDelete) {
|
|
269
|
-
const forced = /\bgit\s+branch\s+(?:-D|--delete\s+--force)\b/.test(
|
|
289
|
+
const forced = /\bgit\s+branch\s+(?:-D|--delete\s+--force)\b/.test(gitCmd);
|
|
270
290
|
return {
|
|
271
|
-
title:
|
|
291
|
+
title: `Delete local Git branch${inRepo(BRANCH_DELETE_RE)}`,
|
|
272
292
|
target: branchDelete[1],
|
|
273
293
|
annotation: forced ? "even if not merged" : undefined,
|
|
274
294
|
kind: "git_branch_delete",
|
|
@@ -277,21 +297,29 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
277
297
|
const prisma = summarizePrismaDeploy(cmd);
|
|
278
298
|
if (prisma)
|
|
279
299
|
return prisma;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (
|
|
285
|
-
return { title:
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
300
|
+
const GIT_RESET_RE = /\bgit\s+(?:-C\s+\S+\s+)?reset\s+--hard\b/;
|
|
301
|
+
if (GIT_RESET_RE.test(cmd))
|
|
302
|
+
return { title: `Hard reset${inRepo(GIT_RESET_RE)}, discard all local changes`, kind: "git_reset_hard" };
|
|
303
|
+
const GIT_CLEAN_RE = /\bgit\s+(?:-C\s+\S+\s+)?clean\s+-f/;
|
|
304
|
+
if (GIT_CLEAN_RE.test(cmd))
|
|
305
|
+
return { title: `Remove all untracked files${inRepo(GIT_CLEAN_RE)}`, kind: "git_clean" };
|
|
306
|
+
const GIT_CHECKOUT_RE = /\bgit\s+(?:-C\s+\S+\s+)?checkout\s+--\s+\./;
|
|
307
|
+
if (GIT_CHECKOUT_RE.test(cmd))
|
|
308
|
+
return { title: `Discard all unstaged changes${inRepo(GIT_CHECKOUT_RE)}`, kind: "git_checkout" };
|
|
309
|
+
const GIT_RESTORE_RE = /\bgit\s+(?:-C\s+\S+\s+)?restore\s+--staged\s+\./;
|
|
310
|
+
if (GIT_RESTORE_RE.test(cmd))
|
|
311
|
+
return { title: `Unstage all staged changes${inRepo(GIT_RESTORE_RE)}`, kind: "git_restore" };
|
|
312
|
+
const GIT_COMMIT_RE = /\bgit\s+(?:-C\s+\S+\s+)?commit\b/;
|
|
313
|
+
if (GIT_COMMIT_RE.test(cmd)) {
|
|
289
314
|
// Pull a simple quoted -m message. Bail (show plain "Git commit") when the
|
|
290
315
|
// message is a command substitution / heredoc — `-m "$(cat <<'EOF' … )"` —
|
|
291
316
|
// since that has no clean inline title to extract.
|
|
292
317
|
const m = cmd.match(/-m\s+["']([^"'$]+)["']/);
|
|
293
318
|
// The subject line only: a multi-line message made a multi-line title.
|
|
294
|
-
|
|
319
|
+
const where = inRepo(GIT_COMMIT_RE);
|
|
320
|
+
return m
|
|
321
|
+
? { title: `Git commit "${truncate(m[1].split("\n")[0].trim(), 60)}"${where}`, kind: "git_commit" }
|
|
322
|
+
: { title: `Git commit${where}`, kind: "git_commit" };
|
|
295
323
|
}
|
|
296
324
|
const gh = summarizeGh(cmd);
|
|
297
325
|
if (gh)
|
|
@@ -425,21 +453,21 @@ function summarizeCompoundBash(cmd, sizeBytes, cwd) {
|
|
|
425
453
|
const step = expandVars(steps[lead], vars);
|
|
426
454
|
// npm publish reads the package.json a preceding `cd` points at; prisma reads
|
|
427
455
|
// a DATABASE_URL an earlier step exported.
|
|
456
|
+
// A step runs in the folder that the `cd` steps before it moved to.
|
|
457
|
+
const dirAt = (i) => cwdAfterCds(steps.slice(0, i), vars, cwd);
|
|
428
458
|
const r = (/\bnpm\s+publish\b/.test(step) && summarizeNpmPublish(cmd, cwd)) ||
|
|
429
459
|
summarizePrismaDeploy(/\bprisma\s+migrate\s+deploy\b/.test(step) ? cmd : "") ||
|
|
430
|
-
summarizeBash(step, sizeBytes,
|
|
460
|
+
summarizeBash(step, sizeBytes, dirAt(lead));
|
|
431
461
|
const also = [...new Set(steps
|
|
432
|
-
.
|
|
433
|
-
.
|
|
462
|
+
.map((s, i) => (i !== lead && rank[i] >= TIER_ORDER.review ? describeStep(expandVars(s, vars), dirAt(i)) : ""))
|
|
463
|
+
.filter(Boolean))].filter((t) => t !== describeStep(step, dirAt(lead)));
|
|
434
464
|
// The body shows the steps that need approval, not the setup and polling
|
|
435
|
-
// around them
|
|
465
|
+
// around them.
|
|
436
466
|
const risky = steps.filter((_, i) => rank[i] >= TIER_ORDER.review);
|
|
437
|
-
const quiet = steps.length - risky.length;
|
|
438
467
|
return {
|
|
439
468
|
...r,
|
|
440
469
|
subline: also.length ? `Also: ${also.join("; ")}` : r.subline,
|
|
441
470
|
body: r.body ?? truncateBody(risky.join("\n")),
|
|
442
|
-
footnote: r.footnote ?? (quiet ? "Other steps in this command need no approval" : undefined),
|
|
443
471
|
};
|
|
444
472
|
}
|
|
445
473
|
function describeStep(step, cwd) {
|
|
@@ -535,7 +563,9 @@ function summarizeNpmPublish(cmd, cwd) {
|
|
|
535
563
|
else
|
|
536
564
|
flags[name] = value;
|
|
537
565
|
}
|
|
538
|
-
else if (positional === undefined) {
|
|
566
|
+
else if (positional === undefined && /^[\w.~/@-][\w.~/@+-]*$/.test(t)) {
|
|
567
|
+
// A folder or tarball. Quote and bracket leftovers from quoted data
|
|
568
|
+
// (`…publish\"]'`) are not a path.
|
|
539
569
|
positional = t;
|
|
540
570
|
}
|
|
541
571
|
}
|
|
@@ -545,7 +575,8 @@ function summarizeNpmPublish(cmd, cwd) {
|
|
|
545
575
|
const cds = [...before.matchAll(/(?:^|[\n;&|(])\s*cd\s+("[^"]+"|'[^']+'|\S+)/g)];
|
|
546
576
|
if (cds.length) {
|
|
547
577
|
const dir = stripQuotes(cds[cds.length - 1][1]);
|
|
548
|
-
|
|
578
|
+
// `cd $SP/pkg`: the variable is not known here, so the folder is not known.
|
|
579
|
+
baseDir = /[$`]/.test(dir) ? undefined : isAbsolute(dir) ? dir : baseDir ? resolve(baseDir, dir) : undefined;
|
|
549
580
|
}
|
|
550
581
|
const allWorkspaces = flags["--workspaces"] === true || flags["-ws"] === true;
|
|
551
582
|
let pkgDirs = [];
|
|
@@ -1718,6 +1749,85 @@ function summarizePrismaDeploy(cmd) {
|
|
|
1718
1749
|
function shellText(cmd) {
|
|
1719
1750
|
return blankTextCommandArgs(stripInlineScriptBodies(cmd));
|
|
1720
1751
|
}
|
|
1752
|
+
const GIT_C_RE = /\bgit\s+-C\s+(?:"[^"]+"|'[^']+'|[^\s;&|]+)\s+/;
|
|
1753
|
+
/** The folder a shell is in after these steps, following each `cd`. Unknown
|
|
1754
|
+
* when a `cd` goes to a relative path with no known start, or to `$VAR`. */
|
|
1755
|
+
function cwdAfterCds(steps, vars, cwd) {
|
|
1756
|
+
let dir = cwd;
|
|
1757
|
+
for (const s of steps) {
|
|
1758
|
+
const m = s.match(/^\s*cd\s+("[^"]+"|'[^']+'|[^\s;&|]+)\s*$/);
|
|
1759
|
+
if (m)
|
|
1760
|
+
dir = resolveDir(stripQuotes(expandVars(m[1], vars)), dir);
|
|
1761
|
+
}
|
|
1762
|
+
return dir;
|
|
1763
|
+
}
|
|
1764
|
+
function resolveDir(dir, base) {
|
|
1765
|
+
const d = dir.replace(/^~(?=\/|$)/, homedir());
|
|
1766
|
+
if (d.includes("$"))
|
|
1767
|
+
return undefined;
|
|
1768
|
+
return isAbsolute(d) ? d : base ? resolve(base, d) : undefined;
|
|
1769
|
+
}
|
|
1770
|
+
/** The repo the git command matched by `re` runs in: after the `cd` steps
|
|
1771
|
+
* before it, and its own `git -C`. */
|
|
1772
|
+
function gitRepoFor(cmd, re, cwd) {
|
|
1773
|
+
const m = re.exec(cmd);
|
|
1774
|
+
if (!m)
|
|
1775
|
+
return null;
|
|
1776
|
+
const before = splitTopLevel(cmd.slice(0, m.index), { pipes: false });
|
|
1777
|
+
let dir = cwdAfterCds(before, literalAssignments(cmd), cwd);
|
|
1778
|
+
const c = m[0].match(/\bgit\s+-C\s+("[^"]+"|'[^']+'|\S+)/)?.[1];
|
|
1779
|
+
if (c)
|
|
1780
|
+
dir = resolveDir(stripQuotes(expandVars(c, literalAssignments(cmd))), dir);
|
|
1781
|
+
return dir ? readGitRepo(dir) : null;
|
|
1782
|
+
}
|
|
1783
|
+
function readGitRepo(start) {
|
|
1784
|
+
try {
|
|
1785
|
+
for (let top = resolve(start);; top = dirname(top)) {
|
|
1786
|
+
const dotGit = join(top, ".git");
|
|
1787
|
+
if (existsSync(dotGit)) {
|
|
1788
|
+
// A worktree's `.git` is a file that points at its git dir, which
|
|
1789
|
+
// points at the main repo's git dir (`commondir`).
|
|
1790
|
+
let gitDir = dotGit;
|
|
1791
|
+
const pointer = statSync(dotGit).isFile() ? readFileSync(dotGit, "utf8").match(/^gitdir:\s*(.+)$/m) : null;
|
|
1792
|
+
if (pointer)
|
|
1793
|
+
gitDir = resolve(top, pointer[1].trim());
|
|
1794
|
+
const commonFile = join(gitDir, "commondir");
|
|
1795
|
+
const commonDir = existsSync(commonFile) ? resolve(gitDir, readFileSync(commonFile, "utf8").trim()) : gitDir;
|
|
1796
|
+
const remotes = new Map();
|
|
1797
|
+
let section;
|
|
1798
|
+
for (const line of readFileSync(join(commonDir, "config"), "utf8").split("\n")) {
|
|
1799
|
+
const head = line.match(/^\s*\[\s*remote\s+"([^"]+)"\s*\]/);
|
|
1800
|
+
if (head)
|
|
1801
|
+
section = head[1];
|
|
1802
|
+
else if (/^\s*\[/.test(line))
|
|
1803
|
+
section = undefined;
|
|
1804
|
+
else if (section && !remotes.has(section)) {
|
|
1805
|
+
const url = line.match(/^\s*url\s*=\s*(.+?)\s*$/)?.[1];
|
|
1806
|
+
if (url)
|
|
1807
|
+
remotes.set(section, url);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
const head = existsSync(join(gitDir, "HEAD")) ? readFileSync(join(gitDir, "HEAD"), "utf8") : "";
|
|
1811
|
+
const mainTop = basename(commonDir) === ".git" ? dirname(commonDir) : top;
|
|
1812
|
+
return {
|
|
1813
|
+
name: repoSlug(remotes.get("origin")) ?? basename(mainTop),
|
|
1814
|
+
remotes,
|
|
1815
|
+
branch: head.match(/^ref:\s*refs\/heads\/(.+?)\s*$/m)?.[1],
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
if (dirname(top) === top)
|
|
1819
|
+
return null;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
catch {
|
|
1823
|
+
return null;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
/** `git@github.com:oked-ai/oked-sdk.git` or `https://github.com/oked-ai/oked-sdk` → `oked-ai/oked-sdk`. */
|
|
1827
|
+
function repoSlug(url) {
|
|
1828
|
+
const path = url?.match(/^(?:[a-z][a-z0-9+.-]*:\/\/[^/]+\/|[^@\s/]+@[^:\s]+:)(.+?)(?:\.git)?\/?$/i)?.[1];
|
|
1829
|
+
return path?.split("/").slice(-2).join("/") || undefined;
|
|
1830
|
+
}
|
|
1721
1831
|
/** `NAME=value` assignments with a literal value (no `$(…)`, no backticks), in order. */
|
|
1722
1832
|
function literalAssignments(cmd) {
|
|
1723
1833
|
const vars = new Map();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oked/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.11",
|
|
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.11"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.13.10",
|