claudecode-omc 5.9.1 → 5.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/.local/settings/settings.json +8 -0
  2. package/.omc-curation/governance.json +3 -0
  3. package/.omc-curation/sources.lock.json +5 -0
  4. package/README.md +10 -1
  5. package/bundled/manifest.json +2 -1
  6. package/bundled/upstream/impeccable/.omc-source/bundle.json +20 -0
  7. package/bundled/upstream/impeccable/.omc-source/provenance.json +105 -0
  8. package/bundled/upstream/impeccable/agents/impeccable-manual-edit-applier.md +97 -0
  9. package/bundled/upstream/impeccable/skills/impeccable/SKILL.md +168 -0
  10. package/bundled/upstream/impeccable/skills/impeccable/reference/adapt.md +311 -0
  11. package/bundled/upstream/impeccable/skills/impeccable/reference/animate.md +201 -0
  12. package/bundled/upstream/impeccable/skills/impeccable/reference/audit.md +133 -0
  13. package/bundled/upstream/impeccable/skills/impeccable/reference/bolder.md +113 -0
  14. package/bundled/upstream/impeccable/skills/impeccable/reference/brand.md +108 -0
  15. package/bundled/upstream/impeccable/skills/impeccable/reference/clarify.md +288 -0
  16. package/bundled/upstream/impeccable/skills/impeccable/reference/codex.md +105 -0
  17. package/bundled/upstream/impeccable/skills/impeccable/reference/colorize.md +257 -0
  18. package/bundled/upstream/impeccable/skills/impeccable/reference/craft.md +123 -0
  19. package/bundled/upstream/impeccable/skills/impeccable/reference/critique.md +767 -0
  20. package/bundled/upstream/impeccable/skills/impeccable/reference/delight.md +302 -0
  21. package/bundled/upstream/impeccable/skills/impeccable/reference/distill.md +111 -0
  22. package/bundled/upstream/impeccable/skills/impeccable/reference/document.md +429 -0
  23. package/bundled/upstream/impeccable/skills/impeccable/reference/extract.md +69 -0
  24. package/bundled/upstream/impeccable/skills/impeccable/reference/harden.md +347 -0
  25. package/bundled/upstream/impeccable/skills/impeccable/reference/hooks.md +88 -0
  26. package/bundled/upstream/impeccable/skills/impeccable/reference/init.md +172 -0
  27. package/bundled/upstream/impeccable/skills/impeccable/reference/interaction-design.md +189 -0
  28. package/bundled/upstream/impeccable/skills/impeccable/reference/layout.md +161 -0
  29. package/bundled/upstream/impeccable/skills/impeccable/reference/live.md +718 -0
  30. package/bundled/upstream/impeccable/skills/impeccable/reference/onboard.md +234 -0
  31. package/bundled/upstream/impeccable/skills/impeccable/reference/optimize.md +258 -0
  32. package/bundled/upstream/impeccable/skills/impeccable/reference/overdrive.md +130 -0
  33. package/bundled/upstream/impeccable/skills/impeccable/reference/polish.md +241 -0
  34. package/bundled/upstream/impeccable/skills/impeccable/reference/product.md +60 -0
  35. package/bundled/upstream/impeccable/skills/impeccable/reference/quieter.md +99 -0
  36. package/bundled/upstream/impeccable/skills/impeccable/reference/shape.md +165 -0
  37. package/bundled/upstream/impeccable/skills/impeccable/reference/typeset.md +279 -0
  38. package/bundled/upstream/impeccable/skills/impeccable/scripts/command-metadata.json +94 -0
  39. package/bundled/upstream/impeccable/skills/impeccable/scripts/context-signals.mjs +225 -0
  40. package/bundled/upstream/impeccable/skills/impeccable/scripts/context.mjs +280 -0
  41. package/bundled/upstream/impeccable/skills/impeccable/scripts/critique-storage.mjs +242 -0
  42. package/bundled/upstream/impeccable/skills/impeccable/scripts/detect-csp.mjs +198 -0
  43. package/bundled/upstream/impeccable/skills/impeccable/scripts/detect.mjs +21 -0
  44. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/browser/injected/index.mjs +1735 -0
  45. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/cli/main.mjs +244 -0
  46. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +4907 -0
  47. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/detect-antipatterns.mjs +43 -0
  48. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +252 -0
  49. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +552 -0
  50. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +1013 -0
  51. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +208 -0
  52. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +189 -0
  53. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/findings.mjs +12 -0
  54. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/node/file-system.mjs +198 -0
  55. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/profile/profiler.mjs +166 -0
  56. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/registry/antipatterns.mjs +419 -0
  57. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/rules/checks.mjs +2671 -0
  58. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/shared/color.mjs +124 -0
  59. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/shared/constants.mjs +101 -0
  60. package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/shared/page.mjs +7 -0
  61. package/bundled/upstream/impeccable/skills/impeccable/scripts/hook-admin.mjs +574 -0
  62. package/bundled/upstream/impeccable/skills/impeccable/scripts/hook-before-edit.mjs +473 -0
  63. package/bundled/upstream/impeccable/skills/impeccable/scripts/hook-lib.mjs +1286 -0
  64. package/bundled/upstream/impeccable/skills/impeccable/scripts/hook.mjs +61 -0
  65. package/bundled/upstream/impeccable/skills/impeccable/scripts/lib/design-parser.mjs +835 -0
  66. package/bundled/upstream/impeccable/skills/impeccable/scripts/lib/impeccable-paths.mjs +126 -0
  67. package/bundled/upstream/impeccable/skills/impeccable/scripts/lib/is-generated.mjs +69 -0
  68. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/browser-script-parts.mjs +49 -0
  69. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/completion.mjs +19 -0
  70. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/event-validation.mjs +137 -0
  71. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/insert-ui.mjs +458 -0
  72. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/manual-apply.mjs +939 -0
  73. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/manual-edit-routes.mjs +357 -0
  74. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/manual-edits-buffer.mjs +152 -0
  75. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/session-store.mjs +289 -0
  76. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/svelte-component.mjs +826 -0
  77. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/sveltekit-adapter.mjs +274 -0
  78. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/ui-core.mjs +180 -0
  79. package/bundled/upstream/impeccable/skills/impeccable/scripts/live/vocabulary.mjs +36 -0
  80. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-accept.mjs +812 -0
  81. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-browser-dom.js +146 -0
  82. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-browser-session.js +123 -0
  83. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-browser.js +11086 -0
  84. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-commit-manual-edits.mjs +1241 -0
  85. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-complete.mjs +75 -0
  86. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-copy-edit-agent.mjs +683 -0
  87. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-discard-manual-edits.mjs +51 -0
  88. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-inject.mjs +583 -0
  89. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-insert.mjs +272 -0
  90. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-manual-edit-evidence.mjs +363 -0
  91. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-poll.mjs +379 -0
  92. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-resume.mjs +94 -0
  93. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-server.mjs +1134 -0
  94. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-status.mjs +61 -0
  95. package/bundled/upstream/impeccable/skills/impeccable/scripts/live-wrap.mjs +894 -0
  96. package/bundled/upstream/impeccable/skills/impeccable/scripts/live.mjs +246 -0
  97. package/bundled/upstream/impeccable/skills/impeccable/scripts/modern-screenshot.umd.js +14 -0
  98. package/bundled/upstream/impeccable/skills/impeccable/scripts/palette.mjs +633 -0
  99. package/bundled/upstream/impeccable/skills/impeccable/scripts/pin.mjs +214 -0
  100. package/package.json +1 -1
  101. package/src/cli/source.js +6 -0
  102. package/src/config/sources.js +15 -0
  103. package/src/merge/content-patch.js +4 -0
