@oked/sdk 0.6.10 → 0.6.12
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/describe.d.ts +2 -1
- package/dist/describe.js +152 -37
- package/package.json +2 -2
package/dist/describe.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* approvals. Output is a sentence-shaped Rendered value: title + optional
|
|
4
4
|
* subline + optional body (quoted block) + optional footnote.
|
|
5
5
|
*
|
|
6
|
-
* Surfaces (Telegram, dashboard) consume Title/Subline/Body/Footnote keys
|
|
6
|
+
* Surfaces (Telegram, dashboard) consume Title/Subline/Body/Footnote/Link keys
|
|
7
7
|
* from the `fields` payload. `describe()` returns just the title for
|
|
8
8
|
* backwards-compatible single-line consumers (audit logs, SMS).
|
|
9
9
|
*/
|
|
@@ -15,6 +15,7 @@ export interface Rendered {
|
|
|
15
15
|
subline?: string;
|
|
16
16
|
body?: string;
|
|
17
17
|
footnote?: string;
|
|
18
|
+
link?: string;
|
|
18
19
|
kind: OperationKind;
|
|
19
20
|
}
|
|
20
21
|
/** Optional caller context. `cwd` lets describers read local files (e.g. the
|
package/dist/describe.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* approvals. Output is a sentence-shaped Rendered value: title + optional
|
|
4
4
|
* subline + optional body (quoted block) + optional footnote.
|
|
5
5
|
*
|
|
6
|
-
* Surfaces (Telegram, dashboard) consume Title/Subline/Body/Footnote keys
|
|
6
|
+
* Surfaces (Telegram, dashboard) consume Title/Subline/Body/Footnote/Link keys
|
|
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;
|
|
@@ -44,6 +45,8 @@ export function describeFields(toolName, toolInput, ctx = {}) {
|
|
|
44
45
|
out.Body = r.body;
|
|
45
46
|
if (r.footnote)
|
|
46
47
|
out.Footnote = r.footnote;
|
|
48
|
+
if (r.link)
|
|
49
|
+
out.Link = r.link;
|
|
47
50
|
return out;
|
|
48
51
|
}
|
|
49
52
|
// ───────────────────────────────────────────────────────────────────────
|
|
@@ -251,28 +254,43 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
251
254
|
kind: "file_delete",
|
|
252
255
|
};
|
|
253
256
|
}
|
|
254
|
-
// git
|
|
255
|
-
|
|
257
|
+
// git. Each card names the repo: the folder the command runs in (after a
|
|
258
|
+
// `cd` or `git -C`), shown as owner/name from its origin remote.
|
|
259
|
+
const gitCmd = cmd.replace(GIT_C_RE, "git ");
|
|
260
|
+
const repoAt = (re) => gitRepoFor(cmd, re, cwd);
|
|
261
|
+
const inRepo = (re) => {
|
|
262
|
+
const repo = repoAt(re);
|
|
263
|
+
return repo ? ` in ${repo.name}` : "";
|
|
264
|
+
};
|
|
265
|
+
if (/\bgit\s+push\b/.test(shellText(gitCmd))) {
|
|
256
266
|
// Parse the remote + branch ignoring flags (-u, --force, --set-upstream, …)
|
|
257
267
|
// so `git push -u origin feat` renders "feat → origin", not "origin → -u".
|
|
258
|
-
|
|
268
|
+
// The arguments end at a quote or a separator: `node x '["git push origin
|
|
269
|
+
// main","git push …"]'` pushes main, not `main","git`.
|
|
270
|
+
const after = gitCmd.match(/\bgit\s+push\b([^\n;&|"'`)]*)/)?.[1] ?? "";
|
|
259
271
|
const args = after.split(/\s+/).filter((a) => a && !a.startsWith("-"));
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
272
|
+
const repo = repoAt(/\bgit\s+(?:-C\s+\S+\s+)?push\b/);
|
|
273
|
+
const remote = args[0] ?? (repo?.remotes.has("origin") ? "origin" : undefined);
|
|
274
|
+
const branch = args[1] ?? (args[0] === undefined ? repo?.branch : undefined);
|
|
275
|
+
const dest = remote ? repoSlug(repo?.remotes.get(remote)) ?? remote : undefined;
|
|
276
|
+
// Name the local repo when the remote did not.
|
|
277
|
+
const annotation = repo && dest !== repo.name && !(remote && repo.remotes.has(remote)) ? `in ${repo.name}` : undefined;
|
|
278
|
+
const deleted = /\s(?:--delete|-d)\b/.test(after) ? args[1] : args[1]?.match(/^\+?:([^\s:]+)$/)?.[1];
|
|
279
|
+
if (dest && deleted) {
|
|
280
|
+
return { title: "Delete remote Git branch", target: `${deleted} on ${dest}`, annotation, kind: "git_branch_delete" };
|
|
264
281
|
}
|
|
265
|
-
const target =
|
|
266
|
-
const forced = /\bgit\s+push\b[^\n]*\s(?:--force(?:-with-lease)?|-f)\b/.test(
|
|
282
|
+
const target = dest && branch ? `${branch} → ${dest}` : dest || "current branch";
|
|
283
|
+
const forced = /\bgit\s+push\b[^\n]*\s(?:--force(?:-with-lease)?|-f)\b/.test(gitCmd);
|
|
267
284
|
return forced
|
|
268
|
-
? { title: "Force push", target, kind: "git_force_push" }
|
|
269
|
-
: { title: "Push", target, kind: "git_push" };
|
|
285
|
+
? { title: "Force push", target, annotation, kind: "git_force_push" }
|
|
286
|
+
: { title: "Push", target, annotation, kind: "git_push" };
|
|
270
287
|
}
|
|
271
|
-
const
|
|
288
|
+
const BRANCH_DELETE_RE = /\bgit\s+(?:-C\s+\S+\s+)?branch\s+(?:-D|--delete\s+--force|-d|--delete)\s+([^\s;&|]+)/;
|
|
289
|
+
const branchDelete = cmd.match(BRANCH_DELETE_RE);
|
|
272
290
|
if (branchDelete) {
|
|
273
|
-
const forced = /\bgit\s+branch\s+(?:-D|--delete\s+--force)\b/.test(
|
|
291
|
+
const forced = /\bgit\s+branch\s+(?:-D|--delete\s+--force)\b/.test(gitCmd);
|
|
274
292
|
return {
|
|
275
|
-
title:
|
|
293
|
+
title: `Delete local Git branch${inRepo(BRANCH_DELETE_RE)}`,
|
|
276
294
|
target: branchDelete[1],
|
|
277
295
|
annotation: forced ? "even if not merged" : undefined,
|
|
278
296
|
kind: "git_branch_delete",
|
|
@@ -281,23 +299,31 @@ function summarizeBash(command, sizeBytes, cwd) {
|
|
|
281
299
|
const prisma = summarizePrismaDeploy(cmd);
|
|
282
300
|
if (prisma)
|
|
283
301
|
return prisma;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (
|
|
289
|
-
return { title:
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
302
|
+
const GIT_RESET_RE = /\bgit\s+(?:-C\s+\S+\s+)?reset\s+--hard\b/;
|
|
303
|
+
if (GIT_RESET_RE.test(cmd))
|
|
304
|
+
return { title: `Hard reset${inRepo(GIT_RESET_RE)}, discard all local changes`, kind: "git_reset_hard" };
|
|
305
|
+
const GIT_CLEAN_RE = /\bgit\s+(?:-C\s+\S+\s+)?clean\s+-f/;
|
|
306
|
+
if (GIT_CLEAN_RE.test(cmd))
|
|
307
|
+
return { title: `Remove all untracked files${inRepo(GIT_CLEAN_RE)}`, kind: "git_clean" };
|
|
308
|
+
const GIT_CHECKOUT_RE = /\bgit\s+(?:-C\s+\S+\s+)?checkout\s+--\s+\./;
|
|
309
|
+
if (GIT_CHECKOUT_RE.test(cmd))
|
|
310
|
+
return { title: `Discard all unstaged changes${inRepo(GIT_CHECKOUT_RE)}`, kind: "git_checkout" };
|
|
311
|
+
const GIT_RESTORE_RE = /\bgit\s+(?:-C\s+\S+\s+)?restore\s+--staged\s+\./;
|
|
312
|
+
if (GIT_RESTORE_RE.test(cmd))
|
|
313
|
+
return { title: `Unstage all staged changes${inRepo(GIT_RESTORE_RE)}`, kind: "git_restore" };
|
|
314
|
+
const GIT_COMMIT_RE = /\bgit\s+(?:-C\s+\S+\s+)?commit\b/;
|
|
315
|
+
if (GIT_COMMIT_RE.test(cmd)) {
|
|
293
316
|
// Pull a simple quoted -m message. Bail (show plain "Git commit") when the
|
|
294
317
|
// message is a command substitution / heredoc — `-m "$(cat <<'EOF' … )"` —
|
|
295
318
|
// since that has no clean inline title to extract.
|
|
296
319
|
const m = cmd.match(/-m\s+["']([^"'$]+)["']/);
|
|
297
320
|
// The subject line only: a multi-line message made a multi-line title.
|
|
298
|
-
|
|
321
|
+
const where = inRepo(GIT_COMMIT_RE);
|
|
322
|
+
return m
|
|
323
|
+
? { title: `Git commit "${truncate(m[1].split("\n")[0].trim(), 60)}"${where}`, kind: "git_commit" }
|
|
324
|
+
: { title: `Git commit${where}`, kind: "git_commit" };
|
|
299
325
|
}
|
|
300
|
-
const gh = summarizeGh(cmd);
|
|
326
|
+
const gh = summarizeGh(cmd, cwd);
|
|
301
327
|
if (gh)
|
|
302
328
|
return gh;
|
|
303
329
|
// gh pr create — reversible (PRs can be closed). Extract --title when present.
|
|
@@ -429,21 +455,21 @@ function summarizeCompoundBash(cmd, sizeBytes, cwd) {
|
|
|
429
455
|
const step = expandVars(steps[lead], vars);
|
|
430
456
|
// npm publish reads the package.json a preceding `cd` points at; prisma reads
|
|
431
457
|
// a DATABASE_URL an earlier step exported.
|
|
458
|
+
// A step runs in the folder that the `cd` steps before it moved to.
|
|
459
|
+
const dirAt = (i) => cwdAfterCds(steps.slice(0, i), vars, cwd);
|
|
432
460
|
const r = (/\bnpm\s+publish\b/.test(step) && summarizeNpmPublish(cmd, cwd)) ||
|
|
433
461
|
summarizePrismaDeploy(/\bprisma\s+migrate\s+deploy\b/.test(step) ? cmd : "") ||
|
|
434
|
-
summarizeBash(step, sizeBytes,
|
|
462
|
+
summarizeBash(step, sizeBytes, dirAt(lead));
|
|
435
463
|
const also = [...new Set(steps
|
|
436
|
-
.
|
|
437
|
-
.
|
|
464
|
+
.map((s, i) => (i !== lead && rank[i] >= TIER_ORDER.review ? describeStep(expandVars(s, vars), dirAt(i)) : ""))
|
|
465
|
+
.filter(Boolean))].filter((t) => t !== describeStep(step, dirAt(lead)));
|
|
438
466
|
// The body shows the steps that need approval, not the setup and polling
|
|
439
|
-
// around them
|
|
467
|
+
// around them.
|
|
440
468
|
const risky = steps.filter((_, i) => rank[i] >= TIER_ORDER.review);
|
|
441
|
-
const quiet = steps.length - risky.length;
|
|
442
469
|
return {
|
|
443
470
|
...r,
|
|
444
471
|
subline: also.length ? `Also: ${also.join("; ")}` : r.subline,
|
|
445
472
|
body: r.body ?? truncateBody(risky.join("\n")),
|
|
446
|
-
footnote: r.footnote ?? (quiet ? "Other steps in this command need no approval" : undefined),
|
|
447
473
|
};
|
|
448
474
|
}
|
|
449
475
|
function describeStep(step, cwd) {
|
|
@@ -451,17 +477,24 @@ function describeStep(step, cwd) {
|
|
|
451
477
|
return r.target && !r.title.includes(r.target) ? `${r.title} ${r.target}` : r.title;
|
|
452
478
|
}
|
|
453
479
|
/** GitHub CLI writes: which PR, issue or release, in which repo. */
|
|
454
|
-
|
|
455
|
-
|
|
480
|
+
const GH_RE = /\bgh\s+(pr|issue|release|repo|workflow|run|secret|variable|api)\s+(\S+)(.*)$/s;
|
|
481
|
+
function summarizeGh(cmd, cwd) {
|
|
482
|
+
const m = cmd.match(GH_RE);
|
|
456
483
|
if (!m)
|
|
457
484
|
return null;
|
|
458
485
|
const [, noun, verb, rest] = m;
|
|
459
486
|
const url = rest.match(/https:\/\/github\.com\/([^/\s]+\/[^/\s]+)\/(?:pull|issues)\/(\d+)/);
|
|
460
487
|
const repoFlag = rest.match(/\s(?:-R|--repo)[\s=]+(\S+)/)?.[1];
|
|
461
|
-
|
|
488
|
+
// With no URL and no --repo, gh acts on the GitHub repo of its folder.
|
|
489
|
+
const repo = url?.[1] ?? (repoFlag ? stripQuotes(repoFlag) : undefined) ?? gitRepoFor(cmd, GH_RE, cwd)?.github;
|
|
462
490
|
const num = url?.[2] ?? rest.match(/^\s+#?(\d+)\b/)?.[1];
|
|
463
491
|
const ref = num ? `#${num}` : "";
|
|
464
492
|
const where = repo ? ` in ${repo}` : "";
|
|
493
|
+
// `-R github.com/owner/name` and `-R owner/name` are on github.com; other hosts get no link.
|
|
494
|
+
const slug = repo?.replace(/^github\.com\//, "");
|
|
495
|
+
const link = slug && /^[^/]+\/[^/]+$/.test(slug) && num && (noun === "pr" || noun === "issue")
|
|
496
|
+
? `https://github.com/${slug}/${noun === "pr" ? "pull" : "issues"}/${num}`
|
|
497
|
+
: undefined;
|
|
465
498
|
if (noun === "pr" && verb === "merge") {
|
|
466
499
|
const how = /\s(?:--squash|-s)\b/.test(rest) ? "squash" : /\s(?:--rebase|-r)\b/.test(rest) ? "rebase" : undefined;
|
|
467
500
|
const auto = /\s--auto\b/.test(rest);
|
|
@@ -469,6 +502,7 @@ function summarizeGh(cmd) {
|
|
|
469
502
|
title: `Merge PR ${ref}${where}`.replace(/\s+/g, " ").trim(),
|
|
470
503
|
annotation: [how, auto ? "when checks pass" : undefined, /\s(?:--delete-branch|-d)\b/.test(rest) ? "deletes branch" : undefined]
|
|
471
504
|
.filter(Boolean).join(", ") || undefined,
|
|
505
|
+
link,
|
|
472
506
|
kind: "git_pr_merge",
|
|
473
507
|
};
|
|
474
508
|
}
|
|
@@ -507,6 +541,7 @@ function summarizeGh(cmd) {
|
|
|
507
541
|
return {
|
|
508
542
|
title: `${phrase}${where}`,
|
|
509
543
|
body: body ? truncateBody(body[1] ?? body[2] ?? "") : undefined,
|
|
544
|
+
link,
|
|
510
545
|
kind: noun === "pr" ? "git_pr_write" : "gh_write",
|
|
511
546
|
};
|
|
512
547
|
}
|
|
@@ -1725,6 +1760,86 @@ function summarizePrismaDeploy(cmd) {
|
|
|
1725
1760
|
function shellText(cmd) {
|
|
1726
1761
|
return blankTextCommandArgs(stripInlineScriptBodies(cmd));
|
|
1727
1762
|
}
|
|
1763
|
+
const GIT_C_RE = /\bgit\s+-C\s+(?:"[^"]+"|'[^']+'|[^\s;&|]+)\s+/;
|
|
1764
|
+
/** The folder a shell is in after these steps, following each `cd`. Unknown
|
|
1765
|
+
* when a `cd` goes to a relative path with no known start, or to `$VAR`. */
|
|
1766
|
+
function cwdAfterCds(steps, vars, cwd) {
|
|
1767
|
+
let dir = cwd;
|
|
1768
|
+
for (const s of steps) {
|
|
1769
|
+
const m = s.match(/^\s*cd\s+("[^"]+"|'[^']+'|[^\s;&|]+)\s*$/);
|
|
1770
|
+
if (m)
|
|
1771
|
+
dir = resolveDir(stripQuotes(expandVars(m[1], vars)), dir);
|
|
1772
|
+
}
|
|
1773
|
+
return dir;
|
|
1774
|
+
}
|
|
1775
|
+
function resolveDir(dir, base) {
|
|
1776
|
+
const d = dir.replace(/^~(?=\/|$)/, homedir());
|
|
1777
|
+
if (d.includes("$"))
|
|
1778
|
+
return undefined;
|
|
1779
|
+
return isAbsolute(d) ? d : base ? resolve(base, d) : undefined;
|
|
1780
|
+
}
|
|
1781
|
+
/** The repo the git command matched by `re` runs in: after the `cd` steps
|
|
1782
|
+
* before it, and its own `git -C`. */
|
|
1783
|
+
function gitRepoFor(cmd, re, cwd) {
|
|
1784
|
+
const m = re.exec(cmd);
|
|
1785
|
+
if (!m)
|
|
1786
|
+
return null;
|
|
1787
|
+
const before = splitTopLevel(cmd.slice(0, m.index), { pipes: false });
|
|
1788
|
+
let dir = cwdAfterCds(before, literalAssignments(cmd), cwd);
|
|
1789
|
+
const c = m[0].match(/\bgit\s+-C\s+("[^"]+"|'[^']+'|\S+)/)?.[1];
|
|
1790
|
+
if (c)
|
|
1791
|
+
dir = resolveDir(stripQuotes(expandVars(c, literalAssignments(cmd))), dir);
|
|
1792
|
+
return dir ? readGitRepo(dir) : null;
|
|
1793
|
+
}
|
|
1794
|
+
function readGitRepo(start) {
|
|
1795
|
+
try {
|
|
1796
|
+
for (let top = resolve(start);; top = dirname(top)) {
|
|
1797
|
+
const dotGit = join(top, ".git");
|
|
1798
|
+
if (existsSync(dotGit)) {
|
|
1799
|
+
// A worktree's `.git` is a file that points at its git dir, which
|
|
1800
|
+
// points at the main repo's git dir (`commondir`).
|
|
1801
|
+
let gitDir = dotGit;
|
|
1802
|
+
const pointer = statSync(dotGit).isFile() ? readFileSync(dotGit, "utf8").match(/^gitdir:\s*(.+)$/m) : null;
|
|
1803
|
+
if (pointer)
|
|
1804
|
+
gitDir = resolve(top, pointer[1].trim());
|
|
1805
|
+
const commonFile = join(gitDir, "commondir");
|
|
1806
|
+
const commonDir = existsSync(commonFile) ? resolve(gitDir, readFileSync(commonFile, "utf8").trim()) : gitDir;
|
|
1807
|
+
const remotes = new Map();
|
|
1808
|
+
let section;
|
|
1809
|
+
for (const line of readFileSync(join(commonDir, "config"), "utf8").split("\n")) {
|
|
1810
|
+
const head = line.match(/^\s*\[\s*remote\s+"([^"]+)"\s*\]/);
|
|
1811
|
+
if (head)
|
|
1812
|
+
section = head[1];
|
|
1813
|
+
else if (/^\s*\[/.test(line))
|
|
1814
|
+
section = undefined;
|
|
1815
|
+
else if (section && !remotes.has(section)) {
|
|
1816
|
+
const url = line.match(/^\s*url\s*=\s*(.+?)\s*$/)?.[1];
|
|
1817
|
+
if (url)
|
|
1818
|
+
remotes.set(section, url);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
const head = existsSync(join(gitDir, "HEAD")) ? readFileSync(join(gitDir, "HEAD"), "utf8") : "";
|
|
1822
|
+
const mainTop = basename(commonDir) === ".git" ? dirname(commonDir) : top;
|
|
1823
|
+
return {
|
|
1824
|
+
name: repoSlug(remotes.get("origin")) ?? basename(mainTop),
|
|
1825
|
+
github: /^(?:https?:\/\/(?:[^@/]+@)?|ssh:\/\/[^@/]+@|[^@\s/]+@)github\.com[:/]/i.test(remotes.get("origin") ?? "") ? repoSlug(remotes.get("origin")) : undefined,
|
|
1826
|
+
remotes,
|
|
1827
|
+
branch: head.match(/^ref:\s*refs\/heads\/(.+?)\s*$/m)?.[1],
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
if (dirname(top) === top)
|
|
1831
|
+
return null;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
catch {
|
|
1835
|
+
return null;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
/** `git@github.com:oked-ai/oked-sdk.git` or `https://github.com/oked-ai/oked-sdk` → `oked-ai/oked-sdk`. */
|
|
1839
|
+
function repoSlug(url) {
|
|
1840
|
+
const path = url?.match(/^(?:[a-z][a-z0-9+.-]*:\/\/[^/]+\/|[^@\s/]+@[^:\s]+:)(.+?)(?:\.git)?\/?$/i)?.[1];
|
|
1841
|
+
return path?.split("/").slice(-2).join("/") || undefined;
|
|
1842
|
+
}
|
|
1728
1843
|
/** `NAME=value` assignments with a literal value (no `$(…)`, no backticks), in order. */
|
|
1729
1844
|
function literalAssignments(cmd) {
|
|
1730
1845
|
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.12",
|
|
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.12"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.13.10",
|