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