class-ai-agent 1.2.3 → 1.4.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 (242) hide show
  1. package/.agent/README.md +33 -0
  2. package/.agent/SESSION.md +54 -0
  3. package/.agent/SESSION.template.md +46 -0
  4. package/.claude/CLAUDE.md +24 -6
  5. package/.claude/commands/build.md +5 -4
  6. package/.claude/commands/debug.md +2 -1
  7. package/.claude/commands/handoff.md +94 -0
  8. package/.claude/commands/plan.md +1 -0
  9. package/.claude/commands/publish-npm.md +119 -0
  10. package/.claude/commands/resume.md +107 -0
  11. package/.claude/commands/spec.md +2 -1
  12. package/.claude/references/agent-continuity.md +42 -0
  13. package/.claude/references/codegraph.md +50 -0
  14. package/.claude/references/supabase.md +55 -0
  15. package/.claude/rules/agent-continuity.md +39 -0
  16. package/.claude/rules/tech-stack.md +2 -1
  17. package/.claude/skills/agent-continuity/SKILL.md +70 -0
  18. package/.claude/skills/supabase/SKILL.md +135 -0
  19. package/.claude/skills/supabase/UPSTREAM.md +16 -0
  20. package/.claude/skills/supabase/assets/feedback-issue-template.md +17 -0
  21. package/.claude/skills/supabase/references/skill-feedback.md +17 -0
  22. package/.claude/skills/supabase-postgres-best-practices/SKILL.md +64 -0
  23. package/.claude/skills/supabase-postgres-best-practices/UPSTREAM.md +16 -0
  24. package/.claude/skills/supabase-postgres-best-practices/references/_contributing.md +170 -0
  25. package/.claude/skills/supabase-postgres-best-practices/references/_sections.md +39 -0
  26. package/.claude/skills/supabase-postgres-best-practices/references/_template.md +34 -0
  27. package/.claude/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
  28. package/.claude/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
  29. package/.claude/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
  30. package/.claude/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
  31. package/.claude/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
  32. package/.claude/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
  33. package/.claude/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
  34. package/.claude/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
  35. package/.claude/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
  36. package/.claude/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
  37. package/.claude/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
  38. package/.claude/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
  39. package/.claude/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
  40. package/.claude/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
  41. package/.claude/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
  42. package/.claude/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
  43. package/.claude/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
  44. package/.claude/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
  45. package/.claude/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
  46. package/.claude/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
  47. package/.claude/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
  48. package/.claude/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
  49. package/.claude/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
  50. package/.claude/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
  51. package/.claude/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
  52. package/.claude/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
  53. package/.claude/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
  54. package/.claude/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
  55. package/.claude/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
  56. package/.claude/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
  57. package/.claude/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -0
  58. package/.cursor/CURSOR.md +40 -5
  59. package/.cursor/commands/build.md +5 -4
  60. package/.cursor/commands/debug.md +2 -1
  61. package/.cursor/commands/handoff.md +94 -0
  62. package/.cursor/commands/plan.md +1 -0
  63. package/.cursor/commands/publish-npm.md +119 -0
  64. package/.cursor/commands/resume.md +107 -0
  65. package/.cursor/commands/spec.md +2 -1
  66. package/.cursor/mcp.json +19 -0
  67. package/.cursor/references/agent-continuity.md +42 -0
  68. package/.cursor/references/codegraph.md +87 -0
  69. package/.cursor/references/supabase.md +55 -0
  70. package/.cursor/rules/agent-continuity.mdc +44 -0
  71. package/.cursor/rules/codegraph.mdc +47 -0
  72. package/.cursor/rules/cursor-overview.mdc +10 -3
  73. package/.cursor/rules/tech-stack.mdc +2 -1
  74. package/.cursor/settings.json +6 -1
  75. package/.cursor/skills/agent-continuity/SKILL.md +70 -0
  76. package/.cursor/skills/supabase/SKILL.md +135 -0
  77. package/.cursor/skills/supabase/UPSTREAM.md +16 -0
  78. package/.cursor/skills/supabase/assets/feedback-issue-template.md +17 -0
  79. package/.cursor/skills/supabase/references/skill-feedback.md +17 -0
  80. package/.cursor/skills/supabase-postgres-best-practices/SKILL.md +64 -0
  81. package/.cursor/skills/supabase-postgres-best-practices/UPSTREAM.md +16 -0
  82. package/.cursor/skills/supabase-postgres-best-practices/references/_contributing.md +170 -0
  83. package/.cursor/skills/supabase-postgres-best-practices/references/_sections.md +39 -0
  84. package/.cursor/skills/supabase-postgres-best-practices/references/_template.md +34 -0
  85. package/.cursor/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
  86. package/.cursor/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
  87. package/.cursor/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
  88. package/.cursor/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
  89. package/.cursor/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
  90. package/.cursor/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
  91. package/.cursor/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
  92. package/.cursor/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
  93. package/.cursor/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
  94. package/.cursor/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
  95. package/.cursor/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
  96. package/.cursor/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
  97. package/.cursor/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
  98. package/.cursor/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
  99. package/.cursor/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
  100. package/.cursor/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
  101. package/.cursor/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
  102. package/.cursor/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
  103. package/.cursor/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
  104. package/.cursor/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
  105. package/.cursor/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
  106. package/.cursor/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
  107. package/.cursor/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
  108. package/.cursor/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
  109. package/.cursor/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
  110. package/.cursor/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
  111. package/.cursor/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
  112. package/.cursor/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
  113. package/.cursor/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
  114. package/.cursor/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
  115. package/.cursor/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -0
  116. package/.kiro/KIRO.md +149 -0
  117. package/.kiro/agents/backend.md +395 -0
  118. package/.kiro/agents/code-reviewer.md +110 -0
  119. package/.kiro/agents/copywriter-seo.md +236 -0
  120. package/.kiro/agents/frontend.md +384 -0
  121. package/.kiro/agents/project-manager.md +201 -0
  122. package/.kiro/agents/qa.md +221 -0
  123. package/.kiro/agents/security-auditor.md +143 -0
  124. package/.kiro/agents/systems-architect.md +211 -0
  125. package/.kiro/agents/test-engineer.md +123 -0
  126. package/.kiro/agents/ui-ux-designer.md +210 -0
  127. package/.kiro/commands/build.md +133 -0
  128. package/.kiro/commands/debug.md +243 -0
  129. package/.kiro/commands/deploy.md +40 -0
  130. package/.kiro/commands/fix-issue.md +42 -0
  131. package/.kiro/commands/handoff.md +94 -0
  132. package/.kiro/commands/plan.md +126 -0
  133. package/.kiro/commands/publish-npm.md +119 -0
  134. package/.kiro/commands/resume.md +107 -0
  135. package/.kiro/commands/review.md +50 -0
  136. package/.kiro/commands/simplify.md +222 -0
  137. package/.kiro/commands/spec.md +96 -0
  138. package/.kiro/commands/test.md +214 -0
  139. package/.kiro/references/accessibility-checklist.md +174 -0
  140. package/.kiro/references/agent-continuity.md +42 -0
  141. package/.kiro/references/codegraph.md +86 -0
  142. package/.kiro/references/performance-checklist.md +150 -0
  143. package/.kiro/references/security-checklist.md +94 -0
  144. package/.kiro/references/supabase.md +55 -0
  145. package/.kiro/references/testing-patterns.md +183 -0
  146. package/.kiro/settings/mcp.json +19 -0
  147. package/.kiro/settings.json +8 -0
  148. package/.kiro/skills/agent-continuity/SKILL.md +70 -0
  149. package/.kiro/skills/code-review/SKILL.md +208 -0
  150. package/.kiro/skills/deploy/SKILL.md +68 -0
  151. package/.kiro/skills/deploy/deploy.md +735 -0
  152. package/.kiro/skills/incremental-implementation/SKILL.md +210 -0
  153. package/.kiro/skills/security-review/SKILL.md +71 -0
  154. package/.kiro/skills/supabase/SKILL.md +135 -0
  155. package/.kiro/skills/supabase/UPSTREAM.md +16 -0
  156. package/.kiro/skills/supabase/assets/feedback-issue-template.md +17 -0
  157. package/.kiro/skills/supabase/references/skill-feedback.md +17 -0
  158. package/.kiro/skills/supabase-postgres-best-practices/SKILL.md +64 -0
  159. package/.kiro/skills/supabase-postgres-best-practices/UPSTREAM.md +16 -0
  160. package/.kiro/skills/supabase-postgres-best-practices/references/_contributing.md +170 -0
  161. package/.kiro/skills/supabase-postgres-best-practices/references/_sections.md +39 -0
  162. package/.kiro/skills/supabase-postgres-best-practices/references/_template.md +34 -0
  163. package/.kiro/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
  164. package/.kiro/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
  165. package/.kiro/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
  166. package/.kiro/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
  167. package/.kiro/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
  168. package/.kiro/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
  169. package/.kiro/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
  170. package/.kiro/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
  171. package/.kiro/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
  172. package/.kiro/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
  173. package/.kiro/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
  174. package/.kiro/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
  175. package/.kiro/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
  176. package/.kiro/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
  177. package/.kiro/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
  178. package/.kiro/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
  179. package/.kiro/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
  180. package/.kiro/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
  181. package/.kiro/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
  182. package/.kiro/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
  183. package/.kiro/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
  184. package/.kiro/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
  185. package/.kiro/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
  186. package/.kiro/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
  187. package/.kiro/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
  188. package/.kiro/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
  189. package/.kiro/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
  190. package/.kiro/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
  191. package/.kiro/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
  192. package/.kiro/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
  193. package/.kiro/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -0
  194. package/.kiro/skills/tdd/SKILL.md +217 -0
  195. package/.kiro/skills/ui-ux-pro-max/SKILL.md +288 -0
  196. package/.kiro/skills/ui-ux-pro-max/data/charts.csv +26 -0
  197. package/.kiro/skills/ui-ux-pro-max/data/colors.csv +97 -0
  198. package/.kiro/skills/ui-ux-pro-max/data/icons.csv +101 -0
  199. package/.kiro/skills/ui-ux-pro-max/data/landing.csv +31 -0
  200. package/.kiro/skills/ui-ux-pro-max/data/products.csv +97 -0
  201. package/.kiro/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
  202. package/.kiro/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
  203. package/.kiro/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  204. package/.kiro/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  205. package/.kiro/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  206. package/.kiro/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  207. package/.kiro/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  208. package/.kiro/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  209. package/.kiro/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  210. package/.kiro/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
  211. package/.kiro/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  212. package/.kiro/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  213. package/.kiro/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  214. package/.kiro/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  215. package/.kiro/skills/ui-ux-pro-max/data/styles.csv +68 -0
  216. package/.kiro/skills/ui-ux-pro-max/data/typography.csv +58 -0
  217. package/.kiro/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  218. package/.kiro/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  219. package/.kiro/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
  220. package/.kiro/skills/ui-ux-pro-max/scripts/core.py +253 -0
  221. package/.kiro/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
  222. package/.kiro/skills/ui-ux-pro-max/scripts/search.py +114 -0
  223. package/.kiro/steering/agent-continuity.md +44 -0
  224. package/.kiro/steering/api-conventions.md +85 -0
  225. package/.kiro/steering/clean-code.md +211 -0
  226. package/.kiro/steering/code-style.md +92 -0
  227. package/.kiro/steering/codegraph.md +47 -0
  228. package/.kiro/steering/database.md +66 -0
  229. package/.kiro/steering/error-handling.md +98 -0
  230. package/.kiro/steering/git-workflow.md +83 -0
  231. package/.kiro/steering/kiro-overview.md +38 -0
  232. package/.kiro/steering/monitoring.md +317 -0
  233. package/.kiro/steering/naming-conventions.md +266 -0
  234. package/.kiro/steering/project-structure.md +71 -0
  235. package/.kiro/steering/security.md +95 -0
  236. package/.kiro/steering/system-design.md +168 -0
  237. package/.kiro/steering/tech-stack.md +463 -0
  238. package/.kiro/steering/testing.md +110 -0
  239. package/AGENTS.md +13 -7
  240. package/README.md +126 -18
  241. package/bin/class-ai-agent.cjs +171 -11
  242. package/package.json +12 -4
