#!/usr/bin/env bash # shellcheck disable=SC2086 # graphify 설치 및 바이브 코딩 에이전트 연동 스크립트 # # uv tool을 이용하여 graphifyy를 설치하고, 다양한 AI 코딩 에이전트(Antigravity, Claude, Codex, OpenCode) # 및 Gemini MCP 설정을 자동으로 구성합니다. set -euo pipefail # ──────────────────────────────────────────── # 유틸리티 함수 (모두 stderr 출력) # ──────────────────────────────────────────── info() { echo "[INFO] $*" >&2; } warn() { echo "[WARN] $*" >&2; } error() { echo "[ERROR] $*" >&2; exit 1; } success() { echo "[OK] $*" >&2; } # ──────────────────────────────────────────── # 필수 명령어 확인 # ──────────────────────────────────────────── check_requirements() { if ! command -v uv &>/dev/null; then echo "" >&2 echo "=================================================================" >&2 echo "[ERROR] 'uv' 패키지 관리자가 설치되어 있지 않습니다." >&2 echo "graphify를 설치하려면 먼저 uv가 필요합니다." >&2 echo "아래 명령어를 실행하여 uv를 먼저 설치해 주세요:" >&2 echo "" >&2 echo " curl -fsSL https://astral.sh/uv/install.sh | bash" >&2 echo "=================================================================" >&2 echo "" >&2 exit 1 fi } # ──────────────────────────────────────────── # Gemini MCP 설정 갱신/작성 # ──────────────────────────────────────────── configure_gemini_mcp() { local target_dir="$HOME/.gemini/antigravity" local config_file="$target_dir/mcp_config.json" mkdir -p "$target_dir" info "Gemini MCP 설정 파일 구성 중: $config_file" # uv run python을 활용하여 안전하게 JSON 구조 생성 또는 병합 uv run - << 'EOF' import json import os import sys target_dir = os.path.expanduser("~/.gemini/antigravity") config_file = os.path.join(target_dir, "mcp_config.json") graphify_entry = { "command": "uv", "args": [ "run", "--with", "graphifyy", "--with", "mcp", "-m", "graphify.serve", "${workspace.path}/graphify-out/graph.json" ] } data = {} if os.path.exists(config_file): try: with open(config_file, "r", encoding="utf-8") as f: content = f.read().strip() if content.startswith("{") and content.endswith("}"): data = json.loads(content) elif content.startswith('"graphify"'): # Handle key-only fragments if previously written data = json.loads("{" + content + "}") except Exception as e: sys.stderr.write(f"[WARN] 기존 설정 파싱 실패 (신규 파일로 생성합니다): {e}\n") data = {} # Antigravity/Gemini mcp_config structure handling if "mcpServers" in data and isinstance(data["mcpServers"], dict): data["mcpServers"]["graphify"] = graphify_entry else: data["graphify"] = graphify_entry with open(config_file, "w", encoding="utf-8") as f: json.dump(data, f, indent=2, ensure_ascii=False) f.write("\n") print(f"[OK] Gemini MCP 설정이 성공적으로 저장되었습니다: {config_file}") EOF } # ──────────────────────────────────────────── # 메인 설치 로직 # ──────────────────────────────────────────── main() { info "===== Graphify 지식 그래프 도구 설치 스크립트 =====" # 1. uv 확인 check_requirements success "uv 패키지 관리자가 확인되었습니다." # 2. graphifyy 설치 (uv tool) info "uv tool을 통해 'graphifyy[pdf,openai,anthropic,gemini]' 패키지를 설치/업데이트합니다..." uv tool install --upgrade 'graphifyy[pdf,openai,anthropic,gemini]' success "graphify 도구 설치가 완료되었습니다." # 3. 바이브 코딩 에이전트 연동 info "바이브 코딩 에이전트별 연동 설정을 진행합니다..." agents=("antigravity" "claude" "codex" "opencode") for agent in "${agents[@]}"; do info "에이전트 연동 실행 중: graphify $agent install" if uv tool run --from graphifyy graphify "$agent" install 2>&1 | sed 's/^/ [agent] /'; then success "graphify $agent 연동 완료" else warn "graphify $agent 연동 중 경고/에러가 발생했으나 계속 진행합니다." fi done # 4. Gemini MCP 설정 작성 configure_gemini_mcp echo "" success "===== Graphify 및 에이전트 연동 설치가 모두 완료되었습니다! =====" info "사용 방법 안내:" info " 1. 코드베이스 그래프 생성: graphify ." info " 2. 자연어 질의: graphify query \"프로젝트 구조 설명해줘\"" info " 3. 관계 경로 분석: graphify path \"ClassA\" \"ClassB\"" info " 4. 개념 상세 확인: graphify explain \"AuthManager\"" echo "" } main "$@"