self-evolve-framework 1.5.0 → 1.6.1

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