From 4743fd23cdc902558eba452a3ede9ab83fb21bd4 Mon Sep 17 00:00:00 2001 From: reizha Date: Fri, 8 May 2026 20:18:03 +0700 Subject: [PATCH 1/2] feat: add npm wrapper and postinstall setup --- .gitignore | 1 + bin/cli.js | 76 ++++++++++++++++++++++++++++++++++++++ package.json | 46 +++++++++++++++++++++++ scripts/npm-postinstall.js | 72 ++++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) create mode 100755 bin/cli.js create mode 100644 package.json create mode 100644 scripts/npm-postinstall.js diff --git a/.gitignore b/.gitignore index 53279054..81e7ad23 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ dist/ build/ *.egg .eggs/ +.gemini/ # Virtual environments .venv/ diff --git a/bin/cli.js b/bin/cli.js new file mode 100755 index 00000000..c2630105 --- /dev/null +++ b/bin/cli.js @@ -0,0 +1,76 @@ +#!/usr/bin/env node + +/** + * Node.js wrapper for code-review-graph Python CLI. + * This forwards all commands and arguments to the underlying Python implementation. + */ + +const { spawn } = require('child_process'); +const path = require('path'); +const fs = require('fs'); + +function findPythonCLI() { + // 1. Check if the command is already in PATH (e.g. installed via global pip) + // We don't use 'which' here to avoid platform issues, instead we try to spawn it. + + // 2. Check for a local virtualenv in the package directory + // This is where postinstall might have installed it + const packageRoot = path.join(__dirname, '..'); + const venvBin = process.platform === 'win32' + ? path.join(packageRoot, '.venv', 'Scripts', 'code-review-graph.exe') + : path.join(packageRoot, '.venv', 'bin', 'code-review-graph'); + + if (fs.existsSync(venvBin)) { + return venvBin; + } + + // 3. Fallback to just 'code-review-graph' assuming it's in PATH + return 'code-review-graph'; +} + +const cliPath = findPythonCLI(); +const args = process.argv.slice(2); + +// Handle the case where the CLI isn't found at all +// We'll try to run it; if it fails with ENOENT, we'll give a helpful message. + +const child = spawn(cliPath, args, { + stdio: 'inherit', + env: { + ...process.env, + // Ensure Python doesn't buffer output, which is critical for MCP server mode + PYTHONUNBUFFERED: '1' + } +}); + +child.on('error', (err) => { + if (err.code === 'ENOENT') { + console.error('\x1b[31mError: code-review-graph Python core not found.\x1b[0m'); + console.error('Please ensure you have Python 3.10+ installed.'); + console.error('Try running: npm install (to trigger postinstall setup)'); + console.error('\nIf that fails, you can install the core manually via:'); + console.error(' pip install code-review-graph'); + process.exit(1); + } else { + console.error('Error spawning code-review-graph:', err.message); + process.exit(1); + } +}); + +child.on('exit', (code, signal) => { + if (code !== null) { + process.exit(code); + } else if (signal) { + process.kill(process.pid, signal); + } +}); + +// Forward signals to the child process +const signals = ['SIGINT', 'SIGTERM', 'SIGHUP']; +signals.forEach(sig => { + process.on(sig, () => { + if (child.connected) { + child.kill(sig); + } + }); +}); diff --git a/package.json b/package.json new file mode 100644 index 00000000..d91a790d --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "code-review-graph", + "version": "2.3.3", + "description": "Persistent incremental knowledge graph for token-efficient, context-aware code reviews. Node.js wrapper for the Python CLI.", + "main": "bin/cli.js", + "bin": { + "code-review-graph": "bin/cli.js", + "crg": "bin/cli.js" + }, + "scripts": { + "postinstall": "node scripts/npm-postinstall.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/tirth8205/code-review-graph.git" + }, + "keywords": [ + "code-review", + "knowledge-graph", + "tree-sitter", + "mcp", + "ai-agent", + "static-analysis" + ], + "author": "Tirth", + "license": "MIT", + "bugs": { + "url": "https://github.com/tirth8205/code-review-graph/issues" + }, + "homepage": "https://github.com/tirth8205/code-review-graph#readme", + "engines": { + "node": ">=16.0.0" + }, + "files": [ + "bin", + "scripts", + "code_review_graph", + "pyproject.toml", + "README.md", + "LICENSE", + "uv.lock", + "skills", + "hooks" + ] +} diff --git a/scripts/npm-postinstall.js b/scripts/npm-postinstall.js new file mode 100644 index 00000000..e7d8b9ba --- /dev/null +++ b/scripts/npm-postinstall.js @@ -0,0 +1,72 @@ +/** + * NPM Post-install script for code-review-graph. + * Sets up the Python environment and installs the core package. + */ + +const { execSync, spawnSync } = require('child_process'); +const path = require('path'); +const fs = require('fs'); + +const packageRoot = path.join(__dirname, '..'); +const venvDir = path.join(packageRoot, '.venv'); + +console.log('\x1b[36mSetting up code-review-graph Python core...\x1b[0m'); + +function run(cmd, args, options = {}) { + const result = spawnSync(cmd, args, { + stdio: 'inherit', + shell: true, + cwd: packageRoot, + ...options + }); + if (result.status !== 0) { + throw new Error(`Command failed: ${cmd} ${args.join(' ')}`); + } +} + +try { + // 1. Check for Python 3.10+ + try { + const pyVersion = execSync('python3 --version').toString().trim(); + console.log(`Found ${pyVersion}`); + } catch (e) { + console.error('\x1b[31mError: Python 3 not found.\x1b[0m'); + console.error('code-review-graph requires Python 3.10 or higher.'); + process.exit(1); + } + + // 2. Check for uv (faster) or fallback to venv + pip + let hasUv = false; + try { + execSync('uv --version'); + hasUv = true; + console.log('Found uv, using it for faster setup...'); + } catch (e) {} + + if (hasUv) { + run('uv', ['sync', '--no-dev']); + } else { + // Standard venv + pip + if (!fs.existsSync(venvDir)) { + console.log('Creating virtual environment...'); + run('python3', ['-m', 'venv', '.venv']); + } + + const pipPath = process.platform === 'win32' + ? path.join(venvDir, 'Scripts', 'pip') + : path.join(venvDir, 'bin', 'pip'); + + console.log('Installing Python dependencies...'); + run(pipPath, ['install', '--upgrade', 'pip']); + run(pipPath, ['install', '.']); + } + + console.log('\x1b[32m\nSuccessfully set up code-review-graph!\x1b[0m'); + console.log('You can now run it using: code-review-graph --help'); + +} catch (error) { + console.error('\x1b[31m\nFailed to set up Python environment.\x1b[0m'); + console.error(error.message); + console.error('\nYou can still use the tool if you install it manually via pip:'); + console.error(' pip install code-review-graph'); +} From d4526df575e1a917b4fd16800383ad4a9c227fab Mon Sep 17 00:00:00 2001 From: reizha Date: Fri, 8 May 2026 20:21:35 +0700 Subject: [PATCH 2/2] fix: fix md file to support npm --- README.hi-IN.md | 7 ++++++- README.ja-JP.md | 7 ++++++- README.ko-KR.md | 7 ++++++- README.md | 7 ++++++- README.zh-CN.md | 7 ++++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.hi-IN.md b/README.hi-IN.md index ab40ade0..5a6f8060 100644 --- a/README.hi-IN.md +++ b/README.hi-IN.md @@ -37,7 +37,12 @@ AI कोडिंग टूल्स हर टास्क पर आपका ## त्वरित शुरुआत ```bash +# Python का उपयोग करके (अनुशंसित) pip install code-review-graph # या: pipx install code-review-graph + +# Node.js का उपयोग करके +npm install -g code-review-graph + code-review-graph install # सभी समर्थित प्लेटफ़ॉर्म को स्वचालित रूप से पहचानता और कॉन्फ़िगर करता है code-review-graph build # अपना कोडबेस पार्स करें ``` @@ -317,6 +322,6 @@ MIT। [LICENSE](LICENSE) देखें।


