@oked/sdk 0.6.12 → 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.
- package/dist/describe.d.ts +3 -0
- package/dist/describe.js +21 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/pr-title.d.ts +7 -0
- package/dist/pr-title.js +16 -0
- package/package.json +2 -2
package/dist/describe.d.ts
CHANGED
|
@@ -22,6 +22,9 @@ export interface Rendered {
|
|
|
22
22
|
* package.json behind `npm publish`) to show what an action will touch. */
|
|
23
23
|
export interface DescribeContext {
|
|
24
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;
|
|
25
28
|
}
|
|
26
29
|
export declare function describe(toolName: string, toolInput: Record<string, unknown>, ctx?: DescribeContext): string;
|
|
27
30
|
export declare function describeFields(toolName: string, toolInput: Record<string, unknown>, ctx?: DescribeContext): Record<string, string> | null;
|
package/dist/describe.js
CHANGED
|
@@ -53,6 +53,23 @@ export function describeFields(toolName, toolInput, ctx = {}) {
|
|
|
53
53
|
// Top-level dispatch
|
|
54
54
|
// ───────────────────────────────────────────────────────────────────────
|
|
55
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) {
|
|
56
73
|
const fileSizeBytes = typeof toolInput._file_size_bytes === "number" ? toolInput._file_size_bytes : undefined;
|
|
57
74
|
switch (toolName) {
|
|
58
75
|
case "Bash":
|
|
@@ -498,13 +515,16 @@ function summarizeGh(cmd, cwd) {
|
|
|
498
515
|
if (noun === "pr" && verb === "merge") {
|
|
499
516
|
const how = /\s(?:--squash|-s)\b/.test(rest) ? "squash" : /\s(?:--rebase|-r)\b/.test(rest) ? "rebase" : undefined;
|
|
500
517
|
const auto = /\s--auto\b/.test(rest);
|
|
501
|
-
|
|
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 = {
|
|
502
521
|
title: `Merge PR ${ref}${where}`.replace(/\s+/g, " ").trim(),
|
|
503
522
|
annotation: [how, auto ? "when checks pass" : undefined, /\s(?:--delete-branch|-d)\b/.test(rest) ? "deletes branch" : undefined]
|
|
504
523
|
.filter(Boolean).join(", ") || undefined,
|
|
505
524
|
link,
|
|
506
525
|
kind: "git_pr_merge",
|
|
507
526
|
};
|
|
527
|
+
return subject ? namePr(r, subject[1] ?? subject[2] ?? "") : r;
|
|
508
528
|
}
|
|
509
529
|
if (noun === "api") {
|
|
510
530
|
const args = ` ${verb}${rest}`;
|
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>;
|
package/dist/pr-title.js
ADDED
|
@@ -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.
|
|
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.
|
|
48
|
+
"@oked/receipt-core": "0.6.13"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.13.10",
|