|
| 1 | +#!/usr/bin/env bash |
| 2 | +#ddev-generated |
| 3 | +#annertech-ddev |
| 4 | + |
| 5 | +## Description: AI Prompts Operations Centre |
| 6 | +## Usage: ai-prompts |
| 7 | +## Example: "ddev ai-prompts" |
| 8 | +## Aliases: ai |
| 9 | + |
| 10 | +# Colours |
| 11 | +RED='\033[0;31m' |
| 12 | +GREEN='\033[0;32m' |
| 13 | +YELLOW='\033[1;33m' |
| 14 | +NC='\033[0m' |
| 15 | + |
| 16 | +echo_red() { echo -e "${RED}$1${NC}" >&2; } |
| 17 | +echo_green() { echo -e "${GREEN}$1${NC}" >&2; } |
| 18 | +echo_yellow() { echo -e "${YELLOW}$1${NC}" >&2; } |
| 19 | + |
| 20 | +# Menu options |
| 21 | +OPTIONS=( |
| 22 | + "1. BackstopJS Init" |
| 23 | +) |
| 24 | + |
| 25 | +# AI Agent options |
| 26 | +AI_AGENTS=( |
| 27 | + "1. Gemini" |
| 28 | + "2. Claude" |
| 29 | +) |
| 30 | + |
| 31 | +# Select action |
| 32 | +select_action() { |
| 33 | + echo_green "Start typing to select a prompt" |
| 34 | + printf '%s\n' "${OPTIONS[@]}" | fzf --reverse --height=50% --header="AI Prompt" |
| 35 | +} |
| 36 | + |
| 37 | +# Select AI agent |
| 38 | +select_agent() { |
| 39 | + echo_green "Select AI agent" |
| 40 | + printf '%s\n' "${AI_AGENTS[@]}" | fzf --reverse --height=50% --header="AI Agent" |
| 41 | +} |
| 42 | + |
| 43 | +# BackstopJS Init function |
| 44 | +backstop_init() { |
| 45 | + # Extract environment variables from DDEV container |
| 46 | + TEST_DOMAIN=$(ddev exec env | grep -E '^DDEV_PRIMARY_URL=' | cut -d= -f2) |
| 47 | + REFERENCE_DOMAIN=$(ddev exec env | grep -E '^STAGE_FILE_PROXY_URL=' | cut -d= -f2) |
| 48 | + |
| 49 | + # Validate variables |
| 50 | + if [ -z "$TEST_DOMAIN" ]; then |
| 51 | + echo_red "Error: DDEV_PRIMARY_URL not found" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + |
| 55 | + if [ -z "$REFERENCE_DOMAIN" ]; then |
| 56 | + echo_red "Error: STAGE_FILE_PROXY_URL not found" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + |
| 60 | + # Change to tests/backstop directory |
| 61 | + if ! cd tests/backstop 2>/dev/null; then |
| 62 | + echo_red "Error: tests/backstop directory not found" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + |
| 66 | + # Select AI agent |
| 67 | + local agent_selection |
| 68 | + agent_selection=$(select_agent) |
| 69 | + if [[ -z "$agent_selection" ]]; then |
| 70 | + echo_red "No agent selected... Exiting" |
| 71 | + exit 0 |
| 72 | + fi |
| 73 | + |
| 74 | + # Extract agent label |
| 75 | + local agent_label |
| 76 | + agent_label=$(echo "$agent_selection" | sed 's/^[0-9]*\. //') |
| 77 | + |
| 78 | + echo_green "Initializing BackstopJS configuration with ${agent_label}..." |
| 79 | + echo "" |
| 80 | + |
| 81 | + # Read and populate the prompt |
| 82 | + local prompt_content |
| 83 | + prompt_content=$(sed -e "s|__TEST_DOMAIN__|$TEST_DOMAIN|g" \ |
| 84 | + -e "s|__REFERENCE_DOMAIN__|$REFERENCE_DOMAIN|g" \ |
| 85 | + ../../.ddev/scripts/prompts/backstop-init.md) |
| 86 | + |
| 87 | + # Call the selected AI agent |
| 88 | + case "$agent_label" in |
| 89 | + "Gemini") |
| 90 | + gemini "$prompt_content" |
| 91 | + ;; |
| 92 | + "Claude") |
| 93 | + claude "$prompt_content" |
| 94 | + ;; |
| 95 | + *) |
| 96 | + echo_red "Unknown agent: $agent_label" |
| 97 | + exit 1 |
| 98 | + ;; |
| 99 | + esac |
| 100 | +} |
| 101 | + |
| 102 | +# Main function |
| 103 | +main() { |
| 104 | + # Banner |
| 105 | + echo_green " |
| 106 | + █████╗ ██╗ ██████╗ ██████╗ ██████╗ ███╗ ███╗██████╗ ████████╗███████╗ |
| 107 | +██╔══██╗██║ ██╔══██╗██╔══██╗██╔═══██╗████╗ ████║██╔══██╗╚══██╔══╝██╔════╝ |
| 108 | +███████║██║ ██████╔╝██████╔╝██║ ██║██╔████╔██║██████╔╝ ██║ ███████╗ |
| 109 | +██╔══██║██║ ██╔═══╝ ██╔══██╗██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ╚════██║ |
| 110 | +██║ ██║██║ ██║ ██║ ██║╚██████╔╝██║ ╚═╝ ██║██║ ██║ ███████║ |
| 111 | +╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝ |
| 112 | +" |
| 113 | + echo " AI-Powered Prompt Operations by Annertech" |
| 114 | + echo "" |
| 115 | + |
| 116 | + # Select action |
| 117 | + local action_selection |
| 118 | + action_selection=$(select_action) |
| 119 | + if [[ -z "$action_selection" ]]; then |
| 120 | + echo_red "Nothing selected... Exiting" |
| 121 | + exit 0 |
| 122 | + fi |
| 123 | + |
| 124 | + # Extract action from selection (remove number prefix) |
| 125 | + local action_label |
| 126 | + action_label=$(echo "$action_selection" | sed 's/^[0-9]*\. //') |
| 127 | + |
| 128 | + echo "" |
| 129 | + |
| 130 | + # Execute selected action |
| 131 | + case "$action_label" in |
| 132 | + "BackstopJS Init") |
| 133 | + backstop_init |
| 134 | + ;; |
| 135 | + *) |
| 136 | + echo_red "Unknown action: $action_label" |
| 137 | + exit 1 |
| 138 | + ;; |
| 139 | + esac |
| 140 | +} |
| 141 | + |
| 142 | +main |
0 commit comments