@oked/sdk 0.6.11 → 0.6.13

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.
@@ -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,12 +15,16 @@ 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
21
22
  * package.json behind `npm publish`) to show what an action will touch. */
22
23
  export interface DescribeContext {
23
24
  cwd?: string;
25
+ /** Title of the PR the card links to, when the command does not say it.
26
+ * `lookupPrTitle()` gets it from GitHub. */
27
+ prTitle?: string;
24
28
  }
25
29
  export declare function describe(toolName: string, toolInput: Record<string, unknown>, ctx?: DescribeContext): string;
26
30
  export declare function describeFields(toolName: string, toolInput: Record<string, unknown>, ctx?: DescribeContext): Record<string, string> | null;
package/dist/describe.js 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
  */
@@ -45,12 +45,31 @@ export function describeFields(toolName, toolInput, ctx = {}) {
45
45
  out.Body = r.body;
46
46
  if (r.footnote)
47
47
  out.Footnote = r.footnote;
48
+ if (r.link)
49
+ out.Link = r.link;
48
50
  return out;
49
51
  }
50
52
  // ───────────────────────────────────────────────────────────────────────
51
53
  // Top-level dispatch
52
54
  // ───────────────────────────────────────────────────────────────────────
53
55
  function summarize(toolName, toolInput, ctx) {
56
+ const r = summarizeTool(toolName, toolInput, ctx);
57
+ return ctx.prTitle ? namePr(r, ctx.prTitle) : r;
58
+ }
59
+ /**
60
+ * "Merge PR #49 in o/r" says which PR, not what it does. Put the PR title after
61
+ * the number: `Merge PR #49 "feat: OG image" in o/r`. A title that already
62
+ * quotes something keeps it.
63
+ */
64
+ function namePr(r, prTitle) {
65
+ const num = r.title.match(/\bPR #(\d+)\b/)?.[1];
66
+ // A subject made by `$(…)` or a variable is not known here.
67
+ const name = prTitle.split("\n")[0].replace(new RegExp(`\\s*\\(#${num}\\)$`), "").trim();
68
+ if (!num || !name || /[$`]/.test(name) || r.title.includes('"'))
69
+ return r;
70
+ return { ...r, title: r.title.replace(`PR #${num}`, `PR #${num} "${truncate(name, 60)}"`) };
71
+ }
72
+ function summarizeTool(toolName, toolInput, ctx) {
54
73
  const fileSizeBytes = typeof toolInput._file_size_bytes === "number" ? toolInput._file_size_bytes : undefined;
55
74
  switch (toolName) {
56
75
  case "Bash":
@@ -321,7 +340,7 @@ function summarizeBash(command, sizeBytes, cwd) {
321
340
  ? { title: `Git commit "${truncate(m[1].split("\n")[0].trim(), 60)}"${where}`, kind: "git_commit" }
322
341
  : { title: `Git commit${where}`, kind: "git_commit" };
323
342
  }
324
- const gh = summarizeGh(cmd);
343
+ const gh = summarizeGh(cmd, cwd);
325
344
  if (gh)
326
345
  return gh;
327
346
  // gh pr create — reversible (PRs can be closed). Extract --title when present.
@@ -475,26 +494,37 @@ function describeStep(step, cwd) {
475
494
  return r.target && !r.title.includes(r.target) ? `${r.title} ${r.target}` : r.title;
476
495
  }
477
496
  /** GitHub CLI writes: which PR, issue or release, in which repo. */
478
- function summarizeGh(cmd) {
479
- const m = cmd.match(/\bgh\s+(pr|issue|release|repo|workflow|run|secret|variable|api)\s+(\S+)(.*)$/s);
497
+ const GH_RE = /\bgh\s+(pr|issue|release|repo|workflow|run|secret|variable|api)\s+(\S+)(.*)$/s;
498
+ function summarizeGh(cmd, cwd) {
499
+ const m = cmd.match(GH_RE);
480
500
  if (!m)
481
501
  return null;
482
502
  const [, noun, verb, rest] = m;
483
503
  const url = rest.match(/https:\/\/github\.com\/([^/\s]+\/[^/\s]+)\/(?:pull|issues)\/(\d+)/);
484
504
  const repoFlag = rest.match(/\s(?:-R|--repo)[\s=]+(\S+)/)?.[1];
485
- const repo = url?.[1] ?? repoFlag;
505
+ // With no URL and no --repo, gh acts on the GitHub repo of its folder.
506
+ const repo = url?.[1] ?? (repoFlag ? stripQuotes(repoFlag) : undefined) ?? gitRepoFor(cmd, GH_RE, cwd)?.github;
486
507
  const num = url?.[2] ?? rest.match(/^\s+#?(\d+)\b/)?.[1];
487
508
  const ref = num ? `#${num}` : "";
488
509
  const where = repo ? ` in ${repo}` : "";
510
+ // `-R github.com/owner/name` and `-R owner/name` are on github.com; other hosts get no link.
511
+ const slug = repo?.replace(/^github\.com\//, "");
512
+ const link = slug && /^[^/]+\/[^/]+$/.test(slug) && num && (noun === "pr" || noun === "issue")
513
+ ? `https://github.com/${slug}/${noun === "pr" ? "pull" : "issues"}/${num}`
514
+ : undefined;
489
515
  if (noun === "pr" && verb === "merge") {
490
516
  const how = /\s(?:--squash|-s)\b/.test(rest) ? "squash" : /\s(?:--rebase|-r)\b/.test(rest) ? "rebase" : undefined;
491
517
  const auto = /\s--auto\b/.test(rest);
492
- return {
518
+ // The squash or merge commit subject is the PR title in most merges.
519
+ const subject = rest.match(/\s(?:-t|--subject)[\s=]+(?:'([^']*)'|"((?:[^"\\]|\\.)*)")/);
520
+ const r = {
493
521
  title: `Merge PR ${ref}${where}`.replace(/\s+/g, " ").trim(),
494
522
  annotation: [how, auto ? "when checks pass" : undefined, /\s(?:--delete-branch|-d)\b/.test(rest) ? "deletes branch" : undefined]
495
523
  .filter(Boolean).join(", ") || undefined,
524
+ link,
496
525
  kind: "git_pr_merge",
497
526
  };
527
+ return subject ? namePr(r, subject[1] ?? subject[2] ?? "") : r;
498
528
  }
499
529
  if (noun === "api") {
500
530
  const args = ` ${verb}${rest}`;
@@ -531,6 +561,7 @@ function summarizeGh(cmd) {
531
561
  return {
532
562
  title: `${phrase}${where}`,
533
563
  body: body ? truncateBody(body[1] ?? body[2] ?? "") : undefined,
564
+ link,
534
565
  kind: noun === "pr" ? "git_pr_write" : "gh_write",
535
566
  };
536
567
  }
@@ -1811,6 +1842,7 @@ function readGitRepo(start) {
1811
1842
  const mainTop = basename(commonDir) === ".git" ? dirname(commonDir) : top;
1812
1843
  return {
1813
1844
  name: repoSlug(remotes.get("origin")) ?? basename(mainTop),
1845
+ github: /^(?:https?:\/\/(?:[^@/]+@)?|ssh:\/\/[^@/]+@|[^@\s/]+@)github\.com[:/]/i.test(remotes.get("origin") ?? "") ? repoSlug(remotes.get("origin")) : undefined,
1814
1846
  remotes,
1815
1847
  branch: head.match(/^ref:\s*refs\/heads\/(.+?)\s*$/m)?.[1],
1816
1848
  };
package/dist/index.d.ts CHANGED
@@ -48,6 +48,7 @@ export { verifyReceipt, verifyChain, shortReceiptId, type SignedReceipt, type Re
48
48
  export { TIER_ORDER, degradedDecision } from "./degraded.js";
49
49
  export { classify } from "./classify.js";
50
50
  export { describe, describeFields } from "./describe.js";
51
+ export { lookupPrTitle } from "./pr-title.js";
51
52
  export { applyRules } from "./rules.js";
52
53
  export type { Rule, RuleMatch, RuleAction, RuleDecision, FieldOp, } from "./rules.js";
53
54
  export type { Rendered } from "./describe.js";
package/dist/index.js CHANGED
@@ -399,6 +399,7 @@ export { verifyReceipt, verifyChain, shortReceiptId, } from "@oked/receipt-core"
399
399
  export { TIER_ORDER, degradedDecision } from "./degraded.js";
400
400
  export { classify } from "./classify.js";
401
401
  export { describe, describeFields } from "./describe.js";
402
+ export { lookupPrTitle } from "./pr-title.js";
402
403
  export { applyRules } from "./rules.js";
403
404
  export { CLASSIFIER_VERSION } from "./kinds.js";
404
405
  export { loadOKedConfig, OKED_CONFIG_PATH, OKED_RECEIPT_KEYS_PATH } from "./config.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Title of the PR that a card links to, from GitHub (`gh pr view`), for a card
3
+ * whose command does not say it. Pass the result to `describeFields()` as
4
+ * `prTitle`. Returns undefined when the card needs no title, or when gh is not
5
+ * installed, not signed in, or slower than `timeoutMs`.
6
+ */
7
+ export declare function lookupPrTitle(fields: Record<string, string> | undefined, timeoutMs?: number): Promise<string | undefined>;
@@ -0,0 +1,16 @@
1
+ import { execFile } from "node:child_process";
2
+ /**
3
+ * Title of the PR that a card links to, from GitHub (`gh pr view`), for a card
4
+ * whose command does not say it. Pass the result to `describeFields()` as
5
+ * `prTitle`. Returns undefined when the card needs no title, or when gh is not
6
+ * installed, not signed in, or slower than `timeoutMs`.
7
+ */
8
+ export function lookupPrTitle(fields, timeoutMs = 3000) {
9
+ const link = fields?.Link;
10
+ if (!link || !/^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+$/.test(link) || fields.Title?.includes('"')) {
11
+ return Promise.resolve(undefined);
12
+ }
13
+ return new Promise((done) => {
14
+ execFile("gh", ["pr", "view", link, "--json", "title", "--jq", ".title"], { timeout: timeoutMs, env: { ...process.env, GH_PROMPT_DISABLED: "1" } }, (err, stdout) => done(err ? undefined : stdout.trim().split("\n")[0] || undefined));
15
+ });
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/sdk",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
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.11"
48
+ "@oked/receipt-core": "0.6.13"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^22.13.10",