OpenWriterControle/scripts/prompts/use-prompt.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

225 lines
6.7 KiB
Bash
Executable file

#!/bin/bash
#
# use-prompt.sh - Switch an agent to use a specific prompt variant
#
# Usage:
# ./scripts/prompts/use-prompt.sh --agent=openagent --variant=gpt
# ./scripts/prompts/use-prompt.sh --agent=openagent --variant=default
#
# What it does:
# 1. If variant is "default", restores the canonical agent file (no-op, already default)
# 2. Otherwise, copies the model-specific variant to the agent location
#
# New Architecture:
# - Agent files (.opencode/agent/*.md) are the canonical defaults
# - Prompt variants (.opencode/prompts/<agent>/<model>.md) are model-specific optimizations
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Default values
AGENT_NAME=""
PROMPT_VARIANT=""
# Paths
PROMPTS_DIR="$ROOT_DIR/.opencode/prompts"
AGENT_DIR="$ROOT_DIR/.opencode/agent"
# Function to extract metadata from prompt file
extract_metadata() {
local file="$1"
local key="$2"
# Extract YAML frontmatter between --- markers
awk -v key="$key" '
/^---$/ { in_yaml = !in_yaml; next }
in_yaml && $0 ~ "^" key ":" {
sub("^" key ": *", "")
gsub(/"/, "")
print
exit
}
' "$file"
}
# Function to extract recommended models array from metadata
extract_recommended_models() {
local file="$1"
# Extract recommended_models array from YAML
awk '
/^---$/ { in_yaml = !in_yaml; next }
in_yaml && /^recommended_models:/ { in_models = 1; next }
in_yaml && in_models && /^ - / {
# Remove leading spaces, dash, and quotes
gsub(/^ - /, "")
gsub(/"/, "")
# Remove comments
sub(/ *#.*$/, "")
# Trim whitespace
gsub(/^ +| +$/, "")
print
}
in_yaml && in_models && /^[a-z_]+:/ { exit }
' "$file"
}
usage() {
echo "Usage: $0 --agent=<name> --variant=<name>"
echo ""
echo "Required:"
echo " --agent=NAME Agent name (e.g., openagent, opencoder)"
echo " --variant=NAME Prompt variant (default, gpt, gemini, grok, llama)"
echo ""
echo "Optional:"
echo " --help, -h Show this help"
echo ""
echo -e "${BLUE}Architecture:${NC}"
echo " • Agent files (.opencode/agent/*.md) = Canonical defaults"
echo " • Prompt variants (.opencode/prompts/<agent>/<model>.md) = Model-specific"
echo ""
echo "Examples:"
echo " # Use default (canonical agent file)"
echo " $0 --agent=openagent --variant=default"
echo ""
echo " # Switch to GPT-optimized prompt"
echo " $0 --agent=openagent --variant=gpt"
echo ""
echo " # Switch to Gemini-optimized prompt"
echo " $0 --agent=openagent --variant=gemini"
echo ""
echo "Available prompts:"
for agent_dir in "$PROMPTS_DIR"/*/; do
[ -d "$agent_dir" ] || continue
agent=$(basename "$agent_dir")
echo " $agent:"
echo " - default (canonical agent file)"
for prompt in "$agent_dir"*.md; do
if [[ -f "$prompt" ]] && [[ "$(basename "$prompt")" != "TEMPLATE.md" ]] && [[ "$(basename "$prompt")" != "README.md" ]]; then
variant=$(basename "$prompt" .md)
model_family=$(extract_metadata "$prompt" "model_family")
if [[ -n "$model_family" ]]; then
echo " - $variant ($model_family family)"
else
echo " - $variant"
fi
fi
done
done
exit 1
}
# Parse arguments
for arg in "$@"; do
case $arg in
--agent=*)
AGENT_NAME="${arg#*=}"
shift
;;
--variant=*)
PROMPT_VARIANT="${arg#*=}"
shift
;;
--help|-h)
usage
;;
*)
echo -e "${RED}Unknown argument: $arg${NC}"
echo ""
usage
;;
esac
done
# Validate arguments
if [[ -z "$AGENT_NAME" ]] || [[ -z "$PROMPT_VARIANT" ]]; then
echo -e "${RED}Error: Missing required arguments${NC}"
echo ""
usage
fi
AGENT_FILE="$AGENT_DIR/$AGENT_NAME.md"
# Check agent exists
if [[ ! -f "$AGENT_FILE" ]]; then
echo -e "${RED}Error: Agent not found: $AGENT_FILE${NC}"
echo ""
echo "Available agents:"
ls -1 "$AGENT_DIR/"*.md 2>/dev/null | xargs -I {} basename {} .md || echo " (none found)"
exit 1
fi
# Handle "default" variant - agent file is already the default
if [[ "$PROMPT_VARIANT" == "default" ]]; then
echo -e "${GREEN}✓${NC} Agent ${GREEN}$AGENT_NAME${NC} is using the ${GREEN}default${NC} prompt"
echo ""
echo " Location: $AGENT_FILE"
echo ""
echo -e "${BLUE}Note:${NC} In the new architecture, agent files are the canonical defaults."
echo " No action needed - you're already using the default!"
echo ""
exit 0
fi
# For non-default variants, copy from prompts directory
PROMPT_FILE="$PROMPTS_DIR/$AGENT_NAME/$PROMPT_VARIANT.md"
# Check prompt exists
if [[ ! -f "$PROMPT_FILE" ]]; then
echo -e "${RED}Error: Prompt variant not found: $PROMPT_FILE${NC}"
echo ""
echo "Available variants for $AGENT_NAME:"
echo " - default (canonical agent file)"
if [[ -d "$PROMPTS_DIR/$AGENT_NAME" ]]; then
ls -1 "$PROMPTS_DIR/$AGENT_NAME/"*.md 2>/dev/null | grep -v "TEMPLATE.md" | grep -v "README.md" | xargs -I {} basename {} .md || echo " (no model variants found)"
else
echo " (no model variants found)"
fi
exit 1
fi
# Read metadata from prompt file
MODEL_FAMILY=$(extract_metadata "$PROMPT_FILE" "model_family")
RECOMMENDED_MODELS=$(extract_recommended_models "$PROMPT_FILE")
STATUS=$(extract_metadata "$PROMPT_FILE" "status")
# Copy prompt to agent location
cp "$PROMPT_FILE" "$AGENT_FILE"
echo -e "${GREEN}✓${NC} Now using ${GREEN}$PROMPT_VARIANT${NC} prompt for ${GREEN}$AGENT_NAME${NC}"
echo ""
echo " Source: $PROMPT_FILE"
echo " Active: $AGENT_FILE"
echo ""
# Show metadata if available
if [[ -n "$MODEL_FAMILY" ]]; then
echo -e "${YELLOW}Prompt Info:${NC}"
echo " Model Family: $MODEL_FAMILY"
if [[ -n "$STATUS" ]]; then
echo " Status: $STATUS"
fi
if [[ -n "$RECOMMENDED_MODELS" ]]; then
echo " Recommended Models:"
while IFS= read -r model; do
echo " - $model"
done <<< "$RECOMMENDED_MODELS"
fi
echo ""
fi
echo "To restore the default:"
echo " ./scripts/prompts/use-prompt.sh --agent=$AGENT_NAME --variant=default"
echo ""
echo "To test this prompt:"
echo " ./scripts/prompts/test-prompt.sh --agent=$AGENT_NAME --variant=$PROMPT_VARIANT"