Files
claude-scripts/setup_global_hook.sh
Travis Vasceannie 4ac9b1c5e1 Refactor: move hooks to quality package
- Move Claude Code hooks under src/quality/hooks (rename modules)
- Add a project-local installer for Claude Code hooks
- Introduce internal_duplicate_detector and code_quality_guard
- Update tests to reference new module paths and guard API
- Bump package version to 0.1.1 and adjust packaging
2025-10-26 22:15:04 +00:00

111 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# Setup script to install the Claude Code quality hooks as a project-local
# configuration inside .claude/ without mutating any global Claude settings.
set -euo pipefail
# Colors for formatted output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${YELLOW}Configuring project-local Claude Code quality hook...${NC}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$SCRIPT_DIR"
DEFAULT_MIRROR="https://git.sidepiece.rip/api/packages/vasceannie/pypi/simple"
CLAUDE_SCRIPTS_VERSION="${CLAUDE_SCRIPTS_VERSION:-0.1.1}"
CLAUDE_SCRIPTS_PYPI_INDEX="${CLAUDE_SCRIPTS_PYPI_INDEX:-$DEFAULT_MIRROR}"
CLAUDE_SCRIPTS_EXTRA_INDEX_URL="${CLAUDE_SCRIPTS_EXTRA_INDEX_URL:-}"
install_claude_scripts_if_missing() {
if command -v claude-quality >/dev/null 2>&1; then
return 0
fi
echo -e "${YELLOW}claude-quality not found. Installing claude-scripts==${CLAUDE_SCRIPTS_VERSION} via ${CLAUDE_SCRIPTS_PYPI_INDEX}...${NC}"
if ! command -v python3 >/dev/null 2>&1; then
echo -e "${RED}Error: python3 is required to install claude-scripts${NC}"
return 1
fi
install_args=(python3 -m pip install --upgrade)
install_args+=(--index-url "$CLAUDE_SCRIPTS_PYPI_INDEX")
if [ -n "$CLAUDE_SCRIPTS_EXTRA_INDEX_URL" ]; then
install_args+=(--extra-index-url "$CLAUDE_SCRIPTS_EXTRA_INDEX_URL")
fi
install_args+=("claude-scripts==${CLAUDE_SCRIPTS_VERSION}")
if "${install_args[@]}"; then
if command -v claude-quality >/dev/null 2>&1; then
echo -e "${GREEN}✓ claude-quality installed successfully${NC}"
return 0
fi
echo -e "${RED}Error: claude-quality command still not found after installation${NC}"
return 1
fi
echo -e "${RED}Error: Failed to install claude-scripts from mirror${NC}"
return 1
}
install_claude_scripts_if_missing
HOOK_DIR="$(python3 - <<'PY'
from importlib import import_module
from pathlib import Path
try:
module = import_module("quality.hooks")
except ModuleNotFoundError:
raise SystemExit("")
print(Path(module.__file__).resolve().parent)
PY
)"
if [ -z "$HOOK_DIR" ]; then
echo -e "${RED}Error: Unable to locate quality.hooks package. Ensure claude-scripts is installed.${NC}"
exit 1
fi
HOOK_ENTRY="$HOOK_DIR/cli.py"
HOOK_TEMPLATE="$HOOK_DIR/claude-code-settings.json"
if [ ! -d "$HOOK_DIR" ]; then
echo -e "${RED}Error: Hook directory not found at $HOOK_DIR${NC}"
exit 1
fi
if [ ! -f "$HOOK_ENTRY" ]; then
echo -e "${RED}Error: Hook entry script not found at $HOOK_ENTRY${NC}"
exit 1
fi
if [ ! -f "$HOOK_TEMPLATE" ]; then
echo -e "${RED}Error: Hook settings template not found at $HOOK_TEMPLATE${NC}"
exit 1
fi
echo ""
echo -e "${YELLOW}Running Python installer to configure project-local hook...${NC}"
if python3 -m quality.hooks.install --project "$PROJECT_DIR" --create-alias; then
echo ""
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}✓ Project-local code quality hook successfully installed!${NC}"
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
else
echo -e "${RED}✗ Project-local installer reported an error. See output above.${NC}"
exit 1
fi
echo ""
echo "Quick start:"
echo -e " ${YELLOW}claude-quality strict${NC} # Enable strict quality enforcement"
echo -e " ${YELLOW}claude-quality moderate${NC} # Use moderate settings"
echo -e " ${YELLOW}claude-quality status${NC} # Inspect current environment settings"