@kennyzhao/cgm 0.0.0-stage → 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/DEPLOY-Linux.md +75 -0
- package/LICENSE +21 -0
- package/README.en.md +220 -0
- package/README.md +220 -2
- package/cli.mjs +68 -0
- package/install.cmd +5 -0
- package/install.ps1 +55 -0
- package/install.sh +66 -0
- package/mcp-config.json +8 -0
- package/mcp.mjs +487 -0
- package/package.json +35 -4
- package/public/img/add-provider.png +0 -0
- package/public/img/index.png +0 -0
- package/public/img/repo-show.png +0 -0
- package/public/img/setting.png +0 -0
- package/public/index.html +892 -0
- package/server.mjs +1144 -0
- package/verify-mcp.mjs +207 -0
package/DEPLOY-Linux.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# CodeGraph Manager —— 服务器部署说明
|
|
2
|
+
|
|
3
|
+
一个带前端界面的服务,管理服务器上"GitLab 仓库 → clone → codegraph 分析 → 移除"的完整闭环。
|
|
4
|
+
零依赖:只需 Node.js + git + codegraph。
|
|
5
|
+
|
|
6
|
+
## 一条命令跑起来(Linux)
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
# 依赖检查
|
|
10
|
+
node -v && git --version
|
|
11
|
+
# codegraph(任选安装方式)
|
|
12
|
+
curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh
|
|
13
|
+
codegraph --version
|
|
14
|
+
|
|
15
|
+
# 拉工程、起服务
|
|
16
|
+
cd /opt && git clone <你的仓库> codegraph-manager # 或 scp server.mjs + public/
|
|
17
|
+
cd codegraph-manager
|
|
18
|
+
HOST=127.0.0.1 PORT=8801 DATA_DIR=/var/lib/codegraph-manager \
|
|
19
|
+
node server.mjs
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 环境变量
|
|
23
|
+
|
|
24
|
+
| 变量 | 默认 | 说明 |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| `HOST` | `127.0.0.1` | 监听地址。只本机管理就默认;**要团队网页访问改 `0.0.0.0` + 设 ADMIN_TOKEN** |
|
|
27
|
+
| `PORT` | `8801` | 端口 |
|
|
28
|
+
| `DATA_DIR` | `./data` | `settings.json`(含 GitLab token) + `repos.json` 存放 |
|
|
29
|
+
| `ADMIN_TOKEN` | 空 | 可选 Bearer 令牌,保护页面/API |
|
|
30
|
+
| `CODEGRAPH_BIN` | `codegraph` | codegraph 调用方式:`codegraph`、`/usr/local/bin/codegraph`、或 **JSON 数组**(含空格路径时用,如 `["node","/opt/.../npm-shim.js"]`) |
|
|
31
|
+
|
|
32
|
+
## systemd 常驻
|
|
33
|
+
|
|
34
|
+
`/etc/systemd/system/codegraph-manager.service`:
|
|
35
|
+
```ini
|
|
36
|
+
[Unit]
|
|
37
|
+
Description=CodeGraph Manager
|
|
38
|
+
After=network.target
|
|
39
|
+
|
|
40
|
+
[Service]
|
|
41
|
+
Type=simple
|
|
42
|
+
WorkingDirectory=/opt/codegraph-manager
|
|
43
|
+
Environment=HOST=127.0.0.1
|
|
44
|
+
Environment=PORT=8801
|
|
45
|
+
Environment=DATA_DIR=/var/lib/codegraph-manager
|
|
46
|
+
Environment=CODEGRAPH_BIN=/usr/local/bin/codegraph
|
|
47
|
+
# GitLab appkey 不进 unit,从界面保存后落在 DATA_DIR/settings.json
|
|
48
|
+
ExecStart=/usr/bin/node server.mjs
|
|
49
|
+
Restart=always
|
|
50
|
+
User=codegraph
|
|
51
|
+
Group=codegraph
|
|
52
|
+
|
|
53
|
+
[Install]
|
|
54
|
+
WantedBy=multi-user.target
|
|
55
|
+
```
|
|
56
|
+
```bash
|
|
57
|
+
systemctl daemon-reload && systemctl enable --now codegraph-manager
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 使用流程(界面 http://<host>:8801)
|
|
61
|
+
1. **GitLab 配置**:填 GitLab 地址 + AppKey(Access Token),点"校验 Token"。保存后 token 落盘在 `DATA_DIR/settings.json`。
|
|
62
|
+
2. **添加仓库**:搜索 GitLab 项目 → 选中 → 添加 → 自动 Clone。
|
|
63
|
+
3. **操作列**:Clone / 分析(跑 codegraph init) / 状态 / 移除(删目录+注册)。
|
|
64
|
+
|
|
65
|
+
## 关键运维点
|
|
66
|
+
- **clone 基目录**(界面上填的"仓库克隆基目录")应指向本地磁盘;索引放网络盘会退化。
|
|
67
|
+
- **版本对齐**:GitLab 项目克隆的是你选的**默认分支**;若要分析部署版本,注册时改 gitUrl/branch 指向部署分支/tag。
|
|
68
|
+
- **登录/鉴权**:默认仅本机。要团队访问:`HOST=0.0.0.0` + `ADMIN_TOKEN=...`,并建议前加 Nginx/TLS。
|
|
69
|
+
- **token 安全**:`settings.json` 里是明文 GitLab token——`chmod 600` DATA_DIR。
|
|
70
|
+
- **代码库形态**:多独立仓库默认**每个 index 独立**(不跨仓);跨仓调用链需 GitNexus groups 或 monorepo。
|
|
71
|
+
|
|
72
|
+
## 本机已验证(Windows 开发机)
|
|
73
|
+
- 设置持久化(settings.json) / 仓库注册表(repos.json) / GitLab 校验与搜索端点
|
|
74
|
+
- clone → (codegraph 真实索引 `codegraph.db`) → status→indexed → remove(删目录+清注册) ✅
|
|
75
|
+
- GitLab 实网 clone/搜索需你填真实 GitLab URL + AppKey 验证(本机已用本地 git 源测通 clone 机制)。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zhao-T-X
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# CodeGraph Manager
|
|
4
|
+
|
|
5
|
+
**Turn your entire codebase into a knowledge graph your AI can read.**
|
|
6
|
+
|
|
7
|
+
Manage repositories from GitLab / Gitee / GitHub in one place, build a code knowledge graph with [CodeGraph](https://github.com/colbymchenry/codegraph), and let AI agents like Cursor or Claude query your code directly over **MCP (Model Context Protocol)**.
|
|
8
|
+
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
[](#-dependencies)
|
|
11
|
+
[](#-license)
|
|
12
|
+
[](#-mcp-integration)
|
|
13
|
+
|
|
14
|
+
<a href="README.md">🇨🇳 中文</a> · 🇬🇧 English
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
Zero-dependency Node backend + single-file vanilla-JS frontend, **one command to start**: no database install, no build step, no Docker.
|
|
21
|
+
The whole pipeline — clone → index → AI retrieval — runs automatically. Tokens are encrypted at rest; all data lives in one directory.
|
|
22
|
+
|
|
23
|
+
## ✨ Features
|
|
24
|
+
|
|
25
|
+
**Repository management**
|
|
26
|
+
- Multi-provider — GitLab / Gitee / GitHub with multiple instances each; one cross-source query returns everything
|
|
27
|
+
- Full lifecycle — one-click `clone → analyze → sync → remove`; shallow clone is ~10x faster
|
|
28
|
+
- Local repos — register an already-cloned directory directly (auto-detects Git remote)
|
|
29
|
+
- Branch worktrees — lazily spin up an isolated worktree per branch with its own index, so AI can query any branch; the main index stays clean automatically
|
|
30
|
+
- Spaces — tag repos into groups and filter the UI by space
|
|
31
|
+
- Create: `All spaces → New Space` (top right); assign: `+ Spaces` on a repository row
|
|
32
|
+
- Scheduled freshness — configurable auto `git pull + sync`; a failed pull is marked `pull_failed` instead of pretending the index is fresh
|
|
33
|
+
|
|
34
|
+
**AI retrieval (MCP)**
|
|
35
|
+
- 4 MCP tools (Streamable HTTP / JSON-RPC 2.0); cross-repo aggregated search — concurrent queries over all indexed repos, ranked hits with per-repo caps so your context window doesn't explode
|
|
36
|
+
- Querying a branch with no index yet? The server builds one in the background and returns "retry shortly"
|
|
37
|
+
|
|
38
|
+
**Security**
|
|
39
|
+
- Route-level auth — `/api/*` and `/mcp*` guarded by `ADMIN_TOKEN` / `MCP_TOKEN`, constant-time comparison
|
|
40
|
+
- Role-based access tokens — Settings → Access tokens creates `web` / `mcp` tokens; web tokens only see/operate repositories in their spaces, mcp tokens only search their spaces, admin is unrestricted
|
|
41
|
+
- Loopback exemption — local access allowed by default (with same-origin checks so web pages can't hit your localhost); fail-closed when exposed: refuses to start without a token
|
|
42
|
+
- Auto-generated 192-bit token on first start, persisted to `auth.json` — safe to expose without any manual setup
|
|
43
|
+
- Token protection, three layers — AES-256-GCM at rest, masked in API responses (dots + last 4), masked PUT values never overwrite real tokens
|
|
44
|
+
- 1 MB body limit (413), cross-origin requests always 401, `X-Forwarded-For` only trusted from configured proxies
|
|
45
|
+
|
|
46
|
+
**Engineering**
|
|
47
|
+
- SQLite storage (`node:sqlite`, zero npm dependencies) — transactional atomic writes; legacy JSON auto-migrates on first start
|
|
48
|
+
- Three-tier concurrency control — global index queue + per-repo lifecycle mutex + per-file write serialization
|
|
49
|
+
- Restart self-healing — interrupted in-flight states reset automatically; `CODEGRAPH_BIN` auto-detected (no manual config on Windows)
|
|
50
|
+
- SSE live status push with 30s polling fallback; `BASE_PATH` for reverse-proxy sub-path deployments
|
|
51
|
+
- Built-in regression suite `node verify-mcp.mjs` (49 assertions: protocol / auth / masking / concurrency / migration)
|
|
52
|
+
|
|
53
|
+
## 📸 Screenshots
|
|
54
|
+
|
|
55
|
+
| Overview | Repositories |
|
|
56
|
+
|---|---|
|
|
57
|
+
|  |  |
|
|
58
|
+
|
|
59
|
+
| Add provider | Settings |
|
|
60
|
+
|---|---|
|
|
61
|
+
|  |  |
|
|
62
|
+
|
|
63
|
+
> Screenshots use sample data (Acme), not real repositories.
|
|
64
|
+
|
|
65
|
+
## 🚀 Quick Start
|
|
66
|
+
|
|
67
|
+
**One-click install** (installs anything missing: Node → git → CodeGraph → cgm, skips what's already there):
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
bash install.sh --port 8801 # Linux / macOS
|
|
71
|
+
.\install.cmd --port 8801 # Windows (or double-click install.cmd)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Manual install**:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm i -g @colbymchenry/codegraph # the only external dependency
|
|
78
|
+
npm i -g @kennyzhao/cgm # or: npm i -g . inside this repo
|
|
79
|
+
cgm # start from any directory
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Open **http://127.0.0.1:8801** → Settings → add a provider → Add Selected → Clone & Analyze. Done.
|
|
83
|
+
|
|
84
|
+
> CLI precedence: flags > environment variables > defaults. `cgm --port 9000 --data /srv/cgm-data`
|
|
85
|
+
|
|
86
|
+
## 🔌 MCP Integration
|
|
87
|
+
|
|
88
|
+
MCP endpoint: `http://127.0.0.1:8801/mcp` (Streamable HTTP / JSON-RPC 2.0)
|
|
89
|
+
|
|
90
|
+
> UI: **Settings → MCP access** copies the endpoint and a ready `mcpServers` config; loopback gets a header-free version, non-loopback includes a Bearer placeholder.
|
|
91
|
+
|
|
92
|
+
**Cursor / Claude Desktop / Cline** (standard `mcpServers` format, also shipped as `mcp-config.json`):
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"mcpServers": {
|
|
97
|
+
"cgm": {
|
|
98
|
+
"url": "http://127.0.0.1:8801/mcp",
|
|
99
|
+
"headers": { "Authorization": "Bearer <your-token>" }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
> Local access is token-free by default, so `headers` is optional. Where does the token come from: the first-start log, or `<DATA_DIR>/auth.json` (`adminToken`); you can also set `ADMIN_TOKEN` explicitly. URL-only clients can fall back to `?token=<token>`.
|
|
106
|
+
|
|
107
|
+
### Tools
|
|
108
|
+
|
|
109
|
+
| Tool | Description |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `query_repository(name)` | Look up a repo by name: local path / status / provider |
|
|
112
|
+
| `list_repositories(status?)` | List registered repos, filterable by status |
|
|
113
|
+
| `search_repositories(query)` | Fuzzy repo-name search |
|
|
114
|
+
| `search_code(query, repo?, branch?, maxFiles?)` | **The core search**: queries the CodeGraph knowledge graph for symbols / files / call relationships. Omit `repo` to aggregate across all indexed repos |
|
|
115
|
+
|
|
116
|
+
Branch-scoped query example:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{"jsonrpc":"2.0","id":1,"method":"tools/call",
|
|
120
|
+
"params":{"name":"search_code","arguments":{"query":"AuthService loginUser","repo":"tineco-nmp","branch":"dev_ibu","maxFiles":12}}}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## ⚙️ Configuration
|
|
124
|
+
|
|
125
|
+
| Variable | Default | Description |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| `PORT` / `HOST` | `8801` / `127.0.0.1` | Listen address; non-loopback `HOST` requires a token (refuses to start otherwise) |
|
|
128
|
+
| `DATA_DIR` | `<cwd>/data` | Data directory (`cgm.db`; cloned repos default to `<DATA_DIR>/repos`) |
|
|
129
|
+
| `ADMIN_TOKEN` | auto-generated | Token for `/api/*`; on first start a random one is generated into `auth.json` |
|
|
130
|
+
| `MCP_TOKEN` | falls back to `ADMIN_TOKEN` | Token for `/mcp*` (one variable is enough for personal use) |
|
|
131
|
+
| `LOCAL_NO_AUTH` | `1` | Loopback auth exemption; set `0` to require auth locally too |
|
|
132
|
+
| `BASE_PATH` | empty | Reverse-proxy sub-path (e.g. `/cgm` → endpoints under `/cgm/mcp`) |
|
|
133
|
+
| `MAX_BODY_BYTES` | `1048576` | Request body limit, over-limit returns 413 |
|
|
134
|
+
| `TRUSTED_PROXIES` | empty | Comma-separated trusted proxy IPs; `X-Forwarded-For` only honored from these |
|
|
135
|
+
| `CODEGRAPH_BIN` | auto-detected | CodeGraph executable (PATH probe → npm global shim → explicit) |
|
|
136
|
+
| `SYNC_HOURS` | `6` | Scheduled sync interval in hours, `0` disables; also configurable in Settings |
|
|
137
|
+
| `QUEUE_CONCURRENCY` | `2` | Index queue concurrency |
|
|
138
|
+
| `ENCRYPTION_KEY` | auto-generated `.key` | 64-char hex AES-256-GCM key |
|
|
139
|
+
|
|
140
|
+
## 🔒 Security Model
|
|
141
|
+
|
|
142
|
+
| Scenario | Behavior |
|
|
143
|
+
|---|---|
|
|
144
|
+
| Local 127.0.0.1 access | Token-free by default (dev-friendly); cross-origin web requests still get 401 |
|
|
145
|
+
| LAN / remote access | Token required (Bearer header / `?token=` / Cookie) |
|
|
146
|
+
| `HOST=0.0.0.0` with no token | Starts with an auto-generated random token; the log tells you where it is |
|
|
147
|
+
| Token exposure surface | Encrypted at rest + masked via API + printed to log once, on first start only |
|
|
148
|
+
|
|
149
|
+
`data/` is excluded by `.gitignore` — real tokens never enter version control. For public exposure, put Nginx + HTTPS in front (see [DEPLOY-Linux.md](DEPLOY-Linux.md)).
|
|
150
|
+
|
|
151
|
+
## 🔌 API Reference
|
|
152
|
+
|
|
153
|
+
| Endpoint | Methods | Description |
|
|
154
|
+
|---|---|---|
|
|
155
|
+
| `/healthz` | GET | Liveness probe (no auth) |
|
|
156
|
+
| `/api/settings` | GET/PUT | Global settings (tokens masked in responses) |
|
|
157
|
+
| `/api/providers[/...]` | GET/POST/PUT/DELETE | Provider CRUD + connection test + cross-source project search |
|
|
158
|
+
| `/api/repos[/local]` | GET/POST | Registry / add a local repo |
|
|
159
|
+
| `/api/repos/:id/{clone,analyze,status,remove,sync}` | POST | Per-repo ops (async; same-repo ops are automatically serialized) |
|
|
160
|
+
| `/api/repos/:id/worktree/:branch` | POST/DELETE | Create / remove a branch worktree |
|
|
161
|
+
| `/api/spaces[/...]` | GET/POST/PUT/DELETE | Space management / repo binding |
|
|
162
|
+
| `/api/tokens[/...]` | GET/POST/DELETE | Access-token management (admin): roles + space scopes |
|
|
163
|
+
| `/api/browse?path=` | GET | Server-side directory browser (for adding local repos) |
|
|
164
|
+
| `/mcp` · `/mcp/message` | POST/GET | MCP endpoint (Streamable HTTP + SSE) |
|
|
165
|
+
|
|
166
|
+
## ❓ FAQ
|
|
167
|
+
|
|
168
|
+
<details>
|
|
169
|
+
<summary><b>codegraph ENOENT on startup?</b></summary>
|
|
170
|
+
|
|
171
|
+
On Windows the globally installed codegraph is a bash shim that can't be spawned directly. The service auto-detects it and rewrites it as `["node", "<shim>"]` — no manual `CODEGRAPH_BIN` needed on recent versions.
|
|
172
|
+
</details>
|
|
173
|
+
|
|
174
|
+
<details>
|
|
175
|
+
<summary><b>Frontend keeps returning 401 after I set ADMIN_TOKEN?</b></summary>
|
|
176
|
+
|
|
177
|
+
The page pops up a token prompt — paste the token there (stored in localStorage). Or clear the `cgm_token` localStorage key and re-enter.
|
|
178
|
+
</details>
|
|
179
|
+
|
|
180
|
+
<details>
|
|
181
|
+
<summary><b>Will I lose data?</b></summary>
|
|
182
|
+
|
|
183
|
+
Everything lives in one `<DATA_DIR>` (SQLite + keys + auth.json); backing up = copying the directory. Legacy JSON files auto-migrate on first start and are kept as `*.json.migrated-*` — delete `cgm.db*`, rename them back, and you've rolled back.
|
|
184
|
+
</details>
|
|
185
|
+
|
|
186
|
+
<details>
|
|
187
|
+
<summary><b>Search results feel stale?</b></summary>
|
|
188
|
+
|
|
189
|
+
Check the status column: `pull_failed` means the scheduled pull failed (retried next round). You can also hit Sync manually. Indexes are updated incrementally via CodeGraph sync.
|
|
190
|
+
</details>
|
|
191
|
+
|
|
192
|
+
## 🛠 Development
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
git clone https://github.com/Zhao-T-X/CGM.git && cd CGM
|
|
196
|
+
node server.mjs # dev server (127.0.0.1:8801)
|
|
197
|
+
node verify-mcp.mjs # regression suite: 49 assertions (protocol/auth/security/concurrency/migration)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
cgm/
|
|
202
|
+
├── cli.mjs CLI entry (the cgm command)
|
|
203
|
+
├── server.mjs HTTP backend (route auth, providers/repos/spaces, SQLite persistence)
|
|
204
|
+
├── mcp.mjs MCP module (4 tools + CodeGraph stdio gateway client)
|
|
205
|
+
├── verify-mcp.mjs Regression suite (49 assertions, isolated temp instances)
|
|
206
|
+
├── public/index.html Single-file frontend (Vercel-style dark UI)
|
|
207
|
+
└── install.sh/.cmd One-click installers
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## 🚢 Release (maintainers)
|
|
211
|
+
|
|
212
|
+
Pushing a `v*` tag triggers GitHub Actions to publish to npm (tag/version check → `npm pack --dry-run` → `npm publish --provenance`; requires the `NPM_TOKEN` secret).
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
npm version patch && git push --follow-tags
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## 📄 License
|
|
219
|
+
|
|
220
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,3 +1,221 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# CodeGraph Manager
|
|
4
|
+
|
|
5
|
+
**把整个代码库变成 AI 能读懂的知识图谱。**
|
|
6
|
+
|
|
7
|
+
统一管理 GitLab / Gitee / GitHub 仓库,自动用 [CodeGraph](https://github.com/colbymchenry/codegraph) 构建代码知识图谱,
|
|
8
|
+
通过 **MCP(Model Context Protocol)** 让 Cursor、Claude 等 AI 代理直接检索你的代码。
|
|
9
|
+
|
|
10
|
+
[](https://nodejs.org)
|
|
11
|
+
[](#-依赖)
|
|
12
|
+
[](#-license)
|
|
13
|
+
[](#-mcp-接入)
|
|
14
|
+
|
|
15
|
+
🇨🇳 中文 · <a href="README.en.md">🇬🇧 English</a>
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
零依赖 Node 后端 + 单文件原生 JS 前端,**一条命令启动**:无需数据库安装、无需构建步骤、无需 Docker。
|
|
22
|
+
仓库 clone → 索引 → AI 检索全流程自动化,Token 加密落盘,数据一个目录全带走。
|
|
23
|
+
|
|
24
|
+
## ✨ 功能
|
|
25
|
+
|
|
26
|
+
**仓库管理**
|
|
27
|
+
- 多提供商统一管理 —— GitLab / Gitee / GitHub 多实例并存,跨源搜索一次出结果
|
|
28
|
+
- 全生命周期 —— `clone → analyze → sync → remove` 一键流转,浅克隆提速 10 倍级
|
|
29
|
+
- 本地仓库直纳 —— 已克隆目录直接注册,自动识别 Git 远程
|
|
30
|
+
- 多分支 worktree —— 按分支懒加载切出独立 worktree 并各建索引,AI 可检索任意分支;主索引自动豁免不污染
|
|
31
|
+
- 空间分组 —— 仓库打标签分组,界面按空间筛选
|
|
32
|
+
- 新建空间:右上角 `All spaces → New Space`;分配仓库:仓库行 `+ Spaces`
|
|
33
|
+
- 定时保新鲜 —— 可配置周期自动 `git pull + sync`;拉取失败明确标记 `pull_failed`,不假装索引是最新的
|
|
34
|
+
|
|
35
|
+
**AI 检索(MCP)**
|
|
36
|
+
- 4 个 MCP 工具(Streamable HTTP / JSON-RPC 2.0),跨仓聚合检索:并发查所有已索引仓库,命中排序 + 每仓收敛,上下文不爆炸
|
|
37
|
+
- 首次检索未建索引的分支自动后台建索引,完成后即可用
|
|
38
|
+
|
|
39
|
+
**安全**
|
|
40
|
+
- 路由级鉴权 —— `/api/*` 与 `/mcp*` 分别持 `ADMIN_TOKEN` / `MCP_TOKEN`,`timingSafeEqual` 恒时比较
|
|
41
|
+
- 角色化访问令牌 —— Settings → Access tokens 创建 `web` / `mcp` token;web 只能查看/操作授权空间内的仓库,mcp 只能检索授权空间,admin 无限制
|
|
42
|
+
- 回环免鉴权 —— 本机访问默认放行(同源校验防网页打本地),对外开放时 fail-closed:无 token 拒绝启动
|
|
43
|
+
- 首启自动生成随机令牌(192bit)持久化到 `auth.json`,不用手动配也能安全对外开放
|
|
44
|
+
- Token 三重防护 —— 落盘 AES-256-GCM 加密、API 返回脱敏(掩码+末4位)、PUT 掩码不覆盖真值
|
|
45
|
+
- 请求体 1MB 上限(413)、跨源 Origin 一律 401、`X-Forwarded-For` 仅信可信代理
|
|
46
|
+
|
|
47
|
+
**工程化**
|
|
48
|
+
- SQLite 存储(`node:sqlite`,零 npm 依赖)—— 事务原子写,旧 JSON 首启自动迁移
|
|
49
|
+
- 三级并发治理 —— 全局索引队列限流 + 单仓生命周期互斥 + 每文件写串行,多仓并发不互踩
|
|
50
|
+
- 重启自愈 —— 中断的运行中状态自动重置;`CODEGRAPH_BIN` 自动探测,Windows 无需手配
|
|
51
|
+
- SSE 实时推送状态,30s 兜底轮询;`BASE_PATH` 支持反代子路径部署
|
|
52
|
+
- 内置回归脚本 `node verify-mcp.mjs`(49 项断言:协议合规 / 鉴权 / 脱敏 / 并发 / 迁移)
|
|
53
|
+
|
|
54
|
+
## 📸 界面
|
|
55
|
+
|
|
56
|
+
| 概览 | 仓库管理 |
|
|
57
|
+
|---|---|
|
|
58
|
+
|  |  |
|
|
59
|
+
|
|
60
|
+
| 添加提供商 | 设置 |
|
|
61
|
+
|---|---|
|
|
62
|
+
|  |  |
|
|
63
|
+
|
|
64
|
+
> 截图使用示例数据(Acme),不代表真实仓库内容。
|
|
65
|
+
|
|
66
|
+
## 🚀 快速开始
|
|
67
|
+
|
|
68
|
+
**一键安装**(自动装齐 Node → git → CodeGraph → cgm,已装的自动跳过):
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
bash install.sh --port 8801 # Linux / macOS
|
|
72
|
+
.\install.cmd --port 8801 # Windows(或双击 install.cmd)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**手动安装**:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm i -g @colbymchenry/codegraph # 唯一外部依赖
|
|
79
|
+
npm i -g @kennyzhao/cgm # 或在本仓库根目录 npm i -g .
|
|
80
|
+
cgm # 任意目录一键启动
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
打开 **http://127.0.0.1:8801** → Settings 添加提供商 → Add Selected → Clone & Analyze,完成。
|
|
84
|
+
|
|
85
|
+
> CLI 参数优先级:命令行 > 环境变量 > 默认值。`cgm --port 9000 --data /srv/cgm-data`
|
|
86
|
+
|
|
87
|
+
## 🔌 MCP 接入
|
|
88
|
+
|
|
89
|
+
MCP 端点:`http://127.0.0.1:8801/mcp`(Streamable HTTP / JSON-RPC 2.0)
|
|
90
|
+
|
|
91
|
+
> UI 入口:**Settings → MCP access** 可直接复制 endpoint 与 `mcpServers` 客户端配置;本机生成无 header 版本,非 loopback 自动带 Bearer 占位。
|
|
92
|
+
|
|
93
|
+
**Cursor / Claude Desktop / Cline**(`mcpServers` 标准格式,本仓库附带 `mcp-config.json`):
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"mcpServers": {
|
|
98
|
+
"cgm": {
|
|
99
|
+
"url": "http://127.0.0.1:8801/mcp",
|
|
100
|
+
"headers": { "Authorization": "Bearer <你的令牌>" }
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
> 本机访问默认免鉴权,`headers` 可省略。令牌从哪来:首次启动日志,或 `<DATA_DIR>/auth.json` 的 `adminToken`;也可用环境变量 `ADMIN_TOKEN` 显式指定。只能填 URL 的客户端可用 `?token=<令牌>` 兜底。
|
|
107
|
+
|
|
108
|
+
### 工具列表
|
|
109
|
+
|
|
110
|
+
| 工具 | 说明 |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `query_repository(name)` | 按名查仓库:本地路径 / 状态 / 提供商 |
|
|
113
|
+
| `list_repositories(status?)` | 列出注册仓库,可按状态过滤 |
|
|
114
|
+
| `search_repositories(query)` | 模糊搜索仓库名 |
|
|
115
|
+
| `search_code(query, repo?, branch?, maxFiles?)` | **核心检索**:查 CodeGraph 知识图谱,返回符号 / 文件 / 调用关系。不传 `repo` 则跨所有已索引仓库聚合 |
|
|
116
|
+
|
|
117
|
+
按分支检索示例:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{"jsonrpc":"2.0","id":1,"method":"tools/call",
|
|
121
|
+
"params":{"name":"search_code","arguments":{"query":"AuthService loginUser","repo":"tineco-nmp","branch":"dev_ibu","maxFiles":12}}}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## ⚙️ 配置
|
|
125
|
+
|
|
126
|
+
| 变量 | 默认 | 说明 |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `PORT` / `HOST` | `8801` / `127.0.0.1` | 监听地址;`HOST` 非回环时必须配 token(无则拒绝启动) |
|
|
129
|
+
| `DATA_DIR` | `<cwd>/data` | 数据目录(`cgm.db` + 克隆仓库默认存 `<DATA_DIR>/repos`) |
|
|
130
|
+
| `ADMIN_TOKEN` | 自动生成 | `/api/*` 令牌;未设置时首启生成随机值写入 `auth.json` |
|
|
131
|
+
| `MCP_TOKEN` | 回落 `ADMIN_TOKEN` | `/mcp*` 令牌(自用只配一个变量即可) |
|
|
132
|
+
| `LOCAL_NO_AUTH` | `1` | 回环免鉴权开关;设 `0` 本机也强制鉴权 |
|
|
133
|
+
| `BASE_PATH` | 空 | 反代子路径(如设 `/cgm` 后经 `/cgm/mcp` 访问) |
|
|
134
|
+
| `MAX_BODY_BYTES` | `1048576` | 请求体上限,超限 413 |
|
|
135
|
+
| `TRUSTED_PROXIES` | 空 | 逗号分隔可信代理 IP,仅对可信代理采信 `X-Forwarded-For` |
|
|
136
|
+
| `CODEGRAPH_BIN` | 自动探测 | CodeGraph 可执行(PATH 探测 → npm 全局 shim → 显式指定) |
|
|
137
|
+
| `SYNC_HOURS` | `6` | 定时同步周期(小时),`0` 关闭;UI Settings 可覆盖 |
|
|
138
|
+
| `QUEUE_CONCURRENCY` | `2` | 索引队列并发数 |
|
|
139
|
+
| `ENCRYPTION_KEY` | 自动生成 `.key` | 64 位 hex,AES-256-GCM 密钥 |
|
|
140
|
+
|
|
141
|
+
## 🔒 安全模型
|
|
142
|
+
|
|
143
|
+
| 场景 | 行为 |
|
|
144
|
+
|---|---|
|
|
145
|
+
| 本机 127.0.0.1 访问 | 默认免鉴权(开发/自用友好),跨源网页请求仍被 401 拦截 |
|
|
146
|
+
| 局域网 / 远程访问 | 必须持令牌(Bearer 头 / `?token=` / Cookie 任一) |
|
|
147
|
+
| `HOST=0.0.0.0` 且无令牌 | 启动时用自动生成的随机令牌兜底,日志打印令牌位置 |
|
|
148
|
+
| 令牌泄露面 | 落盘加密 + API 脱敏 + 首启仅日志打印一次 |
|
|
149
|
+
|
|
150
|
+
`data/` 已被 `.gitignore` 排除,真实 token 永不入库。对外开放建议叠加 Nginx 反代 + HTTPS(见 [DEPLOY-Linux.md](DEPLOY-Linux.md))。
|
|
151
|
+
|
|
152
|
+
## 🔌 API 参考
|
|
153
|
+
|
|
154
|
+
| 端点 | 方法 | 说明 |
|
|
155
|
+
|---|---|---|
|
|
156
|
+
| `/healthz` | GET | 存活探针(无鉴权) |
|
|
157
|
+
| `/api/settings` | GET/PUT | 全局配置(返回值 token 已脱敏) |
|
|
158
|
+
| `/api/providers[/...]` | GET/POST/PUT/DELETE | 提供商 CRUD + 连接测试 + 跨源项目搜索 |
|
|
159
|
+
| `/api/repos[/local]` | GET/POST | 仓库注册表 / 添加本地仓库 |
|
|
160
|
+
| `/api/repos/:id/{clone,analyze,status,remove,sync}` | POST | 单仓操作(异步执行,同仓操作自动排队互斥) |
|
|
161
|
+
| `/api/repos/:id/worktree/:branch` | POST/DELETE | 分支 worktree 创建 / 删除 |
|
|
162
|
+
| `/api/spaces[/...]` | GET/POST/PUT/DELETE | 空间分组管理 / 仓库绑定 |
|
|
163
|
+
| `/api/tokens[/...]` | GET/POST/DELETE | 访问令牌管理(admin):角色 + 空间范围 |
|
|
164
|
+
| `/api/browse?path=` | GET | 服务端目录浏览(添加本地仓库用) |
|
|
165
|
+
| `/mcp` · `/mcp/message` | POST/GET | MCP 端点(Streamable HTTP + SSE) |
|
|
166
|
+
|
|
167
|
+
## ❓ 常见问题
|
|
168
|
+
|
|
169
|
+
<details>
|
|
170
|
+
<summary><b>启动报 codegraph ENOENT?</b></summary>
|
|
171
|
+
|
|
172
|
+
Windows 全局安装的 codegraph 是 bash shim,PATH 直接 spawn 不通。本服务会自动探测并转成 `["node", "<shim>"]` 形式;老版本升级后无需再手配 `CODEGRAPH_BIN`。
|
|
173
|
+
</details>
|
|
174
|
+
|
|
175
|
+
<details>
|
|
176
|
+
<summary><b>配了 ADMIN_TOKEN 后前端一直 401?</b></summary>
|
|
177
|
+
|
|
178
|
+
页面会弹出令牌输入框,粘贴令牌即可(存浏览器 localStorage)。或清除 localStorage 里的 `cgm_token` 重新输入。
|
|
179
|
+
</details>
|
|
180
|
+
|
|
181
|
+
<details>
|
|
182
|
+
<summary><b>数据会丢吗?</b></summary>
|
|
183
|
+
|
|
184
|
+
所有数据在 `<DATA_DIR>` 一个目录(SQLite + 密钥 + auth.json),备份 = 拷贝目录。旧版 JSON 文件首启自动迁移,原文件改名 `*.json.migrated-*` 保留,删掉 `cgm.db*` 改回原名即可回退。
|
|
185
|
+
</details>
|
|
186
|
+
|
|
187
|
+
<details>
|
|
188
|
+
<summary><b>检索结果过时?</b></summary>
|
|
189
|
+
|
|
190
|
+
看仓库状态列:`pull_failed` 表示定时同步拉取失败(下轮自动重试);也可手动点 Sync。索引基于 CodeGraph 增量 sync。
|
|
191
|
+
</details>
|
|
192
|
+
|
|
193
|
+
## 🛠 开发
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
git clone https://github.com/Zhao-T-X/CGM.git && cd CGM
|
|
197
|
+
node server.mjs # 开发启动(127.0.0.1:8801)
|
|
198
|
+
node verify-mcp.mjs # 回归测试:49 项断言(协议/鉴权/安全/并发/迁移)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
cgm/
|
|
203
|
+
├── cli.mjs CLI 入口(cgm 命令)
|
|
204
|
+
├── server.mjs HTTP 后端(路由鉴权、提供商/仓库/空间、SQLite 持久化)
|
|
205
|
+
├── mcp.mjs MCP 模块(4 工具 + CodeGraph stdio 网关客户端)
|
|
206
|
+
├── verify-mcp.mjs 回归脚本(49 项断言,临时实例隔离运行)
|
|
207
|
+
├── public/index.html 前端单文件(Vercel 风深色 UI)
|
|
208
|
+
└── install.sh/.cmd 一键安装脚本
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 🚢 发布(维护者)
|
|
212
|
+
|
|
213
|
+
推送 `v*` tag 触发 GitHub Actions 自动发 npm(tag 与版本校验 → `npm pack --dry-run` → `npm publish --provenance`,需配置 `NPM_TOKEN`)。
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
npm version patch && git push --follow-tags
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## 📄 License
|
|
220
|
+
|
|
221
|
+
MIT
|
package/cli.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// CodeGraph Manager CLI —— 一键启动
|
|
3
|
+
//
|
|
4
|
+
// 安装全局命令: npm i -g . (项目根执行一次)
|
|
5
|
+
// 使用: cgm [选项] 任意目录一键启动服务
|
|
6
|
+
// 不装全局: node cli.mjs [选项] 效果相同
|
|
7
|
+
//
|
|
8
|
+
// 选项(优先级:命令行参数 > 环境变量 > 默认值):
|
|
9
|
+
// --port <n> 监听端口 默认 8801
|
|
10
|
+
// --host <addr> 监听地址 默认 127.0.0.1(对外开放 0.0.0.0 并配 ADMIN_TOKEN)
|
|
11
|
+
// --data <dir> 数据目录 默认 ./data
|
|
12
|
+
// --codegraph <bin> codegraph 调用方式 默认自动探测(PATH 里的 codegraph → npm 全局 shim)
|
|
13
|
+
// -v / --version 版本
|
|
14
|
+
// -h / --help 帮助
|
|
15
|
+
import { createRequire } from 'node:module';
|
|
16
|
+
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
18
|
+
const { version } = require('./package.json');
|
|
19
|
+
|
|
20
|
+
const HELP = `CodeGraph Manager v${version} —— 多 Git 平台仓库索引管理 + MCP 代码检索
|
|
21
|
+
|
|
22
|
+
用法:
|
|
23
|
+
cgm [选项] 启动服务(前台运行,Ctrl+C 退出)
|
|
24
|
+
cgm -v | --version 显示版本
|
|
25
|
+
cgm -h | --help 显示本帮助
|
|
26
|
+
|
|
27
|
+
选项(优先级:命令行参数 > 环境变量 > 默认值):
|
|
28
|
+
--port <n> 监听端口 默认 8801
|
|
29
|
+
--host <addr> 监听地址 默认 127.0.0.1
|
|
30
|
+
--data <dir> 数据目录 默认 ./data(settings/repos/克隆仓库都在这,备份=拷目录)
|
|
31
|
+
--codegraph <bin> codegraph 调用方式 默认自动探测,无需配置
|
|
32
|
+
|
|
33
|
+
示例:
|
|
34
|
+
cgm # 全默认:http://127.0.0.1:8801
|
|
35
|
+
cgm --port 9000 --data /srv/cgm-data # 自定义端口与数据目录
|
|
36
|
+
HOST=0.0.0.0 ADMIN_TOKEN=xxx cgm # 对外开放(env 方式)
|
|
37
|
+
界面 http://127.0.0.1:<port> · MCP 端点 /mcp · 探活 /healthz`;
|
|
38
|
+
|
|
39
|
+
function fail(msg) { console.error(`cgm: ${msg}(--help 查看用法)`); process.exit(1); }
|
|
40
|
+
|
|
41
|
+
const opts = {};
|
|
42
|
+
const argv = process.argv.slice(2);
|
|
43
|
+
for (let i = 0; i < argv.length; i++) {
|
|
44
|
+
const a = argv[i];
|
|
45
|
+
switch (a) {
|
|
46
|
+
case '-h': case '--help': console.log(HELP); process.exit(0);
|
|
47
|
+
case '-v': case '--version': console.log(version); process.exit(0);
|
|
48
|
+
case '--port': opts.port = argv[++i]; break;
|
|
49
|
+
case '--host': opts.host = argv[++i]; break;
|
|
50
|
+
case '--data': opts.data = argv[++i]; break;
|
|
51
|
+
case '--codegraph': opts.codegraph = argv[++i]; break;
|
|
52
|
+
case 'start': break; // 兼容 `cgm start` 写法
|
|
53
|
+
default: fail(`未知参数: ${a}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 参数映射为环境变量(server.mjs 顶层读取),显式参数覆盖 env
|
|
58
|
+
if (opts.port !== undefined) {
|
|
59
|
+
const p = Number.parseInt(opts.port, 10);
|
|
60
|
+
if (!Number.isInteger(p) || p <= 0 || p > 65535) fail(`非法端口: ${opts.port}`);
|
|
61
|
+
process.env.PORT = String(p);
|
|
62
|
+
}
|
|
63
|
+
if (opts.host !== undefined) process.env.HOST = opts.host;
|
|
64
|
+
if (opts.data !== undefined) process.env.DATA_DIR = opts.data;
|
|
65
|
+
if (opts.codegraph !== undefined) process.env.CODEGRAPH_BIN = opts.codegraph;
|
|
66
|
+
|
|
67
|
+
// env 已就位,动态加载服务入口(顶层读取上述变量完成初始化)
|
|
68
|
+
await import('./server.mjs');
|
package/install.cmd
ADDED
package/install.ps1
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# CodeGraph Manager 一键安装(Windows)
|
|
2
|
+
# 自动安装缺失依赖:Node.js(>=18) → git → CodeGraph → cgm,然后启动服务
|
|
3
|
+
# 用法: .\install.cmd [cgm 参数透传] 例: .\install.cmd --port 9000 --data E:\cgm-data
|
|
4
|
+
# 也可: powershell -NoProfile -ExecutionPolicy Bypass -File install.ps1
|
|
5
|
+
$ErrorActionPreference = 'Stop'
|
|
6
|
+
$Repo = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
7
|
+
|
|
8
|
+
function Say($m) { Write-Host "==> $m" -ForegroundColor Green }
|
|
9
|
+
function Refresh-Path {
|
|
10
|
+
$env:Path = [Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' +
|
|
11
|
+
[Environment]::GetEnvironmentVariable('Path', 'User')
|
|
12
|
+
}
|
|
13
|
+
function Get-NodeMajor {
|
|
14
|
+
try { return [int](((node -v) -replace '^v', '').Split('.')[0]) } catch { return 0 }
|
|
15
|
+
}
|
|
16
|
+
function Install-Winget([string]$Id) {
|
|
17
|
+
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
|
|
18
|
+
Write-Error "未找到 winget,请手动安装后重试(Node: https://nodejs.org / git: https://git-scm.com)"
|
|
19
|
+
}
|
|
20
|
+
winget install -e --id $Id --accept-source-agreements --accept-package-agreements
|
|
21
|
+
Refresh-Path
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# ---------- 1) Node.js >= 18 ----------
|
|
25
|
+
if ((Get-NodeMajor) -ge 18) {
|
|
26
|
+
Say "Node $(node -v) 已就绪"
|
|
27
|
+
} else {
|
|
28
|
+
Say "安装 Node.js 22 LTS ..."
|
|
29
|
+
Install-Winget 'OpenJS.NodeJS.LTS'
|
|
30
|
+
if ((Get-NodeMajor) -lt 18) { Write-Error "Node 安装后仍不可用,请重开终端再运行本脚本" }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# ---------- 2) git(服务端 clone 业务仓库依赖) ----------
|
|
34
|
+
if (Get-Command git -ErrorAction SilentlyContinue) {
|
|
35
|
+
Say "git 已就绪"
|
|
36
|
+
} else {
|
|
37
|
+
Say "安装 git ..."
|
|
38
|
+
Install-Winget 'Git.Git'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# ---------- 3) CodeGraph ----------
|
|
42
|
+
if (Get-Command codegraph -ErrorAction SilentlyContinue) {
|
|
43
|
+
Say "codegraph 已就绪"
|
|
44
|
+
} else {
|
|
45
|
+
Say "安装 CodeGraph ..."
|
|
46
|
+
npm i -g @colbymchenry/codegraph
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# ---------- 4) cgm(本仓库 CLI,link 到全局) ----------
|
|
50
|
+
Say "安装 cgm(npm i -g $Repo)..."
|
|
51
|
+
npm i -g $Repo
|
|
52
|
+
|
|
53
|
+
# ---------- 5) 启动(参数透传) ----------
|
|
54
|
+
Say "启动 CodeGraph Manager ...(Ctrl+C 退出;参数透传给 cgm)"
|
|
55
|
+
cgm @args
|