gitnexus 1.1.6 → 1.1.7

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.
@@ -14,89 +14,68 @@ const __dirname = path.dirname(__filename);
14
14
  const GITNEXUS_START_MARKER = '<!-- gitnexus:start -->';
15
15
  const GITNEXUS_END_MARKER = '<!-- gitnexus:end -->';
16
16
  /**
17
- * Generate the full GitNexus context content (resources-first approach)
17
+ * Generate the full GitNexus context content.
18
+ *
19
+ * Design principles (learned from real agent behavior):
20
+ * - AGENTS.md is the ROUTER — it tells the agent WHICH skill to use
21
+ * - Skills contain the actual workflows — AGENTS.md does NOT duplicate them
22
+ * - Use MUST/ALWAYS language — agents skip "examples" and "suggestions"
23
+ * - Keep reference material (tools, resources, schema) in AGENTS.md as a quick lookup
18
24
  */
19
25
  function generateGitNexusContent(projectName, stats) {
20
26
  const clusterCount = stats.clusters || stats.communities || 0;
21
27
  return `${GITNEXUS_START_MARKER}
22
28
  # GitNexus MCP
23
29
 
24
- This project is indexed as **${projectName}** by GitNexus, providing AI agents with deep code intelligence.
30
+ This project is indexed by GitNexus as **${projectName}** (${stats.nodes || 0} symbols, ${stats.edges || 0} relationships, ${clusterCount} clusters, ${stats.processes || 0} processes).
25
31
 
26
- ## Project: ${projectName}
32
+ GitNexus adds a knowledge graph layer to this codebase — use it to understand architecture, trace call chains, analyze blast radius, and navigate code by meaning rather than just filenames. It complements your existing tools (read, grep, etc.) with structural and semantic intelligence.
27
33
 
28
- | Metric | Count |
29
- |--------|-------|
30
- | Files | ${stats.files || 0} |
31
- | Symbols | ${stats.nodes || 0} |
32
- | Relationships | ${stats.edges || 0} |
33
- | Clusters | ${clusterCount} |
34
- | Processes | ${stats.processes || 0} |
34
+ IMPORTANT: GitNexus MCP tool usage is highly encouraged, especially for gathering deep and accurate codebase knowledge.
35
35
 
36
- > **Staleness:** If the index is out of date, run \`npx gitnexus analyze\` in the terminal to refresh. The \`gitnexus://repo/${projectName}/context\` resource will warn you when the index is stale.
36
+ > **Staleness:** The \`gitnexus://repo/{name}/context\` resource warns when the index is out of date. Refresh with \`npx gitnexus analyze\` in the terminal.
37
37
 
38
- ## Quick Start
38
+ ## Skills
39
39
 
40
- \`\`\`
41
- 1. READ gitnexus://repos → Discover all indexed repos
42
- 2. READ gitnexus://repo/${projectName}/context → Get codebase overview (~150 tokens)
43
- 3. READ gitnexus://repo/${projectName}/clusters → See all functional clusters
44
- 4. gitnexus_search({query: "...", repo: "${projectName}"}) → Find code by query
45
- \`\`\`
40
+ For these tasks, read the matching skill and follow its workflow:
46
41
 
47
- ## Available Resources
42
+ | Task | Skill | Path |
43
+ |------|-------|------|
44
+ | Understand architecture / "How does X work?" | **Exploring** | \`.claude/skills/gitnexus/exploring/SKILL.md\` |
45
+ | Blast radius / "What breaks if I change X?" | **Impact Analysis** | \`.claude/skills/gitnexus/impact-analysis/SKILL.md\` |
46
+ | Trace bugs / "Why is X failing?" | **Debugging** | \`.claude/skills/gitnexus/debugging/SKILL.md\` |
47
+ | Rename / extract / split / refactor | **Refactoring** | \`.claude/skills/gitnexus/refactoring/SKILL.md\` |
48
48
 
49
- | Resource | Purpose |
50
- |----------|---------|
51
- | \`gitnexus://repos\` | List all indexed repositories |
52
- | \`gitnexus://repo/${projectName}/context\` | Codebase stats, tools, and resources overview |
53
- | \`gitnexus://repo/${projectName}/clusters\` | All clusters with symbol counts and cohesion |
54
- | \`gitnexus://repo/${projectName}/cluster/{name}\` | Cluster members and details |
55
- | \`gitnexus://repo/${projectName}/processes\` | All execution flows with types |
56
- | \`gitnexus://repo/${projectName}/process/{name}\` | Full process trace with steps |
57
- | \`gitnexus://repo/${projectName}/schema\` | Graph schema for Cypher queries |
49
+ ## Tools
58
50
 
59
- ## Available Tools
51
+ | Tool | What it gives you |
52
+ |------|-------------------|
53
+ | \`search\` | Semantic + keyword code search with cluster context |
54
+ | \`explore\` | Symbol deep dive — callers, callees, cluster membership, processes |
55
+ | \`impact\` | Blast radius — what breaks at depth 1/2/3 with confidence scores |
56
+ | \`overview\` | All clusters and processes at a glance |
57
+ | \`cypher\` | Raw graph queries (read \`gitnexus://repo/{name}/schema\` first) |
58
+ | \`list_repos\` | Discover indexed repos |
60
59
 
61
- | Tool | Purpose | When to Use |
62
- |------|---------|-------------|
63
- | \`list_repos\` | Discover indexed repos | First step with multiple repos |
64
- | \`search\` | Semantic + keyword search | Finding code by query |
65
- | \`overview\` | List clusters & processes | Understanding architecture |
66
- | \`explore\` | Deep dive on symbol/cluster/process | Detailed investigation |
67
- | \`impact\` | Blast radius analysis | Before making changes |
68
- | \`cypher\` | Raw graph queries | Complex analysis |
60
+ ## Resources
69
61
 
70
- > **Re-indexing:** To refresh a stale index, run \`npx gitnexus analyze\` in the terminal. Use \`--force\` only to rebuild from scratch. This is a CLI command, not an MCP tool.
62
+ Lightweight reads (~100-500 tokens) for navigation:
71
63
 
72
- > **Multi-repo:** When multiple repos are indexed, pass \`repo: "${projectName}"\` to target this project.
73
-
74
- ## Workflow Examples
75
-
76
- ### Exploring the Codebase
77
- \`\`\`
78
- READ gitnexus://repos → Discover repos
79
- READ gitnexus://repo/${projectName}/context → Stats and overview (check for staleness)
80
- READ gitnexus://repo/${projectName}/clusters → Find relevant cluster by name
81
- READ gitnexus://repo/${projectName}/cluster/{name} → See members of that cluster
82
- gitnexus_explore({name: "<symbol_name>", type: "symbol", repo: "${projectName}"})
83
- \`\`\`
84
-
85
- ### Planning a Change
86
- \`\`\`
87
- gitnexus_search({query: "<what you want to change>", repo: "${projectName}"})
88
- gitnexus_impact({target: "<symbol_name>", direction: "upstream", repo: "${projectName}"})
89
- READ gitnexus://repo/${projectName}/processes → Check affected execution flows
90
- \`\`\`
64
+ | Resource | Content |
65
+ |----------|---------|
66
+ | \`gitnexus://repo/{name}/context\` | Stats, staleness check |
67
+ | \`gitnexus://repo/{name}/clusters\` | All clusters with cohesion scores |
68
+ | \`gitnexus://repo/{name}/cluster/{clusterName}\` | Cluster members |
69
+ | \`gitnexus://repo/{name}/processes\` | All execution flows |
70
+ | \`gitnexus://repo/{name}/process/{processName}\` | Step-by-step trace |
71
+ | \`gitnexus://repo/{name}/schema\` | Graph schema for Cypher |
91
72
 
92
73
  ## Graph Schema
93
74
 
94
75
  **Nodes:** File, Function, Class, Interface, Method, Community, Process
95
-
96
- **Relationships:** CALLS, IMPORTS, EXTENDS, IMPLEMENTS, DEFINES, MEMBER_OF, STEP_IN_PROCESS
76
+ **Edges (via CodeRelation.type):** CALLS, IMPORTS, EXTENDS, IMPLEMENTS, DEFINES, MEMBER_OF, STEP_IN_PROCESS
97
77
 
98
78
  \`\`\`cypher
99
- // Example: Find callers of a function
100
79
  MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "myFunc"})
101
80
  RETURN caller.name, caller.filePath
102
81
  \`\`\`
@@ -15,6 +15,47 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
15
15
  import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListResourceTemplatesRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
16
16
  import { GITNEXUS_TOOLS } from './tools.js';
17
17
  import { getResourceDefinitions, getResourceTemplates, readResource } from './resources.js';
18
+ /**
19
+ * Next-step hints appended to tool responses.
20
+ *
21
+ * Agents often stop after one tool call. These hints guide them to the
22
+ * logical next action, creating a self-guiding workflow without hooks.
23
+ *
24
+ * Design: Each hint is a short, actionable instruction (not a suggestion).
25
+ * The hint references the specific tool/resource to use next.
26
+ */
27
+ function getNextStepHint(toolName, args) {
28
+ const repo = args?.repo;
29
+ const repoParam = repo ? `, repo: "${repo}"` : '';
30
+ const repoPath = repo || '{name}';
31
+ switch (toolName) {
32
+ case 'list_repos':
33
+ return `\n\n---\n**Next:** READ gitnexus://repo/{name}/context for any repo above to get its overview and check staleness.`;
34
+ case 'search':
35
+ return `\n\n---\n**Next:** To understand a result in context, use explore({name: "<symbol_name>", type: "symbol"${repoParam}}) to see its callers, callees, and cluster membership.`;
36
+ case 'explore': {
37
+ const exploreType = args?.type || 'symbol';
38
+ if (exploreType === 'symbol') {
39
+ return `\n\n---\n**Next:** If planning changes, use impact({target: "${args?.name || '<name>'}", direction: "upstream"${repoParam}}) to check blast radius. To see execution flows, READ gitnexus://repo/${repoPath}/processes.`;
40
+ }
41
+ if (exploreType === 'cluster') {
42
+ return `\n\n---\n**Next:** To drill into a specific symbol, use explore({name: "<symbol_name>", type: "symbol"${repoParam}}). To see execution flows, READ gitnexus://repo/${repoPath}/processes.`;
43
+ }
44
+ if (exploreType === 'process') {
45
+ return `\n\n---\n**Next:** To explore any step in detail, use explore({name: "<step_name>", type: "symbol"${repoParam}}).`;
46
+ }
47
+ return '';
48
+ }
49
+ case 'overview':
50
+ return `\n\n---\n**Next:** To drill into a cluster, READ gitnexus://repo/${repoPath}/cluster/{name} or use explore({name: "<cluster_name>", type: "cluster"${repoParam}}).`;
51
+ case 'impact':
52
+ return `\n\n---\n**Next:** Review d=1 items first (WILL BREAK). To check affected execution flows, READ gitnexus://repo/${repoPath}/processes.`;
53
+ case 'cypher':
54
+ return `\n\n---\n**Next:** To explore a result symbol, use explore({name: "<name>", type: "symbol"${repoParam}}). For schema reference, READ gitnexus://repo/${repoPath}/schema.`;
55
+ default:
56
+ return '';
57
+ }
58
+ }
18
59
  export async function startMCPServer(backend) {
19
60
  const server = new Server({
20
61
  name: 'gitnexus',
@@ -84,16 +125,18 @@ export async function startMCPServer(backend) {
84
125
  inputSchema: tool.inputSchema,
85
126
  })),
86
127
  }));
