@oked/claude-code 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/dist/cli.js CHANGED
@@ -6,18 +6,7 @@ import { fileURLToPath } from "url";
6
6
  import { spawn } from "child_process";
7
7
  import { createInterface } from "readline";
8
8
  import { OKedClient, loadOKedConfig, OKED_CONFIG_PATH } from "@oked/sdk";
9
- const MCP_TOOL_MATCHER = "mcp__.*";
10
- const DEFAULT_TOOL_MATCHER = `Bash|Write|Edit|Agent|${MCP_TOOL_MATCHER}`;
11
- const HOOK_CONFIG = {
12
- matcher: DEFAULT_TOOL_MATCHER,
13
- hooks: [
14
- {
15
- type: "command",
16
- command: "oked-hook",
17
- timeout: 300,
18
- },
19
- ],
20
- };
9
+ import { HOOK_CONFIG, hasOkedCommandHook, ensureMcpMatcher, ensureHookTimeout, } from "./hook-config.js";
21
10
  const DEFAULT_BACKEND_URL = process.env.OKED_BACKEND_URL || "https://api.oked.ai";
22
11
  // Derived from this package's package.json at runtime so the version the
23
12
  // backend sees (client_version) can never drift from what's actually shipped.
@@ -64,20 +53,6 @@ function writeOkedConfig(apiKey, backendUrl) {
64
53
  // Windows doesn't honor chmod; the file lives in the user profile anyway.
65
54
  }
66
55
  }
