validate-pr.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # Validate that all agents use their default prompts
  3. # This ensures PRs maintain stable defaults in the main branch
  4. set -e
  5. AGENT_DIR=".opencode/agent"
  6. PROMPTS_DIR=".opencode/prompts"
  7. FAILED=0
  8. WARNINGS=0
  9. # Colors
  10. RED='\033[0;31m'
  11. GREEN='\033[0;32m'
  12. YELLOW='\033[1;33m'
  13. NC='\033[0m' # No Color
  14. echo "🔍 Validating agent prompts..."
  15. echo ""
  16. # Check if prompts directory exists
  17. if [ ! -d "$PROMPTS_DIR" ]; then
  18. echo -e "${YELLOW}⚠️ Prompts library not yet set up${NC}"
  19. echo " This is expected if the prompt library system hasn't been implemented yet."
  20. echo " Skipping validation."
  21. exit 0
  22. fi
  23. # Find all agent markdown files (excluding subagents)
  24. for agent_file in "$AGENT_DIR"/*.md; do
  25. # Skip if no files found
  26. [ -e "$agent_file" ] || continue
  27. agent_name=$(basename "$agent_file" .md)
  28. default_file="$PROMPTS_DIR/$agent_name/default.md"
  29. # Check if default exists
  30. if [ ! -f "$default_file" ]; then
  31. echo -e "${YELLOW}⚠️ No default found for $agent_name${NC}"
  32. echo " Expected: $default_file"
  33. echo " This agent will be skipped."
  34. echo ""
  35. WARNINGS=$((WARNINGS + 1))
  36. continue
  37. fi
  38. # Compare files
  39. if ! diff -q "$agent_file" "$default_file" > /dev/null 2>&1; then
  40. echo -e "${RED}❌ $agent_name.md does not match default${NC}"
  41. echo " Current: $agent_file"
  42. echo " Expected: $default_file"
  43. echo ""
  44. echo " To fix this:"
  45. echo " ./scripts/prompts/use-prompt.sh $agent_name default"
  46. echo ""
  47. FAILED=$((FAILED + 1))
  48. else
  49. echo -e "${GREEN}✅ $agent_name.md matches default${NC}"
  50. fi
  51. done
  52. echo ""
  53. # Summary
  54. if [ $FAILED -eq 0 ] && [ $WARNINGS -eq 0 ]; then
  55. echo -e "${GREEN}✅ All agents use default prompts${NC}"
  56. exit 0
  57. elif [ $FAILED -eq 0 ]; then
  58. echo -e "${YELLOW}⚠️ Validation passed with $WARNINGS warning(s)${NC}"
  59. echo " Some agents don't have defaults yet - this is expected during development."
  60. exit 0
  61. else
  62. echo -e "${RED}❌ PR validation failed - $FAILED agent(s) do not use default prompts${NC}"
  63. echo ""
  64. echo "PRs must use default prompts to keep the main branch stable."
  65. echo ""
  66. echo "To fix:"
  67. echo " 1. Restore defaults: ./scripts/prompts/use-prompt.sh <agent> default"
  68. echo " 2. Or run: ./scripts/prompts/validate-pr.sh"
  69. echo ""
  70. echo "If you're adding a new prompt variant:"
  71. echo " - Add it to .opencode/prompts/<agent>/<variant>.md"
  72. echo " - Do NOT modify .opencode/agent/<agent>.md"
  73. echo " - See docs/contributing/CONTRIBUTING.md for details"
  74. echo ""
  75. exit 1
  76. fi