@@ -0,0 +1,473 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Impeccable design hook — Cursor preToolUse write gate.
4
+ *
5
+ * Cursor's stop hook is not consistently dispatched by the headless agent, so
6
+ * this hook checks proposed Write/Edit content before it lands. It only denies
7
+ * writes when the real detector finds an issue in the proposed UI content.
8
+ *
9
+ * Contract: never break a turn accidentally. On malformed input or internal
10
+ * errors, allow the tool and exit 0.
11
+ */
12
+
13
+ import fs from 'node:fs';
14
+ import path from 'node:path';
15
+
16
+ import {
17
+ ALLOWED_EXTS,
18
+ EDIT_COUNT_THRESHOLD,
19
+ GENERATED_PATH,
20
+ SENSITIVE_PATH,
21
+ filterFindings,
22
+ loadDetector,
23
+ matchesAnyGlob,
24
+ persistCache,
25
+ readCache,
26
+ readConfig,
27
+ renderTemplate,
28
+ resolveProjectCwd,
29
+ truthy,
30
+ writeAuditLog,
31
+ } from './hook-lib.mjs';
32
+
33
+ async function readStdin() {
34
+ if (process.stdin.isTTY) return '';
35
+ const chunks = [];
36
+ for await (const chunk of process.stdin) chunks.push(chunk);
37
+ return Buffer.concat(chunks).toString('utf-8');
38
+ }
39
+
40
+ function done(payload = null) {
41
+ if (payload) process.stdout.write(JSON.stringify(payload));
42
+ process.exit(0);
43
+ }
44
+
45
+ function allow(extra = {}, payload = {}) {
46
+ writeAuditLog(process.env, {
47
+ ts: new Date().toISOString(),
48
+ event: 'preToolUse',
49
+ ...extra,
50
+ });
51
+ return done({ permission: 'allow', ...payload });
52
+ }
53
+
54
+ function deny(message, audit) {
55
+ writeAuditLog(process.env, {
56
+ ts: new Date().toISOString(),
57
+ event: 'preToolUse',
58
+ blocked: true,
59
+ ...audit,
60
+ });
61
+ return done({
62
+ permission: 'deny',
63
+ user_message: message,
64
+ agent_message: message,
65
+ });
66
+ }
67
+
68
+ function toolInput(event) {
69
+ return event?.tool_input && typeof event.tool_input === 'object' ? event.tool_input : {};
70
+ }
71
+
72
+ function proposedFilePath(event, cwd) {
73
+ const input = toolInput(event);
74
+ const raw = input.file_path || input.path || input.target_file || event?.file_path;
75
+ const candidate = typeof raw === 'string' && raw.trim()
76
+ ? raw
77
+ : shellWriteDestination(shellCommand(input));
78
+ if (typeof candidate !== 'string' || !candidate.trim()) return '';
79
+ return path.isAbsolute(candidate) ? candidate : path.resolve(cwd, candidate);
80
+ }
81
+
82
+ function proposedContent(event, cwd, filePath) {
83
+ const input = toolInput(event);
84
+ for (const key of ['content', 'streamContent', 'text']) {
85
+ if (typeof input[key] === 'string') return input[key];
86
+ }
87
+
88
+ const editProjection = projectedEditContent(input, filePath, cwd);
89
+ if (editProjection !== undefined) return editProjection;
90
+
91
+ if (hasFragmentEditContent(input)) {
92
+ return { skipped: 'fragment-only-edit' };
93
+ }
94
+
95
+ const command = shellCommand(input);
96
+ const pythonContent = shellPythonWriteContent(command);
97
+ if (pythonContent) return pythonContent;
98
+ const shellContent = shellHereDocContent(command);
99
+ if (shellContent) return shellContent;
100
+ const copiedContent = shellCopiedFileContent(command, cwd);
101
+ if (copiedContent) return copiedContent;
102
+ return '';
103
+ }
104
+
105
+ function hasFragmentEditContent(input) {
106
+ if (!input || typeof input !== 'object') return false;
107
+ if (typeof input.new_string === 'string' || typeof input.newString === 'string' || typeof input.new_str === 'string' || typeof input.replacement === 'string') {
108
+ return true;
109
+ }
110
+ return Array.isArray(input.edits) && input.edits.some((edit) => edit && typeof edit === 'object');
111
+ }
112
+
113
+ function projectedEditContent(input, filePath, cwd) {
114
+ if (!filePath) return undefined;
115
+ const singleOld = firstString(input, ['old_string', 'oldString', 'old_str', 'target']);
116
+ const singleNew = firstString(input, ['new_string', 'newString', 'new_str', 'replacement']);
117
+ if (singleOld !== undefined || singleNew !== undefined) {
118
+ if (singleOld === undefined || singleNew === undefined) return { skipped: 'fragment-only-edit' };
119
+ const original = readExistingProjectFile(filePath, cwd);
120
+ if (original === null) return { skipped: 'edit-original-unreadable' };
121
+ const projected = replaceOnce(original, singleOld, singleNew);
122
+ return projected === null ? { skipped: 'edit-old-string-missing' } : projected;
123
+ }
124
+
125
+ if (!Array.isArray(input.edits)) return undefined;
126
+ const original = readExistingProjectFile(filePath, cwd);
127
+ if (original === null) return { skipped: 'edit-original-unreadable' };
128
+
129
+ let projected = original;
130
+ for (const edit of input.edits) {
131
+ if (!edit || typeof edit !== 'object') return { skipped: 'fragment-only-edit' };
132
+ const oldString = firstString(edit, ['old_string', 'oldString', 'old_str', 'target']);
133
+ const newString = firstString(edit, ['new_string', 'newString', 'new_str', 'replacement']);
134
+ if (oldString === undefined || newString === undefined) return { skipped: 'fragment-only-edit' };
135
+ const next = replaceOnce(projected, oldString, newString);
136
+ if (next === null) return { skipped: 'edit-old-string-missing' };
137
+ projected = next;
138
+ }
139
+ return projected;
140
+ }
141
+
142
+ function firstString(obj, keys) {
143
+ for (const key of keys) {
144
+ if (typeof obj?.[key] === 'string') return obj[key];
145
+ }
146
+ return undefined;
147
+ }
148
+
149
+ function replaceOnce(original, oldString, newString) {
150
+ if (oldString === '') return null;
151
+ const index = original.indexOf(oldString);
152
+ if (index === -1) return null;
153
+ return `${original.slice(0, index)}${newString}${original.slice(index + oldString.length)}`;
154
+ }
155
+
156
+ function readExistingProjectFile(filePath, cwd) {
157
+ if (!isInsideProject(filePath, cwd)) return null;
158
+ if (SENSITIVE_PATH.test(filePath) || GENERATED_PATH.test(filePath)) return null;
159
+ try {
160
+ const stat = fs.statSync(filePath);
161
+ if (!stat.isFile() || stat.size > 1024 * 1024) return null;
162
+ return fs.readFileSync(filePath, 'utf-8');
163
+ } catch {
164
+ return null;
165
+ }
166
+ }
167
+
168
+ function shellCommand(input) {
169
+ if (typeof input.command === 'string') return input.command;
170
+ if (input.args && typeof input.args.command === 'string') return input.args.command;
171
+ return '';
172
+ }
173
+
174
+ function shellRedirectPath(command) {
175
+ if (!command || typeof command !== 'string') return '';
176
+ const match = command.match(/(?:^|[\s;&|])(?:>>?|1>>?)\s*(?:"([^"]+)"|'([^']+)'|([^<>\s]+))/);
177
+ return (match?.[1] || match?.[2] || match?.[3] || '').trim();
178
+ }
179
+
180
+ function shellWriteDestination(command) {
181
+ return shellRedirectPath(command) || shellTeeDestination(command) || shellCopyPaths(command)?.dest || shellPythonWriteDestination(command) || '';
182
+ }
183
+
184
+ function shellPythonWriteDestination(command) {
185
+ if (!/\bpython(?:3)?\b/.test(command || '')) return '';
186
+ const directPath = firstMatch(command, /(?:^|[^\w.])(?:pathlib\.)?Path\(\s*(["'])(.*?)\1\s*\)\s*\.write_text\s*\(/);
187
+ if (directPath) return directPath;
188
+
189
+ const pathsByVar = new Map();
190
+ const assignmentRe = /\b([A-Za-z_]\w*)\s*=\s*(?:pathlib\.)?Path\(\s*(["'])(.*?)\2\s*\)/g;
191
+ let assignment;
192
+ while ((assignment = assignmentRe.exec(command))) {
193
+ pathsByVar.set(assignment[1], assignment[3]);
194
+ }
195
+
196
+ const writeVarRe = /\b([A-Za-z_]\w*)\.write_text\s*\(/g;
197
+ let writeVar;
198
+ while ((writeVar = writeVarRe.exec(command))) {
199
+ const candidate = pathsByVar.get(writeVar[1]);
200
+ if (candidate) return candidate;
201
+ }
202
+
203
+ return firstMatch(command, /\bopen\(\s*(["'])(.*?)\1\s*,\s*(["'])[wax](?:\+)?b?\3/);
204
+ }
205
+
206
+ function firstMatch(value, re) {
207
+ const match = String(value || '').match(re);
208
+ return (match?.[2] || '').trim();
209
+ }
210
+
211
+ function shellTeeDestination(command) {
212
+ const words = shellWords(command);
213
+ const teeIndex = words.findIndex((word) => path.basename(word) === 'tee');
214
+ if (teeIndex === -1) return '';
215
+ for (const word of words.slice(teeIndex + 1)) {
216
+ if (['&&', '||', ';', '|'].includes(word)) break;
217
+ if (word === '--') continue;
218
+ if (word.startsWith('-')) continue;
219
+ return word;
220
+ }
221
+ return '';
222
+ }
223
+
224
+ function shellCopiedFileContent(command, cwd) {
225
+ const source = shellCopyPaths(command)?.source;
226
+ if (!source) return '';
227
+ const sourcePath = path.isAbsolute(source) ? source : path.resolve(cwd, source);
228
+ if (!isInsideProject(sourcePath, cwd)) return '';
229
+ if (SENSITIVE_PATH.test(sourcePath) || GENERATED_PATH.test(sourcePath)) return '';
230
+ try {
231
+ const stat = fs.statSync(sourcePath);
232
+ if (!stat.isFile() || stat.size > 1024 * 1024) return '';
233
+ return fs.readFileSync(sourcePath, 'utf-8');
234
+ } catch {
235
+ return '';
236
+ }
237
+ }
238
+
239
+ function shellCopyPaths(command) {
240
+ const words = shellWords(command);
241
+ if (words.length < 3 || path.basename(words[0]) !== 'cp') return null;
242
+ const args = [];
243
+ for (const word of words.slice(1)) {
244
+ if (['&&', '||', ';', '|'].includes(word)) break;
245
+ if (word === '--') continue;
246
+ if (word.startsWith('-')) continue;
247
+ args.push(word);
248
+ }
249
+ if (args.length < 2) return null;
250
+ return { source: args[args.length - 2], dest: args[args.length - 1] };
251
+ }
252
+
253
+ function shellWords(command) {
254
+ if (!command || typeof command !== 'string') return [];
255
+ const words = [];
256
+ const re = /"((?:\\"|[^"])*)"|'((?:\\'|[^'])*)'|([^\s]+)/g;
257
+ let match;
258
+ while ((match = re.exec(command))) {
259
+ words.push((match[1] ?? match[2] ?? match[3] ?? '').replace(/\\(["'])/g, '$1'));
260
+ }
261
+ return words;
262
+ }
263
+
264
+ function shellHereDocContent(command) {
265
+ if (!command || typeof command !== 'string') return '';
266
+ const markerMatch = command.match(/<<-?\s*['"]?([A-Za-z0-9_.-]+)['"]?[^\r\n]*\r?\n/);
267
+ if (!markerMatch) return '';
268
+ const marker = markerMatch[1];
269
+ const start = (markerMatch.index || 0) + markerMatch[0].length;
270
+ const rest = command.slice(start);
271
+ const endRe = new RegExp(`\\r?\\n${escapeRegExp(marker)}(?:\\r?\\n|$)`);
272
+ const end = rest.search(endRe);
273
+ return end >= 0 ? rest.slice(0, end) : '';
274
+ }
275
+
276
+ function shellPythonWriteContent(command) {
277
+ if (!/\bpython(?:3)?\b/.test(command || '')) return '';
278
+ const script = shellHereDocContent(command) || command;
279
+ return pythonStringArg(script, /\.write_text\s*\(\s*/g) || pythonStringArg(script, /\.write\s*\(\s*/g);
280
+ }
281
+
282
+ function pythonStringArg(script, prefixRe) {
283
+ let prefix;
284
+ while ((prefix = prefixRe.exec(script))) {
285
+ const start = prefixRe.lastIndex;
286
+ const triple = script.slice(start, start + 3);
287
+ if (triple === "'''" || triple === '"""') {
288
+ const end = script.indexOf(triple, start + 3);
289
+ if (end !== -1) return script.slice(start + 3, end);
290
+ continue;
291
+ }
292
+ const quote = script[start];
293
+ if (quote !== '"' && quote !== "'") continue;
294
+ let out = '';
295
+ for (let i = start + 1; i < script.length; i++) {
296
+ const ch = script[i];
297
+ if (ch === '\\') {
298
+ out += script[i + 1] || '';
299
+ i += 1;
300
+ } else if (ch === quote) {
301
+ return out;
302
+ } else {
303
+ out += ch;
304
+ }
305
+ }
306
+ }
307
+ return '';
308
+ }
309
+
310
+ function escapeRegExp(value) {
311
+ return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
312
+ }
313
+
314
+ function relativePath(filePath, cwd) {
315
+ try {
316
+ const rel = path.relative(cwd, filePath);
317
+ if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return filePath;
318
+ return rel.split(path.sep).join('/');
319
+ } catch {
320
+ return filePath;
321
+ }
322
+ }
323
+
324
+ function isInsideProject(filePath, cwd) {
325
+ try {
326
+ const rel = path.relative(cwd, filePath);
327
+ return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
328
+ } catch {
329
+ return false;
330
+ }
331
+ }
332
+
333
+ function cursorBlockMessage(findings, filePath, config, cwd) {
334
+ const rendered = renderTemplate(findings, filePath, config, { cwd });
335
+ const blocked = rendered.replace(
336
+ '[impeccable@1] Design hook findings requiring review',
337
+ '[impeccable@1] Impeccable design hook blocked this write before it landed. Design hook findings requiring review',
338
+ );
339
+ return blocked.length > 4000 ? `${blocked.slice(0, 3984)}\n...(truncated)` : blocked;
340
+ }
341
+
342
+ function findingSignature(findings) {
343
+ return findings
344
+ .map((finding) => `${finding.antipattern || 'unknown'}:${finding.line || 0}`)
345
+ .sort()
346
+ .join('|');
347
+ }
348
+
349
+ function bumpCursorDenial(cache, sessionId, filePath, findings) {
350
+ const session = cache.sessions[sessionId] || { updatedAt: Date.now(), files: {} };
351
+ cache.sessions[sessionId] = session;
352
+ session.updatedAt = Date.now();
353
+ const fileEntry = session.files[filePath] || { editCount: 0, findings: [] };
354
+ session.files[filePath] = fileEntry;
355
+ const key = findingSignature(findings);
356
+ fileEntry.cursorDenials = fileEntry.cursorDenials && typeof fileEntry.cursorDenials === 'object'
357
+ ? fileEntry.cursorDenials
358
+ : {};
359
+ fileEntry.cursorDenials[key] = (fileEntry.cursorDenials[key] || 0) + 1;
360
+ return { key, count: fileEntry.cursorDenials[key] };
361
+ }
362
+
363
+ async function main() {
364
+ if (truthy(process.env.IMPECCABLE_HOOK_DISABLED)) {
365
+ return allow({ skipped: 'env-disabled' });
366
+ }
367
+
368
+ let event = null;
369
+ try {
370
+ const raw = await readStdin();
371
+ if (raw) event = JSON.parse(raw);
372
+ } catch {
373
+ return allow({ skipped: 'stdin-malformed' });
374
+ }
375
+
376
+ if (!event || typeof event !== 'object') {
377
+ return allow({ skipped: 'stdin-empty' });
378
+ }
379
+
380
+ const cwd = resolveProjectCwd(event);
381
+ const started = Date.now();
382
+ const filePath = proposedFilePath(event, cwd);
383
+ const audit = {
384
+ harness: 'cursor',
385
+ cwd,
386
+ tool: event.tool_name || null,
387
+ file: filePath || null,
388
+ };
389
+
390
+ if (!filePath) return allow({ ...audit, skipped: 'no-file-path', durationMs: Date.now() - started });
391
+ if (!isInsideProject(filePath, cwd)) return allow({ ...audit, skipped: 'outside-project', durationMs: Date.now() - started });
392
+ if (SENSITIVE_PATH.test(filePath)) return allow({ ...audit, skipped: 'sensitive', durationMs: Date.now() - started });
393
+ if (GENERATED_PATH.test(filePath)) return allow({ ...audit, skipped: 'generated', durationMs: Date.now() - started });
394
+
395
+ const ext = path.extname(filePath).toLowerCase();
396
+ audit.ext = ext;
397
+ if (!ALLOWED_EXTS.has(ext)) return allow({ ...audit, skipped: 'extension', durationMs: Date.now() - started });
398
+
399
+ const contentResult = proposedContent(event, cwd, filePath);
400
+ if (contentResult && typeof contentResult === 'object' && contentResult.skipped) {
401
+ return allow({ ...audit, skipped: contentResult.skipped, durationMs: Date.now() - started });
402
+ }
403
+ const content = typeof contentResult === 'string' ? contentResult : '';
404
+ if (!content) return allow({ ...audit, skipped: 'no-proposed-content', durationMs: Date.now() - started });
405
+
406
+ const config = readConfig(cwd);
407
+ if (config.enabled === false) return allow({ ...audit, skipped: 'config-disabled', durationMs: Date.now() - started });
408
+
409
+ const rel = relativePath(filePath, cwd);
410
+ if (matchesAnyGlob(rel, config.ignoreFiles) || matchesAnyGlob(filePath, config.ignoreFiles)) {
411
+ return allow({ ...audit, skipped: 'config-ignore-file', durationMs: Date.now() - started });
412
+ }
413
+
414
+ const detector = await loadDetector();
415
+ if (!detector || typeof detector.detectText !== 'function') {
416
+ return allow({ ...audit, skipped: 'detector-missing', durationMs: Date.now() - started });
417
+ }
418
+
419
+ let findings = [];
420
+ try {
421
+ findings = await detector.detectText(content, filePath);
422
+ } catch {
423
+ return allow({ ...audit, error: 'detector-threw', durationMs: Date.now() - started });
424
+ }
425
+
426
+ const filtered = filterFindings(findings || [], content, ext, config);
427
+ if (filtered.length === 0) {
428
+ return allow({
429
+ ...audit,
430
+ findings: (findings || []).length,
431
+ blockedFindings: 0,
432
+ durationMs: Date.now() - started,
433
+ });
434
+ }
435
+
436
+ const message = cursorBlockMessage(filtered, filePath, config, cwd);
437
+ const sessionId = event.session_id || event.conversation_id || 'unknown';
438
+ const cache = readCache(cwd);
439
+ const denial = bumpCursorDenial(cache, sessionId, filePath, filtered);
440
+ persistCache(cwd, cache);
441
+ if (denial.count > EDIT_COUNT_THRESHOLD) {
442
+ const warning = `${message}\n\nThis is the ${denial.count}th repeated denial for the same file and finding signature, so Impeccable is allowing this write to avoid a loop. Reconsider the issue immediately after the tool runs.`;
443
+ return allow({
444
+ ...audit,
445
+ findings: (findings || []).length,
446
+ blockedFindings: filtered.length,
447
+ cursorDenialKey: denial.key,
448
+ cursorDenialCount: denial.count,
449
+ downgraded: true,
450
+ chars: warning.length,
451
+ durationMs: Date.now() - started,
452
+ }, {
453
+ user_message: warning,
454
+ agent_message: warning,
455
+ });
456
+ }
457
+ return deny(message, {
458
+ ...audit,
459
+ findings: (findings || []).length,
460
+ blockedFindings: filtered.length,
461
+ cursorDenialKey: denial.key,
462
+ cursorDenialCount: denial.count,
463
+ chars: message.length,
464
+ durationMs: Date.now() - started,
465
+ });
466
+ }
467
+
468
+ main().catch((err) => {
469
+ if (process.env.IMPECCABLE_HOOK_DEBUG) {
470
+ process.stderr.write(`[impeccable-hook-before-edit] ${err}\n`);
471
+ }
472
+ done({ permission: 'allow' });
473
+ });