pi-gitnexus-fork 0.7.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/.github/workflows/ci.yml +20 -0
- package/.gitnexusignore +11 -0
- package/.sg-rules/async-function-must-await-or-return.yml +55 -0
- package/.sg-rules/catch-must-log-error.yml +78 -0
- package/.sg-rules/class-must-implement-or-extend.yml +61 -0
- package/.sg-rules/class-property-must-be-readonly.yml +61 -0
- package/.sg-rules/error-must-extend-base.yml +56 -0
- package/.sg-rules/generic-must-be-constrained.yml +60 -0
- package/.sg-rules/import-reexport-risk.yml +9 -0
- package/.sg-rules/missing-session-id-in-api.yml +16 -0
- package/.sg-rules/no-any-in-generic-args.yml +57 -0
- package/.sg-rules/no-await-in-promise-all.yml +28 -0
- package/.sg-rules/no-barrel-export.yml +17 -0
- package/.sg-rules/no-bq-write-in-module.yml +65 -0
- package/.sg-rules/no-console-except-error.yml +27 -0
- package/.sg-rules/no-console-in-server.yml +42 -0
- package/.sg-rules/no-empty-catch.yml +20 -0
- package/.sg-rules/no-empty-function.yml +24 -0
- package/.sg-rules/no-eval.yml +28 -0
- package/.sg-rules/no-explicit-any.yml +34 -0
- package/.sg-rules/no-hardcoded-placeholder-string.yml +23 -0
- package/.sg-rules/no-hardcoded-secrets.yml +32 -0
- package/.sg-rules/no-innerHTML.yml +22 -0
- package/.sg-rules/no-json-parse-without-trycatch.yml +33 -0
- package/.sg-rules/no-magic-numbers.yml +25 -0
- package/.sg-rules/no-nested-ternary.yml +21 -0
- package/.sg-rules/no-non-null-assertion.yml +25 -0
- package/.sg-rules/no-stub-implementation.yml +44 -0
- package/.sg-rules/no-throw-literal.yml +50 -0
- package/.sg-rules/no-todo-comment.yml +24 -0
- package/.sg-rules/no-ts-ignore-comment.yml +48 -0
- package/.sg-rules/no-type-assertion-in-jsx.yml +23 -0
- package/.sg-rules/no-unguarded-trim.yml +24 -0
- package/.sg-rules/no-unknown-without-narrowing.yml +76 -0
- package/.sg-rules/no-unsafe-bracket-access.yml +58 -0
- package/.sg-rules/no-unsafe-type-assertion.yml +45 -0
- package/.sg-rules/switch-must-be-exhaustive.yml +62 -0
- package/.sg-rules/zod-async-refine-without-abort.yml +62 -0
- package/.sg-rules/zod-enum-unsafe-access.yml +59 -0
- package/.sg-rules/zod-nested-object-deep-path.yml +70 -0
- package/.sg-rules/zod-optional-without-default-in-route.yml +50 -0
- package/.sg-rules/zod-parse-not-safe.yml +42 -0
- package/.sg-rules/zod-preprocess-without-fallback.yml +58 -0
- package/.sg-rules/zod-refine-no-return-undefined.yml +54 -0
- package/.sg-rules/zod-transform-without-output-type.yml +52 -0
- package/.sg-sha +1 -0
- package/.sgignore +4 -0
- package/AGENTS.md +1 -0
- package/CHANGELOG.md +99 -0
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/biome.json +25 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +890 -0
- package/coverage/coverage-final.json +12 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/coverage/src/augment-remote.ts.html +274 -0
- package/coverage/src/gitnexus.ts.html +1363 -0
- package/coverage/src/index.html +236 -0
- package/coverage/src/index.ts.html +1561 -0
- package/coverage/src/mcp-client-factory.ts.html +367 -0
- package/coverage/src/mcp-client-stdio.ts.html +736 -0
- package/coverage/src/mcp-client.ts.html +568 -0
- package/coverage/src/remote-mcp-client.ts.html +709 -0
- package/coverage/src/repo-resolver.ts.html +526 -0
- package/coverage/src/tools.ts.html +970 -0
- package/coverage/src/ui/index.html +131 -0
- package/coverage/src/ui/main-menu.ts.html +502 -0
- package/coverage/src/ui/settings-menu.ts.html +460 -0
- package/dist/augment-remote.d.ts +11 -0
- package/dist/augment-remote.js +55 -0
- package/dist/gitnexus.d.ts +103 -0
- package/dist/gitnexus.js +410 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +479 -0
- package/dist/mcp-client-factory.d.ts +19 -0
- package/dist/mcp-client-factory.js +78 -0
- package/dist/mcp-client-stdio.d.ts +35 -0
- package/dist/mcp-client-stdio.js +186 -0
- package/dist/mcp-client.d.ts +45 -0
- package/dist/mcp-client.js +145 -0
- package/dist/remote-mcp-client.d.ts +43 -0
- package/dist/remote-mcp-client.js +181 -0
- package/dist/repo-resolver.d.ts +47 -0
- package/dist/repo-resolver.js +123 -0
- package/dist/tools.d.ts +6 -0
- package/dist/tools.js +230 -0
- package/dist/ui/main-menu.d.ts +33 -0
- package/dist/ui/main-menu.js +102 -0
- package/dist/ui/settings-menu.d.ts +16 -0
- package/dist/ui/settings-menu.js +95 -0
- package/docs/design/remote-mcp-backend.md +153 -0
- package/media/screenshot.png +0 -0
- package/package.json +61 -0
- package/sgconfig.yml +4 -0
- package/skills/gitnexus-debugging/SKILL.md +84 -0
- package/skills/gitnexus-exploring/SKILL.md +73 -0
- package/skills/gitnexus-impact-analysis/SKILL.md +93 -0
- package/skills/gitnexus-pr-review/SKILL.md +109 -0
- package/skills/gitnexus-refactoring/SKILL.md +85 -0
- package/src/augment-remote.ts +63 -0
- package/src/gitnexus.ts +426 -0
- package/src/index.ts +492 -0
- package/src/mcp-client-factory.ts +94 -0
- package/src/mcp-client-stdio.ts +217 -0
- package/src/mcp-client.ts +208 -0
- package/src/remote-mcp-client.ts +250 -0
- package/src/repo-resolver.ts +147 -0
- package/src/tools.ts +295 -0
- package/src/ui/main-menu.ts +139 -0
- package/src/ui/settings-menu.ts +125 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Design: Remote MCP Backend for pi-gitnexus
|
|
2
|
+
|
|
3
|
+
## Problem
|
|
4
|
+
|
|
5
|
+
The upstream `tintinweb/pi-gitnexus` extension uses a local `gitnexus` CLI binary for:
|
|
6
|
+
|
|
7
|
+
1. **Auto-augment hooks** — spawn `gitnexus augment <pattern>` via stdio
|
|
8
|
+
2. **Registered tools** — spawn `gitnexus mcp` via stdio JSON-RPC
|
|
9
|
+
|
|
10
|
+
On this machine:
|
|
11
|
+
|
|
12
|
+
- The npm `gitnexus@1.6.3` binary is a stub (`exit 0`)
|
|
13
|
+
- Even with a working binary, LadybugDB segfaults (Node 22 Docker vs Node 24 host ABI mismatch)
|
|
14
|
+
- A centralized GitNexus server runs on bhd-main2 (`http://100.114.135.99:4747`) and writes `.gitnexus/` indexes locally via shared mount
|
|
15
|
+
- The server exposes MCP tools via StreamableHTTP at `/api/mcp`
|
|
16
|
+
|
|
17
|
+
## Approach: Dual Transport with Auto-Detection
|
|
18
|
+
|
|
19
|
+
Add a `RemoteMcpClient` alongside the existing `StdioMcpClient`. A factory selects based on config:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
mode=auto → probe local binary → works? use stdio : use remote
|
|
23
|
+
mode=local → stdio only (existing behavior)
|
|
24
|
+
mode=remote → StreamableHTTP to server
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Architecture
|
|
28
|
+
|
|
29
|
+
### Config (~/.pi/pi-gitnexus.json)
|
|
30
|
+
|
|
31
|
+
```jsonc
|
|
32
|
+
{
|
|
33
|
+
"mode": "auto", // "auto" | "local" | "remote"
|
|
34
|
+
"serverUrl": "http://100.114.135.99:4747/api/mcp",
|
|
35
|
+
// existing fields...
|
|
36
|
+
"cmd": "", // local command override
|
|
37
|
+
"autoAugment": true,
|
|
38
|
+
"augmentTimeout": 8, // seconds
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### MCP Client Interface
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
interface McpClient {
|
|
46
|
+
callTool(
|
|
47
|
+
name: string,
|
|
48
|
+
args: Record<string, unknown>,
|
|
49
|
+
cwd: string,
|
|
50
|
+
): Promise<string>;
|
|
51
|
+
stop(): void;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Components
|
|
56
|
+
|
|
57
|
+
| Component | File | Purpose |
|
|
58
|
+
| ------------------ | -------------------------------- | --------------------------------------------------- |
|
|
59
|
+
| `McpClientFactory` | `src/mcp-client.ts` (modify) | Extract interface, add factory, keep StdioMcpClient |
|
|
60
|
+
| `RemoteMcpClient` | `src/remote-mcp-client.ts` (new) | StreamableHTTP transport to server |
|
|
61
|
+
| `RepoResolver` | `src/repo-resolver.ts` (new) | Map host cwd → server repo name/path |
|
|
62
|
+
| `AutoMcpClient` | `src/mcp-client.ts` (new) | Probe → select → cache transport |
|
|
63
|
+
| Augment hook | `src/index.ts` (modify) | Use remote client for augment via `query` tool |
|
|
64
|
+
|
|
65
|
+
### Repo Resolution Strategy
|
|
66
|
+
|
|
67
|
+
The server knows repos by container paths (`/workspace/bhd/pi-plugins`) or registered names.
|
|
68
|
+
The host cwd is `/home/bhd/Documents/Projects/bhd/pi-plugins`.
|
|
69
|
+
|
|
70
|
+
Resolution:
|
|
71
|
+
|
|
72
|
+
1. Fetch server registry from `GET /api/repos` (or `list_repos` MCP tool)
|
|
73
|
+
2. Cache locally (in-memory, refreshed per session)
|
|
74
|
+
3. Match host cwd to server repo by:
|
|
75
|
+
a. Git remote URL (most reliable)
|
|
76
|
+
b. Basename of cwd matches basename of server path
|
|
77
|
+
c. Fallback: pass `findGitNexusRoot(cwd)` as repo path
|
|
78
|
+
|
|
79
|
+
### Augment via Query
|
|
80
|
+
|
|
81
|
+
The server doesn't expose `augment` as an MCP tool. In remote mode:
|
|
82
|
+
|
|
83
|
+
- Auto-augment hook calls `callTool('query', { query: pattern, repo, limit: 3 })`
|
|
84
|
+
- This returns relevant graph context — serves the same purpose as augment
|
|
85
|
+
- The agent also has native `gitnexus_query` tool, so this is consistent
|
|
86
|
+
|
|
87
|
+
### Graceful Degradation
|
|
88
|
+
|
|
89
|
+
- Server unreachable → augment hook returns empty (same as current broken state, but explicit)
|
|
90
|
+
- No retry storms — single attempt per hook fire
|
|
91
|
+
- Log warning via `ctx.ui.notify()` on first failure per session
|
|
92
|
+
|
|
93
|
+
## Test Plan
|
|
94
|
+
|
|
95
|
+
### P0 — RemoteMcpClient (src/remote-mcp-client.ts)
|
|
96
|
+
|
|
97
|
+
- StreamableHTTP POST request/response cycle
|
|
98
|
+
- JSON-RPC 2.0 message format
|
|
99
|
+
- MCP initialize handshake
|
|
100
|
+
- Error handling: network failure, timeout, MCP error response
|
|
101
|
+
- Response parsing: text content extraction, truncation
|
|
102
|
+
- Connection reuse across calls
|
|
103
|
+
|
|
104
|
+
### P0 — RepoResolver (src/repo-resolver.ts)
|
|
105
|
+
|
|
106
|
+
- Parse registry response (array of {name, path, remoteUrl})
|
|
107
|
+
- Match host cwd by git remote URL
|
|
108
|
+
- Match host cwd by basename
|
|
109
|
+
- Fallback to findGitNexusRoot
|
|
110
|
+
- Cache behavior (store, invalidate, refresh)
|
|
111
|
+
|
|
112
|
+
### P0 — McpClientFactory (src/mcp-client.ts)
|
|
113
|
+
|
|
114
|
+
- Mode selection: local, remote, auto
|
|
115
|
+
- Auto probe: binary works → stdio, else → remote
|
|
116
|
+
- Config loading with defaults
|
|
117
|
+
|
|
118
|
+
### P1 — Augment hook integration (src/index.ts)
|
|
119
|
+
|
|
120
|
+
- Remote augment via query tool
|
|
121
|
+
- Fallback on error
|
|
122
|
+
- Pattern extraction unchanged
|
|
123
|
+
|
|
124
|
+
### P1 — Config (src/gitnexus.ts)
|
|
125
|
+
|
|
126
|
+
- serverUrl loading
|
|
127
|
+
- mode loading with validation
|
|
128
|
+
- Environment variable overrides
|
|
129
|
+
|
|
130
|
+
### Coverage Target: 60%+
|
|
131
|
+
|
|
132
|
+
## Files to Create/Modify
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
src/
|
|
136
|
+
remote-mcp-client.ts ← NEW
|
|
137
|
+
repo-resolver.ts ← NEW
|
|
138
|
+
mcp-client.ts ← MODIFY (extract interface, add factory + AutoMcpClient)
|
|
139
|
+
gitnexus.ts ← MODIFY (add mode/serverUrl to GitNexusConfig)
|
|
140
|
+
index.ts ← MODIFY (auto-augment uses remote when available)
|
|
141
|
+
tests/
|
|
142
|
+
remote-mcp-client.test.ts ← NEW
|
|
143
|
+
repo-resolver.test.ts ← NEW
|
|
144
|
+
augment-remote.test.ts ← NEW
|
|
145
|
+
mcp-client.test.ts ← MODIFY (add factory tests)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Constraints
|
|
149
|
+
|
|
150
|
+
- NO changes to the GitNexus server — it's a read-only dependency
|
|
151
|
+
- NO new npm dependencies for HTTP (use native `fetch`)
|
|
152
|
+
- Existing tests MUST continue to pass (backward compat)
|
|
153
|
+
- Config is additive — existing fields keep their meaning
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-gitnexus-fork",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "GitNexus knowledge graph integration for pi \u2014 enriches searches with call chains, execution flows, and blast radius",
|
|
5
|
+
"author": "tintinweb",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/buihongduc132/pi-gitnexus.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/buihongduc132/pi-gitnexus#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/buihongduc132/pi-gitnexus/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"pi-package",
|
|
17
|
+
"pi-extension",
|
|
18
|
+
"pi",
|
|
19
|
+
"pi-coding-agent",
|
|
20
|
+
"gitnexus",
|
|
21
|
+
"code-intelligence",
|
|
22
|
+
"knowledge-graph"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"prepublishOnly": "npm run lint && npm run typecheck && npm run build",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"check": "npm run typecheck && npm run test",
|
|
30
|
+
"lint": "biome check src/",
|
|
31
|
+
"lint:fix": "biome check --fix src/"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@mariozechner/pi-ai": ">=0.70",
|
|
35
|
+
"@mariozechner/pi-coding-agent": ">=0.70",
|
|
36
|
+
"typebox": ">=1.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"cross-spawn": "7.0.6"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@biomejs/biome": "^2.4.14",
|
|
43
|
+
"@mariozechner/pi-ai": "^0.72.1",
|
|
44
|
+
"@mariozechner/pi-coding-agent": "^0.72.1",
|
|
45
|
+
"@types/cross-spawn": "6.0.6",
|
|
46
|
+
"@types/node": "^25.6.0",
|
|
47
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
48
|
+
"typebox": "^1.1.37",
|
|
49
|
+
"typescript": "^6.0.3",
|
|
50
|
+
"vitest": "^4.1.5"
|
|
51
|
+
},
|
|
52
|
+
"pi": {
|
|
53
|
+
"extensions": [
|
|
54
|
+
"./src/index.ts"
|
|
55
|
+
],
|
|
56
|
+
"skills": [
|
|
57
|
+
"./skills"
|
|
58
|
+
],
|
|
59
|
+
"image": "https://github.com/tintinweb/pi-gitnexus/raw/master/media/screenshot.png"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/sgconfig.yml
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gitnexus-debugging
|
|
3
|
+
description: "Use when the user is debugging a bug, tracing an error, or asking why something fails. Examples: \"Why is X failing?\", \"Where does this error come from?\", \"Trace this bug\""
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Debugging with GitNexus
|
|
7
|
+
|
|
8
|
+
## When to Use
|
|
9
|
+
|
|
10
|
+
- "Why is this function failing?"
|
|
11
|
+
- "Trace where this error comes from"
|
|
12
|
+
- "Who calls this method?"
|
|
13
|
+
- "This endpoint returns 500"
|
|
14
|
+
- Investigating bugs, errors, or unexpected behavior
|
|
15
|
+
|
|
16
|
+
## Workflow
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
1. gitnexus_query({query: "<error or symptom>"}) → Find related execution flows
|
|
20
|
+
2. gitnexus_context({name: "<suspect>"}) → See callers/callees/processes
|
|
21
|
+
3. gitnexus_cypher({query: "MATCH path..."}) → Custom traces if needed
|
|
22
|
+
4. Read source files to confirm root cause
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> If index is stale → run `/gitnexus analyze` to rebuild.
|
|
26
|
+
|
|
27
|
+
## Debugging Patterns
|
|
28
|
+
|
|
29
|
+
| Symptom | GitNexus Approach |
|
|
30
|
+
| -------------------- | ---------------------------------------------------------- |
|
|
31
|
+
| Error message | `gitnexus_query` for error text → `context` on throw sites |
|
|
32
|
+
| Wrong return value | `context` on the function → trace callees for data flow |
|
|
33
|
+
| Intermittent failure | `context` → look for external calls, async deps |
|
|
34
|
+
| Performance issue | `context` → find symbols with many callers (hot paths) |
|
|
35
|
+
| Recent regression | `gitnexus_detect_changes` to see what your changes affect |
|
|
36
|
+
|
|
37
|
+
## Checklist
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
- [ ] Understand the symptom (error message, unexpected behavior)
|
|
41
|
+
- [ ] gitnexus_query for error text or related code
|
|
42
|
+
- [ ] Identify the suspect function from returned processes
|
|
43
|
+
- [ ] gitnexus_context to see callers and callees
|
|
44
|
+
- [ ] gitnexus_cypher for custom call chain traces if needed
|
|
45
|
+
- [ ] Read source files to confirm root cause
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Tools
|
|
49
|
+
|
|
50
|
+
**gitnexus_query** — find code related to error:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
gitnexus_query({query: "payment validation error"})
|
|
54
|
+
→ Processes: CheckoutFlow, ErrorHandling
|
|
55
|
+
→ Symbols: validatePayment, handlePaymentError, PaymentException
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**gitnexus_context** — full context for a suspect:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
gitnexus_context({name: "validatePayment"})
|
|
62
|
+
→ Incoming calls: processCheckout, webhookHandler
|
|
63
|
+
→ Outgoing calls: verifyCard, fetchRates (external API!)
|
|
64
|
+
→ Processes: CheckoutFlow (step 3/7)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**gitnexus_cypher** — custom call chain traces:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
gitnexus_cypher({query: "MATCH path = (a)-[:CodeRelation {type: 'CALLS'}*1..2]->(b:Function {name: 'validatePayment'}) RETURN [n IN nodes(path) | n.name] AS chain"})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Example: "Payment endpoint returns 500 intermittently"
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
1. gitnexus_query({query: "payment error handling"})
|
|
77
|
+
→ Processes: CheckoutFlow, ErrorHandling
|
|
78
|
+
→ Symbols: validatePayment, handlePaymentError
|
|
79
|
+
|
|
80
|
+
2. gitnexus_context({name: "validatePayment"})
|
|
81
|
+
→ Outgoing calls: verifyCard, fetchRates (external API!)
|
|
82
|
+
|
|
83
|
+
3. Root cause: fetchRates calls external API without proper timeout
|
|
84
|
+
```
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gitnexus-exploring
|
|
3
|
+
description: "Use when the user asks how code works, wants to understand architecture, trace execution flows, or explore unfamiliar parts of the codebase. Examples: \"How does X work?\", \"What calls this function?\", \"Show me the auth flow\""
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Exploring Codebases with GitNexus
|
|
7
|
+
|
|
8
|
+
## When to Use
|
|
9
|
+
|
|
10
|
+
- "How does authentication work?"
|
|
11
|
+
- "What's the project structure?"
|
|
12
|
+
- "Show me the main components"
|
|
13
|
+
- "Where is the database logic?"
|
|
14
|
+
- Understanding code you haven't seen before
|
|
15
|
+
|
|
16
|
+
## Workflow
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
1. gitnexus_list_repos() → Discover indexed repos
|
|
20
|
+
2. gitnexus_query({query: "<what you want to understand>"}) → Find related execution flows
|
|
21
|
+
3. gitnexus_context({name: "<symbol>"}) → Deep dive on specific symbol
|
|
22
|
+
4. Read source files for implementation details
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> If index is stale → run `/gitnexus analyze` to rebuild.
|
|
26
|
+
|
|
27
|
+
## Checklist
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
- [ ] gitnexus_query for the concept you want to understand
|
|
31
|
+
- [ ] Review returned processes (execution flows)
|
|
32
|
+
- [ ] gitnexus_context on key symbols for callers/callees
|
|
33
|
+
- [ ] Read source files for implementation details
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Tools
|
|
37
|
+
|
|
38
|
+
**gitnexus_query** — find execution flows related to a concept:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
gitnexus_query({query: "payment processing"})
|
|
42
|
+
→ Processes: CheckoutFlow, RefundFlow, WebhookHandler
|
|
43
|
+
→ Symbols grouped by flow with file locations
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**gitnexus_context** — 360-degree view of a symbol:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
gitnexus_context({name: "validateUser"})
|
|
50
|
+
→ Incoming calls: loginHandler, apiMiddleware
|
|
51
|
+
→ Outgoing calls: checkToken, getUserById
|
|
52
|
+
→ Processes: LoginFlow (step 2/5), TokenRefresh (step 1/3)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**gitnexus_cypher** — custom graph queries for deeper exploration:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
gitnexus_cypher({query: "MATCH (f:Function)-[:CodeRelation {type: 'CALLS'}]->(g) WHERE f.name = 'main' RETURN g.name, g.filePath"})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Example: "How does payment processing work?"
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
1. gitnexus_query({query: "payment processing"})
|
|
65
|
+
→ CheckoutFlow: processPayment → validateCard → chargeStripe
|
|
66
|
+
→ RefundFlow: initiateRefund → calculateRefund → processRefund
|
|
67
|
+
|
|
68
|
+
2. gitnexus_context({name: "processPayment"})
|
|
69
|
+
→ Incoming: checkoutHandler, webhookHandler
|
|
70
|
+
→ Outgoing: validateCard, chargeStripe, saveTransaction
|
|
71
|
+
|
|
72
|
+
3. Read src/payments/processor.ts for implementation details
|
|
73
|
+
```
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gitnexus-impact-analysis
|
|
3
|
+
description: "Use when the user wants to know what will break if they change something, or needs safety analysis before editing code. Examples: \"Is it safe to change X?\", \"What depends on this?\", \"What will break?\""
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Impact Analysis with GitNexus
|
|
7
|
+
|
|
8
|
+
## When to Use
|
|
9
|
+
|
|
10
|
+
- "Is it safe to change this function?"
|
|
11
|
+
- "What will break if I modify X?"
|
|
12
|
+
- "Show me the blast radius"
|
|
13
|
+
- "Who uses this code?"
|
|
14
|
+
- Before making non-trivial code changes
|
|
15
|
+
- Before committing — to understand what your changes affect
|
|
16
|
+
|
|
17
|
+
## Workflow
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
1. gitnexus_impact({target: "X", direction: "upstream"}) → What depends on this
|
|
21
|
+
2. gitnexus_detect_changes() → Map current git changes to affected flows
|
|
22
|
+
3. Assess risk and report to user
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> If index is stale → run `/gitnexus analyze` to rebuild.
|
|
26
|
+
|
|
27
|
+
## Understanding Output
|
|
28
|
+
|
|
29
|
+
| Depth | Risk Level | Meaning |
|
|
30
|
+
| ----- | ---------------- | ------------------------ |
|
|
31
|
+
| d=1 | **WILL BREAK** | Direct callers/importers |
|
|
32
|
+
| d=2 | LIKELY AFFECTED | Indirect dependencies |
|
|
33
|
+
| d=3 | MAY NEED TESTING | Transitive effects |
|
|
34
|
+
|
|
35
|
+
## Risk Assessment
|
|
36
|
+
|
|
37
|
+
| Affected | Risk |
|
|
38
|
+
| ------------------------------ | -------- |
|
|
39
|
+
| <5 symbols, few processes | LOW |
|
|
40
|
+
| 5-15 symbols, 2-5 processes | MEDIUM |
|
|
41
|
+
| >15 symbols or many processes | HIGH |
|
|
42
|
+
| Critical path (auth, payments) | CRITICAL |
|
|
43
|
+
|
|
44
|
+
## Checklist
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
- [ ] gitnexus_impact({target, direction: "upstream"}) to find dependents
|
|
48
|
+
- [ ] Review d=1 items first (these WILL BREAK)
|
|
49
|
+
- [ ] Check high-confidence (>0.8) dependencies
|
|
50
|
+
- [ ] gitnexus_detect_changes() for pre-commit check
|
|
51
|
+
- [ ] Assess risk level and report to user
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Tools
|
|
55
|
+
|
|
56
|
+
**gitnexus_impact** — primary tool for symbol blast radius:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
gitnexus_impact({
|
|
60
|
+
target: "validateUser",
|
|
61
|
+
direction: "upstream",
|
|
62
|
+
minConfidence: 0.8,
|
|
63
|
+
maxDepth: 3
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
→ d=1 (WILL BREAK):
|
|
67
|
+
- loginHandler (src/auth/login.ts:42) [CALLS, 100%]
|
|
68
|
+
- apiMiddleware (src/api/middleware.ts:15) [CALLS, 100%]
|
|
69
|
+
|
|
70
|
+
→ d=2 (LIKELY AFFECTED):
|
|
71
|
+
- authRouter (src/routes/auth.ts:22) [CALLS, 95%]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**gitnexus_detect_changes** — git-diff based impact analysis:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
gitnexus_detect_changes({scope: "staged"})
|
|
78
|
+
|
|
79
|
+
→ Changed: 5 symbols in 3 files
|
|
80
|
+
→ Affected: LoginFlow, TokenRefresh, APIMiddlewarePipeline
|
|
81
|
+
→ Risk: MEDIUM
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Example: "What breaks if I change validateUser?"
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
1. gitnexus_impact({target: "validateUser", direction: "upstream"})
|
|
88
|
+
→ d=1: loginHandler, apiMiddleware (WILL BREAK)
|
|
89
|
+
→ d=2: authRouter, sessionManager (LIKELY AFFECTED)
|
|
90
|
+
|
|
91
|
+
2. Risk: 2 direct callers, 2 processes = MEDIUM
|
|
92
|
+
→ Recommend: update loginHandler and apiMiddleware first, then run tests
|
|
93
|
+
```
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gitnexus-pr-review
|
|
3
|
+
description: "Use when the user wants to review a pull request, understand what a PR changes, assess risk of merging, or check for missing test coverage. Examples: \"Review this PR\", \"What does PR #42 change?\", \"Is this PR safe to merge?\""
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# PR Review with GitNexus
|
|
7
|
+
|
|
8
|
+
## When to Use
|
|
9
|
+
|
|
10
|
+
- "Review this PR"
|
|
11
|
+
- "What does PR #42 change?"
|
|
12
|
+
- "Is this safe to merge?"
|
|
13
|
+
- "What's the blast radius of this PR?"
|
|
14
|
+
- Reviewing someone else's code changes before merge
|
|
15
|
+
|
|
16
|
+
## Workflow
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
1. gh pr diff <number> → Get the raw diff
|
|
20
|
+
2. gitnexus_detect_changes({scope: "compare", base_ref: "main"}) → Map diff to affected flows
|
|
21
|
+
3. gitnexus_impact({target: "<symbol>", direction: "upstream"}) → Blast radius per change
|
|
22
|
+
4. gitnexus_context({name: "<key symbol>"}) → Understand callers/callees
|
|
23
|
+
5. Summarize findings with risk assessment
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
> If index is stale → run `/gitnexus analyze` before reviewing.
|
|
27
|
+
|
|
28
|
+
## Checklist
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
- [ ] Fetch PR diff (gh pr diff or git diff base...head)
|
|
32
|
+
- [ ] gitnexus_detect_changes to map changes to affected execution flows
|
|
33
|
+
- [ ] gitnexus_impact on each non-trivial changed symbol
|
|
34
|
+
- [ ] Review d=1 items (WILL BREAK) — are callers updated?
|
|
35
|
+
- [ ] gitnexus_context on key changed symbols to understand full picture
|
|
36
|
+
- [ ] Check if affected processes have test coverage
|
|
37
|
+
- [ ] Assess overall risk level
|
|
38
|
+
- [ ] Write review summary with findings
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Review Dimensions
|
|
42
|
+
|
|
43
|
+
| Dimension | How GitNexus Helps |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| **Correctness** | `context` shows callers — are they all compatible with the change? |
|
|
46
|
+
| **Blast radius** | `impact` shows d=1/d=2/d=3 dependents — anything missed? |
|
|
47
|
+
| **Completeness** | `detect_changes` shows all affected flows — are they all handled? |
|
|
48
|
+
| **Test coverage** | `impact({includeTests: true})` shows which tests touch changed code |
|
|
49
|
+
| **Breaking changes** | d=1 upstream items that aren't updated in the PR = potential breakage |
|
|
50
|
+
|
|
51
|
+
## Risk Assessment
|
|
52
|
+
|
|
53
|
+
| Signal | Risk |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| Changes touch <3 symbols, 0-1 processes | LOW |
|
|
56
|
+
| Changes touch 3-10 symbols, 2-5 processes | MEDIUM |
|
|
57
|
+
| Changes touch >10 symbols or many processes | HIGH |
|
|
58
|
+
| Changes touch auth, payments, or data integrity code | CRITICAL |
|
|
59
|
+
| d=1 callers exist outside the PR diff | Potential breakage — flag it |
|
|
60
|
+
|
|
61
|
+
## Review Output Format
|
|
62
|
+
|
|
63
|
+
```markdown
|
|
64
|
+
## PR Review: <title>
|
|
65
|
+
|
|
66
|
+
**Risk: LOW / MEDIUM / HIGH / CRITICAL**
|
|
67
|
+
|
|
68
|
+
### Changes Summary
|
|
69
|
+
- <N> symbols changed across <M> files
|
|
70
|
+
- <P> execution flows affected
|
|
71
|
+
|
|
72
|
+
### Findings
|
|
73
|
+
1. **[severity]** Description of finding
|
|
74
|
+
- Evidence from GitNexus tools
|
|
75
|
+
- Affected callers/flows
|
|
76
|
+
|
|
77
|
+
### Missing Coverage
|
|
78
|
+
- Callers not updated in PR: ...
|
|
79
|
+
- Untested flows: ...
|
|
80
|
+
|
|
81
|
+
### Recommendation
|
|
82
|
+
APPROVE / REQUEST CHANGES / NEEDS DISCUSSION
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Example: "Review PR #42"
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
1. gh pr diff 42
|
|
89
|
+
→ 4 files changed: payments.ts, checkout.ts, types.ts, utils.ts
|
|
90
|
+
|
|
91
|
+
2. gitnexus_detect_changes({scope: "compare", base_ref: "main"})
|
|
92
|
+
→ Changed symbols: validatePayment, PaymentInput, formatAmount
|
|
93
|
+
→ Affected processes: CheckoutFlow, RefundFlow
|
|
94
|
+
→ Risk: MEDIUM
|
|
95
|
+
|
|
96
|
+
3. gitnexus_impact({target: "validatePayment", direction: "upstream"})
|
|
97
|
+
→ d=1: processCheckout, webhookHandler (WILL BREAK)
|
|
98
|
+
→ webhookHandler is NOT in the PR diff — potential breakage!
|
|
99
|
+
|
|
100
|
+
4. gitnexus_impact({target: "PaymentInput", direction: "upstream"})
|
|
101
|
+
→ d=1: validatePayment (in PR), createPayment (NOT in PR)
|
|
102
|
+
→ createPayment uses the old PaymentInput shape — breaking change!
|
|
103
|
+
|
|
104
|
+
5. Review summary:
|
|
105
|
+
- MEDIUM risk — 3 changed symbols affect 2 execution flows
|
|
106
|
+
- BUG: webhookHandler not updated for new validatePayment signature
|
|
107
|
+
- BUG: createPayment depends on changed PaymentInput type
|
|
108
|
+
- OK: formatAmount change is backwards-compatible
|
|
109
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gitnexus-refactoring
|
|
3
|
+
description: "Use when the user wants to rename, extract, split, move, or restructure code safely. Examples: \"Rename this function\", \"Extract this into a module\", \"Refactor this class\", \"Move this to a separate file\""
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Refactoring with GitNexus
|
|
7
|
+
|
|
8
|
+
## When to Use
|
|
9
|
+
|
|
10
|
+
- "Rename this function safely"
|
|
11
|
+
- "Extract this into a module"
|
|
12
|
+
- "Split this service"
|
|
13
|
+
- "Move this to a new file"
|
|
14
|
+
- Any task involving renaming, extracting, splitting, or restructuring code
|
|
15
|
+
|
|
16
|
+
## Workflow
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
1. gitnexus_impact({target: "X", direction: "upstream"}) → Map all dependents
|
|
20
|
+
2. gitnexus_query({query: "X"}) → Find execution flows involving X
|
|
21
|
+
3. gitnexus_context({name: "X"}) → See all incoming/outgoing refs
|
|
22
|
+
4. Plan update order: interfaces → implementations → callers → tests
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> If index is stale → run `/gitnexus analyze` to rebuild.
|
|
26
|
+
|
|
27
|
+
## Checklists
|
|
28
|
+
|
|
29
|
+
### Rename Symbol
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
- [ ] gitnexus_rename({symbol_name: "oldName", new_name: "newName", dry_run: true}) — preview all edits
|
|
33
|
+
- [ ] Review graph edits (high confidence) and ast_search edits (review carefully)
|
|
34
|
+
- [ ] If satisfied: gitnexus_rename({..., dry_run: false}) — apply edits
|
|
35
|
+
- [ ] gitnexus_detect_changes() — verify only expected files changed
|
|
36
|
+
- [ ] Run tests for affected processes
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Extract Module
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
- [ ] gitnexus_context({name: target}) — see all incoming/outgoing refs
|
|
43
|
+
- [ ] gitnexus_impact({target, direction: "upstream"}) — find all external callers
|
|
44
|
+
- [ ] Define new module interface
|
|
45
|
+
- [ ] Extract code, update imports
|
|
46
|
+
- [ ] gitnexus_detect_changes() — verify affected scope
|
|
47
|
+
- [ ] Run tests for affected processes
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Split Function/Service
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
- [ ] gitnexus_context({name: target}) — understand all callees
|
|
54
|
+
- [ ] Group callees by responsibility
|
|
55
|
+
- [ ] gitnexus_impact({target, direction: "upstream"}) — map callers to update
|
|
56
|
+
- [ ] Create new functions/services
|
|
57
|
+
- [ ] Update callers
|
|
58
|
+
- [ ] gitnexus_detect_changes() — verify affected scope
|
|
59
|
+
- [ ] Run tests for affected processes
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Risk Rules
|
|
63
|
+
|
|
64
|
+
| Risk Factor | Mitigation |
|
|
65
|
+
| ------------------- | ----------------------------------------- |
|
|
66
|
+
| Many callers (>5) | Use gitnexus_rename for automated updates |
|
|
67
|
+
| Cross-area refs | Use detect_changes after to verify scope |
|
|
68
|
+
| String/dynamic refs | gitnexus_query to find them |
|
|
69
|
+
| External/public API | Version and deprecate properly |
|
|
70
|
+
|
|
71
|
+
## Example: Rename `validateUser` to `authenticateUser`
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
1. gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
|
|
75
|
+
→ 12 edits: 10 graph (safe), 2 ast_search (review)
|
|
76
|
+
|
|
77
|
+
2. Review ast_search edits (config.json: dynamic reference!)
|
|
78
|
+
|
|
79
|
+
3. gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: false})
|
|
80
|
+
→ Applied 12 edits across 8 files
|
|
81
|
+
|
|
82
|
+
4. gitnexus_detect_changes({scope: "all"})
|
|
83
|
+
→ Affected: LoginFlow, TokenRefresh
|
|
84
|
+
→ Risk: MEDIUM — run tests for these flows
|
|
85
|
+
```
|