code-review-graph.com

-pip install code-review-graph && code-review-graph install
+pip install code-review-graph # या: npm install -g code-review-graph
code-review-graph install

Codex, Claude Code, Cursor, Windsurf, Zed, Continue, OpenCode, Antigravity, और Kiro के साथ काम करता है

diff --git a/README.ja-JP.md b/README.ja-JP.md index 220ea864..2f8521a8 100644 --- a/README.ja-JP.md +++ b/README.ja-JP.md @@ -37,7 +37,12 @@ AIコーディングツールはタスクのたびにコードベース全体を ## クイックスタート ```bash +# Pythonを使用 (推奨) pip install code-review-graph # または: pipx install code-review-graph + +# Node.jsを使用 +npm install -g code-review-graph + code-review-graph install # 対応プラットフォームを自動検出して設定 code-review-graph build # コードベースを解析 ``` @@ -319,6 +324,6 @@ MIT。詳細は [LICENSE](LICENSE) を参照してください。


code-review-graph.com

-pip install code-review-graph && code-review-graph install
+pip install code-review-graph # または: npm install -g code-review-graph
code-review-graph install

Codex、Claude Code、Cursor、Windsurf、Zed、Continue、OpenCode、Antigravity、Kiroに対応

diff --git a/README.ko-KR.md b/README.ko-KR.md index f593f065..ef6b3244 100644 --- a/README.ko-KR.md +++ b/README.ko-KR.md @@ -37,7 +37,12 @@ AI 코딩 도구는 매 작업마다 전체 코드베이스를 다시 읽습니 ## 빠른 시작 ```bash +# Python 사용 (권장) pip install code-review-graph # 또는: pipx install code-review-graph + +# Node.js 사용 +npm install -g code-review-graph + code-review-graph install # 지원되는 모든 플랫폼을 자동 감지하고 설정 code-review-graph build # 코드베이스 파싱 ``` @@ -319,6 +324,6 @@ MIT. [LICENSE](LICENSE)를 참조하세요.


