@oked/sdk 0.3.5 → 0.4.0
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 +1 -1
- package/dist/classify.d.ts +8 -0
- package/dist/classify.js +184 -15
- package/dist/describe.js +96 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -1
- package/dist/kinds.d.ts +1 -1
- package/dist/types.d.ts +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ Pass to `new OKedClient(config)`:
|
|
|
44
44
|
|---|---|---|---|
|
|
45
45
|
| `apiKey` | `string` | `OKED_API_KEY` env | Your OKed API key. Required. |
|
|
46
46
|
| `backendUrl` | `string` | `https://api.oked.ai` | Override the OKed backend URL. |
|
|
47
|
-
| `timeout` | `number` | `
|
|
47
|
+
| `timeout` | `number` | `600000` | Per-approval timeout in ms (10 minutes). If you raise it, raise the harness hook timeout to match: it must stay above this value so the fail-safe deny is written before the hook process is killed. |
|
|
48
48
|
| `strictFailClosed` | `boolean` | `false` | When true, backend outages deny every tier. When false, outages deny only `high_stakes` and allow lower tiers. |
|
|
49
49
|
|
|
50
50
|
## API
|
package/dist/classify.d.ts
CHANGED
|
@@ -19,4 +19,12 @@ export interface ShellWriteOp {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function stripHeredocBodies(command: string): string;
|
|
21
21
|
export declare function stripInlineScriptBodies(command: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Blank the interior of quoted curl request bodies, keeping the quotes and the
|
|
24
|
+
* flag so the per-stage curl rules still see a POST. A JSON payload that
|
|
25
|
+
* mentions `git push --force` or `rm -rf` is data, and must not trip the
|
|
26
|
+
* full-command high-stakes scan. Only applies inside a curl stage (from `curl`
|
|
27
|
+
* to the next unquoted `;`, `|`, `&` or newline).
|
|
28
|
+
*/
|
|
29
|
+
export declare function stripCurlDataBodies(command: string): string;
|
|
22
30
|
export declare function extractShellWriteOps(command: string): ShellWriteOp[];
|
package/dist/classify.js
CHANGED
|
@@ -225,6 +225,34 @@ function isEphemeralPath(filePath) {
|
|
|
225
225
|
return false;
|
|
226
226
|
return TEMP_VAR_RE.test(filePath) || EPHEMERAL_PATH_RE.test(filePath);
|
|
227
227
|
}
|
|
228
|
+
// A shell variable assigned from `mktemp` / `mktemp -d` (optionally `export`ed)
|
|
229
|
+
// at the start of a stage: `EMPTYHOME=$(mktemp -d)`, `T=`mktemp``. Its value is a
|
|
230
|
+
// throwaway temp path the shell just created, so a same-command `rm -rf "$T"`
|
|
231
|
+
// that deletes it is the ephemeral-temp case, not a real-data wipe. These names
|
|
232
|
+
// are gathered across every stage of a compound command BEFORE any stage is
|
|
233
|
+
// classified (see classifyBashCommand), so a delete in a later stage can see a
|
|
234
|
+
// binding declared in an earlier one. Safe because the whole binding is visible
|
|
235
|
+
// in this single inspected command string — no environment-resolution guess.
|
|
236
|
+
const MKTEMP_ASSIGN_RE = /^(?:export\s+|declare\s+|local\s+|readonly\s+)?(\w+)=["']?(?:\$\(|`)\s*mktemp\b/;
|
|
237
|
+
function collectMktempVars(stage, into) {
|
|
238
|
+
const m = stage.match(MKTEMP_ASSIGN_RE);
|
|
239
|
+
if (m)
|
|
240
|
+
into.add(m[1]);
|
|
241
|
+
}
|
|
242
|
+
// True when `target` is a reference (`$VAR`, `${VAR}`, optionally with a trailing
|
|
243
|
+
// subpath like `$VAR/cache`) to a variable known to hold an mktemp temp dir. A
|
|
244
|
+
// subpath that climbs out with `..` could escape the temp tree, so it does NOT
|
|
245
|
+
// qualify — that stays a real deletion.
|
|
246
|
+
function isEphemeralVar(target, vars) {
|
|
247
|
+
if (vars.size === 0)
|
|
248
|
+
return false;
|
|
249
|
+
const m = target.match(/^\$\{?(\w+)\}?(\/.*)?$/);
|
|
250
|
+
if (!m || !vars.has(m[1]))
|
|
251
|
+
return false;
|
|
252
|
+
if (m[2] && m[2].split("/").includes(".."))
|
|
253
|
+
return false;
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
228
256
|
// Paths where a write/edit is genuinely dangerous and must stay `review`:
|
|
229
257
|
// system directories, credential/secret stores, shell startup files (a
|
|
230
258
|
// persistence vector), and OKed's own config (so an agent can't disable its
|
|
@@ -310,7 +338,7 @@ export function classify(toolName, toolInput) {
|
|
|
310
338
|
}
|
|
311
339
|
// MCP tools: mcp__<server>__<tool>
|
|
312
340
|
if (toolName.startsWith("mcp__")) {
|
|
313
|
-
return classifyMcpTool(toolName);
|
|
341
|
+
return classifyMcpTool(toolName, toolInput);
|
|
314
342
|
}
|
|
315
343
|
// Shell-exec-style tools from other agents (Codex CLI's `exec`, OpenClaw,
|
|
316
344
|
// generic `run`/`run_command`/`shell`). Detect by signature: a string
|
|
@@ -439,18 +467,22 @@ function splitTopLevel(cmd) {
|
|
|
439
467
|
return out.filter(Boolean);
|
|
440
468
|
}
|
|
441
469
|
// rm/rmdir/trash whose every target is an ephemeral temp path (/tmp, %TEMP%,
|
|
442
|
-
// …)
|
|
443
|
-
//
|
|
444
|
-
//
|
|
445
|
-
//
|
|
446
|
-
|
|
470
|
+
// …) or a variable bound to one by `mktemp` earlier in the same command
|
|
471
|
+
// (`ephemeralVars`, e.g. `EMPTYHOME=$(mktemp -d); rm -rf "$EMPTYHOME"`).
|
|
472
|
+
// Deleting throwaway temp files is low-risk, so it downgrades to warning. Any
|
|
473
|
+
// non-temp target (or deleting a temp ROOT like `/tmp` itself, which isn't an
|
|
474
|
+
// ephemeral *path*) means this returns false and the deletion stays high_stakes.
|
|
475
|
+
function isEphemeralOnlyDeletion(command, ephemeralVars = new Set()) {
|
|
447
476
|
const m = command.match(/^(?:sudo\s+)?(?:rm|rmdir|trash|trash-put)\b\s+(.+)$/s);
|
|
448
477
|
if (!m)
|
|
449
478
|
return false;
|
|
450
479
|
const targets = splitArgs(m[1]).filter((a) => !a.startsWith("-"));
|
|
451
480
|
if (targets.length === 0)
|
|
452
481
|
return false;
|
|
453
|
-
return targets.every((a) =>
|
|
482
|
+
return targets.every((a) => {
|
|
483
|
+
const t = unquote(a);
|
|
484
|
+
return isEphemeralPath(t) || isEphemeralVar(t, ephemeralVars);
|
|
485
|
+
});
|
|
454
486
|
}
|
|
455
487
|
/**
|
|
456
488
|
* Classifies a single stage that begins with one or more `NAME=value`
|
|
@@ -701,7 +733,7 @@ function isLoopbackHttpStage(stage) {
|
|
|
701
733
|
return false;
|
|
702
734
|
return /(?:^|[\s@])(?:localhost|127(?:\.\d{1,3}){3}|0\.0\.0\.0|\[::1\])(?::\d+)?(?:[/\s'"]|$)/i.test(stage);
|
|
703
735
|
}
|
|
704
|
-
function classifyBashCommand(command) {
|
|
736
|
+
function classifyBashCommand(command, ephemeralVars = new Set()) {
|
|
705
737
|
if (!command)
|
|
706
738
|
return "safe";
|
|
707
739
|
// Two views of the command:
|
|
@@ -712,11 +744,12 @@ function classifyBashCommand(command) {
|
|
|
712
744
|
// SHELL-pattern scan, so a shell token embedded as code/data in
|
|
713
745
|
// an interpreter body (`rm`, `curl -d`, a `>` redirect — e.g. a
|
|
714
746
|
// reddit post fed to `node -e '…samples…'`) does not trip a
|
|
715
|
-
// destructive/outward rule.
|
|
747
|
+
// destructive/outward rule. Quoted curl request bodies (`-d
|
|
748
|
+
// '{"command":"git push --force"}'`) are blanked the same way. (SQL keywords in that data can still
|
|
716
749
|
// surface via `intact` — that is the accepted shell-only-opacity
|
|
717
750
|
// trade-off; see classifyStageShellEffects.)
|
|
718
751
|
const intact = stripHeredocBodies(command).trim();
|
|
719
|
-
const stripped = stripInlineScriptBodies(intact).trim();
|
|
752
|
+
const stripped = stripCurlDataBodies(stripInlineScriptBodies(intact)).trim();
|
|
720
753
|
// High-stakes scan on the FULL (body-stripped) command, before any splitting.
|
|
721
754
|
// These patterns use \b and several intentionally span an operator (e.g.
|
|
722
755
|
// `curl … | bash`, `wget … | sh` — download-and-execute), so they have to be
|
|
@@ -735,7 +768,14 @@ function classifyBashCommand(command) {
|
|
|
735
768
|
// body aren't split points either way — so stage boundaries are identical.)
|
|
736
769
|
const stages = splitTopLevel(intact);
|
|
737
770
|
if (stages.length > 1) {
|
|
738
|
-
|
|
771
|
+
// Gather temp-dir variables (`VAR=$(mktemp -d)`) declared anywhere in this
|
|
772
|
+
// compound command BEFORE classifying any stage, so a later `rm -rf "$VAR"`
|
|
773
|
+
// stage recognizes its target as throwaway even though the binding lives in
|
|
774
|
+
// an earlier stage. Inherits any vars passed from an enclosing command.
|
|
775
|
+
const vars = new Set(ephemeralVars);
|
|
776
|
+
for (const stage of stages)
|
|
777
|
+
collectMktempVars(stage, vars);
|
|
778
|
+
return stages.reduce((worst, stage) => maxTier(worst, classifyBashCommand(stage, vars)), "safe");
|
|
739
779
|
}
|
|
740
780
|
// ---- single stage from here ----
|
|
741
781
|
// SQL severity from the body-INTACT view: an interpreter wrapper (python -c,
|
|
@@ -744,20 +784,20 @@ function classifyBashCommand(command) {
|
|
|
744
784
|
// shell pass short-circuits to `safe` (e.g. an assignment-prefixed node -e).
|
|
745
785
|
const sql = findSqlInCommand(intact);
|
|
746
786
|
const sqlTier = sql ? classifySqlSeverity(sql) : "safe";
|
|
747
|
-
return maxTier(sqlTier, classifyStageShellEffects(stripped));
|
|
787
|
+
return maxTier(sqlTier, classifyStageShellEffects(stripped, ephemeralVars));
|
|
748
788
|
}
|
|
749
789
|
/**
|
|
750
790
|
* Shell-effect classification of a SINGLE, already-body-stripped stage. No SQL
|
|
751
791
|
* detection here — that runs on the body-intact view in classifyBashCommand and
|
|
752
792
|
* is folded in by the caller. Returns the stage's tier (default `safe`).
|
|
753
793
|
*/
|
|
754
|
-
function classifyStageShellEffects(stage) {
|
|
794
|
+
function classifyStageShellEffects(stage, ephemeralVars = new Set()) {
|
|
755
795
|
// File deletion in COMMAND POSITION, per-stage so the ephemeral-temp carve-out
|
|
756
796
|
// can win: deleting only throwaway temp files (/tmp, $TMPDIR, /var/folders, …)
|
|
757
797
|
// → warning; any non-temp target (or the temp root itself) → high_stakes.
|
|
758
798
|
// A delete word sitting in an argument (filename, branch name, echo text) is
|
|
759
799
|
// NOT a deletion — that's the false positive DELETE_COMMAND_RE avoids.
|
|
760
|
-
if (isEphemeralOnlyDeletion(stage))
|
|
800
|
+
if (isEphemeralOnlyDeletion(stage, ephemeralVars))
|
|
761
801
|
return "warning";
|
|
762
802
|
if (DELETE_COMMAND_RE.test(stage.replace(DELETE_LEAD, "")))
|
|
763
803
|
return "high_stakes";
|
|
@@ -959,6 +999,60 @@ export function stripInlineScriptBodies(command) {
|
|
|
959
999
|
out += command.slice(last);
|
|
960
1000
|
return out;
|
|
961
1001
|
}
|
|
1002
|
+
// curl request-body flags whose quoted value is payload sent to a server,
|
|
1003
|
+
// never run locally.
|
|
1004
|
+
const CURL_DATA_FLAG_RE = /^(?:-d|--data(?:-raw|-binary|-urlencode|-ascii)?|--json|-F|--form)(?:\s+|=)(['"])/;
|
|
1005
|
+
/**
|
|
1006
|
+
* Blank the interior of quoted curl request bodies, keeping the quotes and the
|
|
1007
|
+
* flag so the per-stage curl rules still see a POST. A JSON payload that
|
|
1008
|
+
* mentions `git push --force` or `rm -rf` is data, and must not trip the
|
|
1009
|
+
* full-command high-stakes scan. Only applies inside a curl stage (from `curl`
|
|
1010
|
+
* to the next unquoted `;`, `|`, `&` or newline).
|
|
1011
|
+
*/
|
|
1012
|
+
export function stripCurlDataBodies(command) {
|
|
1013
|
+
let out = "";
|
|
1014
|
+
let inCurl = false;
|
|
1015
|
+
let i = 0;
|
|
1016
|
+
while (i < command.length) {
|
|
1017
|
+
const ch = command[i];
|
|
1018
|
+
if (ch === "'" || ch === '"') {
|
|
1019
|
+
// Copy a quoted span verbatim (it isn't a body we're blanking).
|
|
1020
|
+
let j = i + 1;
|
|
1021
|
+
while (j < command.length && command[j] !== ch) {
|
|
1022
|
+
if (ch === '"' && command[j] === "\\")
|
|
1023
|
+
j++;
|
|
1024
|
+
j++;
|
|
1025
|
+
}
|
|
1026
|
+
out += command.slice(i, j + 1);
|
|
1027
|
+
i = j + 1;
|
|
1028
|
+
continue;
|
|
1029
|
+
}
|
|
1030
|
+
if (/[;|&\n]/.test(ch))
|
|
1031
|
+
inCurl = false;
|
|
1032
|
+
else if (!inCurl && /^curl\b/.test(command.slice(i)) && (i === 0 || /[\s(;|&]/.test(command[i - 1]))) {
|
|
1033
|
+
inCurl = true;
|
|
1034
|
+
}
|
|
1035
|
+
else if (inCurl && /\s/.test(ch)) {
|
|
1036
|
+
const m = command.slice(i + 1).match(CURL_DATA_FLAG_RE);
|
|
1037
|
+
if (m) {
|
|
1038
|
+
const quote = m[1];
|
|
1039
|
+
const bodyStart = i + 1 + m[0].length;
|
|
1040
|
+
let j = bodyStart;
|
|
1041
|
+
while (j < command.length && command[j] !== quote) {
|
|
1042
|
+
if (quote === '"' && command[j] === "\\")
|
|
1043
|
+
j++;
|
|
1044
|
+
j++;
|
|
1045
|
+
}
|
|
1046
|
+
out += command.slice(i, bodyStart) + quote;
|
|
1047
|
+
i = j + 1;
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
out += ch;
|
|
1052
|
+
i++;
|
|
1053
|
+
}
|
|
1054
|
+
return out;
|
|
1055
|
+
}
|
|
962
1056
|
/** Find output redirects (`>`, `>>`, `&>`, `2>`, …) outside quoted strings.
|
|
963
1057
|
* The target token may itself be quoted. Skips `2>&1`-style FD dups, bare
|
|
964
1058
|
* digits, and /dev/null. Heredoc `<<` is ignored (only `>` is a write). */
|
|
@@ -1120,9 +1214,84 @@ function splitArgs(s) {
|
|
|
1120
1214
|
out.push(cur);
|
|
1121
1215
|
return out;
|
|
1122
1216
|
}
|
|
1123
|
-
|
|
1217
|
+
// Browser MCP servers: the desktop app's built-in browser pane (also reached
|
|
1218
|
+
// as mcp__remote-devices__Claude_Browser__* from cloud sessions) and the
|
|
1219
|
+
// Claude in Chrome extension. Their tool names don't follow the verb-prefix
|
|
1220
|
+
// convention below, so they get an explicit table keyed on the tool name.
|
|
1221
|
+
const BROWSER_MCP_SERVERS = new Set(["Claude_Browser", "claude-in-chrome"]);
|
|
1222
|
+
// Browser tools that only look at, open, or arrange pages (no clicks, typing,
|
|
1223
|
+
// form fills, script execution, or uploads). Navigation is a read, like
|
|
1224
|
+
// WebSearch. Anything not listed here falls through to `review`.
|
|
1225
|
+
const SAFE_BROWSER_TOOLS = new Set([
|
|
1226
|
+
"navigate",
|
|
1227
|
+
"find",
|
|
1228
|
+
"read_page",
|
|
1229
|
+
"get_page_text",
|
|
1230
|
+
"read_console_messages",
|
|
1231
|
+
"read_network_requests",
|
|
1232
|
+
"tabs_context",
|
|
1233
|
+
"tabs_context_mcp",
|
|
1234
|
+
"tabs_create",
|
|
1235
|
+
"tabs_create_mcp",
|
|
1236
|
+
"tabs_select",
|
|
1237
|
+
"tabs_close",
|
|
1238
|
+
"tabs_close_mcp",
|
|
1239
|
+
"resize_window",
|
|
1240
|
+
"preview_list",
|
|
1241
|
+
"preview_logs",
|
|
1242
|
+
"preview_stop",
|
|
1243
|
+
"gif_creator",
|
|
1244
|
+
"shortcuts_list",
|
|
1245
|
+
"list_connected_browsers",
|
|
1246
|
+
"select_browser",
|
|
1247
|
+
"switch_browser",
|
|
1248
|
+
]);
|
|
1249
|
+
// `computer` actions that only observe or move the viewport.
|
|
1250
|
+
const SAFE_COMPUTER_ACTIONS = new Set(["screenshot", "zoom", "scroll", "scroll_to", "hover", "wait"]);
|
|
1251
|
+
// Page interactions (clicks, typing, form fills, in-page JS). In the desktop
|
|
1252
|
+
// app's built-in browser pane these act in an isolated browser, mostly against
|
|
1253
|
+
// the user's own dev servers, so they're logged (`warning`) rather than
|
|
1254
|
+
// prompted: a prompt per click is pure approval fatigue. In Claude in Chrome
|
|
1255
|
+
// they act inside the user's real logged-in sessions (mail, banking, …), so
|
|
1256
|
+
// they stay `review`.
|
|
1257
|
+
const BROWSER_INTERACTION_TOOLS = new Set(["computer", "form_input", "javascript_tool"]);
|
|
1258
|
+
function classifyBrowserTool(tool, toolInput, server) {
|
|
1259
|
+
if (SAFE_BROWSER_TOOLS.has(tool))
|
|
1260
|
+
return "safe";
|
|
1261
|
+
// preview_start with `url` just opens a tab. With `name` it launches the
|
|
1262
|
+
// dev-server command from .claude/launch.json, which is arbitrary command
|
|
1263
|
+
// execution, so it stays `review`.
|
|
1264
|
+
if (tool === "preview_start") {
|
|
1265
|
+
return typeof toolInput.url === "string" && toolInput.name === undefined ? "safe" : "review";
|
|
1266
|
+
}
|
|
1267
|
+
if (tool === "computer" && SAFE_COMPUTER_ACTIONS.has(toolInput.action))
|
|
1268
|
+
return "safe";
|
|
1269
|
+
if (BROWSER_INTERACTION_TOOLS.has(tool)) {
|
|
1270
|
+
return server === "claude-in-chrome" ? "review" : "warning";
|
|
1271
|
+
}
|
|
1272
|
+
// A batch is as risky as its riskiest step.
|
|
1273
|
+
if (tool === "browser_batch") {
|
|
1274
|
+
const actions = toolInput.actions;
|
|
1275
|
+
if (!Array.isArray(actions) || actions.length === 0)
|
|
1276
|
+
return "review";
|
|
1277
|
+
let tier = "safe";
|
|
1278
|
+
for (const a of actions) {
|
|
1279
|
+
const name = a?.name;
|
|
1280
|
+
const input = a?.input;
|
|
1281
|
+
if (typeof name !== "string" || name === "browser_batch")
|
|
1282
|
+
return "review";
|
|
1283
|
+
tier = maxTier(tier, classifyBrowserTool(name, (input && typeof input === "object" ? input : {}), server));
|
|
1284
|
+
}
|
|
1285
|
+
return tier;
|
|
1286
|
+
}
|
|
1287
|
+
return "review";
|
|
1288
|
+
}
|
|
1289
|
+
function classifyMcpTool(toolName, toolInput = {}) {
|
|
1124
1290
|
const parts = toolName.split("__");
|
|
1125
1291
|
const tool = parts[parts.length - 1] || "";
|
|
1292
|
+
const browserServer = parts.slice(1, -1).find((p) => BROWSER_MCP_SERVERS.has(p));
|
|
1293
|
+
if (browserServer)
|
|
1294
|
+
return classifyBrowserTool(tool, toolInput, browserServer);
|
|
1126
1295
|
// Read-only retrieval verbs.
|
|
1127
1296
|
if (tool.startsWith("list_") || tool.startsWith("get_") || tool.startsWith("search_") ||
|
|
1128
1297
|
tool.startsWith("read_") || tool.startsWith("fetch_") || tool.startsWith("query_") ||
|
package/dist/describe.js
CHANGED
|
@@ -102,12 +102,39 @@ function summarizeMutatingCurl(cmd) {
|
|
|
102
102
|
const url = cmd.match(/https?:\/\/[^\s'"]+/)?.[0] || "";
|
|
103
103
|
const host = url ? extractHost(url) : "URL";
|
|
104
104
|
const kind = method === "DELETE" ? "http_delete" : method === "PUT" ? "http_put" : "http_post";
|
|
105
|
+
// The endpoint path and the payload say what the request does; the raw
|
|
106
|
+
// command's head is often just setup (`SP=/long/scratch/path; (curl …`) and
|
|
107
|
+
// eats the whole preview before reaching either.
|
|
108
|
+
const endpoint = url ? extractPath(url) : undefined;
|
|
109
|
+
const payload = extractCurlPayload(cmd);
|
|
105
110
|
return {
|
|
106
111
|
title: `${method} request to ${host}`,
|
|
107
|
-
|
|
112
|
+
target: endpoint,
|
|
113
|
+
body: payload !== undefined
|
|
114
|
+
? truncateBody(payload)
|
|
115
|
+
: cmd.length > COMMAND_INLINE_MAX ? truncateBody(cmd) : undefined,
|
|
108
116
|
kind,
|
|
109
117
|
};
|
|
110
118
|
}
|
|
119
|
+
/** Path (+ query) of a URL, or undefined for a bare origin. */
|
|
120
|
+
function extractPath(url) {
|
|
121
|
+
try {
|
|
122
|
+
const u = new URL(url);
|
|
123
|
+
const p = u.pathname + u.search;
|
|
124
|
+
return p && p !== "/" ? truncate(p, 80) : undefined;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** The value of the first curl request-body flag (-d, --data*, --json, -F, --form). */
|
|
131
|
+
function extractCurlPayload(cmd) {
|
|
132
|
+
const m = cmd.match(/\s(?:-d|--data(?:-raw|-binary|-urlencode|-ascii)?|--json|-F|--form)(?:\s+|=)(?:'([^']*)'|"((?:[^"\\]|\\.)*)"|([^\s'"|;&]+))/);
|
|
133
|
+
if (!m)
|
|
134
|
+
return undefined;
|
|
135
|
+
const v = m[1] ?? m[2] ?? m[3];
|
|
136
|
+
return v ? v : undefined;
|
|
137
|
+
}
|
|
111
138
|
function summarizeBash(command, sizeBytes) {
|
|
112
139
|
const cmd = (command || "").trim();
|
|
113
140
|
if (!cmd)
|
|
@@ -629,10 +656,78 @@ function summarizeAgent(input) {
|
|
|
629
656
|
const short = truncate(prompt, 80);
|
|
630
657
|
return { title: "Launch sub-agent", body: short, kind: "agent_launch" };
|
|
631
658
|
}
|
|
659
|
+
/**
|
|
660
|
+
* Built-in browser pane / Claude in Chrome. The tool names (`computer`,
|
|
661
|
+
* `javascript_tool`, …) say nothing on their own, so lead with what the step
|
|
662
|
+
* does and use the agent's own `action_summary` as the target when present.
|
|
663
|
+
*/
|
|
664
|
+
function summarizeBrowser(tool, input, server) {
|
|
665
|
+
const where = server === "claude-in-chrome" ? "in Chrome" : "in browser";
|
|
666
|
+
const str = (v) => (typeof v === "string" && v.trim() ? v.trim() : undefined);
|
|
667
|
+
const summary = str(input.action_summary);
|
|
668
|
+
switch (tool) {
|
|
669
|
+
case "navigate": {
|
|
670
|
+
const url = str(input.url);
|
|
671
|
+
return { title: `Open page ${where}`, target: url ? truncate(url, 80) : undefined, kind: "browser_navigate" };
|
|
672
|
+
}
|
|
673
|
+
case "preview_start": {
|
|
674
|
+
const url = str(input.url);
|
|
675
|
+
if (url)
|
|
676
|
+
return { title: `Open page ${where}`, target: truncate(url, 80), kind: "browser_navigate" };
|
|
677
|
+
const name = str(input.name);
|
|
678
|
+
return {
|
|
679
|
+
title: name ? `Start dev server "${truncate(name, 40)}"` : "Start dev server",
|
|
680
|
+
footnote: "Runs the command configured in .claude/launch.json",
|
|
681
|
+
kind: "browser_dev_server",
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
case "computer": {
|
|
685
|
+
const action = str(input.action) || "action";
|
|
686
|
+
const text = str(input.text);
|
|
687
|
+
return {
|
|
688
|
+
title: `${action.replace(/_/g, " ")} ${where}`.replace(/^./, (c) => c.toUpperCase()),
|
|
689
|
+
target: summary,
|
|
690
|
+
body: text ? truncateBody(text) : undefined,
|
|
691
|
+
kind: "browser_interact",
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
case "form_input": {
|
|
695
|
+
const value = input.value;
|
|
696
|
+
return {
|
|
697
|
+
title: `Fill form field ${where}`,
|
|
698
|
+
target: summary,
|
|
699
|
+
body: value !== undefined ? truncateBody(String(value)) : undefined,
|
|
700
|
+
kind: "browser_interact",
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
case "javascript_tool": {
|
|
704
|
+
const code = str(input.text);
|
|
705
|
+
return { title: `Run JavaScript ${where}`, body: code ? truncateBody(code) : undefined, kind: "browser_script" };
|
|
706
|
+
}
|
|
707
|
+
case "browser_batch": {
|
|
708
|
+
const actions = Array.isArray(input.actions) ? input.actions : [];
|
|
709
|
+
const steps = actions.map((a) => {
|
|
710
|
+
const name = str(a?.name) || "step";
|
|
711
|
+
const inp = (a?.input ?? {});
|
|
712
|
+
const r = summarizeBrowser(name, inp, server);
|
|
713
|
+
return r.target ? `${r.title}: ${r.target}` : r.title;
|
|
714
|
+
});
|
|
715
|
+
return {
|
|
716
|
+
title: `Run ${actions.length} browser step${actions.length === 1 ? "" : "s"}`,
|
|
717
|
+
body: steps.length ? truncateBody(steps.join("\n")) : undefined,
|
|
718
|
+
kind: "browser_interact",
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return { title: `${tool.replace(/_/g, " ")} ${where}`.replace(/^./, (c) => c.toUpperCase()), target: summary, kind: "unknown_tool" };
|
|
723
|
+
}
|
|
632
724
|
function summarizeMcp(toolName, input) {
|
|
633
725
|
const parts = toolName.split("__");
|
|
634
726
|
const server = parts[1] || "unknown";
|
|
635
727
|
const tool = parts[2] || "";
|
|
728
|
+
const browser = parts.slice(1, -1).find((p) => p === "Claude_Browser" || p === "claude-in-chrome");
|
|
729
|
+
if (browser)
|
|
730
|
+
return summarizeBrowser(parts[parts.length - 1] || "", input, browser);
|
|
636
731
|
if (tool === "send_email")
|
|
637
732
|
return summarizeEmail(input);
|
|
638
733
|
if (tool === "send_message")
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { ApprovalRequest, ApprovalResponse, OKedConfig } from "./types.js";
|
|
2
2
|
import type { Rule } from "./rules.js";
|
|
3
|
+
/**
|
|
4
|
+
* How long we wait for a human decision before giving up on the request.
|
|
5
|
+
*
|
|
6
|
+
* Sized for a human who has to be woken up (an oncall paged at 3am), not for a
|
|
7
|
+
* developer watching the terminal. Integrations that run under a harness which
|
|
8
|
+
* kills the hook process must set their own limit ABOVE this one, so our
|
|
9
|
+
* fail-safe deny is written before the harness pulls the plug. See
|
|
10
|
+
* HOOK_TIMEOUT_SECONDS in @oked/claude-code.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_APPROVAL_TIMEOUT_MS = 600000;
|
|
3
13
|
export declare class OKedClient {
|
|
4
14
|
private config;
|
|
5
15
|
constructor(config?: Partial<OKedConfig>);
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,16 @@ import { dirname } from "path";
|
|
|
3
3
|
import { loadOKedConfig, OKED_RULES_CACHE_PATH, OKED_HEARTBEAT_PATH } from "./config.js";
|
|
4
4
|
import { OKedAuthError, OKedBackendUnreachableError } from "./errors.js";
|
|
5
5
|
import { hostname } from "os";
|
|
6
|
+
/**
|
|
7
|
+
* How long we wait for a human decision before giving up on the request.
|
|
8
|
+
*
|
|
9
|
+
* Sized for a human who has to be woken up (an oncall paged at 3am), not for a
|
|
10
|
+
* developer watching the terminal. Integrations that run under a harness which
|
|
11
|
+
* kills the hook process must set their own limit ABOVE this one, so our
|
|
12
|
+
* fail-safe deny is written before the harness pulls the plug. See
|
|
13
|
+
* HOOK_TIMEOUT_SECONDS in @oked/claude-code.
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_APPROVAL_TIMEOUT_MS = 600_000;
|
|
6
16
|
function envStrictFailClosed() {
|
|
7
17
|
const raw = process.env.OKED_STRICT_FAIL_CLOSED;
|
|
8
18
|
if (raw === undefined)
|
|
@@ -78,7 +88,7 @@ export class OKedClient {
|
|
|
78
88
|
process.env.OKED_BACKEND_URL ||
|
|
79
89
|
persisted.backendUrl ||
|
|
80
90
|
"https://api.oked.ai",
|
|
81
|
-
timeout: config?.timeout ||
|
|
91
|
+
timeout: config?.timeout || DEFAULT_APPROVAL_TIMEOUT_MS,
|
|
82
92
|
// Precedence: constructor > env > ~/.oked/config.json > default false.
|
|
83
93
|
strictFailClosed: config?.strictFailClosed ??
|
|
84
94
|
envStrictFailClosed() ??
|
package/dist/kinds.d.ts
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* classifier that produced them.
|
|
8
8
|
*/
|
|
9
9
|
export declare const CLASSIFIER_VERSION = "v2";
|
|
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" | "git_push" | "git_force_push" | "git_reset_hard" | "git_clean" | "git_checkout" | "git_restore" | "git_commit" | "git_pr_create" | "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" | "agent_launch" | "shell_pipeline" | "unknown_bash" | "unknown_tool";
|
|
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" | "git_push" | "git_force_push" | "git_reset_hard" | "git_clean" | "git_checkout" | "git_restore" | "git_commit" | "git_pr_create" | "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" | "agent_launch" | "shell_pipeline" | "unknown_bash" | "unknown_tool";
|
package/dist/types.d.ts
CHANGED
|
@@ -16,6 +16,17 @@ export interface ApprovalResponse {
|
|
|
16
16
|
export interface OKedConfig {
|
|
17
17
|
apiKey: string;
|
|
18
18
|
backendUrl: string;
|
|
19
|
+
/**
|
|
20
|
+
* How long to wait for a human decision, in ms. Default 600_000 (10 min);
|
|
21
|
+
* see DEFAULT_APPROVAL_TIMEOUT_MS.
|
|
22
|
+
*
|
|
23
|
+
* Three timers nest around one approval: the backend's own expiry (which
|
|
24
|
+
* returns `decision: "timeout"`), this client-side abort, and - under a
|
|
25
|
+
* harness that kills the hook process - the harness limit. They must stay
|
|
26
|
+
* ordered backend < this < harness. Raise this and the harness limit has to
|
|
27
|
+
* move with it, or the process is killed before the fail-safe deny is
|
|
28
|
+
* written and the gate falls open instead of denying.
|
|
29
|
+
*/
|
|
19
30
|
timeout: number;
|
|
20
31
|
/**
|
|
21
32
|
* When true, an unreachable backend hard-denies every sensitive action
|