OpenWriterControle/scripts/development/demo.sh
Darren Hinde 784ffadf92
chore: verify and stabilize main branch (#42)
* chore: update package-lock.json after npm install

* chore: remove unused ajv-cli, keep vitest at stable 1.6.1

- Removed ajv-cli (unused dev dependency, had high severity vulnerability)
- Kept vitest at 1.6.1 (stable, upgrading to v4 requires extensive refactoring)
- Reduced vulnerabilities from 6 to 4 (all moderate, dev-only)
- All remaining vulnerabilities are in esbuild/vite (dev server only, no production impact)
- Build and tests verified working

* feat(evals): add execution-balance validation to 21 OpenAgent tests and enhance agent system

Major improvements to evaluation framework and agent capabilities:

## Execution Balance Evaluator Integration
- Added execution-balance rule to 21 OpenAgent tests (2.7% → 31.5% coverage)
- Validates "read before execute" pattern across critical rules, workflows, and edge cases
- Tests now check: read operations before execution tools, healthy read/exec ratio (≥1.0)
- Coverage includes: approval-gate, context-loading, stop-on-failure, report-first tests

## Agent System Enhancements
- Enhanced OpenCoder agent with critical rules enforcement (approval gates, context loading)
- Added structured delegation rules and workflow phases
- Improved error handling with REPORT→PROPOSE→REQUEST→FIX pattern

## New Agent Creation System
- Added research-backed agent creation templates and guides
- Includes 8 test templates covering planning, context, incremental execution, tools
- Automated agent scaffolding with /create-agent command
- Complete documentation in .opencode/command/openagents/new-agents/

## OpenCoder Test Suite
- Added 8 comprehensive test cases for OpenCoder agent
- Tests cover: planning, context-loading, delegation, error-handling, implementation
- Includes DEBUG_GUIDE.md and QUICK_TEST_GUIDE.md for developers

## Documentation & Tooling
- Added DEVELOPMENT.md guide for contributors
- Enhanced CONTRIBUTING.md with quick reference and common commands
- Improved event-logger with DEBUG_VERBOSE mode for detailed output
- Added debug scripts: show-test-conversation.sh, run-test-verbose.sh
- Removed deprecated EXTERNAL_PR_GUIDE.md

## Version Bump
- Bumped version to 0.0.3 (patch)

Files changed: 60+ files (21 test updates, 16 new agent templates, 8 new tests, docs, tooling)

* feat(ci): add PR title validation for semantic versioning

Add automated PR title validation to ensure conventional commit format.
This enables proper automatic version bumping when PRs are merged.

Features:
- Validates PR titles against conventional commit patterns
- Shows expected version bump (major/minor/patch)
- Posts helpful comment with examples if validation fails
- Supports all conventional commit types (feat, fix, docs, etc.)
- Supports breaking changes (feat!, fix!)
- Supports pre-release tags ([alpha], [beta], [rc])

When PR titles follow the format, version bumping works correctly:
- feat: → minor bump (0.3.0 → 0.4.0)
- fix: → patch bump (0.3.0 → 0.3.1)
- feat!: → major bump (0.3.0 → 1.0.0)

* fix(ci): improve PR checks workflow with sequential execution

Reorganize PR checks to run in logical sequence and skip unnecessary checks:

Changes:
- Run PR title validation first (fast, always required)
- Detect changed files to determine which checks to run
- Only run build checks if evals/ files changed
- Add comprehensive summary job showing all check results
- Prevent cache errors when evals files not changed

Benefits:
- Faster PR checks (skip unnecessary builds)
- Clear sequential execution (title → changes → build)
- Better error messages and summaries
- Reduced CI/CD costs

* fix(ci): resolve PR #42 issues and refactor prompt architecture

## Fixed PR #42 Issues

1. **Prompt Validation** - Refactored to new architecture where agent files are canonical defaults
2. **Package-lock.json** - Fixed workflow to use root package-lock (npm workspaces)
3. **Git Merge Base** - Added fetch-depth: 0 to PR checks workflow

## New Prompt Architecture

**Before:**
- Agent files had to match .opencode/prompts/<agent>/default.md
- Caused validation failures when updating prompts
- Redundant duplication

**After:**
- Agent files (.opencode/agent/*.md) = Canonical defaults (source of truth)
- Prompt variants (.opencode/prompts/<agent>/<model>.md) = Model-specific optimizations
- No more default.md files needed

## Changes

### Workflows
- pr-checks.yml: Added fetch-depth: 0 for full git history
- validate-test-suites.yml: Fixed package-lock path for npm workspaces
- validate-registry.yml: Updated validation messaging

### Scripts
- validate-pr.sh: Validates prompt library structure (rejects default.md files)
- use-prompt.sh: Handles 'default' as agent file, variants as model-specific
- test-prompt.sh: Tests default variant correctly, saves results to prompts/results/

### Documentation
- .opencode/prompts/README.md: Updated architecture explanation
- docs/contributing/CONTRIBUTING.md: Updated prompt workflow
- scripts/development/demo.sh: Updated structure display

## Results

- 12 files changed, 231 insertions(+), 811 deletions(-)
- Net reduction: 580 lines (cleaner codebase)
- All validations passing
- Results directory structure preserved
- Backwards compatible with existing test results
2025-12-09 13:26:52 +00:00

415 lines
10 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# OpenCode Repository Demo
# Shows repository structure and prompt library system
#
# Usage:
# ./scripts/development/demo.sh # Interactive mode
# ./scripts/development/demo.sh --quick # Quick tour (non-interactive)
# ./scripts/development/demo.sh --full # Full demo (non-interactive)
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Helper functions
print_header() {
echo ""
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${CYAN} $1${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
print_section() {
echo ""
echo -e "${BLUE}▶ $1${NC}"
echo ""
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_info() {
echo -e "${YELLOW}ℹ${NC} $1"
}
pause() {
if [ "$NON_INTERACTIVE" != "true" ]; then
echo ""
read -p "Press Enter to continue..."
else
echo ""
fi
}
# Main demo functions
show_welcome() {
clear
print_header "Welcome to OpenCode Agents"
cat << EOF
OpenCode is a context-aware agent system for AI-powered development.
This demo will show you:
1. Repository structure
2. Agent system architecture
3. Prompt library system
4. Testing framework
5. How to contribute
Choose a mode:
[1] Quick Tour (2-3 minutes)
[2] Full Demo (10-15 minutes)
[3] Interactive Explorer
[q] Quit
EOF
read -p "Your choice: " choice
echo "$choice"
}
show_repo_structure() {
print_header "Repository Structure"
print_section "Main Directories"
cat << EOF
${GREEN}.opencode/${NC}
├── agent/ ${YELLOW}# Agents${NC}
│ ├── openagent.md ${YELLOW}# Main orchestrator${NC}
│ ├── opencoder.md ${YELLOW}# Development specialist${NC}
│ └── subagents/ ${YELLOW}# Specialized subagents${NC}
├── prompts/ ${YELLOW}# Prompt library (variants)${NC}
├── command/ ${YELLOW}# Slash commands${NC}
├── tool/ ${YELLOW}# Utility tools${NC}
└── context/ ${YELLOW}# Context files${NC}
${GREEN}evals/${NC}
├── agents/ ${YELLOW}# Agent test suites${NC}
├── framework/ ${YELLOW}# Testing framework${NC}
└── results/ ${YELLOW}# Test results${NC}
${GREEN}scripts/${NC}
├── prompts/ ${YELLOW}# Prompt management${NC}
└── tests/ ${YELLOW}# Test utilities${NC}
${GREEN}docs/${NC}
├── agents/ ${YELLOW}# Agent documentation${NC}
├── contributing/ ${YELLOW}# Contribution guides${NC}
└── guides/ ${YELLOW}# User guides${NC}
EOF
pause
}
show_agent_system() {
print_header "Agent System"
print_section "Main Agents"
if [ -f ".opencode/agent/openagent.md" ]; then
print_success "openagent.md - Main orchestrator agent"
echo " Handles planning, delegation, and workflow management"
fi
if [ -f ".opencode/agent/opencoder.md" ]; then
print_success "opencoder.md - Development specialist"
echo " Focused on writing clean, maintainable code"
fi
print_section "Subagents"
if [ -d ".opencode/agent/subagents" ]; then
subagent_count=$(find .opencode/agent/subagents -name "*.md" -type f | wc -l | tr -d ' ')
echo "Found $subagent_count specialized subagents:"
echo ""
# Show subagent categories
for category in .opencode/agent/subagents/*/; do
if [ -d "$category" ]; then
category_name=$(basename "$category")
agent_count=$(find "$category" -name "*.md" -type f | wc -l | tr -d ' ')
echo -e "${GREEN}$category_name/${NC} ($agent_count agents)"
fi
done
fi
pause
}
show_prompt_library() {
print_header "Prompt Library System"
print_section "How It Works"
cat << EOF
The prompt library allows different AI models to use optimized prompts:
${GREEN}.opencode/agent/${NC}
└── openagent.md ${YELLOW}# Canonical default (Claude-optimized)${NC}
${GREEN}.opencode/prompts/openagent/${NC}
├── gpt.md ${YELLOW}# GPT-4 optimized${NC}
├── gemini.md ${YELLOW}# Gemini optimized${NC}
├── grok.md ${YELLOW}# Grok optimized${NC}
├── llama.md ${YELLOW}# Llama/OSS optimized${NC}
├── TEMPLATE.md ${YELLOW}# Template for new variants${NC}
└── results/ ${YELLOW}# Test results (all variants)${NC}
${BLUE}Key Principles:${NC}
• Agent files are canonical defaults (source of truth)
• Variants are model-specific optimizations
• All variants tested and documented
• Users can choose the best prompt for their model
• Contributors can add optimized variants
EOF
pause
print_section "Available Variants"
if [ -d ".opencode/prompts" ]; then
for agent_dir in .opencode/prompts/*/; do
if [ -d "$agent_dir" ]; then
agent=$(basename "$agent_dir")
echo -e "${GREEN}$agent:${NC}"
variant_count=0
for variant in "$agent_dir"*.md; do
if [ -f "$variant" ]; then
variant_name=$(basename "$variant" .md)
if [ "$variant_name" != "README" ] && [ "$variant_name" != "TEMPLATE" ]; then
variant_count=$((variant_count + 1))
# Check if results exist
results_file="$agent_dir/results/$variant_name-results.json"
if [ -f "$results_file" ]; then
passed=$(jq -r '.passed // 0' "$results_file" 2>/dev/null || echo "?")
total=$(jq -r '.total // 0' "$results_file" 2>/dev/null || echo "?")
echo " ✓ $variant_name ($passed/$total tests passing)"
else
echo " • $variant_name (not tested)"
fi
fi
fi
done
if [ $variant_count -eq 0 ]; then
echo " ${YELLOW}No variants yet - coming soon!${NC}"
fi
echo ""
fi
done
else
echo "${YELLOW}Prompt library not yet set up - coming soon!${NC}"
fi
pause
}
show_testing_framework() {
print_header "Testing Framework"
print_section "Test Structure"
cat << EOF
${GREEN}evals/agents/openagent/tests/${NC}
├── 01-critical-rules/ ${YELLOW}# Core behavior tests${NC}
├── 02-workflow-stages/ ${YELLOW}# Workflow validation${NC}
├── 03-delegation/ ${YELLOW}# Delegation logic${NC}
└── ...
Each test validates specific agent behaviors.
EOF
if [ -d "evals/agents/openagent/tests" ]; then
test_count=$(find evals/agents/openagent/tests -name "*.json" -type f | wc -l | tr -d ' ')
echo "Total tests: $test_count"
echo ""
fi
print_section "Running Tests"
cat << EOF
${BLUE}Test a prompt variant:${NC}
./scripts/prompts/test-prompt.sh openagent sonnet-4
${BLUE}Validate PR:${NC}
./scripts/prompts/validate-pr.sh
${BLUE}Use a variant:${NC}
./scripts/prompts/use-prompt.sh openagent sonnet-4
EOF
pause
}
show_contributing() {
print_header "Contributing"
print_section "How to Contribute"
cat << EOF
${BLUE}1. Create a prompt variant:${NC}
cp .opencode/prompts/openagent/TEMPLATE.md .opencode/prompts/openagent/my-variant.md
${BLUE}2. Edit your variant:${NC}
# Optimize for your target model
vim .opencode/prompts/openagent/my-variant.md
${BLUE}3. Test it:${NC}
./scripts/prompts/test-prompt.sh openagent my-variant
${BLUE}4. Document results:${NC}
# Update .opencode/prompts/openagent/README.md with test results
${BLUE}5. Submit PR:${NC}
# Include your variant and results
# Do NOT change the default prompt
${YELLOW}Important:${NC} All PRs must use default prompts (CI enforces this)
EOF
print_section "Other Ways to Contribute"
cat << EOF
• Add new agents or subagents
• Improve documentation
• Add test cases
• Fix bugs
• Enhance the testing framework
See ${BLUE}docs/contributing/CONTRIBUTING.md${NC} for details.
EOF
pause
}
interactive_mode() {
while true; do
clear
print_header "Interactive Explorer"
cat << EOF
Choose a section to explore:
[1] Repository Structure
[2] Agent System
[3] Prompt Library
[4] Testing Framework
[5] Contributing Guide
[b] Back to main menu
[q] Quit
EOF
read -p "Your choice: " choice
case $choice in
1) show_repo_structure ;;
2) show_agent_system ;;
3) show_prompt_library ;;
4) show_testing_framework ;;
5) show_contributing ;;
b) return ;;
q) exit 0 ;;
*) echo "Invalid choice" ;;
esac
done
}
quick_tour() {
show_repo_structure
show_agent_system
show_prompt_library
print_header "Quick Tour Complete!"
cat << EOF
${GREEN}Next Steps:${NC}
• Read the docs: ${BLUE}docs/README.md${NC}
• Try the agents: ${BLUE}.opencode/agent/${NC}
• Run tests: ${BLUE}./scripts/prompts/test-prompt.sh${NC}
• Contribute: ${BLUE}docs/contributing/CONTRIBUTING.md${NC}
${YELLOW}For more details, run:${NC}
./scripts/development/demo.sh
EOF
}
full_demo() {
show_repo_structure
show_agent_system
show_prompt_library
show_testing_framework
show_contributing
print_header "Demo Complete!"
cat << EOF
${GREEN}You've seen:${NC}
✓ Repository structure
✓ Agent system architecture
✓ Prompt library system
✓ Testing framework
✓ How to contribute
${YELLOW}Ready to get started?${NC}
• Read: ${BLUE}docs/getting-started/installation.md${NC}
• Explore: ${BLUE}.opencode/prompts/${NC}
• Test: ${BLUE}./scripts/prompts/test-prompt.sh${NC}
EOF
}
# Main
main() {
# Check for command line arguments
if [ "$1" = "--quick" ]; then
NON_INTERACTIVE=true
quick_tour
exit 0
elif [ "$1" = "--full" ]; then
NON_INTERACTIVE=true
full_demo
exit 0
elif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat << EOF
OpenCode Repository Demo
Usage:
./scripts/development/demo.sh Interactive mode with menu
./scripts/development/demo.sh --quick Quick tour (non-interactive)
./scripts/development/demo.sh --full Full demo (non-interactive)
./scripts/development/demo.sh --help Show this help
EOF
exit 0
fi
# Interactive mode
choice=$(show_welcome)
case $choice in
1) quick_tour ;;
2) full_demo ;;
3) interactive_mode ;;
q) exit 0 ;;
*) echo "Invalid choice"; exit 1 ;;
esac
}
main "$@"