gitnexus 1.2.6 → 1.2.8

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.
@@ -1,135 +1,135 @@
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 relative to this hook script (same package)
105
- // hooks/claude/gitnexus-hook.cjs → dist/cli/index.js
106
- const cliPath = path.resolve(__dirname, '..', '..', 'dist', 'cli', 'index.js');
107
-
108
- // augment CLI writes result to stderr (KuzuDB's native module captures
109
- // stdout fd at OS level, making it unusable in subprocess contexts).
110
- const { spawnSync } = require('child_process');
111
- let result = '';
112
- try {
113
- const child = spawnSync(
114
- process.execPath,
115
- [cliPath, 'augment', pattern],
116
- { encoding: 'utf-8', timeout: 8000, cwd, stdio: ['pipe', 'pipe', 'pipe'] }
117
- );
118
- result = child.stderr || '';
119
- } catch { /* graceful failure */ }
120
-
121
- if (result && result.trim()) {
122
- console.log(JSON.stringify({
123
- hookSpecificOutput: {
124
- hookEventName: 'PreToolUse',
125
- additionalContext: result.trim()
126
- }
127
- }));
128
- }
129
- } catch (err) {
130
- // Graceful failure — log to stderr for debugging
131
- console.error('GitNexus hook error:', err.message);
132
- }
133
- }
134
-
135
- 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 relative to this hook script (same package)
105
+ // hooks/claude/gitnexus-hook.cjs → dist/cli/index.js
106
+ const cliPath = path.resolve(__dirname, '..', '..', 'dist', 'cli', 'index.js');
107
+
108
+ // augment CLI writes result to stderr (KuzuDB's native module captures
109
+ // stdout fd at OS level, making it unusable in subprocess contexts).
110
+ const { spawnSync } = require('child_process');
111
+ let result = '';
112
+ try {
113
+ const child = spawnSync(
114
+ process.execPath,
115
+ [cliPath, 'augment', pattern],
116
+ { encoding: 'utf-8', timeout: 8000, cwd, stdio: ['pipe', 'pipe', 'pipe'] }
117
+ );
118
+ result = child.stderr || '';
119
+ } catch { /* graceful failure */ }
120
+
121
+ if (result && result.trim()) {
122
+ console.log(JSON.stringify({
123
+ hookSpecificOutput: {
124
+ hookEventName: 'PreToolUse',
125
+ additionalContext: result.trim()
126
+ }
127
+ }));
128
+ }
129
+ } catch (err) {
130
+ // Graceful failure — log to stderr for debugging
131
+ console.error('GitNexus hook error:', err.message);
132
+ }
133
+ }
134
+
135
+ main();
@@ -1,78 +1,78 @@
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
- RESULT=$(cd "$CWD" && npx -y gitnexus augment "$PATTERN" 2>/dev/null)
67
-
68
- if [ -n "$RESULT" ]; then
69
- ESCAPED=$(echo "$RESULT" | jq -Rs .)
70
- jq -n --argjson ctx "$ESCAPED" '{
71
- hookSpecificOutput: {
72
- hookEventName: "PreToolUse",
73
- additionalContext: $ctx
74
- }
75
- }'
76
- else
77
- exit 0
78
- 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
+ RESULT=$(cd "$CWD" && npx -y gitnexus augment "$PATTERN" 2>/dev/null)
67
+
68
+ if [ -n "$RESULT" ]; then
69
+ ESCAPED=$(echo "$RESULT" | jq -Rs .)
70
+ jq -n --argjson ctx "$ESCAPED" '{
71
+ hookSpecificOutput: {
72
+ hookEventName: "PreToolUse",
73
+ additionalContext: $ctx
74
+ }
75
+ }'
76
+ else
77
+ exit 0
78
+ 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitnexus",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
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",