@istmx/skills 1.2.0 → 2.0.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 (111) hide show
  1. package/README.md +38 -20
  2. package/bin/cli.js +50 -24
  3. package/istm-animate/SKILL.md +31 -26
  4. package/istm-animate/core/motion-principles/SKILL.md +284 -0
  5. package/istm-animate/core/motion-principles/references/designers.md +127 -0
  6. package/istm-animate/core/motion-principles/references/easing-guide.md +231 -0
  7. package/istm-animate/core/motion-principles/references/enter-exit-recipes.md +466 -0
  8. package/istm-animate/frameworks/canvas-generative/SKILL.md +325 -0
  9. package/istm-animate/frameworks/canvas-generative/references/algorithms.md +925 -0
  10. package/istm-animate/frameworks/css-native/SKILL.md +319 -0
  11. package/istm-animate/frameworks/css-native/references/modern-css.md +465 -0
  12. package/istm-animate/frameworks/framer-motion/SKILL.md +187 -0
  13. package/istm-animate/frameworks/framer-motion/references/api.md +312 -0
  14. package/istm-animate/frameworks/gsap/SKILL.md +188 -0
  15. package/istm-animate/frameworks/gsap/references/core.md +218 -0
  16. package/istm-animate/frameworks/gsap/references/plugins.md +371 -0
  17. package/istm-animate/frameworks/gsap/references/scrolltrigger.md +325 -0
  18. package/istm-animate/frameworks/gsap/references/timeline.md +218 -0
  19. package/istm-animate/frameworks/threejs-r3f/SKILL.md +243 -0
  20. package/istm-animate/frameworks/threejs-r3f/references/scene-setup.md +392 -0
  21. package/istm-animate/frameworks/threejs-r3f/references/shaders.md +446 -0
  22. package/istm-animate/mobile/android/compose-graphics/SKILL.md +503 -0
  23. package/istm-animate/mobile/android/compose-graphics/references/agsl-recipes.md +356 -0
  24. package/istm-animate/mobile/android/compose-graphics/references/canvas-generative.md +282 -0
  25. package/istm-animate/mobile/android/compose-graphics/references/m3-expressive-deep.md +303 -0
  26. package/istm-animate/mobile/android/compose-motion/SKILL.md +359 -0
  27. package/istm-animate/mobile/android/compose-motion/references/gestures-compose.md +273 -0
  28. package/istm-animate/mobile/android/compose-motion/references/recomposition-and-anim.md +196 -0
  29. package/istm-animate/mobile/android/compose-motion/references/shared-transitions.md +281 -0
  30. package/istm-animate/mobile/android/compose-multiplatform/SKILL.md +311 -0
  31. package/istm-animate/mobile/android/compose-multiplatform/references/cmp-interop.md +288 -0
  32. package/istm-animate/mobile/android/compose-multiplatform/references/cmp-platform-quirks.md +156 -0
  33. package/istm-animate/mobile/apple/swiftui-graphics/SKILL.md +408 -0
  34. package/istm-animate/mobile/apple/swiftui-graphics/references/canvas-swiftui.md +239 -0
  35. package/istm-animate/mobile/apple/swiftui-graphics/references/liquid-glass-deep.md +252 -0
  36. package/istm-animate/mobile/apple/swiftui-graphics/references/metal-recipes.md +382 -0
  37. package/istm-animate/mobile/apple/swiftui-motion/SKILL.md +379 -0
  38. package/istm-animate/mobile/apple/swiftui-motion/references/gestures-swiftui.md +336 -0
  39. package/istm-animate/mobile/apple/swiftui-motion/references/phase-keyframe-deep.md +231 -0
  40. package/istm-animate/mobile/apple/swiftui-motion/references/springs-cheatsheet.md +129 -0
  41. package/istm-animate/references/animate.md +199 -0
  42. package/istm-animate/references/audit.md +115 -0
  43. package/istm-animate/references/design-engineering.md +674 -0
  44. package/istm-animate/references/improve.md +101 -0
  45. package/istm-animate/references/opportunities.md +132 -0
  46. package/istm-animate/references/plan-template.md +73 -0
  47. package/istm-animate/references/recipes.md +324 -0
  48. package/istm-animate/references/review.md +112 -0
  49. package/istm-animate/references/standards.md +187 -0
  50. package/istm-animate/references/vocabulary.md +173 -0
  51. package/istm-awwward-designer/SKILL.md +29 -17
  52. package/istm-design/SKILL.md +31 -59
  53. package/istm-design/core/design-audit/SKILL.md +248 -0
  54. package/istm-design/core/desktop-principles/SKILL.md +363 -0
  55. package/istm-design/core/desktop-principles/references/keyboard-patterns.md +137 -0
  56. package/istm-design/core/desktop-principles/references/multi-window.md +105 -0
  57. package/istm-design/core/mobile-principles/SKILL.md +289 -0
  58. package/istm-design/core/mobile-principles/references/accessibility-mobile.md +175 -0
  59. package/istm-design/core/mobile-principles/references/gestures-deep.md +220 -0
  60. package/istm-design/core/ui-ux-pro-max/SKILL.md +392 -0
  61. package/istm-design/core/ui-ux-pro-max/UPSTREAM.md +23 -0
  62. package/istm-design/core/ui-ux-pro-max/data/app-interface.csv +31 -0
  63. package/istm-design/core/ui-ux-pro-max/data/charts.csv +26 -0
  64. package/istm-design/core/ui-ux-pro-max/data/colors.csv +193 -0
  65. package/istm-design/core/ui-ux-pro-max/data/google-fonts.csv +1924 -0
  66. package/istm-design/core/ui-ux-pro-max/data/icons.csv +106 -0
  67. package/istm-design/core/ui-ux-pro-max/data/landing.csv +35 -0
  68. package/istm-design/core/ui-ux-pro-max/data/motion.csv +17 -0
  69. package/istm-design/core/ui-ux-pro-max/data/products.csv +193 -0
  70. package/istm-design/core/ui-ux-pro-max/data/react-performance.csv +45 -0
  71. package/istm-design/core/ui-ux-pro-max/data/stacks/angular.csv +51 -0
  72. package/istm-design/core/ui-ux-pro-max/data/stacks/astro.csv +54 -0
  73. package/istm-design/core/ui-ux-pro-max/data/stacks/avalonia.csv +57 -0
  74. package/istm-design/core/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  75. package/istm-design/core/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  76. package/istm-design/core/ui-ux-pro-max/data/stacks/javafx.csv +76 -0
  77. package/istm-design/core/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  78. package/istm-design/core/ui-ux-pro-max/data/stacks/laravel.csv +51 -0
  79. package/istm-design/core/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  80. package/istm-design/core/ui-ux-pro-max/data/stacks/nuxt-ui.csv +71 -0
  81. package/istm-design/core/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  82. package/istm-design/core/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  83. package/istm-design/core/ui-ux-pro-max/data/stacks/react.csv +54 -0
  84. package/istm-design/core/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  85. package/istm-design/core/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  86. package/istm-design/core/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  87. package/istm-design/core/ui-ux-pro-max/data/stacks/threejs.csv +54 -0
  88. package/istm-design/core/ui-ux-pro-max/data/stacks/uno.csv +60 -0
  89. package/istm-design/core/ui-ux-pro-max/data/stacks/uwp.csv +56 -0
  90. package/istm-design/core/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  91. package/istm-design/core/ui-ux-pro-max/data/stacks/winui.csv +60 -0
  92. package/istm-design/core/ui-ux-pro-max/data/stacks/wpf.csv +57 -0
  93. package/istm-design/core/ui-ux-pro-max/data/styles.csv +85 -0
  94. package/istm-design/core/ui-ux-pro-max/data/typography.csv +75 -0
  95. package/istm-design/core/ui-ux-pro-max/data/ui-reasoning.csv +162 -0
  96. package/istm-design/core/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  97. package/istm-design/core/ui-ux-pro-max/references/pro-rules.md +109 -0
  98. package/istm-design/core/ui-ux-pro-max/references/quick-reference.md +240 -0
  99. package/istm-design/core/ui-ux-pro-max/scripts/core.py +464 -0
  100. package/istm-design/core/ui-ux-pro-max/scripts/design_system.py +1371 -0
  101. package/istm-design/core/ui-ux-pro-max/scripts/search.py +162 -0
  102. package/istm-design/core/ui-ux-pro-max/scripts/tests/test_core.py +134 -0
  103. package/istm-design/core/ui-ux-pro-max/scripts/validate_data.py +114 -0
  104. package/istm-design/references/apple-design.md +282 -0
  105. package/istm-design/references/generation-guide.md +209 -0
  106. package/istm-design/references/pick-ui-library.md +77 -0
  107. package/istm-design/references/picker.md +197 -0
  108. package/istm-design/references/prototype.md +90 -0
  109. package/istm-design/references/schema.md +366 -0
  110. package/package.json +1 -1
  111. package/RELEASE_v1.2.0.md +0 -40
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ UI/UX Pro Max Search - BM25 search engine for UI/UX style guides
5
+ Usage: python search.py "<query>" [--domain <domain>] [--stack <stack>] [--max-results 3]
6
+ python search.py "<query>" --design-system [-p "Project Name"]
7
+ python search.py "<query>" --design-system --persist [-p "Project Name"] --output-dir "<project-root>" [--page "dashboard"]
8
+ python search.py "<query>" --design-system --variance 8 --motion 9 --density 7
9
+
10
+ Domains: style, color, chart, landing, product, ux, typography, google-fonts, icons, gsap, react, web
11
+ Stacks: react, nextjs, vue, svelte, astro, swiftui, react-native, flutter, nuxtjs, nuxt-ui,
12
+ html-tailwind, shadcn, jetpack-compose, threejs, angular, laravel
13
+
14
+ Design dials (1-10, only with --design-system):
15
+ --variance DESIGN_VARIANCE: 1=centered/minimal, 10=bold/asymmetric
16
+ --motion MOTION_INTENSITY: 1=subtle, 10=complex; attaches a GSAP snippet from motion.csv
17
+ --density VISUAL_DENSITY: 1=spacious, 10=dense/dashboard; overrides the spacing scale
18
+
19
+ Persistence (Master + Overrides pattern):
20
+ --persist Save design system to design-system/<project-slug>/MASTER.md
21
+ --output-dir Directory the design-system/ folder is created under (defaults to cwd --
22
+ always pass this explicitly, pointed at the project root)
23
+ --page Also create a page-specific override file in design-system/<project-slug>/pages/
24
+ --force Overwrite an existing MASTER.md (without this, persistence is skipped
25
+ if MASTER.md already exists, so prior design decisions aren't lost)
26
+ """
27
+
28
+ import argparse
29
+ import json as json_module
30
+ import sys
31
+ import io
32
+ from core import CSV_CONFIG, AVAILABLE_STACKS, MAX_RESULTS, UNTRUNCATED_COLS, search, search_stack
33
+ from design_system import generate_design_system
34
+
35
+ # Force UTF-8 for stdout/stderr to handle emojis on Windows (cp1252 default)
36
+ if sys.stdout.encoding and sys.stdout.encoding.lower() != 'utf-8':
37
+ sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
38
+ if sys.stderr.encoding and sys.stderr.encoding.lower() != 'utf-8':
39
+ sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
40
+
41
+ TRUNCATE_AT = 300
42
+
43
+
44
+ def format_output(result, full=False):
45
+ """Format results for Claude consumption (token-optimized)"""
46
+ if "error" in result:
47
+ return f"Error: {result['error']}"
48
+
49
+ output = []
50
+ if result.get("stack"):
51
+ output.append("## UI Pro Max Stack Guidelines")
52
+ output.append(f"**Stack:** {result['stack']} | **Query:** {result['query']}")
53
+ else:
54
+ output.append("## UI Pro Max Search Results")
55
+ domain_note = result['domain']
56
+ if result.get("auto_detected"):
57
+ domain_note += " (auto-detected"
58
+ if result.get("runner_up_domain"):
59
+ domain_note += f", runner-up: {result['runner_up_domain']}"
60
+ domain_note += ")"
61
+ output.append(f"**Domain:** {domain_note} | **Query:** {result['query']}")
62
+ output.append(f"**Source:** {result['file']} | **Found:** {result['count']} results\n")
63
+
64
+ if result['count'] == 0:
65
+ output.append(
66
+ "No matches. This is not a match with an empty value -- the query "
67
+ "did not hit the database. Retry with broader/different keywords "
68
+ "before falling back to general defaults, and say explicitly that "
69
+ "no database match was found if you do fall back."
70
+ )
71
+ suggestions = result.get("suggestions") or []
72
+ if suggestions:
73
+ output.append(f"**Closest known terms:** {', '.join(suggestions)}")
74
+ return "\n".join(output)
75
+
76
+ for i, row in enumerate(result['results'], 1):
77
+ output.append(f"### Result {i}")
78
+ for key, value in row.items():
79
+ value_str = str(value)
80
+ if not full and key not in UNTRUNCATED_COLS and len(value_str) > TRUNCATE_AT:
81
+ value_str = value_str[:TRUNCATE_AT] + "..."
82
+ output.append(f"- **{key}:** {value_str}")
83
+ output.append("")
84
+
85
+ return "\n".join(output)
86
+
87
+
88
+ if __name__ == "__main__":
89
+ parser = argparse.ArgumentParser(description="UI Pro Max Search")
90
+ parser.add_argument("query", help="Search query")
91
+ parser.add_argument("--domain", "-d", choices=list(CSV_CONFIG.keys()), help="Search domain")
92
+ parser.add_argument("--stack", "-s", choices=AVAILABLE_STACKS, help=f"Stack-specific search. Available: {', '.join(AVAILABLE_STACKS)}")
93
+ parser.add_argument("--max-results", "-n", type=int, default=MAX_RESULTS, help="Max results (default: 3)")
94
+ parser.add_argument("--json", action="store_true", help="Output as JSON")
95
+ parser.add_argument("--full", action="store_true", help="Do not truncate long field values in text output")
96
+ # Design system generation
97
+ parser.add_argument("--design-system", "-ds", action="store_true", help="Generate complete design system recommendation")
98
+ parser.add_argument("--project-name", "-p", type=str, default=None, help="Project name for design system output")
99
+ parser.add_argument("--format", "-f", choices=["ascii", "markdown"], default="ascii", help="Output format for design system (ignored if --json)")
100
+ # Persistence (Master + Overrides pattern)
101
+ parser.add_argument("--persist", action="store_true", help="Save design system to design-system/<project-slug>/MASTER.md (creates hierarchical structure)")
102
+ parser.add_argument("--page", type=str, default=None, help="Create page-specific override file in design-system/<project-slug>/pages/")
103
+ parser.add_argument("--output-dir", "-o", type=str, default=None, help="Output directory for persisted files (default: current directory -- pass this explicitly, pointed at the project root)")
104
+ parser.add_argument("--force", action="store_true", help="Overwrite an existing MASTER.md when persisting (default: skip if it already exists)")
105
+ # Design dials (1-10), only applied with --design-system
106
+ parser.add_argument("--variance", type=int, choices=range(1, 11), metavar="1-10", help="DESIGN_VARIANCE dial: 1=centered/minimal, 10=bold/asymmetric (only with --design-system)")
107
+ parser.add_argument("--motion", type=int, choices=range(1, 11), metavar="1-10", help="MOTION_INTENSITY dial: 1=subtle, 10=complex; pulls a matching GSAP snippet from motion.csv (only with --design-system)")
108
+ parser.add_argument("--density", type=int, choices=range(1, 11), metavar="1-10", help="VISUAL_DENSITY dial: 1=spacious, 10=dense/dashboard; overrides the spacing scale (only with --design-system)")
109
+
110
+ args = parser.parse_args()
111
+
112
+ # Design system takes priority
113
+ if args.design_system:
114
+ result = generate_design_system(
115
+ args.query,
116
+ args.project_name,
117
+ args.format,
118
+ persist=args.persist,
119
+ page=args.page,
120
+ output_dir=args.output_dir,
121
+ variance=args.variance,
122
+ motion=args.motion,
123
+ density=args.density,
124
+ force=args.force,
125
+ )
126
+
127
+ if args.json:
128
+ print(json_module.dumps(
129
+ {"design_system": result["design_system"], "persistence": result["persistence"]},
130
+ indent=2, ensure_ascii=False,
131
+ ))
132
+ else:
133
+ print(result["text"])
134
+
135
+ if args.persist:
136
+ persistence = result["persistence"] or {}
137
+ print("\n" + "=" * 60)
138
+ if persistence.get("status") == "skipped_exists":
139
+ print(f"⚠️ {persistence.get('message', 'MASTER.md already exists; not overwritten.')}")
140
+ else:
141
+ ds_dir = persistence.get("design_system_dir", "design-system/<project>")
142
+ print(f"✅ Design system persisted to {ds_dir}/")
143
+ for f in persistence.get("created_files", []):
144
+ print(f" 📄 {f}")
145
+ print("")
146
+ print(f"📖 Usage: When building a page, check {ds_dir}/pages/[page].md first.")
147
+ print(" If it exists, its rules override MASTER.md. Otherwise, use MASTER.md.")
148
+ print("=" * 60)
149
+ # Stack search
150
+ elif args.stack:
151
+ result = search_stack(args.query, args.stack, args.max_results)
152
+ if args.json:
153
+ print(json_module.dumps(result, indent=2, ensure_ascii=False))
154
+ else:
155
+ print(format_output(result, full=args.full))
156
+ # Domain search
157
+ else:
158
+ result = search(args.query, args.domain, args.max_results)
159
+ if args.json:
160
+ print(json_module.dumps(result, indent=2, ensure_ascii=False))
161
+ else:
162
+ print(format_output(result, full=args.full))
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Stdlib-only regression tests for core.py / design_system.py (unittest, not
5
+ pytest -- this project ships with zero external dependencies and the tests
6
+ shouldn't add one).
7
+
8
+ Run with:
9
+ python -m unittest discover -s scripts/tests -v
10
+ or directly:
11
+ python scripts/tests/test_core.py
12
+ """
13
+
14
+ import sys
15
+ import tempfile
16
+ import unittest
17
+ from pathlib import Path
18
+
19
+ SCRIPTS_DIR = Path(__file__).resolve().parent.parent
20
+ sys.path.insert(0, str(SCRIPTS_DIR))
21
+
22
+ from core import BM25, detect_domain, search, search_stack, CSV_CONFIG, AVAILABLE_STACKS
23
+ from design_system import generate_design_system, persist_design_system, DesignSystemGenerator
24
+
25
+
26
+ class TestTokenizer(unittest.TestCase):
27
+ def test_short_domain_terms_are_kept(self):
28
+ bm25 = BM25()
29
+ tokens = bm25.tokenize("UI and UX design with 3D and AI")
30
+ self.assertIn("ui", tokens)
31
+ self.assertIn("3d", tokens)
32
+ self.assertIn("ai", tokens)
33
+
34
+ def test_stopwords_removed(self):
35
+ bm25 = BM25()
36
+ tokens = bm25.tokenize("this is for the team to do")
37
+ for stopword in ("is", "for", "the", "to", "do"):
38
+ self.assertNotIn(stopword, tokens)
39
+
40
+ def test_synonym_normalization(self):
41
+ bm25 = BM25()
42
+ self.assertEqual(bm25.tokenize("e-commerce store"), bm25.tokenize("ecommerce store"))
43
+ self.assertEqual(bm25.tokenize("dark-mode toggle"), bm25.tokenize("dark toggle"))
44
+
45
+
46
+ class TestSearchDomains(unittest.TestCase):
47
+ """Known query -> expected top-domain sanity checks (not exact-row pinning,
48
+ since data can grow; these assert the engine still finds *something*
49
+ relevant for each domain's core vocabulary)."""
50
+
51
+ def test_ui_is_searchable_in_style_domain(self):
52
+ result = search("ui minimalism", domain="style", max_results=1)
53
+ self.assertGreater(result["count"], 0, "literal 'ui' token must be searchable, not filtered by tokenizer")
54
+
55
+ def test_accessibility_query_hits_ux(self):
56
+ result = search("accessibility contrast wcag keyboard", domain="ux", max_results=3)
57
+ self.assertGreater(result["count"], 0)
58
+
59
+ def test_zero_result_query_reports_suggestions_not_error(self):
60
+ result = search("zzqqxx totally made up gibberish", domain="ux", max_results=2)
61
+ self.assertEqual(result["count"], 0)
62
+ self.assertIn("suggestions", result)
63
+ self.assertNotIn("error", result)
64
+
65
+ def test_every_configured_domain_file_exists_and_is_searchable(self):
66
+ for domain, config in CSV_CONFIG.items():
67
+ with self.subTest(domain=domain):
68
+ result = search("design", domain=domain, max_results=1)
69
+ self.assertNotIn("error", result, f"domain '{domain}' failed: {result.get('error')}")
70
+
71
+ def test_every_stack_file_exists_and_is_searchable(self):
72
+ for stack in AVAILABLE_STACKS:
73
+ with self.subTest(stack=stack):
74
+ result = search_stack("performance", stack, max_results=1)
75
+ self.assertNotIn("error", result, f"stack '{stack}' failed: {result.get('error')}")
76
+
77
+
78
+ class TestDomainDetection(unittest.TestCase):
79
+ def test_style_keywords_route_to_style(self):
80
+ self.assertEqual(detect_domain("glassmorphism dark ui"), "style")
81
+
82
+ def test_accessibility_keywords_route_to_ux(self):
83
+ self.assertEqual(detect_domain("accessibility contrast wcag"), "ux")
84
+
85
+ def test_ambiguous_query_returns_runner_up(self):
86
+ domain, runner_up = detect_domain("font pairing elegant crypto", return_scores=True)
87
+ self.assertIsNotNone(domain)
88
+ # runner_up may be None if the winning domain has no close second --
89
+ # this just verifies the call shape works without raising.
90
+
91
+ def test_empty_query_falls_back_to_style(self):
92
+ self.assertEqual(detect_domain("...!!!???"), "style")
93
+
94
+
95
+ class TestPersistence(unittest.TestCase):
96
+ def test_persist_then_skip_then_force(self):
97
+ with tempfile.TemporaryDirectory() as tmp:
98
+ result = generate_design_system("saas dashboard", "Test Project", persist=True, output_dir=tmp)
99
+ self.assertEqual(result["persistence"]["status"], "success")
100
+ master = Path(result["persistence"]["master_file"])
101
+ self.assertTrue(master.exists())
102
+ original_content = master.read_text(encoding="utf-8")
103
+
104
+ # Second persist without force must not overwrite.
105
+ result2 = generate_design_system("saas dashboard", "Test Project", persist=True, output_dir=tmp)
106
+ self.assertEqual(result2["persistence"]["status"], "skipped_exists")
107
+ self.assertEqual(master.read_text(encoding="utf-8"), original_content)
108
+
109
+ # With force=True it must overwrite.
110
+ result3 = generate_design_system("ecommerce luxury", "Test Project", persist=True, output_dir=tmp, force=True)
111
+ self.assertEqual(result3["persistence"]["status"], "success")
112
+
113
+ def test_persist_writes_only_under_output_dir(self):
114
+ with tempfile.TemporaryDirectory() as tmp:
115
+ generate_design_system("saas dashboard", "Scoped Project", persist=True, output_dir=tmp)
116
+ expected = Path(tmp) / "design-system" / "scoped-project" / "MASTER.md"
117
+ self.assertTrue(expected.exists())
118
+
119
+
120
+ class TestReasoningMatch(unittest.TestCase):
121
+ def test_known_category_matches_exactly(self):
122
+ gen = DesignSystemGenerator()
123
+ rule = gen._find_reasoning_rule("SaaS (General)")
124
+ self.assertTrue(rule, "exact-match category lookup should not fall through to fuzzy matching")
125
+
126
+ def test_unknown_category_falls_back_gracefully(self):
127
+ gen = DesignSystemGenerator()
128
+ rule = gen._find_reasoning_rule("Totally Unknown Category XYZ")
129
+ # Should not raise; may return {} which _apply_reasoning handles with defaults.
130
+ self.assertIsInstance(rule, dict)
131
+
132
+
133
+ if __name__ == "__main__":
134
+ unittest.main()
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Data integrity guardrail for ui-ux-pro-max. Stdlib-only, no pytest dependency,
5
+ so it can run as a standalone pre-publish/CI check:
6
+
7
+ python validate_data.py
8
+
9
+ Checks, per configured domain/stack CSV:
10
+ - file exists
11
+ - header row contains every column referenced in search_cols/output_cols
12
+ - no duplicate primary-key values (first column) within a file
13
+ - any "Decision_Rules"-style JSON column parses as JSON
14
+
15
+ Exits 0 with no output on success; exits 1 and prints every problem found
16
+ on failure (fail-fast is the wrong call here -- a data change can break
17
+ several files at once, so we want the full list in one run).
18
+ """
19
+
20
+ import csv
21
+ import json
22
+ import sys
23
+ from pathlib import Path
24
+
25
+ from core import CSV_CONFIG, STACK_CONFIG, _STACK_COLS, DATA_DIR
26
+
27
+ # REASONING_FILE lives in design_system.py, not core.py -- redeclared here to
28
+ # avoid a circular import (design_system.py imports core.py).
29
+ REASONING_FILE = "ui-reasoning.csv"
30
+ JSON_COLUMNS = {"Decision_Rules"}
31
+
32
+
33
+ def _read_rows(filepath):
34
+ with open(filepath, "r", encoding="utf-8") as f:
35
+ reader = csv.DictReader(f)
36
+ return reader.fieldnames or [], list(reader)
37
+
38
+
39
+ def _check_file(label, filepath, search_cols, output_cols, problems):
40
+ if not filepath.exists():
41
+ problems.append(f"[{label}] missing file: {filepath}")
42
+ return
43
+
44
+ try:
45
+ headers, rows = _read_rows(filepath)
46
+ except (csv.Error, UnicodeDecodeError, OSError) as e:
47
+ problems.append(f"[{label}] failed to parse {filepath.name}: {e}")
48
+ return
49
+
50
+ header_set = set(headers)
51
+ for col in set(search_cols) | set(output_cols):
52
+ if col not in header_set:
53
+ problems.append(f"[{label}] {filepath.name}: expected column '{col}' not found in header")
54
+
55
+ # Only check for duplicates against an actual identifier column ("No" is
56
+ # the sequential-index convention used across this dataset). The first
57
+ # CSV column is not reliably a unique key -- e.g. stack files use
58
+ # "Category", which legitimately repeats across many guideline rows.
59
+ if "No" in header_set:
60
+ seen = {}
61
+ for i, row in enumerate(rows, start=2): # +1 header, +1 to be 1-indexed
62
+ key = row.get("No", "")
63
+ if key in seen:
64
+ problems.append(
65
+ f"[{label}] {filepath.name}: duplicate 'No' value '{key}' on rows {seen[key]} and {i}"
66
+ )
67
+ else:
68
+ seen[key] = i
69
+ elif label.startswith("stack:"):
70
+ problems.append(
71
+ f"[{label}] {filepath.name}: missing 'No' index column present in other stack files "
72
+ "(schema drift -- harmless for search, but inconsistent with the rest of data/stacks/)"
73
+ )
74
+
75
+ for row_idx, row in enumerate(rows, start=2):
76
+ for col in JSON_COLUMNS:
77
+ if col in row and row[col]:
78
+ try:
79
+ json.loads(row[col])
80
+ except json.JSONDecodeError as e:
81
+ problems.append(
82
+ f"[{label}] {filepath.name} row {row_idx}: column '{col}' is not valid JSON: {e}"
83
+ )
84
+
85
+
86
+ def main():
87
+ problems = []
88
+
89
+ for domain, config in CSV_CONFIG.items():
90
+ _check_file(f"domain:{domain}", DATA_DIR / config["file"],
91
+ config["search_cols"], config["output_cols"], problems)
92
+
93
+ for stack, config in STACK_CONFIG.items():
94
+ _check_file(f"stack:{stack}", DATA_DIR / config["file"],
95
+ _STACK_COLS["search_cols"], _STACK_COLS["output_cols"], problems)
96
+
97
+ reasoning_path = DATA_DIR / REASONING_FILE
98
+ if reasoning_path.exists():
99
+ _check_file("reasoning", reasoning_path, ["UI_Category"], ["UI_Category", "Decision_Rules"], problems)
100
+ else:
101
+ problems.append(f"[reasoning] missing file: {reasoning_path}")
102
+
103
+ if problems:
104
+ print(f"FAILED: {len(problems)} data integrity issue(s) found:\n")
105
+ for p in problems:
106
+ print(f" - {p}")
107
+ sys.exit(1)
108
+
109
+ print(f"OK: validated {len(CSV_CONFIG)} domain files, {len(STACK_CONFIG)} stack files, and ui-reasoning.csv")
110
+ sys.exit(0)
111
+
112
+
113
+ if __name__ == "__main__":
114
+ main()