gitnexus 1.4.0 → 1.4.1
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/README.md +194 -214
- package/dist/cli/ai-context.d.ts +1 -2
- package/dist/cli/ai-context.js +90 -117
- package/dist/cli/analyze.d.ts +0 -2
- package/dist/cli/analyze.js +2 -20
- package/dist/cli/index.js +25 -17
- package/dist/cli/setup.js +19 -17
- package/dist/core/augmentation/engine.js +20 -20
- package/dist/core/embeddings/embedding-pipeline.js +26 -26
- package/dist/core/graph/types.d.ts +2 -5
- package/dist/core/ingestion/ast-cache.js +2 -3
- package/dist/core/ingestion/call-processor.d.ts +5 -5
- package/dist/core/ingestion/call-processor.js +258 -173
- package/dist/core/ingestion/cluster-enricher.js +16 -16
- package/dist/core/ingestion/entry-point-scoring.d.ts +1 -2
- package/dist/core/ingestion/entry-point-scoring.js +22 -81
- package/dist/core/ingestion/framework-detection.d.ts +1 -5
- package/dist/core/ingestion/framework-detection.js +8 -39
- package/dist/core/ingestion/heritage-processor.d.ts +4 -13
- package/dist/core/ingestion/heritage-processor.js +28 -92
- package/dist/core/ingestion/import-processor.d.ts +19 -17
- package/dist/core/ingestion/import-processor.js +695 -170
- package/dist/core/ingestion/parsing-processor.d.ts +10 -1
- package/dist/core/ingestion/parsing-processor.js +177 -41
- package/dist/core/ingestion/pipeline.js +26 -49
- package/dist/core/ingestion/process-processor.js +1 -2
- package/dist/core/ingestion/symbol-table.d.ts +1 -12
- package/dist/core/ingestion/symbol-table.js +12 -19
- package/dist/core/ingestion/tree-sitter-queries.d.ts +11 -11
- package/dist/core/ingestion/tree-sitter-queries.js +485 -590
- package/dist/core/ingestion/utils.d.ts +0 -67
- package/dist/core/ingestion/utils.js +9 -692
- package/dist/core/ingestion/workers/parse-worker.d.ts +3 -20
- package/dist/core/ingestion/workers/parse-worker.js +345 -84
- package/dist/core/ingestion/workers/worker-pool.js +0 -8
- package/dist/core/kuzu/csv-generator.js +3 -19
- package/dist/core/kuzu/kuzu-adapter.js +19 -14
- package/dist/core/kuzu/schema.d.ts +3 -3
- package/dist/core/kuzu/schema.js +288 -303
- package/dist/core/search/bm25-index.js +6 -7
- package/dist/core/search/hybrid-search.js +3 -3
- package/dist/core/wiki/diagrams.d.ts +27 -0
- package/dist/core/wiki/diagrams.js +163 -0
- package/dist/core/wiki/generator.d.ts +50 -2
- package/dist/core/wiki/generator.js +548 -49
- package/dist/core/wiki/graph-queries.d.ts +42 -0
- package/dist/core/wiki/graph-queries.js +276 -97
- package/dist/core/wiki/html-viewer.js +192 -192
- package/dist/core/wiki/llm-client.js +73 -11
- package/dist/core/wiki/prompts.d.ts +52 -8
- package/dist/core/wiki/prompts.js +200 -86
- package/dist/mcp/core/kuzu-adapter.d.ts +3 -1
- package/dist/mcp/core/kuzu-adapter.js +44 -13
- package/dist/mcp/local/local-backend.js +128 -128
- package/dist/mcp/resources.js +42 -42
- package/dist/mcp/server.js +19 -18
- package/dist/mcp/tools.js +104 -103
- package/hooks/claude/gitnexus-hook.cjs +155 -238
- package/hooks/claude/pre-tool-use.sh +79 -79
- package/hooks/claude/session-start.sh +42 -42
- package/package.json +96 -96
- package/scripts/patch-tree-sitter-swift.cjs +74 -74
- package/skills/gitnexus-cli.md +82 -82
- package/skills/gitnexus-debugging.md +89 -89
- package/skills/gitnexus-exploring.md +78 -78
- package/skills/gitnexus-guide.md +64 -64
- package/skills/gitnexus-impact-analysis.md +97 -97
- package/skills/gitnexus-pr-review.md +163 -163
- package/skills/gitnexus-refactoring.md +121 -121
- package/vendor/leiden/index.cjs +355 -355
- package/vendor/leiden/utils.cjs +392 -392
- package/dist/cli/lazy-action.d.ts +0 -6
- package/dist/cli/lazy-action.js +0 -18
- package/dist/cli/skill-gen.d.ts +0 -26
- package/dist/cli/skill-gen.js +0 -549
- package/dist/core/ingestion/constants.d.ts +0 -16
- package/dist/core/ingestion/constants.js +0 -16
- package/dist/core/ingestion/export-detection.d.ts +0 -18
- package/dist/core/ingestion/export-detection.js +0 -230
- package/dist/core/ingestion/language-config.d.ts +0 -46
- package/dist/core/ingestion/language-config.js +0 -167
- package/dist/core/ingestion/mro-processor.d.ts +0 -45
- package/dist/core/ingestion/mro-processor.js +0 -369
- package/dist/core/ingestion/named-binding-extraction.d.ts +0 -61
- package/dist/core/ingestion/named-binding-extraction.js +0 -363
- package/dist/core/ingestion/resolvers/csharp.d.ts +0 -22
- package/dist/core/ingestion/resolvers/csharp.js +0 -109
- package/dist/core/ingestion/resolvers/go.d.ts +0 -19
- package/dist/core/ingestion/resolvers/go.js +0 -42
- package/dist/core/ingestion/resolvers/index.d.ts +0 -16
- package/dist/core/ingestion/resolvers/index.js +0 -11
- package/dist/core/ingestion/resolvers/jvm.d.ts +0 -23
- package/dist/core/ingestion/resolvers/jvm.js +0 -87
- package/dist/core/ingestion/resolvers/php.d.ts +0 -15
- package/dist/core/ingestion/resolvers/php.js +0 -35
- package/dist/core/ingestion/resolvers/rust.d.ts +0 -15
- package/dist/core/ingestion/resolvers/rust.js +0 -73
- package/dist/core/ingestion/resolvers/standard.d.ts +0 -28
- package/dist/core/ingestion/resolvers/standard.js +0 -145
- package/dist/core/ingestion/resolvers/utils.d.ts +0 -33
- package/dist/core/ingestion/resolvers/utils.js +0 -120
- package/dist/core/ingestion/symbol-resolver.d.ts +0 -32
- package/dist/core/ingestion/symbol-resolver.js +0 -83
- package/dist/core/ingestion/type-env.d.ts +0 -27
- package/dist/core/ingestion/type-env.js +0 -86
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/c-cpp.js +0 -60
- package/dist/core/ingestion/type-extractors/csharp.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/csharp.js +0 -89
- package/dist/core/ingestion/type-extractors/go.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/go.js +0 -105
- package/dist/core/ingestion/type-extractors/index.d.ts +0 -21
- package/dist/core/ingestion/type-extractors/index.js +0 -29
- package/dist/core/ingestion/type-extractors/jvm.d.ts +0 -3
- package/dist/core/ingestion/type-extractors/jvm.js +0 -121
- package/dist/core/ingestion/type-extractors/php.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/php.js +0 -31
- package/dist/core/ingestion/type-extractors/python.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/python.js +0 -41
- package/dist/core/ingestion/type-extractors/rust.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/rust.js +0 -39
- package/dist/core/ingestion/type-extractors/shared.d.ts +0 -17
- package/dist/core/ingestion/type-extractors/shared.js +0 -97
- package/dist/core/ingestion/type-extractors/swift.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/swift.js +0 -43
- package/dist/core/ingestion/type-extractors/types.d.ts +0 -14
- package/dist/core/ingestion/type-extractors/types.js +0 -1
- package/dist/core/ingestion/type-extractors/typescript.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/typescript.js +0 -46
- package/dist/mcp/compatible-stdio-transport.d.ts +0 -25
- package/dist/mcp/compatible-stdio-transport.js +0 -200
|
@@ -1,238 +1,155 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* GitNexus Claude Code Hook
|
|
4
|
-
*
|
|
5
|
-
* PreToolUse
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Emit a PostToolUse hook response with additional context for the agent.
|
|
159
|
-
*/
|
|
160
|
-
function sendHookResponse(hookEventName, message) {
|
|
161
|
-
console.log(JSON.stringify({
|
|
162
|
-
hookSpecificOutput: { hookEventName, additionalContext: message }
|
|
163
|
-
}));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* PostToolUse handler — detect index staleness after git mutations.
|
|
168
|
-
*
|
|
169
|
-
* Instead of spawning a full `gitnexus analyze` synchronously (which blocks
|
|
170
|
-
* the agent for up to 120s and risks KuzuDB corruption on timeout), we do a
|
|
171
|
-
* lightweight staleness check: compare `git rev-parse HEAD` against the
|
|
172
|
-
* lastCommit stored in `.gitnexus/meta.json`. If they differ, notify the
|
|
173
|
-
* agent so it can decide when to reindex.
|
|
174
|
-
*/
|
|
175
|
-
function handlePostToolUse(input) {
|
|
176
|
-
const toolName = input.tool_name || '';
|
|
177
|
-
if (toolName !== 'Bash') return;
|
|
178
|
-
|
|
179
|
-
const command = (input.tool_input || {}).command || '';
|
|
180
|
-
if (!/\bgit\s+(commit|merge|rebase|cherry-pick|pull)(\s|$)/.test(command)) return;
|
|
181
|
-
|
|
182
|
-
// Only proceed if the command succeeded
|
|
183
|
-
const toolOutput = input.tool_output || {};
|
|
184
|
-
if (toolOutput.exit_code !== undefined && toolOutput.exit_code !== 0) return;
|
|
185
|
-
|
|
186
|
-
const cwd = input.cwd || process.cwd();
|
|
187
|
-
if (!path.isAbsolute(cwd)) return;
|
|
188
|
-
const gitNexusDir = findGitNexusDir(cwd);
|
|
189
|
-
if (!gitNexusDir) return;
|
|
190
|
-
|
|
191
|
-
// Compare HEAD against last indexed commit — skip if unchanged
|
|
192
|
-
let currentHead = '';
|
|
193
|
-
try {
|
|
194
|
-
const headResult = spawnSync('git', ['rev-parse', 'HEAD'], {
|
|
195
|
-
encoding: 'utf-8', timeout: 3000, cwd, stdio: ['pipe', 'pipe', 'pipe'],
|
|
196
|
-
});
|
|
197
|
-
currentHead = (headResult.stdout || '').trim();
|
|
198
|
-
} catch { return; }
|
|
199
|
-
|
|
200
|
-
if (!currentHead) return;
|
|
201
|
-
|
|
202
|
-
let lastCommit = '';
|
|
203
|
-
let hadEmbeddings = false;
|
|
204
|
-
try {
|
|
205
|
-
const meta = JSON.parse(fs.readFileSync(path.join(gitNexusDir, 'meta.json'), 'utf-8'));
|
|
206
|
-
lastCommit = meta.lastCommit || '';
|
|
207
|
-
hadEmbeddings = (meta.stats && meta.stats.embeddings > 0);
|
|
208
|
-
} catch { /* no meta — treat as stale */ }
|
|
209
|
-
|
|
210
|
-
// If HEAD matches last indexed commit, no reindex needed
|
|
211
|
-
if (currentHead && currentHead === lastCommit) return;
|
|
212
|
-
|
|
213
|
-
const analyzeCmd = `npx gitnexus analyze${hadEmbeddings ? ' --embeddings' : ''}`;
|
|
214
|
-
sendHookResponse('PostToolUse',
|
|
215
|
-
`GitNexus index is stale (last indexed: ${lastCommit ? lastCommit.slice(0, 7) : 'never'}). ` +
|
|
216
|
-
`Run \`${analyzeCmd}\` to update the knowledge graph.`
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Dispatch map for hook events
|
|
221
|
-
const handlers = {
|
|
222
|
-
PreToolUse: handlePreToolUse,
|
|
223
|
-
PostToolUse: handlePostToolUse,
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
function main() {
|
|
227
|
-
try {
|
|
228
|
-
const input = readInput();
|
|
229
|
-
const handler = handlers[input.hook_event_name || ''];
|
|
230
|
-
if (handler) handler(input);
|
|
231
|
-
} catch (err) {
|
|
232
|
-
if (process.env.GITNEXUS_DEBUG) {
|
|
233
|
-
console.error('GitNexus hook error:', (err.message || '').slice(0, 200));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
main();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* GitNexus Claude Code Hook
|
|
4
|
+
*
|
|
5
|
+
* PreToolUse handler — intercepts Grep/Glob/Bash searches
|
|
6
|
+
* and augments with graph context from the GitNexus index.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: SessionStart hooks are broken on Windows (Claude Code bug).
|
|
9
|
+
* Session context is injected via CLAUDE.md / skills instead.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const { execFileSync } = require('child_process');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Read JSON input from stdin synchronously.
|
|
18
|
+
*/
|
|
19
|
+
function readInput() {
|
|
20
|
+
try {
|
|
21
|
+
const data = fs.readFileSync(0, 'utf-8');
|
|
22
|
+
return JSON.parse(data);
|
|
23
|
+
} catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check if a directory (or ancestor) has a .gitnexus index.
|
|
30
|
+
*/
|
|
31
|
+
function findGitNexusIndex(startDir) {
|
|
32
|
+
let dir = startDir || process.cwd();
|
|
33
|
+
for (let i = 0; i < 5; i++) {
|
|
34
|
+
if (fs.existsSync(path.join(dir, '.gitnexus'))) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const parent = path.dirname(dir);
|
|
38
|
+
if (parent === dir) break;
|
|
39
|
+
dir = parent;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Extract search pattern from tool input.
|
|
46
|
+
*/
|
|
47
|
+
function extractPattern(toolName, toolInput) {
|
|
48
|
+
if (toolName === 'Grep') {
|
|
49
|
+
return toolInput.pattern || null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (toolName === 'Glob') {
|
|
53
|
+
const raw = toolInput.pattern || '';
|
|
54
|
+
const match = raw.match(/[*\/]([a-zA-Z][a-zA-Z0-9_-]{2,})/);
|
|
55
|
+
return match ? match[1] : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (toolName === 'Bash') {
|
|
59
|
+
const cmd = toolInput.command || '';
|
|
60
|
+
if (!/\brg\b|\bgrep\b/.test(cmd)) return null;
|
|
61
|
+
|
|
62
|
+
const tokens = cmd.split(/\s+/);
|
|
63
|
+
let foundCmd = false;
|
|
64
|
+
let skipNext = false;
|
|
65
|
+
const flagsWithValues = new Set(['-e', '-f', '-m', '-A', '-B', '-C', '-g', '--glob', '-t', '--type', '--include', '--exclude']);
|
|
66
|
+
|
|
67
|
+
for (const token of tokens) {
|
|
68
|
+
if (skipNext) { skipNext = false; continue; }
|
|
69
|
+
if (!foundCmd) {
|
|
70
|
+
if (/\brg$|\bgrep$/.test(token)) foundCmd = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (token.startsWith('-')) {
|
|
74
|
+
if (flagsWithValues.has(token)) skipNext = true;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const cleaned = token.replace(/['"]/g, '');
|
|
78
|
+
return cleaned.length >= 3 ? cleaned : null;
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function main() {
|
|
87
|
+
try {
|
|
88
|
+
const input = readInput();
|
|
89
|
+
const hookEvent = input.hook_event_name || '';
|
|
90
|
+
|
|
91
|
+
if (hookEvent !== 'PreToolUse') return;
|
|
92
|
+
|
|
93
|
+
const cwd = input.cwd || process.cwd();
|
|
94
|
+
if (!findGitNexusIndex(cwd)) return;
|
|
95
|
+
|
|
96
|
+
const toolName = input.tool_name || '';
|
|
97
|
+
const toolInput = input.tool_input || {};
|
|
98
|
+
|
|
99
|
+
if (toolName !== 'Grep' && toolName !== 'Glob' && toolName !== 'Bash') return;
|
|
100
|
+
|
|
101
|
+
const pattern = extractPattern(toolName, toolInput);
|
|
102
|
+
if (!pattern || pattern.length < 3) return;
|
|
103
|
+
|
|
104
|
+
// Resolve CLI path — try multiple strategies:
|
|
105
|
+
// 1. Relative path (works when script is inside npm package)
|
|
106
|
+
// 2. require.resolve (works when gitnexus is globally installed)
|
|
107
|
+
// 3. Fall back to npx (works when neither is available)
|
|
108
|
+
let cliPath = path.resolve(__dirname, '..', '..', 'dist', 'cli', 'index.js');
|
|
109
|
+
if (!fs.existsSync(cliPath)) {
|
|
110
|
+
try {
|
|
111
|
+
cliPath = require.resolve('gitnexus/dist/cli/index.js');
|
|
112
|
+
} catch {
|
|
113
|
+
cliPath = ''; // will use npx fallback
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// augment CLI writes result to stderr (KuzuDB's native module captures
|
|
118
|
+
// stdout fd at OS level, making it unusable in subprocess contexts).
|
|
119
|
+
const { spawnSync } = require('child_process');
|
|
120
|
+
let result = '';
|
|
121
|
+
try {
|
|
122
|
+
let child;
|
|
123
|
+
if (cliPath) {
|
|
124
|
+
child = spawnSync(
|
|
125
|
+
process.execPath,
|
|
126
|
+
[cliPath, 'augment', pattern],
|
|
127
|
+
{ encoding: 'utf-8', timeout: 8000, cwd, stdio: ['pipe', 'pipe', 'pipe'] }
|
|
128
|
+
);
|
|
129
|
+
} else {
|
|
130
|
+
// npx fallback
|
|
131
|
+
const cmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
132
|
+
child = spawnSync(
|
|
133
|
+
cmd,
|
|
134
|
+
['-y', 'gitnexus', 'augment', pattern],
|
|
135
|
+
{ encoding: 'utf-8', timeout: 15000, cwd, stdio: ['pipe', 'pipe', 'pipe'] }
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
result = child.stderr || '';
|
|
139
|
+
} catch { /* graceful failure */ }
|
|
140
|
+
|
|
141
|
+
if (result && result.trim()) {
|
|
142
|
+
console.log(JSON.stringify({
|
|
143
|
+
hookSpecificOutput: {
|
|
144
|
+
hookEventName: 'PreToolUse',
|
|
145
|
+
additionalContext: result.trim()
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
} catch (err) {
|
|
150
|
+
// Graceful failure — log to stderr for debugging
|
|
151
|
+
console.error('GitNexus hook error:', err.message);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
main();
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# GitNexus PreToolUse hook for Claude Code
|
|
3
|
-
# Intercepts Grep/Glob/Bash searches and augments with graph context.
|
|
4
|
-
# Receives JSON on stdin with { tool_name, tool_input, cwd, ... }
|
|
5
|
-
# Returns JSON with additionalContext for graph-enriched results.
|
|
6
|
-
|
|
7
|
-
INPUT=$(cat)
|
|
8
|
-
|
|
9
|
-
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
|
|
10
|
-
CWD=$(echo "$INPUT" | jq -r '.cwd // empty' 2>/dev/null)
|
|
11
|
-
|
|
12
|
-
# Extract search pattern based on tool type
|
|
13
|
-
PATTERN=""
|
|
14
|
-
|
|
15
|
-
case "$TOOL_NAME" in
|
|
16
|
-
Grep)
|
|
17
|
-
PATTERN=$(echo "$INPUT" | jq -r '.tool_input.pattern // empty' 2>/dev/null)
|
|
18
|
-
;;
|
|
19
|
-
Glob)
|
|
20
|
-
# Glob patterns are file paths, not search terms — extract meaningful part
|
|
21
|
-
RAW=$(echo "$INPUT" | jq -r '.tool_input.pattern // empty' 2>/dev/null)
|
|
22
|
-
# Strip glob syntax to get the meaningful name (e.g., "**/*.ts" → skip, "auth*.ts" → "auth")
|
|
23
|
-
PATTERN=$(echo "$RAW" | sed -n 's/.*[*\/]\([a-zA-Z][a-zA-Z0-9_-]*\).*/\1/p')
|
|
24
|
-
;;
|
|
25
|
-
Bash)
|
|
26
|
-
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
|
27
|
-
# Only augment grep/rg commands
|
|
28
|
-
if echo "$CMD" | grep -qE '\brg\b|\bgrep\b'; then
|
|
29
|
-
# Extract pattern from rg/grep
|
|
30
|
-
if echo "$CMD" | grep -qE '\brg\b'; then
|
|
31
|
-
PATTERN=$(echo "$CMD" | sed -n "s/.*\brg\s\+\(--[^ ]*\s\+\)*['\"]\\?\([^'\";\| >]*\\).*/\2/p")
|
|
32
|
-
elif echo "$CMD" | grep -qE '\bgrep\b'; then
|
|
33
|
-
PATTERN=$(echo "$CMD" | sed -n "s/.*\bgrep\s\+\(-[^ ]*\s\+\)*['\"]\\?\([^'\";\| >]*\\).*/\2/p")
|
|
34
|
-
fi
|
|
35
|
-
fi
|
|
36
|
-
;;
|
|
37
|
-
*)
|
|
38
|
-
# Not a search tool — skip
|
|
39
|
-
exit 0
|
|
40
|
-
;;
|
|
41
|
-
esac
|
|
42
|
-
|
|
43
|
-
# Skip if pattern too short or empty
|
|
44
|
-
if [ -z "$PATTERN" ] || [ ${#PATTERN} -lt 3 ]; then
|
|
45
|
-
exit 0
|
|
46
|
-
fi
|
|
47
|
-
|
|
48
|
-
# Check if we're in a GitNexus-indexed repo
|
|
49
|
-
dir="${CWD:-$PWD}"
|
|
50
|
-
found=false
|
|
51
|
-
for i in 1 2 3 4 5; do
|
|
52
|
-
if [ -d "$dir/.gitnexus" ]; then
|
|
53
|
-
found=true
|
|
54
|
-
break
|
|
55
|
-
fi
|
|
56
|
-
parent="$(dirname "$dir")"
|
|
57
|
-
[ "$parent" = "$dir" ] && break
|
|
58
|
-
dir="$parent"
|
|
59
|
-
done
|
|
60
|
-
|
|
61
|
-
if [ "$found" = false ]; then
|
|
62
|
-
exit 0
|
|
63
|
-
fi
|
|
64
|
-
|
|
65
|
-
# Run gitnexus augment — must be fast (<500ms target)
|
|
66
|
-
# augment writes to stderr (KuzuDB captures stdout at OS level), so capture stderr and discard stdout
|
|
67
|
-
RESULT=$(cd "$CWD" && npx -y gitnexus augment "$PATTERN" 2>&1 1>/dev/null)
|
|
68
|
-
|
|
69
|
-
if [ -n "$RESULT" ]; then
|
|
70
|
-
ESCAPED=$(echo "$RESULT" | jq -Rs .)
|
|
71
|
-
jq -n --argjson ctx "$ESCAPED" '{
|
|
72
|
-
hookSpecificOutput: {
|
|
73
|
-
hookEventName: "PreToolUse",
|
|
74
|
-
additionalContext: $ctx
|
|
75
|
-
}
|
|
76
|
-
}'
|
|
77
|
-
else
|
|
78
|
-
exit 0
|
|
79
|
-
fi
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# GitNexus PreToolUse hook for Claude Code
|
|
3
|
+
# Intercepts Grep/Glob/Bash searches and augments with graph context.
|
|
4
|
+
# Receives JSON on stdin with { tool_name, tool_input, cwd, ... }
|
|
5
|
+
# Returns JSON with additionalContext for graph-enriched results.
|
|
6
|
+
|
|
7
|
+
INPUT=$(cat)
|
|
8
|
+
|
|
9
|
+
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
|
|
10
|
+
CWD=$(echo "$INPUT" | jq -r '.cwd // empty' 2>/dev/null)
|
|
11
|
+
|
|
12
|
+
# Extract search pattern based on tool type
|
|
13
|
+
PATTERN=""
|
|
14
|
+
|
|
15
|
+
case "$TOOL_NAME" in
|
|
16
|
+
Grep)
|
|
17
|
+
PATTERN=$(echo "$INPUT" | jq -r '.tool_input.pattern // empty' 2>/dev/null)
|
|
18
|
+
;;
|
|
19
|
+
Glob)
|
|
20
|
+
# Glob patterns are file paths, not search terms — extract meaningful part
|
|
21
|
+
RAW=$(echo "$INPUT" | jq -r '.tool_input.pattern // empty' 2>/dev/null)
|
|
22
|
+
# Strip glob syntax to get the meaningful name (e.g., "**/*.ts" → skip, "auth*.ts" → "auth")
|
|
23
|
+
PATTERN=$(echo "$RAW" | sed -n 's/.*[*\/]\([a-zA-Z][a-zA-Z0-9_-]*\).*/\1/p')
|
|
24
|
+
;;
|
|
25
|
+
Bash)
|
|
26
|
+
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
|
27
|
+
# Only augment grep/rg commands
|
|
28
|
+
if echo "$CMD" | grep -qE '\brg\b|\bgrep\b'; then
|
|
29
|
+
# Extract pattern from rg/grep
|
|
30
|
+
if echo "$CMD" | grep -qE '\brg\b'; then
|
|
31
|
+
PATTERN=$(echo "$CMD" | sed -n "s/.*\brg\s\+\(--[^ ]*\s\+\)*['\"]\\?\([^'\";\| >]*\\).*/\2/p")
|
|
32
|
+
elif echo "$CMD" | grep -qE '\bgrep\b'; then
|
|
33
|
+
PATTERN=$(echo "$CMD" | sed -n "s/.*\bgrep\s\+\(-[^ ]*\s\+\)*['\"]\\?\([^'\";\| >]*\\).*/\2/p")
|
|
34
|
+
fi
|
|
35
|
+
fi
|
|
36
|
+
;;
|
|
37
|
+
*)
|
|
38
|
+
# Not a search tool — skip
|
|
39
|
+
exit 0
|
|
40
|
+
;;
|
|
41
|
+
esac
|
|
42
|
+
|
|
43
|
+
# Skip if pattern too short or empty
|
|
44
|
+
if [ -z "$PATTERN" ] || [ ${#PATTERN} -lt 3 ]; then
|
|
45
|
+
exit 0
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# Check if we're in a GitNexus-indexed repo
|
|
49
|
+
dir="${CWD:-$PWD}"
|
|
50
|
+
found=false
|
|
51
|
+
for i in 1 2 3 4 5; do
|
|
52
|
+
if [ -d "$dir/.gitnexus" ]; then
|
|
53
|
+
found=true
|
|
54
|
+
break
|
|
55
|
+
fi
|
|
56
|
+
parent="$(dirname "$dir")"
|
|
57
|
+
[ "$parent" = "$dir" ] && break
|
|
58
|
+
dir="$parent"
|
|
59
|
+
done
|
|
60
|
+
|
|
61
|
+
if [ "$found" = false ]; then
|
|
62
|
+
exit 0
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
# Run gitnexus augment — must be fast (<500ms target)
|
|
66
|
+
# augment writes to stderr (KuzuDB captures stdout at OS level), so capture stderr and discard stdout
|
|
67
|
+
RESULT=$(cd "$CWD" && npx -y gitnexus augment "$PATTERN" 2>&1 1>/dev/null)
|
|
68
|
+
|
|
69
|
+
if [ -n "$RESULT" ]; then
|
|
70
|
+
ESCAPED=$(echo "$RESULT" | jq -Rs .)
|
|
71
|
+
jq -n --argjson ctx "$ESCAPED" '{
|
|
72
|
+
hookSpecificOutput: {
|
|
73
|
+
hookEventName: "PreToolUse",
|
|
74
|
+
additionalContext: $ctx
|
|
75
|
+
}
|
|
76
|
+
}'
|
|
77
|
+
else
|
|
78
|
+
exit 0
|
|
79
|
+
fi
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# GitNexus SessionStart hook for Claude Code
|
|
3
|
-
# Fires on session startup. Stdout is injected into Claude's context.
|
|
4
|
-
# Checks if the current directory has a GitNexus index.
|
|
5
|
-
|
|
6
|
-
dir="$PWD"
|
|
7
|
-
found=false
|
|
8
|
-
for i in 1 2 3 4 5; do
|
|
9
|
-
if [ -d "$dir/.gitnexus" ]; then
|
|
10
|
-
found=true
|
|
11
|
-
break
|
|
12
|
-
fi
|
|
13
|
-
parent="$(dirname "$dir")"
|
|
14
|
-
[ "$parent" = "$dir" ] && break
|
|
15
|
-
dir="$parent"
|
|
16
|
-
done
|
|
17
|
-
|
|
18
|
-
if [ "$found" = false ]; then
|
|
19
|
-
exit 0
|
|
20
|
-
fi
|
|
21
|
-
|
|
22
|
-
# Inject GitNexus context — this stdout goes directly into Claude's context
|
|
23
|
-
cat << 'EOF'
|
|
24
|
-
## GitNexus Code Intelligence
|
|
25
|
-
|
|
26
|
-
This codebase is indexed by GitNexus, providing a knowledge graph with execution flows, relationships, and semantic search.
|
|
27
|
-
|
|
28
|
-
**Available MCP Tools:**
|
|
29
|
-
- `query` — Process-grouped code intelligence (execution flows related to a concept)
|
|
30
|
-
- `context` — 360-degree symbol view (categorized refs, process participation)
|
|
31
|
-
- `impact` — Blast radius analysis (what breaks if you change a symbol)
|
|
32
|
-
- `detect_changes` — Git-diff impact analysis (what do your changes affect)
|
|
33
|
-
- `rename` — Multi-file coordinated rename with confidence tags
|
|
34
|
-
- `cypher` — Raw graph queries
|
|
35
|
-
- `list_repos` — Discover indexed repos
|
|
36
|
-
|
|
37
|
-
**Quick Start:** READ `gitnexus://repo/{name}/context` for codebase overview, then use `query` to find execution flows.
|
|
38
|
-
|
|
39
|
-
**Resources:** `gitnexus://repo/{name}/context` (overview), `/processes` (execution flows), `/schema` (for Cypher)
|
|
40
|
-
EOF
|
|
41
|
-
|
|
42
|
-
exit 0
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# GitNexus SessionStart hook for Claude Code
|
|
3
|
+
# Fires on session startup. Stdout is injected into Claude's context.
|
|
4
|
+
# Checks if the current directory has a GitNexus index.
|
|
5
|
+
|
|
6
|
+
dir="$PWD"
|
|
7
|
+
found=false
|
|
8
|
+
for i in 1 2 3 4 5; do
|
|
9
|
+
if [ -d "$dir/.gitnexus" ]; then
|
|
10
|
+
found=true
|
|
11
|
+
break
|
|
12
|
+
fi
|
|
13
|
+
parent="$(dirname "$dir")"
|
|
14
|
+
[ "$parent" = "$dir" ] && break
|
|
15
|
+
dir="$parent"
|
|
16
|
+
done
|
|
17
|
+
|
|
18
|
+
if [ "$found" = false ]; then
|
|
19
|
+
exit 0
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
# Inject GitNexus context — this stdout goes directly into Claude's context
|
|
23
|
+
cat << 'EOF'
|
|
24
|
+
## GitNexus Code Intelligence
|
|
25
|
+
|
|
26
|
+
This codebase is indexed by GitNexus, providing a knowledge graph with execution flows, relationships, and semantic search.
|
|
27
|
+
|
|
28
|
+
**Available MCP Tools:**
|
|
29
|
+
- `query` — Process-grouped code intelligence (execution flows related to a concept)
|
|
30
|
+
- `context` — 360-degree symbol view (categorized refs, process participation)
|
|
31
|
+
- `impact` — Blast radius analysis (what breaks if you change a symbol)
|
|
32
|
+
- `detect_changes` — Git-diff impact analysis (what do your changes affect)
|
|
33
|
+
- `rename` — Multi-file coordinated rename with confidence tags
|
|
34
|
+
- `cypher` — Raw graph queries
|
|
35
|
+
- `list_repos` — Discover indexed repos
|
|
36
|
+
|
|
37
|
+
**Quick Start:** READ `gitnexus://repo/{name}/context` for codebase overview, then use `query` to find execution flows.
|
|
38
|
+
|
|
39
|
+
**Resources:** `gitnexus://repo/{name}/context` (overview), `/processes` (execution flows), `/schema` (for Cypher)
|
|
40
|
+
EOF
|
|
41
|
+
|
|
42
|
+
exit 0
|