popeye-cli 1.4.7 → 1.6.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 (214) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +264 -63
  3. package/dist/adapters/gemini.d.ts +1 -0
  4. package/dist/adapters/gemini.d.ts.map +1 -1
  5. package/dist/adapters/gemini.js +9 -4
  6. package/dist/adapters/gemini.js.map +1 -1
  7. package/dist/adapters/grok.d.ts +1 -0
  8. package/dist/adapters/grok.d.ts.map +1 -1
  9. package/dist/adapters/grok.js +9 -4
  10. package/dist/adapters/grok.js.map +1 -1
  11. package/dist/adapters/openai.d.ts +1 -1
  12. package/dist/adapters/openai.d.ts.map +1 -1
  13. package/dist/adapters/openai.js +35 -9
  14. package/dist/adapters/openai.js.map +1 -1
  15. package/dist/cli/commands/create.d.ts.map +1 -1
  16. package/dist/cli/commands/create.js +54 -4
  17. package/dist/cli/commands/create.js.map +1 -1
  18. package/dist/cli/interactive.d.ts +29 -0
  19. package/dist/cli/interactive.d.ts.map +1 -1
  20. package/dist/cli/interactive.js +132 -7
  21. package/dist/cli/interactive.js.map +1 -1
  22. package/dist/generators/all.d.ts +8 -2
  23. package/dist/generators/all.d.ts.map +1 -1
  24. package/dist/generators/all.js +37 -316
  25. package/dist/generators/all.js.map +1 -1
  26. package/dist/generators/doc-parser.d.ts +64 -0
  27. package/dist/generators/doc-parser.d.ts.map +1 -0
  28. package/dist/generators/doc-parser.js +407 -0
  29. package/dist/generators/doc-parser.js.map +1 -0
  30. package/dist/generators/frontend-design-analyzer.d.ts +30 -0
  31. package/dist/generators/frontend-design-analyzer.d.ts.map +1 -0
  32. package/dist/generators/frontend-design-analyzer.js +208 -0
  33. package/dist/generators/frontend-design-analyzer.js.map +1 -0
  34. package/dist/generators/shared-packages.d.ts +45 -0
  35. package/dist/generators/shared-packages.d.ts.map +1 -0
  36. package/dist/generators/shared-packages.js +456 -0
  37. package/dist/generators/shared-packages.js.map +1 -0
  38. package/dist/generators/templates/index.d.ts +8 -0
  39. package/dist/generators/templates/index.d.ts.map +1 -1
  40. package/dist/generators/templates/index.js +8 -0
  41. package/dist/generators/templates/index.js.map +1 -1
  42. package/dist/generators/templates/website-components.d.ts +33 -0
  43. package/dist/generators/templates/website-components.d.ts.map +1 -0
  44. package/dist/generators/templates/website-components.js +303 -0
  45. package/dist/generators/templates/website-components.js.map +1 -0
  46. package/dist/generators/templates/website-config.d.ts +55 -0
  47. package/dist/generators/templates/website-config.d.ts.map +1 -0
  48. package/dist/generators/templates/website-config.js +425 -0
  49. package/dist/generators/templates/website-config.js.map +1 -0
  50. package/dist/generators/templates/website-conversion.d.ts +27 -0
  51. package/dist/generators/templates/website-conversion.d.ts.map +1 -0
  52. package/dist/generators/templates/website-conversion.js +326 -0
  53. package/dist/generators/templates/website-conversion.js.map +1 -0
  54. package/dist/generators/templates/website-landing.d.ts +24 -0
  55. package/dist/generators/templates/website-landing.d.ts.map +1 -0
  56. package/dist/generators/templates/website-landing.js +276 -0
  57. package/dist/generators/templates/website-landing.js.map +1 -0
  58. package/dist/generators/templates/website-layout.d.ts +42 -0
  59. package/dist/generators/templates/website-layout.d.ts.map +1 -0
  60. package/dist/generators/templates/website-layout.js +408 -0
  61. package/dist/generators/templates/website-layout.js.map +1 -0
  62. package/dist/generators/templates/website-pricing.d.ts +11 -0
  63. package/dist/generators/templates/website-pricing.d.ts.map +1 -0
  64. package/dist/generators/templates/website-pricing.js +313 -0
  65. package/dist/generators/templates/website-pricing.js.map +1 -0
  66. package/dist/generators/templates/website-sections.d.ts +102 -0
  67. package/dist/generators/templates/website-sections.d.ts.map +1 -0
  68. package/dist/generators/templates/website-sections.js +444 -0
  69. package/dist/generators/templates/website-sections.js.map +1 -0
  70. package/dist/generators/templates/website-seo.d.ts +76 -0
  71. package/dist/generators/templates/website-seo.d.ts.map +1 -0
  72. package/dist/generators/templates/website-seo.js +326 -0
  73. package/dist/generators/templates/website-seo.js.map +1 -0
  74. package/dist/generators/templates/website.d.ts +10 -83
  75. package/dist/generators/templates/website.d.ts.map +1 -1
  76. package/dist/generators/templates/website.js +12 -875
  77. package/dist/generators/templates/website.js.map +1 -1
  78. package/dist/generators/website-content-scanner.d.ts +37 -0
  79. package/dist/generators/website-content-scanner.d.ts.map +1 -0
  80. package/dist/generators/website-content-scanner.js +165 -0
  81. package/dist/generators/website-content-scanner.js.map +1 -0
  82. package/dist/generators/website-context.d.ts +119 -0
  83. package/dist/generators/website-context.d.ts.map +1 -0
  84. package/dist/generators/website-context.js +350 -0
  85. package/dist/generators/website-context.js.map +1 -0
  86. package/dist/generators/website-debug.d.ts +68 -0
  87. package/dist/generators/website-debug.d.ts.map +1 -0
  88. package/dist/generators/website-debug.js +93 -0
  89. package/dist/generators/website-debug.js.map +1 -0
  90. package/dist/generators/website.d.ts +5 -0
  91. package/dist/generators/website.d.ts.map +1 -1
  92. package/dist/generators/website.js +136 -11
  93. package/dist/generators/website.js.map +1 -1
  94. package/dist/generators/workspace-root.d.ts +27 -0
  95. package/dist/generators/workspace-root.d.ts.map +1 -0
  96. package/dist/generators/workspace-root.js +100 -0
  97. package/dist/generators/workspace-root.js.map +1 -0
  98. package/dist/state/index.d.ts +35 -0
  99. package/dist/state/index.d.ts.map +1 -1
  100. package/dist/state/index.js +40 -0
  101. package/dist/state/index.js.map +1 -1
  102. package/dist/types/consensus.d.ts +3 -0
  103. package/dist/types/consensus.d.ts.map +1 -1
  104. package/dist/types/consensus.js +1 -0
  105. package/dist/types/consensus.js.map +1 -1
  106. package/dist/types/website-strategy.d.ts +263 -0
  107. package/dist/types/website-strategy.d.ts.map +1 -0
  108. package/dist/types/website-strategy.js +105 -0
  109. package/dist/types/website-strategy.js.map +1 -0
  110. package/dist/types/workflow.d.ts +21 -0
  111. package/dist/types/workflow.d.ts.map +1 -1
  112. package/dist/types/workflow.js +8 -0
  113. package/dist/types/workflow.js.map +1 -1
  114. package/dist/upgrade/handlers.d.ts +15 -0
  115. package/dist/upgrade/handlers.d.ts.map +1 -1
  116. package/dist/upgrade/handlers.js +52 -0
  117. package/dist/upgrade/handlers.js.map +1 -1
  118. package/dist/workflow/auto-fix-bundler.d.ts +37 -0
  119. package/dist/workflow/auto-fix-bundler.d.ts.map +1 -0
  120. package/dist/workflow/auto-fix-bundler.js +320 -0
  121. package/dist/workflow/auto-fix-bundler.js.map +1 -0
  122. package/dist/workflow/auto-fix.d.ts.map +1 -1
  123. package/dist/workflow/auto-fix.js +10 -3
  124. package/dist/workflow/auto-fix.js.map +1 -1
  125. package/dist/workflow/consensus.d.ts.map +1 -1
  126. package/dist/workflow/consensus.js +2 -0
  127. package/dist/workflow/consensus.js.map +1 -1
  128. package/dist/workflow/execution-mode.d.ts.map +1 -1
  129. package/dist/workflow/execution-mode.js +18 -0
  130. package/dist/workflow/execution-mode.js.map +1 -1
  131. package/dist/workflow/index.d.ts +4 -0
  132. package/dist/workflow/index.d.ts.map +1 -1
  133. package/dist/workflow/index.js +37 -0
  134. package/dist/workflow/index.js.map +1 -1
  135. package/dist/workflow/overview.d.ts +89 -0
  136. package/dist/workflow/overview.d.ts.map +1 -0
  137. package/dist/workflow/overview.js +358 -0
  138. package/dist/workflow/overview.js.map +1 -0
  139. package/dist/workflow/plan-mode.d.ts +6 -4
  140. package/dist/workflow/plan-mode.d.ts.map +1 -1
  141. package/dist/workflow/plan-mode.js +148 -6
  142. package/dist/workflow/plan-mode.js.map +1 -1
  143. package/dist/workflow/website-strategy.d.ts +79 -0
  144. package/dist/workflow/website-strategy.d.ts.map +1 -0
  145. package/dist/workflow/website-strategy.js +310 -0
  146. package/dist/workflow/website-strategy.js.map +1 -0
  147. package/dist/workflow/website-updater.d.ts +17 -0
  148. package/dist/workflow/website-updater.d.ts.map +1 -0
  149. package/dist/workflow/website-updater.js +116 -0
  150. package/dist/workflow/website-updater.js.map +1 -0
  151. package/dist/workflow/workflow-logger.d.ts +1 -1
  152. package/dist/workflow/workflow-logger.d.ts.map +1 -1
  153. package/dist/workflow/workflow-logger.js.map +1 -1
  154. package/package.json +1 -1
  155. package/src/adapters/gemini.ts +10 -4
  156. package/src/adapters/grok.ts +10 -4
  157. package/src/adapters/openai.ts +38 -6
  158. package/src/cli/commands/create.ts +58 -4
  159. package/src/cli/interactive.ts +143 -7
  160. package/src/generators/all.ts +49 -332
  161. package/src/generators/doc-parser.ts +449 -0
  162. package/src/generators/frontend-design-analyzer.ts +261 -0
  163. package/src/generators/shared-packages.ts +500 -0
  164. package/src/generators/templates/index.ts +8 -0
  165. package/src/generators/templates/website-components.ts +330 -0
  166. package/src/generators/templates/website-config.ts +444 -0
  167. package/src/generators/templates/website-conversion.ts +341 -0
  168. package/src/generators/templates/website-landing.ts +331 -0
  169. package/src/generators/templates/website-layout.ts +443 -0
  170. package/src/generators/templates/website-pricing.ts +330 -0
  171. package/src/generators/templates/website-sections.ts +541 -0
  172. package/src/generators/templates/website-seo.ts +370 -0
  173. package/src/generators/templates/website.ts +38 -905
  174. package/src/generators/website-content-scanner.ts +208 -0
  175. package/src/generators/website-context.ts +493 -0
  176. package/src/generators/website-debug.ts +130 -0
  177. package/src/generators/website.ts +178 -20
  178. package/src/generators/workspace-root.ts +113 -0
  179. package/src/state/index.ts +56 -0
  180. package/src/types/consensus.ts +3 -0
  181. package/src/types/website-strategy.ts +243 -0
  182. package/src/types/workflow.ts +21 -0
  183. package/src/upgrade/handlers.ts +65 -0
  184. package/src/workflow/auto-fix-bundler.ts +392 -0
  185. package/src/workflow/auto-fix.ts +11 -3
  186. package/src/workflow/consensus.ts +2 -0
  187. package/src/workflow/execution-mode.ts +21 -0
  188. package/src/workflow/index.ts +37 -0
  189. package/src/workflow/overview.ts +475 -0
  190. package/src/workflow/plan-mode.ts +193 -8
  191. package/src/workflow/website-strategy.ts +379 -0
  192. package/src/workflow/website-updater.ts +142 -0
  193. package/src/workflow/workflow-logger.ts +1 -0
  194. package/tests/adapters/persona-switching.test.ts +63 -0
  195. package/tests/cli/project-naming.test.ts +136 -0
  196. package/tests/generators/doc-parser.test.ts +121 -0
  197. package/tests/generators/frontend-design-analyzer.test.ts +90 -0
  198. package/tests/generators/quality-gate.test.ts +183 -0
  199. package/tests/generators/shared-packages.test.ts +83 -0
  200. package/tests/generators/website-components.test.ts +159 -0
  201. package/tests/generators/website-config.test.ts +84 -0
  202. package/tests/generators/website-content-scanner.test.ts +181 -0
  203. package/tests/generators/website-context.test.ts +331 -0
  204. package/tests/generators/website-debug.test.ts +77 -0
  205. package/tests/generators/website-landing.test.ts +188 -0
  206. package/tests/generators/website-pricing.test.ts +98 -0
  207. package/tests/generators/website-sections.test.ts +245 -0
  208. package/tests/generators/website-seo-quality.test.ts +246 -0
  209. package/tests/generators/workspace-root.test.ts +105 -0
  210. package/tests/upgrade/handlers.test.ts +162 -0
  211. package/tests/workflow/auto-fix-bundler.test.ts +242 -0
  212. package/tests/workflow/overview.test.ts +392 -0
  213. package/tests/workflow/plan-mode.test.ts +111 -1
  214. package/tests/workflow/website-strategy.test.ts +246 -0
