#!/usr/bin/env bash set -euo pipefail BASE_URL="${CODEGRAFF_URL:-https://codegraff.com/v}" INSTALL_DIR="${CODEGRAFF_DIR:-$HOME/bin}" TOOLS=(zigrep zigread zigpatch zigcreate zigdiff zigmemo zigpar codedb-pro) # Colors R='\033[0;31m' G='\033[0;32m' Y='\033[0;33m' B='\033[0;34m' C='\033[0;36m' W='\033[1;37m' D='\033[0;90m' N='\033[0m' detect_platform() { local os arch os="$(uname -s)" arch="$(uname -m)" case "$os" in Darwin) os="darwin" ;; Linux) os="linux" ;; *) printf " ${R}Unsupported OS: $os${N}\n" >&2; exit 1 ;; esac case "$arch" in arm64|aarch64) arch="arm64" ;; x86_64|amd64) arch="x86_64" ;; *) printf " ${R}Unsupported arch: $arch${N}\n" >&2; exit 1 ;; esac # Apple Silicon under a Rosetta-translated shell reports x86_64 from uname -m. # Prefer the native arm64 build: it exists and is signed, whereas an unsigned # x86_64 build is SIGKILLed under Rosetta (and arm64 is faster regardless). if [ "$os" = "darwin" ] && [ "$arch" = "x86_64" ]; then if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = "1" ] || [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" = "1" ]; then arch="arm64" fi fi echo "${os}-${arch}" } register_claude() { local codedbpro_bin="$1" local config="$HOME/.claude.json" if ! command -v python3 >/dev/null 2>&1; then printf " ${D}claude: skip (python3 not found)${N}\n" return fi python3 - "$config" "$codedbpro_bin" << 'PYEOF' import json, sys, os config_path, codedbpro_bin = sys.argv[1], sys.argv[2] try: with open(config_path) as f: data = json.load(f) except (FileNotFoundError, json.JSONDecodeError): data = {} servers = data.setdefault("mcpServers", {}) servers["codedbpro"] = {"command": codedbpro_bin, "args": ["--mcp"]} with open(config_path, "w") as f: json.dump(data, f, indent=2) f.write("\n") PYEOF printf " ${G}✓${N} claude code ${D}→ $config${N}\n" } register_codex() { local codedbpro_bin="$1" local config_dir="$HOME/.codex" local config="$config_dir/config.toml" mkdir -p "$config_dir" if [ -f "$config" ] && grep -q '\[mcp_servers\.codedbpro\]' "$config" 2>/dev/null; then printf " ${G}✓${N} codex ${D}→ $config (updated)${N}\n" return fi { [ -f "$config" ] && [ -s "$config" ] && echo "" echo '[mcp_servers.codedbpro]' echo "command = \"$codedbpro_bin\"" echo 'args = ["--mcp"]' } >> "$config" printf " ${G}✓${N} codex ${D}→ $config${N}\n" } register_gemini() { local codedbpro_bin="$1" local config_dir="$HOME/.gemini" local config="$config_dir/settings.json" # Only register if Gemini CLI is installed (config dir exists) if [ ! -d "$config_dir" ]; then return fi if ! command -v python3 >/dev/null 2>&1; then printf " ${D}gemini: skip (python3 not found)${N}\n" return fi python3 - "$config" "$codedbpro_bin" << 'PYEOF' import json, sys, os config_path, codedbpro_bin = sys.argv[1], sys.argv[2] try: with open(config_path) as f: data = json.load(f) except (FileNotFoundError, json.JSONDecodeError): data = {} servers = data.setdefault("mcpServers", {}) servers["codedbpro"] = {"command": codedbpro_bin, "args": ["--mcp"]} with open(config_path, "w") as f: json.dump(data, f, indent=2) f.write("\n") PYEOF printf " ${G}✓${N} gemini cli ${D}→ $config${N}\n" } register_cursor() { local codedbpro_bin="$1" local config_dir="$HOME/.cursor" local config="$config_dir/mcp.json" # Only register if Cursor is installed (config dir exists) if [ ! -d "$config_dir" ]; then return fi if ! command -v python3 >/dev/null 2>&1; then printf " ${D}cursor: skip (python3 not found)${N}\n" return fi python3 - "$config" "$codedbpro_bin" << 'PYEOF' import json, sys, os config_path, codedbpro_bin = sys.argv[1], sys.argv[2] try: with open(config_path) as f: data = json.load(f) except (FileNotFoundError, json.JSONDecodeError): data = {} servers = data.setdefault("mcpServers", {}) servers["codedbpro"] = {"command": codedbpro_bin, "args": ["--mcp"]} with open(config_path, "w") as f: json.dump(data, f, indent=2) f.write("\n") PYEOF printf " ${G}✓${N} cursor ${D}→ $config${N}\n" } register_hooks() { local codedbpro_bin="$1" if ! command -v python3 >/dev/null 2>&1; then printf " ${D}hooks: skip (python3 not found)${N}\n" return fi python3 - "$codedbpro_bin" << 'PYEOF' import json, os, stat, sys codedbpro_bin = sys.argv[1] home = os.path.expanduser("~") hooks_dir = os.path.join(home, ".claude", "hooks") settings_path = os.path.join(home, ".claude", "settings.json") os.makedirs(hooks_dir, exist_ok=True) scripts = { "block-legacy-tools.sh": r'''#!/bin/bash source "$HOME/.claude/hooks/codedbpro-gate.sh" 2>/dev/null || exit 0 codedbpro_enforce || exit 0 command -v jq >/dev/null 2>&1 || exit 0 INPUT=$(cat) CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty') STRIPPED=$(echo "$CMD" | sed -E 's/^[[:space:]]*(env|sudo|command|builtin|exec|nohup)[[:space:]]+//') STRIPPED=$(echo "$STRIPPED" | sed -E 's/^[[:space:]]*[A-Za-z_][A-Za-z0-9_]*=[^[:space:]]*[[:space:]]+//') FIRST=$(echo "$STRIPPED" | awk '{print $1}') case "$FIRST" in grep|rg|egrep|fgrep) echo "BLOCKED: Use mcp__codedbpro__search (preferred) or zigrep instead of $FIRST" >&2; exit 2 ;; cat) echo "BLOCKED: Use mcp__codedbpro__read (preferred) or zigread instead of cat" >&2; exit 2 ;; head|tail) echo "BLOCKED: Use mcp__codedbpro__read with mode=lines (preferred) or zigread -L instead of $FIRST" >&2; exit 2 ;; sed|awk) echo "BLOCKED: Use mcp__codedbpro__edit (preferred) or zigpatch instead of $FIRST" >&2; exit 2 ;; find) echo "BLOCKED: Use mcp__codedbpro__search with find=true (preferred) or zigrep -F instead of find" >&2; exit 2 ;; esac exit 0 ''', "block-native-tools.sh": r'''#!/bin/bash # Steer native file tools to codedbpro, but ONLY when codedb-pro is licensed # and usable. Otherwise no-op (exit 0) so the agent keeps its native tools. source "$HOME/.claude/hooks/codedbpro-gate.sh" 2>/dev/null || exit 0 codedbpro_enforce || exit 0 echo "BLOCKED: Use mcp__codedbpro__read/search/edit/create/diff (preferred) or zigread/zigrep/zigpatch/zigcreate/zigdiff via Bash" >&2 exit 2 ''', "auto-verify-edit.sh": r'''#!/bin/bash command -v zigdiff >/dev/null 2>&1 || exit 0 command -v jq >/dev/null 2>&1 || exit 0 INPUT=$(cat) CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty') [ -z "$CMD" ] && exit 0 if echo "$CMD" | grep -qE '(zigpatch|zigcreate)' && ! echo "$CMD" | grep -qE '(zigpatch|zigcreate)[[:space:]]+(pipe|--undo|--help|-h)'; then FILE=$(echo "$CMD" | awk '{for(i=1;i<=NF;i++){if($i=="zigpatch"||$i=="zigcreate"){for(j=i+1;j<=NF;j++){if(substr($j,1,1)!="-"){print $j;exit}}}}}') [ -n "$FILE" ] && [ -f "$FILE" ] && zigdiff "$FILE" >&2 2>&1 fi exit 0 ''', "auto-log-error.sh": r'''#!/bin/bash command -v zigmemo >/dev/null 2>&1 || exit 0 command -v jq >/dev/null 2>&1 || exit 0 INPUT=$(cat) CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty') ERROR=$(echo "$INPUT" | jq -r '.tool_error // .stderr // empty' | head -3) [ -z "$CMD" ] && exit 0 [ -z "$ERROR" ] && exit 0 zigmemo error "$(echo "$CMD" | head -1 | cut -c1-120)" "$(echo "$ERROR" | head -1 | cut -c1-200)" 2>/dev/null exit 0 ''', "pre-compact-save.sh": r'''#!/bin/bash command -v zigmemo >/dev/null 2>&1 || exit 0 PLAN=$(zigmemo plan --status 2>/dev/null) if [ -n "$PLAN" ] && ! echo "$PLAN" | grep -q 'no plan'; then zigmemo store "[pre-compact] Plan: $PLAN" --tag compact-save 2>/dev/null fi ERRORS=$(zigmemo errors 2>/dev/null) if [ -n "$ERRORS" ] && ! echo "$ERRORS" | grep -q 'no errors'; then zigmemo store "[pre-compact] Errors: $ERRORS" --tag compact-save 2>/dev/null fi exit 0 ''', "post-compact-reload.sh": r'''#!/bin/bash command -v zigmemo >/dev/null 2>&1 || exit 0 CONTEXT=$(zigmemo context 2>/dev/null) [ -n "$CONTEXT" ] && echo "$CONTEXT" exit 0 ''', } # Shared gate sourced by the two blocking hooks. codedbpro_enforce returns 0 # only when codedb-pro is present AND licensed (codedb-pro probe exits 0). The # result is cached briefly so the blocking hooks do not fork a probe on every # tool call. Because the blocking hooks consult this, they stay dormant until a # valid license exists, re-enable automatically once one does, and a lapsed # license can never deadlock the agent. scripts["codedbpro-gate.sh"] = r'''#!/bin/bash codedbpro_enforce() { local bin cache sticky ttl now ts val code bin="__CODEDBPRO_BIN__" [ -x "$bin" ] || bin="$(command -v codedb-pro 2>/dev/null)" [ -n "$bin" ] && [ -x "$bin" ] || return 1 cache="$HOME/.claude/.codedbpro_probe" sticky="$HOME/.claude/.codedbpro_licensed" ttl=60 now="$(date +%s 2>/dev/null || echo 0)" # Fast path: only definitive verdicts (1/0) are ever cached, so a fresh cache # entry is always a real decision — never a guess that could flap. if [ -r "$cache" ]; then read -r ts val < "$cache" 2>/dev/null if [ -n "${ts:-}" ] && [ "$now" -gt 0 ] && [ $((now - ts)) -lt "$ttl" ]; then [ "$val" = "1" ] && return 0 return 1 fi fi # Probe: 0 = licensed, 73 = definitively dormant, 75 = indeterminate. "$bin" probe >/dev/null 2>&1 code=$? if [ "$code" -eq 0 ]; then : > "$sticky" 2>/dev/null # remember: this machine is licensed printf '%s 1\n' "$now" > "$cache" 2>/dev/null return 0 fi if [ "$code" -eq 73 ]; then rm -f "$sticky" 2>/dev/null # genuine deactivation: forget it printf '%s 0\n' "$now" > "$cache" 2>/dev/null return 1 fi # Indeterminate (75) or any unexpected non-zero: do NOT trust this as a license # verdict. Hold the last-known state via the sticky marker — a licensed machine # keeps enforcing through env/transient probe failures (the claude -p flap, # #119), while a never-licensed machine stays dormant and is never deadlocked. if [ -e "$sticky" ]; then val=1; else val=0; fi printf '%s %s\n' "$now" "$val" > "$cache" 2>/dev/null [ "$val" = "1" ] } '''.replace("__CODEDBPRO_BIN__", codedbpro_bin) for name, content in scripts.items(): path = os.path.join(hooks_dir, name) with open(path, "w") as f: f.write(content) os.chmod(path, os.stat(path).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) try: with open(settings_path) as f: data = json.load(f) except (FileNotFoundError, json.JSONDecodeError): data = {} hooks = data.setdefault("hooks", {}) hooks["PreToolUse"] = [ {"matcher": "Read|Edit|Write|Grep|Glob", "hooks": [{"type": "command", "command": "$HOME/.claude/hooks/block-native-tools.sh"}]}, {"matcher": "Bash", "hooks": [{"type": "command", "command": "$HOME/.claude/hooks/block-legacy-tools.sh"}]} ] hooks["PostToolUse"] = [ {"matcher": "Bash", "hooks": [{"type": "command", "command": "$HOME/.claude/hooks/auto-verify-edit.sh"}]} ] hooks["PostToolUseFailure"] = [ {"matcher": "Bash", "hooks": [{"type": "command", "command": "$HOME/.claude/hooks/auto-log-error.sh"}]} ] hooks["PreCompact"] = [ {"matcher": "", "hooks": [{"type": "command", "command": "$HOME/.claude/hooks/pre-compact-save.sh"}]} ] hooks["SessionStart"] = [ {"matcher": "compact", "hooks": [{"type": "command", "command": "$HOME/.claude/hooks/post-compact-reload.sh"}]} ] with open(settings_path, "w") as f: json.dump(data, f, indent=2) f.write("\n") PYEOF printf " ${G}✓${N} hooks ${D}→ ~/.claude/hooks/ + settings.json${N}\n" } register_cursor_hooks() { local cursor_dir="$HOME/.cursor" local hooks_config="$cursor_dir/hooks.json" # Only register if Cursor is installed if [ ! -d "$cursor_dir" ]; then return fi if ! command -v python3 >/dev/null 2>&1; then printf " ${D}cursor hooks: skip (python3 not found)${N}\n" return fi # Reuse the same hook scripts from ~/.claude/hooks/ (already installed by register_hooks) local hooks_dir="$HOME/.claude/hooks" if [ ! -d "$hooks_dir" ]; then return fi python3 - "$hooks_config" "$hooks_dir" << 'PYEOF' import json, sys, os config_path, hooks_dir = sys.argv[1], sys.argv[2] try: with open(config_path) as f: data = json.load(f) except (FileNotFoundError, json.JSONDecodeError): data = {} data["version"] = 1 hooks = data.setdefault("hooks", {}) hooks["beforeShellExecution"] = [ {"command": os.path.join(hooks_dir, "block-legacy-tools.sh")} ] hooks["afterShellExecution"] = [ {"command": os.path.join(hooks_dir, "auto-verify-edit.sh")} ] hooks["afterFileEdit"] = [ {"command": os.path.join(hooks_dir, "auto-log-error.sh")} ] hooks["preCompact"] = [ {"command": os.path.join(hooks_dir, "pre-compact-save.sh")} ] hooks["sessionStart"] = [ {"command": os.path.join(hooks_dir, "post-compact-reload.sh")} ] with open(config_path, "w") as f: json.dump(data, f, indent=2) f.write("\n") PYEOF printf " ${G}✓${N} cursor hooks ${D}→ $hooks_config${N}\n" } safe_download() { local url="$1" tmp="$2" if ! curl -fsSL --max-time 60 -A 'codegraff-installer' "$url" -o "$tmp" 2>/dev/null; then rm -f "$tmp" 2>/dev/null return 1 fi if [ ! -s "$tmp" ]; then rm -f "$tmp" return 1 fi # Reject text bodies (JSON / HTML error pages) returned with HTTP 200 — they # would otherwise clobber an existing binary via mv -f. Real Mach-O / ELF # binaries start with non-printable magic bytes, never '{' or '<'. case "$(head -c 1 "$tmp" 2>/dev/null)" in '{'|'<') rm -f "$tmp" return 1 ;; esac return 0 } migrate_old_muonry() { # Pre-rename installs left a "muonry" binary + MCP server. Remove them so upgraders # don't keep a dead muonry server next to codedbpro, and carry the Pro license over. local old_bin="$INSTALL_DIR/muonry" local did=0 if [ -f "$HOME/.config/muonry/config" ] && [ ! -f "$HOME/.config/codedbpro/config" ]; then mkdir -p "$HOME/.config/codedbpro" cp "$HOME/.config/muonry/config" "$HOME/.config/codedbpro/config" 2>/dev/null && did=1 fi if [ -f "$old_bin" ]; then rm -f "$old_bin" && did=1; fi if command -v python3 >/dev/null 2>&1; then for cfg in "$HOME/.claude.json" "$HOME/.gemini/settings.json" "$HOME/.cursor/mcp.json"; do [ -f "$cfg" ] || continue python3 - "$cfg" << 'PYEOF' import json, sys p = sys.argv[1] try: with open(p) as f: data = json.load(f) except Exception: sys.exit(0) s = data.get("mcpServers") if isinstance(s, dict) and s.pop("muonry", None) is not None: with open(p, "w") as f: json.dump(data, f, indent=2) f.write("\n") PYEOF done fi local codex="$HOME/.codex/config.toml" if [ -f "$codex" ] && grep -q '\[mcp_servers\.muonry\]' "$codex" 2>/dev/null; then awk '/^\[mcp_servers\.muonry\]/{skip=1;next} /^\[/{skip=0} skip!=1{print}' "$codex" > "$codex.tmp" && mv -f "$codex.tmp" "$codex" did=1 fi # Guard the trailing test: a bare [ ... ] && printf returns non-zero when # did=0 (fresh install, nothing to migrate), and under set -e that aborts # the whole registration phase. An explicit if-block always returns 0. if [ "$did" = "1" ]; then printf " ${G}✓${N} migrated ${D}→ removed old muonry, kept your license${N}\n" fi } windows_notice() { echo "" printf " ${W}codegraff installer${N}\n" echo "" printf " ${Y}Windows detected${N} — graff runs natively; install it from PowerShell:\n" echo "" printf " ${C}irm https://codegraff.com/install.ps1 | iex${N}\n" echo "" printf " The other Codegraff tools are Linux/macOS binaries; for those use ${G}WSL2${N}:\n" echo "" printf " ${C}wsl curl -fsSL https://codegraff.com/v/install.sh | bash${N}\n" echo "" printf " ${D}https://learn.microsoft.com/en-us/windows/wsl/install${N}\n" echo "" } main() { local platform version ext="" # Here, not in detect_platform: that runs in $(...), where exit only leaves the subshell. case "$(uname -s)" in MINGW*|MSYS*|CYGWIN*) windows_notice; exit 0 ;; esac platform="$(detect_platform)" echo "" printf " ${W}codegraff${N} ${D}installer${N}\n" echo "" printf " ${D}platform${N} $platform\n" version="${CODEGRAFF_VERSION:-}" if [ -z "$version" ]; then version="$(curl -fsSL "$BASE_URL/latest.json" | grep -o '"version":"[^"]*"' | cut -d'"' -f4)" fi if [ -z "$version" ]; then printf " ${R}error: could not fetch latest version${N}\n" >&2 exit 1 fi printf " ${D}version${N} v${version}\n" [[ "$platform" == windows-* ]] && ext=".exe" mkdir -p "$INSTALL_DIR" printf " ${D}install${N} $INSTALL_DIR\n" echo "" local ok=0 total=${#TOOLS[@]} # Parallel download phase: network I/O dominates install time, so fan out # every download at once instead of fetching one tool after another. codedb # lives on GitHub (a separate host), so it gets a head start; then we batch # the codegraff tools. The local mv/chmod work is microseconds, so we # serialize that below to keep the per-tool status lines ordered and clean. # codedb (symbol intelligence): kicked off first so its GitHub fetch overlaps # the tool downloads. Reaped later in the codedb section below. local codedb_url="https://github.com/justrach/codedb/releases/latest/download/codedb-${platform}${ext}" local codedb_dest="$INSTALL_DIR/codedb${ext}" local codedb_tmp="/tmp/codedb.tmp.$$" safe_download "$codedb_url" "$codedb_tmp" & local codedb_pid="$!" # Fan out every tool download to its own temp file (validated by safe_download # so a JSON/HTML error body can't clobber a dest via mv -f). printf " ${D}downloading ${total} tools in parallel...${N}\n" local -a dl_pids=() dl_tmps=() for tool in "${TOOLS[@]}"; do local url="$BASE_URL/v${version}/${tool}-${platform}${ext}" local tmp="/tmp/${tool}.tmp.$$" safe_download "$url" "$tmp" & dl_pids+=("$!") dl_tmps+=("$tmp") done # Reap in tool order: wait returns each job's stored exit status, so the # status lines stay ordered and a job that finished early costs nothing. local idx=0 for tool in "${TOOLS[@]}"; do local dest="$INSTALL_DIR/${tool}${ext}" local tmp="${dl_tmps[$idx]}" printf " ${D}│${N} %-12s " "$tool" # mv via temp first avoids macOS Sequoia's immutable provenance xattr. if wait "${dl_pids[$idx]}"; then xattr -c "$tmp" 2>/dev/null || true mv -f "$tmp" "$dest" chmod +x "$dest" printf "${G}✓${N}\n" ok=$((ok + 1)) else printf "${D}skip${N}\n" fi idx=$((idx + 1)) done echo "" printf " ${G}${ok}${N}${D}/${total} tools installed${N}\n" if [ "$ok" -eq 0 ]; then echo "" printf " ${R}✗ install failed: no prebuilt binaries for ${platform}${N}\n" printf " ${D}every download returned 404; this platform is not published yet.${N}\n" case "$platform" in darwin-x86_64) printf " ${D}Intel Mac builds are rolling out; on Apple Silicon use a native (non-Rosetta) terminal.${N}\n" ;; esac exit 1 fi # Register MCP servers + hooks local codedbpro_bin="$INSTALL_DIR/codedb-pro${ext}" if [ -f "$codedbpro_bin" ]; then echo "" printf " ${W}registering integrations${N}\n" echo "" migrate_old_muonry register_claude "$codedbpro_bin" register_codex "$codedbpro_bin" register_gemini "$codedbpro_bin" register_cursor "$codedbpro_bin" register_hooks "$codedbpro_bin" register_cursor_hooks # Belt: probe once now to seed the cache + sticky marker the self-gating # hooks read, and to report state. Hooks are written either way and stay # dormant until codedb-pro probe succeeds, so activating later self-enables # enforcement with no re-install, and a lapsed license can never deadlock. mkdir -p "$HOME/.claude" local _now _code; _now="$(date +%s 2>/dev/null || echo 0)" _code=0; "$codedbpro_bin" probe >/dev/null 2>&1 || _code=$? if [ "$_code" -eq 0 ]; then printf '%s 1\n' "$_now" > "$HOME/.claude/.codedbpro_probe" 2>/dev/null || true : > "$HOME/.claude/.codedbpro_licensed" 2>/dev/null || true printf " ${G}✓${N} enforcement ${D}→ active (Pro license valid)${N}\n" elif [ "$_code" -eq 73 ]; then printf '%s 0\n' "$_now" > "$HOME/.claude/.codedbpro_probe" 2>/dev/null || true rm -f "$HOME/.claude/.codedbpro_licensed" 2>/dev/null || true printf " ${Y}!${N} enforcement ${D}→ dormant until: ${C}codedb-pro activate${D} (hooks self-enable, no re-install)${N}\n" else # Indeterminate (env/transient): don't seed a verdict. The gate resolves on # first real use and then holds last-known state. printf " ${Y}!${N} enforcement ${D}→ pending (license unverified now; resolves on first use)${N}\n" fi fi # Install codedb (symbol intelligence — powers codedb-pro's symbol_search) # Fetched directly from GitHub releases — codedb.codegraff.com has been # observed returning HTTP 200 with JSON error bodies on missing assets, # which would clobber the destination binary via mv -f. safe_download # additionally rejects any non-binary response as defense in depth. echo "" printf " ${W}codedb${N} ${D}(symbol intelligence)${N}\n" # Reap the codedb download kicked off in parallel at the start of main(). if wait "$codedb_pid"; then xattr -c "$codedb_tmp" 2>/dev/null || true mv -f "$codedb_tmp" "$codedb_dest" chmod +x "$codedb_dest" printf " ${G}✓${N} codedb installed\n" else printf " ${Y}!${N} codedb install skipped — run later: ${C}curl -fsSL https://codedb.codegraff.com/install.sh | bash${N}\n" fi # Register codedb as its own MCP server (symbol intelligence, separate from codedb-pro) if [ -f "$codedb_dest" ] && command -v python3 >/dev/null 2>&1; then python3 - "$HOME/.claude.json" "$codedb_dest" << 'CODEDBEOF' import json, sys config_path, codedb_bin = sys.argv[1], sys.argv[2] try: with open(config_path) as f: data = json.load(f) except (FileNotFoundError, json.JSONDecodeError): data = {} servers = data.setdefault("mcpServers", {}) servers["codedb"] = {"command": codedb_bin, "args": ["mcp"]} with open(config_path, "w") as f: json.dump(data, f, indent=2); f.write("\n") CODEDBEOF printf " ${G}✓${N} codedb mcp ${D}→ ~/.claude.json${N}\n" fi # Install graff (the free CLI, already SOTA on Terminal-Bench). Its branded # installer drops the graff binary into the same $HOME/bin as the rest of the # toolchain; we pipe it through the codegraff.com proxy so the URL stays # on-brand and always tracks the latest release. Non-fatal: the rest of the # toolchain is already installed by the time we get here. echo "" printf " ${W}graff${N} ${D}(free CLI, SOTA on Terminal-Bench)${N}\n" graff_sh=sh if command -v bash >/dev/null 2>&1; then graff_sh=bash; fi if curl -fsSL --max-time 60 -A 'codegraff-installer' https://codegraff.com/install-graff.sh 2>/dev/null | HARNESS_DIR="$INSTALL_DIR" HARNESS_NO_GRAFF=1 "$graff_sh" >/dev/null 2>&1; then printf " ${G}✓${N} graff installed ${D}→ $INSTALL_DIR${N}\n" else printf " ${Y}!${N} graff install skipped, run later: ${C}curl -fsSL https://codegraff.com/install-graff.sh | bash${N}\n" fi # Check PATH case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) echo "" printf " ${Y}add to PATH:${N}\n" printf " ${C}export PATH=\"$INSTALL_DIR:\$PATH\"${N}\n" printf " ${D}(add to ~/.bashrc or ~/.zshrc)${N}\n" ;; esac echo "" printf " ${W}next:${N}\n" printf " ${C}graff login${N} ${D}free Codegraff key, then run ${C}graff${D} in any project${N}\n" echo "" printf " ${D}codedb-pro license (optional):${N} ${C}codedb-pro activate CGPRO-XXXX you@email.com${N}\n" printf " ${D}no license yet?${N} ${B}https://codegraff.com/buy${N}\n" echo "" } main