@cdot65/prisma-airs-cursor-hooks 0.1.0 → 0.1.3

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
@@ -4,7 +4,7 @@ Cursor IDE hooks that scan prompts and AI responses in real-time using [Prisma A
4
4
 
5
5
  Built on the [`@cdot65/prisma-airs-sdk`](https://github.com/cdot65/prisma-airs-sdk).
6
6
 
7
- ## Architecture
7
+ ## How It Works
8
8
 
9
9
  ```
10
10
  Developer prompt → beforeSubmitPrompt hook → AIRS Sync API → allow/block
@@ -12,8 +12,6 @@ Developer prompt → beforeSubmitPrompt hook → AIRS Sync API → allow/block
12
12
  Cursor AI Agent (if allowed)
13
13
 
14
14
  AI response → afterAgentResponse hook → code extractor → AIRS Sync API → allow/block
15
-
16
- (response field + code_response field)
17
15
  ```
18
16
 
19
17
  Both hooks use Cursor's native hooks.json system. They receive structured JSON on stdin, scan via the AIRS API, and reply on stdout (`{ "continue": false }` to block prompts, `{ "permission": "deny" }` + exit code 2 to block responses).
@@ -25,29 +23,15 @@ Both hooks use Cursor's native hooks.json system. They receive structured JSON o
25
23
  - **Prisma AIRS API key** and regional endpoint URL
26
24
  - **AIRS security profiles** configured for prompt and response scanning
27
25
 
28
- ## Setup
29
-
30
- ### Option A: Install from npm (recommended)
26
+ ## Install
31
27
 
32
28
  ```bash
33
29
  npm install -g @cdot65/prisma-airs-cursor-hooks
34
30
  ```
35
31
 
36
- Then register hooks in Cursor:
37
-
38
- ```bash
39
- prisma-airs-hooks install --global
40
- ```
41
-
42
- ### Option B: Install from source
43
-
44
- ```bash
45
- git clone https://github.com/cdot65/prisma-airs-cursor-hooks.git
46
- cd prisma-airs-cursor-hooks
47
- npm install # also runs `npm run build` via prepare hook
48
- ```
32
+ > **From source?** See the [Development](#development) section below.
49
33
 
50
- ### 2. Set environment variables
34
+ ## Set Environment Variables
51
35
 
52
36
  Add to your shell profile (`~/.zshrc`, `~/.bashrc`, etc.):
53
37
 
@@ -68,51 +52,38 @@ Available regional endpoints:
68
52
  | India | `https://service-in.api.aisecurity.paloaltonetworks.com` |
69
53
  | Singapore | `https://service-sg.api.aisecurity.paloaltonetworks.com` |
70
54
 
71
- ### 3. Validate connectivity
55
+ ## Validate Connectivity
72
56
 
73
57
  ```bash
74
- # Test that your API key and endpoint work
75
- npm run validate-connection
76
-
77
- # Confirm prompt injection detection is active
78
- npm run validate-detection
58
+ prisma-airs-hooks validate-connection
59
+ prisma-airs-hooks validate-detection
79
60
  ```
80
61
 
81
- ### 4. Install hooks into Cursor
82
-
83
- If installed from npm:
62
+ ## Register Hooks in Cursor
84
63
 
85
64
  ```bash
86
65
  prisma-airs-hooks install --global
87
66
  ```
88
67
 
89
- If installed from source:
90
-
91
- ```bash
92
- npm run install-hooks -- --global # all workspaces (~/.cursor/hooks.json)
93
- ```
94
-
95
- This writes `hooks.json` registering two hooks pointing at precompiled JS in `dist/`:
68
+ This writes `hooks.json` registering two hooks pointing at precompiled JS:
96
69
  - **`beforeSubmitPrompt`** — scans every prompt before it reaches the AI agent
97
70
  - **`afterAgentResponse`** — scans every AI response (with code extraction) before display
98
71
 
99
72
  It also copies `airs-config.json` to the hooks config directory.
100
73
 
101
- > **Why compiled JS?** Hooks run as a fresh process on every prompt/response. Using precompiled JS (`node dist/...`) vs TypeScript (`npx tsx src/...`) eliminates ~1.5s of startup overhead per invocation (npx resolution + tsx transpilation). See [Development mode](#development-mode) for the tsx alternative.
102
-
103
- ### 5. Restart Cursor
74
+ ## Restart Cursor
104
75
 
105
76
  Cursor reads `hooks.json` at startup. **Restart Cursor** to activate the hooks.
106
77
 
107
- ### 6. Verify installation
78
+ ## Verify
108
79
 
109
80
  ```bash
110
- npm run verify-hooks
81
+ prisma-airs-hooks verify
111
82
  ```
112
83
 
113
84
  ## Configuration
114
85
 
115
- Runtime config lives at `.cursor/hooks/airs-config.json`:
86
+ Runtime config lives at `~/.cursor/hooks/airs-config.json`:
116
87
 
117
88
  ```json
118
89
  {
@@ -171,82 +142,55 @@ When `mode` is `enforce`, each detection service can be configured independently
171
142
 
172
143
  After `failure_threshold` consecutive AIRS API failures, scanning is temporarily bypassed for `cooldown_ms` milliseconds. A probe request is sent after cooldown — if it succeeds, scanning resumes normally.
173
144
 
174
- ## Scanning details
175
-
176
- ### Prompt scanning (beforeSubmitPrompt)
177
-
178
- - Prompt text sent to AIRS with `prompt` content key
179
- - Scanned against the prompt security profile (prompt injection, DLP, toxicity, custom topics)
180
-
181
- ### Response scanning (afterAgentResponse)
182
-
183
- - AI response is parsed by the code extractor:
184
- - Fenced code blocks (` ```lang `) are extracted with language detection
185
- - Indented code blocks (4+ spaces) are detected
186
- - Heuristic fallback for unfenced code-like content
187
- - Natural language goes in the `response` field
188
- - Extracted code goes in the `code_response` field (triggers WildFire/ATP malicious code detection)
189
- - Scanned against the response security profile (malicious code, DLP, URL categorization, toxicity)
190
-
191
- ### Fail-open design
192
-
193
- Scanning **never blocks the developer workflow** on infrastructure failures:
194
- - `failClosed: false` in hooks.json — Cursor allows through if the hook process crashes
195
- - Network errors and timeouts return `{ "permission": "allow" }`
196
- - Config errors return allow with a warning message
197
- - Circuit breaker bypasses scanning after consecutive failures
198
-
199
- ## Commands
145
+ ## CLI Commands
200
146
 
201
147
  | Command | Description |
202
148
  |---------|-------------|
203
- | `npm run build` | Compile hooks to `dist/` (also runs on `npm install`) |
204
- | `npm test` | Run all tests (66 tests across 9 suites) |
205
- | `npm run typecheck` | TypeScript type checking |
206
- | `npm run validate-connection` | Test AIRS API connectivity |
207
- | `npm run validate-detection` | Verify prompt injection detection |
208
- | `npm run install-hooks` | Write AIRS entries to `.cursor/hooks.json` |
209
- | `npm run uninstall-hooks` | Remove AIRS entries from `.cursor/hooks.json` |
210
- | `npm run verify-hooks` | Check hooks are installed and env vars set |
211
- | `npm run stats` | Show scan statistics from log file |
212
- | `npm run stats -- --since 7d --json` | Stats for last 7 days as JSON |
149
+ | `prisma-airs-hooks install [--global]` | Register hooks in Cursor |
150
+ | `prisma-airs-hooks uninstall [--global]` | Remove AIRS hooks from Cursor |
151
+ | `prisma-airs-hooks verify` | Check hooks registration and env vars |
152
+ | `prisma-airs-hooks validate-connection` | Test AIRS API connectivity |
153
+ | `prisma-airs-hooks validate-detection` | Verify prompt injection detection |
154
+ | `prisma-airs-hooks stats [--since 7d] [--json]` | Show scan statistics |
213
155
 
214
156
  ## Uninstall
215
157
 
216
158
  ```bash
217
- # npm global install
218
159
  prisma-airs-hooks uninstall --global
219
-
220
- # from source
221
- npm run uninstall-hooks -- --global
222
160
  ```
223
161
 
224
- Removes AIRS entries from `.cursor/hooks.json` while preserving other hooks, config, and logs. Restart Cursor after uninstalling.
162
+ Removes AIRS entries from `hooks.json` while preserving other hooks, config, and logs. Restart Cursor after uninstalling.
225
163
 
226
164
  ## Development
227
165
 
166
+ For contributors or those who want to run from source:
167
+
228
168
  ```bash
229
- # Install dependencies + build
169
+ git clone https://github.com/cdot65/prisma-airs-cursor-hooks.git
170
+ cd prisma-airs-cursor-hooks
230
171
  npm install
231
-
232
- # Run tests in watch mode
233
- npm run test:watch
234
-
235
- # Type check
236
- npm run typecheck
237
-
238
- # Rebuild after source changes
239
172
  npm run build
240
-
241
- # Build docs
242
- npm run docs:build
243
173
  ```
244
174
 
245
- ### Development mode
175
+ ### Development commands
176
+
177
+ | Command | Description |
178
+ |---------|-------------|
179
+ | `npm run build` | Compile hooks to `dist/` |
180
+ | `npm test` | Run all tests (66 tests across 9 suites) |
181
+ | `npm run typecheck` | TypeScript type checking |
182
+ | `npm run test:watch` | Run tests in watch mode |
183
+ | `npm run validate-connection` | Test AIRS API connectivity |
184
+ | `npm run validate-detection` | Verify prompt injection detection |
185
+ | `npm run install-hooks` | Write AIRS entries to `.cursor/hooks.json` |
186
+ | `npm run install-hooks -- --global` | Write AIRS entries to `~/.cursor/hooks.json` |
187
+ | `npm run uninstall-hooks -- --global` | Remove AIRS entries from global hooks.json |
188
+ | `npm run verify-hooks` | Check hooks are installed and env vars set |
189
+ | `npm run stats` | Show scan statistics from log file |
246
190
 
247
- During development you can run hooks directly from TypeScript source without a build step. This is useful when iterating on hook logic — changes take effect immediately without rebuilding.
191
+ ### Development mode
248
192
 
249
- Manually edit `~/.cursor/hooks.json` (or `.cursor/hooks.json`) to use tsx:
193
+ During development you can run hooks directly from TypeScript source without a build step:
250
194
 
251
195
  ```json
252
196
  {
@@ -254,12 +198,7 @@ Manually edit `~/.cursor/hooks.json` (or `.cursor/hooks.json`) to use tsx:
254
198
  }
255
199
  ```
256
200
 
257
- This adds ~1.5s per hook invocation compared to compiled JS, so switch back to `node dist/...` for production use:
258
-
259
- ```bash
260
- npm run build
261
- npm run install-hooks -- --global
262
- ```
201
+ This adds ~1.5s per hook invocation compared to compiled JS, so switch back to `node dist/...` for production use.
263
202
 
264
203
  ### Project structure
265
204
 
@@ -268,6 +207,7 @@ src/ TypeScript source
268
207
  hooks/
269
208
  before-submit-prompt.ts Cursor beforeSubmitPrompt entry point
270
209
  after-agent-response.ts Cursor afterAgentResponse entry point
210
+ cli.ts CLI entry point (prisma-airs-hooks command)
271
211
  config.ts Config loader (project → global fallback)
272
212
  airs-client.ts SDK wrapper with circuit breaker
273
213
  scanner.ts Scan orchestration + DLP masking + UX messages
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdot65/prisma-airs-cursor-hooks",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Cursor IDE hooks integrating Prisma AIRS scanning into the developer workflow",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  "test": "vitest run",
42
42
  "test:watch": "vitest",
43
43
  "build": "tsc -p tsconfig.build.json",
44
- "prepare": "npm run build",
44
+ "prepack": "npm run build",
45
45
  "typecheck": "tsc --noEmit",
46
46
  "validate-connection": "tsx scripts/validate-connection.ts",
47
47
  "validate-detection": "tsx scripts/validate-detection.ts",
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2022",
4
- "module": "ES2022",
5
- "moduleResolution": "bundler",
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
6
6
  "strict": true,
7
7
  "esModuleInterop": true,
8
8
  "skipLibCheck": true,