crg-dev-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -0
- package/assets/CLAUDE.md +48 -0
- package/assets/README.md +72 -0
- package/assets/check-crg.sh +34 -0
- package/assets/crg-cheatsheet.pdf +0 -0
- package/assets/setup-crg.ps1 +182 -0
- package/assets/setup-crg.sh +242 -0
- package/bin/cli.js +250 -0
- package/bin/tutorial.js +198 -0
- package/lib/analytics.js +250 -0
- package/lib/roi.js +250 -0
- package/package.json +38 -0
- package/server.js +502 -0
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# CRG Dev Kit
|
|
2
|
+
|
|
3
|
+
One command to set up [code-review-graph](https://github.com/tirth8205/code-review-graph) across any project, any stack. Track token savings and prove ROI to your team.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Open the dashboard
|
|
9
|
+
npx crg-dev-kit
|
|
10
|
+
|
|
11
|
+
# Copy setup scripts to your project
|
|
12
|
+
npx crg-dev-kit install
|
|
13
|
+
|
|
14
|
+
# Check installation status
|
|
15
|
+
npx crg-dev-kit status
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Commands
|
|
19
|
+
|
|
20
|
+
| Command | What it does |
|
|
21
|
+
|---------|-------------|
|
|
22
|
+
| `npx crg-dev-kit` | Opens the dashboard (default) |
|
|
23
|
+
| `npx crg-dev-kit install` | Copies setup scripts to current directory |
|
|
24
|
+
| `npx crg-dev-kit start --port 9000` | Dashboard on custom port |
|
|
25
|
+
| `npx crg-dev-kit start --no-open` | Dashboard without auto-opening browser |
|
|
26
|
+
| `npx crg-dev-kit status` | Check if CRG is installed in current project |
|
|
27
|
+
| `npx crg-dev-kit uninstall` | Remove CRG files from current project |
|
|
28
|
+
| `npx crg-dev-kit help` | Show all commands |
|
|
29
|
+
|
|
30
|
+
## What You Get
|
|
31
|
+
|
|
32
|
+
### Setup Scripts
|
|
33
|
+
- **Linux/macOS/WSL**: `bash setup-crg.sh --with-communities`
|
|
34
|
+
- **Windows**: `.\setup-crg.ps1 -WithCommunities`
|
|
35
|
+
- **Health check**: `bash check-crg.sh`
|
|
36
|
+
- **AI config**: `CLAUDE.md` (drop in project root)
|
|
37
|
+
- **Reference**: `crg-cheatsheet.pdf`
|
|
38
|
+
|
|
39
|
+
### Token Analytics Dashboard
|
|
40
|
+
|
|
41
|
+
The dashboard at `http://localhost:8742` shows:
|
|
42
|
+
- **Token savings %** — average reduction vs reading full source files
|
|
43
|
+
- **Cost estimates** — approximate $ savings at current LLM pricing
|
|
44
|
+
- **Per-project breakdown** — sessions, files reviewed, savings by project
|
|
45
|
+
- **Tool usage** — which CRG tools your team uses most
|
|
46
|
+
|
|
47
|
+
Data stored locally in `~/.crg-analytics/` — zero telemetry.
|
|
48
|
+
|
|
49
|
+
### REST API
|
|
50
|
+
|
|
51
|
+
The dashboard exposes endpoints for programmatic access:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Get all analytics
|
|
55
|
+
curl http://localhost:8742/api/analytics
|
|
56
|
+
|
|
57
|
+
# Download analytics report (Markdown)
|
|
58
|
+
curl http://localhost:8742/api/report
|
|
59
|
+
|
|
60
|
+
# Start a new session
|
|
61
|
+
curl -X POST http://localhost:8742/api/session \
|
|
62
|
+
-H 'Content-Type: application/json' \
|
|
63
|
+
-d '{"project": "/path/to/repo", "operation": "code_review"}'
|
|
64
|
+
|
|
65
|
+
# Log tool usage
|
|
66
|
+
curl -X POST http://localhost:8742/api/session/{sessionId} \
|
|
67
|
+
-H 'Content-Type: application/json' \
|
|
68
|
+
-d '{"tool": "detect_changes", "count": 1}'
|
|
69
|
+
|
|
70
|
+
# End session
|
|
71
|
+
curl -X POST http://localhost:8742/api/session/{sessionId} \
|
|
72
|
+
-H 'Content-Type: application/json' \
|
|
73
|
+
-d '{"filesReviewed": 12, "avgLinesPerFile": 150}'
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## For Team Leads
|
|
77
|
+
|
|
78
|
+
Share this with your team:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Everyone runs this in their project
|
|
82
|
+
npx crg-dev-kit install
|
|
83
|
+
bash setup-crg.sh --with-communities
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then open the dashboard to see team-wide analytics:
|
|
87
|
+
```bash
|
|
88
|
+
npx crg-dev-kit
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Token Savings
|
|
92
|
+
|
|
93
|
+
Based on benchmarks across 6 real repos, CRG tools reduce token usage by **8.2x on average**:
|
|
94
|
+
|
|
95
|
+
| Scenario | Without CRG | With CRG | Reduction |
|
|
96
|
+
|----------|:---:|:---:|:---:|
|
|
97
|
+
| 200-file project review | ~150k tokens | ~25k tokens | 6x |
|
|
98
|
+
| Incremental review | ~150k tokens | ~8k tokens | 19x |
|
|
99
|
+
| PR review | ~100k tokens | ~15k tokens | 6.7x |
|
|
100
|
+
|
|
101
|
+
The dashboard tracks your actual savings in real time.
|
|
102
|
+
|
|
103
|
+
## Requirements
|
|
104
|
+
|
|
105
|
+
- Node.js >= 16
|
|
106
|
+
- Python 3.10+ (for code-review-graph installation)
|
|
107
|
+
- pipx (recommended) or pip
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
package/assets/CLAUDE.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
## MCP Tools: code-review-graph
|
|
2
|
+
|
|
3
|
+
**Graph first, grep second.** Use CRG tools before Grep/Glob/Read — fewer tokens, structural context.
|
|
4
|
+
|
|
5
|
+
### Tools that work (no extras)
|
|
6
|
+
|
|
7
|
+
| Tool | When |
|
|
8
|
+
|------|------|
|
|
9
|
+
| `detect_changes` | Review changes — risk-scored, prioritized |
|
|
10
|
+
| `get_review_context` | Token-efficient source snippets for review |
|
|
11
|
+
| `get_impact_radius` | Blast radius of changed files (2-hop BFS) |
|
|
12
|
+
| `query_graph` | 8 patterns: callers_of, callees_of, imports_of, importers_of, children_of, tests_for, inheritors_of, file_summary |
|
|
13
|
+
| `semantic_search_nodes` | Find functions/classes by keyword |
|
|
14
|
+
| `refactor_tool` | mode=rename (preview+apply), mode=dead_code, mode=suggest |
|
|
15
|
+
| `apply_refactor` | Execute previewed rename (10min expiry) |
|
|
16
|
+
| `find_large_functions` | Functions/classes over N lines |
|
|
17
|
+
| `build_or_update_graph` | Build or refresh the graph |
|
|
18
|
+
| `list_graph_stats` | Node/edge counts, health |
|
|
19
|
+
| `cross_repo_search` | Search across registered repos |
|
|
20
|
+
|
|
21
|
+
### Tools that need [communities] extra
|
|
22
|
+
|
|
23
|
+
| Tool | Note |
|
|
24
|
+
|------|------|
|
|
25
|
+
| `get_architecture_overview` | **Returns empty without communities — no error** |
|
|
26
|
+
| `list_communities` | Use min_size=20 to avoid token overflow |
|
|
27
|
+
| `get_community` | include_members=true for deep dive |
|
|
28
|
+
| `generate_wiki` | Also needs Ollama running |
|
|
29
|
+
|
|
30
|
+
### Broken in v2.1.0 — skip these
|
|
31
|
+
|
|
32
|
+
- `get_affected_flows` — depends on flows (broken)
|
|
33
|
+
- `list_flows` / `get_flow` — trace_flows TypeError bug
|
|
34
|
+
|
|
35
|
+
### Workflow
|
|
36
|
+
|
|
37
|
+
1. Graph auto-updates via hooks on file save.
|
|
38
|
+
2. `detect_changes` for code review.
|
|
39
|
+
3. `query_graph pattern="tests_for"` for coverage check.
|
|
40
|
+
4. `get_impact_radius` before merging.
|
|
41
|
+
5. Fall back to Grep/Glob/Read only when graph doesn't cover it.
|
|
42
|
+
|
|
43
|
+
### Gotchas
|
|
44
|
+
|
|
45
|
+
- Communities return 0? Restart AI tool (MCP server caches old env).
|
|
46
|
+
- Over-clustered? `list_communities(min_size=20)`.
|
|
47
|
+
- Package name is `code-review-graph` NOT `crg`.
|
|
48
|
+
- Linux: use pipx, not pip. Extras via `pipx inject`.
|
package/assets/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# code-review-graph — Dev Kit
|
|
2
|
+
|
|
3
|
+
AI knowledge graph for your codebase. Gives your AI assistant (Claude Code, Cursor, etc.) structural understanding — callers, dependencies, test coverage, blast radius — without reading every file.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### Windows (PowerShell)
|
|
8
|
+
```powershell
|
|
9
|
+
cd your-project
|
|
10
|
+
.\setup-crg.ps1 # basic install
|
|
11
|
+
.\setup-crg.ps1 -WithCommunities # + architecture view
|
|
12
|
+
.\setup-crg.ps1 -WithAll # + semantic search (2GB download)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Linux / macOS / WSL
|
|
16
|
+
```bash
|
|
17
|
+
cd your-project
|
|
18
|
+
bash setup-crg.sh # basic install
|
|
19
|
+
bash setup-crg.sh --with-communities # + architecture view
|
|
20
|
+
bash setup-crg.sh --with-all # + semantic search (2GB download)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Health Check
|
|
24
|
+
```bash
|
|
25
|
+
bash check-crg.sh # run anytime to verify
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## What's in this kit
|
|
29
|
+
|
|
30
|
+
| File | Purpose |
|
|
31
|
+
|------|---------|
|
|
32
|
+
| `setup-crg.sh` | Setup script for Linux/macOS/WSL |
|
|
33
|
+
| `setup-crg.ps1` | Setup script for Windows |
|
|
34
|
+
| `check-crg.sh` | Health check (run anytime) |
|
|
35
|
+
| `CLAUDE.md` | Drop into project root — tells AI which tools to use |
|
|
36
|
+
| `crg-cheatsheet.pdf` | One-page visual reference |
|
|
37
|
+
| `.github/workflows/test-crg.yml` | CI workflow to validate on Windows + Ubuntu |
|
|
38
|
+
|
|
39
|
+
## What the setup script does
|
|
40
|
+
|
|
41
|
+
1. Detects OS and Python version
|
|
42
|
+
2. Installs `code-review-graph` (pip on Windows, pipx on Linux)
|
|
43
|
+
3. Configures MCP server for your AI tool
|
|
44
|
+
4. Builds the knowledge graph
|
|
45
|
+
5. Optionally installs extras (communities, embeddings)
|
|
46
|
+
6. Runs community detection workaround (v2.1.0 bug)
|
|
47
|
+
7. Adds `.code-review-graph/` to `.gitignore`
|
|
48
|
+
8. Runs health check
|
|
49
|
+
|
|
50
|
+
## What works after setup
|
|
51
|
+
|
|
52
|
+
**13 tools work immediately** — code review, search, impact analysis, refactoring.
|
|
53
|
+
|
|
54
|
+
**5 tools need `--with-communities`** — architecture overview, module clusters.
|
|
55
|
+
|
|
56
|
+
**3 tools are broken in v2.1.0** — flow analysis (trace_flows TypeError). Skip these.
|
|
57
|
+
|
|
58
|
+
## Known Issues (v2.1.0)
|
|
59
|
+
|
|
60
|
+
| Issue | Impact | Workaround |
|
|
61
|
+
|-------|--------|------------|
|
|
62
|
+
| `architecture_overview` returns empty | Misleading — no error | Install communities extra |
|
|
63
|
+
| `build` doesn't trigger Leiden | Communities stay 0 | Setup script handles this automatically |
|
|
64
|
+
| `trace_flows` TypeError | Flows completely broken | No fix — wait for v2.2+ |
|
|
65
|
+
| Over-clustering (400+ for 500 files) | Token overflow | Use `min_size=20` param |
|
|
66
|
+
| `crg` is wrong package name | Installs different package | Always use `code-review-graph` |
|
|
67
|
+
| PEP 668 on Linux | pip blocked | Setup script auto-detects, uses pipx |
|
|
68
|
+
| MCP server caches old env | Extras don't activate | Restart AI tool after installing extras |
|
|
69
|
+
|
|
70
|
+
## For CI
|
|
71
|
+
|
|
72
|
+
Copy `.github/workflows/test-crg.yml` into your repo. Tests install + build + communities on both Windows and Ubuntu. Trigger manually from Actions tab.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Quick health check — run anytime to verify CRG is working
|
|
3
|
+
set -uo pipefail
|
|
4
|
+
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
|
|
5
|
+
|
|
6
|
+
echo -e "${CYAN}code-review-graph health check${NC}"
|
|
7
|
+
echo "──────────────────────────────"
|
|
8
|
+
|
|
9
|
+
P=0; T=0
|
|
10
|
+
check() {
|
|
11
|
+
T=$((T+1))
|
|
12
|
+
if eval "$2" &>/dev/null; then echo -e "${GREEN}✓${NC} $1"; P=$((P+1))
|
|
13
|
+
else echo -e "${RED}✗${NC} $1"; fi
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
PYTHON=$(command -v python3 || command -v python)
|
|
17
|
+
|
|
18
|
+
check "Python 3.10+" "$PYTHON -c 'import sys; assert sys.version_info >= (3,10)'"
|
|
19
|
+
check "CRG installed" "command -v code-review-graph"
|
|
20
|
+
check "Graph DB exists" "test -f .code-review-graph/graph.db"
|
|
21
|
+
check "Nodes > 0" "$PYTHON -c \"import sqlite3; assert sqlite3.connect('.code-review-graph/graph.db').execute('SELECT COUNT(*) FROM nodes').fetchone()[0] > 0\""
|
|
22
|
+
check "Edges > 0" "$PYTHON -c \"import sqlite3; assert sqlite3.connect('.code-review-graph/graph.db').execute('SELECT COUNT(*) FROM edges').fetchone()[0] > 0\""
|
|
23
|
+
check "Communities > 0" "$PYTHON -c \"import sqlite3; assert sqlite3.connect('.code-review-graph/graph.db').execute('SELECT COUNT(*) FROM communities').fetchone()[0] > 0\"" || true
|
|
24
|
+
check "igraph importable" "$PYTHON -c 'import igraph'" || true
|
|
25
|
+
check "leidenalg importable" "$PYTHON -c 'import leidenalg'" || true
|
|
26
|
+
|
|
27
|
+
echo "──────────────────────────────"
|
|
28
|
+
echo -e "Result: ${GREEN}$P${NC}/$T passed"
|
|
29
|
+
|
|
30
|
+
# Show graph stats
|
|
31
|
+
if command -v code-review-graph &>/dev/null && [ -f ".code-review-graph/graph.db" ]; then
|
|
32
|
+
echo ""
|
|
33
|
+
code-review-graph status 2>/dev/null
|
|
34
|
+
fi
|
|
Binary file
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# ─────────────────────────────────────────────────────────────
|
|
2
|
+
# code-review-graph — Automated Setup Script (Windows)
|
|
3
|
+
# Works on: Windows 10/11, PowerShell 5.1+
|
|
4
|
+
# Usage: .\setup-crg.ps1 [-WithCommunities] [-WithEmbeddings] [-WithAll]
|
|
5
|
+
# ─────────────────────────────────────────────────────────────
|
|
6
|
+
param(
|
|
7
|
+
[switch]$WithCommunities,
|
|
8
|
+
[switch]$WithEmbeddings,
|
|
9
|
+
[switch]$WithAll
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
$ErrorActionPreference = "Stop"
|
|
13
|
+
|
|
14
|
+
if ($WithAll) { $WithCommunities = $true; $WithEmbeddings = $true }
|
|
15
|
+
|
|
16
|
+
function Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Cyan }
|
|
17
|
+
function Ok($msg) { Write-Host "[OK] $msg" -ForegroundColor Green }
|
|
18
|
+
function Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow }
|
|
19
|
+
function Fail($msg) { Write-Host "[FAIL] $msg" -ForegroundColor Red; exit 1 }
|
|
20
|
+
|
|
21
|
+
# ── Step 1: Check Python ──
|
|
22
|
+
Info "Checking Python..."
|
|
23
|
+
$python = $null
|
|
24
|
+
foreach ($cmd in @("python", "python3", "py")) {
|
|
25
|
+
try {
|
|
26
|
+
$ver = & $cmd -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>$null
|
|
27
|
+
$major = & $cmd -c "import sys; print(sys.version_info.major)" 2>$null
|
|
28
|
+
$minor = & $cmd -c "import sys; print(sys.version_info.minor)" 2>$null
|
|
29
|
+
if ([int]$major -ge 3 -and [int]$minor -ge 10) {
|
|
30
|
+
$python = $cmd
|
|
31
|
+
Ok "Python $ver found ($cmd)"
|
|
32
|
+
break
|
|
33
|
+
}
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
if (-not $python) { Fail "Python 3.10+ required. Install from https://python.org" }
|
|
37
|
+
|
|
38
|
+
# ── Step 2: Install ──
|
|
39
|
+
$installed = $false
|
|
40
|
+
try { $null = & code-review-graph --version 2>$null; $installed = $true } catch {}
|
|
41
|
+
|
|
42
|
+
if ($installed) {
|
|
43
|
+
$v = & code-review-graph --version 2>$null
|
|
44
|
+
Ok "code-review-graph already installed ($v)"
|
|
45
|
+
} else {
|
|
46
|
+
Info "Installing code-review-graph..."
|
|
47
|
+
& $python -m pip install code-review-graph
|
|
48
|
+
if ($LASTEXITCODE -ne 0) { Fail "pip install failed. Try: $python -m pip install --user code-review-graph" }
|
|
49
|
+
Ok "Installed via pip"
|
|
50
|
+
|
|
51
|
+
# Verify on PATH
|
|
52
|
+
try { $null = & code-review-graph --version 2>$null }
|
|
53
|
+
catch {
|
|
54
|
+
Warn "code-review-graph not on PATH. Adding Python Scripts to PATH..."
|
|
55
|
+
$scriptsDir = & $python -c "import sysconfig; print(sysconfig.get_path('scripts'))" 2>$null
|
|
56
|
+
if ($scriptsDir) {
|
|
57
|
+
$env:PATH = "$scriptsDir;$env:PATH"
|
|
58
|
+
Warn "Added $scriptsDir to PATH for this session. Add permanently via System Settings."
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# ── Step 3: Configure MCP ──
|
|
64
|
+
Info "Configuring MCP server..."
|
|
65
|
+
try {
|
|
66
|
+
& code-review-graph install --platform claude-code 2>$null
|
|
67
|
+
Ok "MCP server configured"
|
|
68
|
+
} catch {
|
|
69
|
+
Warn "Auto-configure failed. Run manually: code-review-graph install"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# ── Step 4: Build graph ──
|
|
73
|
+
if (-not (Test-Path ".code-review-graph/graph.db")) {
|
|
74
|
+
Info "Building knowledge graph (first build)..."
|
|
75
|
+
& code-review-graph build
|
|
76
|
+
} else {
|
|
77
|
+
Info "Graph exists. Incremental update..."
|
|
78
|
+
try { & code-review-graph update --base HEAD~5 2>$null }
|
|
79
|
+
catch { & code-review-graph build }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Write-Host ""
|
|
83
|
+
& code-review-graph status
|
|
84
|
+
Write-Host ""
|
|
85
|
+
|
|
86
|
+
# ── Step 5: Extras ──
|
|
87
|
+
if ($WithCommunities) {
|
|
88
|
+
Info "Installing communities extra..."
|
|
89
|
+
& $python -m pip install "code-review-graph[communities]"
|
|
90
|
+
Ok "Communities deps installed"
|
|
91
|
+
|
|
92
|
+
Info "Rebuilding graph..."
|
|
93
|
+
& code-review-graph build
|
|
94
|
+
|
|
95
|
+
Info "Running community detection (v2.1.0 workaround)..."
|
|
96
|
+
& $python -c @"
|
|
97
|
+
import sys, glob
|
|
98
|
+
try:
|
|
99
|
+
from code_review_graph.graph import GraphStore
|
|
100
|
+
from code_review_graph.communities import detect_communities, store_communities
|
|
101
|
+
dbs = glob.glob('.code-review-graph/graph.db')
|
|
102
|
+
if not dbs:
|
|
103
|
+
print('No graph DB found')
|
|
104
|
+
sys.exit(0)
|
|
105
|
+
gs = GraphStore(dbs[0])
|
|
106
|
+
comms = detect_communities(gs)
|
|
107
|
+
store_communities(gs, comms)
|
|
108
|
+
print(f'Communities detected: {len(comms)}')
|
|
109
|
+
except ImportError:
|
|
110
|
+
print('igraph/leidenalg not importable')
|
|
111
|
+
except Exception as e:
|
|
112
|
+
print(f'Community detection failed: {e}')
|
|
113
|
+
"@
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if ($WithEmbeddings) {
|
|
117
|
+
Warn "Embeddings require PyTorch (~2GB download). Takes 5-10 minutes."
|
|
118
|
+
$reply = Read-Host "Continue? [y/N]"
|
|
119
|
+
if ($reply -eq 'y' -or $reply -eq 'Y') {
|
|
120
|
+
Info "Installing embeddings..."
|
|
121
|
+
& $python -m pip install "code-review-graph[embeddings]"
|
|
122
|
+
Ok "Embeddings installed. Use embed_graph MCP tool to compute vectors."
|
|
123
|
+
} else {
|
|
124
|
+
Info "Skipped embeddings."
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
# ── Step 6: .gitignore ──
|
|
129
|
+
if (Test-Path ".gitignore") {
|
|
130
|
+
$content = Get-Content ".gitignore" -Raw -ErrorAction SilentlyContinue
|
|
131
|
+
if ($content -notmatch "code-review-graph") {
|
|
132
|
+
Add-Content ".gitignore" "`n# code-review-graph`n.code-review-graph/"
|
|
133
|
+
Ok "Added .code-review-graph/ to .gitignore"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# ── Step 7: Health check ──
|
|
138
|
+
Write-Host ""
|
|
139
|
+
Write-Host "═══════════════════════════════════════" -ForegroundColor Cyan
|
|
140
|
+
Write-Host " Health Check" -ForegroundColor Cyan
|
|
141
|
+
Write-Host "═══════════════════════════════════════" -ForegroundColor Cyan
|
|
142
|
+
|
|
143
|
+
$pass = 0; $total = 0
|
|
144
|
+
|
|
145
|
+
function Check($name, $test) {
|
|
146
|
+
$script:total++
|
|
147
|
+
try {
|
|
148
|
+
$result = & $python -c $test 2>$null
|
|
149
|
+
if ($LASTEXITCODE -eq 0) { Ok $name; $script:pass++ }
|
|
150
|
+
else { Warn "$name - FAILED" }
|
|
151
|
+
} catch { Warn "$name - FAILED" }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
$total++
|
|
155
|
+
try { $null = & code-review-graph --version 2>$null; Ok "code-review-graph on PATH"; $pass++ }
|
|
156
|
+
catch { Warn "code-review-graph on PATH - FAILED" }
|
|
157
|
+
|
|
158
|
+
$total++
|
|
159
|
+
if (Test-Path ".code-review-graph/graph.db") { Ok "Graph DB exists"; $pass++ }
|
|
160
|
+
else { Warn "Graph DB exists - FAILED" }
|
|
161
|
+
|
|
162
|
+
Check "Nodes > 0" "import sqlite3; db=sqlite3.connect('.code-review-graph/graph.db'); n=db.execute('SELECT COUNT(*) FROM nodes').fetchone()[0]; assert n > 0"
|
|
163
|
+
Check "Edges > 0" "import sqlite3; db=sqlite3.connect('.code-review-graph/graph.db'); n=db.execute('SELECT COUNT(*) FROM edges').fetchone()[0]; assert n > 0"
|
|
164
|
+
|
|
165
|
+
if ($WithCommunities) {
|
|
166
|
+
Check "Communities > 0" "import sqlite3; db=sqlite3.connect('.code-review-graph/graph.db'); n=db.execute('SELECT COUNT(*) FROM communities').fetchone()[0]; assert n > 0"
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
Write-Host ""
|
|
170
|
+
Write-Host "Passed: $pass/$total" -ForegroundColor Green
|
|
171
|
+
|
|
172
|
+
if ($pass -eq $total) {
|
|
173
|
+
Write-Host ""
|
|
174
|
+
Write-Host "Setup complete. Your AI assistant can now use the knowledge graph." -ForegroundColor Green
|
|
175
|
+
Write-Host ""
|
|
176
|
+
Write-Host 'Quick test - ask your AI:'
|
|
177
|
+
Write-Host ' "Use detect_changes to review my recent changes"'
|
|
178
|
+
Write-Host ' "Use query_graph to find callers of <function_name>"'
|
|
179
|
+
} else {
|
|
180
|
+
Write-Host ""
|
|
181
|
+
Warn "Some checks failed. See warnings above."
|
|
182
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# ─────────────────────────────────────────────────────────────
|
|
3
|
+
# code-review-graph — Automated Setup Script
|
|
4
|
+
# Works on: Ubuntu/Debian, macOS, WSL2
|
|
5
|
+
# Usage: bash setup-crg.sh [--with-communities] [--with-embeddings] [--with-all]
|
|
6
|
+
# ─────────────────────────────────────────────────────────────
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
|
|
9
|
+
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
|
|
10
|
+
info() { echo -e "${CYAN}[INFO]${NC} $1"; }
|
|
11
|
+
ok() { echo -e "${GREEN}[OK]${NC} $1"; }
|
|
12
|
+
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
|
13
|
+
fail() { echo -e "${RED}[FAIL]${NC} $1"; exit 1; }
|
|
14
|
+
|
|
15
|
+
INSTALL_COMMUNITIES=false
|
|
16
|
+
INSTALL_EMBEDDINGS=false
|
|
17
|
+
for arg in "$@"; do
|
|
18
|
+
case $arg in
|
|
19
|
+
--with-communities) INSTALL_COMMUNITIES=true ;;
|
|
20
|
+
--with-embeddings) INSTALL_EMBEDDINGS=true ;;
|
|
21
|
+
--with-all) INSTALL_COMMUNITIES=true; INSTALL_EMBEDDINGS=true ;;
|
|
22
|
+
esac
|
|
23
|
+
done
|
|
24
|
+
|
|
25
|
+
# ── Step 1: Check Python ──
|
|
26
|
+
info "Checking Python..."
|
|
27
|
+
PYTHON=""
|
|
28
|
+
for cmd in python3 python; do
|
|
29
|
+
if command -v "$cmd" &>/dev/null; then
|
|
30
|
+
ver=$("$cmd" -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>/dev/null)
|
|
31
|
+
major=$("$cmd" -c "import sys; print(sys.version_info.major)" 2>/dev/null)
|
|
32
|
+
minor=$("$cmd" -c "import sys; print(sys.version_info.minor)" 2>/dev/null)
|
|
33
|
+
if [ "$major" -ge 3 ] && [ "$minor" -ge 10 ]; then
|
|
34
|
+
PYTHON="$cmd"
|
|
35
|
+
ok "Python $ver found ($cmd)"
|
|
36
|
+
break
|
|
37
|
+
fi
|
|
38
|
+
fi
|
|
39
|
+
done
|
|
40
|
+
[ -z "$PYTHON" ] && fail "Python 3.10+ required. Install from https://python.org"
|
|
41
|
+
|
|
42
|
+
# ── Step 2: Detect install method ──
|
|
43
|
+
USE_PIPX=false
|
|
44
|
+
if command -v code-review-graph &>/dev/null; then
|
|
45
|
+
ok "code-review-graph already installed ($(code-review-graph --version 2>/dev/null || echo 'unknown version'))"
|
|
46
|
+
# Detect if installed via pipx
|
|
47
|
+
if pipx list 2>/dev/null | grep -q "code-review-graph"; then
|
|
48
|
+
USE_PIPX=true
|
|
49
|
+
info "Installed via pipx"
|
|
50
|
+
else
|
|
51
|
+
info "Installed via pip"
|
|
52
|
+
fi
|
|
53
|
+
else
|
|
54
|
+
info "Installing code-review-graph..."
|
|
55
|
+
|
|
56
|
+
# Try pip first
|
|
57
|
+
if $PYTHON -m pip install code-review-graph 2>/dev/null; then
|
|
58
|
+
ok "Installed via pip"
|
|
59
|
+
else
|
|
60
|
+
# pip blocked (PEP 668) — use pipx
|
|
61
|
+
warn "pip blocked by system (PEP 668). Trying pipx..."
|
|
62
|
+
if ! command -v pipx &>/dev/null; then
|
|
63
|
+
info "Installing pipx..."
|
|
64
|
+
if command -v apt &>/dev/null; then
|
|
65
|
+
sudo apt install -y pipx 2>/dev/null || $PYTHON -m pip install --user pipx
|
|
66
|
+
elif command -v brew &>/dev/null; then
|
|
67
|
+
brew install pipx
|
|
68
|
+
else
|
|
69
|
+
$PYTHON -m pip install --user pipx
|
|
70
|
+
fi
|
|
71
|
+
pipx ensurepath 2>/dev/null || true
|
|
72
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
73
|
+
fi
|
|
74
|
+
pipx install code-review-graph
|
|
75
|
+
USE_PIPX=true
|
|
76
|
+
ok "Installed via pipx"
|
|
77
|
+
fi
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
# Verify on PATH
|
|
81
|
+
if ! command -v code-review-graph &>/dev/null; then
|
|
82
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
83
|
+
if ! command -v code-review-graph &>/dev/null; then
|
|
84
|
+
fail "code-review-graph not found on PATH. Run: pipx ensurepath && source ~/.bashrc"
|
|
85
|
+
fi
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
# ── Step 3: Configure MCP server ──
|
|
89
|
+
info "Configuring MCP server..."
|
|
90
|
+
# Detect platform
|
|
91
|
+
PLATFORM="claude-code"
|
|
92
|
+
if [ -d "$HOME/.cursor" ] || [ -d "$HOME/Library/Application Support/Cursor" ]; then
|
|
93
|
+
PLATFORM="all"
|
|
94
|
+
fi
|
|
95
|
+
code-review-graph install --platform "$PLATFORM" --no-hooks 2>/dev/null || \
|
|
96
|
+
code-review-graph install --platform claude-code 2>/dev/null || \
|
|
97
|
+
warn "Could not auto-configure MCP. Run manually: code-review-graph install"
|
|
98
|
+
ok "MCP server configured for $PLATFORM"
|
|
99
|
+
|
|
100
|
+
# ── Step 4: Build graph ──
|
|
101
|
+
if [ ! -f ".code-review-graph/graph.db" ]; then
|
|
102
|
+
info "Building knowledge graph (first build)..."
|
|
103
|
+
code-review-graph build
|
|
104
|
+
else
|
|
105
|
+
info "Graph exists. Running incremental update..."
|
|
106
|
+
code-review-graph update --base HEAD~5 2>/dev/null || code-review-graph build
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
# Show stats
|
|
110
|
+
echo ""
|
|
111
|
+
code-review-graph status
|
|
112
|
+
echo ""
|
|
113
|
+
|
|
114
|
+
# ── Step 5: Install extras ──
|
|
115
|
+
install_extra() {
|
|
116
|
+
local name="$1"
|
|
117
|
+
shift
|
|
118
|
+
local deps=("$@")
|
|
119
|
+
|
|
120
|
+
info "Installing $name..."
|
|
121
|
+
if $USE_PIPX; then
|
|
122
|
+
pipx inject code-review-graph "${deps[@]}"
|
|
123
|
+
else
|
|
124
|
+
$PYTHON -m pip install "code-review-graph[$name]" 2>/dev/null || \
|
|
125
|
+
$PYTHON -m pip install "${deps[@]}"
|
|
126
|
+
fi
|
|
127
|
+
ok "$name installed"
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if $INSTALL_COMMUNITIES; then
|
|
131
|
+
install_extra "communities" igraph leidenalg
|
|
132
|
+
|
|
133
|
+
info "Rebuilding graph with community detection..."
|
|
134
|
+
code-review-graph build
|
|
135
|
+
|
|
136
|
+
# Workaround: v2.1.0 may not auto-trigger Leiden
|
|
137
|
+
info "Running community detection (v2.1.0 workaround)..."
|
|
138
|
+
|
|
139
|
+
# Detect the right Python — pipx venv or system
|
|
140
|
+
CRG_PYTHON="$PYTHON"
|
|
141
|
+
if $USE_PIPX; then
|
|
142
|
+
PIPX_PYTHON="$HOME/.local/share/pipx/venvs/code-review-graph/bin/python"
|
|
143
|
+
if [ -f "$PIPX_PYTHON" ]; then
|
|
144
|
+
CRG_PYTHON="$PIPX_PYTHON"
|
|
145
|
+
fi
|
|
146
|
+
fi
|
|
147
|
+
|
|
148
|
+
$CRG_PYTHON -c "
|
|
149
|
+
import sys, glob
|
|
150
|
+
try:
|
|
151
|
+
from code_review_graph.graph import GraphStore
|
|
152
|
+
from code_review_graph.communities import detect_communities, store_communities
|
|
153
|
+
dbs = glob.glob('.code-review-graph/graph.db')
|
|
154
|
+
if not dbs:
|
|
155
|
+
print('No graph DB found — skipping community detection')
|
|
156
|
+
sys.exit(0)
|
|
157
|
+
gs = GraphStore(dbs[0])
|
|
158
|
+
comms = detect_communities(gs)
|
|
159
|
+
store_communities(gs, comms)
|
|
160
|
+
print(f'Communities detected: {len(comms)}')
|
|
161
|
+
except ImportError as e:
|
|
162
|
+
print(f'Import failed: {e}')
|
|
163
|
+
print('Try restarting your AI tool, then run: code-review-graph build')
|
|
164
|
+
except Exception as e:
|
|
165
|
+
print(f'Community detection failed: {e}')
|
|
166
|
+
" 2>/dev/null || warn "Community detection workaround failed. Restart AI tool + rebuild."
|
|
167
|
+
fi
|
|
168
|
+
|
|
169
|
+
if $INSTALL_EMBEDDINGS; then
|
|
170
|
+
warn "Embeddings require PyTorch (~2GB download). This will take 5-10 minutes."
|
|
171
|
+
read -p "Continue? [y/N] " -n 1 -r
|
|
172
|
+
echo
|
|
173
|
+
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
174
|
+
install_extra "embeddings" sentence-transformers
|
|
175
|
+
ok "Embeddings installed. Run embed_graph MCP tool to compute vectors."
|
|
176
|
+
else
|
|
177
|
+
info "Skipped embeddings."
|
|
178
|
+
fi
|
|
179
|
+
fi
|
|
180
|
+
|
|
181
|
+
# ── Step 6: Add .gitignore entry ──
|
|
182
|
+
if [ -f ".gitignore" ]; then
|
|
183
|
+
if ! grep -q "code-review-graph" .gitignore 2>/dev/null; then
|
|
184
|
+
echo -e "\n# code-review-graph\n.code-review-graph/" >> .gitignore
|
|
185
|
+
ok "Added .code-review-graph/ to .gitignore"
|
|
186
|
+
fi
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
# ── Step 7: Health check ──
|
|
190
|
+
echo ""
|
|
191
|
+
echo -e "${CYAN}═══════════════════════════════════════${NC}"
|
|
192
|
+
echo -e "${CYAN} Health Check${NC}"
|
|
193
|
+
echo -e "${CYAN}═══════════════════════════════════════${NC}"
|
|
194
|
+
|
|
195
|
+
PASS=0; TOTAL=0
|
|
196
|
+
|
|
197
|
+
check() {
|
|
198
|
+
TOTAL=$((TOTAL + 1))
|
|
199
|
+
if eval "$2" &>/dev/null; then
|
|
200
|
+
ok "$1"
|
|
201
|
+
PASS=$((PASS + 1))
|
|
202
|
+
else
|
|
203
|
+
warn "$1 — FAILED"
|
|
204
|
+
fi
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
check "code-review-graph on PATH" "command -v code-review-graph"
|
|
208
|
+
check "Graph DB exists" "test -f .code-review-graph/graph.db"
|
|
209
|
+
check "Nodes > 0" "$PYTHON -c \"
|
|
210
|
+
import sqlite3; db=sqlite3.connect('.code-review-graph/graph.db')
|
|
211
|
+
n=db.execute('SELECT COUNT(*) FROM nodes').fetchone()[0]
|
|
212
|
+
assert n > 0, f'nodes={n}'
|
|
213
|
+
\""
|
|
214
|
+
check "Edges > 0" "$PYTHON -c \"
|
|
215
|
+
import sqlite3; db=sqlite3.connect('.code-review-graph/graph.db')
|
|
216
|
+
n=db.execute('SELECT COUNT(*) FROM edges').fetchone()[0]
|
|
217
|
+
assert n > 0, f'edges={n}'
|
|
218
|
+
\""
|
|
219
|
+
|
|
220
|
+
if $INSTALL_COMMUNITIES; then
|
|
221
|
+
check "Communities > 0" "$PYTHON -c \"
|
|
222
|
+
import sqlite3; db=sqlite3.connect('.code-review-graph/graph.db')
|
|
223
|
+
n=db.execute('SELECT COUNT(*) FROM communities').fetchone()[0]
|
|
224
|
+
assert n > 0, f'communities={n}'
|
|
225
|
+
\""
|
|
226
|
+
fi
|
|
227
|
+
|
|
228
|
+
echo ""
|
|
229
|
+
echo -e "${GREEN}Passed: $PASS/$TOTAL${NC}"
|
|
230
|
+
|
|
231
|
+
if [ "$PASS" -eq "$TOTAL" ]; then
|
|
232
|
+
echo ""
|
|
233
|
+
echo -e "${GREEN}Setup complete. Your AI assistant can now use the knowledge graph.${NC}"
|
|
234
|
+
echo ""
|
|
235
|
+
echo "Quick test — ask your AI:"
|
|
236
|
+
echo ' "Use detect_changes to review my recent changes"'
|
|
237
|
+
echo ' "Use query_graph to find callers of <function_name>"'
|
|
238
|
+
echo ' "Use find_large_functions with min_lines=100"'
|
|
239
|
+
else
|
|
240
|
+
echo ""
|
|
241
|
+
warn "Some checks failed. See warnings above."
|
|
242
|
+
fi
|