67
- function hasOkedCommandHook(entry) {
68
- return Boolean(entry.hooks?.some((h) => typeof h === "object" &&
69
- h !== null &&
70
- h.command === "oked-hook"));
71
- }
72
- function ensureMcpMatcher(matcher) {
73
- if (!matcher)
74
- return matcher;
75
- const parts = matcher.split("|").map((part) => part.trim());
76
- if (parts.some((part) => part === MCP_TOOL_MATCHER || part.startsWith("mcp__"))) {
77
- return matcher;
78
- }
79
- return `${matcher}|${MCP_TOOL_MATCHER}`;
80
- }
81
56
  function openBrowser(url) {
82
57
  const platform = process.platform;
83
58
  let cmd;
@@ -230,17 +205,20 @@ async function init() {
230
205
  // Merge OKed hook into existing hooks
231
206
  const hooks = (settings.hooks || {});
232
207
  const preToolUse = (hooks.PreToolUse || []);
233
- // Check if OKed hook already exists and upgrade older matchers to cover MCP
234
- // tools (`mcp__<server>__<tool>`) as regular PreToolUse events.
235
- let updatedOkedMatcher = false;
208
+ // Check if OKed hook already exists and upgrade it in place: older matchers
209
+ // need to cover MCP tools (`mcp__<server>__<tool>`) as regular PreToolUse
210
+ // events, and older timeouts predate the 10-minute approval window.
211
+ let updatedOkedHook = false;
236
212
  const hasOked = preToolUse.some((entry) => {
237
213
  if (!hasOkedCommandHook(entry))
238
214
  return false;
239
215
  const nextMatcher = ensureMcpMatcher(entry.matcher);
240
216
  if (nextMatcher !== entry.matcher) {
241
217
  entry.matcher = nextMatcher;
242
- updatedOkedMatcher = true;
218
+ updatedOkedHook = true;
243
219
  }
220
+ if (ensureHookTimeout(entry))
221
+ updatedOkedHook = true;
244
222
  return true;
245
223
  });
246
224
  if (!hasOked) {
@@ -251,7 +229,7 @@ async function init() {
251
229
  console.log("OKed hook installed.");
252
230
  console.log(` Config: ${settingsPath}`);
253
231
  }
254
- else if (updatedOkedMatcher) {
232
+ else if (updatedOkedHook) {
255
233
  hooks.PreToolUse = preToolUse;
256
234
  settings.hooks = hooks;
257
235
  writeSettings(settingsPath, settings);
@@ -0,0 +1,41 @@
1
+ export declare const MCP_TOOL_MATCHER = "mcp__.*";
2
+ export declare const DEFAULT_TOOL_MATCHER = "Bash|Write|Edit|Agent|mcp__.*";
3
+ /**
4
+ * Seconds Claude Code lets `oked-hook` run before killing it.
5
+ *
6
+ * Must stay ABOVE the SDK's approval timeout: on expiry the SDK aborts its
7
+ * request and the hook writes a fail-safe deny, but a killed process writes
8
+ * nothing at all and Claude Code falls back to its own default, so an equal
9
+ * (or smaller) value turns the timeout path from "deny" into "gate falls
10
+ * open". The 60s margin covers process spawn plus heartbeat() and getRules(),
11
+ * which both run before approve() is even called.
12
+ *
13
+ * Claude Code imposes no ceiling of its own: the field is validated as any
14
+ * positive number of seconds, and defaults to 600 when absent.
15
+ */
16
+ export declare const HOOK_TIMEOUT_SECONDS: number;
17
+ export declare const HOOK_CONFIG: {
18
+ matcher: string;
19
+ hooks: {
20
+ type: string;
21
+ command: string;
22
+ timeout: number;
23
+ }[];
24
+ };
25
+ export declare function isOkedCommandHook(h: unknown): h is Record<string, unknown>;
26
+ export declare function hasOkedCommandHook(entry: {
27
+ hooks?: unknown[];
28
+ }): boolean;
29
+ export declare function ensureMcpMatcher(matcher?: string): string | undefined;
30
+ /**
31
+ * Raise a stale hook timeout in place. Installs created before the 10-minute
32
+ * approval window carry the old 300s, and `init()` never rewrites an entry it
33
+ * already recognizes, so without this they would keep a limit that now sits
34
+ * BELOW the SDK's own timeout - the killed-before-deny case. Only ever raises:
35
+ * a user who deliberately set a longer window keeps it.
36
+ *
37
+ * Returns true when something changed.
38
+ */
39
+ export declare function ensureHookTimeout(entry: {
40
+ hooks?: unknown[];
41
+ }): boolean;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The hook entry `oked init` writes into `.claude/settings.json`, plus the
3
+ * in-place upgrades applied when an older entry is already there.
4
+ *
5
+ * Kept out of cli.ts because that module runs its command switch on import,
6
+ * which makes it untestable. These are pure functions over the settings shape.
7
+ */
8
+ import { DEFAULT_APPROVAL_TIMEOUT_MS } from "@oked/sdk";
9
+ export const MCP_TOOL_MATCHER = "mcp__.*";
10
+ export const DEFAULT_TOOL_MATCHER = `Bash|Write|Edit|Agent|${MCP_TOOL_MATCHER}`;
11
+ /**
12
+ * Seconds Claude Code lets `oked-hook` run before killing it.
13
+ *
14
+ * Must stay ABOVE the SDK's approval timeout: on expiry the SDK aborts its
15
+ * request and the hook writes a fail-safe deny, but a killed process writes
16
+ * nothing at all and Claude Code falls back to its own default, so an equal
17
+ * (or smaller) value turns the timeout path from "deny" into "gate falls
18
+ * open". The 60s margin covers process spawn plus heartbeat() and getRules(),
19
+ * which both run before approve() is even called.
20
+ *
21
+ * Claude Code imposes no ceiling of its own: the field is validated as any
22
+ * positive number of seconds, and defaults to 600 when absent.
23
+ */
24
+ export const HOOK_TIMEOUT_SECONDS = DEFAULT_APPROVAL_TIMEOUT_MS / 1000 + 60;
25
+ export const HOOK_CONFIG = {
26
+ matcher: DEFAULT_TOOL_MATCHER,
27
+ hooks: [
28
+ {
29
+ type: "command",
30
+ command: "oked-hook",
31
+ timeout: HOOK_TIMEOUT_SECONDS,
32
+ },
33
+ ],
34
+ };
35
+ export function isOkedCommandHook(h) {
36
+ return (typeof h === "object" &&
37
+ h !== null &&
38
+ h.command === "oked-hook");
39
+ }
40
+ export function hasOkedCommandHook(entry) {
41
+ return Boolean(entry.hooks?.some(isOkedCommandHook));
42
+ }
43
+ export function ensureMcpMatcher(matcher) {
44
+ if (!matcher)
45
+ return matcher;
46
+ const parts = matcher.split("|").map((part) => part.trim());
47
+ if (parts.some((part) => part === MCP_TOOL_MATCHER || part.startsWith("mcp__"))) {
48
+ return matcher;
49
+ }
50
+ return `${matcher}|${MCP_TOOL_MATCHER}`;
51
+ }
52
+ /**
53
+ * Raise a stale hook timeout in place. Installs created before the 10-minute
54
+ * approval window carry the old 300s, and `init()` never rewrites an entry it
55
+ * already recognizes, so without this they would keep a limit that now sits
56
+ * BELOW the SDK's own timeout - the killed-before-deny case. Only ever raises:
57
+ * a user who deliberately set a longer window keeps it.
58
+ *
59
+ * Returns true when something changed.
60
+ */
61
+ export function ensureHookTimeout(entry) {
62
+ let updated = false;
63
+ for (const h of entry.hooks ?? []) {
64
+ if (!isOkedCommandHook(h))
65
+ continue;
66
+ const current = h.timeout;
67
+ if (typeof current === "number" && current >= HOOK_TIMEOUT_SECONDS)
68
+ continue;
69
+ h.timeout = HOOK_TIMEOUT_SECONDS;
70
+ updated = true;
71
+ }
72
+ return updated;
73
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/claude-code",
3
- "version": "0.3.5",
3
+ "version": "0.4.0",
4
4
  "description": "OKed for Claude Code - zero-code human approval for sensitive actions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,6 +10,7 @@
10
10
  "scripts": {
11
11
  "prebuild": "npm run build --workspace=@oked/sdk",
12
12
  "build": "tsc",
13
+ "test": "npm run build && node src/smoke.test.mjs",
13
14
  "prepublishOnly": "npm run build"
14
15
  },
15
16
  "files": [
@@ -43,7 +44,7 @@
43
44
  "access": "public"
44
45
  },
45
46
  "dependencies": {
46
- "@oked/sdk": "0.3.5"
47
+ "@oked/sdk": "0.4.0"
47
48
  },
48
49
  "devDependencies": {
49
50
  "typescript": "^5.6.0"