@@ -0,0 +1,253 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ UI/UX Pro Max Core - BM25 search engine for UI/UX style guides
5
+ """
6
+
7
+ import csv
8
+ import re
9
+ from pathlib import Path
10
+ from math import log
11
+ from collections import defaultdict
12
+
13
+ # ============ CONFIGURATION ============
14
+ DATA_DIR = Path(__file__).parent.parent / "data"
15
+ MAX_RESULTS = 3
16
+
17
+ CSV_CONFIG = {
18
+ "style": {
19
+ "file": "styles.csv",
20
+ "search_cols": ["Style Category", "Keywords", "Best For", "Type", "AI Prompt Keywords"],
21
+ "output_cols": ["Style Category", "Type", "Keywords", "Primary Colors", "Effects & Animation", "Best For", "Performance", "Accessibility", "Framework Compatibility", "Complexity", "AI Prompt Keywords", "CSS/Technical Keywords", "Implementation Checklist", "Design System Variables"]
22
+ },
23
+ "color": {
24
+ "file": "colors.csv",
25
+ "search_cols": ["Product Type", "Notes"],
26
+ "output_cols": ["Product Type", "Primary (Hex)", "Secondary (Hex)", "CTA (Hex)", "Background (Hex)", "Text (Hex)", "Notes"]
27
+ },
28
+ "chart": {
29
+ "file": "charts.csv",
30
+ "search_cols": ["Data Type", "Keywords", "Best Chart Type", "Accessibility Notes"],
31
+ "output_cols": ["Data Type", "Keywords", "Best Chart Type", "Secondary Options", "Color Guidance", "Accessibility Notes", "Library Recommendation", "Interactive Level"]
32
+ },
33
+ "landing": {
34
+ "file": "landing.csv",
35
+ "search_cols": ["Pattern Name", "Keywords", "Conversion Optimization", "Section Order"],
36
+ "output_cols": ["Pattern Name", "Keywords", "Section Order", "Primary CTA Placement", "Color Strategy", "Conversion Optimization"]
37
+ },
38
+ "product": {
39
+ "file": "products.csv",
40
+ "search_cols": ["Product Type", "Keywords", "Primary Style Recommendation", "Key Considerations"],
41
+ "output_cols": ["Product Type", "Keywords", "Primary Style Recommendation", "Secondary Styles", "Landing Page Pattern", "Dashboard Style (if applicable)", "Color Palette Focus"]
42
+ },
43
+ "ux": {
44
+ "file": "ux-guidelines.csv",
45
+ "search_cols": ["Category", "Issue", "Description", "Platform"],
46
+ "output_cols": ["Category", "Issue", "Platform", "Description", "Do", "Don't", "Code Example Good", "Code Example Bad", "Severity"]
47
+ },
48
+ "typography": {
49
+ "file": "typography.csv",
50
+ "search_cols": ["Font Pairing Name", "Category", "Mood/Style Keywords", "Best For", "Heading Font", "Body Font"],
51
+ "output_cols": ["Font Pairing Name", "Category", "Heading Font", "Body Font", "Mood/Style Keywords", "Best For", "Google Fonts URL", "CSS Import", "Tailwind Config", "Notes"]
52
+ },
53
+ "icons": {
54
+ "file": "icons.csv",
55
+ "search_cols": ["Category", "Icon Name", "Keywords", "Best For"],
56
+ "output_cols": ["Category", "Icon Name", "Keywords", "Library", "Import Code", "Usage", "Best For", "Style"]
57
+ },
58
+ "react": {
59
+ "file": "react-performance.csv",
60
+ "search_cols": ["Category", "Issue", "Keywords", "Description"],
61
+ "output_cols": ["Category", "Issue", "Platform", "Description", "Do", "Don't", "Code Example Good", "Code Example Bad", "Severity"]
62
+ },
63
+ "web": {
64
+ "file": "web-interface.csv",
65
+ "search_cols": ["Category", "Issue", "Keywords", "Description"],
66
+ "output_cols": ["Category", "Issue", "Platform", "Description", "Do", "Don't", "Code Example Good", "Code Example Bad", "Severity"]
67
+ }
68
+ }
69
+
70
+ STACK_CONFIG = {
71
+ "html-tailwind": {"file": "stacks/html-tailwind.csv"},
72
+ "react": {"file": "stacks/react.csv"},
73
+ "nextjs": {"file": "stacks/nextjs.csv"},
74
+ "astro": {"file": "stacks/astro.csv"},
75
+ "vue": {"file": "stacks/vue.csv"},
76
+ "nuxtjs": {"file": "stacks/nuxtjs.csv"},
77
+ "nuxt-ui": {"file": "stacks/nuxt-ui.csv"},
78
+ "svelte": {"file": "stacks/svelte.csv"},
79
+ "swiftui": {"file": "stacks/swiftui.csv"},
80
+ "react-native": {"file": "stacks/react-native.csv"},
81
+ "flutter": {"file": "stacks/flutter.csv"},
82
+ "shadcn": {"file": "stacks/shadcn.csv"},
83
+ "jetpack-compose": {"file": "stacks/jetpack-compose.csv"}
84
+ }
85
+
86
+ # Common columns for all stacks
87
+ _STACK_COLS = {
88
+ "search_cols": ["Category", "Guideline", "Description", "Do", "Don't"],
89
+ "output_cols": ["Category", "Guideline", "Description", "Do", "Don't", "Code Good", "Code Bad", "Severity", "Docs URL"]
90
+ }
91
+
92
+ AVAILABLE_STACKS = list(STACK_CONFIG.keys())
93
+
94
+
95
+ # ============ BM25 IMPLEMENTATION ============
96
+ class BM25:
97
+ """BM25 ranking algorithm for text search"""
98
+
99
+ def __init__(self, k1=1.5, b=0.75):
100
+ self.k1 = k1
101
+ self.b = b
102
+ self.corpus = []
103
+ self.doc_lengths = []
104
+ self.avgdl = 0
105
+ self.idf = {}
106
+ self.doc_freqs = defaultdict(int)
107
+ self.N = 0
108
+
109
+ def tokenize(self, text):
110
+ """Lowercase, split, remove punctuation, filter short words"""
111
+ text = re.sub(r'[^\w\s]', ' ', str(text).lower())
112
+ return [w for w in text.split() if len(w) > 2]
113
+
114
+ def fit(self, documents):
115
+ """Build BM25 index from documents"""
116
+ self.corpus = [self.tokenize(doc) for doc in documents]
117
+ self.N = len(self.corpus)
118
+ if self.N == 0:
119
+ return
120
+ self.doc_lengths = [len(doc) for doc in self.corpus]
121
+ self.avgdl = sum(self.doc_lengths) / self.N
122
+
123
+ for doc in self.corpus:
124
+ seen = set()
125
+ for word in doc:
126
+ if word not in seen:
127
+ self.doc_freqs[word] += 1
128
+ seen.add(word)
129
+
130
+ for word, freq in self.doc_freqs.items():
131
+ self.idf[word] = log((self.N - freq + 0.5) / (freq + 0.5) + 1)
132
+
133
+ def score(self, query):
134
+ """Score all documents against query"""
135
+ query_tokens = self.tokenize(query)
136
+ scores = []
137
+
138
+ for idx, doc in enumerate(self.corpus):
139
+ score = 0
140
+ doc_len = self.doc_lengths[idx]
141
+ term_freqs = defaultdict(int)
142
+ for word in doc:
143
+ term_freqs[word] += 1
144
+
145
+ for token in query_tokens:
146
+ if token in self.idf:
147
+ tf = term_freqs[token]
148
+ idf = self.idf[token]
149
+ numerator = tf * (self.k1 + 1)
150
+ denominator = tf + self.k1 * (1 - self.b + self.b * doc_len / self.avgdl)
151
+ score += idf * numerator / denominator
152
+
153
+ scores.append((idx, score))
154
+
155
+ return sorted(scores, key=lambda x: x[1], reverse=True)
156
+
157
+
158
+ # ============ SEARCH FUNCTIONS ============
159
+ def _load_csv(filepath):
160
+ """Load CSV and return list of dicts"""
161
+ with open(filepath, 'r', encoding='utf-8') as f:
162
+ return list(csv.DictReader(f))
163
+
164
+
165
+ def _search_csv(filepath, search_cols, output_cols, query, max_results):
166
+ """Core search function using BM25"""
167
+ if not filepath.exists():
168
+ return []
169
+
170
+ data = _load_csv(filepath)
171
+
172
+ # Build documents from search columns
173
+ documents = [" ".join(str(row.get(col, "")) for col in search_cols) for row in data]
174
+
175
+ # BM25 search
176
+ bm25 = BM25()
177
+ bm25.fit(documents)
178
+ ranked = bm25.score(query)
179
+
180
+ # Get top results with score > 0
181
+ results = []
182
+ for idx, score in ranked[:max_results]:
183
+ if score > 0:
184
+ row = data[idx]
185
+ results.append({col: row.get(col, "") for col in output_cols if col in row})
186
+
187
+ return results
188
+
189
+
190
+ def detect_domain(query):
191
+ """Auto-detect the most relevant domain from query"""
192
+ query_lower = query.lower()
193
+
194
+ domain_keywords = {
195
+ "color": ["color", "palette", "hex", "#", "rgb"],
196
+ "chart": ["chart", "graph", "visualization", "trend", "bar", "pie", "scatter", "heatmap", "funnel"],
197
+ "landing": ["landing", "page", "cta", "conversion", "hero", "testimonial", "pricing", "section"],
198
+ "product": ["saas", "ecommerce", "e-commerce", "fintech", "healthcare", "gaming", "portfolio", "crypto", "dashboard"],
199
+ "style": ["style", "design", "ui", "minimalism", "glassmorphism", "neumorphism", "brutalism", "dark mode", "flat", "aurora", "prompt", "css", "implementation", "variable", "checklist", "tailwind"],
200
+ "ux": ["ux", "usability", "accessibility", "wcag", "touch", "scroll", "animation", "keyboard", "navigation", "mobile"],
201
+ "typography": ["font", "typography", "heading", "serif", "sans"],
202
+ "icons": ["icon", "icons", "lucide", "heroicons", "symbol", "glyph", "pictogram", "svg icon"],
203
+ "react": ["react", "next.js", "nextjs", "suspense", "memo", "usecallback", "useeffect", "rerender", "bundle", "waterfall", "barrel", "dynamic import", "rsc", "server component"],
204
+ "web": ["aria", "focus", "outline", "semantic", "virtualize", "autocomplete", "form", "input type", "preconnect"]
205
+ }
206
+
207
+ scores = {domain: sum(1 for kw in keywords if kw in query_lower) for domain, keywords in domain_keywords.items()}
208
+ best = max(scores, key=scores.get)
209
+ return best if scores[best] > 0 else "style"
210
+
211
+
212
+ def search(query, domain=None, max_results=MAX_RESULTS):
213
+ """Main search function with auto-domain detection"""
214
+ if domain is None:
215
+ domain = detect_domain(query)
216
+
217
+ config = CSV_CONFIG.get(domain, CSV_CONFIG["style"])
218
+ filepath = DATA_DIR / config["file"]
219
+
220
+ if not filepath.exists():
221
+ return {"error": f"File not found: {filepath}", "domain": domain}
222
+
223
+ results = _search_csv(filepath, config["search_cols"], config["output_cols"], query, max_results)
224
+
225
+ return {
226
+ "domain": domain,
227
+ "query": query,
228
+ "file": config["file"],
229
+ "count": len(results),
230
+ "results": results
231
+ }
232
+
233
+
234
+ def search_stack(query, stack, max_results=MAX_RESULTS):
235
+ """Search stack-specific guidelines"""
236
+ if stack not in STACK_CONFIG:
237
+ return {"error": f"Unknown stack: {stack}. Available: {', '.join(AVAILABLE_STACKS)}"}
238
+
239
+ filepath = DATA_DIR / STACK_CONFIG[stack]["file"]
240
+
241
+ if not filepath.exists():
242
+ return {"error": f"Stack file not found: {filepath}", "stack": stack}
243
+
244
+ results = _search_csv(filepath, _STACK_COLS["search_cols"], _STACK_COLS["output_cols"], query, max_results)
245
+
246
+ return {
247
+ "domain": "stack",
248
+ "stack": stack,
249
+ "query": query,
250
+ "file": STACK_CONFIG[stack]["file"],
251
+ "count": len(results),
252
+ "results": results
253
+ }