diff --git a/.claude-plugin/check_update.sh b/.claude-plugin/check_update.sh new file mode 100755 index 00000000..e7a744c1 --- /dev/null +++ b/.claude-plugin/check_update.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Version update check for Databricks AI Dev Kit. +# Stdout from this script is injected as context Claude can see at session start. +# Silent on success (up to date) or failure (network error, missing files). + +# Find the installed version. Check multiple locations: +# 1. Plugin mode: VERSION at plugin root +# 2. Project-scoped install: .ai-dev-kit/version in project dir +# 3. Global install: ~/.ai-dev-kit/version +# 4. Fallback: script-relative +VERSION_FILE="" +for candidate in \ + "${CLAUDE_PLUGIN_ROOT:+$CLAUDE_PLUGIN_ROOT/VERSION}" \ + "${CLAUDE_PROJECT_DIR:+$CLAUDE_PROJECT_DIR/.ai-dev-kit/version}" \ + "$HOME/.ai-dev-kit/version" \ + "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/VERSION"; do + [ -n "$candidate" ] && [ -f "$candidate" ] && VERSION_FILE="$candidate" && break +done +CACHE_FILE="$HOME/.ai-dev-kit/.update-check" +REMOTE_URL="https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/VERSION" +CACHE_TTL=86400 # 24 hours + +[ ! -f "$VERSION_FILE" ] && exit 0 +local_ver=$(cat "$VERSION_FILE" 2>/dev/null) +[ -z "$local_ver" ] && exit 0 + +remote_ver="" + +# Check cache +if [ -f "$CACHE_FILE" ]; then + cached_ts=$(grep '^TIMESTAMP=' "$CACHE_FILE" 2>/dev/null | cut -d= -f2) + cached_ver=$(grep '^REMOTE_VERSION=' "$CACHE_FILE" 2>/dev/null | cut -d= -f2) + now=$(date +%s) + if [ -n "$cached_ts" ] && [ -n "$cached_ver" ] && [ $((now - cached_ts)) -lt $CACHE_TTL ]; then + remote_ver="$cached_ver" + fi +fi + +# Fetch if cache is stale +if [ -z "$remote_ver" ]; then + remote_ver=$(curl -fsSL --connect-timeout 3 --max-time 3 "$REMOTE_URL" 2>/dev/null || echo "") + if [ -n "$remote_ver" ] && [[ ! "$remote_ver" =~ (404|Not\ Found|error) ]]; then + mkdir -p "$HOME/.ai-dev-kit" + printf 'TIMESTAMP=%s\nREMOTE_VERSION=%s\n' "$(date +%s)" "$remote_ver" > "$CACHE_FILE" + else + exit 0 + fi +fi + +# If versions differ, output a message for Claude to relay to the user +if [ -n "$remote_ver" ] && [ "$remote_ver" != "$local_ver" ]; then + cat </dev/null && return + fi + + # Fallback: write new file (only if no existing file) + [ -f "$path" ] && return # Don't overwrite existing settings without Python + cat > "$path" << EOF +{ + "hooks": { + "SessionStart": [ + { + "hooks": [ + { + "type": "command", + "command": "bash $script", + "timeout": 5 + } + ] + } + ] + } +} +EOF +} + write_mcp_configs() { step "Configuring MCP" @@ -895,6 +944,14 @@ write_mcp_configs() { claude) [ "$SCOPE" = "global" ] && write_mcp_json "$HOME/.claude/mcp.json" || write_mcp_json "$base_dir/.mcp.json" ok "Claude MCP config" + # Add version check hook to Claude settings + local check_script="$REPO_DIR/.claude-plugin/check_update.sh" + if [ "$SCOPE" = "global" ]; then + write_claude_hook "$HOME/.claude/settings.json" "$check_script" + else + write_claude_hook "$base_dir/.claude/settings.json" "$check_script" + fi + ok "Claude update check hook" ;; cursor) if [ "$SCOPE" = "global" ]; then