@monoes/monodesign 1.2.18 → 1.2.20
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 +1 -1
- package/cli/engine/detect-antipatterns-browser.js +12 -1
- package/cli/engine/registry/antipatterns-provider.mjs +60 -0
- package/cli/engine/registry/antipatterns-quality.mjs +218 -0
- package/cli/engine/registry/antipatterns-slop.mjs +226 -0
- package/cli/engine/registry/antipatterns.mjs +7 -494
- package/cli/engine/rules/checks-background.mjs +155 -0
- package/cli/engine/rules/checks-css-values.mjs +137 -0
- package/cli/engine/rules/checks-dom-effects.mjs +243 -0
- package/cli/engine/rules/checks-dom.mjs +148 -0
- package/cli/engine/rules/checks-element.mjs +286 -0
- package/cli/engine/rules/checks-html.mjs +204 -0
- package/cli/engine/rules/checks-overflow.mjs +263 -0
- package/cli/engine/rules/checks-page.mjs +465 -0
- package/cli/engine/rules/checks-pure.mjs +453 -0
- package/cli/engine/rules/checks-quality.mjs +447 -0
- package/cli/engine/rules/checks-stylesheet.mjs +324 -0
- package/cli/engine/rules/checks.mjs +98 -2939
- package/package.json +2 -2
- package/skill/scripts/hook-before-edit-shell.mjs +184 -0
- package/skill/scripts/hook-before-edit.mjs +9 -165
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monoes/monodesign",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.20",
|
|
4
4
|
"description": "Frontend design intelligence for AI agents — design tokens, antipattern detection, and the monodesign skill",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"optionalDependencies": {
|
|
47
47
|
"puppeteer": "^25.1.0",
|
|
48
|
-
"@monoes/monobrowse": "1.0.
|
|
48
|
+
"@monoes/monobrowse": "1.0.26"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"prebuild": "node ../../../scripts/build-fs.mjs clean dist tsconfig.tsbuildinfo",
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell-command parsing for the Cursor preToolUse write gate
|
|
3
|
+
* (hook-before-edit.mjs): where a shell command writes, and what it writes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
import { SENSITIVE_PATH, isGeneratedPath } from './hook-lib.mjs';
|
|
10
|
+
|
|
11
|
+
function shellCommand(input) {
|
|
12
|
+
if (typeof input.command === 'string') return input.command;
|
|
13
|
+
if (input.args && typeof input.args.command === 'string') return input.args.command;
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function shellRedirectPath(command) {
|
|
18
|
+
if (!command || typeof command !== 'string') return '';
|
|
19
|
+
const match = command.match(/(?:^|[\s;&|])(?:>>?|1>>?)\s*(?:"([^"]+)"|'([^']+)'|([^<>\s]+))/);
|
|
20
|
+
return (match?.[1] || match?.[2] || match?.[3] || '').trim();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function shellWriteDestination(command) {
|
|
24
|
+
return shellRedirectPath(command) || shellTeeDestination(command) || shellCopyPaths(command)?.dest || shellPythonWriteDestination(command) || '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function shellPythonWriteDestination(command) {
|
|
28
|
+
if (!/\bpython(?:3)?\b/.test(command || '')) return '';
|
|
29
|
+
const directPath = firstMatch(command, /(?:^|[^\w.])(?:pathlib\.)?Path\(\s*(["'])(.*?)\1\s*\)\s*\.write_text\s*\(/);
|
|
30
|
+
if (directPath) return directPath;
|
|
31
|
+
|
|
32
|
+
const pathsByVar = new Map();
|
|
33
|
+
const assignmentRe = /\b([A-Za-z_]\w*)\s*=\s*(?:pathlib\.)?Path\(\s*(["'])(.*?)\2\s*\)/g;
|
|
34
|
+
let assignment;
|
|
35
|
+
while ((assignment = assignmentRe.exec(command))) {
|
|
36
|
+
pathsByVar.set(assignment[1], assignment[3]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const writeVarRe = /\b([A-Za-z_]\w*)\.write_text\s*\(/g;
|
|
40
|
+
let writeVar;
|
|
41
|
+
while ((writeVar = writeVarRe.exec(command))) {
|
|
42
|
+
const candidate = pathsByVar.get(writeVar[1]);
|
|
43
|
+
if (candidate) return candidate;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return firstMatch(command, /\bopen\(\s*(["'])(.*?)\1\s*,\s*(["'])[wax](?:\+)?b?\3/);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function firstMatch(value, re) {
|
|
50
|
+
const match = String(value || '').match(re);
|
|
51
|
+
return (match?.[2] || '').trim();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function shellTeeDestination(command) {
|
|
55
|
+
const words = shellWords(command);
|
|
56
|
+
const teeIndex = words.findIndex((word) => path.basename(word) === 'tee');
|
|
57
|
+
if (teeIndex === -1) return '';
|
|
58
|
+
for (const word of words.slice(teeIndex + 1)) {
|
|
59
|
+
if (['&&', '||', ';', '|'].includes(word)) break;
|
|
60
|
+
if (word === '--') continue;
|
|
61
|
+
if (word.startsWith('-')) continue;
|
|
62
|
+
return word;
|
|
63
|
+
}
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function shellCopiedFileContent(command, cwd) {
|
|
68
|
+
const source = shellCopyPaths(command)?.source;
|
|
69
|
+
if (!source) return '';
|
|
70
|
+
const sourcePath = path.isAbsolute(source) ? source : path.resolve(cwd, source);
|
|
71
|
+
if (!isInsideProject(sourcePath, cwd)) return '';
|
|
72
|
+
if (SENSITIVE_PATH.test(sourcePath) || isGeneratedPath(sourcePath, cwd)) return '';
|
|
73
|
+
try {
|
|
74
|
+
const stat = fs.statSync(sourcePath);
|
|
75
|
+
if (!stat.isFile() || stat.size > 1024 * 1024) return '';
|
|
76
|
+
return fs.readFileSync(sourcePath, 'utf-8');
|
|
77
|
+
} catch {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function shellCopyPaths(command) {
|
|
83
|
+
const words = shellWords(command);
|
|
84
|
+
if (words.length < 3 || path.basename(words[0]) !== 'cp') return null;
|
|
85
|
+
const args = [];
|
|
86
|
+
for (const word of words.slice(1)) {
|
|
87
|
+
if (['&&', '||', ';', '|'].includes(word)) break;
|
|
88
|
+
if (word === '--') continue;
|
|
89
|
+
if (word.startsWith('-')) continue;
|
|
90
|
+
args.push(word);
|
|
91
|
+
}
|
|
92
|
+
if (args.length < 2) return null;
|
|
93
|
+
return { source: args[args.length - 2], dest: args[args.length - 1] };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function shellWords(command) {
|
|
97
|
+
if (!command || typeof command !== 'string') return [];
|
|
98
|
+
const words = [];
|
|
99
|
+
const re = /"((?:\\"|[^"])*)"|'((?:\\'|[^'])*)'|([^\s]+)/g;
|
|
100
|
+
let match;
|
|
101
|
+
while ((match = re.exec(command))) {
|
|
102
|
+
words.push((match[1] ?? match[2] ?? match[3] ?? '').replace(/\\(["'])/g, '$1'));
|
|
103
|
+
}
|
|
104
|
+
return words;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function shellHereDocContent(command) {
|
|
108
|
+
if (!command || typeof command !== 'string') return '';
|
|
109
|
+
const markerMatch = command.match(/<<-?\s*['"]?([A-Za-z0-9_.-]+)['"]?[^\r\n]*\r?\n/);
|
|
110
|
+
if (!markerMatch) return '';
|
|
111
|
+
const marker = markerMatch[1];
|
|
112
|
+
const start = (markerMatch.index || 0) + markerMatch[0].length;
|
|
113
|
+
const rest = command.slice(start);
|
|
114
|
+
const endRe = new RegExp(`\\r?\\n${escapeRegExp(marker)}(?:\\r?\\n|$)`);
|
|
115
|
+
const end = rest.search(endRe);
|
|
116
|
+
return end >= 0 ? rest.slice(0, end) : '';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function shellPythonWriteContent(command) {
|
|
120
|
+
if (!/\bpython(?:3)?\b/.test(command || '')) return '';
|
|
121
|
+
const script = shellHereDocContent(command) || command;
|
|
122
|
+
return pythonStringArg(script, /\.write_text\s*\(\s*/g) || pythonStringArg(script, /\.write\s*\(\s*/g);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function pythonStringArg(script, prefixRe) {
|
|
126
|
+
let prefix;
|
|
127
|
+
while ((prefix = prefixRe.exec(script))) {
|
|
128
|
+
const start = prefixRe.lastIndex;
|
|
129
|
+
const triple = script.slice(start, start + 3);
|
|
130
|
+
if (triple === "'''" || triple === '"""') {
|
|
131
|
+
const end = script.indexOf(triple, start + 3);
|
|
132
|
+
if (end !== -1) return script.slice(start + 3, end);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const quote = script[start];
|
|
136
|
+
if (quote !== '"' && quote !== "'") continue;
|
|
137
|
+
let out = '';
|
|
138
|
+
for (let i = start + 1; i < script.length; i++) {
|
|
139
|
+
const ch = script[i];
|
|
140
|
+
if (ch === '\\') {
|
|
141
|
+
out += script[i + 1] || '';
|
|
142
|
+
i += 1;
|
|
143
|
+
} else if (ch === quote) {
|
|
144
|
+
return out;
|
|
145
|
+
} else {
|
|
146
|
+
out += ch;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return '';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function escapeRegExp(value) {
|
|
154
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function relativePath(filePath, cwd) {
|
|
158
|
+
try {
|
|
159
|
+
const rel = path.relative(cwd, filePath).split(path.sep).join('/');
|
|
160
|
+
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return filePath;
|
|
161
|
+
return rel.split(path.sep).join('/');
|
|
162
|
+
} catch {
|
|
163
|
+
return filePath;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isInsideProject(filePath, cwd) {
|
|
168
|
+
try {
|
|
169
|
+
const rel = path.relative(cwd, filePath).split(path.sep).join('/');
|
|
170
|
+
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
|
|
171
|
+
} catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export {
|
|
177
|
+
shellCommand,
|
|
178
|
+
shellWriteDestination,
|
|
179
|
+
shellCopiedFileContent,
|
|
180
|
+
shellHereDocContent,
|
|
181
|
+
shellPythonWriteContent,
|
|
182
|
+
relativePath,
|
|
183
|
+
isInsideProject,
|
|
184
|
+
};
|
|
@@ -36,6 +36,15 @@ import {
|
|
|
36
36
|
truthy,
|
|
37
37
|
writeAuditLog,
|
|
38
38
|
} from './hook-lib.mjs';
|
|
39
|
+
import {
|
|
40
|
+
shellCommand,
|
|
41
|
+
shellWriteDestination,
|
|
42
|
+
shellCopiedFileContent,
|
|
43
|
+
shellHereDocContent,
|
|
44
|
+
shellPythonWriteContent,
|
|
45
|
+
relativePath,
|
|
46
|
+
isInsideProject,
|
|
47
|
+
} from './hook-before-edit-shell.mjs';
|
|
39
48
|
|
|
40
49
|
async function readStdin() {
|
|
41
50
|
if (process.stdin.isTTY) return '';
|
|
@@ -172,171 +181,6 @@ function readExistingProjectFile(filePath, cwd) {
|
|
|
172
181
|
}
|
|
173
182
|
}
|
|
174
183
|
|
|
175
|
-
function shellCommand(input) {
|
|
176
|
-
if (typeof input.command === 'string') return input.command;
|
|
177
|
-
if (input.args && typeof input.args.command === 'string') return input.args.command;
|
|
178
|
-
return '';
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function shellRedirectPath(command) {
|
|
182
|
-
if (!command || typeof command !== 'string') return '';
|
|
183
|
-
const match = command.match(/(?:^|[\s;&|])(?:>>?|1>>?)\s*(?:"([^"]+)"|'([^']+)'|([^<>\s]+))/);
|
|
184
|
-
return (match?.[1] || match?.[2] || match?.[3] || '').trim();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function shellWriteDestination(command) {
|
|
188
|
-
return shellRedirectPath(command) || shellTeeDestination(command) || shellCopyPaths(command)?.dest || shellPythonWriteDestination(command) || '';
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function shellPythonWriteDestination(command) {
|
|
192
|
-
if (!/\bpython(?:3)?\b/.test(command || '')) return '';
|
|
193
|
-
const directPath = firstMatch(command, /(?:^|[^\w.])(?:pathlib\.)?Path\(\s*(["'])(.*?)\1\s*\)\s*\.write_text\s*\(/);
|
|
194
|
-
if (directPath) return directPath;
|
|
195
|
-
|
|
196
|
-
const pathsByVar = new Map();
|
|
197
|
-
const assignmentRe = /\b([A-Za-z_]\w*)\s*=\s*(?:pathlib\.)?Path\(\s*(["'])(.*?)\2\s*\)/g;
|
|
198
|
-
let assignment;
|
|
199
|
-
while ((assignment = assignmentRe.exec(command))) {
|
|
200
|
-
pathsByVar.set(assignment[1], assignment[3]);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const writeVarRe = /\b([A-Za-z_]\w*)\.write_text\s*\(/g;
|
|
204
|
-
let writeVar;
|
|
205
|
-
while ((writeVar = writeVarRe.exec(command))) {
|
|
206
|
-
const candidate = pathsByVar.get(writeVar[1]);
|
|
207
|
-
if (candidate) return candidate;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return firstMatch(command, /\bopen\(\s*(["'])(.*?)\1\s*,\s*(["'])[wax](?:\+)?b?\3/);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function firstMatch(value, re) {
|
|
214
|
-
const match = String(value || '').match(re);
|
|
215
|
-
return (match?.[2] || '').trim();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function shellTeeDestination(command) {
|
|
219
|
-
const words = shellWords(command);
|
|
220
|
-
const teeIndex = words.findIndex((word) => path.basename(word) === 'tee');
|
|
221
|
-
if (teeIndex === -1) return '';
|
|
222
|
-
for (const word of words.slice(teeIndex + 1)) {
|
|
223
|
-
if (['&&', '||', ';', '|'].includes(word)) break;
|
|
224
|
-
if (word === '--') continue;
|
|
225
|
-
if (word.startsWith('-')) continue;
|
|
226
|
-
return word;
|
|
227
|
-
}
|
|
228
|
-
return '';
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function shellCopiedFileContent(command, cwd) {
|
|
232
|
-
const source = shellCopyPaths(command)?.source;
|
|
233
|
-
if (!source) return '';
|
|
234
|
-
const sourcePath = path.isAbsolute(source) ? source : path.resolve(cwd, source);
|
|
235
|
-
if (!isInsideProject(sourcePath, cwd)) return '';
|
|
236
|
-
if (SENSITIVE_PATH.test(sourcePath) || isGeneratedPath(sourcePath, cwd)) return '';
|
|
237
|
-
try {
|
|
238
|
-
const stat = fs.statSync(sourcePath);
|
|
239
|
-
if (!stat.isFile() || stat.size > 1024 * 1024) return '';
|
|
240
|
-
return fs.readFileSync(sourcePath, 'utf-8');
|
|
241
|
-
} catch {
|
|
242
|
-
return '';
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function shellCopyPaths(command) {
|
|
247
|
-
const words = shellWords(command);
|
|
248
|
-
if (words.length < 3 || path.basename(words[0]) !== 'cp') return null;
|
|
249
|
-
const args = [];
|
|
250
|
-
for (const word of words.slice(1)) {
|
|
251
|
-
if (['&&', '||', ';', '|'].includes(word)) break;
|
|
252
|
-
if (word === '--') continue;
|
|
253
|
-
if (word.startsWith('-')) continue;
|
|
254
|
-
args.push(word);
|
|
255
|
-
}
|
|
256
|
-
if (args.length < 2) return null;
|
|
257
|
-
return { source: args[args.length - 2], dest: args[args.length - 1] };
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function shellWords(command) {
|
|
261
|
-
if (!command || typeof command !== 'string') return [];
|
|
262
|
-
const words = [];
|
|
263
|
-
const re = /"((?:\\"|[^"])*)"|'((?:\\'|[^'])*)'|([^\s]+)/g;
|
|
264
|
-
let match;
|
|
265
|
-
while ((match = re.exec(command))) {
|
|
266
|
-
words.push((match[1] ?? match[2] ?? match[3] ?? '').replace(/\\(["'])/g, '$1'));
|
|
267
|
-
}
|
|
268
|
-
return words;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function shellHereDocContent(command) {
|
|
272
|
-
if (!command || typeof command !== 'string') return '';
|
|
273
|
-
const markerMatch = command.match(/<<-?\s*['"]?([A-Za-z0-9_.-]+)['"]?[^\r\n]*\r?\n/);
|
|
274
|
-
if (!markerMatch) return '';
|
|
275
|
-
const marker = markerMatch[1];
|
|
276
|
-
const start = (markerMatch.index || 0) + markerMatch[0].length;
|
|
277
|
-
const rest = command.slice(start);
|
|
278
|
-
const endRe = new RegExp(`\\r?\\n${escapeRegExp(marker)}(?:\\r?\\n|$)`);
|
|
279
|
-
const end = rest.search(endRe);
|
|
280
|
-
return end >= 0 ? rest.slice(0, end) : '';
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function shellPythonWriteContent(command) {
|
|
284
|
-
if (!/\bpython(?:3)?\b/.test(command || '')) return '';
|
|
285
|
-
const script = shellHereDocContent(command) || command;
|
|
286
|
-
return pythonStringArg(script, /\.write_text\s*\(\s*/g) || pythonStringArg(script, /\.write\s*\(\s*/g);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
function pythonStringArg(script, prefixRe) {
|
|
290
|
-
let prefix;
|
|
291
|
-
while ((prefix = prefixRe.exec(script))) {
|
|
292
|
-
const start = prefixRe.lastIndex;
|
|
293
|
-
const triple = script.slice(start, start + 3);
|
|
294
|
-
if (triple === "'''" || triple === '"""') {
|
|
295
|
-
const end = script.indexOf(triple, start + 3);
|
|
296
|
-
if (end !== -1) return script.slice(start + 3, end);
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
const quote = script[start];
|
|
300
|
-
if (quote !== '"' && quote !== "'") continue;
|
|
301
|
-
let out = '';
|
|
302
|
-
for (let i = start + 1; i < script.length; i++) {
|
|
303
|
-
const ch = script[i];
|
|
304
|
-
if (ch === '\\') {
|
|
305
|
-
out += script[i + 1] || '';
|
|
306
|
-
i += 1;
|
|
307
|
-
} else if (ch === quote) {
|
|
308
|
-
return out;
|
|
309
|
-
} else {
|
|
310
|
-
out += ch;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return '';
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function escapeRegExp(value) {
|
|
318
|
-
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function relativePath(filePath, cwd) {
|
|
322
|
-
try {
|
|
323
|
-
const rel = path.relative(cwd, filePath).split(path.sep).join('/');
|
|
324
|
-
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return filePath;
|
|
325
|
-
return rel.split(path.sep).join('/');
|
|
326
|
-
} catch {
|
|
327
|
-
return filePath;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function isInsideProject(filePath, cwd) {
|
|
332
|
-
try {
|
|
333
|
-
const rel = path.relative(cwd, filePath).split(path.sep).join('/');
|
|
334
|
-
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
|
|
335
|
-
} catch {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
184
|
// The static HTML engine reads its input from disk, but preToolUse only has
|
|
341
185
|
// the proposed content. Stage it in a temp file so html-engine targets get the
|
|
342
186
|
// same DOM-structural rules pre-write that runHook applies post-edit.
|