code-review-graph.com

-pip install code-review-graph && code-review-graph install
+pip install code-review-graph # 또는: npm install -g code-review-graph
code-review-graph install

Codex, Claude Code, Cursor, Windsurf, Zed, Continue, OpenCode, Antigravity, Kiro에서 사용 가능

diff --git a/README.md b/README.md index 0c576965..4c28f6a9 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,12 @@ AI coding tools re-read your entire codebase on every task. `code-review-graph` ## Quick Start ```bash +# Using Python (recommended) pip install code-review-graph # or: pipx install code-review-graph + +# Using Node.js +npm install -g code-review-graph + code-review-graph install # auto-detects and configures all supported platforms code-review-graph build # parse your codebase ``` @@ -531,6 +536,6 @@ MIT. See [LICENSE](LICENSE).


code-review-graph.com

-pip install code-review-graph && code-review-graph install
+pip install code-review-graph # or: npm install -g code-review-graph
code-review-graph install

Works with Codex, Claude Code, Cursor, Windsurf, Zed, Continue, OpenCode, Antigravity, Gemini CLI, Qwen, Qoder, Kiro, GitHub Copilot, and GitHub Copilot CLI

diff --git a/README.zh-CN.md b/README.zh-CN.md index 9d1c8fa0..6efb5bc3 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -37,7 +37,12 @@ AI 编码工具在每次任务中都会重新读取整个代码库。`code-revie ## 快速开始 ```bash +# 使用 Python (推荐) pip install code-review-graph # 或: pipx install code-review-graph + +# 使用 Node.js +npm install -g code-review-graph + code-review-graph install # 自动检测并配置所有支持的平台 code-review-graph build # 解析代码库 ``` @@ -317,6 +322,6 @@ MIT。详见 [LICENSE](LICENSE)。


code-review-graph.com

-pip install code-review-graph && code-review-graph install
+pip install code-review-graph # 或: npm install -g code-review-graph
code-review-graph install

支持 Codex、Claude Code、Cursor、Windsurf、Zed、Continue、OpenCode、Antigravity 和 Kiro