@oked/claude-agent-sdk 0.3.6 → 0.5.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/index.d.ts CHANGED
@@ -17,5 +17,6 @@ export declare const okedPreToolUseHook: HookCallback;
17
17
  export declare function okedHooks(): {
18
18
  PreToolUse: {
19
19
  hooks: HookCallback[];
20
+ timeout: number;
20
21
  }[];
21
22
  };
package/dist/index.js CHANGED
@@ -12,10 +12,24 @@
12
12
  * via `OKED_API_KEY` (or `~/.oked/config.json`); see README.
13
13
  *
14
14
  * Failure semantics mirror the other OKed integrations: fail safe. Auth
15
- * errors deny; backend-unreachable degrades per tier (`degradedDecision`);
16
- * any unexpected error denies. Never let an agent proceed when in doubt.
15
+ * errors and receipts that do not verify deny; backend-unreachable degrades
16
+ * per tier (`degradedDecision`); any unexpected error denies. Never let an agent proceed when in doubt.
17
17
  */
18
- import { OKedClient, classify, describe, describeFields, degradedDecision, OKedAuthError, OKedBackendUnreachableError, } from "@oked/sdk";
18
+ import { OKedClient, classify, describe, describeFields, degradedDecision, OKedAuthError, OKedBackendUnreachableError, OKedReceiptError, DEFAULT_APPROVAL_TIMEOUT_MS, } from "@oked/sdk";
19
+ import { readFileSync } from "node:fs";
20
+ import { dirname, join } from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+ // This package's version, read from its package.json at runtime (dist/*.js
23
+ // sits one dir below it) so receipts name the exact client that asked.
24
+ const CLIENT_ID = (() => {
25
+ try {
26
+ const pkgPath = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
27
+ return `@oked/claude-agent-sdk@${JSON.parse(readFileSync(pkgPath, "utf-8")).version}`;
28
+ }
29
+ catch {
30
+ return "@oked/claude-agent-sdk";
31
+ }
32
+ })();
19
33
  function log(msg) {
20
34
  process.stderr.write(`[OKed] ${msg}\n`);
21
35
  }
@@ -47,7 +61,7 @@ export const okedPreToolUseHook = async (rawInput) => {
47
61
  const toolName = input.tool_name;
48
62
  const toolInput = (input.tool_input ?? {});
49
63
  const tier = classify(toolName, toolInput);
50
- const client = new OKedClient();
64
+ const client = new OKedClient({ client: CLIENT_ID, source: "claude-agent-sdk" });
51
65
  // Presence ping (throttled to once/day on disk, never throws). Fired before
52
66
  // the safe/warning return so installs that only run safe actions still
53
67
  // register for retention. Fire-and-forget: this is a long-lived process, so
@@ -67,8 +81,8 @@ export const okedPreToolUseHook = async (rawInput) => {
67
81
  log("OKED_API_KEY not set - deferring to the agent's built-in permission flow.");
68
82
  return ask();
69
83
  }
70
- const description = describe(toolName, toolInput);
71
- const fields = describeFields(toolName, toolInput) ?? undefined;
84
+ const description = describe(toolName, toolInput, { cwd: input.cwd });
85
+ const fields = describeFields(toolName, toolInput, { cwd: input.cwd }) ?? undefined;
72
86
  log(`${toolName}: "${description}" - ${tier}`);
73
87
  log("Requesting approval... (check your phone)");
74
88
  try {
@@ -89,6 +103,11 @@ export const okedPreToolUseHook = async (rawInput) => {
89
103
  return deny(`Denied via OKed: ${description}`);
90
104
  }
91
105
  catch (err) {
106
+ if (err instanceof OKedReceiptError) {
107
+ // A decision we cannot prove is not a decision — always deny.
108
+ log(`Approval receipt did not verify (${err.problems.join(", ")}) - action denied`);
109
+ return deny(`OKed: the approval receipt did not verify (${err.problems.join(", ")}); action denied`);
110
+ }
92
111
  if (err instanceof OKedAuthError) {
93
112
  // Auth misconfig is not an outage — always deny.
94
113
  log("Invalid API key - action denied");
@@ -110,6 +129,16 @@ export const okedPreToolUseHook = async (rawInput) => {
110
129
  return deny("OKed: unexpected error (fail-safe)");
111
130
  }
112
131
  };
132
+ /**
133
+ * Seconds the Agent SDK allows this hook before aborting it.
134
+ *
135
+ * Must stay ABOVE the SDK's approval timeout. An aborted hook returns no
136
+ * permission decision at all, so the tool call falls back to the agent's
137
+ * normal permission flow rather than being denied - the same
138
+ * killed-before-deny hole the Claude Code hook has. Letting our own timeout
139
+ * fire first means the approval always resolves to an explicit allow or deny.
140
+ */
141
+ const HOOK_TIMEOUT_SECONDS = DEFAULT_APPROVAL_TIMEOUT_MS / 1000 + 60;
113
142
  /**
114
143
  * Convenience: spread into the Claude Agent SDK `options.hooks`.
115
144
  *
@@ -121,5 +150,7 @@ export const okedPreToolUseHook = async (rawInput) => {
121
150
  * ```
122
151
  */
123
152
  export function okedHooks() {
124
- return { PreToolUse: [{ hooks: [okedPreToolUseHook] }] };
153
+ return {
154
+ PreToolUse: [{ hooks: [okedPreToolUseHook], timeout: HOOK_TIMEOUT_SECONDS }],
155
+ };
125
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/claude-agent-sdk",
3
- "version": "0.3.6",
3
+ "version": "0.5.0",
4
4
  "description": "OKed for the Claude Agent SDK. A ready-made PreToolUse hook that gates sensitive tool calls behind a human approval push to your phone.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -32,7 +32,7 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@oked/sdk": "0.3.6"
35
+ "@oked/sdk": "0.5.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@anthropic-ai/claude-agent-sdk": "^0.1.0",