#!/usr/bin/env bash # Agent Auto-Routing Reminder Hook # Analyzes user prompts and injects routing reminders for specialized agents # # This hook enables automatic agent invocation by detecting keywords # and triggering appropriate specialist agents set -euo pipefail # Get language setting from environment LANG="${ORCHESTRA_LANGUAGE:-en}" # Read JSON input from stdin INPUT_JSON=$(cat) # Extract user prompt from JSON USER_PROMPT=$(echo "$INPUT_JSON" | jq -r '.prompt // empty' 2>/dev/null || echo "") # If no prompt provided, exit silently if [ -z "$USER_PROMPT" ]; then exit 0 fi # Convert to lowercase for case-insensitive matching PROMPT_LOWER=$(echo "$USER_PROMPT" | tr '[:upper:]' '[:lower:]') # Track if any agent was matched AGENT_MATCHED=false MATCHED_AGENTS=() # --- Priority 1: Ambiguous Requirements → Riley --- if echo "$PROMPT_LOWER" | grep -qE "(fast|faster|slow|slower|easy to use|intuitive|clean|simple|improve performance|optimize|better)"; then MATCHED_AGENTS+=("Riley") AGENT_MATCHED=true fi # --- Priority 2: Major Feature Addition → Alex --- if echo "$PROMPT_LOWER" | grep -qE "(add new|build new|implement new|create new|新しい.*追加|新規.*作成|作りたい|作る|build|make|開発したい)"; then if echo "$PROMPT_LOWER" | grep -qE "(system|feature|authentication|auth|認証|payment|決済|api|site|サイト|app|アプリ|website|ウェブサイト|service|サービス)"; then MATCHED_AGENTS+=("Alex") AGENT_MATCHED=true fi fi # Authentication specifically triggers Alex + Iris if echo "$PROMPT_LOWER" | grep -qE "(authentication|auth|login|認証|ログイン|oauth|jwt|session)"; then if ! [[ " ${MATCHED_AGENTS[@]+"${MATCHED_AGENTS[@]}"} " =~ " Alex " ]]; then MATCHED_AGENTS+=("Alex") AGENT_MATCHED=true fi fi # --- Priority 3: UI/UX → Nova --- if echo "$PROMPT_LOWER" | grep -qE "(ui|dashboard|ダッシュボード|component|コンポーネント|form|フォーム|design|デザイン|layout|responsive|accessibility|a11y|lighthouse|portfolio|ポートフォリオ|landing.*page|ランディング.*ページ|website|ウェブサイト|site.*design|サイト.*デザイン)"; then MATCHED_AGENTS+=("Nova") AGENT_MATCHED=true fi # --- Priority 4: Database → Leo --- if echo "$PROMPT_LOWER" | grep -qE "(database|データベース|table|テーブル|schema|スキーマ|migration|マイグレーション|column|カラム|index|インデックス|rls)"; then MATCHED_AGENTS+=("Leo") AGENT_MATCHED=true fi # --- Priority 5: External Integration → Mina --- if echo "$PROMPT_LOWER" | grep -qE "(stripe|paypal|shopify|aws|gcp|azure|oauth|webhook|api integration|統合)"; then MATCHED_AGENTS+=("Mina") AGENT_MATCHED=true fi # --- Priority 6: Architecture → Kai --- if echo "$PROMPT_LOWER" | grep -qE "(architecture|アーキテクチャ|refactor|リファクタ|design pattern|adr|technical decision)"; then MATCHED_AGENTS+=("Kai") AGENT_MATCHED=true fi # --- Priority 7: Security → Iris --- if echo "$PROMPT_LOWER" | grep -qE "(security|セキュリティ|secret|シークレット|vulnerability|脆弱性|encryption|暗号化|auth|oauth|jwt|token|password|secure)"; then MATCHED_AGENTS+=("Iris") AGENT_MATCHED=true fi # --- Priority 8: Testing & QA → Finn --- if echo "$PROMPT_LOWER" | grep -qE "(test|テスト|unit test|統合テスト|e2e|e2e test|coverage|カバレッジ|flaky|failing|jest|playwright|cypress|quality|qa|validate|benchmark)"; then MATCHED_AGENTS+=("Finn") AGENT_MATCHED=true fi # --- Priority 9: Documentation → Eden --- if echo "$PROMPT_LOWER" | grep -qE "(documentation|ドキュメント|readme|guide|ガイド|handbook|runbook|adr|onboarding|knowledge|wiki|技術仕様書)"; then MATCHED_AGENTS+=("Eden") AGENT_MATCHED=true fi # --- Priority 10: Deployment & Release → Blake --- if echo "$PROMPT_LOWER" | grep -qE "(deploy|デプロイ|release|リリース|version|バージョン|hotfix|hotfix|rollback|ロールバック|production|本番|staging|merge|pull request)"; then MATCHED_AGENTS+=("Blake") AGENT_MATCHED=true fi # --- Priority 11: Operations & Monitoring → Theo --- if echo "$PROMPT_LOWER" | grep -qE "(monitoring|モニタリング|logs|ログ|metrics|メトリクス|alert|アラート|incident|インシデント|performance|パフォーマンス|latency|error|reliability|uptime)"; then MATCHED_AGENTS+=("Theo") AGENT_MATCHED=true fi # --- Priority 12: Code Implementation → Skye (when clear specs) --- if echo "$PROMPT_LOWER" | grep -qE "(implement|実装|write|書く|code|コード|fix bug|バグ修正|refactor|リファクタ|optimize|最適化)"; then # Check if requirements seem clear (no ambiguity words) if ! echo "$PROMPT_LOWER" | grep -qE "(how should|どのように|what's the best|最善|vague|曖昧)"; then MATCHED_AGENTS+=("Skye") AGENT_MATCHED=true fi fi # --- Default: If no specific agent matched, route to Riley (Requirements Clarifier) --- if [ "$AGENT_MATCHED" = false ]; then MATCHED_AGENTS+=("Riley") AGENT_MATCHED=true fi # If any agents matched, output routing reminder as context for Claude if [ "$AGENT_MATCHED" = true ]; then # Build context message based on language if [ "$LANG" = "ja" ]; then CONTEXT=$(cat <