validate-pr.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 (including category subdirectories, excluding subagents)
  31. while IFS= read -r agent_file; do
  32. # Skip if no files found
  33. [ -e "$agent_file" ] || continue
  34. # Skip subagents directory
  35. if [[ "$agent_file" == *"/subagents/"* ]]; then
  36. continue
  37. fi
  38. agent_name=$(basename "$agent_file" .md)
  39. prompts_subdir="$PROMPTS_DIR/$agent_name"
  40. # Check if prompts directory exists for this agent
  41. if [ ! -d "$prompts_subdir" ]; then
  42. echo -e "${YELLOW}⚠️ No prompt variants for $agent_name${NC}"
  43. echo " Agent file: $agent_file (canonical default)"
  44. echo " Variants directory: $prompts_subdir (not found)"
  45. echo " This is OK - variants are optional."
  46. echo ""
  47. WARNINGS=$((WARNINGS + 1))
  48. continue
  49. fi
  50. # Check for default.md (should NOT exist in new architecture)
  51. if [ -f "$prompts_subdir/default.md" ]; then
  52. echo -e "${RED}❌ Found default.md for $agent_name${NC}"
  53. echo " Location: $prompts_subdir/default.md"
  54. echo " This file should not exist in the new architecture."
  55. echo ""
  56. echo " To fix:"
  57. echo " rm $prompts_subdir/default.md"
  58. echo ""
  59. echo " The agent file is now the canonical default:"
  60. echo " $agent_file"
  61. echo ""
  62. FAILED=$((FAILED + 1))
  63. else
  64. # Count variants
  65. variant_count=$(find "$prompts_subdir" -maxdepth 1 -name "*.md" -not -name "README.md" -not -name "TEMPLATE.md" | wc -l | tr -d ' ')
  66. if [ "$variant_count" -gt 0 ]; then
  67. echo -e "${GREEN}✅ $agent_name${NC}"
  68. echo " Default: $agent_file"
  69. echo " Variants: $variant_count model-specific optimization(s)"
  70. else
  71. echo -e "${GREEN}✅ $agent_name${NC}"
  72. echo " Default: $agent_file"
  73. echo " Variants: none (using default for all models)"
  74. fi
  75. fi
  76. done < <(find "$AGENT_DIR" -type f -name "*.md" ! -name "README.md" ! -name "index.md" 2>/dev/null)
  77. echo ""
  78. # Summary
  79. if [ $FAILED -eq 0 ] && [ $WARNINGS -eq 0 ]; then
  80. echo -e "${GREEN}✅ Prompt library structure is valid${NC}"
  81. exit 0
  82. elif [ $FAILED -eq 0 ]; then
  83. echo -e "${YELLOW}⚠️ Validation passed with $WARNINGS warning(s)${NC}"
  84. echo " Some agents don't have variant directories yet - this is expected."
  85. exit 0
  86. else
  87. echo -e "${RED}❌ PR validation failed - $FAILED issue(s) found${NC}"
  88. echo ""
  89. echo "The new prompt architecture:"
  90. echo " • Agent files (.opencode/agent/*.md) are the canonical defaults"
  91. echo " • Prompt variants (.opencode/prompts/<agent>/<model>.md) are model-specific"
  92. echo " • default.md files should NOT exist"
  93. echo ""
  94. echo "See docs/contributing/CONTRIBUTING.md for details"
  95. echo ""
  96. exit 1
  97. fi