demo.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. #!/bin/bash
  2. # OpenCode Repository Demo
  3. # Shows repository structure and prompt library system
  4. #
  5. # Usage:
  6. # ./scripts/development/demo.sh # Interactive mode
  7. # ./scripts/development/demo.sh --quick # Quick tour (non-interactive)
  8. # ./scripts/development/demo.sh --full # Full demo (non-interactive)
  9. set -e
  10. # Colors
  11. RED='\033[0;31m'
  12. GREEN='\033[0;32m'
  13. YELLOW='\033[1;33m'
  14. BLUE='\033[0;34m'
  15. PURPLE='\033[0;35m'
  16. CYAN='\033[0;36m'
  17. NC='\033[0m' # No Color
  18. # Helper functions
  19. print_header() {
  20. echo ""
  21. echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
  22. echo -e "${CYAN} $1${NC}"
  23. echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
  24. echo ""
  25. }
  26. print_section() {
  27. echo ""
  28. echo -e "${BLUE}▶ $1${NC}"
  29. echo ""
  30. }
  31. print_success() {
  32. echo -e "${GREEN}✓${NC} $1"
  33. }
  34. print_info() {
  35. echo -e "${YELLOW}ℹ${NC} $1"
  36. }
  37. pause() {
  38. if [ "$NON_INTERACTIVE" != "true" ]; then
  39. echo ""
  40. read -p "Press Enter to continue..."
  41. else
  42. echo ""
  43. fi
  44. }
  45. # Main demo functions
  46. show_welcome() {
  47. clear
  48. print_header "Welcome to OpenCode Agents"
  49. cat << EOF
  50. OpenCode is a context-aware agent system for AI-powered development.
  51. This demo will show you:
  52. 1. Repository structure
  53. 2. Agent system architecture
  54. 3. Prompt library system
  55. 4. Testing framework
  56. 5. How to contribute
  57. Choose a mode:
  58. [1] Quick Tour (2-3 minutes)
  59. [2] Full Demo (10-15 minutes)
  60. [3] Interactive Explorer
  61. [q] Quit
  62. EOF
  63. read -p "Your choice: " choice
  64. echo "$choice"
  65. }
  66. show_repo_structure() {
  67. print_header "Repository Structure"
  68. print_section "Main Directories"
  69. cat << EOF
  70. ${GREEN}.opencode/${NC}
  71. ├── agent/ ${YELLOW}# Agents${NC}
  72. │ ├── openagent.md ${YELLOW}# Main orchestrator${NC}
  73. │ ├── opencoder.md ${YELLOW}# Development specialist${NC}
  74. │ └── subagents/ ${YELLOW}# Specialized subagents${NC}
  75. ├── prompts/ ${YELLOW}# Prompt library (variants)${NC}
  76. ├── command/ ${YELLOW}# Slash commands${NC}
  77. ├── tool/ ${YELLOW}# Utility tools${NC}
  78. └── context/ ${YELLOW}# Context files${NC}
  79. ${GREEN}evals/${NC}
  80. ├── agents/ ${YELLOW}# Agent test suites${NC}
  81. ├── framework/ ${YELLOW}# Testing framework${NC}
  82. └── results/ ${YELLOW}# Test results${NC}
  83. ${GREEN}scripts/${NC}
  84. ├── prompts/ ${YELLOW}# Prompt management${NC}
  85. └── tests/ ${YELLOW}# Test utilities${NC}
  86. ${GREEN}docs/${NC}
  87. ├── agents/ ${YELLOW}# Agent documentation${NC}
  88. ├── contributing/ ${YELLOW}# Contribution guides${NC}
  89. └── guides/ ${YELLOW}# User guides${NC}
  90. EOF
  91. pause
  92. }
  93. show_agent_system() {
  94. print_header "Agent System"
  95. print_section "Main Agents"
  96. if [ -f ".opencode/agent/openagent.md" ]; then
  97. print_success "openagent.md - Main orchestrator agent"
  98. echo " Handles planning, delegation, and workflow management"
  99. fi
  100. if [ -f ".opencode/agent/opencoder.md" ]; then
  101. print_success "opencoder.md - Development specialist"
  102. echo " Focused on writing clean, maintainable code"
  103. fi
  104. print_section "Subagents"
  105. if [ -d ".opencode/agent/subagents" ]; then
  106. subagent_count=$(find .opencode/agent/subagents -name "*.md" -type f | wc -l | tr -d ' ')
  107. echo "Found $subagent_count specialized subagents:"
  108. echo ""
  109. # Show subagent categories
  110. for category in .opencode/agent/subagents/*/; do
  111. if [ -d "$category" ]; then
  112. category_name=$(basename "$category")
  113. agent_count=$(find "$category" -name "*.md" -type f | wc -l | tr -d ' ')
  114. echo -e "${GREEN}$category_name/${NC} ($agent_count agents)"
  115. fi
  116. done
  117. fi
  118. pause
  119. }
  120. show_prompt_library() {
  121. print_header "Prompt Library System"
  122. print_section "How It Works"
  123. cat << EOF
  124. The prompt library allows different AI models to use optimized prompts:
  125. ${GREEN}.opencode/prompts/openagent/${NC}
  126. ├── default.md ${YELLOW}# Stable version (used in PRs)${NC}
  127. ├── sonnet-4.md ${YELLOW}# Claude Sonnet 4 optimized${NC}
  128. ├── grok-fast.md ${YELLOW}# Grok Fast optimized${NC}
  129. ├── TEMPLATE.md ${YELLOW}# Template for new variants${NC}
  130. └── results/ ${YELLOW}# Test results${NC}
  131. ${BLUE}Key Principles:${NC}
  132. • PRs must use default prompts (enforced by CI)
  133. • Variants are tested and documented
  134. • Users can choose the best prompt for their model
  135. • Contributors can add optimized variants
  136. EOF
  137. pause
  138. print_section "Available Variants"
  139. if [ -d ".opencode/prompts" ]; then
  140. for agent_dir in .opencode/prompts/*/; do
  141. if [ -d "$agent_dir" ]; then
  142. agent=$(basename "$agent_dir")
  143. echo -e "${GREEN}$agent:${NC}"
  144. variant_count=0
  145. for variant in "$agent_dir"*.md; do
  146. if [ -f "$variant" ]; then
  147. variant_name=$(basename "$variant" .md)
  148. if [ "$variant_name" != "README" ] && [ "$variant_name" != "TEMPLATE" ]; then
  149. variant_count=$((variant_count + 1))
  150. # Check if results exist
  151. results_file="$agent_dir/results/$variant_name-results.json"
  152. if [ -f "$results_file" ]; then
  153. passed=$(jq -r '.passed // 0' "$results_file" 2>/dev/null || echo "?")
  154. total=$(jq -r '.total // 0' "$results_file" 2>/dev/null || echo "?")
  155. echo " ✓ $variant_name ($passed/$total tests passing)"
  156. else
  157. echo " • $variant_name (not tested)"
  158. fi
  159. fi
  160. fi
  161. done
  162. if [ $variant_count -eq 0 ]; then
  163. echo " ${YELLOW}No variants yet - coming soon!${NC}"
  164. fi
  165. echo ""
  166. fi
  167. done
  168. else
  169. echo "${YELLOW}Prompt library not yet set up - coming soon!${NC}"
  170. fi
  171. pause
  172. }
  173. show_testing_framework() {
  174. print_header "Testing Framework"
  175. print_section "Test Structure"
  176. cat << EOF
  177. ${GREEN}evals/agents/openagent/tests/${NC}
  178. ├── 01-critical-rules/ ${YELLOW}# Core behavior tests${NC}
  179. ├── 02-workflow-stages/ ${YELLOW}# Workflow validation${NC}
  180. ├── 03-delegation/ ${YELLOW}# Delegation logic${NC}
  181. └── ...
  182. Each test validates specific agent behaviors.
  183. EOF
  184. if [ -d "evals/agents/openagent/tests" ]; then
  185. test_count=$(find evals/agents/openagent/tests -name "*.json" -type f | wc -l | tr -d ' ')
  186. echo "Total tests: $test_count"
  187. echo ""
  188. fi
  189. print_section "Running Tests"
  190. cat << EOF
  191. ${BLUE}Test a prompt variant:${NC}
  192. ./scripts/prompts/test-prompt.sh openagent sonnet-4
  193. ${BLUE}Validate PR:${NC}
  194. ./scripts/prompts/validate-pr.sh
  195. ${BLUE}Use a variant:${NC}
  196. ./scripts/prompts/use-prompt.sh openagent sonnet-4
  197. EOF
  198. pause
  199. }
  200. show_contributing() {
  201. print_header "Contributing"
  202. print_section "How to Contribute"
  203. cat << EOF
  204. ${BLUE}1. Create a prompt variant:${NC}
  205. cp .opencode/prompts/openagent/TEMPLATE.md .opencode/prompts/openagent/my-variant.md
  206. ${BLUE}2. Edit your variant:${NC}
  207. # Optimize for your target model
  208. vim .opencode/prompts/openagent/my-variant.md
  209. ${BLUE}3. Test it:${NC}
  210. ./scripts/prompts/test-prompt.sh openagent my-variant
  211. ${BLUE}4. Document results:${NC}
  212. # Update .opencode/prompts/openagent/README.md with test results
  213. ${BLUE}5. Submit PR:${NC}
  214. # Include your variant and results
  215. # Do NOT change the default prompt
  216. ${YELLOW}Important:${NC} All PRs must use default prompts (CI enforces this)
  217. EOF
  218. print_section "Other Ways to Contribute"
  219. cat << EOF
  220. • Add new agents or subagents
  221. • Improve documentation
  222. • Add test cases
  223. • Fix bugs
  224. • Enhance the testing framework
  225. See ${BLUE}docs/contributing/CONTRIBUTING.md${NC} for details.
  226. EOF
  227. pause
  228. }
  229. interactive_mode() {
  230. while true; do
  231. clear
  232. print_header "Interactive Explorer"
  233. cat << EOF
  234. Choose a section to explore:
  235. [1] Repository Structure
  236. [2] Agent System
  237. [3] Prompt Library
  238. [4] Testing Framework
  239. [5] Contributing Guide
  240. [b] Back to main menu
  241. [q] Quit
  242. EOF
  243. read -p "Your choice: " choice
  244. case $choice in
  245. 1) show_repo_structure ;;
  246. 2) show_agent_system ;;
  247. 3) show_prompt_library ;;
  248. 4) show_testing_framework ;;
  249. 5) show_contributing ;;
  250. b) return ;;
  251. q) exit 0 ;;
  252. *) echo "Invalid choice" ;;
  253. esac
  254. done
  255. }
  256. quick_tour() {
  257. show_repo_structure
  258. show_agent_system
  259. show_prompt_library
  260. print_header "Quick Tour Complete!"
  261. cat << EOF
  262. ${GREEN}Next Steps:${NC}
  263. • Read the docs: ${BLUE}docs/README.md${NC}
  264. • Try the agents: ${BLUE}.opencode/agent/${NC}
  265. • Run tests: ${BLUE}./scripts/prompts/test-prompt.sh${NC}
  266. • Contribute: ${BLUE}docs/contributing/CONTRIBUTING.md${NC}
  267. ${YELLOW}For more details, run:${NC}
  268. ./scripts/development/demo.sh
  269. EOF
  270. }
  271. full_demo() {
  272. show_repo_structure
  273. show_agent_system
  274. show_prompt_library
  275. show_testing_framework
  276. show_contributing
  277. print_header "Demo Complete!"
  278. cat << EOF
  279. ${GREEN}You've seen:${NC}
  280. ✓ Repository structure
  281. ✓ Agent system architecture
  282. ✓ Prompt library system
  283. ✓ Testing framework
  284. ✓ How to contribute
  285. ${YELLOW}Ready to get started?${NC}
  286. • Read: ${BLUE}docs/getting-started/installation.md${NC}
  287. • Explore: ${BLUE}.opencode/prompts/${NC}
  288. • Test: ${BLUE}./scripts/prompts/test-prompt.sh${NC}
  289. EOF
  290. }
  291. # Main
  292. main() {
  293. # Check for command line arguments
  294. if [ "$1" = "--quick" ]; then
  295. NON_INTERACTIVE=true
  296. quick_tour
  297. exit 0
  298. elif [ "$1" = "--full" ]; then
  299. NON_INTERACTIVE=true
  300. full_demo
  301. exit 0
  302. elif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
  303. cat << EOF
  304. OpenCode Repository Demo
  305. Usage:
  306. ./scripts/development/demo.sh Interactive mode with menu
  307. ./scripts/development/demo.sh --quick Quick tour (non-interactive)
  308. ./scripts/development/demo.sh --full Full demo (non-interactive)
  309. ./scripts/development/demo.sh --help Show this help
  310. EOF
  311. exit 0
  312. fi
  313. # Interactive mode
  314. choice=$(show_welcome)
  315. case $choice in
  316. 1) quick_tour ;;
  317. 2) full_demo ;;
  318. 3) interactive_mode ;;
  319. q) exit 0 ;;
  320. *) echo "Invalid choice"; exit 1 ;;
  321. esac
  322. }
  323. main "$@"