#!/usr/bin/env bash # auto-setup-xstudio-ai.sh # # Wrap setup-xstudio-ai.sh with auto-detection: # - If ai-config.json already has claude-process provider with non-empty baseURL → no-op # - Else → call setup-xstudio-ai.sh on workspace root # # Usage: # bash scripts/auto-setup-xstudio-ai.sh # use $PWD as workspaceRoot # bash scripts/auto-setup-xstudio-ai.sh # explicit workspaceRoot # # Returns: # 0 config already present OR written OK # 1 bad arg # 2 setup-xstudio-ai.sh failed # 3 ai-config.json missing after setup set -euo pipefail WS_ROOT="${1:-$PWD}" if [ ! -d "$WS_ROOT" ]; then echo "ERROR: workspaceRoot $WS_ROOT 不存在" >&2 exit 1 fi CONFIG="$WS_ROOT/.xstudio/ai-config.json" # 检测是否已就绪:claude-process.baseURL 非空 if [ -f "$CONFIG" ] && python3 -c " import json, sys try: cfg = json.load(open('$CONFIG')) cp = cfg.get('providers', {}).get('claude-process', {}) sys.exit(0 if cp.get('baseURL') else 1) except Exception: sys.exit(1) " 2>/dev/null; then echo "ai-config already has claude-process provider; no-op" exit 0 fi # 调 setup-xstudio-ai.sh SELF_DIR="$(cd "$(dirname "$0")" && pwd)" if ! bash "$SELF_DIR/setup-xstudio-ai.sh" "$WS_ROOT"; then echo "ERROR: setup-xstudio-ai.sh failed" >&2 exit 2 fi # 后置断言 if [ ! -f "$CONFIG" ]; then echo "ERROR: $CONFIG 仍不存在" >&2 exit 3 fi echo "ai-config ready: $CONFIG"