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,552 @@
1
+ import { GENERIC_FONTS } from '../../shared/constants.mjs';
2
+ import { isFullPage } from '../../shared/page.mjs';
3
+ import { finding } from '../../findings.mjs';
4
+ import { filterByProviders } from '../../registry/antipatterns.mjs';
5
+ import { profileFindings, profileStep } from '../../profile/profiler.mjs';
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // Regex fallback (non-HTML files: CSS, JSX, TSX, etc.)
9
+ // ---------------------------------------------------------------------------
10
+
11
+ const hasRounded = (line) => /\brounded(?:-\w+)?\b/.test(line);
12
+ const hasBorderRadius = (line) => /border-radius/i.test(line);
13
+ const isSafeElement = (line) => /<(?:blockquote|nav[\s>]|pre[\s>]|code[\s>]|a\s|input[\s>]|span[\s>])/i.test(line);
14
+
15
+ /** Strip HTML to plain text — drops script/style/comments/tags so
16
+ * content-text analyzers don't false-positive on code or CSS. */
17
+ function stripHtmlToText(html) {
18
+ return html
19
+ .replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, ' ')
20
+ .replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, ' ')
21
+ .replace(/<!--[\s\S]*?-->/g, ' ')
22
+ .replace(/<[^>]+>/g, ' ')
23
+ .replace(/\s+/g, ' ');
24
+ }
25
+
26
+ const PAGE_ANALYZER_EXTS = new Set(['.html', '.htm', '.astro', '.vue', '.svelte']);
27
+
28
+ function extFromFilePath(filePath) {
29
+ return filePath ? (filePath.match(/\.\w+$/)?.[0] || '').toLowerCase() : '';
30
+ }
31
+
32
+ function shouldRunPageAnalyzers(content, filePath) {
33
+ if (!isFullPage(content)) return false;
34
+ const ext = extFromFilePath(filePath);
35
+ return !ext || PAGE_ANALYZER_EXTS.has(ext);
36
+ }
37
+
38
+ function isNeutralBorderColor(str) {
39
+ const m = str.match(/solid\s+(#[0-9a-f]{3,8}|rgba?\([^)]+\)|\w+)/i);
40
+ if (!m) return false;
41
+ const c = m[1].toLowerCase();
42
+ if (['gray', 'grey', 'silver', 'white', 'black', 'transparent', 'currentcolor'].includes(c)) return true;
43
+ const hex = c.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/);
44
+ if (hex) {
45
+ const [r, g, b] = [parseInt(hex[1], 16), parseInt(hex[2], 16), parseInt(hex[3], 16)];
46
+ return (Math.max(r, g, b) - Math.min(r, g, b)) < 30;
47
+ }
48
+ const shex = c.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/);
49
+ if (shex) {
50
+ const [r, g, b] = [parseInt(shex[1] + shex[1], 16), parseInt(shex[2] + shex[2], 16), parseInt(shex[3] + shex[3], 16)];
51
+ return (Math.max(r, g, b) - Math.min(r, g, b)) < 30;
52
+ }
53
+ return false;
54
+ }
55
+
56
+ const REGEX_MATCHERS = [
57
+ // --- Side-tab ---
58
+ { id: 'side-tab', regex: /\bborder-[lrse]-(\d+)\b/g,
59
+ test: (m, line) => { const n = +m[1]; return hasRounded(line) ? n >= 1 : n >= 4; },
60
+ fmt: (m) => m[0] },
61
+ { id: 'side-tab', regex: /border-(?:left|right)\s*:\s*(\d+)px\s+solid[^;]*/gi,
62
+ test: (m, line) => { if (isSafeElement(line)) return false; if (isNeutralBorderColor(m[0])) return false; const n = +m[1]; return hasBorderRadius(line) ? n >= 1 : n >= 3; },
63
+ fmt: (m) => m[0].replace(/\s*;?\s*$/, '') },
64
+ { id: 'side-tab', regex: /border-(?:left|right)-width\s*:\s*(\d+)px/gi,
65
+ test: (m, line) => !isSafeElement(line) && +m[1] >= 3,
66
+ fmt: (m) => m[0] },
67
+ { id: 'side-tab', regex: /border-inline-(?:start|end)\s*:\s*(\d+)px\s+solid/gi,
68
+ test: (m, line) => !isSafeElement(line) && +m[1] >= 3,
69
+ fmt: (m) => m[0] },
70
+ { id: 'side-tab', regex: /border-inline-(?:start|end)-width\s*:\s*(\d+)px/gi,
71
+ test: (m, line) => !isSafeElement(line) && +m[1] >= 3,
72
+ fmt: (m) => m[0] },
73
+ { id: 'side-tab', regex: /border(?:Left|Right)\s*[:=]\s*["'`](\d+)px\s+solid/g,
74
+ test: (m) => +m[1] >= 3,
75
+ fmt: (m) => m[0] },
76
+ // --- Border accent on rounded ---
77
+ { id: 'border-accent-on-rounded', regex: /\bborder-[tb]-(\d+)\b/g,
78
+ test: (m, line) => hasRounded(line) && +m[1] >= 1,
79
+ fmt: (m) => m[0] },
80
+ { id: 'border-accent-on-rounded', regex: /border-(?:top|bottom)\s*:\s*(\d+)px\s+solid/gi,
81
+ test: (m, line) => +m[1] >= 3 && hasBorderRadius(line),
82
+ fmt: (m) => m[0] },
83
+ // --- Overused font ---
84
+ { id: 'overused-font', regex: /font-family\s*:\s*['"]?(Inter|Roboto|Open Sans|Lato|Montserrat|Arial|Helvetica|Fraunces|Geist Sans|Geist Mono|Geist|Mona Sans|Plus Jakarta Sans|Space Grotesk|Recoleta|Instrument Sans|Instrument Serif)\b/gi,
85
+ test: () => true,
86
+ fmt: (m) => m[0] },
87
+ { id: 'overused-font', regex: /fonts\.googleapis\.com\/css2?\?family=(Inter|Roboto|Open\+Sans|Lato|Montserrat|Fraunces|Plus\+Jakarta\+Sans|Space\+Grotesk|Instrument\+Sans|Instrument\+Serif|Mona\+Sans|Geist)\b/gi,
88
+ test: () => true,
89
+ fmt: (m) => `Google Fonts: ${m[1].replace(/\+/g, ' ')}` },
90
+ // --- Gradient text ---
91
+ { id: 'gradient-text', regex: /background-clip\s*:\s*text|-webkit-background-clip\s*:\s*text/gi,
92
+ test: (m, line) => /gradient/i.test(line),
93
+ fmt: () => 'background-clip: text + gradient' },
94
+ // --- Gradient text (Tailwind) ---
95
+ { id: 'gradient-text', regex: /\bbg-clip-text\b/g,
96
+ test: (m, line) => /\bbg-gradient-to-/i.test(line),
97
+ fmt: () => 'bg-clip-text + bg-gradient' },
98
+ // --- Tailwind gray on colored bg ---
99
+ { id: 'gray-on-color', regex: /\btext-(?:gray|slate|zinc|neutral|stone)-(\d+)\b/g,
100
+ test: (m, line) => /\bbg-(?:red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-\d+\b/.test(line),
101
+ fmt: (m, line) => { const bg = line.match(/\bbg-(?:red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-\d+\b/); return `${m[0]} on ${bg?.[0] || '?'}`; } },
102
+ // --- Tailwind AI palette ---
103
+ { id: 'ai-color-palette', regex: /\btext-(?:purple|violet|indigo)-(\d+)\b/g,
104
+ test: (m, line) => /\btext-(?:[2-9]xl|[3-9]xl)\b|<h[1-3]/i.test(line),
105
+ fmt: (m) => `${m[0]} on heading` },
106
+ { id: 'ai-color-palette', regex: /\bfrom-(?:purple|violet|indigo)-(\d+)\b/g,
107
+ test: (m, line) => /\bto-(?:purple|violet|indigo|blue|cyan|pink|fuchsia)-\d+\b/.test(line),
108
+ fmt: (m) => `${m[0]} gradient` },
109
+ // --- Bounce/elastic easing ---
110
+ { id: 'bounce-easing', regex: /\banimate-bounce\b/g,
111
+ test: () => true,
112
+ fmt: () => 'animate-bounce (Tailwind)' },
113
+ { id: 'bounce-easing', regex: /animation(?:-name)?\s*:\s*([^;{}]*(?:bounce|elastic|wobble|jiggle|spring)[^;{}]*)/gi,
114
+ test: () => true,
115
+ fmt: (m) => {
116
+ const token = m[1]
117
+ .split(/[,\s]+/)
118
+ .find((part) => /bounce|elastic|wobble|jiggle|spring/i.test(part));
119
+ return `animation: ${token || m[1].trim()}`;
120
+ } },
121
+ { id: 'bounce-easing', regex: /cubic-bezier\(\s*([\d.-]+)\s*,\s*([\d.-]+)\s*,\s*([\d.-]+)\s*,\s*([\d.-]+)\s*\)/g,
122
+ test: (m) => {
123
+ const y1 = parseFloat(m[2]), y2 = parseFloat(m[4]);
124
+ return y1 < -0.1 || y1 > 1.1 || y2 < -0.1 || y2 > 1.1;
125
+ },
126
+ fmt: (m) => `cubic-bezier(${m[1]}, ${m[2]}, ${m[3]}, ${m[4]})` },
127
+ // --- Layout property transition ---
128
+ { id: 'layout-transition', regex: /transition\s*:\s*([^;{}]+)/gi,
129
+ test: (m) => {
130
+ const val = m[1].toLowerCase();
131
+ if (/\ball\b/.test(val)) return false;
132
+ return /\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding\b|\bmargin\b/.test(val);
133
+ },
134
+ fmt: (m) => {
135
+ const found = m[1].match(/\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding(?:-(?:top|right|bottom|left))?\b|\bmargin(?:-(?:top|right|bottom|left))?\b/gi);
136
+ return `transition: ${found ? found.join(', ') : m[1].trim()}`;
137
+ } },
138
+ { id: 'layout-transition', regex: /transition-property\s*:\s*([^;{}]+)/gi,
139
+ test: (m) => {
140
+ const val = m[1].toLowerCase();
141
+ if (/\ball\b/.test(val)) return false;
142
+ return /\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding\b|\bmargin\b/.test(val);
143
+ },
144
+ fmt: (m) => {
145
+ const found = m[1].match(/\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding(?:-(?:top|right|bottom|left))?\b|\bmargin(?:-(?:top|right|bottom|left))?\b/gi);
146
+ return `transition-property: ${found ? found.join(', ') : m[1].trim()}`;
147
+ } },
148
+ // --- Broken image: src="" or src="#" or src=" " ---
149
+ { id: 'broken-image', regex: /<img\b[^>]*?\bsrc\s*=\s*(?:""|''|"\s+"|'\s+'|"#"|'#')/gi,
150
+ test: () => true,
151
+ fmt: (m) => m[0].slice(0, 100) },
152
+ // --- Broken image: <img> with no src attribute at all ---
153
+ { id: 'broken-image', regex: /<img\b(?:(?!\bsrc\s*=)[^>])*>/gi,
154
+ test: (m) => !/\bsrc\s*=/i.test(m[0]),
155
+ fmt: (m) => m[0].slice(0, 100) },
156
+ ];
157
+
158
+ const REGEX_ANALYZERS = [
159
+ // Single font
160
+ (content, filePath) => {
161
+ const fontFamilyRe = /font-family\s*:\s*([^;}]+)/gi;
162
+ const fonts = new Set();
163
+ let m;
164
+ while ((m = fontFamilyRe.exec(content)) !== null) {
165
+ for (const f of m[1].split(',').map(f => f.trim().replace(/^['"]|['"]$/g, '').toLowerCase())) {
166
+ if (f && !GENERIC_FONTS.has(f)) fonts.add(f);
167
+ }
168
+ }
169
+ const gfRe = /fonts\.googleapis\.com\/css2?\?family=([^&"'\s]+)/gi;
170
+ while ((m = gfRe.exec(content)) !== null) {
171
+ for (const f of m[1].split('|').map(f => f.split(':')[0].replace(/\+/g, ' ').toLowerCase())) fonts.add(f);
172
+ }
173
+ if (fonts.size !== 1 || content.split('\n').length < 20) return [];
174
+ const name = [...fonts][0];
175
+ const lines = content.split('\n');
176
+ let line = 1;
177
+ for (let i = 0; i < lines.length; i++) { if (lines[i].toLowerCase().includes(name)) { line = i + 1; break; } }
178
+ return [finding('single-font', filePath, `only font used is ${name}`, line)];
179
+ },
180
+ // Flat type hierarchy
181
+ (content, filePath) => {
182
+ const sizes = new Set();
183
+ const REM = 16;
184
+ let m;
185
+ const sizeRe = /font-size\s*:\s*([\d.]+)(px|rem|em)\b/gi;
186
+ while ((m = sizeRe.exec(content)) !== null) {
187
+ const px = m[2] === 'px' ? +m[1] : +m[1] * REM;
188
+ if (px > 0 && px < 200) sizes.add(Math.round(px * 10) / 10);
189
+ }
190
+ const clampRe = /font-size\s*:\s*clamp\(\s*([\d.]+)(px|rem|em)\s*,\s*[^,]+,\s*([\d.]+)(px|rem|em)\s*\)/gi;
191
+ while ((m = clampRe.exec(content)) !== null) {
192
+ sizes.add(Math.round((m[2] === 'px' ? +m[1] : +m[1] * REM) * 10) / 10);
193
+ sizes.add(Math.round((m[4] === 'px' ? +m[3] : +m[3] * REM) * 10) / 10);
194
+ }
195
+ const TW = { 'text-xs': 12, 'text-sm': 14, 'text-base': 16, 'text-lg': 18, 'text-xl': 20, 'text-2xl': 24, 'text-3xl': 30, 'text-4xl': 36, 'text-5xl': 48, 'text-6xl': 60, 'text-7xl': 72, 'text-8xl': 96, 'text-9xl': 128 };
196
+ for (const [cls, px] of Object.entries(TW)) { if (new RegExp(`\\b${cls}\\b`).test(content)) sizes.add(px); }
197
+ if (sizes.size < 3) return [];
198
+ const sorted = [...sizes].sort((a, b) => a - b);
199
+ const ratio = sorted[sorted.length - 1] / sorted[0];
200
+ if (ratio >= 2.0) return [];
201
+ const lines = content.split('\n');
202
+ let line = 1;
203
+ for (let i = 0; i < lines.length; i++) { if (/font-size/i.test(lines[i]) || /\btext-(?:xs|sm|base|lg|xl|\d)/i.test(lines[i])) { line = i + 1; break; } }
204
+ return [finding('flat-type-hierarchy', filePath, `Sizes: ${sorted.map(s => s + 'px').join(', ')} (ratio ${ratio.toFixed(1)}:1)`, line)];
205
+ },
206
+ // Monotonous spacing (regex)
207
+ (content, filePath) => {
208
+ const vals = [];
209
+ let m;
210
+ const pxRe = /(?:padding|margin)(?:-(?:top|right|bottom|left))?\s*:\s*(\d+)px/gi;
211
+ while ((m = pxRe.exec(content)) !== null) { const v = +m[1]; if (v > 0 && v < 200) vals.push(v); }
212
+ const remRe = /(?:padding|margin)(?:-(?:top|right|bottom|left))?\s*:\s*([\d.]+)rem/gi;
213
+ while ((m = remRe.exec(content)) !== null) { const v = Math.round(parseFloat(m[1]) * 16); if (v > 0 && v < 200) vals.push(v); }
214
+ const gapRe = /gap\s*:\s*(\d+)px/gi;
215
+ while ((m = gapRe.exec(content)) !== null) vals.push(+m[1]);
216
+ const twRe = /\b(?:p|px|py|pt|pb|pl|pr|m|mx|my|mt|mb|ml|mr|gap)-(\d+)\b/g;
217
+ while ((m = twRe.exec(content)) !== null) vals.push(+m[1] * 4);
218
+ const rounded = vals.map(v => Math.round(v / 4) * 4);
219
+ if (rounded.length < 10) return [];
220
+ const counts = {};
221
+ for (const v of rounded) counts[v] = (counts[v] || 0) + 1;
222
+ const maxCount = Math.max(...Object.values(counts));
223
+ const pct = maxCount / rounded.length;
224
+ const unique = [...new Set(rounded)].filter(v => v > 0);
225
+ if (pct <= 0.6 || unique.length > 3) return [];
226
+ const dominant = Object.entries(counts).sort((a, b) => b[1] - a[1])[0][0];
227
+ return [finding('monotonous-spacing', filePath, `~${dominant}px used ${maxCount}/${rounded.length} times (${Math.round(pct * 100)}%)`)];
228
+ },
229
+ // Em-dash overuse: 5+ em-dashes or "--" in body text content
230
+ // (occasional em-dash use in prose is fine; the pattern fires only
231
+ // when count crosses into AI-cadence territory).
232
+ (content, filePath) => {
233
+ const text = stripHtmlToText(content);
234
+ let count = 0;
235
+ const re = /[—]|--(?=\S)/g;
236
+ while (re.exec(text) !== null) count++;
237
+ if (count < 5) return [];
238
+ return [finding('em-dash-overuse', filePath, `${count} em-dashes in body text`)];
239
+ },
240
+ // Marketing buzzwords: SaaS phrase list
241
+ (content, filePath) => {
242
+ const text = stripHtmlToText(content);
243
+ const lower = text.toLowerCase();
244
+ const BUZZWORDS = [
245
+ 'streamline your', 'empower your', 'supercharge your',
246
+ 'unleash your', 'unleash the power', 'leverage the power',
247
+ 'built for the modern', 'trusted by leading', 'trusted by the world',
248
+ 'best-in-class', 'industry-leading', 'world-class', 'enterprise-grade',
249
+ 'next-generation', 'cutting-edge', 'transform your business',
250
+ 'revolutionize', 'game-changer', 'game changing',
251
+ 'mission-critical', 'best of breed', 'future-proof', 'future proof',
252
+ 'seamless experience', 'seamlessly integrate',
253
+ 'drive engagement', 'drive growth', 'drive results',
254
+ 'harness the power',
255
+ ];
256
+ let count = 0;
257
+ let firstSample = '';
258
+ for (const phrase of BUZZWORDS) {
259
+ let from = 0;
260
+ while (true) {
261
+ const idx = lower.indexOf(phrase, from);
262
+ if (idx === -1) break;
263
+ count++;
264
+ if (!firstSample) {
265
+ firstSample = text.slice(Math.max(0, idx - 12), Math.min(text.length, idx + phrase.length + 12)).trim();
266
+ }
267
+ from = idx + phrase.length;
268
+ }
269
+ }
270
+ if (count === 0) return [];
271
+ return [finding('marketing-buzzword', filePath, `${count} buzzword phrase${count === 1 ? '' : 's'}: "${firstSample}"`)];
272
+ },
273
+ // Numbered section markers (01 / 02 / 03 ...)
274
+ (content, filePath) => {
275
+ const text = stripHtmlToText(content);
276
+ const re = /\b(0[1-9]|1[0-2])\b/g;
277
+ const seen = new Set();
278
+ let m;
279
+ while ((m = re.exec(text)) !== null) seen.add(m[1]);
280
+ if (seen.size < 3) return [];
281
+ const sorted = [...seen].sort();
282
+ let sequential = 0;
283
+ for (let i = 1; i < sorted.length; i++) {
284
+ if (parseInt(sorted[i], 10) === parseInt(sorted[i - 1], 10) + 1) sequential++;
285
+ }
286
+ if (sequential < 2) return [];
287
+ return [finding('numbered-section-markers', filePath, `Sequence: ${sorted.slice(0, 6).join(', ')}`)];
288
+ },
289
+ // Aphoristic cadence: manufactured-contrast + short-rebuttal
290
+ (content, filePath) => {
291
+ const text = stripHtmlToText(content);
292
+ const NOT_A_RE = /\bNot an? [a-z][^.!?]{1,40}[.!]\s+[A-Z][^.!?]{1,60}[.!]/g;
293
+ const SHORT_REBUTTAL_RE = /\b[A-Z][^.!?]{4,80}[.!]\s+(No|Just)\s+[a-z][^.!?]{2,60}[.!]/g;
294
+ let count = 0;
295
+ let firstSample = '';
296
+ let m;
297
+ NOT_A_RE.lastIndex = 0;
298
+ while ((m = NOT_A_RE.exec(text)) !== null) {
299
+ count++;
300
+ if (!firstSample) firstSample = m[0].trim().slice(0, 80);
301
+ }
302
+ SHORT_REBUTTAL_RE.lastIndex = 0;
303
+ while ((m = SHORT_REBUTTAL_RE.exec(text)) !== null) {
304
+ count++;
305
+ if (!firstSample) firstSample = m[0].trim().slice(0, 80);
306
+ }
307
+ if (count < 3) return [];
308
+ return [finding('aphoristic-cadence', filePath, `${count} aphoristic constructions: "${firstSample}"`)];
309
+ },
310
+ // Dark glow (page-level: dark bg + colored box-shadow with blur)
311
+ (content, filePath) => {
312
+ // Check if page has a dark background
313
+ const darkBgRe = /background(?:-color)?\s*:\s*(?:#(?:0[0-9a-f]|1[0-9a-f]|2[0-3])[0-9a-f]{4}\b|#(?:0|1)[0-9a-f]{2}\b|rgb\(\s*(\d{1,2})\s*,\s*(\d{1,2})\s*,\s*(\d{1,2})\s*\))/gi;
314
+ const twDarkBg = /\bbg-(?:gray|slate|zinc|neutral|stone)-(?:9\d{2}|800)\b/;
315
+ const hasDarkBg = darkBgRe.test(content) || twDarkBg.test(content);
316
+ if (!hasDarkBg) return [];
317
+
318
+ // Check for colored box-shadow with blur > 4px
319
+ const shadowRe = /box-shadow\s*:\s*([^;{}]+)/gi;
320
+ let m;
321
+ while ((m = shadowRe.exec(content)) !== null) {
322
+ const val = m[1];
323
+ const colorMatch = val.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
324
+ if (!colorMatch) continue;
325
+ const [r, g, b] = [+colorMatch[1], +colorMatch[2], +colorMatch[3]];
326
+ if ((Math.max(r, g, b) - Math.min(r, g, b)) < 30) continue; // skip gray
327
+ // Check blur: look for pattern like "0 0 20px" (third number > 4)
328
+ const pxVals = [...val.matchAll(/(\d+)px|(?<![.\d])\b(0)\b(?![.\d])/g)].map(p => +(p[1] || p[2]));
329
+ if (pxVals.length >= 3 && pxVals[2] > 4) {
330
+ const lines = content.substring(0, m.index).split('\n');
331
+ return [finding('dark-glow', filePath, `Colored glow (rgb(${r},${g},${b})) on dark page`, lines.length)];
332
+ }
333
+ }
334
+ return [];
335
+ },
336
+ ];
337
+
338
+ // ---------------------------------------------------------------------------
339
+ // Style block extraction (Vue/Svelte <style> blocks)
340
+ // ---------------------------------------------------------------------------
341
+
342
+ function extractStyleBlocks(content, ext) {
343
+ ext = ext.toLowerCase();
344
+ if (ext !== '.vue' && ext !== '.svelte') return [];
345
+ const blocks = [];
346
+ const re = /<style[^>]*>([\s\S]*?)<\/style>/gi;
347
+ let m;
348
+ while ((m = re.exec(content)) !== null) {
349
+ const before = content.substring(0, m.index);
350
+ const startLine = before.split('\n').length + 1;
351
+ blocks.push({ content: m[1], startLine });
352
+ }
353
+ return blocks;
354
+ }
355
+
356
+ // ---------------------------------------------------------------------------
357
+ // CSS-in-JS extraction (styled-components, emotion)
358
+ // ---------------------------------------------------------------------------
359
+
360
+ const CSS_IN_JS_EXTENSIONS = new Set(['.js', '.ts', '.jsx', '.tsx']);
361
+
362
+ function extractCSSinJS(content, ext) {
363
+ ext = ext.toLowerCase();
364
+ if (!CSS_IN_JS_EXTENSIONS.has(ext)) return [];
365
+ const blocks = [];
366
+ const re = /(?:styled(?:\.\w+|\([^)]+\))|css)\s*`([\s\S]*?)`/g;
367
+ let m;
368
+ while ((m = re.exec(content)) !== null) {
369
+ const before = content.substring(0, m.index);
370
+ const startLine = before.split('\n').length;
371
+ blocks.push({ content: m[1], startLine });
372
+ }
373
+ return blocks;
374
+ }
375
+
376
+ function runRegexMatchers(lines, filePath, lineOffset = 0, blockContext = null, options = {}) {
377
+ const { profile, phase = 'regex-matchers' } = options || {};
378
+ const findings = [];
379
+ if (!profile) {
380
+ for (const matcher of REGEX_MATCHERS) {
381
+ for (let i = 0; i < lines.length; i++) {
382
+ const line = lines[i];
383
+ matcher.regex.lastIndex = 0;
384
+ let m;
385
+ while ((m = matcher.regex.exec(line)) !== null) {
386
+ // For extracted blocks, use nearby lines as context for multi-line CSS patterns
387
+ const context = blockContext
388
+ ? lines.slice(Math.max(0, i - 3), Math.min(lines.length, i + 4)).join(' ')
389
+ : line;
390
+ if (matcher.test(m, context)) {
391
+ findings.push(finding(matcher.id, filePath, matcher.fmt(m, context), i + 1 + lineOffset));
392
+ }
393
+ }
394
+ }
395
+ }
396
+ return findings;
397
+ }
398
+
399
+ for (const matcher of REGEX_MATCHERS) {
400
+ const matcherFindings = profileFindings(profile, {
401
+ engine: 'regex',
402
+ phase,
403
+ ruleId: matcher.id,
404
+ target: filePath,
405
+ }, () => {
406
+ const matches = [];
407
+ for (let i = 0; i < lines.length; i++) {
408
+ const line = lines[i];
409
+ matcher.regex.lastIndex = 0;
410
+ let m;
411
+ while ((m = matcher.regex.exec(line)) !== null) {
412
+ // For extracted blocks, use nearby lines as context for multi-line CSS patterns
413
+ const context = blockContext
414
+ ? lines.slice(Math.max(0, i - 3), Math.min(lines.length, i + 4)).join(' ')
415
+ : line;
416
+ if (matcher.test(m, context)) {
417
+ matches.push(finding(matcher.id, filePath, matcher.fmt(m, context), i + 1 + lineOffset));
418
+ }
419
+ }
420
+ }
421
+ return matches;
422
+ });
423
+ findings.push(...matcherFindings);
424
+ }
425
+ return findings;
426
+ }
427
+
428
+ /** Page-level analyzers that scan rendered text content (em-dash use,
429
+ * buzzword phrases, numbered section markers, aphoristic cadence).
430
+ * These are detector-agnostic — they work on any HTML/text source
431
+ * and don't need a parsed DOM. Exported so detectHtml can call them
432
+ * for `.html` files (which otherwise skip the regex engine). */
433
+ const TEXT_CONTENT_ANALYZER_IDS = [
434
+ 'em-dash-overuse',
435
+ 'marketing-buzzword',
436
+ 'numbered-section-markers',
437
+ 'aphoristic-cadence',
438
+ ];
439
+
440
+ function runTextContentAnalyzers(content, filePath, options = {}) {
441
+ const profile = options?.profile;
442
+ if (!shouldRunPageAnalyzers(content, filePath)) return [];
443
+ // The 4 text-content analyzers are at indices 3-6 in REGEX_ANALYZERS.
444
+ const findings = [];
445
+ for (let i = 0; i < TEXT_CONTENT_ANALYZER_IDS.length; i++) {
446
+ const analyzer = REGEX_ANALYZERS[3 + i];
447
+ const ruleId = TEXT_CONTENT_ANALYZER_IDS[i];
448
+ findings.push(...profileFindings(profile, {
449
+ engine: 'regex',
450
+ phase: 'text-content',
451
+ ruleId,
452
+ target: filePath,
453
+ }, () => analyzer(content, filePath)));
454
+ }
455
+ return findings;
456
+ }
457
+
458
+ function detectText(content, filePath, options = {}) {
459
+ const profile = options?.profile;
460
+ const findings = [];
461
+ const lines = content.split('\n');
462
+ const ext = extFromFilePath(filePath);
463
+
464
+ // Run regex matchers on the full file content (catches Tailwind classes, inline styles)
465
+ // Enable block context for CSS files where related properties span multiple lines
466
+ const cssLike = new Set(['.css', '.scss', '.sass', '.less']);
467
+ findings.push(...runRegexMatchers(lines, filePath, 0, cssLike.has(ext) || null, {
468
+ profile,
469
+ phase: 'source',
470
+ }));
471
+
472
+ // Extract and scan <style> blocks from Vue/Svelte SFCs
473
+ const styleBlocks = profile
474
+ ? profileStep(profile, {
475
+ engine: 'regex',
476
+ phase: 'extract',
477
+ ruleId: 'style-blocks',
478
+ target: filePath,
479
+ }, () => extractStyleBlocks(content, ext))
480
+ : extractStyleBlocks(content, ext);
481
+ for (const block of styleBlocks) {
482
+ const blockLines = block.content.split('\n');
483
+ findings.push(...runRegexMatchers(blockLines, filePath, block.startLine - 1, true, {
484
+ profile,
485
+ phase: 'style-block',
486
+ }));
487
+ }
488
+
489
+ // Extract and scan CSS-in-JS template literals
490
+ const cssJsBlocks = profile
491
+ ? profileStep(profile, {
492
+ engine: 'regex',
493
+ phase: 'extract',
494
+ ruleId: 'css-in-js',
495
+ target: filePath,
496
+ }, () => extractCSSinJS(content, ext))
497
+ : extractCSSinJS(content, ext);
498
+ for (const block of cssJsBlocks) {
499
+ const blockLines = block.content.split('\n');
500
+ findings.push(...runRegexMatchers(blockLines, filePath, block.startLine - 1, true, {
501
+ profile,
502
+ phase: 'css-in-js',
503
+ }));
504
+ }
505
+
506
+ // Deduplicate findings (same antipattern + similar snippet, within 2 lines)
507
+ const deduped = [];
508
+ for (const f of findings) {
509
+ const isDupe = deduped.some(d =>
510
+ d.antipattern === f.antipattern &&
511
+ d.snippet === f.snippet &&
512
+ Math.abs(d.line - f.line) <= 2
513
+ );
514
+ if (!isDupe) deduped.push(f);
515
+ }
516
+
517
+ // Page-level analyzers only run on full pages
518
+ if (shouldRunPageAnalyzers(content, filePath)) {
519
+ const analyzerIds = [
520
+ 'single-font',
521
+ 'flat-type-hierarchy',
522
+ 'monotonous-spacing',
523
+ 'em-dash-overuse',
524
+ 'marketing-buzzword',
525
+ 'numbered-section-markers',
526
+ 'aphoristic-cadence',
527
+ 'dark-glow',
528
+ ];
529
+ for (let i = 0; i < REGEX_ANALYZERS.length; i++) {
530
+ const analyzer = REGEX_ANALYZERS[i];
531
+ deduped.push(...profileFindings(profile, {
532
+ engine: 'regex',
533
+ phase: 'page-analyzer',
534
+ ruleId: analyzerIds[i] || `analyzer-${i + 1}`,
535
+ target: filePath,
536
+ }, () => analyzer(content, filePath)));
537
+ }
538
+ }
539
+
540
+ return filterByProviders(deduped, options?.providers);
541
+ }
542
+
543
+ export {
544
+ REGEX_MATCHERS,
545
+ REGEX_ANALYZERS,
546
+ TEXT_CONTENT_ANALYZER_IDS,
547
+ extractStyleBlocks,
548
+ extractCSSinJS,
549
+ runRegexMatchers,
550
+ runTextContentAnalyzers,
551
+ detectText,
552
+ };