riazmo commited on
Commit
df99f32
Β·
verified Β·
1 Parent(s): 4ee20f9

Upload llm_agents.py

Browse files
Files changed (1) hide show
  1. agents/llm_agents.py +38 -9
agents/llm_agents.py CHANGED
@@ -688,8 +688,17 @@ You are Agent 3 of 4 in the Design System Analysis pipeline.
688
  - Type Scale Standard Ratio: 10 points
689
  - Base Size Accessible: 15 points
690
  - Spacing Grid: 15 points
691
- - Color Count: 10 points
692
- - No Near-Duplicates: 10 points"""
 
 
 
 
 
 
 
 
 
693
 
694
  PROMPT_TEMPLATE = """Validate the following design tokens against best practices and prioritize fixes.
695
 
@@ -716,6 +725,10 @@ You are Agent 3 of 4 in the Design System Analysis pipeline.
716
  - Duplicates: {duplicates}
717
  - Near-Duplicates: {near_duplicates}
718
 
 
 
 
 
719
  ## BEST PRACTICES CHECKLIST (check each one)
720
 
721
  1. Type scale uses standard ratio (1.2, 1.25, 1.333, 1.5, 1.618)
@@ -725,6 +738,7 @@ You are Agent 3 of 4 in the Design System Analysis pipeline.
725
  5. Spacing uses consistent grid (4px or 8px base)
726
  6. Limited color palette (< 20 unique semantic colors)
727
  7. No near-duplicate colors (< 3 delta-E apart)
 
728
 
729
  ## YOUR TASK
730
 
@@ -744,7 +758,8 @@ You are Agent 3 of 4 in the Design System Analysis pipeline.
744
  "aa_compliance": {{"status": "...", "note": "..."}},
745
  "spacing_grid": {{"status": "...", "note": "..."}},
746
  "color_count": {{"status": "...", "note": "..."}},
747
- "near_duplicates": {{"status": "...", "note": "..."}}
 
748
  }},
749
  "priority_fixes": [
750
  {{
@@ -773,35 +788,47 @@ Return ONLY valid JSON."""
773
  async def analyze(
774
  self,
775
  rule_engine_results: Any,
 
776
  log_callback: Callable = None,
777
  ) -> BestPracticesResult:
778
  """
779
  Validate against best practices.
780
-
781
  Args:
782
  rule_engine_results: Results from rule engine
 
783
  log_callback: Progress logging function
784
-
785
  Returns:
786
  BestPracticesResult with validation
787
  """
788
  def log(msg: str):
789
  if log_callback:
790
  log_callback(msg)
791
-
792
  log("")
793
  log(" βœ… SENTINEL β€” Best Practices Validator (Qwen 72B)")
794
  log(" └─ Checking against design system standards...")
795
-
796
  # Extract data from rule engine
797
  typo = rule_engine_results.typography
798
  spacing = rule_engine_results.spacing
799
  color_stats = rule_engine_results.color_stats
800
  accessibility = rule_engine_results.accessibility
801
-
802
  failures = [a for a in accessibility if not a.passes_aa_normal]
803
  failing_colors_str = ", ".join([f"{a.hex_color} ({a.contrast_on_white:.1f}:1)" for a in failures[:5]])
804
-
 
 
 
 
 
 
 
 
 
 
805
  prompt = self.PROMPT_TEMPLATE.format(
806
  type_ratio=f"{typo.detected_ratio:.3f}",
807
  type_consistent="consistent" if typo.is_consistent else f"inconsistent, variance={typo.variance:.2f}",
@@ -817,6 +844,8 @@ Return ONLY valid JSON."""
817
  unique_colors=color_stats.unique_count,
818
  duplicates=color_stats.duplicate_count,
819
  near_duplicates=len(color_stats.near_duplicates),
 
 
820
  )
821
 
822
  try:
 
688
  - Type Scale Standard Ratio: 10 points
689
  - Base Size Accessible: 15 points
690
  - Spacing Grid: 15 points
691
+ - Color Count: 5 points
692
+ - No Near-Duplicates: 5 points
693
+ - Shadow System: 10 points (elevation hierarchy, consistency)
694
+
695
+ ## SHADOW SYSTEM BEST PRACTICES:
696
+ - Use 3-6 elevation levels (xs, sm, md, lg, xl, 2xl)
697
+ - Consistent Y-offset progression (shadows should grow with elevation)
698
+ - Blur radius should increase with elevation (more blur = higher elevation)
699
+ - Shadow colors should be neutral (black/gray with alpha) or brand-colored with low opacity
700
+ - Avoid shadows with 0 blur (looks harsh/flat)
701
+ - Avoid excessive blur (>32px for most use cases)"""
702
 
703
  PROMPT_TEMPLATE = """Validate the following design tokens against best practices and prioritize fixes.
704
 
 
725
  - Duplicates: {duplicates}
726
  - Near-Duplicates: {near_duplicates}
727
 
728
+ ### Shadow System
729
+ - Total Shadows: {shadow_count}
730
+ - Shadow Values: {shadow_values}
731
+
732
  ## BEST PRACTICES CHECKLIST (check each one)
733
 
734
  1. Type scale uses standard ratio (1.2, 1.25, 1.333, 1.5, 1.618)
 
738
  5. Spacing uses consistent grid (4px or 8px base)
739
  6. Limited color palette (< 20 unique semantic colors)
740
  7. No near-duplicate colors (< 3 delta-E apart)
741
+ 8. Shadow system has consistent elevation hierarchy (blur/Y-offset increase together)
742
 
743
  ## YOUR TASK
744
 
 
758
  "aa_compliance": {{"status": "...", "note": "..."}},
759
  "spacing_grid": {{"status": "...", "note": "..."}},
760
  "color_count": {{"status": "...", "note": "..."}},
761
+ "near_duplicates": {{"status": "...", "note": "..."}},
762
+ "shadow_system": {{"status": "...", "note": "Elevation hierarchy, blur consistency, color appropriateness"}}
763
  }},
