@oked/claude-code 0.6.19 → 0.6.21

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
@@ -1,11 +1,11 @@
1
1
  # @oked/claude-code
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@oked/claude-code.svg)](https://www.npmjs.com/package/@oked/claude-code)
4
- [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](./LICENSE)
4
+ [![License: Apache-2.0](https://img.shields.io/npm/l/@oked/claude-code.svg)](./LICENSE)
5
5
 
6
- Zero-code integration for Claude Code. Installs a `PreToolUse` hook that routes sensitive actions (destructive Bash commands, payment MCP tools, etc.) through the OKed backend and waits for a human decision before Claude Code proceeds.
6
+ Claude Code hook. Sensitive actions wait for a person in Telegram or on the [web dashboard](https://oked.ai/dashboard) before Claude Code continues. The iPhone app is coming soon.
7
7
 
8
- Non-dangerous actions are left to Claude's normal permission flow - OKed only intervenes when it matters.
8
+ Safe actions are allowed by the hook, with no notification. Warning actions are allowed and logged. OKed asks only for `review` and `high_stakes`.
9
9
 
10
10
  ## Install
11
11
 
@@ -14,66 +14,74 @@ npm install -g @oked/claude-code
14
14
  oked init
15
15
  ```
16
16
 
17
- `oked init` writes a `PreToolUse` hook entry into the current project's `.claude/settings.json`, opens OKed's device-pairing flow in your browser, and stores the paired API key in `~/.oked/config.json`. Open a new Claude Code session in that project to activate the hook.
17
+ `oked init` writes a `PreToolUse` hook into the current project's `.claude/settings.json`, opens the device-pairing page in your browser, and stores the API key in `~/.oked/config.json`. Open a new Claude Code session in that project.
18
+
19
+ On a TTY, unless `NO_COLOR` is set, init also prints a QR code of the pairing link. The QR opens that link in the phone's browser.
20
+
21
+ The approval window is 10 minutes. The hook process is allowed 690 seconds, and the SDK client waits 630 seconds, so a timeout becomes a deny instead of Claude killing the hook first.
18
22
 
19
23
  ## Commands
20
24
 
21
25
  | Command | What it does |
22
26
  |---|---|
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`. |
26
- | `oked status` | Show install state and ping the backend. |
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. |
28
- | `oked uninstall` | Remove the project hook entry (other hooks are preserved). |
27
+ | `oked init` | Install or update the project hook and pair this device. It also updates an existing `oked-hook` entry in user settings (`~/.claude/settings.json`), for example to raise an old timeout. Run it again after you update the package. |
28
+ | `oked init --key-only` | Create or show the API key in `~/.oked/config.json`. It does not add or change a hook. Use it for tools that only need the key, such as the [OpenShell](https://github.com/oked-ai/oked-openshell) middleware. The paired client type is `sdk`. |
29
+ | `oked init --no-browser` | Print the pairing link. Do not open a browser, and do not touch the clipboard. Works with `--key-only`. |
30
+ | `oked init --yes` (or `-y`) | Skip the "press Enter to open the browser" prompt. For a non-interactive shell. |
31
+ | `oked status` | Show install state and ping `GET /health` on the backend. |
32
+ | `oked receipts verify [file]` | Check this machine's receipts (default `~/.oked/receipts.jsonl`): every signature, and the chain links between neighbouring receipts. |
33
+ | `oked uninstall` | Remove the project hook entry. Other hooks are kept. |
29
34
 
30
35
  ## What gets intercepted
31
36
 
32
- The hook uses a four-tier classifier. Classification is **effect-based**: it
33
- detects the *kind of effect* an action has rather than matching specific command
34
- names, and **defaults to no prompt**. Only destructive, irreversible, or
35
- outward-facing operations put a human in the loop.
37
+ The hook uses a four-tier classifier. Classification is effect-based: it detects the kind of effect, not a list of command names, and it defaults to no prompt. Only destructive, irreversible, or outward-facing operations ask a person.
36
38
 
37
39
  | Tier | Behavior | Examples |
38
40
  |---|---|---|
39
- | `safe` | Auto-allow, no notification | Reads & queries, a DB `SELECT`, and any command with no detected side effect — `ls`, `grep`, `jq`, `node`, `npx`, plain `curl` GET (the default) |
40
- | `warning` | Terminal log only, no push | A reversible local mutation: file create / `cp` / `mv`, a `/tmp` delete, local git (`add`/`commit`), `npm install`, SQL `INSERT`/`CREATE` |
41
- | `review` | Push notification, tap to approve | Sensitive-path writes (`~/.ssh`, shell rc, system dirs, OKed config), `sudo`, outward message/email sends, `curl` POST/PUT/PATCH with an inline body, MCP `create_*` / `send_*` / `update_*` |
42
- | `high_stakes` | Push notification with confirmation | Destructive / irreversible / external: `rm` of non-temp data, `DROP TABLE` / `DELETE FROM`, `git push` / `reset --hard` / `branch -D`, `mkfs` / `dd`-to-device / `shutdown`, `curl` DELETE / file upload / pay-or-send API, `ssh`/`scp`, `npm publish`, `kill` |
41
+ | `safe` | Allow, no notification | Reads and queries, a DB `SELECT`, and any Bash command with no detected side effect: `ls`, `grep`, `jq`, `node`, `npx`, plain `curl` GET |
42
+ | `warning` | Terminal log only, no approval | A reversible local change: file create, `cp`, `mv`, a `/tmp` delete, local git (`add`, `commit`), `npm install`, SQL `INSERT` or `CREATE` |
43
+ | `review` | Wait for approval | Sensitive-path writes (`~/.ssh`, shell rc, system dirs, OKed config), `sudo`, outward message or email sends, `curl` POST/PUT/PATCH with an inline body, other cloud CLI writes (`aws s3 cp` to a bucket, `kubectl apply`, `helm upgrade`, a preview deploy), MCP tools named `create_*`, `send_*`, or `update_*` |
44
+ | `high_stakes` | Wait for approval, with confirmation | Destructive or hard to undo: `rm` of non-temp data, `DROP TABLE` or `DELETE FROM`, `git push` / `reset --hard` / `branch -D`, `mkfs`, `dd` to a device, `shutdown`, `curl` DELETE, file upload, pay or send APIs, `ssh` / `scp`, `npm publish`, `kill`, cloud and cluster deletes (`aws s3 rm`, `kubectl delete`), `terraform apply` / `destroy`, production deploys (`vercel --prod`, `fly deploy`), Stripe CLI writes |
43
45
 
44
- A Bash command that matches none of the prompt-worthy effect categories defaults
45
- to `safe` — running a command is not, by itself, something we interrupt you for.
46
- (Unknown non-Bash *tools* still default to `review`.)
46
+ A Bash command that matches none of those effect categories defaults to `safe`. Cloud CLI reads (`aws s3 ls`, `kubectl get`, `terraform plan`), `--help`, and dry runs are `safe`. Running a command is not, by itself, a reason to interrupt you. Unknown tools that are not Bash default to `review`. MCP tools named `delete_*`, `drop_*`, or `remove_*` are `high_stakes`.
47
47
 
48
48
  ## How it works
49
49
 
50
- 1. Claude Code fires the `PreToolUse` hook before every tool call.
51
- 2. The hook classifies the action locally (no network call for safe actions).
52
- 3. If it's high-stakes, it sends an approval request to the OKed backend.
53
- 4. You get a notification (Telegram, web push, or dashboard).
54
- 5. Approve or deny - Claude waits for your decision.
50
+ 1. Claude Code runs the `PreToolUse` hook (`oked-hook`) before the tool call. The hook is a separate process.
51
+ 2. The hook classifies the action locally. `safe` and `warning` do not wait on the network, unless a cached user rule matches and the action has to be sent to the backend.
52
+ 3. For `review` and `high_stakes`, it sends an approval request.
53
+ 4. You decide in Telegram or on the web dashboard. Web push is optional.
54
+ 5. Approve, and Claude continues. Deny or time out, and the tool call is denied.
55
+
56
+ If this device is not paired, the hook returns `ask`, so Claude Code's own permission prompt can decide.
55
57
 
56
58
  ## Environment
57
59
 
58
60
  | Var | Required | Description |
59
61
  |---|---|---|
60
- | `OKED_API_KEY` | no, after pairing | Optional override. `oked init` normally stores the paired key in `~/.oked/config.json`. |
62
+ | `OKED_API_KEY` | no, after pairing | Optional override. `oked init` stores the paired key in `~/.oked/config.json`. |
61
63
  | `OKED_BACKEND_URL` | no | Override the hosted backend URL. |
62
- | `OKED_STRICT_FAIL_CLOSED` | no | Set to `1` or `true` to deny every sensitive action when the backend is unreachable. |
64
+ | `OKED_STRICT_FAIL_CLOSED` | no | `1` or `true` denies every sensitive action when the backend is unreachable. |
65
+ | `OKED_REQUIRE_RECEIPT` | no | `0` allows an approval with no receipt. On by default since 0.6.0. |
66
+ | `OKED_HOOK_LOG` | no | Decision log path. Default `~/.oked/hook.log`. |
63
67
 
64
68
  ## Receipts
65
69
 
66
- Every decision comes with a receipt signed by OKed (who decided, how they were verified, the exact command, when). The hook verifies it before allowing the action, shows its short id (`Approved via OKed (receipt rcpt_7Q2FABCD)`), and keeps your own copy in `~/.oked/receipts.jsonl`. Check that file any time with `oked receipts verify`. Since 0.6.0 the hook denies any approval that comes without a valid receipt. Set `OKED_REQUIRE_RECEIPT=0` only for a backend that does not sign receipts. See [docs/receipts.md](../../docs/receipts.md).
70
+ Every decision comes with a receipt signed by OKed (who decided, how they were verified, the exact command, when). The hook verifies it before allowing the action, shows its short id (`Approved via OKed (receipt rcpt_7Q2FABCD)`), and keeps a copy in `~/.oked/receipts.jsonl`. Check that file with `oked receipts verify`. Since 0.6.0 the hook denies an approval that has no valid receipt. Set `OKED_REQUIRE_RECEIPT=0` only for a backend that does not sign receipts.
71
+
72
+ You can also paste one receipt at [oked.ai/docs/#verify](https://oked.ai/docs/#verify), or check an export with `npx @oked/verify`. See [docs/receipts.md](../../docs/receipts.md).
67
73
 
68
74
  ## Degraded-mode behavior
69
75
 
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.
76
+ Explicit denials, invalid API keys, and receipts that do not verify deny the action. If the backend is unreachable, OKed denies `high_stakes` and, by default, allows lower tiers, so a short outage does not stop every workflow. Set `OKED_STRICT_FAIL_CLOSED=1` to deny every sensitive action during an outage.
77
+
78
+ 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. Deny reasons include the error and its HTTP status.
71
79
 
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.
80
+ If the hook cannot parse its stdin, it allows the call, so a bad payload does not crash Claude. Every other unexpected error denies.
73
81
 
74
82
  ## Decision log
75
83
 
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.
84
+ 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, client, approval id, receipt id, and error (name, message, HTTP status). The log never holds the tool input or the command. Above 1 MB, the file moves to `hook.log.1`. Set `OKED_HOOK_LOG` to use another path.
77
85
 
78
86
  ## License
79
87
 
package/dist/cli.js CHANGED
@@ -8,6 +8,7 @@ import { OKedClient, loadOKedConfig, OKED_CONFIG_PATH } from "@oked/sdk";
8
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
+ import { renderQR } from "./qr.js";
11
12
  const DEFAULT_BACKEND_URL = process.env.OKED_BACKEND_URL || "https://api.oked.ai";
12
13
  /** `oked init --key-only`: create or show the API key; add or change no hook. */
13
14
  const KEY_ONLY = process.argv.includes("--key-only");
@@ -118,14 +119,27 @@ function copyToClipboard(text) {
118
119
  return candidates.reduce((acc, cand) => acc.then((ok) => (ok ? true : tryCopy(cand))), Promise.resolve(false));
119
120
  }
120
121
  /** Wait for the user to press Enter. Resolves immediately if stdin is closed. */
122
+ /** Ask for Enter. cancel() takes the prompt away, for when pairing ends first. */
121
123
  function waitForEnter(message) {
122
- return new Promise((resolve) => {
123
- const rl = createInterface({ input: process.stdin, output: process.stdout });
124
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
125
+ // The pairing poll keeps the process alive, so Ctrl+C must exit on purpose.
126
+ rl.on("SIGINT", () => {
127
+ process.stdout.write("\n");
128
+ process.exit(130);
129
+ });
130
+ const pressed = new Promise((resolve) => {
124
131
  rl.question(message, () => {
125
132
  rl.close();
126
133
  resolve();
127
134
  });
128
135
  });
136
+ return {
137
+ pressed,
138
+ cancel: () => {
139
+ process.stdout.write("\n");
140
+ rl.close();
141
+ },
142
+ };
129
143
  }
130
144
  async function pair(clientType) {
131
145
  const codeRes = await fetch(`${DEFAULT_BACKEND_URL}/api/v1/device/code`, {
@@ -151,6 +165,16 @@ async function pair(clientType) {
151
165
  console.log(" (copied to clipboard)");
152
166
  }
153
167
  console.log("");
168
+ // The QR code holds the pairing link: the OKed app pairs from it, and the
169
+ // Camera app opens it in the browser. Only in a terminal that shows colors.
170
+ if (process.stdout.isTTY && !process.env.NO_COLOR) {
171
+ console.log(" Or scan this with your iPhone:");
172
+ console.log("");
173
+ console.log(renderQR(code.verification_uri_complete));
174
+ console.log("");
175
+ }
176
+ // Poll from now on, so a scan from the phone pairs before anyone presses Enter.
177
+ const paired = pollForKey(code);
154
178
  // Let the user read the code and initiate the browser launch themselves, so
155
179
  // the popup isn't a surprise. Skip the prompt when non-interactive (no TTY,
156
180
  // or `--yes`/`-y`) so CI and scripted installs still work.
@@ -158,13 +182,21 @@ async function pair(clientType) {
158
182
  !process.argv.includes("--yes") &&
159
183
  !process.argv.includes("-y");
160
184
  if (interactive && !NO_BROWSER) {
161
- await waitForEnter(" Press Enter to open your browser (Ctrl+C to cancel)... ");
185
+ const enter = waitForEnter(" Press Enter to open your browser (Ctrl+C to cancel)... ");
186
+ const first = await Promise.race([enter.pressed.then(() => "enter"), paired.then(() => "paired")]);
187
+ if (first === "paired") {
188
+ enter.cancel();
189
+ return paired;
190
+ }
162
191
  }
163
192
  const opened = NO_BROWSER ? false : openBrowser(code.verification_uri_complete);
164
193
  console.log("");
165
194
  if (opened) {
166
195
  console.log(" Opened your browser to:");
167
196
  }
197
+ else if (NO_BROWSER) {
198
+ console.log(" Open this link:");
199
+ }
168
200
  else {
169
201
  console.log(" Couldn't open your browser automatically. Open this link:");
170
202
  }
@@ -174,6 +206,10 @@ async function pair(clientType) {
174
206
  console.log(" or enter it in the OKed app on your iPhone.)");
175
207
  console.log("");
176
208
  console.log(" Waiting for confirmation...");
209
+ return paired;
210
+ }
211
+ /** Poll until the code is confirmed (the API key), or it expires (null). */
212
+ async function pollForKey(code) {
177
213
  const deadline = Date.now() + code.expires_in * 1000;
178
214
  const intervalMs = Math.max(1, code.interval) * 1000;
179
215
  while (Date.now() < deadline) {
package/dist/qr.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /** The QR modules for text: rows of booleans, true is dark. No quiet zone. */
2
+ export declare function encodeQR(text: string): boolean[][];
3
+ /**
4
+ * The QR code as terminal text, two modules per character with half blocks,
5
+ * in black on white with ANSI colors, so it scans on dark and light themes.
6
+ */
7
+ export declare function renderQR(text: string, indent?: string): string;
package/dist/qr.js ADDED
@@ -0,0 +1,332 @@
1
+ // A small QR code encoder for the pairing link that `oked init` prints, so the
2
+ // OKed iPhone app can scan it. Byte mode, error correction level M, versions
3
+ // 1 to 10 (up to 213 bytes): enough for a URL. It follows ISO/IEC 18004 and
4
+ // Project Nayuki's reference design. It is here, not a dependency, so the hook
5
+ // package keeps a single dependency.
6
+ const ECC_PER_BLOCK = [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26];
7
+ const NUM_BLOCKS = [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5];
8
+ const MAX_VERSION = 10;
9
+ const FORMAT_ECC_M = 0;
10
+ /** The QR modules for text: rows of booleans, true is dark. No quiet zone. */
11
+ export function encodeQR(text) {
12
+ const bytes = [...Buffer.from(text, "utf8")];
13
+ let version = 1;
14
+ for (; version <= MAX_VERSION; version++) {
15
+ if (4 + charCountBits(version) + bytes.length * 8 <= dataCodewords(version) * 8)
16
+ break;
17
+ }
18
+ if (version > MAX_VERSION)
19
+ throw new Error("Text too long for a QR code");
20
+ // The data bits: mode, length, bytes, terminator, then pad bytes.
21
+ const capacity = dataCodewords(version) * 8;
22
+ const bits = [];
23
+ const append = (value, length) => {
24
+ for (let i = length - 1; i >= 0; i--)
25
+ bits.push((value >>> i) & 1);
26
+ };
27
+ append(0b0100, 4);
28
+ append(bytes.length, charCountBits(version));
29
+ for (const b of bytes)
30
+ append(b, 8);
31
+ append(0, Math.min(4, capacity - bits.length));
32
+ append(0, (8 - (bits.length % 8)) % 8);
33
+ for (let pad = 0xec; bits.length < capacity; pad ^= 0xec ^ 0x11)
34
+ append(pad, 8);
35
+ const data = [];
36
+ for (let i = 0; i < bits.length; i += 8)
37
+ data.push(parseInt(bits.slice(i, i + 8).join(""), 2));
38
+ const qr = new Matrix(version);
39
+ qr.drawFunctionPatterns();
40
+ qr.drawCodewords(addEccAndInterleave(data, version));
41
+ let best = [];
42
+ let bestPenalty = Infinity;
43
+ for (let mask = 0; mask < 8; mask++) {
44
+ const masked = qr.withMask(mask);
45
+ const penalty = penaltyScore(masked);
46
+ if (penalty < bestPenalty) {
47
+ best = masked;
48
+ bestPenalty = penalty;
49
+ }
50
+ }
51
+ return best;
52
+ }
53
+ /**
54
+ * The QR code as terminal text, two modules per character with half blocks,
55
+ * in black on white with ANSI colors, so it scans on dark and light themes.
56
+ */
57
+ export function renderQR(text, indent = " ") {
58
+ const modules = encodeQR(text);
59
+ const quiet = 2;
60
+ const size = modules.length + quiet * 2;
61
+ const dark = (x, y) => x >= quiet && y >= quiet && x < size - quiet && y < size - quiet && modules[y - quiet][x - quiet];
62
+ const lines = [];
63
+ for (let y = 0; y < size; y += 2) {
64
+ let line = "";
65
+ for (let x = 0; x < size; x++) {
66
+ const top = dark(x, y);
67
+ const bottom = y + 1 < size && dark(x, y + 1);
68
+ line += top && bottom ? "█" : top ? "▀" : bottom ? "▄" : " ";
69
+ }
70
+ lines.push(`${indent}\x1b[30;107m${line}\x1b[0m`);
71
+ }
72
+ return lines.join("\n");
73
+ }
74
+ function charCountBits(version) {
75
+ return version <= 9 ? 8 : 16;
76
+ }
77
+ function rawDataModules(version) {
78
+ let result = (16 * version + 128) * version + 64;
79
+ if (version >= 2) {
80
+ const numAlign = Math.floor(version / 7) + 2;
81
+ result -= (25 * numAlign - 10) * numAlign - 55;
82
+ if (version >= 7)
83
+ result -= 36;
84
+ }
85
+ return result;
86
+ }
87
+ function dataCodewords(version) {
88
+ return Math.floor(rawDataModules(version) / 8) - ECC_PER_BLOCK[version] * NUM_BLOCKS[version];
89
+ }
90
+ function addEccAndInterleave(data, version) {
91
+ const numBlocks = NUM_BLOCKS[version];
92
+ const eccLen = ECC_PER_BLOCK[version];
93
+ const rawCodewords = Math.floor(rawDataModules(version) / 8);
94
+ const numShortBlocks = numBlocks - (rawCodewords % numBlocks);
95
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
96
+ const divisor = reedSolomonDivisor(eccLen);
97
+ const blocks = [];
98
+ for (let i = 0, k = 0; i < numBlocks; i++) {
99
+ const dat = data.slice(k, k + shortBlockLen - eccLen + (i < numShortBlocks ? 0 : 1));
100
+ k += dat.length;
101
+ const ecc = reedSolomonRemainder(dat, divisor);
102
+ if (i < numShortBlocks)
103
+ dat.push(0);
104
+ blocks.push(dat.concat(ecc));
105
+ }
106
+ const result = [];
107
+ for (let i = 0; i < blocks[0].length; i++) {
108
+ blocks.forEach((block, j) => {
109
+ // Skip the padding byte of the short blocks.
110
+ if (i !== shortBlockLen - eccLen || j >= numShortBlocks)
111
+ result.push(block[i]);
112
+ });
113
+ }
114
+ return result;
115
+ }
116
+ function gfMultiply(x, y) {
117
+ let z = 0;
118
+ for (let i = 7; i >= 0; i--) {
119
+ z = (z << 1) ^ ((z >>> 7) * 0x11d);
120
+ z ^= ((y >>> i) & 1) * x;
121
+ }
122
+ return z;
123
+ }
124
+ function reedSolomonDivisor(degree) {
125
+ const result = new Array(degree).fill(0);
126
+ result[degree - 1] = 1;
127
+ let root = 1;
128
+ for (let i = 0; i < degree; i++) {
129
+ for (let j = 0; j < result.length; j++) {
130
+ result[j] = gfMultiply(result[j], root);
131
+ if (j + 1 < result.length)
132
+ result[j] ^= result[j + 1];
133
+ }
134
+ root = gfMultiply(root, 0x02);
135
+ }
136
+ return result;
137
+ }
138
+ function reedSolomonRemainder(data, divisor) {
139
+ const result = divisor.map(() => 0);
140
+ for (const b of data) {
141
+ const factor = b ^ result.shift();
142
+ result.push(0);
143
+ divisor.forEach((coef, i) => (result[i] ^= gfMultiply(coef, factor)));
144
+ }
145
+ return result;
146
+ }
147
+ class Matrix {
148
+ version;
149
+ size;
150
+ modules;
151
+ isFunction;
152
+ constructor(version) {
153
+ this.version = version;
154
+ this.size = version * 4 + 17;
155
+ this.modules = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
156
+ this.isFunction = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
157
+ }
158
+ set(x, y, dark) {
159
+ this.modules[y][x] = dark;
160
+ this.isFunction[y][x] = true;
161
+ }
162
+ drawFunctionPatterns() {
163
+ const size = this.size;
164
+ for (let i = 0; i < size; i++) {
165
+ this.set(6, i, i % 2 === 0);
166
+ this.set(i, 6, i % 2 === 0);
167
+ }
168
+ this.drawFinder(3, 3);
169
+ this.drawFinder(size - 4, 3);
170
+ this.drawFinder(3, size - 4);
171
+ const positions = this.alignmentPositions();
172
+ const last = positions.length - 1;
173
+ positions.forEach((x, i) => positions.forEach((y, j) => {
174
+ if ((i === 0 && j === 0) || (i === 0 && j === last) || (i === last && j === 0))
175
+ return;
176
+ for (let dy = -2; dy <= 2; dy++) {
177
+ for (let dx = -2; dx <= 2; dx++)
178
+ this.set(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
179
+ }
180
+ }));
181
+ // Reserve the format areas now; withMask() writes the real bits.
182
+ this.drawFormatBits(0, this.modules);
183
+ if (this.version >= 7) {
184
+ let rem = this.version;
185
+ for (let i = 0; i < 12; i++)
186
+ rem = (rem << 1) ^ ((rem >>> 11) * 0x1f25);
187
+ const bits = (this.version << 12) | rem;
188
+ for (let i = 0; i < 18; i++) {
189
+ const dark = ((bits >>> i) & 1) !== 0;
190
+ const a = size - 11 + (i % 3);
191
+ const b = Math.floor(i / 3);
192
+ this.set(a, b, dark);
193
+ this.set(b, a, dark);
194
+ }
195
+ }
196
+ }
197
+ drawFinder(cx, cy) {
198
+ for (let dy = -4; dy <= 4; dy++) {
199
+ for (let dx = -4; dx <= 4; dx++) {
200
+ const x = cx + dx;
201
+ const y = cy + dy;
202
+ const dist = Math.max(Math.abs(dx), Math.abs(dy));
203
+ if (x >= 0 && x < this.size && y >= 0 && y < this.size)
204
+ this.set(x, y, dist !== 2 && dist !== 4);
205
+ }
206
+ }
207
+ }
208
+ alignmentPositions() {
209
+ if (this.version === 1)
210
+ return [];
211
+ const numAlign = Math.floor(this.version / 7) + 2;
212
+ const step = Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
213
+ const result = [6];
214
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step)
215
+ result.splice(1, 0, pos);
216
+ return result;
217
+ }
218
+ drawFormatBits(mask, target) {
219
+ const data = (FORMAT_ECC_M << 3) | mask;
220
+ let rem = data;
221
+ for (let i = 0; i < 10; i++)
222
+ rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
223
+ const bits = ((data << 10) | rem) ^ 0x5412;
224
+ const bit = (i) => ((bits >>> i) & 1) !== 0;
225
+ const put = (x, y, dark) => {
226
+ target[y][x] = dark;
227
+ this.isFunction[y][x] = true;
228
+ };
229
+ const size = this.size;
230
+ for (let i = 0; i <= 5; i++)
231
+ put(8, i, bit(i));
232
+ put(8, 7, bit(6));
233
+ put(8, 8, bit(7));
234
+ put(7, 8, bit(8));
235
+ for (let i = 9; i < 15; i++)
236
+ put(14 - i, 8, bit(i));
237
+ for (let i = 0; i < 8; i++)
238
+ put(size - 1 - i, 8, bit(i));
239
+ for (let i = 8; i < 15; i++)
240
+ put(8, size - 15 + i, bit(i));
241
+ put(8, size - 8, true);
242
+ }
243
+ drawCodewords(codewords) {
244
+ const size = this.size;
245
+ let i = 0;
246
+ for (let right = size - 1; right >= 1; right -= 2) {
247
+ if (right === 6)
248
+ right = 5;
249
+ for (let vert = 0; vert < size; vert++) {
250
+ for (let j = 0; j < 2; j++) {
251
+ const x = right - j;
252
+ const upward = ((right + 1) & 2) === 0;
253
+ const y = upward ? size - 1 - vert : vert;
254
+ if (!this.isFunction[y][x] && i < codewords.length * 8) {
255
+ this.modules[y][x] = ((codewords[i >>> 3] >>> (7 - (i & 7))) & 1) !== 0;
256
+ i++;
257
+ }
258
+ }
259
+ }
260
+ }
261
+ }
262
+ /** A copy with the data masked and the format bits for that mask. */
263
+ withMask(mask) {
264
+ const out = this.modules.map((row) => row.slice());
265
+ for (let y = 0; y < this.size; y++) {
266
+ for (let x = 0; x < this.size; x++) {
267
+ if (!this.isFunction[y][x] && maskBit(mask, x, y))
268
+ out[y][x] = !out[y][x];
269
+ }
270
+ }
271
+ this.drawFormatBits(mask, out);
272
+ return out;
273
+ }
274
+ }
275
+ function maskBit(mask, x, y) {
276
+ switch (mask) {
277
+ case 0: return (x + y) % 2 === 0;
278
+ case 1: return y % 2 === 0;
279
+ case 2: return x % 3 === 0;
280
+ case 3: return (x + y) % 3 === 0;
281
+ case 4: return (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
282
+ case 5: return ((x * y) % 2) + ((x * y) % 3) === 0;
283
+ case 6: return (((x * y) % 2) + ((x * y) % 3)) % 2 === 0;
284
+ default: return (((x + y) % 2) + ((x * y) % 3)) % 2 === 0;
285
+ }
286
+ }
287
+ /** The standard mask penalty: runs, 2x2 blocks, finder-like patterns, balance. */
288
+ function penaltyScore(m) {
289
+ const size = m.length;
290
+ let score = 0;
291
+ const lines = [];
292
+ for (let i = 0; i < size; i++) {
293
+ lines.push(m[i]);
294
+ lines.push(m.map((row) => row[i]));
295
+ }
296
+ const finderLike = [
297
+ [true, false, true, true, true, false, true, false, false, false, false],
298
+ [false, false, false, false, true, false, true, true, true, false, true],
299
+ ];
300
+ for (const line of lines) {
301
+ let run = 1;
302
+ for (let i = 1; i <= size; i++) {
303
+ if (i < size && line[i] === line[i - 1]) {
304
+ run++;
305
+ }
306
+ else {
307
+ if (run >= 5)
308
+ score += run - 2;
309
+ run = 1;
310
+ }
311
+ }
312
+ for (let i = 0; i + 11 <= size; i++) {
313
+ for (const pattern of finderLike) {
314
+ if (pattern.every((v, k) => line[i + k] === v))
315
+ score += 40;
316
+ }
317
+ }
318
+ }
319
+ let darkCount = 0;
320
+ for (let y = 0; y < size; y++) {
321
+ for (let x = 0; x < size; x++) {
322
+ if (m[y][x])
323
+ darkCount++;
324
+ if (x + 1 < size && y + 1 < size && m[y][x] === m[y][x + 1] && m[y][x] === m[y + 1][x] && m[y][x] === m[y + 1][x + 1]) {
325
+ score += 3;
326
+ }
327
+ }
328
+ }
329
+ const total = size * size;
330
+ score += Math.floor(Math.abs(darkCount * 20 - total * 10) / total) * 10;
331
+ return score;
332
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/claude-code",
3
- "version": "0.6.19",
3
+ "version": "0.6.21",
4
4
  "description": "OKed for Claude Code - zero-code human approval for sensitive actions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -44,7 +44,7 @@
44
44
  "access": "public"
45
45
  },
46
46
  "dependencies": {
47
- "@oked/sdk": "0.6.19"
47
+ "@oked/sdk": "0.6.21"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "^5.6.0"