@oked/sdk 0.3.6 → 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 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` | `300000` | Per-approval timeout in ms. |
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
@@ -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
@@ -338,7 +338,7 @@ export function classify(toolName, toolInput) {
338
338
  }
339
339
  // MCP tools: mcp__<server>__<tool>
340
340
  if (toolName.startsWith("mcp__")) {
341
- return classifyMcpTool(toolName);
341
+ return classifyMcpTool(toolName, toolInput);
342
342
  }
343
343
  // Shell-exec-style tools from other agents (Codex CLI's `exec`, OpenClaw,
344
344
  // generic `run`/`run_command`/`shell`). Detect by signature: a string
@@ -744,11 +744,12 @@ function classifyBashCommand(command, ephemeralVars = new Set()) {
744
744
  // SHELL-pattern scan, so a shell token embedded as code/data in
745
745
  // an interpreter body (`rm`, `curl -d`, a `>` redirect — e.g. a
746
746
  // reddit post fed to `node -e '…samples…'`) does not trip a
747
- // destructive/outward rule. (SQL keywords in that data can still
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
748
749
  // surface via `intact` — that is the accepted shell-only-opacity
749
750
  // trade-off; see classifyStageShellEffects.)
750
751
  const intact = stripHeredocBodies(command).trim();
751
- const stripped = stripInlineScriptBodies(intact).trim();
752
+ const stripped = stripCurlDataBodies(stripInlineScriptBodies(intact)).trim();
752
753
  // High-stakes scan on the FULL (body-stripped) command, before any splitting.
753
754
  // These patterns use \b and several intentionally span an operator (e.g.
754
755
  // `curl … | bash`, `wget … | sh` — download-and-execute), so they have to be
@@ -998,6 +999,60 @@ export function stripInlineScriptBodies(command) {
998
999
  out += command.slice(last);
999
1000
  return out;
1000
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
+ }
1001
1056
  /** Find output redirects (`>`, `>>`, `&>`, `2>`, …) outside quoted strings.
1002
1057
  * The target token may itself be quoted. Skips `2>&1`-style FD dups, bare
1003
1058
  * digits, and /dev/null. Heredoc `<<` is ignored (only `>` is a write). */
@@ -1159,9 +1214,84 @@ function splitArgs(s) {
1159
1214
  out.push(cur);
1160
1215
  return out;
1161
1216
  }
1162
- function classifyMcpTool(toolName) {
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 = {}) {
1163
1290
  const parts = toolName.split("__");
1164
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);
1165
1295
  // Read-only retrieval verbs.
1166
1296
  if (tool.startsWith("list_") || tool.startsWith("get_") || tool.startsWith("search_") ||
1167
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
- body: cmd.length > COMMAND_INLINE_MAX ? truncateBody(cmd) : undefined,
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 || 300_000,
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/sdk",
3
- "version": "0.3.6",
3
+ "version": "0.4.0",
4
4
  "description": "OKed SDK - human approval layer for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",