@@ -0,0 +1,449 @@
1
+ /**
2
+ * Document parsing helpers for extracting structured content from user docs
3
+ * Used by website-context.ts to populate website templates with project-specific content
4
+ */
5
+
6
+ /** Generic AI preamble patterns to skip */
7
+ const GENERIC_PREAMBLES = [
8
+ "here's a comprehensive",
9
+ "here is a comprehensive",
10
+ "here's a detailed",
11
+ "here is a detailed",
12
+ "based on your idea",
13
+ "based on the idea",
14
+ "here's a software",
15
+ "here is a software",
16
+ ];
17
+
18
+ /**
19
+ * Strip markdown code fences that wrap entire doc files (```md ... ```)
20
+ */
21
+ export function stripCodeFences(text: string): string {
22
+ return text.replace(/```(?:md|markdown)?\s*\n/g, '').replace(/```\s*$/gm, '');
23
+ }
24
+
25
+ /**
26
+ * Extract the real product name from docs or specification
27
+ *
28
+ * Priority chain (first match wins):
29
+ * 1. Parsed docs: "# ProductName -- tagline" heading (picks shortest)
30
+ * 2. Specification: "# ProductName" heading
31
+ * 3. Specification: "Product:" / "Name:" / "App:" label
32
+ * 4. package.json "name" field from workspace root (passed via specification context)
33
+ * 5. undefined (caller falls back to directory name)
34
+ */
35
+ export function extractProductName(
36
+ docs: string,
37
+ specification?: string,
38
+ packageJsonName?: string
39
+ ): string | undefined {
40
+ // 1. Collect all "# Name -- tagline" headings, pick the shortest name
41
+ // Reason: sub-documents like "Gateco UI Color System" are longer than "Gateco"
42
+ const headingPattern = /^#\s+([A-Z][a-zA-Z0-9]+(?:[ \t]+[A-Z][a-zA-Z0-9]+)*)(?:[ \t]*(?:--|[—–|:])[ \t])/gm;
43
+ const candidates: string[] = [];
44
+ let match;
45
+ while ((match = headingPattern.exec(docs)) !== null) {
46
+ candidates.push(match[1].trim());
47
+ }
48
+ if (candidates.length > 0) {
49
+ candidates.sort((a, b) => a.length - b.length);
50
+ return candidates[0];
51
+ }
52
+
53
+ // 2. "# ProductName" heading in specification (standalone heading, not sub-doc)
54
+ // Reason: Exclude common section headings like "Overview", "Introduction", "Summary"
55
+ if (specification) {
56
+ const commonHeadings = /^(Overview|Introduction|Summary|Features|Architecture|Requirements|Setup|Installation|Configuration|Specification|Appendix|Conclusion|References)$/i;
57
+ const specHeading = specification.match(/^#\s+([A-Z][a-zA-Z0-9]+(?:\s+[A-Z][a-zA-Z0-9]+)*)\s*$/m);
58
+ if (specHeading && !commonHeadings.test(specHeading[1].trim())) {
59
+ return specHeading[1].trim();
60
+ }
61
+ }
62
+
63
+ // 3. "Product:" / "Name:" / "App:" label in specification
64
+ if (specification) {
65
+ const nameMatch = specification.match(/\*\*Project\s+Name\*\*:\s*(.+)/i);
66
+ if (nameMatch) return nameMatch[1].trim();
67
+
68
+ const labelMatch = specification.match(/(?:^|\n)\s*(?:Product|Name|App)\s*:\s*(.+)/i);
69
+ if (labelMatch) {
70
+ const value = labelMatch[1].trim().replace(/\*\*/g, '');
71
+ if (value.length > 0 && value.length < 60) return value;
72
+ }
73
+ }
74
+
75
+ // 4. "# ProductName" in spec/product doc sections only
76
+ const sectionHeading = docs.match(/^---\s+\S*(?:spec|product)\S*\s+---\n#\s+([A-Z][a-zA-Z0-9]+)/im);
77
+ if (sectionHeading) return sectionHeading[1].trim();
78
+
79
+ // 5. package.json name (strip @scope/ prefix and convert to title case)
80
+ if (packageJsonName) {
81
+ const cleaned = packageJsonName
82
+ .replace(/^@[^/]+\//, '') // Strip scope
83
+ .replace(/[-_]/g, ' ')
84
+ .replace(/\b\w/g, (c) => c.toUpperCase())
85
+ .trim();
86
+ if (cleaned.length > 0) return cleaned;
87
+ }
88
+
89
+ return undefined;
90
+ }
91
+
92
+ /**
93
+ * Check if a product name looks like a directory name rather than a real product name
94
+ * Used by the quality gate to flag suspicious names
95
+ *
96
+ * @param name - The product name to check
97
+ * @returns True if the name looks suspicious (likely a directory name)
98
+ */
99
+ export function isSuspiciousProductName(name: string): boolean {
100
+ const suspiciousNames = ['my-app', 'my-project', 'project', 'app', 'website', 'frontend'];
101
+ if (suspiciousNames.includes(name.toLowerCase())) return true;
102
+ // Hyphenated lowercase strings like "read-all-files" are likely directory names
103
+ if (/^[a-z]+-[a-z]+(-[a-z]+)*$/.test(name)) return true;
104
+ return false;
105
+ }
106
+
107
+ /**
108
+ * Extract a tagline from docs (text after em-dash in first heading)
109
+ * When productName is provided, prefer tagline from the heading containing that name
110
+ */
111
+ export function extractTagline(docs: string, productName?: string): string | undefined {
112
+ // Collect all "# Name — Tagline" matches
113
+ const taglineMatches = [...docs.matchAll(/^#\s+(.+?)[—\-–]\s*(.{10,80})$/gm)];
114
+
115
+ if (taglineMatches.length > 0) {
116
+ // Prefer tagline from the heading that best matches the product name
117
+ // Reason: "Gateco UI Color System — ..." also includes "Gateco", so prefer exact match
118
+ if (productName) {
119
+ const exactMatch = taglineMatches.find((m) => m[1].trim() === productName);
120
+ if (exactMatch) return exactMatch[2].trim();
121
+ // Fall back to shortest heading containing the name (closest to just the product name)
122
+ const nameMatches = taglineMatches.filter((m) => m[1].includes(productName));
123
+ if (nameMatches.length > 0) {
124
+ nameMatches.sort((a, b) => a[1].length - b[1].length);
125
+ return nameMatches[0][2].trim();
126
+ }
127
+ }
128
+ return taglineMatches[0][2].trim();
129
+ }
130
+
131
+ // Bold tagline near the top: "**Secure AI Retrieval. Priced by Use.**"
132
+ const boldMatch = docs.match(/\*\*([A-Z].{15,80}?)\*\*/);
133
+ if (boldMatch && !boldMatch[1].includes('Project Name')) return boldMatch[1];
134
+
135
+ return undefined;
136
+ }
137
+
138
+ /**
139
+ * Extract a meaningful description, skipping generic AI preambles
140
+ */
141
+ export function extractDescription(docs: string, specification?: string): string | undefined {
142
+ // Look for "What is [Product]?" or "About [Product]" sections in docs
143
+ // Collect all matches and prefer the one that looks most like a product description
144
+ // Reason: "What is a Secured Retrieval?" in pricing doc should not beat "What Is Gateco?" in spec
145
+ const descPattern = /##\s+(?:\d+\.\s*)?(?:What\s+Is|About(?!\s+(?:This|the)))\b[^\n]*\n+([\s\S]*?)(?=\n##\s|\n---)/gi;
146
+ const descMatches = [...docs.matchAll(descPattern)];
147
+ // Sort: prefer matches whose heading has just a product name (no articles like "a/an/the")
148
+ descMatches.sort((a, b) => {
149
+ const headingA = a[0].split('\n')[0];
150
+ const headingB = b[0].split('\n')[0];
151
+ const hasArticleA = /what\s+is\s+(?:a|an|the)\s/i.test(headingA) ? 1 : 0;
152
+ const hasArticleB = /what\s+is\s+(?:a|an|the)\s/i.test(headingB) ? 1 : 0;
153
+ return hasArticleA - hasArticleB;
154
+ });
155
+ for (const whatIsMatch of descMatches) {
156
+ const paragraph = whatIsMatch[1].trim().split('\n\n')[0]
157
+ .replace(/\*\*/g, '').replace(/\n/g, ' ').trim();
158
+ if (paragraph.length > 30) return paragraph.slice(0, 300);
159
+ }
160
+
161
+ // Look in specification, skipping generic lines
162
+ if (specification) {
163
+ for (const line of specification.split('\n')) {
164
+ const trimmed = line.trim();
165
+ if (!trimmed || trimmed.startsWith('#') || trimmed.length < 30) continue;
166
+ const lower = trimmed.toLowerCase();
167
+ if (GENERIC_PREAMBLES.some((p) => lower.startsWith(p))) continue;
168
+ if (lower.startsWith('**project name')) continue;
169
+ return trimmed.replace(/^\*\*(.+?)\*\*:?\s*/, '$1: ').slice(0, 300);
170
+ }
171
+ }
172
+
173
+ return undefined;
174
+ }
175
+
176
+ /** Regex to filter out dev-task items that aren't real product features */
177
+ const DEV_TASK_VERBS = /^(?:implement|fix|refactor|add tests|upgrade|migrate|configure|setup|install|deploy|debug|create|build|write|update|remove|delete)/i;
178
+
179
+ /**
180
+ * Extract features from docs and specification
181
+ * Docs-first: extracts from docs only; falls back to specification if empty
182
+ * Filters out dev-task items (implement, fix, refactor, etc.)
183
+ */
184
+ export function extractFeatures(
185
+ docs: string,
186
+ specification?: string
187
+ ): Array<{ title: string; description: string }> {
188
+ // Docs-first: try docs only, then fall back to spec
189
+ // Reason: specification often contains dev tasks, not user-facing features
190
+ const docsFeatures = extractFeaturesFromSource(docs);
191
+ if (docsFeatures.length > 0) return docsFeatures;
192
+
193
+ if (specification) {
194
+ return extractFeaturesFromSource(specification);
195
+ }
196
+
197
+ return [];
198
+ }
199
+
200
+ /**
201
+ * Extract features from a single text source
202
+ */
203
+ function extractFeaturesFromSource(
204
+ source: string
205
+ ): Array<{ title: string; description: string }> {
206
+ const features: Array<{ title: string; description: string }> = [];
207
+
208
+ // Split into sections by heading
209
+ const sectionPattern = /^#{1,3}\s+(.+)$/gm;
210
+ const sections: Array<{ heading: string; content: string }> = [];
211
+ let lastIndex = 0;
212
+ let lastHeading = '';
213
+ let match;
214
+
215
+ while ((match = sectionPattern.exec(source)) !== null) {
216
+ if (lastIndex > 0) {
217
+ sections.push({
218
+ heading: lastHeading,
219
+ content: source.slice(lastIndex, match.index),
220
+ });
221
+ }
222
+ lastHeading = match[1];
223
+ lastIndex = match.index + match[0].length;
224
+ }
225
+ if (lastIndex > 0) {
226
+ sections.push({ heading: lastHeading, content: source.slice(lastIndex) });
227
+ }
228
+
229
+ // Find sections about product features, principles, capabilities
230
+ // Reason: pattern must be specific to avoid matching design docs ("Feature Gating", "Enforcement Colors")
231
+ // "features" requires plural or "Key/Core Features" prefix to avoid "Feature Gating"
232
+ const featureKeywords = /(?:key|core|main)?\s*features\b|principle|capabilit|what\s+(?:it|we)\s+do|core\s+design/i;
233
+
234
+ for (const section of sections) {
235
+ if (!featureKeywords.test(section.heading)) continue;
236
+
237
+ // Collect bullet points (- or * or +) and numbered items (1. 2. 3.)
238
+ const items = section.content.match(/^(?:[-*+]|\d+\.)\s+.+/gm);
239
+ if (!items) continue;
240
+
241
+ for (const item of items) {
242
+ const text = item.replace(/^(?:[-*+]|\d+\.)\s+/, '');
243
+
244
+ // Try "**bold title** - description" pattern
245
+ const boldWithDesc = text.match(/^\*\*(.+?)\*\*\s*[-–:]\s*(.+)/);
246
+ if (boldWithDesc) {
247
+ const title = boldWithDesc[1].trim();
248
+ // Filter out dev-task items
249
+ if (DEV_TASK_VERBS.test(title)) continue;
250
+ features.push({
251
+ title,
252
+ description: boldWithDesc[2].trim().slice(0, 150),
253
+ });
254
+ } else if (/^\*\*.+\*\*/.test(text)) {
255
+ // Bold title with no trailing description: "**Vector DB agnostic**"
256
+ const title = text.replace(/\*\*/g, '').trim();
257
+ if (DEV_TASK_VERBS.test(title)) continue;
258
+ if (title.length > 3 && title.length < 80) {
259
+ features.push({ title, description: title });
260
+ }
261
+ } else {
262
+ const cleaned = text.replace(/\*\*/g, '');
263
+ // Split on sentence-level delimiters only; keep hyphens in compound words
264
+ const titlePart = cleaned.split(/[.,:;—–]/)[0].trim();
265
+ // Filter out dev-task items
266
+ if (DEV_TASK_VERBS.test(titlePart)) continue;
267
+ if (titlePart.length > 3 && titlePart.length < 60) {
268
+ features.push({
269
+ title: titlePart,
270
+ description: cleaned.slice(0, 150),
271
+ });
272
+ }
273
+ }
274
+
275
+ if (features.length >= 6) break;
276
+ }
277
+
278
+ if (features.length > 0) break;
279
+ }
280
+
281
+ return features;
282
+ }
283
+
284
+ /**
285
+ * Extract pricing tiers from docs
286
+ * Parses markdown tables and "Plan Positioning" sections
287
+ */
288
+ export function extractPricing(
289
+ docs: string
290
+ ): Array<{
291
+ name: string; price: string; period?: string;
292
+ description: string; features: string[];
293
+ cta: string; featured?: boolean;
294
+ }> | undefined {
295
+ const tiers: Array<{
296
+ name: string; price: string; period?: string;
297
+ description: string; features: string[];
298
+ cta: string; featured?: boolean;
299
+ }> = [];
300
+
301
+ // Find the pricing section to avoid matching design token tables
302
+ // Reason: "Plan-Based Color Usage" matches "Plans?" - require "Pricing" keyword
303
+ const pricingSection = docs.match(
304
+ /##\s+(?:[\d.]*\s*)?Pricing\b[^\n]*\n([\s\S]*?)(?=\n##\s(?!.*(?:Plan\s+Positioning|Feature|Comparison))|\n---(?:\s*\n##\s)|$)/i
305
+ );
306
+ const searchArea = pricingSection ? pricingSection[0] : docs;
307
+
308
+ // Look for pricing overview table rows with plan names and actual prices
309
+ const priceMap = new Map<string, string>();
310
+ const tableRows = searchArea.match(/^\|[^|]*(?:Free|Pro|Enterprise|Starter|Growth|Team|Business)[^|]*\|.+\|$/gm);
311
+ if (tableRows) {
312
+ for (const row of tableRows) {
313
+ const cells = row.split('|').map((c) => c.trim()).filter(Boolean);
314
+ if (cells.length >= 2) {
315
+ const planName = cells[0].replace(/[🟢🔵🟣⚪🟡🟠🔴]\s*/g, '').replace(/\*\*/g, '').trim();
316
+ const price = cells[1].replace(/<br>/g, ' / ').replace(/\*\*/g, '').trim();
317
+ // Require the price to look like an actual price (Free, $amount, Custom, Contact)
318
+ // Reason: avoids matching design tokens like `plan-free` from color-scheme docs
319
+ const looksLikePrice = /^free$/i.test(price) || /^\$/.test(price)
320
+ || /^custom/i.test(price) || /^contact/i.test(price);
321
+ if (looksLikePrice && !priceMap.has(planName)) {
322
+ priceMap.set(planName, price);
323
+ }
324
+ }
325
+ }
326
+ }
327
+
328
+ if (priceMap.size === 0) return undefined;
329
+
330
+ // Look for plan descriptions
331
+ const descMap = new Map<string, string>();
332
+ const positionMatch = docs.match(
333
+ /##\s+(?:Plan\s+Positioning|Plan\s+Descriptions?)[^\n]*\n([\s\S]*?)(?=\n##\s|\n---)/i
334
+ );
335
+ if (positionMatch) {
336
+ const descPattern = /[-*]\s+\*\*(.+?)\*\*\s*\n\s+\*(.+?)\*/g;
337
+ let descMatch;
338
+ while ((descMatch = descPattern.exec(positionMatch[1])) !== null) {
339
+ descMap.set(descMatch[1].trim(), descMatch[2].trim());
340
+ }
341
+ }
342
+
343
+ // Build tier objects
344
+ let index = 0;
345
+ for (const [name, price] of priceMap) {
346
+ let displayPrice = price;
347
+ let period: string | undefined;
348
+ if (/free/i.test(price)) {
349
+ displayPrice = 'Free';
350
+ } else if (/custom|contact/i.test(price)) {
351
+ displayPrice = 'Custom';
352
+ } else {
353
+ // If there's a "minimum" monthly amount (e.g. "$0.40/1K ... $99/month minimum"),
354
+ // prefer the minimum amount as the display price
355
+ const minMatch = price.match(/(\$[\d,.]+)\s*\/?\s*month\s*minimum/i);
356
+ if (minMatch) {
357
+ displayPrice = minMatch[1];
358
+ period = '/month';
359
+ } else {
360
+ const dollarMatch = price.match(/\$[\d,.]+/);
361
+ if (dollarMatch) {
362
+ displayPrice = dollarMatch[0];
363
+ if (/month/i.test(price)) period = '/month';
364
+ if (/year|annual/i.test(price)) period = '/year';
365
+ }
366
+ }
367
+ }
368
+
369
+ const description = descMap.get(name) || '';
370
+ const cta = /enterprise|custom/i.test(name) ? 'Contact sales'
371
+ : /pro/i.test(name) ? 'Start free trial'
372
+ : 'Get started';
373
+ const featured = index === 1;
374
+
375
+ tiers.push({
376
+ name: name.replace(/\(.+?\)/, '').trim(),
377
+ price: displayPrice,
378
+ period,
379
+ description,
380
+ features: [],
381
+ cta,
382
+ featured,
383
+ });
384
+ index++;
385
+ }
386
+
387
+ // Extract features per plan from comparison table
388
+ const compTable = docs.match(
389
+ /\|\s*Feature\s*\/\s*Plan\s*\|(.+)\|[\s\S]*?(?=\n\n|\n##\s|\n---)/i
390
+ );
391
+ if (compTable && tiers.length > 0) {
392
+ const rows = compTable[0].split('\n').filter((r) => r.startsWith('|'));
393
+ for (const row of rows.slice(2)) {
394
+ const cells = row.split('|').map((c) => c.trim()).filter(Boolean);
395
+ if (cells.length < 2) continue;
396
+ const featureName = cells[0].replace(/\*\*/g, '').trim();
397
+ if (!featureName || /^[-=]+$/.test(featureName)) continue;
398
+
399
+ for (let i = 0; i < tiers.length && i + 1 < cells.length; i++) {
400
+ const val = cells[i + 1].trim();
401
+ if (val && val !== '❌') {
402
+ const display = val === '✅' ? featureName : `${featureName}: ${val}`;
403
+ tiers[i].features.push(display);
404
+ }
405
+ }
406
+ }
407
+ }
408
+
409
+ for (const tier of tiers) {
410
+ tier.features = tier.features.slice(0, 6);
411
+ }
412
+
413
+ return tiers.length > 0 ? tiers : undefined;
414
+ }
415
+
416
+ /**
417
+ * Extract the primary brand/accent color, not just any hex color
418
+ * Looks for accent/primary/CTA color tokens, avoids dark backgrounds
419
+ */
420
+ export function extractPrimaryColor(docs: string): string | undefined {
421
+ // Look for "accent-primary" or "accent_primary" token with nearby hex
422
+ const accentMatch = docs.match(/accent[_-]?primary[^#]{0,40}(#[0-9a-fA-F]{6})/i);
423
+ if (accentMatch) return accentMatch[1];
424
+
425
+ // Look for "Primary Brand" or "Primary CTA" color label near a hex value
426
+ const primaryMatch = docs.match(
427
+ /(?:primary\s+(?:brand\s+)?(?:accent|color|CTA))[^#]{0,40}(#[0-9a-fA-F]{6})/i
428
+ );
429
+ if (primaryMatch) return primaryMatch[1];
430
+
431
+ // Look for CTA/link color
432
+ const ctaMatch = docs.match(/(?:CTA|primary\s+link)[^#]{0,40}(#[0-9a-fA-F]{6})/i);
433
+ if (ctaMatch) return ctaMatch[1];
434
+
435
+ // Fallback: first hex color that isn't very dark or very light
436
+ const allColors = [...docs.matchAll(/#([0-9a-fA-F]{6})/g)];
437
+ for (const colorMatch of allColors) {
438
+ const hex = colorMatch[1];
439
+ const r = parseInt(hex.substring(0, 2), 16);
440
+ const g = parseInt(hex.substring(2, 4), 16);
441
+ const b = parseInt(hex.substring(4, 6), 16);
442
+ const brightness = (r * 299 + g * 587 + b * 114) / 1000;
443
+ if (brightness > 60 && brightness < 210) {
444
+ return '#' + hex;
445
+ }
446
+ }
447
+
448
+ return undefined;
449
+ }