@oked/claude-code 0.6.4 → 0.6.6
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 +9 -1
- package/dist/cli.js +57 -5
- package/dist/hook-config.d.ts +17 -0
- package/dist/hook-config.js +56 -1
- package/dist/hook-log.d.ts +30 -0
- package/dist/hook-log.js +39 -0
- package/dist/hook.js +52 -16
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -20,7 +20,9 @@ oked init
|
|
|
20
20
|
|
|
21
21
|
| Command | What it does |
|
|
22
22
|
|---|---|
|
|
23
|
-
| `oked init` | Install or update the project hook and pair this device. |
|
|
23
|
+
| `oked init` | Install or update the project hook and pair this device. It also updates an existing `oked-hook` entry in your user settings (`~/.claude/settings.json`), for example to a new timeout. Run it again after you update the package. |
|
|
24
|
+
| `oked init --key-only` | Only create or show your OKed API key (saved in `~/.oked/config.json`). It adds or changes no hook. Use it for tools that only need the key, such as the OpenShell middleware. |
|
|
25
|
+
| `oked init --no-browser` | Print the pairing link instead of opening a browser, and leave the clipboard alone. Useful on a server or over SSH. Works with `--key-only`. |
|
|
24
26
|
| `oked status` | Show install state and ping the backend. |
|
|
25
27
|
| `oked receipts verify [file]` | Check this machine's copy of approval receipts (default `~/.oked/receipts.jsonl`): every signature, and the chain links between neighbouring receipts. |
|
|
26
28
|
| `oked uninstall` | Remove the project hook entry (other hooks are preserved). |
|
|
@@ -67,6 +69,12 @@ Every decision comes with a receipt signed by OKed (who decided, how they were v
|
|
|
67
69
|
|
|
68
70
|
Explicit denials, invalid API keys and approval receipts that do not verify deny the action. If the backend is unreachable, OKed denies `high_stakes` actions and, by default, allows lower tiers so a temporary outage does not stop every Claude Code workflow. If no API key is configured, the hook returns `ask` so Claude Code's native permission flow can handle the decision. Set `OKED_STRICT_FAIL_CLOSED=1` to deny every sensitive action during backend outages.
|
|
69
71
|
|
|
72
|
+
The backend counts as unreachable when the connection fails, when it answers with HTTP 5xx, when the hosting platform answers in its place (for example Railway "Application not found"), or when the reply is not JSON. "Too many pending approvals" (HTTP 429) is not an outage: the hook denies the action and asks you to decide the waiting approvals first. Every deny reason shows the real error and its HTTP status.
|
|
73
|
+
|
|
74
|
+
## Decision log
|
|
75
|
+
|
|
76
|
+
The hook writes one JSON line to `~/.oked/hook.log` (mode 600) for each deny and ask, and for each degraded allow (`"degraded": true`: an action that ran without a person's decision because the backend was unreachable). Each line has the time, decision, tool, tier, reason, approval ID, receipt ID and error (name, message, HTTP status). The log never holds the tool input or the command. Above 1 MB, it moves to `hook.log.1`. Set `OKED_HOOK_LOG` to use another file.
|
|
77
|
+
|
|
70
78
|
## License
|
|
71
79
|
|
|
72
80
|
[MIT](./LICENSE)
|
package/dist/cli.js
CHANGED
|
@@ -5,10 +5,18 @@ import { join, dirname } from "path";
|
|
|
5
5
|
import { spawn } from "child_process";
|
|
6
6
|
import { createInterface } from "readline";
|
|
7
7
|
import { OKedClient, loadOKedConfig, OKED_CONFIG_PATH } from "@oked/sdk";
|
|
8
|
-
import { HOOK_CONFIG, hasOkedCommandHook, ensureMcpMatcher, ensureHookTimeout, } from "./hook-config.js";
|
|
8
|
+
import { HOOK_CONFIG, hasOkedCommandHook, ensureMcpMatcher, ensureHookTimeout, upgradeSettingsFile, userSettingsPath, } from "./hook-config.js";
|
|
9
9
|
import { CLIENT_VERSION } from "./version.js";
|
|
10
10
|
import { OKED_RECEIPTS_LOG, verifyReceiptsFile } from "./receipts.js";
|
|
11
11
|
const DEFAULT_BACKEND_URL = process.env.OKED_BACKEND_URL || "https://api.oked.ai";
|
|
12
|
+
/** `oked init --key-only`: create or show the API key; add or change no hook. */
|
|
13
|
+
const KEY_ONLY = process.argv.includes("--key-only");
|
|
14
|
+
/** `oked init --no-browser`: print the pairing link; open no browser, use no clipboard. */
|
|
15
|
+
const NO_BROWSER = process.argv.includes("--no-browser");
|
|
16
|
+
/** The first 8 characters, never the whole key. */
|
|
17
|
+
function maskKey(key) {
|
|
18
|
+
return `${key.slice(0, 8)}...`;
|
|
19
|
+
}
|
|
12
20
|
function getSettingsPath() {
|
|
13
21
|
return join(process.cwd(), ".claude", "settings.json");
|
|
14
22
|
}
|
|
@@ -139,7 +147,7 @@ async function pair(clientType) {
|
|
|
139
147
|
console.log("");
|
|
140
148
|
console.log(" Your pairing code:");
|
|
141
149
|
console.log(` ${code.user_code}`);
|
|
142
|
-
if (await copyToClipboard(code.user_code)) {
|
|
150
|
+
if (!NO_BROWSER && (await copyToClipboard(code.user_code))) {
|
|
143
151
|
console.log(" (copied to clipboard)");
|
|
144
152
|
}
|
|
145
153
|
console.log("");
|
|
@@ -149,10 +157,10 @@ async function pair(clientType) {
|
|
|
149
157
|
const interactive = Boolean(process.stdin.isTTY) &&
|
|
150
158
|
!process.argv.includes("--yes") &&
|
|
151
159
|
!process.argv.includes("-y");
|
|
152
|
-
if (interactive) {
|
|
160
|
+
if (interactive && !NO_BROWSER) {
|
|
153
161
|
await waitForEnter(" Press Enter to open your browser (Ctrl+C to cancel)... ");
|
|
154
162
|
}
|
|
155
|
-
const opened = openBrowser(code.verification_uri_complete);
|
|
163
|
+
const opened = NO_BROWSER ? false : openBrowser(code.verification_uri_complete);
|
|
156
164
|
console.log("");
|
|
157
165
|
if (opened) {
|
|
158
166
|
console.log(" Opened your browser to:");
|
|
@@ -188,7 +196,35 @@ async function pair(clientType) {
|
|
|
188
196
|
console.log(" Pairing timed out. Run `oked init` again.");
|
|
189
197
|
return null;
|
|
190
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* `oked init --key-only`: pair this device (or show the existing key) and save
|
|
201
|
+
* the key in ~/.oked/config.json. It adds no Claude Code hook and changes no
|
|
202
|
+
* settings file. For tools that only need the key, such as the OpenShell
|
|
203
|
+
* middleware.
|
|
204
|
+
*/
|
|
205
|
+
async function initKeyOnly() {
|
|
206
|
+
const existing = new OKedClient();
|
|
207
|
+
if (existing.apiKey) {
|
|
208
|
+
const ok = await existing.ping();
|
|
209
|
+
const where = process.env.OKED_API_KEY ? "the OKED_API_KEY environment variable" : OKED_CONFIG_PATH;
|
|
210
|
+
console.log("OKed API key already set up (no hook added).");
|
|
211
|
+
console.log("");
|
|
212
|
+
console.log(` API key: ${maskKey(existing.apiKey)}`);
|
|
213
|
+
console.log(` Stored in: ${where}`);
|
|
214
|
+
console.log(` Backend: ${existing.backendUrl} (${ok ? "connected" : "not reachable"})`);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const apiKey = await pair("sdk");
|
|
218
|
+
if (!apiKey)
|
|
219
|
+
return;
|
|
220
|
+
writeOkedConfig(apiKey, DEFAULT_BACKEND_URL);
|
|
221
|
+
console.log("");
|
|
222
|
+
console.log(` Paired ✓ API key ${maskKey(apiKey)} saved to ${OKED_CONFIG_PATH}`);
|
|
223
|
+
console.log(" No Claude Code hook was added. Run `oked init` without --key-only to add it.");
|
|
224
|
+
}
|
|
191
225
|
async function init() {
|
|
226
|
+
if (KEY_ONLY)
|
|
227
|
+
return initKeyOnly();
|
|
192
228
|
const settingsPath = getSettingsPath();
|
|
193
229
|
const settings = readSettings(settingsPath);
|
|
194
230
|
// Merge OKed hook into existing hooks
|
|
@@ -229,12 +265,26 @@ async function init() {
|
|
|
229
265
|
console.log("OKed hook already configured.");
|
|
230
266
|
console.log(` Config: ${settingsPath}`);
|
|
231
267
|
}
|
|
268
|
+
// An oked-hook entry in the user-level settings (all projects) gets the
|
|
269
|
+
// same upgrades, so existing users get a new timeout when they run init
|
|
270
|
+
// after an update. Init never adds the hook there.
|
|
271
|
+
const userPath = userSettingsPath();
|
|
272
|
+
if (userPath !== settingsPath) {
|
|
273
|
+
const result = upgradeSettingsFile(userPath);
|
|
274
|
+
if (result === "updated") {
|
|
275
|
+
console.log("OKed hook updated in your user settings (all projects).");
|
|
276
|
+
console.log(` Config: ${userPath}`);
|
|
277
|
+
}
|
|
278
|
+
else if (result === "unreadable") {
|
|
279
|
+
console.log(` Note: could not read ${userPath}; it was not changed.`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
232
282
|
// Already paired? Just ping and exit.
|
|
233
283
|
const existingClient = new OKedClient();
|
|
234
284
|
if (existingClient.apiKey) {
|
|
235
285
|
const ok = await existingClient.ping();
|
|
236
286
|
console.log("");
|
|
237
|
-
console.log(` API key: ${existingClient.apiKey
|
|
287
|
+
console.log(` API key: ${maskKey(existingClient.apiKey)} (already paired)`);
|
|
238
288
|
console.log(` Backend: ${existingClient.backendUrl} (${ok ? "connected" : "not reachable"})`);
|
|
239
289
|
console.log("");
|
|
240
290
|
console.log("Every Claude Code session in this project is now protected.");
|
|
@@ -334,6 +384,8 @@ switch (command) {
|
|
|
334
384
|
console.log("");
|
|
335
385
|
console.log("Commands:");
|
|
336
386
|
console.log(" init Install OKed hooks in current project and pair this device");
|
|
387
|
+
console.log(" --key-only Only create or show the API key. Add no hook.");
|
|
388
|
+
console.log(" --no-browser Print the pairing link. Open no browser, use no clipboard.");
|
|
337
389
|
console.log(" status Show current config and connection status");
|
|
338
390
|
console.log(" uninstall Remove OKed hooks from current project");
|
|
339
391
|
console.log(" receipts verify [file] Check this machine's approval receipts");
|
package/dist/hook-config.d.ts
CHANGED
|
@@ -39,3 +39,20 @@ export declare function ensureMcpMatcher(matcher?: string): string | undefined;
|
|
|
39
39
|
export declare function ensureHookTimeout(entry: {
|
|
40
40
|
hooks?: unknown[];
|
|
41
41
|
}): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Apply the in-place upgrades (MCP matcher, timeout) to every `oked-hook`
|
|
44
|
+
* entry of a settings object. Never adds a hook. Returns true when something
|
|
45
|
+
* changed.
|
|
46
|
+
*/
|
|
47
|
+
export declare function upgradeOkedHooks(settings: {
|
|
48
|
+
hooks?: Record<string, unknown>;
|
|
49
|
+
}): boolean;
|
|
50
|
+
/** The user-level Claude Code settings file (all projects). */
|
|
51
|
+
export declare function userSettingsPath(): string;
|
|
52
|
+
export type SettingsFileUpgrade = "updated" | "unchanged" | "no-oked-hook" | "absent" | "unreadable";
|
|
53
|
+
/**
|
|
54
|
+
* Upgrade the `oked-hook` entries in one settings file, in place. A file with
|
|
55
|
+
* no `oked-hook` entry is left alone: this never installs the hook there.
|
|
56
|
+
* A file that does not parse is never rewritten.
|
|
57
|
+
*/
|
|
58
|
+
export declare function upgradeSettingsFile(path: string): SettingsFileUpgrade;
|
package/dist/hook-config.js
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
* in-place upgrades applied when an older entry is already there.
|
|
4
4
|
*
|
|
5
5
|
* Kept out of cli.ts because that module runs its command switch on import,
|
|
6
|
-
* which makes it untestable.
|
|
6
|
+
* which makes it untestable. Most are pure functions over the settings shape;
|
|
7
|
+
* upgradeSettingsFile() reads and writes one file.
|
|
7
8
|
*/
|
|
9
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
10
|
+
import { homedir } from "os";
|
|
11
|
+
import { join } from "path";
|
|
8
12
|
import { DEFAULT_APPROVAL_TIMEOUT_MS } from "@oked/sdk";
|
|
9
13
|
export const MCP_TOOL_MATCHER = "mcp__.*";
|
|
10
14
|
export const DEFAULT_TOOL_MATCHER = `Bash|Write|Edit|Agent|${MCP_TOOL_MATCHER}`;
|
|
@@ -71,3 +75,54 @@ export function ensureHookTimeout(entry) {
|
|
|
71
75
|
}
|
|
72
76
|
return updated;
|
|
73
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Apply the in-place upgrades (MCP matcher, timeout) to every `oked-hook`
|
|
80
|
+
* entry of a settings object. Never adds a hook. Returns true when something
|
|
81
|
+
* changed.
|
|
82
|
+
*/
|
|
83
|
+
export function upgradeOkedHooks(settings) {
|
|
84
|
+
const preToolUse = settings.hooks?.PreToolUse;
|
|
85
|
+
if (!Array.isArray(preToolUse))
|
|
86
|
+
return false;
|
|
87
|
+
let updated = false;
|
|
88
|
+
for (const entry of preToolUse) {
|
|
89
|
+
if (!entry || typeof entry !== "object" || !hasOkedCommandHook(entry))
|
|
90
|
+
continue;
|
|
91
|
+
const nextMatcher = ensureMcpMatcher(entry.matcher);
|
|
92
|
+
if (nextMatcher !== entry.matcher) {
|
|
93
|
+
entry.matcher = nextMatcher;
|
|
94
|
+
updated = true;
|
|
95
|
+
}
|
|
96
|
+
if (ensureHookTimeout(entry))
|
|
97
|
+
updated = true;
|
|
98
|
+
}
|
|
99
|
+
return updated;
|
|
100
|
+
}
|
|
101
|
+
/** The user-level Claude Code settings file (all projects). */
|
|
102
|
+
export function userSettingsPath() {
|
|
103
|
+
return join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "settings.json");
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Upgrade the `oked-hook` entries in one settings file, in place. A file with
|
|
107
|
+
* no `oked-hook` entry is left alone: this never installs the hook there.
|
|
108
|
+
* A file that does not parse is never rewritten.
|
|
109
|
+
*/
|
|
110
|
+
export function upgradeSettingsFile(path) {
|
|
111
|
+
if (!existsSync(path))
|
|
112
|
+
return "absent";
|
|
113
|
+
let settings;
|
|
114
|
+
try {
|
|
115
|
+
settings = JSON.parse(readFileSync(path, "utf-8"));
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return "unreadable";
|
|
119
|
+
}
|
|
120
|
+
const pre = settings?.hooks?.PreToolUse;
|
|
121
|
+
if (!Array.isArray(pre) || !pre.some((e) => e && typeof e === "object" && hasOkedCommandHook(e))) {
|
|
122
|
+
return "no-oked-hook";
|
|
123
|
+
}
|
|
124
|
+
if (!upgradeOkedHooks(settings))
|
|
125
|
+
return "unchanged";
|
|
126
|
+
writeFileSync(path, JSON.stringify(settings, null, 2) + "\n");
|
|
127
|
+
return "updated";
|
|
128
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One JSON line per hook decision that is not a normal allow: every deny and
|
|
3
|
+
* ask, and every degraded allow (an action that ran without a person's
|
|
4
|
+
* decision because the backend was unreachable). A person can see later why
|
|
5
|
+
* an action was blocked, or which actions ran during an outage. It never holds
|
|
6
|
+
* the tool input or the description: a command line can contain a secret.
|
|
7
|
+
*/
|
|
8
|
+
export declare const OKED_HOOK_LOG: string;
|
|
9
|
+
export interface ErrorInfo {
|
|
10
|
+
name: string;
|
|
11
|
+
message: string;
|
|
12
|
+
status?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface DecisionLogEntry {
|
|
15
|
+
ts: string;
|
|
16
|
+
decision: "deny" | "ask" | "allow";
|
|
17
|
+
/** True for an allow without a person's decision, during a backend outage. */
|
|
18
|
+
degraded?: boolean;
|
|
19
|
+
reason: string;
|
|
20
|
+
tool: string;
|
|
21
|
+
tier: string | null;
|
|
22
|
+
client: string;
|
|
23
|
+
approval_id?: string | null;
|
|
24
|
+
receipt_id?: string | null;
|
|
25
|
+
error?: ErrorInfo;
|
|
26
|
+
}
|
|
27
|
+
/** Name, one-line message (at most 300 characters) and HTTP status, if any. */
|
|
28
|
+
export declare function errorInfo(err: unknown): ErrorInfo;
|
|
29
|
+
/** Appends one entry. Best-effort: a log problem never changes the decision. */
|
|
30
|
+
export declare function logDecision(entry: Omit<DecisionLogEntry, "ts">, path?: string): void;
|
package/dist/hook-log.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
import { dirname, join } from "path";
|
|
4
|
+
/**
|
|
5
|
+
* One JSON line per hook decision that is not a normal allow: every deny and
|
|
6
|
+
* ask, and every degraded allow (an action that ran without a person's
|
|
7
|
+
* decision because the backend was unreachable). A person can see later why
|
|
8
|
+
* an action was blocked, or which actions ran during an outage. It never holds
|
|
9
|
+
* the tool input or the description: a command line can contain a secret.
|
|
10
|
+
*/
|
|
11
|
+
export const OKED_HOOK_LOG = join(homedir(), ".oked", "hook.log");
|
|
12
|
+
/** Above this size, hook.log moves to hook.log.1 and a new file starts. */
|
|
13
|
+
const MAX_BYTES = 1_000_000;
|
|
14
|
+
/** Name, one-line message (at most 300 characters) and HTTP status, if any. */
|
|
15
|
+
export function errorInfo(err) {
|
|
16
|
+
const e = err;
|
|
17
|
+
const name = typeof e?.name === "string" ? e.name : typeof err;
|
|
18
|
+
const raw = typeof e?.message === "string" ? e.message : String(err);
|
|
19
|
+
const line = raw.replace(/\s+/g, " ").trim();
|
|
20
|
+
const message = line.length > 300 ? line.slice(0, 297) + "..." : line;
|
|
21
|
+
return typeof e?.status === "number" ? { name, message, status: e.status } : { name, message };
|
|
22
|
+
}
|
|
23
|
+
/** Appends one entry. Best-effort: a log problem never changes the decision. */
|
|
24
|
+
export function logDecision(entry, path = process.env.OKED_HOOK_LOG || OKED_HOOK_LOG) {
|
|
25
|
+
try {
|
|
26
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
27
|
+
try {
|
|
28
|
+
if (statSync(path).size > MAX_BYTES)
|
|
29
|
+
renameSync(path, `${path}.1`);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// No file yet.
|
|
33
|
+
}
|
|
34
|
+
appendFileSync(path, JSON.stringify({ ts: new Date().toISOString(), ...entry }) + "\n", { mode: 0o600 });
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// The decision itself is already written to stdout.
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/hook.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { OKedClient, classify, describe, describeFields, applyRules, degradedDecision, OKedAuthError, OKedBackendUnreachableError, OKedReceiptError, shortReceiptId, } from "@oked/sdk";
|
|
2
|
+
import { OKedClient, classify, describe, describeFields, applyRules, degradedDecision, OKedAuthError, OKedBackendUnreachableError, OKedHttpError, OKedReceiptError, OKedTooManyPendingError, shortReceiptId, } from "@oked/sdk";
|
|
3
3
|
import { CLIENT_ID } from "./version.js";
|
|
4
4
|
import { appendReceipt } from "./receipts.js";
|
|
5
|
+
import { logDecision, errorInfo } from "./hook-log.js";
|
|
5
6
|
function makeOutput(decision, reason) {
|
|
6
7
|
return {
|
|
7
8
|
hookSpecificOutput: {
|
|
@@ -14,6 +15,20 @@ function makeOutput(decision, reason) {
|
|
|
14
15
|
function log(msg) {
|
|
15
16
|
process.stderr.write(`[OKed] ${msg}\n`);
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Writes the hook output. Every deny and ask, and every degraded allow, also
|
|
20
|
+
* goes to ~/.oked/hook.log.
|
|
21
|
+
*/
|
|
22
|
+
function respond(decision, reason, ctx) {
|
|
23
|
+
process.stdout.write(JSON.stringify(makeOutput(decision, reason)));
|
|
24
|
+
if (decision !== "allow" || ctx.degraded)
|
|
25
|
+
logDecision({ decision, reason: reason ?? "", client: CLIENT_ID, ...ctx });
|
|
26
|
+
}
|
|
27
|
+
/** "Name: message", one line, short. For deny reasons. */
|
|
28
|
+
function errorText(err) {
|
|
29
|
+
const e = errorInfo(err);
|
|
30
|
+
return `${e.name}: ${e.message}`;
|
|
31
|
+
}
|
|
17
32
|
async function main() {
|
|
18
33
|
// Read hook input from stdin
|
|
19
34
|
let rawInput = "";
|
|
@@ -70,10 +85,11 @@ async function main() {
|
|
|
70
85
|
// A rule matched a normally-silent action — fall through to the backend,
|
|
71
86
|
// which applies the rule authoritatively (escalate / auto-decide + audit).
|
|
72
87
|
}
|
|
88
|
+
const ctx = { tool: toolName, tier };
|
|
73
89
|
// Check if API key is configured
|
|
74
90
|
if (!client.apiKey) {
|
|
75
91
|
log("not paired - run `oked init` to pair this device. Falling back to Claude's built-in prompt.");
|
|
76
|
-
|
|
92
|
+
respond("ask", "OKed: this device is not paired. Run `oked init`.", ctx);
|
|
77
93
|
return;
|
|
78
94
|
}
|
|
79
95
|
// Generate human-readable description
|
|
@@ -94,52 +110,72 @@ async function main() {
|
|
|
94
110
|
if (result.receipt)
|
|
95
111
|
appendReceipt(result.receipt);
|
|
96
112
|
const receiptNote = result.receipt ? ` (receipt ${shortReceiptId(result.receipt.body.receipt_id)})` : "";
|
|
113
|
+
const decided = {
|
|
114
|
+
...ctx,
|
|
115
|
+
approval_id: result.approval_id,
|
|
116
|
+
receipt_id: result.receipt?.body.receipt_id ?? null,
|
|
117
|
+
};
|
|
97
118
|
if (result.approved) {
|
|
98
119
|
log(`Approved (${result.approval_id})${receiptNote}`);
|
|
99
|
-
|
|
120
|
+
respond("allow", `Approved via OKed${receiptNote}`, decided);
|
|
121
|
+
}
|
|
122
|
+
else if (result.decision === "timeout") {
|
|
123
|
+
log(`No decision in time (${result.approval_id})${receiptNote}`);
|
|
124
|
+
respond("deny", `OKed: no decision within the approval window (timed out): ${description}`, decided);
|
|
100
125
|
}
|
|
101
126
|
else {
|
|
102
127
|
log(`Denied (${result.approval_id})${receiptNote}`);
|
|
103
|
-
|
|
128
|
+
respond("deny", `Denied via OKed: ${description}`, decided);
|
|
104
129
|
}
|
|
105
130
|
}
|
|
106
131
|
catch (err) {
|
|
132
|
+
const failed = { ...ctx, error: errorInfo(err) };
|
|
107
133
|
if (err instanceof OKedReceiptError) {
|
|
108
134
|
// A decision we cannot prove is not a decision - always deny.
|
|
109
135
|
log(`Approval receipt did not verify (${err.problems.join(", ")}) - action denied`);
|
|
110
|
-
|
|
136
|
+
respond("deny", `OKed: the approval receipt did not verify (${err.problems.join(", ")}); action denied`, failed);
|
|
111
137
|
}
|
|
112
138
|
else if (err instanceof OKedAuthError) {
|
|
113
139
|
// Auth misconfig is not an outage - always deny.
|
|
114
|
-
log(`Invalid API key - action denied`);
|
|
115
|
-
|
|
140
|
+
log(`Invalid API key (HTTP ${err.status}) - action denied`);
|
|
141
|
+
respond("deny", `OKed: invalid API key (HTTP ${err.status}). Run \`oked init\` to pair again.`, failed);
|
|
142
|
+
}
|
|
143
|
+
else if (err instanceof OKedTooManyPendingError) {
|
|
144
|
+
// Not an outage: the backend works, and too many approvals wait.
|
|
145
|
+
log(`Too many pending approvals (HTTP 429) - action denied`);
|
|
146
|
+
respond("deny", err.message, failed);
|
|
147
|
+
}
|
|
148
|
+
else if (err instanceof OKedHttpError) {
|
|
149
|
+
log(`Backend error HTTP ${err.status} - action denied (fail-safe)`);
|
|
150
|
+
respond("deny", `OKed: backend error HTTP ${err.status}${err.detail ? `: ${err.detail}` : ""} (fail-safe deny)`, failed);
|
|
116
151
|
}
|
|
117
152
|
else if (err instanceof OKedBackendUnreachableError) {
|
|
118
153
|
const decision = degradedDecision(tier, {
|
|
119
154
|
strictFailClosed: client.strictFailClosed,
|
|
120
155
|
});
|
|
156
|
+
const cause = errorInfo(err).message;
|
|
121
157
|
if (decision === "allow") {
|
|
122
|
-
log(`Backend unreachable - allowed (degraded; ${tier}, non-high-stakes)`);
|
|
123
|
-
|
|
158
|
+
log(`Backend unreachable (${cause}) - allowed (degraded; ${tier}, non-high-stakes)`);
|
|
159
|
+
respond("allow", `OKed backend unreachable (${cause}) - allowed (degraded; non-high-stakes)`, { ...failed, degraded: true });
|
|
124
160
|
}
|
|
125
161
|
else {
|
|
126
162
|
const why = client.strictFailClosed
|
|
127
163
|
? "strict fail-closed"
|
|
128
164
|
: "high-stakes";
|
|
129
|
-
log(`Backend unreachable - ${why} denied (fail-safe)`);
|
|
130
|
-
|
|
165
|
+
log(`Backend unreachable (${cause}) - ${why} denied (fail-safe)`);
|
|
166
|
+
respond("deny", `OKed backend unreachable (${cause}) - ${why} denied (fail-safe)`, failed);
|
|
131
167
|
}
|
|
132
168
|
}
|
|
133
169
|
else {
|
|
134
|
-
// Unknown error - fail safe deny.
|
|
135
|
-
log(`Unexpected error - action denied (fail-safe)`);
|
|
136
|
-
|
|
170
|
+
// Unknown error - fail safe deny, with the real cause.
|
|
171
|
+
log(`Unexpected error (${errorText(err)}) - action denied (fail-safe)`);
|
|
172
|
+
respond("deny", `OKed: unexpected error (fail-safe): ${errorText(err)}`, failed);
|
|
137
173
|
}
|
|
138
174
|
}
|
|
139
175
|
}
|
|
140
176
|
main().catch((err) => {
|
|
141
177
|
process.stderr.write(`[OKed] Fatal: ${err}\n`);
|
|
142
|
-
// Fail-safe: deny
|
|
143
|
-
|
|
178
|
+
// Fail-safe: deny, with the real cause.
|
|
179
|
+
respond("deny", `OKed: internal error (fail-safe): ${errorText(err)}`, { tool: "unknown", tier: null, error: errorInfo(err) });
|
|
144
180
|
process.exit(0); // exit 0 so Claude reads our JSON, not a crash
|
|
145
181
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oked/claude-code",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "OKed for Claude Code - zero-code human approval for sensitive actions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -10,7 +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
|
+
"test": "npm run build && node src/smoke.test.mjs && node src/hook.test.mjs && node src/cli.test.mjs",
|
|
14
14
|
"prepublishOnly": "npm run build"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@oked/sdk": "0.6.
|
|
47
|
+
"@oked/sdk": "0.6.6"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"typescript": "^5.6.0"
|