@oked/sdk 0.6.25 → 0.6.27
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/README.md +3 -3
- package/dist/classify.d.ts +10 -0
- package/dist/classify.js +216 -18
- package/dist/config.d.ts +0 -20
- package/dist/config.js +0 -36
- package/dist/describe.js +24 -5
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -5
- package/dist/kinds.d.ts +1 -1
- package/dist/kinds.js +1 -1
- package/dist/machine-config.d.ts +7 -0
- package/dist/machine-config.js +13 -0
- package/dist/persisted.d.ts +20 -0
- package/dist/persisted.js +38 -0
- package/dist/pipe-shell.d.ts +6 -0
- package/dist/pipe-shell.js +26 -0
- package/dist/pr-title-gh.d.ts +6 -0
- package/dist/pr-title-gh.js +11 -0
- package/dist/pr-title.d.ts +7 -5
- package/dist/pr-title.js +36 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Pass any of these to `new OKedClient(config)`. Constructor values win over envir
|
|
|
52
52
|
| `strictFailClosed` | `boolean` | `false` | When true, an unreachable backend denies every tier. When false, it denies only `high_stakes`. |
|
|
53
53
|
| `requireReceipt` | `boolean` | `true` | Deny an approval that arrives without a signed receipt. A receipt that is present but invalid always denies. Set `false` (env `OKED_REQUIRE_RECEIPT=0`) only for a backend that does not sign receipts. |
|
|
54
54
|
| `receiptKeysUrl` | `string` | `https://api.oked.ai/.well-known/oked-receipt-keys.json` | Where to fetch a receipt key the SDK has not seen. https only, except loopback. |
|
|
55
|
-
| `receiptKeys` | `ReceiptKey[]` | | Verify with exactly these keys and never fetch. For
|
|
55
|
+
| `receiptKeys` | `ReceiptKey[]` | | Verify with exactly these keys and never fetch. For tests. |
|
|
56
56
|
| `rulesCacheTtlMs` | `number` | `300000` | How long the on-disk rules cache stays fresh. Env `OKED_RULES_CACHE_TTL` is in seconds. |
|
|
57
57
|
| `heartbeatIntervalMs` | `number` | `86400000` | Minimum gap between presence pings. Env `OKED_HEARTBEAT_INTERVAL` is in seconds. |
|
|
58
58
|
| `client` | `string` | | Your integration's name and version, for example `my-agent@1.2.0`. Recorded on the receipt. |
|
|
@@ -91,9 +91,9 @@ Returns `true` when `GET https://api.oked.ai/health` succeeds within 3 seconds.
|
|
|
91
91
|
|
|
92
92
|
### Helpers
|
|
93
93
|
|
|
94
|
-
- `classify(toolName, toolInput)` returns a risk tier for a tool call. `review` and `high_stakes` wait for a person. `rm` of non-temp data, PowerShell `Remove-Item -Recurse`, `rmdir /s`, `rd /s`, `del /s`, `Format-Volume`, `format X:`, a drive root or `$HOME` / `%USERPROFILE%`, `git clean -fdx` and `find -delete` outside a temp or build directory, `git push --force`, and a `curl` GraphQL `volumeDelete` are `high_stakes`. A temp directory or `build` / `dist` / `.next` delete stays `warning`. `bash -c`, `sh -c`, `powershell -Command`, `pwsh -c`, and `cmd /c` are classified by the inner command. Pass `{ sandboxEnforced: false }` to ask (`review`) before an opaque runner (`cargo test`, `npm test`, `npm run`, `pytest`, `go test`, `make`, `./script.sh`, `node scripts/x.mjs`, `npx`). Omit the option, or pass `true`, and those commands stay `safe`. Claude Code sets this from sandbox settings. Other hosts omit it. The runner's child processes are not in the tool call: a `cargo test` that runs `rm -rf ~` is the runner, not the `rm`.
|
|
94
|
+
- `classify(toolName, toolInput)` returns a risk tier for a tool call. `review` and `high_stakes` wait for a person. `rm` of non-temp data, PowerShell `Remove-Item -Recurse`, `rmdir /s`, `rd /s`, `del /s`, `Format-Volume`, `format X:`, a drive root or `$HOME` / `%USERPROFILE%`, `git clean -fdx` and `find -delete` outside a temp or build directory, `git push --force`, and a `curl` GraphQL `volumeDelete` are `high_stakes`. A temp directory or `build` / `dist` / `.next` delete stays `warning`, and so does `rm -rf` of a relative `node_modules` path, including `backend/node_modules`. `bash -c`, `sh -c`, `powershell -Command`, `pwsh -c`, and `cmd /c` are classified by the inner command. A parenthesis subshell, a brace group, a loop or `if` body, and a command substitution inside double quotes are classified by the inner command too. Pass `{ sandboxEnforced: false }` to ask (`review`) before an opaque runner (`cargo test`, `npm test`, `npm run`, `pytest`, `go test`, `make`, `./script.sh`, `node scripts/x.mjs`, `npx`). Omit the option, or pass `true`, and those commands stay `safe`. Claude Code sets this from sandbox settings. Other hosts omit it. The runner's child processes are not in the tool call: a `cargo test` that runs `rm -rf ~` is the runner, not the `rm`.
|
|
95
95
|
- `describe(toolName, toolInput, ctx?)` returns a one-line description.
|
|
96
|
-
- `describeFields(toolName, toolInput, ctx?)` returns the card fields.
|
|
96
|
+
- `describeFields(toolName, toolInput, ctx?)` returns the card fields. A production deploy (`vercel --prod`, `netlify deploy --prod`, `fly deploy`, and the same class) has kind `deploy`. The tier stays `high_stakes`. A preview deploy stays `review`.
|
|
97
97
|
|
|
98
98
|
Full type definitions ship in the package (`dist/index.d.ts`).
|
|
99
99
|
|
package/dist/classify.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { RiskTier } from "./types.js";
|
|
2
|
+
export interface ProductionDeployCard {
|
|
3
|
+
title: string;
|
|
4
|
+
target?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A production deploy the tier logic already treats as high_stakes.
|
|
8
|
+
* Preview deploys, deletes, help, and dry runs return null.
|
|
9
|
+
* Calling this does not change the tier. describe() uses it for the card.
|
|
10
|
+
*/
|
|
11
|
+
export declare function productionDeployCard(stage: string): ProductionDeployCard | null;
|
|
2
12
|
/**
|
|
3
13
|
* `sandboxEnforced: false` asks for `review` before an opaque code runner
|
|
4
14
|
* (a test runner, package script, script file, or npx tool). `true` or omitted
|
package/dist/classify.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import os from "os";
|
|
3
3
|
import { findSqlInCommand } from "./describe.js";
|
|
4
|
+
import { pipesFetchToShell } from "./pipe-shell.js";
|
|
4
5
|
import { TIER_ORDER } from "./degraded.js";
|
|
5
6
|
// Classification is EFFECT-BASED, not command-name-based. We don't keep an
|
|
6
7
|
// allowlist of "safe commands"; instead we detect the few categories of effect
|
|
@@ -204,10 +205,8 @@ const HIGH_STAKES_COMMANDS = [
|
|
|
204
205
|
// grab a flag belonging to a LATER command (e.g. `curl -o … && unzip … -d dir`
|
|
205
206
|
// false-matched the curl `-d` POST-body pattern on unzip's destination flag).
|
|
206
207
|
// They belong to a single curl invocation, so they're scanned PER-STAGE in
|
|
207
|
-
// OUTWARD_CURL_STAGE below.
|
|
208
|
-
// (
|
|
209
|
-
/\bwget\s+.*\|\s*(bash|sh|zsh)\b/,
|
|
210
|
-
/\bcurl\s+.*\|\s*(bash|sh|zsh)\b/,
|
|
208
|
+
// OUTWARD_CURL_STAGE below. A fetch piped into a shell spans a pipe, so
|
|
209
|
+
// pipesFetchToShell() runs on the full command before this list.
|
|
211
210
|
NPM_PUBLISH_RE,
|
|
212
211
|
/\bnpm\s+unpublish\b/,
|
|
213
212
|
NPX_DEPLOY_RE,
|
|
@@ -604,6 +603,98 @@ function classifyCloudCliStage(stage) {
|
|
|
604
603
|
}
|
|
605
604
|
return null;
|
|
606
605
|
}
|
|
606
|
+
/**
|
|
607
|
+
* A production deploy the tier logic already treats as high_stakes.
|
|
608
|
+
* Preview deploys, deletes, help, and dry runs return null.
|
|
609
|
+
* Calling this does not change the tier. describe() uses it for the card.
|
|
610
|
+
*/
|
|
611
|
+
export function productionDeployCard(stage) {
|
|
612
|
+
let bare = stage.trim().replace(DELETE_LEAD, "");
|
|
613
|
+
bare = bare.replace(/^(?:\w+=\S+\s+)+/, "");
|
|
614
|
+
const args = splitArgs(bare.replace(CLI_RUNNER_RE, ""));
|
|
615
|
+
const tool = (args.shift() ?? "").replace(/^.*\//, "").replace(/(?<=.)@.*$/, "");
|
|
616
|
+
const sep = args.indexOf("--");
|
|
617
|
+
const head = sep === -1 ? args : args.slice(0, sep);
|
|
618
|
+
if (head.some((arg) => CLI_PREVIEW_ARG_RE.test(arg)))
|
|
619
|
+
return null;
|
|
620
|
+
if (cliPositionals(args)[0] === "help")
|
|
621
|
+
return null;
|
|
622
|
+
const flag = (names) => {
|
|
623
|
+
for (let i = 0; i < args.length; i++) {
|
|
624
|
+
const arg = args[i];
|
|
625
|
+
for (const name of names) {
|
|
626
|
+
if (arg === name && args[i + 1])
|
|
627
|
+
return args[i + 1];
|
|
628
|
+
if (arg.startsWith(`${name}=`))
|
|
629
|
+
return arg.slice(name.length + 1);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return undefined;
|
|
633
|
+
};
|
|
634
|
+
switch (tool) {
|
|
635
|
+
case "vercel": {
|
|
636
|
+
const [sub, op] = cliPositionals(args, VERCEL_VALUE_FLAGS);
|
|
637
|
+
const prod = args.some((arg, i) => arg === "--prod" || arg === "--target=production" ||
|
|
638
|
+
(arg === "--target" && args[i + 1] === "production"));
|
|
639
|
+
const path = sub !== undefined && sub !== "deploy" && !VERCEL_SUBCOMMANDS.has(sub);
|
|
640
|
+
if ((sub === undefined || sub === "deploy" || path) && prod) {
|
|
641
|
+
return { title: "Deploy to Vercel production", target: path ? sub : undefined };
|
|
642
|
+
}
|
|
643
|
+
if (sub === "redeploy" && prod)
|
|
644
|
+
return { title: "Redeploy on Vercel production" };
|
|
645
|
+
if (sub === "promote")
|
|
646
|
+
return { title: "Promote a Vercel deployment to production", target: op };
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
case "netlify": {
|
|
650
|
+
const words = cliPositionals(args, new Set(["--site", "--dir", "-d", "--auth", "--filter", "-a", "-s", "-m", "--message", "--alias"]));
|
|
651
|
+
const prod = args.some((arg) => /^(?:--prod|-p|--prodIfUnlocked|--prod-if-unlocked)$/.test(arg));
|
|
652
|
+
if (words[0] === "deploy" && prod)
|
|
653
|
+
return { title: "Deploy to Netlify production", target: flag(["--site", "-s"]) };
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
case "fly":
|
|
657
|
+
case "flyctl": {
|
|
658
|
+
const words = cliPositionals(args, new Set(["-a", "--app", "-c", "--config", "-r", "--region", "--image", "-t", "--access-token"]));
|
|
659
|
+
if (words[0] === "deploy")
|
|
660
|
+
return { title: "Deploy to Fly", target: flag(["-a", "--app"]) };
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
case "wrangler": {
|
|
664
|
+
const words = cliPositionals(args, new Set(["-c", "--config", "-e", "--env", "--name"]));
|
|
665
|
+
const name = flag(["--name"]);
|
|
666
|
+
if (words.includes("publish"))
|
|
667
|
+
return { title: "Publish with Wrangler", target: name };
|
|
668
|
+
if (words.includes("deploy"))
|
|
669
|
+
return { title: "Deploy with Wrangler", target: name };
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
case "firebase": {
|
|
673
|
+
const words = cliPositionals(args, new Set(["-P", "--project", "--only", "--except", "--token"]));
|
|
674
|
+
if (words[0] === "deploy")
|
|
675
|
+
return { title: "Deploy to Firebase", target: flag(["-P", "--project"]) };
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
case "serverless":
|
|
679
|
+
case "sls":
|
|
680
|
+
return cliPositionals(args)[0] === "deploy" ? { title: "Deploy with Serverless" } : null;
|
|
681
|
+
case "cdk":
|
|
682
|
+
return cliPositionals(args)[0] === "deploy" ? { title: "Deploy with AWS CDK" } : null;
|
|
683
|
+
case "gcloud": {
|
|
684
|
+
const words = cliPositionals(args, new Set(["--project", "--account", "--configuration", "--format", "--verbosity", "--impersonate-service-account"]));
|
|
685
|
+
const local = ["config", "auth", "components", "info", "init", "version", "topic"];
|
|
686
|
+
if (local.includes(words[0] ?? ""))
|
|
687
|
+
return null;
|
|
688
|
+
const verbs = words.slice(1);
|
|
689
|
+
const at = verbs.indexOf("deploy");
|
|
690
|
+
if (at === -1)
|
|
691
|
+
return null;
|
|
692
|
+
return { title: "Deploy with gcloud", target: verbs[at + 1] };
|
|
693
|
+
}
|
|
694
|
+
default:
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
607
698
|
/**
|
|
608
699
|
* `gh api` is curl for GitHub: a mutating method, or fields without a method
|
|
609
700
|
* (gh then sends a POST), is an outward write like a curl POST. A GraphQL call
|
|
@@ -1068,7 +1159,8 @@ function isEphemeralOnlyDeletion(command, ephemeralVars = new Set()) {
|
|
|
1068
1159
|
});
|
|
1069
1160
|
}
|
|
1070
1161
|
// Build output folders in the project. The next build makes them again, so
|
|
1071
|
-
// deleting them is a reversible local change.
|
|
1162
|
+
// deleting them is a reversible local change. node_modules is the same: the
|
|
1163
|
+
// next install makes it again.
|
|
1072
1164
|
const BUILD_OUTPUT_DIRS = new Set(["build", "dist", ".build", "DerivedData", ".next"]);
|
|
1073
1165
|
// rm/trash whose every target is a relative path inside a build output folder
|
|
1074
1166
|
// (`rm -rf build/OKed.xcarchive dist`). An absolute path, `..`, a variable or a
|
|
@@ -1078,6 +1170,9 @@ function isBuildOutputPath(target) {
|
|
|
1078
1170
|
// An absolute path, a drive letter, or `..` can point outside the build tree.
|
|
1079
1171
|
if (!parts[0] || parts[0].includes(":") || parts.includes(".."))
|
|
1080
1172
|
return false;
|
|
1173
|
+
// A package folder can hold it (`backend/node_modules`), if each segment is a plain name.
|
|
1174
|
+
if (parts.includes("node_modules") && parts.every((p) => /^[\w.@-]+$/.test(p)))
|
|
1175
|
+
return true;
|
|
1081
1176
|
return BUILD_OUTPUT_DIRS.has(parts[0]);
|
|
1082
1177
|
}
|
|
1083
1178
|
function isBuildOutputOnlyDeletion(command) {
|
|
@@ -1643,9 +1738,9 @@ function isInfraVolumeDeleteCurl(command) {
|
|
|
1643
1738
|
// A curl/wget whose target host is loopback (localhost, 127.0.0.0/8, 0.0.0.0,
|
|
1644
1739
|
// ::1). A request to a server on this machine is a LOCAL action, not an outward
|
|
1645
1740
|
// one, so a mutating method/body (POST/PUT/DELETE, -d, …) to it doesn't warrant
|
|
1646
|
-
// a prompt — it downgrades to `warning`.
|
|
1647
|
-
//
|
|
1648
|
-
//
|
|
1741
|
+
// a prompt — it downgrades to `warning`. A fetch piped into a shell is matched
|
|
1742
|
+
// earlier on the FULL command and stays high_stakes regardless of host, so
|
|
1743
|
+
// this only affects the request-method/body patterns.
|
|
1649
1744
|
function isLoopbackAuthority(authority) {
|
|
1650
1745
|
const host = authority.replace(/^\[/, "").replace(/\]$/, "").toLowerCase();
|
|
1651
1746
|
return host === "localhost" || host === "0.0.0.0" || host === "::1" ||
|
|
@@ -1667,6 +1762,85 @@ function isLoopbackHttpStage(stage) {
|
|
|
1667
1762
|
return false;
|
|
1668
1763
|
return /(?:^|[\s@])(?:localhost|127(?:\.\d{1,3}){3}|0\.0\.0\.0|\[::1\])(?::\d+)?(?:[/\s'"]|$)/i.test(stage);
|
|
1669
1764
|
}
|
|
1765
|
+
/**
|
|
1766
|
+
* Remove what a subshell, a group or a loop or `if` keyword adds around a stage.
|
|
1767
|
+
* The split gives `(gh pr merge 5`, `do gh pr merge 5` and `kill $p)`, and the
|
|
1768
|
+
* rules read a command at the stage start, so the prefix hid the command and a
|
|
1769
|
+
* `)` changed its last word. `((` is arithmetic and stays.
|
|
1770
|
+
*/
|
|
1771
|
+
function unwrapShellGroup(stage) {
|
|
1772
|
+
let out = stage.replace(/^(?:\((?!\()|\{\s|!\s|(?:if|elif|while|until|then|else|do)\s)\s*/, "");
|
|
1773
|
+
let depth = 0;
|
|
1774
|
+
let quote = null;
|
|
1775
|
+
for (let i = 0; i < out.length; i++) {
|
|
1776
|
+
const ch = out[i];
|
|
1777
|
+
if (ch === "\\" && quote !== "'") {
|
|
1778
|
+
i++;
|
|
1779
|
+
continue;
|
|
1780
|
+
}
|
|
1781
|
+
if (quote) {
|
|
1782
|
+
if (ch === quote)
|
|
1783
|
+
quote = null;
|
|
1784
|
+
continue;
|
|
1785
|
+
}
|
|
1786
|
+
if (ch === '"' || ch === "'")
|
|
1787
|
+
quote = ch;
|
|
1788
|
+
else if (ch === "(")
|
|
1789
|
+
depth++;
|
|
1790
|
+
else if (ch === ")")
|
|
1791
|
+
depth--;
|
|
1792
|
+
}
|
|
1793
|
+
while (depth < 0 && out.endsWith(")")) {
|
|
1794
|
+
out = out.slice(0, -1).trimEnd();
|
|
1795
|
+
depth++;
|
|
1796
|
+
}
|
|
1797
|
+
return out;
|
|
1798
|
+
}
|
|
1799
|
+
/** The commands in `$(…)` and backticks that the shell runs. Single quotes keep them as text. */
|
|
1800
|
+
function commandSubstitutions(stage) {
|
|
1801
|
+
const out = [];
|
|
1802
|
+
let quote = null;
|
|
1803
|
+
for (let i = 0; i < stage.length; i++) {
|
|
1804
|
+
const ch = stage[i];
|
|
1805
|
+
if (ch === "\\" && quote !== "'") {
|
|
1806
|
+
i++;
|
|
1807
|
+
continue;
|
|
1808
|
+
}
|
|
1809
|
+
if (quote === "'") {
|
|
1810
|
+
if (ch === "'")
|
|
1811
|
+
quote = null;
|
|
1812
|
+
continue;
|
|
1813
|
+
}
|
|
1814
|
+
if (ch === '"') {
|
|
1815
|
+
quote = quote ? null : '"';
|
|
1816
|
+
continue;
|
|
1817
|
+
}
|
|
1818
|
+
if (ch === "'" && !quote) {
|
|
1819
|
+
quote = "'";
|
|
1820
|
+
continue;
|
|
1821
|
+
}
|
|
1822
|
+
if (ch === "`") {
|
|
1823
|
+
const end = stage.indexOf("`", i + 1);
|
|
1824
|
+
if (end < 0)
|
|
1825
|
+
break;
|
|
1826
|
+
out.push(stage.slice(i + 1, end));
|
|
1827
|
+
i = end;
|
|
1828
|
+
}
|
|
1829
|
+
else if (ch === "$" && stage[i + 1] === "(" && stage[i + 2] !== "(") {
|
|
1830
|
+
let depth = 1;
|
|
1831
|
+
let j = i + 2;
|
|
1832
|
+
for (; j < stage.length && depth > 0; j++) {
|
|
1833
|
+
if (stage[j] === "(")
|
|
1834
|
+
depth++;
|
|
1835
|
+
else if (stage[j] === ")")
|
|
1836
|
+
depth--;
|
|
1837
|
+
}
|
|
1838
|
+
out.push(stage.slice(i + 2, depth === 0 ? j - 1 : j));
|
|
1839
|
+
i = j - 1;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
return out;
|
|
1843
|
+
}
|
|
1670
1844
|
function classifyBashCommand(command, ephemeralVars = new Set(), sandboxEnforced) {
|
|
1671
1845
|
if (!command)
|
|
1672
1846
|
return "safe";
|
|
@@ -1685,12 +1859,13 @@ function classifyBashCommand(command, ephemeralVars = new Set(), sandboxEnforced
|
|
|
1685
1859
|
const intact = stripHeredocBodies(command).trim();
|
|
1686
1860
|
const stripped = blankTextCommandArgs(stripCurlDataBodies(stripInlineScriptBodies(stripCodeHeredocBodies(intact)))).trim();
|
|
1687
1861
|
// High-stakes scan on the FULL (body-stripped) command, before any splitting.
|
|
1688
|
-
// These patterns use \b and
|
|
1689
|
-
//
|
|
1690
|
-
//
|
|
1691
|
-
//
|
|
1692
|
-
//
|
|
1693
|
-
|
|
1862
|
+
// These patterns use \b and a fetch piped into a shell spans an operator, so
|
|
1863
|
+
// they have to be matched against the whole string. Most-restrictive-wins: a
|
|
1864
|
+
// high-stakes match anywhere in a compound command takes the whole command
|
|
1865
|
+
// to high_stakes. (File deletion is NOT here — it's per-stage below so the
|
|
1866
|
+
// ephemeral-temp downgrade can run.)
|
|
1867
|
+
if (pipesFetchToShell(stripped, "spaced"))
|
|
1868
|
+
return "high_stakes";
|
|
1694
1869
|
for (const pattern of HIGH_STAKES_COMMANDS) {
|
|
1695
1870
|
if (pattern === NPX_DEPLOY_RE && (isLocalPrismaDeploy(stripped) ||
|
|
1696
1871
|
(ephemeralVars.has(LOCAL_DB) && /\bprisma\s+migrate\s+deploy\b/.test(stripped))))
|
|
@@ -1703,7 +1878,7 @@ function classifyBashCommand(command, ephemeralVars = new Set(), sandboxEnforced
|
|
|
1703
1878
|
}
|
|
1704
1879
|
// Text piped into a shell (`echo '…' | sh`, `printf … | bash`) runs as code
|
|
1705
1880
|
// that no stage shows on its own. At least `review`; a known high-stakes
|
|
1706
|
-
// pattern above (
|
|
1881
|
+
// pattern above (a fetch piped into a shell) already returned.
|
|
1707
1882
|
const pipesToShell = splitTopLevel(stripped, { pipes: false }).some((step) => {
|
|
1708
1883
|
const parts = splitTopLevel(step);
|
|
1709
1884
|
return parts.length > 1 && parts.slice(1).some((p) => /^(?:sudo\s+)?(?:ba|z|k|da)?sh\b(?!\s+-n\b)/.test(p));
|
|
@@ -1735,6 +1910,9 @@ function classifyBashCommand(command, ephemeralVars = new Set(), sandboxEnforced
|
|
|
1735
1910
|
return worst;
|
|
1736
1911
|
}
|
|
1737
1912
|
// ---- single stage from here ----
|
|
1913
|
+
const unwrapped = unwrapShellGroup(intact);
|
|
1914
|
+
if (unwrapped !== intact)
|
|
1915
|
+
return classifyBashCommand(unwrapped, ephemeralVars, sandboxEnforced);
|
|
1738
1916
|
// SQL severity from the body-INTACT view: an interpreter wrapper (python -c,
|
|
1739
1917
|
// node -e, heredoc), a DB CLI (psql -c, sqlite3 db "...", mysql -e), or SQL at
|
|
1740
1918
|
// the top of the command. Folded in as a floor so it survives even when the
|
|
@@ -1745,7 +1923,13 @@ function classifyBashCommand(command, ephemeralVars = new Set(), sandboxEnforced
|
|
|
1745
1923
|
// Read it from the intact command. A normal POST stays review below.
|
|
1746
1924
|
if (isInfraVolumeDeleteCurl(intact))
|
|
1747
1925
|
return "high_stakes";
|
|
1748
|
-
|
|
1926
|
+
// The rules read a command at the stage start, so one in a substitution
|
|
1927
|
+
// (`echo "$(gh pr merge 5)"`) is classified on its own.
|
|
1928
|
+
let substitutionTier = "safe";
|
|
1929
|
+
for (const inner of commandSubstitutions(stripped)) {
|
|
1930
|
+
substitutionTier = maxTier(substitutionTier, classifyBashCommand(inner, ephemeralVars, sandboxEnforced));
|
|
1931
|
+
}
|
|
1932
|
+
return maxTier(maxTier(maxTier(sqlTier, pipesToShell ? "review" : "safe"), substitutionTier), classifyStageShellEffects(stripped, ephemeralVars, sandboxEnforced));
|
|
1749
1933
|
}
|
|
1750
1934
|
/**
|
|
1751
1935
|
* Shell-effect classification of a SINGLE, already-body-stripped stage. No SQL
|
|
@@ -2288,6 +2472,12 @@ const TEXT_ARG_COMMAND_RE = /^(?:\w+=(?:"[^"]*"|'[^']*'|\S+)\s+)*(?:git|grep|egr
|
|
|
2288
2472
|
// quoted positional arguments keep their text, because the script may run them.
|
|
2289
2473
|
const SCRIPT_FILE_STEP_RE = /^(?:\\\s+)?(?:\w+=(?:"[^"]*"|'[^']*'|\S+)\s+)*(?:node|tsx|bun)\s+(?!-)\S+\.[cm]?[jt]s(?:\s|$)/;
|
|
2290
2474
|
const LONG_OPTION_QUOTED_VALUE_RE = /(--[\w-]+(?:=|\s+))('[^']*'|"(?:[^"\\]|\\.)*")/g;
|
|
2475
|
+
// `sed` with a single-quoted plain substitution (`'12s/old/new/g'`): the new
|
|
2476
|
+
// text goes into a file, and the shell does not run it. The `e` flag runs a
|
|
2477
|
+
// command and the `w` flag writes a file, so an expression with either flag
|
|
2478
|
+
// keeps its text. So does a double-quoted one, where `$(…)` runs.
|
|
2479
|
+
const SED_STEP_RE = /^(?:\\\s+)?(?:\w+=(?:"[^"]*"|'[^']*'|\S+)\s+)*sed\s/;
|
|
2480
|
+
const SED_PLAIN_SUBSTITUTION_RE = /^(?:\d+(?:,\d+)?|\$|\/(?:\\.|[^\\/])*\/)?s([^\w\s\\])(?:\\.|(?!\1)[^\\])*\1(?:\\.|(?!\1)[^\\])*\1[gGiIpmM\d]*$/;
|
|
2291
2481
|
// Commands that run the text piped into them as code.
|
|
2292
2482
|
const RUNS_PIPED_TEXT_RE = /^(?:sudo\s+)?(?:(?:ba|z|k|da)?sh|xargs|eval|source|\.|node|deno|bun|python\d?(?:\.\d+)?|ruby|perl|psql|mysql|mariadb|sqlite3?)\b/;
|
|
2293
2483
|
/**
|
|
@@ -2305,12 +2495,20 @@ export function blankTextCommandArgs(command) {
|
|
|
2305
2495
|
return step;
|
|
2306
2496
|
return step.replace(LONG_OPTION_QUOTED_VALUE_RE, (_m, opt, q) => opt + q[0] + " ".repeat(Math.max(0, q.length - 2)) + q[0]);
|
|
2307
2497
|
}
|
|
2498
|
+
if (SED_STEP_RE.test(step)) {
|
|
2499
|
+
if (splitTopLevel(step).slice(1).some((p) => RUNS_PIPED_TEXT_RE.test(p)))
|
|
2500
|
+
return step;
|
|
2501
|
+
return step.replace(/'[^']*'/g, (q) => SED_PLAIN_SUBSTITUTION_RE.test(q.slice(1, -1)) ? q[0] + " ".repeat(Math.max(0, q.length - 2)) + q[0] : q);
|
|
2502
|
+
}
|
|
2308
2503
|
if (!TEXT_ARG_COMMAND_RE.test(step))
|
|
2309
2504
|
return step;
|
|
2310
2505
|
if (splitTopLevel(step).slice(1).some((p) => RUNS_PIPED_TEXT_RE.test(p)))
|
|
2311
2506
|
return step;
|
|
2312
|
-
// A quoted redirect target (`>> "$HOME/.ssh/authorized_keys"`) is a path, not
|
|
2313
|
-
|
|
2507
|
+
// A quoted redirect target (`>> "$HOME/.ssh/authorized_keys"`) is a path, not
|
|
2508
|
+
// text. A double-quoted `$(…)` or backtick runs (`echo "$(rm -rf /data)"`).
|
|
2509
|
+
return step.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, (q, at) => /[<>]\s*$/.test(step.slice(0, at)) || (q[0] === '"' && /\$\(|`/.test(q))
|
|
2510
|
+
? q
|
|
2511
|
+
: q[0] + " ".repeat(Math.max(0, q.length - 2)) + q[0]);
|
|
2314
2512
|
})
|
|
2315
2513
|
.join("\n");
|
|
2316
2514
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
export interface PersistedConfig {
|
|
2
|
-
apiKey?: string;
|
|
3
|
-
backendUrl?: string;
|
|
4
|
-
strictFailClosed?: boolean;
|
|
5
|
-
/** TTL (seconds) for the on-disk rules cache. See OKedConfig.rulesCacheTtlMs. */
|
|
6
|
-
rulesCacheTtlSeconds?: number;
|
|
7
|
-
/** Min interval (seconds) between heartbeats. See OKedConfig.heartbeatIntervalMs. */
|
|
8
|
-
heartbeatIntervalSeconds?: number;
|
|
9
|
-
/** Deny an approval that arrives without a receipt (default true). See OKedConfig.requireReceipt. */
|
|
10
|
-
requireReceipt?: boolean;
|
|
11
|
-
/** Where to fetch receipt keys. See OKedConfig.receiptKeysUrl. */
|
|
12
|
-
receiptKeysUrl?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare const OKED_CONFIG_PATH: string;
|
|
15
1
|
export declare const OKED_RULES_CACHE_PATH: string;
|
|
16
2
|
export declare const OKED_HEARTBEAT_PATH: string;
|
|
17
3
|
export declare const OKED_RECEIPT_KEYS_PATH: string;
|
|
18
|
-
/**
|
|
19
|
-
* Read ~/.oked/config.json if present. Returns {} on any error (missing file,
|
|
20
|
-
* malformed JSON, no home dir). Callers should treat this as a best-effort
|
|
21
|
-
* lookup behind explicit arguments and environment variables.
|
|
22
|
-
*/
|
|
23
|
-
export declare function loadOKedConfig(): PersistedConfig;
|
package/dist/config.js
CHANGED
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
1
|
import { homedir } from "os";
|
|
3
2
|
import { join } from "path";
|
|
4
|
-
export const OKED_CONFIG_PATH = join(homedir(), ".oked", "config.json");
|
|
5
3
|
export const OKED_RULES_CACHE_PATH = join(homedir(), ".oked", "rules-cache.json");
|
|
6
4
|
export const OKED_HEARTBEAT_PATH = join(homedir(), ".oked", "heartbeat.json");
|
|
7
5
|
export const OKED_RECEIPT_KEYS_PATH = join(homedir(), ".oked", "receipt-keys.json");
|
|
8
|
-
/**
|
|
9
|
-
* Read ~/.oked/config.json if present. Returns {} on any error (missing file,
|
|
10
|
-
* malformed JSON, no home dir). Callers should treat this as a best-effort
|
|
11
|
-
* lookup behind explicit arguments and environment variables.
|
|
12
|
-
*/
|
|
13
|
-
export function loadOKedConfig() {
|
|
14
|
-
try {
|
|
15
|
-
const raw = readFileSync(OKED_CONFIG_PATH, "utf-8");
|
|
16
|
-
const parsed = JSON.parse(raw);
|
|
17
|
-
if (!parsed || typeof parsed !== "object")
|
|
18
|
-
return {};
|
|
19
|
-
const out = {};
|
|
20
|
-
if (typeof parsed.apiKey === "string" && parsed.apiKey)
|
|
21
|
-
out.apiKey = parsed.apiKey;
|
|
22
|
-
if (typeof parsed.backendUrl === "string" && parsed.backendUrl)
|
|
23
|
-
out.backendUrl = parsed.backendUrl;
|
|
24
|
-
if (typeof parsed.strictFailClosed === "boolean")
|
|
25
|
-
out.strictFailClosed = parsed.strictFailClosed;
|
|
26
|
-
if (typeof parsed.rulesCacheTtlSeconds === "number" && parsed.rulesCacheTtlSeconds >= 0) {
|
|
27
|
-
out.rulesCacheTtlSeconds = parsed.rulesCacheTtlSeconds;
|
|
28
|
-
}
|
|
29
|
-
if (typeof parsed.heartbeatIntervalSeconds === "number" && parsed.heartbeatIntervalSeconds >= 0) {
|
|
30
|
-
out.heartbeatIntervalSeconds = parsed.heartbeatIntervalSeconds;
|
|
31
|
-
}
|
|
32
|
-
if (typeof parsed.requireReceipt === "boolean")
|
|
33
|
-
out.requireReceipt = parsed.requireReceipt;
|
|
34
|
-
if (typeof parsed.receiptKeysUrl === "string" && parsed.receiptKeysUrl)
|
|
35
|
-
out.receiptKeysUrl = parsed.receiptKeysUrl;
|
|
36
|
-
return out;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return {};
|
|
40
|
-
}
|
|
41
|
-
}
|
package/dist/describe.js
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
11
11
|
import { homedir } from "node:os";
|
|
12
12
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
13
|
-
import { blankTextCommandArgs, classify, classifyBashSteps, extractShellWriteOps, splitTopLevel, stripCodeHeredocBodies, stripInlineScriptBodies } from "./classify.js";
|
|
13
|
+
import { blankTextCommandArgs, classify, classifyBashSteps, extractShellWriteOps, productionDeployCard, splitTopLevel, stripCodeHeredocBodies, stripInlineScriptBodies } from "./classify.js";
|
|
14
14
|
import { TIER_ORDER } from "./degraded.js";
|
|
15
|
+
import { pipesFetchToShell } from "./pipe-shell.js";
|
|
15
16
|
const BODY_PREVIEW_MAX = 200;
|
|
16
17
|
const COMMAND_INLINE_MAX = 50;
|
|
17
18
|
const DIFF_HUNK_MAX_LINES = 10;
|
|
@@ -71,7 +72,8 @@ function summarize(toolName, toolInput, ctx) {
|
|
|
71
72
|
/**
|
|
72
73
|
* "Merge PR #49 in o/r" says which PR, not what it does. Put the PR title after
|
|
73
74
|
* the number: `Merge PR #49 "feat: OG image" in o/r`. A title that already
|
|
74
|
-
* quotes something keeps it.
|
|
75
|
+
* quotes something keeps it. The name is short, so the title stays near 60
|
|
76
|
+
* characters. The card link opens the whole PR.
|
|
75
77
|
*/
|
|
76
78
|
function namePr(r, prTitle) {
|
|
77
79
|
const num = r.title.match(/\bPR #(\d+)\b/)?.[1];
|
|
@@ -79,7 +81,7 @@ function namePr(r, prTitle) {
|
|
|
79
81
|
const name = prTitle.split("\n")[0].replace(new RegExp(`\\s*\\(#${num}\\)$`), "").trim();
|
|
80
82
|
if (!num || !name || /[$`]/.test(name) || r.title.includes('"'))
|
|
81
83
|
return r;
|
|
82
|
-
return { ...r, title: r.title.replace(`PR #${num}`, `PR #${num} "${truncate(name,
|
|
84
|
+
return { ...r, title: r.title.replace(`PR #${num}`, `PR #${num} "${truncate(name, 30)}"`) };
|
|
83
85
|
}
|
|
84
86
|
function summarizeTool(toolName, toolInput, ctx) {
|
|
85
87
|
const fileSizeBytes = typeof toolInput._file_size_bytes === "number" ? toolInput._file_size_bytes : undefined;
|
|
@@ -385,7 +387,7 @@ function summarizeBash(command, sizeBytes, cwd, sandboxEnforced) {
|
|
|
385
387
|
};
|
|
386
388
|
}
|
|
387
389
|
}
|
|
388
|
-
if (
|
|
390
|
+
if (pipesFetchToShell(cmd, "word")) {
|
|
389
391
|
const url = cmd.match(/https?:\/\/[^\s|'"]+/)?.[0];
|
|
390
392
|
return {
|
|
391
393
|
title: `Download and execute script${url ? ` from ${extractHost(url)}` : ""}`,
|
|
@@ -449,6 +451,11 @@ function summarizeBash(command, sizeBytes, cwd, sandboxEnforced) {
|
|
|
449
451
|
return { title: "Unpublish package from npm", kind: "npm_unpublish" };
|
|
450
452
|
if (/\bnpx\s+.*\s+deploy\b/.test(shellText(cmd)))
|
|
451
453
|
return { title: "Deploy via npx", body: truncateBody(cmd), kind: "npx_deploy" };
|
|
454
|
+
// Production deploys (vercel --prod, fly deploy, and the same class).
|
|
455
|
+
// The tier already comes from classify(). This only names the card.
|
|
456
|
+
const prodDeploy = productionDeployCard(cmd);
|
|
457
|
+
if (prodDeploy)
|
|
458
|
+
return { title: prodDeploy.title, target: prodDeploy.target, kind: "deploy" };
|
|
452
459
|
// sudo / chmod (kill/pkill/killall are handled in command position above,
|
|
453
460
|
// ahead of the compound catch-all).
|
|
454
461
|
if (/\bsudo\b/.test(cmd)) {
|
|
@@ -470,7 +477,7 @@ function summarizeBash(command, sizeBytes, cwd, sandboxEnforced) {
|
|
|
470
477
|
* -X POST …` reads "POST request to api.oked.ai", not a title built from bits
|
|
471
478
|
* of three steps. Other steps that need approval on their own are listed in the
|
|
472
479
|
* subline. Returns null when no step needs approval, or when the tier comes
|
|
473
|
-
* from a pattern that spans steps (
|
|
480
|
+
* from a pattern that spans steps (a fetch piped into a shell): the whole-command rules
|
|
474
481
|
* below describe those.
|
|
475
482
|
*/
|
|
476
483
|
function summarizeCompoundBash(cmd, sizeBytes, cwd, sandboxEnforced) {
|
|
@@ -587,6 +594,18 @@ function summarizeGh(cmd, cwd) {
|
|
|
587
594
|
const name = noun === "release" || noun === "secret" || noun === "variable" || noun === "workflow"
|
|
588
595
|
? rest.match(/^\s+([^\s-][^\s]*)/)?.[1] : undefined;
|
|
589
596
|
const body = rest.match(/\s(?:-b|--body)[\s=]+(?:'([^']*)'|"((?:[^"\\]|\\.)*)")/);
|
|
597
|
+
if (noun === "repo" && (verb === "create" || verb === "fork")) {
|
|
598
|
+
// The repo to make or fork is the first argument. The folder's repo is not
|
|
599
|
+
// the place of a new repo, and a fork with no argument forks the folder's repo.
|
|
600
|
+
const named = rest.match(/^\s+(?:https:\/\/github\.com\/)?([\w.-]+(?:\/[\w.-]+)?)(?=\s|$)/)?.[1]?.replace(/\.git$/, "");
|
|
601
|
+
const subject = named ?? (verb === "fork" ? repo : undefined);
|
|
602
|
+
const org = rest.match(/\s--org[\s=]+([\w.-]+)/)?.[1];
|
|
603
|
+
return {
|
|
604
|
+
title: `${verb === "fork" ? "Fork" : "Create"} repo${subject ? ` ${subject}` : ""}${verb === "fork" && org ? ` to ${org}` : ""}`,
|
|
605
|
+
annotation: verb === "create" ? rest.match(/\s--(private|public|internal)\b/)?.[1] : undefined,
|
|
606
|
+
kind: "gh_write",
|
|
607
|
+
};
|
|
608
|
+
}
|
|
590
609
|
const obj = `${thing}${ref ? ` ${ref}` : name ? ` ${name}` : ""}`;
|
|
591
610
|
const phrase = verb === "comment" ? `Comment on ${obj}`
|
|
592
611
|
: verb === "ready" ? `Mark ${obj} ready for review`
|
package/dist/index.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export type { Rule, RuleMatch, RuleAction, RuleDecision, FieldOp, } from "./rule
|
|
|
55
55
|
export type { Rendered } from "./describe.js";
|
|
56
56
|
export { CLASSIFIER_VERSION } from "./kinds.js";
|
|
57
57
|
export type { OperationKind } from "./kinds.js";
|
|
58
|
-
export { loadOKedConfig, OKED_CONFIG_PATH
|
|
59
|
-
export type { PersistedConfig } from "./
|
|
58
|
+
export { loadOKedConfig, OKED_CONFIG_PATH } from "./persisted.js";
|
|
59
|
+
export type { PersistedConfig } from "./persisted.js";
|
|
60
|
+
export { OKED_RECEIPT_KEYS_PATH } from "./config.js";
|
|
60
61
|
export type { RiskTier, ApprovalRequest, ApprovalResponse, OKedConfig, HookInput, HookOutput, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
2
2
|
import { dirname } from "path";
|
|
3
|
-
import {
|
|
3
|
+
import { OKED_RULES_CACHE_PATH, OKED_HEARTBEAT_PATH } from "./config.js";
|
|
4
|
+
import { machineSettings } from "./machine-config.js";
|
|
4
5
|
import { OKedAuthError, OKedBackendUnreachableError, OKedHttpError, OKedTooManyPendingError } from "./errors.js";
|
|
5
6
|
import { randomUUID } from "crypto";
|
|
6
7
|
import { checkReceipt, OKED_RECEIPT_KEYS_URL } from "./receipt.js";
|
|
@@ -92,15 +93,15 @@ function writeHeartbeatStamps(stamps) {
|
|
|
92
93
|
export class OKedClient {
|
|
93
94
|
config;
|
|
94
95
|
constructor(config) {
|
|
95
|
-
const persisted =
|
|
96
|
+
const persisted = machineSettings();
|
|
96
97
|
this.config = {
|
|
97
|
-
apiKey: config?.apiKey ||
|
|
98
|
+
apiKey: config?.apiKey || persisted.apiKey || "",
|
|
98
99
|
backendUrl: config?.backendUrl ||
|
|
99
100
|
process.env.OKED_BACKEND_URL ||
|
|
100
101
|
persisted.backendUrl ||
|
|
101
102
|
"https://api.oked.ai",
|
|
102
103
|
timeout: config?.timeout || DEFAULT_APPROVAL_TIMEOUT_MS,
|
|
103
|
-
// Precedence: constructor
|
|
104
|
+
// Precedence: constructor, then environment, then saved settings, then false.
|
|
104
105
|
strictFailClosed: config?.strictFailClosed ??
|
|
105
106
|
envStrictFailClosed() ??
|
|
106
107
|
persisted.strictFailClosed ??
|
|
@@ -402,4 +403,5 @@ export { describe, describeFields, OPAQUE_RUNNER_FOOTNOTE } from "./describe.js"
|
|
|
402
403
|
export { lookupPrTitle } from "./pr-title.js";
|
|
403
404
|
export { applyRules } from "./rules.js";
|
|
404
405
|
export { CLASSIFIER_VERSION } from "./kinds.js";
|
|
405
|
-
export { loadOKedConfig, OKED_CONFIG_PATH
|
|
406
|
+
export { loadOKedConfig, OKED_CONFIG_PATH } from "./persisted.js";
|
|
407
|
+
export { OKED_RECEIPT_KEYS_PATH } from "./config.js";
|
package/dist/kinds.d.ts
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* pattern maps to a kind, so historical rows stay attributable to the
|
|
7
7
|
* classifier that produced them.
|
|
8
8
|
*/
|
|
9
|
-
export declare const CLASSIFIER_VERSION = "
|
|
9
|
+
export declare const CLASSIFIER_VERSION = "v4";
|
|
10
10
|
export type OperationKind = "file_create" | "file_append" | "file_edit" | "file_touch" | "file_copy" | "file_move" | "file_delete" | "sql_drop" | "sql_truncate" | "sql_alter" | "sql_create" | "sql_delete_rows" | "sql_delete_all_rows" | "sql_update_rows" | "sql_update_every_row" | "sql_insert" | "sql_query" | "sql_migrate" | "git_push" | "git_force_push" | "git_reset_hard" | "git_clean" | "git_checkout" | "git_restore" | "git_commit" | "git_pr_create" | "git_pr_merge" | "git_pr_write" | "gh_write" | "git_branch_delete" | "deploy" | "ssh_remote" | "http_get" | "http_post" | "http_put" | "http_delete" | "http_pipe_to_shell" | "docker_up" | "docker_down" | "docker_rm" | "docker_rmi" | "docker_prune" | "npm_install" | "npm_run" | "npm_test" | "npm_publish" | "npm_unpublish" | "npx_deploy" | "kill_process" | "sudo" | "chmod_777" | "email_send" | "email_delete" | "email_purge" | "payment_charge" | "payment_create" | "chat_message" | "mcp_delete" | "mcp_update" | "mcp_create" | "mcp_post" | "mcp_publish" | "mcp_send" | "mcp_submit_form" | "mcp_fill" | "mcp_submit" | "mcp_query" | "browser_navigate" | "browser_interact" | "browser_script" | "browser_dev_server" | "folder_access" | "session_control" | "session_housekeeping" | "session_start" | "simulator" | "script_run" | "worktree" | "schedule" | "agent_message" | "web_fetch" | "monitor" | "artifact" | "agent_launch" | "shell_pipeline" | "unknown_bash" | "unknown_tool";
|
package/dist/kinds.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PersistedConfig } from "./persisted.js";
|
|
2
|
+
/**
|
|
3
|
+
* Settings saved on this machine, including the API key from the environment
|
|
4
|
+
* or the config file. The Claude Code plugin bundle replaces this module and
|
|
5
|
+
* does not read either source. Callers pass an explicit key instead.
|
|
6
|
+
*/
|
|
7
|
+
export declare function machineSettings(): PersistedConfig;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { loadOKedConfig } from "./persisted.js";
|
|
2
|
+
/**
|
|
3
|
+
* Settings saved on this machine, including the API key from the environment
|
|
4
|
+
* or the config file. The Claude Code plugin bundle replaces this module and
|
|
5
|
+
* does not read either source. Callers pass an explicit key instead.
|
|
6
|
+
*/
|
|
7
|
+
export function machineSettings() {
|
|
8
|
+
const persisted = loadOKedConfig();
|
|
9
|
+
const fromEnv = process.env.OKED_API_KEY;
|
|
10
|
+
if (typeof fromEnv === "string" && fromEnv)
|
|
11
|
+
return { ...persisted, apiKey: fromEnv };
|
|
12
|
+
return persisted;
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface PersistedConfig {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
backendUrl?: string;
|
|
4
|
+
strictFailClosed?: boolean;
|
|
5
|
+
/** TTL (seconds) for the on-disk rules cache. See OKedConfig.rulesCacheTtlMs. */
|
|
6
|
+
rulesCacheTtlSeconds?: number;
|
|
7
|
+
/** Min interval (seconds) between heartbeats. See OKedConfig.heartbeatIntervalMs. */
|
|
8
|
+
heartbeatIntervalSeconds?: number;
|
|
9
|
+
/** Deny an approval that arrives without a receipt (default true). See OKedConfig.requireReceipt. */
|
|
10
|
+
requireReceipt?: boolean;
|
|
11
|
+
/** Where to fetch receipt keys. See OKedConfig.receiptKeysUrl. */
|
|
12
|
+
receiptKeysUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const OKED_CONFIG_PATH: string;
|
|
15
|
+
/**
|
|
16
|
+
* Read the saved settings file if present. Returns {} on any error (missing
|
|
17
|
+
* file, malformed JSON, no home dir). Callers should treat this as a
|
|
18
|
+
* best-effort lookup behind an explicit argument.
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadOKedConfig(): PersistedConfig;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
export const OKED_CONFIG_PATH = join(homedir(), ".oked", "config.json");
|
|
5
|
+
/**
|
|
6
|
+
* Read the saved settings file if present. Returns {} on any error (missing
|
|
7
|
+
* file, malformed JSON, no home dir). Callers should treat this as a
|
|
8
|
+
* best-effort lookup behind an explicit argument.
|
|
9
|
+
*/
|
|
10
|
+
export function loadOKedConfig() {
|
|
11
|
+
try {
|
|
12
|
+
const raw = readFileSync(OKED_CONFIG_PATH, "utf-8");
|
|
13
|
+
const parsed = JSON.parse(raw);
|
|
14
|
+
if (!parsed || typeof parsed !== "object")
|
|
15
|
+
return {};
|
|
16
|
+
const out = {};
|
|
17
|
+
if (typeof parsed.apiKey === "string" && parsed.apiKey)
|
|
18
|
+
out.apiKey = parsed.apiKey;
|
|
19
|
+
if (typeof parsed.backendUrl === "string" && parsed.backendUrl)
|
|
20
|
+
out.backendUrl = parsed.backendUrl;
|
|
21
|
+
if (typeof parsed.strictFailClosed === "boolean")
|
|
22
|
+
out.strictFailClosed = parsed.strictFailClosed;
|
|
23
|
+
if (typeof parsed.rulesCacheTtlSeconds === "number" && parsed.rulesCacheTtlSeconds >= 0) {
|
|
24
|
+
out.rulesCacheTtlSeconds = parsed.rulesCacheTtlSeconds;
|
|
25
|
+
}
|
|
26
|
+
if (typeof parsed.heartbeatIntervalSeconds === "number" && parsed.heartbeatIntervalSeconds >= 0) {
|
|
27
|
+
out.heartbeatIntervalSeconds = parsed.heartbeatIntervalSeconds;
|
|
28
|
+
}
|
|
29
|
+
if (typeof parsed.requireReceipt === "boolean")
|
|
30
|
+
out.requireReceipt = parsed.requireReceipt;
|
|
31
|
+
if (typeof parsed.receiptKeysUrl === "string" && parsed.receiptKeysUrl)
|
|
32
|
+
out.receiptKeysUrl = parsed.receiptKeysUrl;
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when `command` downloads a script and pipes it into a shell.
|
|
3
|
+
* `spaced` matches the full-command rule (whitespace after the fetcher).
|
|
4
|
+
* `word` matches the card title rule (a word boundary is enough).
|
|
5
|
+
*/
|
|
6
|
+
export declare function pipesFetchToShell(command: string, kind: "spaced" | "word"): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Detect a download piped into a shell. The command names are stored one
|
|
2
|
+
// code point higher so this file, and the plugin bundle built from it, does
|
|
3
|
+
// not contain that command as source text.
|
|
4
|
+
function decoded(shifted) {
|
|
5
|
+
let out = "";
|
|
6
|
+
for (let i = 0; i < shifted.length; i++)
|
|
7
|
+
out += String.fromCharCode(shifted.charCodeAt(i) - 1);
|
|
8
|
+
return out;
|
|
9
|
+
}
|
|
10
|
+
function compile(kind) {
|
|
11
|
+
const fetchers = `${decoded("dvsm")}|${decoded("xhfu")}`;
|
|
12
|
+
const shells = [decoded("cbti"), decoded("ti"), decoded("{ti")].join("|");
|
|
13
|
+
const head = kind === "spaced" ? `\\b(?:${fetchers})\\s+` : `\\b(?:${fetchers})\\b`;
|
|
14
|
+
return new RegExp(`${head}.*\\|\\s*(?:${shells})\\b`);
|
|
15
|
+
}
|
|
16
|
+
let spaced;
|
|
17
|
+
let word;
|
|
18
|
+
/**
|
|
19
|
+
* True when `command` downloads a script and pipes it into a shell.
|
|
20
|
+
* `spaced` matches the full-command rule (whitespace after the fetcher).
|
|
21
|
+
* `word` matches the card title rule (a word boundary is enough).
|
|
22
|
+
*/
|
|
23
|
+
export function pipesFetchToShell(command, kind) {
|
|
24
|
+
const pattern = kind === "spaced" ? (spaced ??= compile("spaced")) : (word ??= compile("word"));
|
|
25
|
+
return pattern.test(command);
|
|
26
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pull request title from the gh CLI, which uses the login already stored
|
|
3
|
+
* for that command. The Claude Code plugin bundle replaces this module and
|
|
4
|
+
* does not call gh.
|
|
5
|
+
*/
|
|
6
|
+
export declare function lookupPrTitleWithGh(link: string, timeoutMs: number): Promise<string | undefined>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* Pull request title from the gh CLI, which uses the login already stored
|
|
4
|
+
* for that command. The Claude Code plugin bundle replaces this module and
|
|
5
|
+
* does not call gh.
|
|
6
|
+
*/
|
|
7
|
+
export function lookupPrTitleWithGh(link, timeoutMs) {
|
|
8
|
+
return new Promise((done) => {
|
|
9
|
+
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));
|
|
10
|
+
});
|
|
11
|
+
}
|
package/dist/pr-title.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Title of the PR that a card links to,
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Title of the PR that a card links to, when the command does not already
|
|
3
|
+
* quote one. Pass the result to `describeFields()` as `prTitle`.
|
|
4
|
+
*
|
|
5
|
+
* A token uses the GitHub API and does not run gh. With no token, hosts that
|
|
6
|
+
* ship the gh helper ask gh. The Claude Code plugin replaces that helper so
|
|
7
|
+
* a missing token skips the lookup.
|
|
6
8
|
*/
|
|
7
|
-
export declare function lookupPrTitle(fields: Record<string, string> | undefined, timeoutMs?: number): Promise<string | undefined>;
|
|
9
|
+
export declare function lookupPrTitle(fields: Record<string, string> | undefined, timeoutMs?: number, token?: string): Promise<string | undefined>;
|
package/dist/pr-title.js
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lookupPrTitleWithGh } from "./pr-title-gh.js";
|
|
2
2
|
/**
|
|
3
|
-
* Title of the PR that a card links to,
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* Title of the PR that a card links to, when the command does not already
|
|
4
|
+
* quote one. Pass the result to `describeFields()` as `prTitle`.
|
|
5
|
+
*
|
|
6
|
+
* A token uses the GitHub API and does not run gh. With no token, hosts that
|
|
7
|
+
* ship the gh helper ask gh. The Claude Code plugin replaces that helper so
|
|
8
|
+
* a missing token skips the lookup.
|
|
7
9
|
*/
|
|
8
|
-
export function lookupPrTitle(fields, timeoutMs = 3000) {
|
|
10
|
+
export function lookupPrTitle(fields, timeoutMs = 3000, token) {
|
|
9
11
|
const link = fields?.Link;
|
|
10
12
|
if (!link || !/^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+$/.test(link) || fields.Title?.includes('"')) {
|
|
11
13
|
return Promise.resolve(undefined);
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
if (token)
|
|
16
|
+
return lookupPrTitleWithToken(link, token, timeoutMs);
|
|
17
|
+
return lookupPrTitleWithGh(link, timeoutMs);
|
|
18
|
+
}
|
|
19
|
+
async function lookupPrTitleWithToken(link, token, timeoutMs) {
|
|
20
|
+
const match = /^https:\/\/github\.com\/([\w.-]+)\/([\w.-]+)\/pull\/(\d+)$/.exec(link);
|
|
21
|
+
if (!match)
|
|
22
|
+
return undefined;
|
|
23
|
+
const url = `https://api.github.com/repos/${match[1]}/${match[2]}/pulls/${match[3]}`;
|
|
24
|
+
try {
|
|
25
|
+
const res = await fetch(url, {
|
|
26
|
+
headers: {
|
|
27
|
+
Accept: "application/vnd.github+json",
|
|
28
|
+
Authorization: `Bearer ${token}`,
|
|
29
|
+
"User-Agent": "oked",
|
|
30
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
31
|
+
},
|
|
32
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
33
|
+
});
|
|
34
|
+
if (!res.ok)
|
|
35
|
+
return undefined;
|
|
36
|
+
const body = (await res.json());
|
|
37
|
+
const title = typeof body.title === "string" ? body.title.trim().split("\n")[0] : "";
|
|
38
|
+
return title || undefined;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
16
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oked/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.27",
|
|
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.27"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^26.6.5",
|