Files
CxIDE/hooks/pre-commit
T
cx-git-agent c118996746 feat: CxIDE v1 — native macOS SwiftUI IDE with agentic AI assistant
- SwiftUI macOS app with C++17 code analysis engine (ObjC++ bridge)
- Agentic AI loop: LLM plans → tool calls → execution → feedback loop
- 15 agent tools: file ops, terminal, git, xcode build, code intel
- 7 persistent terminal tools with background session management
- Chat sidebar with agent step rendering and auto-apply
- NVIDIA NIM API integration (Llama 3.3 70B default)
- OpenAI tool_calls format with prompt-based fallback
- Code editor with syntax highlighting and multi-tab support
- File tree, console view, terminal view
- Git integration and workspace management
2026-04-21 16:05:52 -05:00

90 lines
3.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────────
# CxIDE — pre-commit hook
# Runs lint checks and validates C++ compilation before commit.
# Install: cp hooks/pre-commit .git/hooks/pre-commit
# ──────────────────────────────────────────────────────────────────
set -euo pipefail
ROOT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
RED='\033[0;31m'; GREEN='\033[0;32m'; CYAN='\033[0;36m'; YELLOW='\033[0;33m'; RESET='\033[0m'
echo ""
printf "${CYAN}${RESET} Running pre-commit checks...\n"
ERRORS=0
# ─── Check for debug leftovers ───────────────────────────────────
STAGED=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null || true)
if echo "$STAGED" | grep -qE '\.swift$'; then
# Check for leftover debug prints in staged Swift files
for f in $(echo "$STAGED" | grep -E '\.swift$'); do
[[ -f "$f" ]] || continue
if git diff --cached "$f" | grep -qE '^\+.*debugPrint\(|^\+.*NSLog\('; then
printf "${YELLOW}${RESET} %s: debug logging detected in staged changes\n" "$f"
fi
# Check for hardcoded secrets/tokens
if git diff --cached "$f" | grep -qiE '^\+.*(api_key|apikey|secret|token|password)\s*=\s*"[^"]{8,}"'; then
printf "${RED}${RESET} %s: possible hardcoded secret detected\n" "$f"
((ERRORS++))
fi
done
fi
# ─── Validate C++ syntax if changed ─────────────────────────────
if echo "$STAGED" | grep -qE '\.(cpp|hpp|mm|h)$'; then
printf "${CYAN}${RESET} C++ files changed — validating syntax...\n"
if [[ -f "$ROOT_DIR/Core/CodeEngine.cpp" ]]; then
if clang++ -std=c++17 -fsyntax-only "$ROOT_DIR/Core/CodeEngine.cpp" \
-I "$ROOT_DIR/Core" 2>&1; then
printf "${GREEN}${RESET} CodeEngine.cpp syntax OK\n"
else
printf "${RED}${RESET} CodeEngine.cpp has syntax errors\n"
((ERRORS++))
fi
fi
if [[ -f "$ROOT_DIR/Core/SwiftEngineWrapper.mm" ]]; then
if clang++ -std=c++17 -fobjc-arc -fsyntax-only \
"$ROOT_DIR/Core/SwiftEngineWrapper.mm" -I "$ROOT_DIR/Core" 2>&1; then
printf "${GREEN}${RESET} SwiftEngineWrapper.mm syntax OK\n"
else
printf "${RED}${RESET} SwiftEngineWrapper.mm has syntax errors\n"
((ERRORS++))
fi
fi
fi
# ─── Check for merge conflict markers ────────────────────────────
for f in $(echo "$STAGED" | head -50); do
[[ -f "$f" ]] || continue
if grep -qE '^(<<<<<<<|=======|>>>>>>>)' "$f" 2>/dev/null; then
printf "${RED}${RESET} %s: merge conflict markers found\n" "$f"
((ERRORS++))
fi
done
# ─── Check for large files ───────────────────────────────────────
for f in $(echo "$STAGED" | head -50); do
[[ -f "$f" ]] || continue
SIZE=$(wc -c < "$f" 2>/dev/null || echo 0)
if [[ "$SIZE" -gt 1048576 ]]; then
printf "${YELLOW}${RESET} %s: file exceeds 1MB (%s bytes)\n" "$f" "$SIZE"
fi
done
# ─── Result ──────────────────────────────────────────────────────
if [[ "$ERRORS" -gt 0 ]]; then
echo ""
printf "${RED}✗ Pre-commit failed with %d error(s). Fix issues and try again.${RESET}\n" "$ERRORS"
echo " Use 'git commit --no-verify' to bypass (not recommended)."
exit 1
fi
printf "${GREEN}${RESET} Pre-commit checks passed\n"