764
  "priority_fixes": [
765
  {{
 
788
  async def analyze(
789
  self,
790
  rule_engine_results: Any,
791
+ shadow_tokens: dict = None,
792
  log_callback: Callable = None,
793
  ) -> BestPracticesResult:
794
  """
795
  Validate against best practices.
796
+
797
  Args:
798
  rule_engine_results: Results from rule engine
799
+ shadow_tokens: Shadow tokens dict {name: {value: "..."}}
800
  log_callback: Progress logging function
801
+
802
  Returns:
803
  BestPracticesResult with validation
804
  """
805
  def log(msg: str):
806
  if log_callback:
807
  log_callback(msg)
808
+
809
  log("")
810
  log(" βœ… SENTINEL β€” Best Practices Validator (Qwen 72B)")
811
  log(" └─ Checking against design system standards...")
812
+
813
  # Extract data from rule engine
814
  typo = rule_engine_results.typography
815
  spacing = rule_engine_results.spacing
816
  color_stats = rule_engine_results.color_stats
817
  accessibility = rule_engine_results.accessibility
818
+
819
  failures = [a for a in accessibility if not a.passes_aa_normal]
820
  failing_colors_str = ", ".join([f"{a.hex_color} ({a.contrast_on_white:.1f}:1)" for a in failures[:5]])
821
+
822
+ # Format shadow data for the prompt
823
+ shadow_count = len(shadow_tokens) if shadow_tokens else 0
824
+ shadow_values_str = "None detected"
825
+ if shadow_tokens and shadow_count > 0:
826
+ shadow_list = []
827
+ for name, s in list(shadow_tokens.items())[:6]:
828
+ val = s.get("value", "") if isinstance(s, dict) else str(s)
829
+ shadow_list.append(f"{name}: {val[:50]}")
830
+ shadow_values_str = "; ".join(shadow_list)
831
+
832
  prompt = self.PROMPT_TEMPLATE.format(
833
  type_ratio=f"{typo.detected_ratio:.3f}",
834
  type_consistent="consistent" if typo.is_consistent else f"inconsistent, variance={typo.variance:.2f}",
 
844
  unique_colors=color_stats.unique_count,
845
  duplicates=color_stats.duplicate_count,
846
  near_duplicates=len(color_stats.near_duplicates),
847
+ shadow_count=shadow_count,
848
+ shadow_values=shadow_values_str,
849
  )
850
 
851
  try: