gitnexus 1.3.2 → 1.3.4
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/dist/cli/ai-context.js +23 -52
- package/dist/cli/analyze.js +4 -1
- package/dist/cli/index.js +1 -0
- package/dist/cli/mcp.js +11 -22
- package/dist/cli/serve.d.ts +1 -0
- package/dist/cli/serve.js +2 -1
- package/dist/cli/setup.js +2 -2
- package/dist/cli/wiki.js +6 -2
- package/dist/config/supported-languages.d.ts +2 -1
- package/dist/config/supported-languages.js +1 -1
- package/dist/core/embeddings/embedder.js +40 -1
- package/dist/core/graph/types.d.ts +2 -0
- package/dist/core/ingestion/entry-point-scoring.js +26 -1
- package/dist/core/ingestion/filesystem-walker.js +3 -3
- package/dist/core/ingestion/framework-detection.d.ts +12 -4
- package/dist/core/ingestion/framework-detection.js +105 -5
- package/dist/core/ingestion/import-processor.js +77 -0
- package/dist/core/ingestion/parsing-processor.js +51 -9
- package/dist/core/ingestion/process-processor.js +7 -1
- package/dist/core/ingestion/tree-sitter-queries.d.ts +1 -0
- package/dist/core/ingestion/tree-sitter-queries.js +361 -282
- package/dist/core/ingestion/utils.js +6 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +3 -0
- package/dist/core/ingestion/workers/parse-worker.js +192 -1
- package/dist/core/kuzu/csv-generator.js +4 -2
- package/dist/core/kuzu/kuzu-adapter.d.ts +9 -0
- package/dist/core/kuzu/kuzu-adapter.js +68 -9
- package/dist/core/kuzu/schema.d.ts +6 -6
- package/dist/core/kuzu/schema.js +8 -0
- package/dist/core/tree-sitter/parser-loader.js +2 -0
- package/dist/core/wiki/generator.js +2 -2
- package/dist/mcp/local/local-backend.js +25 -13
- package/dist/mcp/server.d.ts +9 -0
- package/dist/mcp/server.js +13 -2
- package/dist/mcp/staleness.js +2 -2
- package/dist/server/api.d.ts +7 -5
- package/dist/server/api.js +145 -127
- package/dist/server/mcp-http.d.ts +13 -0
- package/dist/server/mcp-http.js +100 -0
- package/package.json +2 -1
- package/skills/gitnexus-cli.md +82 -0
- package/skills/{debugging.md → gitnexus-debugging.md} +12 -8
- package/skills/{exploring.md → gitnexus-exploring.md} +10 -7
- package/skills/gitnexus-guide.md +64 -0
- package/skills/{impact-analysis.md → gitnexus-impact-analysis.md} +14 -11
- package/skills/{refactoring.md → gitnexus-refactoring.md} +15 -7
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP over HTTP
|
|
3
|
+
*
|
|
4
|
+
* Mounts the GitNexus MCP server on Express using StreamableHTTP transport.
|
|
5
|
+
* Each connecting client gets its own stateful session; the LocalBackend
|
|
6
|
+
* is shared across all sessions (thread-safe — lazy KuzuDB per repo).
|
|
7
|
+
*
|
|
8
|
+
* Sessions are cleaned up on explicit close or after SESSION_TTL_MS of inactivity
|
|
9
|
+
* (guards against network drops that never trigger onclose).
|
|
10
|
+
*/
|
|
11
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
12
|
+
import { createMCPServer } from '../mcp/server.js';
|
|
13
|
+
import { randomUUID } from 'crypto';
|
|
14
|
+
/** Idle sessions are evicted after 30 minutes */
|
|
15
|
+
const SESSION_TTL_MS = 30 * 60 * 1000;
|
|
16
|
+
/** Cleanup sweep runs every 5 minutes */
|
|
17
|
+
const CLEANUP_INTERVAL_MS = 5 * 60 * 1000;
|
|
18
|
+
export function mountMCPEndpoints(app, backend) {
|
|
19
|
+
const sessions = new Map();
|
|
20
|
+
// Periodic cleanup of idle sessions (guards against network drops)
|
|
21
|
+
const cleanupTimer = setInterval(() => {
|
|
22
|
+
const now = Date.now();
|
|
23
|
+
for (const [id, session] of sessions) {
|
|
24
|
+
if (now - session.lastActivity > SESSION_TTL_MS) {
|
|
25
|
+
try {
|
|
26
|
+
session.server.close();
|
|
27
|
+
}
|
|
28
|
+
catch { }
|
|
29
|
+
sessions.delete(id);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}, CLEANUP_INTERVAL_MS);
|
|
33
|
+
if (cleanupTimer && typeof cleanupTimer === 'object' && 'unref' in cleanupTimer) {
|
|
34
|
+
cleanupTimer.unref();
|
|
35
|
+
}
|
|
36
|
+
const handleMcpRequest = async (req, res) => {
|
|
37
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
38
|
+
if (sessionId && sessions.has(sessionId)) {
|
|
39
|
+
// Existing session — delegate to its transport
|
|
40
|
+
const session = sessions.get(sessionId);
|
|
41
|
+
session.lastActivity = Date.now();
|
|
42
|
+
await session.transport.handleRequest(req, res, req.body);
|
|
43
|
+
}
|
|
44
|
+
else if (sessionId) {
|
|
45
|
+
// Unknown/expired session ID — tell client to re-initialize (per MCP spec)
|
|
46
|
+
res.status(404).json({
|
|
47
|
+
jsonrpc: '2.0',
|
|
48
|
+
error: { code: -32001, message: 'Session not found. Re-initialize.' },
|
|
49
|
+
id: null,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else if (req.method === 'POST') {
|
|
53
|
+
// No session ID — new client initializing
|
|
54
|
+
const transport = new StreamableHTTPServerTransport({
|
|
55
|
+
sessionIdGenerator: () => randomUUID(),
|
|
56
|
+
});
|
|
57
|
+
const server = createMCPServer(backend);
|
|
58
|
+
await server.connect(transport);
|
|
59
|
+
await transport.handleRequest(req, res, req.body);
|
|
60
|
+
if (transport.sessionId) {
|
|
61
|
+
sessions.set(transport.sessionId, { server, transport, lastActivity: Date.now() });
|
|
62
|
+
transport.onclose = () => {
|
|
63
|
+
sessions.delete(transport.sessionId);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
res.status(400).json({
|
|
69
|
+
jsonrpc: '2.0',
|
|
70
|
+
error: { code: -32000, message: 'No valid session. Send a POST to initialize.' },
|
|
71
|
+
id: null,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
app.all('/api/mcp', (req, res) => {
|
|
76
|
+
void handleMcpRequest(req, res).catch((err) => {
|
|
77
|
+
console.error('MCP HTTP request failed:', err);
|
|
78
|
+
if (res.headersSent)
|
|
79
|
+
return;
|
|
80
|
+
res.status(500).json({
|
|
81
|
+
jsonrpc: '2.0',
|
|
82
|
+
error: { code: -32000, message: 'Internal MCP server error' },
|
|
83
|
+
id: null,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
const cleanup = async () => {
|
|
88
|
+
clearInterval(cleanupTimer);
|
|
89
|
+
const closers = [...sessions.values()].map(async (session) => {
|
|
90
|
+
try {
|
|
91
|
+
await Promise.resolve(session.server.close());
|
|
92
|
+
}
|
|
93
|
+
catch { }
|
|
94
|
+
});
|
|
95
|
+
sessions.clear();
|
|
96
|
+
await Promise.allSettled(closers);
|
|
97
|
+
};
|
|
98
|
+
console.log('MCP HTTP endpoints mounted at /api/mcp');
|
|
99
|
+
return cleanup;
|
|
100
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitnexus",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "Graph-powered code intelligence for AI agents. Index any codebase, query via MCP or CLI.",
|
|
5
5
|
"author": "Abhigyan Patwari",
|
|
6
6
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"tree-sitter-go": "^0.21.0",
|
|
63
63
|
"tree-sitter-java": "^0.21.0",
|
|
64
64
|
"tree-sitter-javascript": "^0.21.0",
|
|
65
|
+
"tree-sitter-php": "^0.23.12",
|
|
65
66
|
"tree-sitter-python": "^0.21.0",
|
|
66
67
|
"tree-sitter-rust": "^0.21.0",
|
|
67
68
|
"tree-sitter-typescript": "^0.21.0",
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gitnexus-cli
|
|
3
|
+
description: "Use when the user needs to run GitNexus CLI commands like analyze/index a repo, check status, clean the index, generate a wiki, or list indexed repos. Examples: \"Index this repo\", \"Reanalyze the codebase\", \"Generate a wiki\""
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# GitNexus CLI Commands
|
|
7
|
+
|
|
8
|
+
All commands work via `npx` — no global install required.
|
|
9
|
+
|
|
10
|
+
## Commands
|
|
11
|
+
|
|
12
|
+
### analyze — Build or refresh the index
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx gitnexus analyze
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Run from the project root. This parses all source files, builds the knowledge graph, writes it to `.gitnexus/`, and generates CLAUDE.md / AGENTS.md context files.
|
|
19
|
+
|
|
20
|
+
| Flag | Effect |
|
|
21
|
+
| -------------- | ---------------------------------------------------------------- |
|
|
22
|
+
| `--force` | Force full re-index even if up to date |
|
|
23
|
+
| `--embeddings` | Enable embedding generation for semantic search (off by default) |
|
|
24
|
+
|
|
25
|
+
**When to run:** First time in a project, after major code changes, or when `gitnexus://repo/{name}/context` reports the index is stale.
|
|
26
|
+
|
|
27
|
+
### status — Check index freshness
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx gitnexus status
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Shows whether the current repo has a GitNexus index, when it was last updated, and symbol/relationship counts. Use this to check if re-indexing is needed.
|
|
34
|
+
|
|
35
|
+
### clean — Delete the index
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx gitnexus clean
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Deletes the `.gitnexus/` directory and unregisters the repo from the global registry. Use before re-indexing if the index is corrupt or after removing GitNexus from a project.
|
|
42
|
+
|
|
43
|
+
| Flag | Effect |
|
|
44
|
+
| --------- | ------------------------------------------------- |
|
|
45
|
+
| `--force` | Skip confirmation prompt |
|
|
46
|
+
| `--all` | Clean all indexed repos, not just the current one |
|
|
47
|
+
|
|
48
|
+
### wiki — Generate documentation from the graph
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx gitnexus wiki
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Generates repository documentation from the knowledge graph using an LLM. Requires an API key (saved to `~/.gitnexus/config.json` on first use).
|
|
55
|
+
|
|
56
|
+
| Flag | Effect |
|
|
57
|
+
| ------------------- | ----------------------------------------- |
|
|
58
|
+
| `--force` | Force full regeneration |
|
|
59
|
+
| `--model <model>` | LLM model (default: minimax/minimax-m2.5) |
|
|
60
|
+
| `--base-url <url>` | LLM API base URL |
|
|
61
|
+
| `--api-key <key>` | LLM API key |
|
|
62
|
+
| `--concurrency <n>` | Parallel LLM calls (default: 3) |
|
|
63
|
+
| `--gist` | Publish wiki as a public GitHub Gist |
|
|
64
|
+
|
|
65
|
+
### list — Show all indexed repos
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npx gitnexus list
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Lists all repositories registered in `~/.gitnexus/registry.json`. The MCP `list_repos` tool provides the same information.
|
|
72
|
+
|
|
73
|
+
## After Indexing
|
|
74
|
+
|
|
75
|
+
1. **Read `gitnexus://repo/{name}/context`** to verify the index loaded
|
|
76
|
+
2. Use the other GitNexus skills (`exploring`, `debugging`, `impact-analysis`, `refactoring`) for your task
|
|
77
|
+
|
|
78
|
+
## Troubleshooting
|
|
79
|
+
|
|
80
|
+
- **"Not inside a git repository"**: Run from a directory inside a git repo
|
|
81
|
+
- **Index is stale after re-analyzing**: Restart Claude Code to reload the MCP server
|
|
82
|
+
- **Embeddings slow**: Omit `--embeddings` (it's off by default) or set `OPENAI_API_KEY` for faster API-based embedding
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: gitnexus-debugging
|
|
3
|
-
description:
|
|
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
4
|
---
|
|
5
5
|
|
|
6
6
|
# Debugging with GitNexus
|
|
7
7
|
|
|
8
8
|
## When to Use
|
|
9
|
+
|
|
9
10
|
- "Why is this function failing?"
|
|
10
11
|
- "Trace where this error comes from"
|
|
11
12
|
- "Who calls this method?"
|
|
@@ -37,17 +38,18 @@ description: Trace bugs through call chains using knowledge graph
|
|
|
37
38
|
|
|
38
39
|
## Debugging Patterns
|
|
39
40
|
|
|
40
|
-
| Symptom
|
|
41
|
-
|
|
42
|
-
| Error message
|
|
43
|
-
| Wrong return value
|
|
44
|
-
| Intermittent failure | `context` → look for external calls, async deps
|
|
45
|
-
| Performance issue
|
|
46
|
-
| Recent regression
|
|
41
|
+
| Symptom | GitNexus Approach |
|
|
42
|
+
| -------------------- | ---------------------------------------------------------- |
|
|
43
|
+
| Error message | `gitnexus_query` for error text → `context` on throw sites |
|
|
44
|
+
| Wrong return value | `context` on the function → trace callees for data flow |
|
|
45
|
+
| Intermittent failure | `context` → look for external calls, async deps |
|
|
46
|
+
| Performance issue | `context` → find symbols with many callers (hot paths) |
|
|
47
|
+
| Recent regression | `detect_changes` to see what your changes affect |
|
|
47
48
|
|
|
48
49
|
## Tools
|
|
49
50
|
|
|
50
51
|
**gitnexus_query** — find code related to error:
|
|
52
|
+
|
|
51
53
|
```
|
|
52
54
|
gitnexus_query({query: "payment validation error"})
|
|
53
55
|
→ Processes: CheckoutFlow, ErrorHandling
|
|
@@ -55,6 +57,7 @@ gitnexus_query({query: "payment validation error"})
|
|
|
55
57
|
```
|
|
56
58
|
|
|
57
59
|
**gitnexus_context** — full context for a suspect:
|
|
60
|
+
|
|
58
61
|
```
|
|
59
62
|
gitnexus_context({name: "validatePayment"})
|
|
60
63
|
→ Incoming calls: processCheckout, webhookHandler
|
|
@@ -63,6 +66,7 @@ gitnexus_context({name: "validatePayment"})
|
|
|
63
66
|
```
|
|
64
67
|
|
|
65
68
|
**gitnexus_cypher** — custom call chain traces:
|
|
69
|
+
|
|
66
70
|
```cypher
|
|
67
71
|
MATCH path = (a)-[:CodeRelation {type: 'CALLS'}*1..2]->(b:Function {name: "validatePayment"})
|
|
68
72
|
RETURN [n IN nodes(path) | n.name] AS chain
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: gitnexus-exploring
|
|
3
|
-
description:
|
|
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
4
|
---
|
|
5
5
|
|
|
6
6
|
# Exploring Codebases with GitNexus
|
|
7
7
|
|
|
8
8
|
## When to Use
|
|
9
|
+
|
|
9
10
|
- "How does authentication work?"
|
|
10
11
|
- "What's the project structure?"
|
|
11
12
|
- "Show me the main components"
|
|
@@ -37,16 +38,17 @@ description: Navigate unfamiliar code using GitNexus knowledge graph
|
|
|
37
38
|
|
|
38
39
|
## Resources
|
|
39
40
|
|
|
40
|
-
| Resource
|
|
41
|
-
|
|
42
|
-
| `gitnexus://repo/{name}/context`
|
|
43
|
-
| `gitnexus://repo/{name}/clusters`
|
|
44
|
-
| `gitnexus://repo/{name}/cluster/{name}` | Area members with file paths (~500 tokens)
|
|
45
|
-
| `gitnexus://repo/{name}/process/{name}` | Step-by-step execution trace (~200 tokens)
|
|
41
|
+
| Resource | What you get |
|
|
42
|
+
| --------------------------------------- | ------------------------------------------------------- |
|
|
43
|
+
| `gitnexus://repo/{name}/context` | Stats, staleness warning (~150 tokens) |
|
|
44
|
+
| `gitnexus://repo/{name}/clusters` | All functional areas with cohesion scores (~300 tokens) |
|
|
45
|
+
| `gitnexus://repo/{name}/cluster/{name}` | Area members with file paths (~500 tokens) |
|
|
46
|
+
| `gitnexus://repo/{name}/process/{name}` | Step-by-step execution trace (~200 tokens) |
|
|
46
47
|
|
|
47
48
|
## Tools
|
|
48
49
|
|
|
49
50
|
**gitnexus_query** — find execution flows related to a concept:
|
|
51
|
+
|
|
50
52
|
```
|
|
51
53
|
gitnexus_query({query: "payment processing"})
|
|
52
54
|
→ Processes: CheckoutFlow, RefundFlow, WebhookHandler
|
|
@@ -54,6 +56,7 @@ gitnexus_query({query: "payment processing"})
|
|
|
54
56
|
```
|
|
55
57
|
|
|
56
58
|
**gitnexus_context** — 360-degree view of a symbol:
|
|
59
|
+
|
|
57
60
|
```
|
|
58
61
|
gitnexus_context({name: "validateUser"})
|
|
59
62
|
→ Incoming calls: loginHandler, apiMiddleware
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gitnexus-guide
|
|
3
|
+
description: "Use when the user asks about GitNexus itself — available tools, how to query the knowledge graph, MCP resources, graph schema, or workflow reference. Examples: \"What GitNexus tools are available?\", \"How do I use GitNexus?\""
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# GitNexus Guide
|
|
7
|
+
|
|
8
|
+
Quick reference for all GitNexus MCP tools, resources, and the knowledge graph schema.
|
|
9
|
+
|
|
10
|
+
## Always Start Here
|
|
11
|
+
|
|
12
|
+
For any task involving code understanding, debugging, impact analysis, or refactoring:
|
|
13
|
+
|
|
14
|
+
1. **Read `gitnexus://repo/{name}/context`** — codebase overview + check index freshness
|
|
15
|
+
2. **Match your task to a skill below** and **read that skill file**
|
|
16
|
+
3. **Follow the skill's workflow and checklist**
|
|
17
|
+
|
|
18
|
+
> If step 1 warns the index is stale, run `npx gitnexus analyze` in the terminal first.
|
|
19
|
+
|
|
20
|
+
## Skills
|
|
21
|
+
|
|
22
|
+
| Task | Skill to read |
|
|
23
|
+
| -------------------------------------------- | ------------------- |
|
|
24
|
+
| Understand architecture / "How does X work?" | `gitnexus-exploring` |
|
|
25
|
+
| Blast radius / "What breaks if I change X?" | `gitnexus-impact-analysis` |
|
|
26
|
+
| Trace bugs / "Why is X failing?" | `gitnexus-debugging` |
|
|
27
|
+
| Rename / extract / split / refactor | `gitnexus-refactoring` |
|
|
28
|
+
| Tools, resources, schema reference | `gitnexus-guide` (this file) |
|
|
29
|
+
| Index, status, clean, wiki CLI commands | `gitnexus-cli` |
|
|
30
|
+
|
|
31
|
+
## Tools Reference
|
|
32
|
+
|
|
33
|
+
| Tool | What it gives you |
|
|
34
|
+
| ---------------- | ------------------------------------------------------------------------ |
|
|
35
|
+
| `query` | Process-grouped code intelligence — execution flows related to a concept |
|
|
36
|
+
| `context` | 360-degree symbol view — categorized refs, processes it participates in |
|
|
37
|
+
| `impact` | Symbol blast radius — what breaks at depth 1/2/3 with confidence |
|
|
38
|
+
| `detect_changes` | Git-diff impact — what do your current changes affect |
|
|
39
|
+
| `rename` | Multi-file coordinated rename with confidence-tagged edits |
|
|
40
|
+
| `cypher` | Raw graph queries (read `gitnexus://repo/{name}/schema` first) |
|
|
41
|
+
| `list_repos` | Discover indexed repos |
|
|
42
|
+
|
|
43
|
+
## Resources Reference
|
|
44
|
+
|
|
45
|
+
Lightweight reads (~100-500 tokens) for navigation:
|
|
46
|
+
|
|
47
|
+
| Resource | Content |
|
|
48
|
+
| ---------------------------------------------- | ----------------------------------------- |
|
|
49
|
+
| `gitnexus://repo/{name}/context` | Stats, staleness check |
|
|
50
|
+
| `gitnexus://repo/{name}/clusters` | All functional areas with cohesion scores |
|
|
51
|
+
| `gitnexus://repo/{name}/cluster/{clusterName}` | Area members |
|
|
52
|
+
| `gitnexus://repo/{name}/processes` | All execution flows |
|
|
53
|
+
| `gitnexus://repo/{name}/process/{processName}` | Step-by-step trace |
|
|
54
|
+
| `gitnexus://repo/{name}/schema` | Graph schema for Cypher |
|
|
55
|
+
|
|
56
|
+
## Graph Schema
|
|
57
|
+
|
|
58
|
+
**Nodes:** File, Function, Class, Interface, Method, Community, Process
|
|
59
|
+
**Edges (via CodeRelation.type):** CALLS, IMPORTS, EXTENDS, IMPLEMENTS, DEFINES, MEMBER_OF, STEP_IN_PROCESS
|
|
60
|
+
|
|
61
|
+
```cypher
|
|
62
|
+
MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "myFunc"})
|
|
63
|
+
RETURN caller.name, caller.filePath
|
|
64
|
+
```
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: gitnexus-impact-analysis
|
|
3
|
-
description:
|
|
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
4
|
---
|
|
5
5
|
|
|
6
6
|
# Impact Analysis with GitNexus
|
|
7
7
|
|
|
8
8
|
## When to Use
|
|
9
|
+
|
|
9
10
|
- "Is it safe to change this function?"
|
|
10
11
|
- "What will break if I modify X?"
|
|
11
12
|
- "Show me the blast radius"
|
|
@@ -37,24 +38,25 @@ description: Analyze blast radius before making code changes
|
|
|
37
38
|
|
|
38
39
|
## Understanding Output
|
|
39
40
|
|
|
40
|
-
| Depth | Risk Level
|
|
41
|
-
|
|
42
|
-
| d=1
|
|
43
|
-
| d=2
|
|
44
|
-
| d=3
|
|
41
|
+
| Depth | Risk Level | Meaning |
|
|
42
|
+
| ----- | ---------------- | ------------------------ |
|
|
43
|
+
| d=1 | **WILL BREAK** | Direct callers/importers |
|
|
44
|
+
| d=2 | LIKELY AFFECTED | Indirect dependencies |
|
|
45
|
+
| d=3 | MAY NEED TESTING | Transitive effects |
|
|
45
46
|
|
|
46
47
|
## Risk Assessment
|
|
47
48
|
|
|
48
|
-
| Affected
|
|
49
|
-
|
|
50
|
-
| <5 symbols, few processes
|
|
51
|
-
| 5-15 symbols, 2-5 processes
|
|
52
|
-
| >15 symbols or many processes
|
|
49
|
+
| Affected | Risk |
|
|
50
|
+
| ------------------------------ | -------- |
|
|
51
|
+
| <5 symbols, few processes | LOW |
|
|
52
|
+
| 5-15 symbols, 2-5 processes | MEDIUM |
|
|
53
|
+
| >15 symbols or many processes | HIGH |
|
|
53
54
|
| Critical path (auth, payments) | CRITICAL |
|
|
54
55
|
|
|
55
56
|
## Tools
|
|
56
57
|
|
|
57
58
|
**gitnexus_impact** — the primary tool for symbol blast radius:
|
|
59
|
+
|
|
58
60
|
```
|
|
59
61
|
gitnexus_impact({
|
|
60
62
|
target: "validateUser",
|
|
@@ -72,6 +74,7 @@ gitnexus_impact({
|
|
|
72
74
|
```
|
|
73
75
|
|
|
74
76
|
**gitnexus_detect_changes** — git-diff based impact analysis:
|
|
77
|
+
|
|
75
78
|
```
|
|
76
79
|
gitnexus_detect_changes({scope: "staged"})
|
|
77
80
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: gitnexus-refactoring
|
|
3
|
-
description:
|
|
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
4
|
---
|
|
5
5
|
|
|
6
6
|
# Refactoring with GitNexus
|
|
7
7
|
|
|
8
8
|
## When to Use
|
|
9
|
+
|
|
9
10
|
- "Rename this function safely"
|
|
10
11
|
- "Extract this into a module"
|
|
11
12
|
- "Split this service"
|
|
@@ -26,6 +27,7 @@ description: Plan safe refactors using blast radius and dependency mapping
|
|
|
26
27
|
## Checklists
|
|
27
28
|
|
|
28
29
|
### Rename Symbol
|
|
30
|
+
|
|
29
31
|
```
|
|
30
32
|
- [ ] gitnexus_rename({symbol_name: "oldName", new_name: "newName", dry_run: true}) — preview all edits
|
|
31
33
|
- [ ] Review graph edits (high confidence) and ast_search edits (review carefully)
|
|
@@ -35,6 +37,7 @@ description: Plan safe refactors using blast radius and dependency mapping
|
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
### Extract Module
|
|
40
|
+
|
|
38
41
|
```
|
|
39
42
|
- [ ] gitnexus_context({name: target}) — see all incoming/outgoing refs
|
|
40
43
|
- [ ] gitnexus_impact({target, direction: "upstream"}) — find all external callers
|
|
@@ -45,6 +48,7 @@ description: Plan safe refactors using blast radius and dependency mapping
|
|
|
45
48
|
```
|
|
46
49
|
|
|
47
50
|
### Split Function/Service
|
|
51
|
+
|
|
48
52
|
```
|
|
49
53
|
- [ ] gitnexus_context({name: target}) — understand all callees
|
|
50
54
|
- [ ] Group callees by responsibility
|
|
@@ -58,6 +62,7 @@ description: Plan safe refactors using blast radius and dependency mapping
|
|
|
58
62
|
## Tools
|
|
59
63
|
|
|
60
64
|
**gitnexus_rename** — automated multi-file rename:
|
|
65
|
+
|
|
61
66
|
```
|
|
62
67
|
gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
|
|
63
68
|
→ 12 edits across 8 files
|
|
@@ -66,6 +71,7 @@ gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_
|
|
|
66
71
|
```
|
|
67
72
|
|
|
68
73
|
**gitnexus_impact** — map all dependents first:
|
|
74
|
+
|
|
69
75
|
```
|
|
70
76
|
gitnexus_impact({target: "validateUser", direction: "upstream"})
|
|
71
77
|
→ d=1: loginHandler, apiMiddleware, testUtils
|
|
@@ -73,6 +79,7 @@ gitnexus_impact({target: "validateUser", direction: "upstream"})
|
|
|
73
79
|
```
|
|
74
80
|
|
|
75
81
|
**gitnexus_detect_changes** — verify your changes after refactoring:
|
|
82
|
+
|
|
76
83
|
```
|
|
77
84
|
gitnexus_detect_changes({scope: "all"})
|
|
78
85
|
→ Changed: 8 files, 12 symbols
|
|
@@ -81,6 +88,7 @@ gitnexus_detect_changes({scope: "all"})
|
|
|
81
88
|
```
|
|
82
89
|
|
|
83
90
|
**gitnexus_cypher** — custom reference queries:
|
|
91
|
+
|
|
84
92
|
```cypher
|
|
85
93
|
MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "validateUser"})
|
|
86
94
|
RETURN caller.name, caller.filePath ORDER BY caller.filePath
|
|
@@ -88,12 +96,12 @@ RETURN caller.name, caller.filePath ORDER BY caller.filePath
|
|
|
88
96
|
|
|
89
97
|
## Risk Rules
|
|
90
98
|
|
|
91
|
-
| Risk Factor
|
|
92
|
-
|
|
93
|
-
| Many callers (>5)
|
|
94
|
-
| Cross-area refs
|
|
95
|
-
| String/dynamic refs | gitnexus_query to find them
|
|
96
|
-
| External/public API | Version and deprecate properly
|
|
99
|
+
| Risk Factor | Mitigation |
|
|
100
|
+
| ------------------- | ----------------------------------------- |
|
|
101
|
+
| Many callers (>5) | Use gitnexus_rename for automated updates |
|
|
102
|
+
| Cross-area refs | Use detect_changes after to verify scope |
|
|
103
|
+
| String/dynamic refs | gitnexus_query to find them |
|
|
104
|
+
| External/public API | Version and deprecate properly |
|
|
97
105
|
|
|
98
106
|
## Example: Rename `validateUser` to `authenticateUser`
|
|
99
107
|
|