@oked/cursor 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,151 @@
1
- # Temporary Holding Version
1
+ # @oked/cursor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/@oked/cursor.svg)](https://www.npmjs.com/package/@oked/cursor)
4
+ [![License: Apache-2.0](https://img.shields.io/npm/l/@oked/cursor.svg)](./LICENSE)
5
+
6
+ Cursor agent hook. Sensitive actions wait for a person in Telegram or on the [web dashboard](https://oked.ai/dashboard?ref=github-cursor) before Cursor continues. The iPhone app is coming soon. Questions: [contact@oked.ai](mailto:contact@oked.ai).
7
+
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
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install -g @oked/cursor
14
+ oked-cursor init
15
+ ```
16
+
17
+ `oked-cursor init` writes `.cursor/hooks.json` in the current project and stores the API key in `~/.oked/config.json`. The file it writes:
18
+
19
+ ```json
20
+ {
21
+ "version": 1,
22
+ "hooks": {
23
+ "preToolUse": [
24
+ {
25
+ "command": "oked-cursor-hook",
26
+ "timeout": 690,
27
+ "failClosed": true
28
+ }
29
+ ]
30
+ }
31
+ }
32
+ ```
33
+
34
+ There is no matcher, so every tool is included. Other hooks already in that file are kept. A second init does not add a second copy. It raises a timeout below 690 and sets `failClosed` to true. The binary is `oked-cursor`, not `oked`, so it can sit next to `@oked/claude-code`.
35
+
36
+ Open a new Cursor agent session in that project. Cursor reloads `hooks.json` when it changes.
37
+
38
+ The approval window is 10 minutes. The hook is configured for 690 seconds, and the SDK client waits 630 seconds, so a timeout can become a deny instead of Cursor killing the hook first. Read the timeout section before you rely on that. Cursor does not document a maximum.
39
+
40
+ ## Commands
41
+
42
+ | Command | What it does |
43
+ |---|---|
44
+ | `oked-cursor init` | Install or update the project hook and pair this device. If a Claude Code `oked-hook` is already installed, this does not add a second hook. |
45
+ | `oked-cursor init --native` | Install the Cursor hook even when a Claude Code `oked-hook` is present. You will get two prompts unless you turn third-party imports off. |
46
+ | `oked-cursor init --no-browser` | Print the pairing link. Do not open a browser, and do not touch the clipboard. |
47
+ | `oked-cursor init --yes` (or `-y`) | Skip the "press Enter to open the browser" prompt. For a non-interactive shell. |
48
+ | `oked-cursor status` | Show install state and ping `GET /health` on the backend. |
49
+ | `oked-cursor uninstall` | Remove the Cursor hook entry. Other hooks in `.cursor/hooks.json` are kept. A Claude Code hook is not removed. |
50
+
51
+ ## What gets intercepted
52
+
53
+ The hook uses the same four-tier classifier as `@oked/claude-code`. The matcher is omitted, so every tool is included. Unknown tools are `review` and wait for approval.
54
+
55
+ | Cursor tool | OKed sees | Notes |
56
+ |---|---|---|
57
+ | `Shell` | `Bash` | `ls` is safe. `rm` of a real file, a force push, network writes, and a production deploy wait. |
58
+ | `Read`, `Grep`, `Glob`, `WebSearch` | the same name | Safe. No prompt. |
59
+ | `WebFetch` | `WebFetch` | Warning. Allowed and logged. |
60
+ | `Write`, `Edit`, `StrReplace` | `Write` or `Edit` | A project file is `warning`. A sensitive path (`/etc`, `~/.ssh`, shell rc, OKed config) is `review`. |
61
+ | `Delete` | `rm` | A temp file is `warning`. Anything else is `high_stakes`. No path is `review`. |
62
+ | `MCP:<tool>` or `MCP:<server>:<tool>` | `mcp__...` | `list_*` and `get_*` are safe. `create_*` and `send_*` are `review`. `delete_*` is `high_stakes`. |
63
+ | `Task` | `Agent` | Starting a sub-agent is safe. Its own tool calls are gated on their own. |
64
+ | anything else | the same name | Unknown tools wait for approval. |
65
+
66
+ Cloud agents load project hooks only (`.cursor/hooks.json`). `preToolUse` fires for MCP tools there, named `MCP:<tool_name>`. For HTTP MCP servers, `preToolUse` can deny the call. Cursor ignores `updated_input` on those. `beforeMCPExecution` does not fire in the cloud.
67
+
68
+ ## How it works
69
+
70
+ 1. Cursor runs `oked-cursor-hook` before the tool call. The hook is a separate process.
71
+ 2. The hook classifies the action locally. `safe` and `warning` do not wait on the network, unless a cached user rule matches.
72
+ 3. For `review` and `high_stakes`, it sends an approval request.
73
+ 4. You decide in Telegram or on the web dashboard. Web push is optional.
74
+ 5. Approve, and the hook prints `{"permission":"allow"}`. Deny or time out, and it prints `permission: "deny"` with `user_message` and `agent_message`.
75
+
76
+ `preToolUse` accepts `"ask"` and does not enforce it ([Cursor hooks](https://cursor.com/docs/hooks)). This hook never prints `ask`. If this device is not paired, the hook denies. The reason is `Pair first: run oked-cursor init`.
77
+
78
+ The hook exits 0 and prints JSON. Cursor treats exit code 2 as deny as well. Other non-zero exits fail open unless `failClosed` is set. This hook sets `failClosed: true`, so a crash, a timeout, or no output denies the action.
79
+
80
+ ## Timeout
81
+
82
+ Cursor's hook reference says `timeout` is seconds and the default is "platform default". It does not say how many seconds that is, and it does not say there is a maximum. Checked on 2026-10-28 at [cursor.com/docs/hooks](https://cursor.com/docs/hooks).
83
+
84
+ `oked-cursor init` writes `"timeout": 690` and `"failClosed": true`. 690 is 60 seconds above the SDK wait of 630. If Cursor honors 690, the SDK's deny is written before the process is killed. If Cursor ignores a timeout that long, or kills the hook earlier, `failClosed` denies the action instead of letting it through.
85
+
86
+ This has not been confirmed inside the Cursor app. Before you depend on a 10 minute approval, run one real session with `timeout: 690` and check that Cursor waits and that an approval comes back as `allow`.
87
+
88
+ A Windows CLI report says some builds wait out the whole timeout and then drop the hook's answer: [forum thread](https://forum.cursor.com/t/cli-hooks-block-each-tool-call-for-the-full-timeout-lowering-it-silently-disables-deny-hooks-windows/169942). On that bug, `failClosed: true` denies an approval as well as a denial, because the verdict is discarded at the deadline. Treat a live check on your machine as required.
89
+
90
+ ## Claude Code hooks, and asking twice
91
+
92
+ Cursor loads Claude Code hooks when "Include Third-Party Plugins, Skills, and Other Configs" is on. That setting is on by default. The files are `.claude/settings.local.json`, `.claude/settings.json`, and `~/.claude/settings.json`. Every matching hook runs. A higher-priority answer wins when they disagree. See [third-party hooks](https://cursor.com/docs/reference/third-party-hooks).
93
+
94
+ An `oked-hook` entry in one of those files plus this package would send two approval requests for one action.
95
+
96
+ `oked-cursor init` looks for that entry. If it finds one, and this project does not already have the native hook, it does not write `.cursor/hooks.json`. Cursor will run the Claude Code hook that is already there. Pairing still runs, because both hooks read `~/.oked/config.json`.
97
+
98
+ That imported hook is the Claude Code one. Two gaps matter:
99
+
100
+ - It returns `ask` when the device is not paired. Cursor does not enforce `ask` on `preToolUse`.
101
+ - Claude settings have no `failClosed` field. Cursor's default is false, so a timeout or a crash of the imported hook fails open. The docs do not say that imported hooks turn `failClosed` on.
102
+
103
+ If you want the native hook (deny when unpaired, `failClosed: true`, Cursor names such as `Shell` and `MCP:`), turn the third-party import setting off, or remove the `oked-hook` entry, and run `oked-cursor init --native`. `--native` installs even when the Claude hook is present. Leave the import setting on only if you accept two prompts.
104
+
105
+ Init never deletes the Claude hook. `oked uninstall` from `@oked/claude-code` removes it, and that also removes it from Claude Code.
106
+
107
+ ## Environment
108
+
109
+ | Var | Required | Description |
110
+ |---|---|---|
111
+ | `OKED_API_KEY` | no, after pairing | Optional override. `oked-cursor init` stores the paired key in `~/.oked/config.json`. |
112
+ | `OKED_BACKEND_URL` | no | Override the hosted backend URL. |
113
+ | `OKED_STRICT_FAIL_CLOSED` | no | `1` or `true` denies every sensitive action when the backend is unreachable. |
114
+ | `OKED_REQUIRE_RECEIPT` | no | `0` allows an approval with no receipt. On by default since 0.6.0. |
115
+ | `OKED_HOOK_LOG` | no | Decision log path. Default `~/.oked/hook.log`. |
116
+
117
+ ## Receipts
118
+
119
+ Every decision comes with a receipt signed by OKed. The hook verifies it before allowing the action and keeps a copy in `~/.oked/receipts.jsonl`. 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.
120
+
121
+ You can paste one receipt at [oked.ai/docs/#verify](https://oked.ai/docs?ref=github-cursor#verify), or check an export with `npx @oked/verify`. See [docs/receipts.md](../../docs/receipts.md).
122
+
123
+ ## Degraded-mode behavior
124
+
125
+ 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. Set `OKED_STRICT_FAIL_CLOSED=1` to deny every sensitive action during an outage.
126
+
127
+ HTTP 429 (too many approvals already waiting) is not an outage: the action is denied until those are decided in Telegram or on the dashboard.
128
+
129
+ If the hook cannot parse its stdin, it denies. A bad payload must not become a silent allow.
130
+
131
+ ## Decision log
132
+
133
+ The hook writes one JSON line to `~/.oked/hook.log` (mode 600) for each deny, and for each degraded allow. The log never holds the tool input or the command.
134
+
135
+ ## Uninstall
136
+
137
+ `oked-cursor uninstall` removes only the `oked-cursor-hook` entry from `.cursor/hooks.json`. Other hooks stay. If that was the only hook, the file is deleted. A Claude Code `oked-hook` entry is left in place. The API key in `~/.oked/config.json` stays.
138
+
139
+ ## Troubleshooting
140
+
141
+ - Hook never runs: open a new agent session. The command `oked-cursor-hook` must be on `PATH` (a global install does that). Project hooks run only in a trusted workspace.
142
+ - The tool ran anyway: Cursor's timeout is undocumented. If it kills the process early, `failClosed: true` should deny. A live check is still required. See the timeout section. On the reported Windows CLI bug, the verdict is dropped at the deadline and `failClosed` denies an approval too.
143
+ - Two cards for one action: a Claude Code `oked-hook` is also loaded. Turn off third-party imports, or remove that entry. `oked-cursor init` skips the native file when it finds one. `oked-cursor init --native` installs anyway and warns.
144
+ - `Pair first: run oked-cursor init`: no API key. The hook denies. It does not print `ask`.
145
+ - Backend down: `high_stakes` is denied. Lower tiers are allowed unless `OKED_STRICT_FAIL_CLOSED=1`. Nobody answering within 10 minutes is a deny.
146
+ - Cloud agents load `.cursor/hooks.json` only. HTTP MCP calls can be denied. Cursor ignores `updated_input` for those.
147
+ - Still stuck: [contact@oked.ai](mailto:contact@oked.ai).
148
+
149
+ ## License
150
+
151
+ [Apache-2.0](./LICENSE)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "../dist/hook.js";
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "../dist/cli.js";
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from "fs";
3
+ import { maskKey, pairDevice, writeOkedConfig } from "@oked/hook-core";
4
+ import { OKedClient, OKED_CONFIG_PATH } from "@oked/sdk";
5
+ import { cursorHookInstalled, hooksPath, installCursorHook, uninstallCursorHook } from "./install.js";
6
+ import { CLIENT_VERSION, PAIR_COMMAND } from "./version.js";
7
+ const BACKEND = process.env.OKED_BACKEND_URL || "https://api.oked.ai";
8
+ const NO_BROWSER = process.argv.includes("--no-browser");
9
+ const NATIVE = process.argv.includes("--native");
10
+ function footer(uri) {
11
+ return [` (Or visit ${uri} and enter the code above.)`, " The iPhone app is coming soon."];
12
+ }
13
+ function printClaudeHits(hits) {
14
+ for (const hit of hits)
15
+ console.log(` ${hit.scope}: ${hit.path}`);
16
+ }
17
+ async function init() {
18
+ const cwd = process.cwd();
19
+ const result = installCursorHook(cwd, { native: NATIVE });
20
+ if (result.action === "unreadable") {
21
+ console.log(`OKed could not read ${result.path}. It was not changed.`);
22
+ }
23
+ else if (result.action === "skipped-claude-hook") {
24
+ console.log("Cursor already runs an @oked/claude-code hook from Claude settings.");
25
+ console.log("A native hook as well would ask twice, so .cursor/hooks.json was not added.");
26
+ printClaudeHits(result.claudeHooks);
27
+ console.log("That imported hook returns ask when this device is not paired, and Cursor does not enforce ask on preToolUse.");
28
+ console.log("It also has no failClosed field. Cursor defaults that to false, so a killed hook fails open.");
29
+ console.log("To install the native hook, turn off Settings > Agents > Third-Party Imports, or remove that oked-hook entry, then run `oked-cursor init --native`.");
30
+ console.log("This command does not remove the Claude Code hook.");
31
+ }
32
+ else if (result.action === "installed") {
33
+ console.log("OKed hook installed.");
34
+ console.log(` Config: ${result.path}`);
35
+ }
36
+ else if (result.action === "updated") {
37
+ console.log("OKed hook updated.");
38
+ console.log(` Config: ${result.path}`);
39
+ }
40
+ else {
41
+ console.log("OKed hook already configured.");
42
+ console.log(` Config: ${result.path}`);
43
+ }
44
+ if (result.claudeHooks.length > 0 && result.action !== "skipped-claude-hook" && result.action !== "unreadable") {
45
+ console.log("A Claude Code oked-hook is also installed. Cursor runs every matching hook, so you will be asked twice.");
46
+ printClaudeHits(result.claudeHooks);
47
+ console.log("Turn off Settings > Agents > Third-Party Imports, or remove the oked-hook entry, to keep a single prompt.");
48
+ }
49
+ const existing = new OKedClient();
50
+ if (existing.apiKey) {
51
+ const ok = await existing.ping();
52
+ console.log("");
53
+ console.log(` API key: ${maskKey(existing.apiKey)} (already paired)`);
54
+ console.log(` Backend: ${existing.backendUrl} (${ok ? "connected" : "not reachable"})`);
55
+ console.log("");
56
+ console.log("Cursor in this project now asks before a risky tool call.");
57
+ return;
58
+ }
59
+ const apiKey = await pairDevice({
60
+ backendUrl: BACKEND,
61
+ clientType: "cursor",
62
+ clientVersion: CLIENT_VERSION,
63
+ noBrowser: NO_BROWSER,
64
+ retryCommand: PAIR_COMMAND,
65
+ scanLine: " Or scan this with your phone camera. It opens the pairing page in the browser.",
66
+ footerLines: footer,
67
+ });
68
+ if (!apiKey)
69
+ return;
70
+ writeOkedConfig(apiKey, BACKEND);
71
+ console.log("");
72
+ console.log(` Paired. Key saved to ${OKED_CONFIG_PATH}`);
73
+ console.log("");
74
+ console.log("Cursor in this project now asks before a risky tool call.");
75
+ console.log("Open a new Cursor agent session to load the hook.");
76
+ }
77
+ async function status() {
78
+ const path = hooksPath(process.cwd());
79
+ const client = new OKedClient();
80
+ console.log("OKed status:");
81
+ console.log(` Hook: ${cursorHookInstalled(process.cwd()) ? "installed" : "not installed"}`);
82
+ console.log(` Project config: ${existsSync(path) ? path : "not found"}`);
83
+ console.log(` API key: ${client.apiKey ? maskKey(client.apiKey) : "not paired"}`);
84
+ console.log(` User config: ${existsSync(OKED_CONFIG_PATH) ? OKED_CONFIG_PATH : "not found"}`);
85
+ if (client.apiKey) {
86
+ const ok = await client.ping();
87
+ console.log(` Backend: ${client.backendUrl} (${ok ? "connected" : "not reachable"})`);
88
+ }
89
+ }
90
+ function uninstall() {
91
+ const result = uninstallCursorHook(process.cwd());
92
+ if (result.action === "unreadable") {
93
+ console.log(`OKed could not read ${result.path}. It was not changed.`);
94
+ return;
95
+ }
96
+ if (result.action === "absent") {
97
+ console.log("OKed hook was not installed in this project.");
98
+ return;
99
+ }
100
+ console.log("OKed hook removed from this project.");
101
+ console.log(` Config: ${result.path}`);
102
+ console.log("A Claude Code hook, if you have one, was left in place.");
103
+ }
104
+ const command = process.argv[2];
105
+ switch (command) {
106
+ case "init":
107
+ init().catch(console.error);
108
+ break;
109
+ case "status":
110
+ status().catch(console.error);
111
+ break;
112
+ case "uninstall":
113
+ uninstall();
114
+ break;
115
+ default:
116
+ console.log("Usage: oked-cursor <command>");
117
+ console.log("");
118
+ console.log("Commands:");
119
+ console.log(" init Install the Cursor preToolUse hook and pair this device");
120
+ console.log(" --native Install even when a Claude Code oked-hook is already present");
121
+ console.log(" --no-browser Print the pairing link. Open no browser, use no clipboard.");
122
+ console.log(" status Show the hook and the connection");
123
+ console.log(" uninstall Remove the OKed Cursor hook from this project");
124
+ break;
125
+ }
package/dist/hook.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/hook.js ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ import { asToolInput, decide, errorInfo, logDecision } from "@oked/hook-core";
3
+ import { mapCursorTool } from "./map.js";
4
+ import { writeDecision } from "./output.js";
5
+ import { CLIENT_ID, PAIR_COMMAND, UNINSTALL_COMMAND } from "./version.js";
6
+ function invalidKeyReason(status) {
7
+ return `OKed: invalid API key (HTTP ${status}). Pair first: run \`${PAIR_COMMAND}\` to pair again, or \`${UNINSTALL_COMMAND}\` to remove OKed.`;
8
+ }
9
+ const UNPAIRED = `OKed: this device is not paired. Pair first: run ${PAIR_COMMAND}`;
10
+ function denyUnreadable(reason) {
11
+ writeDecision({ decision: "deny", reason });
12
+ logDecision({ decision: "deny", reason, tool: "unknown", tier: null, client: CLIENT_ID });
13
+ }
14
+ function stringField(input, keys) {
15
+ for (const key of keys) {
16
+ if (typeof input[key] === "string")
17
+ return input[key];
18
+ }
19
+ return "";
20
+ }
21
+ async function main() {
22
+ let raw = "";
23
+ for await (const chunk of process.stdin)
24
+ raw += chunk;
25
+ let input;
26
+ try {
27
+ const parsed = JSON.parse(raw);
28
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
29
+ throw new Error("not an object");
30
+ input = parsed;
31
+ }
32
+ catch {
33
+ denyUnreadable(`OKed: the hook input could not be read. Pair first: run ${PAIR_COMMAND}`);
34
+ return;
35
+ }
36
+ const toolName = stringField(input, ["tool_name", "toolName"]);
37
+ if (!toolName) {
38
+ denyUnreadable(`OKed: the hook input had no tool name. Pair first: run ${PAIR_COMMAND}`);
39
+ return;
40
+ }
41
+ const mapped = mapCursorTool(toolName, input.tool_input ?? input.toolInput ?? asToolInput(input.toolArgs));
42
+ const session = stringField(input, ["conversation_id", "session_id", "sessionId"]);
43
+ const decision = await decide({
44
+ toolName: mapped.toolName,
45
+ toolInput: mapped.toolInput,
46
+ cwd: typeof input.cwd === "string" ? input.cwd : undefined,
47
+ sessionId: session || undefined,
48
+ }, {
49
+ clientId: CLIENT_ID,
50
+ source: "cursor",
51
+ unpaired: "deny",
52
+ unpairedReason: UNPAIRED,
53
+ unpairedLog: `not paired - pair first: run ${PAIR_COMMAND}`,
54
+ invalidKeyReason,
55
+ });
56
+ writeDecision(decision);
57
+ }
58
+ main().catch((err) => {
59
+ const info = errorInfo(err);
60
+ const reason = `OKed: internal error (fail-safe): ${info.name}: ${info.message}`;
61
+ process.stderr.write(`[OKed] Fatal: ${err}\n`);
62
+ writeDecision({ decision: "deny", reason });
63
+ logDecision({ decision: "deny", reason, tool: "unknown", tier: null, client: CLIENT_ID, error: info });
64
+ process.exit(0);
65
+ });
@@ -0,0 +1,34 @@
1
+ import { type ClaudeHookHit } from "@oked/hook-core";
2
+ export declare const HOOK_COMMAND = "oked-cursor-hook";
3
+ export type InstallAction = "installed" | "updated" | "unchanged" | "skipped-claude-hook" | "unreadable";
4
+ export interface InstallResult {
5
+ action: InstallAction;
6
+ path: string;
7
+ claudeHooks: ClaudeHookHit[];
8
+ }
9
+ export declare function hooksPath(cwd: string): string;
10
+ /**
11
+ * Add the OKed preToolUse hook, or raise a short timeout and set failClosed.
12
+ * A longer timeout is left alone. Other hooks stay.
13
+ */
14
+ export declare function upsertCursorHooks(doc: Record<string, unknown>): {
15
+ doc: Record<string, unknown>;
16
+ changed: boolean;
17
+ };
18
+ export declare function removeCursorHooks(doc: Record<string, unknown>): {
19
+ doc: Record<string, unknown>;
20
+ changed: boolean;
21
+ };
22
+ export declare function cursorHookInstalled(cwd: string): boolean;
23
+ /**
24
+ * Install the project hook. If Cursor would also run an `@oked/claude-code`
25
+ * hook (user or project Claude settings), skip unless `native` is set.
26
+ * A hook that is already installed is updated in place either way.
27
+ */
28
+ export declare function installCursorHook(cwd: string, opts?: {
29
+ native?: boolean;
30
+ }): InstallResult;
31
+ export declare function uninstallCursorHook(cwd: string): {
32
+ action: "removed" | "absent" | "unreadable";
33
+ path: string;
34
+ };
@@ -0,0 +1,136 @@
1
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
2
+ import { dirname, join } from "path";
3
+ import { findClaudeOkedHooks, HOOK_TIMEOUT_SECONDS } from "@oked/hook-core";
4
+ export const HOOK_COMMAND = "oked-cursor-hook";
5
+ export function hooksPath(cwd) {
6
+ return join(cwd, ".cursor", "hooks.json");
7
+ }
8
+ function isOurs(hook) {
9
+ return !!hook && typeof hook === "object" && hook.command === HOOK_COMMAND;
10
+ }
11
+ function readDoc(path) {
12
+ if (!existsSync(path))
13
+ return { doc: {}, state: "absent" };
14
+ try {
15
+ const parsed = JSON.parse(readFileSync(path, "utf-8"));
16
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
17
+ return { doc: {}, state: "unreadable" };
18
+ return { doc: parsed, state: "ok" };
19
+ }
20
+ catch {
21
+ return { doc: {}, state: "unreadable" };
22
+ }
23
+ }
24
+ function preList(doc) {
25
+ const hooks = doc.hooks;
26
+ if (!hooks || typeof hooks !== "object")
27
+ return [];
28
+ const pre = hooks.preToolUse;
29
+ if (!Array.isArray(pre))
30
+ return [];
31
+ return pre.filter((hook) => hook && typeof hook === "object");
32
+ }
33
+ function documentHasOurs(doc) {
34
+ return preList(doc).some(isOurs);
35
+ }
36
+ /**
37
+ * Add the OKed preToolUse hook, or raise a short timeout and set failClosed.
38
+ * A longer timeout is left alone. Other hooks stay.
39
+ */
40
+ export function upsertCursorHooks(doc) {
41
+ const next = structuredClone(doc);
42
+ const hooks = (next.hooks && typeof next.hooks === "object" ? next.hooks : {});
43
+ const list = preList(next);
44
+ let changed = false;
45
+ let found = false;
46
+ for (const hook of list) {
47
+ if (!isOurs(hook))
48
+ continue;
49
+ found = true;
50
+ if (typeof hook.timeout !== "number" || hook.timeout < HOOK_TIMEOUT_SECONDS) {
51
+ hook.timeout = HOOK_TIMEOUT_SECONDS;
52
+ changed = true;
53
+ }
54
+ if (hook.failClosed !== true) {
55
+ hook.failClosed = true;
56
+ changed = true;
57
+ }
58
+ }
59
+ if (!found) {
60
+ list.push({ command: HOOK_COMMAND, timeout: HOOK_TIMEOUT_SECONDS, failClosed: true });
61
+ changed = true;
62
+ }
63
+ if (next.version === undefined) {
64
+ next.version = 1;
65
+ changed = true;
66
+ }
67
+ if (!changed)
68
+ return { doc, changed: false };
69
+ hooks.preToolUse = list;
70
+ next.hooks = hooks;
71
+ return { doc: next, changed: true };
72
+ }
73
+ export function removeCursorHooks(doc) {
74
+ const next = structuredClone(doc);
75
+ const hooks = next.hooks;
76
+ if (!hooks || typeof hooks !== "object" || !Array.isArray(hooks.preToolUse)) {
77
+ return { doc: next, changed: false };
78
+ }
79
+ const record = hooks;
80
+ const kept = record.preToolUse.filter((hook) => !isOurs(hook));
81
+ if (kept.length === record.preToolUse.length)
82
+ return { doc: next, changed: false };
83
+ if (kept.length > 0)
84
+ record.preToolUse = kept;
85
+ else
86
+ delete hooks.preToolUse;
87
+ if (Object.keys(hooks).length === 0)
88
+ delete next.hooks;
89
+ return { doc: next, changed: true };
90
+ }
91
+ function writeDoc(path, doc) {
92
+ mkdirSync(dirname(path), { recursive: true });
93
+ writeFileSync(path, JSON.stringify(doc, null, 2) + "\n");
94
+ }
95
+ export function cursorHookInstalled(cwd) {
96
+ const { doc, state } = readDoc(hooksPath(cwd));
97
+ return state === "ok" && documentHasOurs(doc);
98
+ }
99
+ /**
100
+ * Install the project hook. If Cursor would also run an `@oked/claude-code`
101
+ * hook (user or project Claude settings), skip unless `native` is set.
102
+ * A hook that is already installed is updated in place either way.
103
+ */
104
+ export function installCursorHook(cwd, opts) {
105
+ const path = hooksPath(cwd);
106
+ const claudeHooks = findClaudeOkedHooks(cwd, { includeUser: true });
107
+ const { doc, state } = readDoc(path);
108
+ if (state === "unreadable")
109
+ return { action: "unreadable", path, claudeHooks };
110
+ const had = documentHasOurs(doc);
111
+ if (claudeHooks.length > 0 && !opts?.native && !had) {
112
+ return { action: "skipped-claude-hook", path, claudeHooks };
113
+ }
114
+ const next = upsertCursorHooks(doc);
115
+ if (!next.changed)
116
+ return { action: "unchanged", path, claudeHooks };
117
+ writeDoc(path, next.doc);
118
+ return { action: had ? "updated" : "installed", path, claudeHooks };
119
+ }
120
+ export function uninstallCursorHook(cwd) {
121
+ const path = hooksPath(cwd);
122
+ const { doc, state } = readDoc(path);
123
+ if (state === "absent")
124
+ return { action: "absent", path };
125
+ if (state === "unreadable")
126
+ return { action: "unreadable", path };
127
+ const next = removeCursorHooks(doc);
128
+ if (!next.changed)
129
+ return { action: "absent", path };
130
+ const leftover = Object.keys(next.doc).filter((key) => key !== "version");
131
+ if (leftover.length === 0)
132
+ unlinkSync(path);
133
+ else
134
+ writeDoc(path, next.doc);
135
+ return { action: "removed", path };
136
+ }
package/dist/map.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export interface MappedCall {
2
+ toolName: string;
3
+ toolInput: Record<string, unknown>;
4
+ }
5
+ /** `MCP:server:tool` becomes `mcp__server__tool`. A bare `MCP:tool` uses server `mcp`. */
6
+ export declare function toMcpToolName(name: string): string;
7
+ /**
8
+ * Map a Cursor preToolUse call onto a name and input `classify()` understands.
9
+ * Unknown tools stay unknown, which the classifier sends to approval.
10
+ */
11
+ export declare function mapCursorTool(toolName: string, rawInput: unknown): MappedCall;
package/dist/map.js ADDED
@@ -0,0 +1,45 @@
1
+ import { asToolInput, mapFileDelete, stringField, withNormalizedFields } from "@oked/hook-core";
2
+ /** `MCP:server:tool` becomes `mcp__server__tool`. A bare `MCP:tool` uses server `mcp`. */
3
+ export function toMcpToolName(name) {
4
+ if (name.startsWith("mcp__"))
5
+ return name;
6
+ const rest = name.replace(/^(?:MCP|mcp):/, "");
7
+ const parts = rest.split(":").filter(Boolean);
8
+ if (parts.length >= 2)
9
+ return `mcp__${parts[0]}__${parts.slice(1).join("__")}`;
10
+ return `mcp__mcp__${parts[0] || "tool"}`;
11
+ }
12
+ /**
13
+ * Map a Cursor preToolUse call onto a name and input `classify()` understands.
14
+ * Unknown tools stay unknown, which the classifier sends to approval.
15
+ */
16
+ export function mapCursorTool(toolName, rawInput) {
17
+ const input = withNormalizedFields(asToolInput(rawInput));
18
+ if (toolName === "Shell" || toolName === "shell" || toolName === "Bash") {
19
+ return { toolName: "Bash", toolInput: input };
20
+ }
21
+ if (toolName === "Delete" || toolName === "delete_file") {
22
+ return mapFileDelete(input);
23
+ }
24
+ if (toolName === "Task" || toolName === "Subagent") {
25
+ return { toolName: "Agent", toolInput: input };
26
+ }
27
+ if (toolName === "EditNotebook") {
28
+ return { toolName: "NotebookEdit", toolInput: input };
29
+ }
30
+ if (toolName === "Write" || toolName === "Edit" || toolName === "StrReplace") {
31
+ return { toolName: toolName === "StrReplace" ? "Edit" : toolName, toolInput: input };
32
+ }
33
+ if (/^(?:MCP|mcp):/.test(toolName) || toolName.startsWith("mcp__")) {
34
+ return { toolName: toMcpToolName(toolName), toolInput: input };
35
+ }
36
+ if (toolName === "Read" || toolName === "Grep" || toolName === "Glob" || toolName === "WebSearch" || toolName === "WebFetch") {
37
+ return { toolName, toolInput: input };
38
+ }
39
+ const server = stringField(input, ["server", "serverName", "mcp_server"]);
40
+ const tool = stringField(input, ["tool", "name"]);
41
+ if ((toolName === "MCP" || toolName === "mcp") && server && tool) {
42
+ return { toolName: `mcp__${server}__${tool}`, toolInput: input };
43
+ }
44
+ return { toolName, toolInput: input };
45
+ }
@@ -0,0 +1,6 @@
1
+ import type { GateDecision } from "@oked/hook-core";
2
+ /**
3
+ * Cursor `preToolUse` output. `allow` and `deny` are enforced.
4
+ * `ask` is accepted by the schema and not enforced, so a non-allow is deny.
5
+ */
6
+ export declare function writeDecision(decision: GateDecision): void;
package/dist/output.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Cursor `preToolUse` output. `allow` and `deny` are enforced.
3
+ * `ask` is accepted by the schema and not enforced, so a non-allow is deny.
4
+ */
5
+ export function writeDecision(decision) {
6
+ if (decision.decision === "allow") {
7
+ const out = { permission: "allow" };
8
+ if (decision.reason)
9
+ out.user_message = decision.reason;
10
+ process.stdout.write(JSON.stringify(out));
11
+ return;
12
+ }
13
+ const reason = decision.reason || "OKed denied this action.";
14
+ process.stdout.write(JSON.stringify({
15
+ permission: "deny",
16
+ user_message: reason,
17
+ agent_message: reason,
18
+ }));
19
+ }
@@ -0,0 +1,4 @@
1
+ export declare const CLIENT_VERSION: string;
2
+ export declare const CLIENT_ID: string;
3
+ export declare const PAIR_COMMAND = "oked-cursor init";
4
+ export declare const UNINSTALL_COMMAND = "oked-cursor uninstall";
@@ -0,0 +1,15 @@
1
+ import { readFileSync } from "fs";
2
+ import { dirname, join } from "path";
3
+ import { fileURLToPath } from "url";
4
+ export const CLIENT_VERSION = (() => {
5
+ try {
6
+ const pkgPath = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
7
+ return JSON.parse(readFileSync(pkgPath, "utf-8")).version ?? "0.0.0";
8
+ }
9
+ catch {
10
+ return "0.0.0";
11
+ }
12
+ })();
13
+ export const CLIENT_ID = `@oked/cursor@${CLIENT_VERSION}`;
14
+ export const PAIR_COMMAND = "oked-cursor init";
15
+ export const UNINSTALL_COMMAND = "oked-cursor uninstall";
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@oked/cursor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.6.21",
4
+ "description": "OKed for Cursor. A preToolUse hook that holds risky agent tool calls for a human decision.",
5
+ "type": "module",
6
+ "bin": {
7
+ "oked-cursor": "./bin/oked-cursor.js",
8
+ "oked-cursor-hook": "./bin/oked-cursor-hook.js"
9
+ },
10
+ "scripts": {
11
+ "prebuild": "npm run build --workspace=@oked/hook-core",
12
+ "build": "tsc",
13
+ "test": "npm run build && node src/map.test.mjs && node src/install.test.mjs && node src/hook.test.mjs && node src/fixture.test.mjs",
14
+ "prepublishOnly": "npm run build"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "bin",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "keywords": [
23
+ "oked",
24
+ "cursor",
25
+ "ai-agent",
26
+ "approval",
27
+ "human-in-the-loop",
28
+ "hooks"
29
+ ],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/oked-ai/oked-sdk.git",
33
+ "directory": "packages/cursor"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/oked-ai/oked-sdk/issues"
37
+ },
38
+ "homepage": "https://oked.ai?ref=github-cursor",
39
+ "license": "Apache-2.0",
40
+ "engines": {
41
+ "node": ">=18"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "dependencies": {
47
+ "@oked/hook-core": "0.6.21",
48
+ "@oked/sdk": "0.6.21"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^22.13.10",
52
+ "typescript": "^5.6.0"
53
+ }
54
+ }