demo.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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/agent/${NC}
  126. └── openagent.md ${YELLOW}# Canonical default (Claude-optimized)${NC}
  127. ${GREEN}.opencode/prompts/openagent/${NC}
  128. ├── gpt.md ${YELLOW}# GPT-4 optimized${NC}
  129. ├── gemini.md ${YELLOW}# Gemini optimized${NC}
  130. ├── grok.md ${YELLOW}# Grok optimized${NC}
  131. ├── llama.md ${YELLOW}# Llama/OSS optimized${NC}
  132. ├── TEMPLATE.md ${YELLOW}# Template for new variants${NC}
  133. └── results/ ${YELLOW}# Test results (all variants)${NC}
  134. ${BLUE}Key Principles:${NC}
  135. • Agent files are canonical defaults (source of truth)
  136. • Variants are model-specific optimizations
  137. • All variants tested and documented
  138. • Users can choose the best prompt for their model
  139. • Contributors can add optimized variants
  140. EOF
  141. pause
  142. print_section "Available Variants"
  143. if [ -d ".opencode/prompts" ]; then
  144. for agent_dir in .opencode/prompts/*/; do
  145. if [ -d "$agent_dir" ]; then
  146. agent=$(basename "$agent_dir")
  147. echo -e "${GREEN}$agent:${NC}"
  148. variant_count=0
  149. for variant in "$agent_dir"*.md; do
  150. if [ -f "$variant" ]; then
  151. variant_name=$(basename "$variant" .md)
  152. if [ "$variant_name" != "README" ] && [ "$variant_name" != "TEMPLATE" ]; then
  153. variant_count=$((variant_count + 1))
  154. # Check if results exist
  155. results_file="$agent_dir/results/$variant_name-results.json"
  156. if [ -f "$results_file" ]; then
  157. passed=$(jq -r '.passed // 0' "$results_file" 2>/dev/null || echo "?")
  158. total=$(jq -r '.total // 0' "$results_file" 2>/dev/null || echo "?")
  159. echo " ✓ $variant_name ($passed/$total tests passing)"
  160. else
  161. echo " • $variant_name (not tested)"
  162. fi
  163. fi
  164. fi
  165. done
  166. if [ $variant_count -eq 0 ]; then
  167. echo " ${YELLOW}No variants yet - coming soon!${NC}"
  168. fi
  169. echo ""
  170. fi
  171. done
  172. else
  173. echo "${YELLOW}Prompt library not yet set up - coming soon!${NC}"
  174. fi
  175. pause
  176. }
  177. show_testing_framework() {
  178. print_header "Testing Framework"
  179. print_section "Test Structure"
  180. cat << EOF
  181. ${GREEN}evals/agents/openagent/tests/${NC}
  182. ├── 01-critical-rules/ ${YELLOW}# Core behavior tests${NC}
  183. ├── 02-workflow-stages/ ${YELLOW}# Workflow validation${NC}
  184. ├── 03-delegation/ ${YELLOW}# Delegation logic${NC}
  185. └── ...
  186. Each test validates specific agent behaviors.
  187. EOF
  188. if [ -d "evals/agents/openagent/tests" ]; then
  189. test_count=$(find evals/agents/openagent/tests -name "*.json" -type f | wc -l | tr -d ' ')
  190. echo "Total tests: $test_count"
  191. echo ""
  192. fi
  193. print_section "Running Tests"
  194. cat << EOF
  195. ${BLUE}Test a prompt variant:${NC}
  196. ./scripts/prompts/test-prompt.sh openagent sonnet-4
  197. ${BLUE}Validate PR:${NC}
  198. ./scripts/prompts/validate-pr.sh
  199. ${BLUE}Use a variant:${NC}
  200. ./scripts/prompts/use-prompt.sh openagent sonnet-4
  201. EOF
  202. pause
  203. }
  204. show_contributing() {
  205. print_header "Contributing"
  206. print_section "How to Contribute"
  207. cat << EOF
  208. ${BLUE}1. Create a prompt variant:${NC}
  209. cp .opencode/prompts/openagent/TEMPLATE.md .opencode/prompts/openagent/my-variant.md
  210. ${BLUE}2. Edit your variant:${NC}
  211. # Optimize for your target model
  212. vim .opencode/prompts/openagent/my-variant.md
  213. ${BLUE}3. Test it:${NC}
  214. ./scripts/prompts/test-prompt.sh openagent my-variant
  215. ${BLUE}4. Document results:${NC}
  216. # Update .opencode/prompts/openagent/README.md with test results
  217. ${BLUE}5. Submit PR:${NC}
  218. # Include your variant and results
  219. # Do NOT change the default prompt
  220. ${YELLOW}Important:${NC} All PRs must use default prompts (CI enforces this)
  221. EOF
  222. print_section "Other Ways to Contribute"
  223. cat << EOF
  224. • Add new agents or subagents
  225. • Improve documentation
  226. • Add test cases
  227. • Fix bugs
  228. • Enhance the testing framework
  229. See ${BLUE}docs/contributing/CONTRIBUTING.md${NC} for details.
  230. EOF
  231. pause
  232. }
  233. interactive_mode() {
  234. while true; do
  235. clear
  236. print_header "Interactive Explorer"
  237. cat << EOF
  238. Choose a section to explore:
  239. [1] Repository Structure
  240. [2] Agent System
  241. [3] Prompt Library
  242. [4] Testing Framework
  243. [5] Contributing Guide
  244. [b] Back to main menu
  245. [q] Quit
  246. EOF
  247. read -p "Your choice: " choice
  248. case $choice in
  249. 1) show_repo_structure ;;
  250. 2) show_agent_system ;;
  251. 3) show_prompt_library ;;
  252. 4) show_testing_framework ;;
  253. 5) show_contributing ;;
  254. b) return ;;
  255. q) exit 0 ;;
  256. *) echo "Invalid choice" ;;
  257. esac
  258. done
  259. }
  260. quick_tour() {
  261. show_repo_structure
  262. show_agent_system
  263. show_prompt_library
  264. print_header "Quick Tour Complete!"
  265. cat << EOF
  266. ${GREEN}Next Steps:${NC}
  267. • Read the docs: ${BLUE}docs/README.md${NC}
  268. • Try the agents: ${BLUE}.opencode/agent/${NC}
  269. • Run tests: ${BLUE}./scripts/prompts/test-prompt.sh${NC}
  270. • Contribute: ${BLUE}docs/contributing/CONTRIBUTING.md${NC}
  271. ${YELLOW}For more details, run:${NC}
  272. ./scripts/development/demo.sh
  273. EOF
  274. }
  275. full_demo() {
  276. show_repo_structure
  277. show_agent_system
  278. show_prompt_library
  279. show_testing_framework
  280. show_contributing
  281. print_header "Demo Complete!"
  282. cat << EOF
  283. ${GREEN}You've seen:${NC}
  284. ✓ Repository structure
  285. ✓ Agent system architecture
  286. ✓ Prompt library system
  287. ✓ Testing framework
  288. ✓ How to contribute
  289. ${YELLOW}Ready to get started?${NC}
  290. • Read: ${BLUE}docs/getting-started/installation.md${NC}
  291. • Explore: ${BLUE}.opencode/prompts/${NC}
  292. • Test: ${BLUE}./scripts/prompts/test-prompt.sh${NC}
  293. EOF
  294. }
  295. # Main
  296. main() {
  297. # Check for command line arguments
  298. if [ "$1" = "--quick" ]; then
  299. NON_INTERACTIVE=true
  300. quick_tour
  301. exit 0
  302. elif [ "$1" = "--full" ]; then
  303. NON_INTERACTIVE=true
  304. full_demo
  305. exit 0
  306. elif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
  307. cat << EOF
  308. OpenCode Repository Demo
  309. Usage:
  310. ./scripts/development/demo.sh Interactive mode with menu
  311. ./scripts/development/demo.sh --quick Quick tour (non-interactive)
  312. ./scripts/development/demo.sh --full Full demo (non-interactive)
  313. ./scripts/development/demo.sh --help Show this help
  314. EOF
  315. exit 0
  316. fi
  317. # Interactive mode
  318. choice=$(show_welcome)
  319. case $choice in
  320. 1) quick_tour ;;
  321. 2) full_demo ;;
  322. 3) interactive_mode ;;
  323. q) exit 0 ;;
  324. *) echo "Invalid choice"; exit 1 ;;
  325. esac
  326. }
  327. main "$@"