87
- // Handle tool calls
128
+ // Handle tool calls — append next-step hints to guide agent workflow
88
129
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
89
130
  const { name, arguments: args } = request.params;
90
131
  try {
91
132
  const result = await backend.callTool(name, args);
133
+ const resultText = typeof result === 'string' ? result : JSON.stringify(result, null, 2);
134
+ const hint = getNextStepHint(name, args);
92
135
  return {
93
136
  content: [
94
137
  {
95
138
  type: 'text',
96
- text: typeof result === 'string' ? result : JSON.stringify(result, null, 2),
139
+ text: resultText + hint,
97
140
  },
98
141
  ],
99
142
  };
package/dist/mcp/tools.js CHANGED
@@ -10,7 +10,9 @@ export const GITNEXUS_TOOLS = [
10
10
  description: `List all indexed repositories available to GitNexus.
11
11
 
12
12
  Returns each repo's name, path, indexed date, last commit, and stats.
13
- Use this to discover which repos are available before querying.
13
+
14
+ WHEN TO USE: First step when multiple repos are indexed, or to discover available repos.
15
+ AFTER THIS: READ gitnexus://repo/{name}/context for the repo you want to work with.
14
16
 
15
17
  When multiple repos are indexed, you MUST specify the "repo" parameter
16
18
  on other tools (search, explore, impact, etc.) to target the correct one.`,
@@ -25,7 +27,10 @@ on other tools (search, explore, impact, etc.) to target the correct one.`,
25
27
  description: `Hybrid search (keyword + semantic) across the codebase.
26
28
  Returns code nodes with cluster context and optional graph connections.
27
29
 
28
- BETTER THAN IDE search because:
30
+ WHEN TO USE: Finding code by concept, name, or keyword. Use alongside grep/IDE search for richer results.
31
+ AFTER THIS: Use explore() on interesting results to see callers/callees and cluster membership.
32
+
33
+ Complements grep/IDE search by adding:
29
34
  - Cluster context (which functional area each result belongs to)
30
35
  - Relationship data (callers/callees with depth=full)
31
36
  - Hybrid ranking (BM25 + semantic via Reciprocal Rank Fusion)
@@ -46,6 +51,9 @@ RETURNS: Array of {name, type, filePath, cluster?, connections[]?, fusedScore, s
46
51
  name: 'cypher',
47
52
  description: `Execute Cypher query against the code knowledge graph.
48
53
 
54
+ WHEN TO USE: Complex structural queries that search/explore can't answer. READ gitnexus://repo/{name}/schema first for the full schema.
55
+ AFTER THIS: Use explore() on result symbols for deeper context.
56
+
49
57
  SCHEMA:
50
58
  - Nodes: File, Folder, Function, Class, Interface, Method, Community, Process
51
59
  - Edges via CodeRelation.type: CALLS, IMPORTS, EXTENDS, IMPLEMENTS, CONTAINS, DEFINES, MEMBER_OF, STEP_IN_PROCESS
@@ -77,13 +85,16 @@ TIPS:
77
85
  name: 'explore',
78
86
  description: `Deep dive on a symbol, cluster, or process.
79
87
 
88
+ WHEN TO USE: After search() to understand context, or to drill into a specific node.
89
+ AFTER THIS (symbol): Use impact() if planning changes, or READ process resource to see execution flows.
90
+ AFTER THIS (cluster): Use explore() on specific members, or READ processes resource.
91
+ AFTER THIS (process): Use explore() on individual steps for detail.
92
+
80
93
  TYPE: symbol | cluster | process
81
94
 
82
95
  For SYMBOL: Shows cluster membership, process participation, callers/callees
83
96
  For CLUSTER: Shows members, cohesion score, processes touching it
84
- For PROCESS: Shows step-by-step trace, clusters traversed, entry/terminal points
85
-
86
- Use after search to understand context of a specific node.`,
97
+ For PROCESS: Shows step-by-step trace, clusters traversed, entry/terminal points`,
87
98
  inputSchema: {
88
99
  type: 'object',
89
100
  properties: {
@@ -98,12 +109,13 @@ Use after search to understand context of a specific node.`,
98
109
  name: 'overview',
99
110
  description: `Get codebase map showing all clusters and processes.
100
111
 
112
+ WHEN TO USE: Understanding overall architecture. Prefer READ gitnexus://repo/{name}/clusters resource for a lighter-weight alternative.
113
+ AFTER THIS: Drill into a specific cluster with explore({type: "cluster"}) or search() for specific code.
114
+
101
115
  Returns:
102
116
  - All communities (clusters) with member counts and cohesion scores
103
117
  - All processes with step counts and types (intra/cross-community)
104
- - High-level architectural view
105
-
106
- Use to understand overall codebase structure before diving deep.`,
118
+ - High-level architectural view`,
107
119
  inputSchema: {
108
120
  type: 'object',
109
121
  properties: {
@@ -120,7 +132,8 @@ Use to understand overall codebase structure before diving deep.`,
120
132
  description: `Analyze the impact of changing a code element.
121
133
  Returns all nodes affected by modifying the target, with distance, edge type, and confidence.
122
134
 
123
- USE BEFORE making changes to understand ripple effects.
135
+ WHEN TO USE: Before making code changes, especially refactoring, renaming, or modifying shared code. Shows what would be affected.
136
+ AFTER THIS: Review d=1 items (WILL BREAK). READ gitnexus://repo/{name}/processes to check affected flows. If risk > MEDIUM, warn the user.
124
137
 
125
138
  Output includes:
126
139
  - Affected processes (with step positions)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitnexus",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
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",
@@ -5,78 +5,64 @@ description: Trace bugs through call chains using knowledge graph
5
5
 
6
6
  # Debugging with GitNexus
7
7
 
8
- ## Quick Start
9
- ```
10
- 0. READ gitnexus://repos → Discover indexed repos
11
- 1. If "Index is stale" → run `npx gitnexus analyze` in terminal
12
- 2. gitnexus_search({query: "...", repo: "my-app"}) → Find code related to error
13
- 3. gitnexus_explore({name, type: "symbol", repo: "my-app"}) → Get callers and callees
14
- 4. READ gitnexus://repo/my-app/process/{name} → Trace execution flow
15
- ```
16
-
17
8
  ## When to Use
18
9
  - "Why is this function failing?"
19
10
  - "Trace where this error comes from"
20
11
  - "Who calls this method?"
21
- - "Debug the payment issue"
12
+ - "This endpoint returns 500"
13
+ - Investigating bugs, errors, or unexpected behavior
14
+
15
+ ## Workflow
22
16
 
23
- ## Workflow Checklist
24
17
  ```
25
- Bug Investigation:
26
- - [ ] READ gitnexus://repos to find the right repo
27
- - [ ] Understand the symptom (error message, behavior)
28
- - [ ] gitnexus_search to find related code
29
- - [ ] Identify the suspect function
30
- - [ ] gitnexus_explore to see callers/callees
31
- - [ ] READ gitnexus://repo/{name}/process/{name} if suspect is in a process
32
- - [ ] READ gitnexus://repo/{name}/schema for Cypher query help
33
- - [ ] gitnexus_cypher for custom traces
18
+ 1. gitnexus_search({query: "<error or symptom>"}) → Find related code
19
+ 2. gitnexus_explore({name: "<suspect>", type: "symbol"}) → See callers/callees
20
+ 3. READ gitnexus://repo/{name}/process/{name} → Trace execution flow
21
+ 4. gitnexus_cypher({query: "MATCH path..."}) → Custom traces if needed
34
22
  ```
35
23
 
36
- ## Resource Reference
37
-
38
- ### gitnexus://repo/{name}/schema
39
- Graph schema for writing Cypher queries:
40
- ```yaml
41
- nodes: [Function, Class, Method, File, Community, Process]
42
- relationships: [CALLS, IMPORTS, EXTENDS, IMPLEMENTS, MEMBER_OF, STEP_IN_PROCESS]
43
- example_queries:
44
- find_callers: |
45
- MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "X"})
46
- RETURN caller.name
47
- ```
24
+ > If "Index is stale" → run `npx gitnexus analyze` in terminal.
25
+
26
+ ## Checklist
48
27
 
49
- ### gitnexus://repo/{name}/process/{processName}
50
- Trace execution flow to find where bug might occur:
51
- ```yaml
52
- name: CheckoutFlow
53
- trace:
54
- 1: handleCheckout
55
- 2: validateCart
56
- 3: processPayment ← bug here?
57
- 4: sendConfirmation
58
28
  ```
29
+ - [ ] Understand the symptom (error message, unexpected behavior)
30
+ - [ ] gitnexus_search for error text or related code
31
+ - [ ] Identify the suspect function
32
+ - [ ] gitnexus_explore to see callers and callees
33
+ - [ ] Trace execution flow via process resource if applicable
34
+ - [ ] gitnexus_cypher for custom call chain traces if needed
35
+ - [ ] Read source files to confirm root cause
36
+ ```
37
+
38
+ ## Debugging Patterns
39
+
40
+ | Symptom | GitNexus Approach |
41
+ |---------|-------------------|
42
+ | Error message | `gitnexus_search` for error text → `explore` throw sites |
43
+ | Wrong return value | `explore` the function → trace callees for data flow |
44
+ | Intermittent failure | `explore` → look for external calls, async deps |
45
+ | Performance issue | `explore` → find symbols with many callers (hot paths) |
46
+ | Recent regression | `gitnexus_impact` on recently changed symbols |
59
47
 
60
- ## Tool Reference
48
+ ## Tools
61
49
 
62
- ### gitnexus_search
63
- Find code related to error or symptom:
50
+ **gitnexus_search** — find code related to error:
64
51
  ```
65
- gitnexus_search({query: "payment validation error", depth: "full", repo: "my-app"})
52
+ gitnexus_search({query: "payment validation error", depth: "full"})
53
+ → validatePayment, handlePaymentError, PaymentException
66
54
  ```
67
55
 
68
- ### gitnexus_explore
69
- Get symbol context:
56
+ **gitnexus_explore** — full context for a suspect:
70
57
  ```
71
- gitnexus_explore({name: "validatePayment", type: "symbol", repo: "my-app"})
58
+ gitnexus_explore({name: "validatePayment", type: "symbol"})
72
59
  → Callers: processCheckout, webhookHandler
73
- → Callees: verifyCard, fetchRates
60
+ → Callees: verifyCard, fetchRates (external API!)
61
+ → Cluster: Payment
74
62
  ```
75
63
 
76
- ### gitnexus_cypher
77
- Custom graph queries for tracing:
64
+ **gitnexus_cypher** — custom call chain traces:
78
65
  ```cypher
79
- // Trace call chain (2 hops)
80
66
  MATCH path = (a)-[:CodeRelation {type: 'CALLS'}*1..2]->(b:Function {name: "validatePayment"})
81
67
  RETURN [n IN nodes(path) | n.name] AS chain
82
68
  ```
@@ -84,23 +70,14 @@ RETURN [n IN nodes(path) | n.name] AS chain
84
70
  ## Example: "Payment endpoint returns 500 intermittently"
85
71
 
86
72
  ```
87
- 1. gitnexus_search({query: "payment error handling", repo: "my-app"})
73
+ 1. gitnexus_search({query: "payment error handling"})
88
74
  → validatePayment, handlePaymentError, PaymentException
89
75
 
90
- 2. gitnexus_explore({name: "validatePayment", type: "symbol", repo: "my-app"})
76
+ 2. gitnexus_explore({name: "validatePayment", type: "symbol"})
91
77
  → Callees: verifyCard, fetchRates (external API!)
92
78
 
93
79
  3. READ gitnexus://repo/my-app/process/CheckoutFlow
94
- → Step 3: validatePayment → calls external API
80
+ → Step 3: validatePayment → calls fetchRates (external)
95
81
 
96
82
  4. Root cause: fetchRates calls external API without proper timeout
97
83
  ```
98
-
99
- ## Debugging Patterns
100
-
101
- | Symptom | Approach |
102
- |---------|----------|
103
- | Error message | Search for error text, trace throw sites |
104
- | Wrong return value | Trace data flow through callees |
105
- | Intermittent failure | Look for external calls, timeouts |
106
- | Performance issue | Find hot paths via callers count |
@@ -3,124 +3,71 @@ name: gitnexus-exploring
3
3
  description: Navigate unfamiliar code using GitNexus knowledge graph
4
4
  ---
5
5
 
6
- # Exploring Codebases
7
-
8
- ## Quick Start
9
- ```
10
- 0. READ gitnexus://repos → Discover indexed repos (use repo param if multiple)
11
- 1. If "Index is stale" → run `npx gitnexus analyze` in terminal
12
- 2. READ gitnexus://repo/{name}/context → Get codebase overview (~150 tokens)
13
- 3. READ gitnexus://repo/{name}/clusters → See all functional clusters
14
- 4. READ gitnexus://repo/{name}/cluster/{name} → Deep dive on specific cluster
15
- ```
6
+ # Exploring Codebases with GitNexus
16
7
 
17
8
  ## When to Use
18
9
  - "How does authentication work?"
19
10
  - "What's the project structure?"
20
11
  - "Show me the main components"
21
12
  - "Where is the database logic?"
13
+ - Understanding code you haven't seen before
14
+
15
+ ## Workflow
22
16
 
23
- ## Workflow Checklist
24
17
  ```
25
- Exploration Progress:
26
- - [ ] READ gitnexus://repos to discover available repos
27
- - [ ] READ gitnexus://repo/{name}/context for codebase overview
28
- - [ ] READ gitnexus://repo/{name}/clusters to list all clusters
29
- - [ ] Identify the relevant cluster by name
30
- - [ ] READ gitnexus://repo/{name}/cluster/{name} for cluster details
31
- - [ ] Use gitnexus_explore for specific symbols
18
+ 1. READ gitnexus://repos → Discover indexed repos
19
+ 2. READ gitnexus://repo/{name}/context → Codebase overview, check staleness
20
+ 3. READ gitnexus://repo/{name}/clusters → See all functional areas
21
+ 4. READ gitnexus://repo/{name}/cluster/{name} → Drill into relevant cluster
22
+ 5. gitnexus_explore({name, type: "symbol"}) → Deep dive on specific symbol
32
23
  ```
33
24
 
34
- ## Resource Reference
25
+ > If step 2 says "Index is stale" → run `npx gitnexus analyze` in terminal.
35
26
 
36
- ### gitnexus://repos
37
- Discover all indexed repositories. **Read first.**
38
- ```yaml
39
- repos:
40
- - name: "my-app"
41
- path: "/home/user/my-app"
42
- files: 42
43
- symbols: 918
44
- ```
27
+ ## Checklist
45
28
 
46
- ### gitnexus://repo/{name}/context
47
- Codebase overview for a specific repo.
48
- ```yaml
49
- project: my-app
50
- stats:
51
- files: 42
52
- symbols: 918
53
- clusters: 12
54
- processes: 45
55
- tools_available: [list_repos, search, explore, impact, overview, cypher]
56
29
  ```
57
-
58
- ### gitnexus://repo/{name}/clusters
59
- All functional clusters with cohesion scores.
60
- ```yaml
61
- clusters:
62
- - name: "Auth"
63
- symbols: 47
64
- cohesion: 92%
65
- - name: "Database"
66
- symbols: 32
67
- cohesion: 88%
30
+ - [ ] READ gitnexus://repos
31
+ - [ ] READ gitnexus://repo/{name}/context
32
+ - [ ] READ gitnexus://repo/{name}/clusters
33
+ - [ ] Identify the relevant cluster
34
+ - [ ] READ gitnexus://repo/{name}/cluster/{name}
35
+ - [ ] gitnexus_explore for key symbols
36
+ - [ ] Read source files for implementation details
68
37
  ```
69
38
 
70
- ### gitnexus://repo/{name}/cluster/{clusterName}
71
- Members of a specific cluster.
72
- ```yaml
73
- name: Auth
74
- symbols: 47
75
- cohesion: 92%
76
- members:
77
- - name: validateUser
78
- type: Function
79
- file: src/auth/validator.ts
80
- ```
39
+ ## Resources
81
40
 
82
- ### gitnexus://repo/{name}/process/{processName}
83
- Full execution trace.
84
- ```yaml
85
- name: LoginFlow
86
- type: cross_community
87
- steps:
88
- 1: handleLogin (src/auth/handler.ts)
89
- 2: validateUser (src/auth/validator.ts)
90
- 3: createSession (src/auth/session.ts)
91
- ```
41
+ | Resource | What you get |
42
+ |----------|-------------|
43
+ | `gitnexus://repo/{name}/context` | Stats, staleness warning (~150 tokens) |
44
+ | `gitnexus://repo/{name}/clusters` | All clusters with cohesion scores (~300 tokens) |
45
+ | `gitnexus://repo/{name}/cluster/{name}` | Cluster members with file paths (~500 tokens) |
46
+ | `gitnexus://repo/{name}/process/{name}` | Step-by-step execution trace (~200 tokens) |
92
47
 
93
- ## Tool Reference (When Resources Aren't Enough)
48
+ ## Tools
94
49
 
95
- ### gitnexus_explore
96
- For detailed symbol context with callers/callees:
50
+ **gitnexus_explore** — symbol context with callers/callees:
97
51
  ```
98
- gitnexus_explore({name: "validateUser", type: "symbol", repo: "my-app"})
52
+ gitnexus_explore({name: "validateUser", type: "symbol"})
99
53
  → Callers: loginHandler, apiMiddleware
100
54
  → Callees: checkToken, getUserById
55
+ → Cluster: Auth (92% cohesion)
101
56
  ```
102
57
 
103
- ### gitnexus_search
104
- For finding code by query:
58
+ **gitnexus_search** — find code by query when you don't know the cluster:
105
59
  ```
106
- gitnexus_search({query: "payment validation", depth: "full", repo: "my-app"})
60
+ gitnexus_search({query: "payment validation", depth: "full"})
107
61
  ```
108
62
 
109
63
  ## Example: "How does payment processing work?"
110
64
 
111
65
  ```
112
- 1. READ gitnexus://repos
113
- Repos: my-app (918 symbols)
114
-
115
- 2. READ gitnexus://repo/my-app/context
116
- 918 symbols, 12 clusters
117
-
118
- 3. READ gitnexus://repo/my-app/clusters
119
- → Clusters: Auth, Payment, Database, API...
120
-
121
- 4. READ gitnexus://repo/my-app/cluster/Payment
122
- → Members: processPayment, validateCard, PaymentService
123
-
124
- 5. READ gitnexus://repo/my-app/process/CheckoutFlow
125
- → handleCheckout → validateCart → processPayment → sendConfirmation
66
+ 1. READ gitnexus://repo/my-app/context → 918 symbols, 12 clusters
67
+ 2. READ gitnexus://repo/my-app/clusters → Auth, Payment, Database, API...
68
+ 3. READ gitnexus://repo/my-app/cluster/Payment → processPayment, validateCard, PaymentService
69
+ 4. gitnexus_explore({name: "processPayment", type: "symbol"})
70
+ Callers: checkoutHandler, webhookHandler
71
+ → Callees: validateCard, chargeStripe, saveTransaction
72
+ 5. Read src/payments/processor.ts for implementation details
126
73
  ```
@@ -3,74 +3,64 @@ name: gitnexus-impact-analysis
3
3
  description: Analyze blast radius before making code changes
4
4
  ---
5
5
 
6
- # Impact Analysis
7
-
8
- ## Quick Start
9
- ```
10
- 0. READ gitnexus://repos → Discover indexed repos
11
- 1. If "Index is stale" → run `npx gitnexus analyze` in terminal
12
- 2. gitnexus_impact({target, direction: "upstream", repo: "my-app"}) → What depends on this
13
- 3. READ gitnexus://repo/my-app/clusters → Check affected areas
14
- 4. READ gitnexus://repo/my-app/processes → Affected execution flows
15
- ```
6
+ # Impact Analysis with GitNexus
16
7
 
17
8
  ## When to Use
18
9
  - "Is it safe to change this function?"
19
10
  - "What will break if I modify X?"
20
11
  - "Show me the blast radius"
21
12
  - "Who uses this code?"
13
+ - Before making non-trivial code changes
22
14
 
23
- ## Understanding Output
15
+ ## Workflow
24
16
 
25
- | Depth | Risk Level | Meaning |
26
- |-------|-----------|---------|
27
- | d=1 | WILL BREAK | Direct callers/importers |
28
- | d=2 | LIKELY AFFECTED | Indirect dependencies |
29
- | d=3 | MAY NEED TESTING | Transitive effects |
17
+ ```
18
+ 1. gitnexus_impact({target: "X", direction: "upstream"}) → What depends on this
19
+ 2. READ gitnexus://repo/{name}/clusters → Check which areas are affected
20
+ 3. READ gitnexus://repo/{name}/processes → Check affected execution flows
21
+ 4. Assess risk and report to user
22
+ ```
23
+
24
+ > If "Index is stale" → run `npx gitnexus analyze` in terminal.
25
+
26
+ ## Checklist
30
27
 
31
- ## Workflow Checklist
32
28
  ```
33
- Impact Analysis:
34
- - [ ] READ gitnexus://repos to find the right repo
35
- - [ ] gitnexus_impact(target, "upstream", repo) to find dependents
36
- - [ ] READ gitnexus://repo/{name}/clusters to understand affected areas
37
- - [ ] Check high-confidence (>0.8) dependencies first
29
+ - [ ] gitnexus_impact({target, direction: "upstream"}) to find dependents
30
+ - [ ] Review d=1 items first (these WILL BREAK)
31
+ - [ ] Check high-confidence (>0.8) dependencies
32
+ - [ ] READ clusters to understand which areas are affected
38
33
  - [ ] Count affected clusters (cross-cutting = higher risk)
39
- - [ ] If >10 processes affected, consider splitting change
34
+ - [ ] READ processes to check affected execution flows
35
+ - [ ] Assess risk level and report to user
40
36
  ```
41
37
 
42
- ## Resource Reference
38
+ ## Understanding Output
43
39
 
44
- ### gitnexus://repo/{name}/clusters
45
- Check which clusters might be affected:
46
- ```yaml
47
- clusters:
48
- - name: Auth
49
- symbols: 47
50
- - name: API
51
- symbols: 32
52
- ```
40
+ | Depth | Risk Level | Meaning |
41
+ |-------|-----------|---------|
42
+ | d=1 | **WILL BREAK** | Direct callers/importers |
43
+ | d=2 | LIKELY AFFECTED | Indirect dependencies |
44
+ | d=3 | MAY NEED TESTING | Transitive effects |
53
45
 
54
- ### gitnexus://repo/{name}/processes
55
- Find which processes touch the target:
56
- ```yaml
57
- processes:
58
- - name: LoginFlow
59
- type: cross_community
60
- steps: 5
61
- ```
46
+ ## Risk Assessment
62
47
 
63
- ## Tool Reference
48
+ | Affected | Risk |
49
+ |----------|------|
50
+ | <5 symbols, 1 cluster | LOW |
51
+ | 5-15 symbols, 1-2 clusters | MEDIUM |
52
+ | >15 symbols or 3+ clusters | HIGH |
53
+ | Critical path (auth, payments) | CRITICAL |
54
+
55
+ ## Tools
64
56
 
65
- ### gitnexus_impact
66
- Analyze blast radius:
57
+ **gitnexus_impact** — the primary tool:
67
58
  ```
68
59
  gitnexus_impact({
69
60
  target: "validateUser",
70
61
  direction: "upstream",
71
62
  minConfidence: 0.8,
72
- maxDepth: 3,
73
- repo: "my-app"
63
+ maxDepth: 3
74
64
  })
75
65
 
76
66
  → d=1 (WILL BREAK):
@@ -84,34 +74,15 @@ gitnexus_impact({
84
74
  → Risk: MEDIUM (3 processes)
85
75
  ```
86
76
 
87
- ## Risk Assessment
88
-
89
- | Affected | Risk |
90
- |----------|------|
91
- | <5 symbols, 1 cluster | LOW |
92
- | 5-15 symbols, 1-2 clusters | MEDIUM |
93
- | >15 symbols or 3+ clusters | HIGH |
94
- | Critical path (auth, payments) | CRITICAL |
95
-
96
- ## Pre-Change Checklist
97
- ```
98
- Before Committing:
99
- - [ ] Run impact analysis
100
- - [ ] Review all d=1 (WILL BREAK) items
101
- - [ ] Verify test coverage for affected processes
102
- - [ ] If risk > MEDIUM, get code review
103
- - [ ] If cross-cluster, coordinate with other teams
104
- ```
105
-
106
77
  ## Example: "What breaks if I change validateUser?"
107
78
 
108
79
  ```
109
- 1. gitnexus_impact({target: "validateUser", direction: "upstream", repo: "my-app"})
110
- → d=1: loginHandler, apiMiddleware
111
- → d=2: authRouter, sessionManager
80
+ 1. gitnexus_impact({target: "validateUser", direction: "upstream"})
81
+ → d=1: loginHandler, apiMiddleware (WILL BREAK)
82
+ → d=2: authRouter, sessionManager (LIKELY AFFECTED)
112
83
 
113
84
  2. READ gitnexus://repo/my-app/clusters
114
- → Auth and API clusters affected
85
+ → Auth and API clusters affected (2 clusters)
115
86
 
116
- 3. Decision: 2 direct callers, 2 clusters = MEDIUM risk
87
+ 3. Risk: 2 direct callers, 2 clusters = MEDIUM
117
88
  ```
@@ -5,116 +5,98 @@ description: Plan safe refactors using blast radius and dependency mapping
5
5
 
6
6
  # Refactoring with GitNexus
7
7
 
8
- ## Quick Start
9
- ```
10
- 0. READ gitnexus://repos → Discover indexed repos
11
- 1. If "Index is stale" → run `npx gitnexus analyze` in terminal
12
- 2. gitnexus_impact({target, direction: "upstream", repo: "my-app"}) → Map all dependents
13
- 3. READ gitnexus://repo/my-app/schema → Understand graph structure
14
- 4. gitnexus_cypher({query: "...", repo: "my-app"}) → Find all references
15
- ```
16
-
17
8
  ## When to Use
18
9
  - "Rename this function safely"
19
10
  - "Extract this into a module"
20
11
  - "Split this service"
21
- - "Refactor without breaking things"
12
+ - "Move this to a new file"
13
+ - Any task involving renaming, extracting, splitting, or restructuring code
14
+
15
+ ## Workflow
16
+
17
+ ```
18
+ 1. gitnexus_impact({target: "X", direction: "upstream"}) → Map all dependents
19
+ 2. gitnexus_search({query: "X"}) → Find string/dynamic references
20
+ 3. READ gitnexus://repo/{name}/cluster/{name} → Check cohesion impact
21
+ 4. Plan update order: interfaces → implementations → callers → tests
22
+ ```
23
+
24
+ > If "Index is stale" → run `npx gitnexus analyze` in terminal.
22
25
 
23
26
  ## Checklists
24
27
 
25
28
  ### Rename Symbol
26
29
  ```
27
- Rename Refactoring:
28
- - [ ] gitnexus_impact({target: oldName, direction: "upstream", repo: "my-app"}) — find all callers
29
- - [ ] gitnexus_search({query: oldName, repo: "my-app"}) — find string literals
30
- - [ ] Check for reflection/dynamic references
31
- - [ ] Update in order: interface implementation → usages
30
+ - [ ] gitnexus_impact({target: oldName, direction: "upstream"}) — find all callers
31
+ - [ ] gitnexus_search({query: oldName}) — find string literals and dynamic references
32
+ - [ ] Check for reflection/dynamic invocation patterns
33
+ - [ ] Plan update order: interface → implementation → callers → tests
34
+ - [ ] Update all d=1 (WILL BREAK) items
32
35
  - [ ] Run tests for affected processes
33
36
  ```
34
37
 
35
38
  ### Extract Module
36
39
  ```
37
- Extract Module:
38
- - [ ] gitnexus_explore({name: target, type: "symbol", repo: "my-app"}) — map dependencies
39
- - [ ] gitnexus_impact({target, direction: "upstream", repo: "my-app"}) find callers
40
- - [ ] READ gitnexus://repo/my-app/cluster/{name} — check cohesion
40
+ - [ ] gitnexus_explore({name: target, type: "symbol"}) — map internal dependencies
41
+ - [ ] gitnexus_impact({target, direction: "upstream"}) — find all external callers
42
+ - [ ] READ cluster resource check if extraction preserves cohesion
41
43
  - [ ] Define new module interface
42
- - [ ] Update imports across affected files
44
+ - [ ] Extract code, update imports
45
+ - [ ] Run tests for affected processes
43
46
  ```
44
47
 
45
- ### Split Function
48
+ ### Split Function/Service
46
49
  ```
47
- Split Function:
48
- - [ ] gitnexus_explore({name: target, type: "symbol", repo: "my-app"}) — understand callees
49
- - [ ] Group related logic
50
- - [ ] gitnexus_impact verify callers won't break
51
- - [ ] Create new functions
50
+ - [ ] gitnexus_explore({name: target, type: "symbol"}) — understand all callees
51
+ - [ ] Group callees by responsibility/domain
52
+ - [ ] gitnexus_impact({target, direction: "upstream"}) — map callers to update
53
+ - [ ] Create new functions/services
52
54
  - [ ] Update callers
55
+ - [ ] Run tests for affected processes
53
56
  ```
54
57
 
55
- ## Resource Reference
58
+ ## Tools
56
59
 
57
- ### gitnexus://repo/{name}/schema
58
- Graph structure for Cypher queries:
59
- ```yaml
60
- nodes: [Function, Class, Method, Community, Process]
61
- relationships: [CALLS, IMPORTS, EXTENDS, MEMBER_OF]
62
-
63
- example_queries:
64
- find_callers: |
65
- MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "X"})
66
- RETURN caller.name
60
+ **gitnexus_impact** — map all dependents first:
67
61
  ```
68
-
69
- ### gitnexus://repo/{name}/cluster/{clusterName}
70
- Check if extraction preserves cohesion:
71
- ```yaml
72
- name: Payment
73
- cohesion: 92%
74
- members: [processPayment, validateCard, PaymentService]
62
+ gitnexus_impact({target: "validateUser", direction: "upstream"})
63
+ d=1: loginHandler, apiMiddleware, testUtils
64
+ Affected Processes: LoginFlow, TokenRefresh
75
65
  ```
76
66
 
77
- ## Tool Reference
67
+ **gitnexus_search** find string/dynamic references impact() might miss:
68
+ ```
69
+ gitnexus_search({query: "validateUser"})
70
+ → Found in: config.json (dynamic reference!), test fixtures
71
+ ```
78
72
 
79
- ### Finding all references
73
+ **gitnexus_cypher** custom reference queries:
80
74
  ```cypher
81
75
  MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "validateUser"})
82
- RETURN caller.name, caller.filePath
83
- ORDER BY caller.filePath
76
+ RETURN caller.name, caller.filePath ORDER BY caller.filePath
84
77
  ```
85
78
 
86
- ### Finding imports of a module
87
- ```cypher
88
- MATCH (importer)-[:CodeRelation {type: 'IMPORTS'}]->(f:File {name: "utils.ts"})
89
- RETURN importer.name, importer.filePath
90
- ```
79
+ ## Risk Rules
80
+
81
+ | Risk Factor | Mitigation |
82
+ |-------------|------------|
83
+ | Many callers (>5) | Update in small batches |
84
+ | Cross-cluster refs | Coordinate with affected areas |
85
+ | String/dynamic refs | `gitnexus_search` to find them |
86
+ | External/public API | Version and deprecate properly |
91
87
 
92
- ## Example: Safely Rename `validateUser` to `authenticateUser`
88
+ ## Example: Rename `validateUser` to `authenticateUser`
93
89
 
94
90
  ```
95
- 1. gitnexus_impact({target: "validateUser", direction: "upstream", repo: "my-app"})
96
- → loginHandler, apiMiddleware, testUtils
91
+ 1. gitnexus_impact({target: "validateUser", direction: "upstream"})
92
+ d=1: loginHandler, apiMiddleware, testUtils
97
93
 
98
- 2. gitnexus_search({query: "validateUser", repo: "my-app"})
94
+ 2. gitnexus_search({query: "validateUser"})
99
95
  → Found in: config.json (dynamic reference!)
100
96
 
101
- 3. READ gitnexus://repo/my-app/processes
102
- LoginFlow, TokenRefresh, APIGateway
103
-
104
- 4. Plan update order:
105
- 1. Update declaration in auth.ts
97
+ 3. Plan update order:
98
+ 1. Update declaration in src/auth/validator.ts
106
99
  2. Update config.json string reference
107
- 3. Update loginHandler
108
- 4. Update apiMiddleware
109
- 5. Run tests for LoginFlow, TokenRefresh
100
+ 3. Update loginHandler, apiMiddleware, testUtils
101
+ 4. Run tests for LoginFlow, TokenRefresh
110
102
  ```
111
-
112
- ## Refactoring Safety Rules
113
-
114
- | Risk Factor | Mitigation |
115
- |-------------|------------|
116
- | Many callers (>5) | Update in small batches |
117
- | Cross-cluster | Coordinate with other teams |
118
- | String references | Search for dynamic usage |
119
- | Reflection | Check for dynamic invocation |
120
- | External exports | May break downstream repos |