demo.sh 11 KB

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