validate-pr.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. # Validate prompt library structure
  3. # Agent files in .opencode/agent/ are the canonical defaults
  4. # Prompts in .opencode/prompts/ are model-specific variants
  5. set -e
  6. AGENT_DIR=".opencode/agent"
  7. PROMPTS_DIR=".opencode/prompts"
  8. FAILED=0
  9. WARNINGS=0
  10. # Colors
  11. RED='\033[0;31m'
  12. GREEN='\033[0;32m'
  13. YELLOW='\033[1;33m'
  14. BLUE='\033[0;34m'
  15. NC='\033[0m' # No Color
  16. echo "🔍 Validating prompt library structure..."
  17. echo ""
  18. # Check if prompts directory exists
  19. if [ ! -d "$PROMPTS_DIR" ]; then
  20. echo -e "${YELLOW}⚠️ Prompts library not yet set up${NC}"
  21. echo " This is expected if the prompt library system hasn't been implemented yet."
  22. echo " Skipping validation."
  23. exit 0
  24. fi
  25. # Validate structure: agent files are canonical, prompts are variants
  26. echo -e "${BLUE}Architecture:${NC}"
  27. echo " • Agent files (.opencode/agent/*.md) = Canonical defaults"
  28. echo " • Prompt variants (.opencode/prompts/<agent>/<model>.md) = Model-specific optimizations"
  29. echo ""
  30. # Find all agent markdown files (excluding subagents)
  31. for agent_file in "$AGENT_DIR"/*.md; do
  32. # Skip if no files found
  33. [ -e "$agent_file" ] || continue
  34. agent_name=$(basename "$agent_file" .md)
  35. prompts_subdir="$PROMPTS_DIR/$agent_name"
  36. # Check if prompts directory exists for this agent
  37. if [ ! -d "$prompts_subdir" ]; then
  38. echo -e "${YELLOW}⚠️ No prompt variants for $agent_name${NC}"
  39. echo " Agent file: $agent_file (canonical default)"
  40. echo " Variants directory: $prompts_subdir (not found)"
  41. echo " This is OK - variants are optional."
  42. echo ""
  43. WARNINGS=$((WARNINGS + 1))
  44. continue
  45. fi
  46. # Check for default.md (should NOT exist in new architecture)
  47. if [ -f "$prompts_subdir/default.md" ]; then
  48. echo -e "${RED}❌ Found default.md for $agent_name${NC}"
  49. echo " Location: $prompts_subdir/default.md"
  50. echo " This file should not exist in the new architecture."
  51. echo ""
  52. echo " To fix:"
  53. echo " rm $prompts_subdir/default.md"
  54. echo ""
  55. echo " The agent file is now the canonical default:"
  56. echo " $agent_file"
  57. echo ""
  58. FAILED=$((FAILED + 1))
  59. else
  60. # Count variants
  61. variant_count=$(find "$prompts_subdir" -maxdepth 1 -name "*.md" -not -name "README.md" -not -name "TEMPLATE.md" | wc -l | tr -d ' ')
  62. if [ "$variant_count" -gt 0 ]; then
  63. echo -e "${GREEN}✅ $agent_name${NC}"
  64. echo " Default: $agent_file"
  65. echo " Variants: $variant_count model-specific optimization(s)"
  66. else
  67. echo -e "${GREEN}✅ $agent_name${NC}"
  68. echo " Default: $agent_file"
  69. echo " Variants: none (using default for all models)"
  70. fi
  71. fi
  72. done
  73. echo ""
  74. # Summary
  75. if [ $FAILED -eq 0 ] && [ $WARNINGS -eq 0 ]; then
  76. echo -e "${GREEN}✅ Prompt library structure is valid${NC}"
  77. exit 0
  78. elif [ $FAILED -eq 0 ]; then
  79. echo -e "${YELLOW}⚠️ Validation passed with $WARNINGS warning(s)${NC}"
  80. echo " Some agents don't have variant directories yet - this is expected."
  81. exit 0
  82. else
  83. echo -e "${RED}❌ PR validation failed - $FAILED issue(s) found${NC}"
  84. echo ""
  85. echo "The new prompt architecture:"
  86. echo " • Agent files (.opencode/agent/*.md) are the canonical defaults"
  87. echo " • Prompt variants (.opencode/prompts/<agent>/<model>.md) are model-specific"
  88. echo " • default.md files should NOT exist"
  89. echo ""
  90. echo "See docs/contributing/CONTRIBUTING.md for details"
  91. echo ""
  92. exit 1
  93. fi