@veewo/gitnexus 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.
Files changed (231) hide show
  1. package/README.md +234 -0
  2. package/dist/benchmark/agent-context/evaluators.d.ts +9 -0
  3. package/dist/benchmark/agent-context/evaluators.js +196 -0
  4. package/dist/benchmark/agent-context/evaluators.test.d.ts +1 -0
  5. package/dist/benchmark/agent-context/evaluators.test.js +39 -0
  6. package/dist/benchmark/agent-context/io.d.ts +2 -0
  7. package/dist/benchmark/agent-context/io.js +23 -0
  8. package/dist/benchmark/agent-context/io.test.d.ts +1 -0
  9. package/dist/benchmark/agent-context/io.test.js +19 -0
  10. package/dist/benchmark/agent-context/report.d.ts +2 -0
  11. package/dist/benchmark/agent-context/report.js +59 -0
  12. package/dist/benchmark/agent-context/report.test.d.ts +1 -0
  13. package/dist/benchmark/agent-context/report.test.js +85 -0
  14. package/dist/benchmark/agent-context/runner.d.ts +46 -0
  15. package/dist/benchmark/agent-context/runner.js +111 -0
  16. package/dist/benchmark/agent-context/runner.test.d.ts +1 -0
  17. package/dist/benchmark/agent-context/runner.test.js +79 -0
  18. package/dist/benchmark/agent-context/tool-runner.d.ts +7 -0
  19. package/dist/benchmark/agent-context/tool-runner.js +18 -0
  20. package/dist/benchmark/agent-context/tool-runner.test.d.ts +1 -0
  21. package/dist/benchmark/agent-context/tool-runner.test.js +11 -0
  22. package/dist/benchmark/agent-context/types.d.ts +40 -0
  23. package/dist/benchmark/agent-context/types.js +1 -0
  24. package/dist/benchmark/analyze-runner.d.ts +16 -0
  25. package/dist/benchmark/analyze-runner.js +51 -0
  26. package/dist/benchmark/analyze-runner.test.d.ts +1 -0
  27. package/dist/benchmark/analyze-runner.test.js +37 -0
  28. package/dist/benchmark/evaluators.d.ts +6 -0
  29. package/dist/benchmark/evaluators.js +10 -0
  30. package/dist/benchmark/evaluators.test.d.ts +1 -0
  31. package/dist/benchmark/evaluators.test.js +12 -0
  32. package/dist/benchmark/io.d.ts +7 -0
  33. package/dist/benchmark/io.js +25 -0
  34. package/dist/benchmark/io.test.d.ts +1 -0
  35. package/dist/benchmark/io.test.js +35 -0
  36. package/dist/benchmark/neonspark-candidates.d.ts +19 -0
  37. package/dist/benchmark/neonspark-candidates.js +94 -0
  38. package/dist/benchmark/neonspark-candidates.test.d.ts +1 -0
  39. package/dist/benchmark/neonspark-candidates.test.js +43 -0
  40. package/dist/benchmark/neonspark-materialize.d.ts +19 -0
  41. package/dist/benchmark/neonspark-materialize.js +111 -0
  42. package/dist/benchmark/neonspark-materialize.test.d.ts +1 -0
  43. package/dist/benchmark/neonspark-materialize.test.js +124 -0
  44. package/dist/benchmark/neonspark-sync.d.ts +3 -0
  45. package/dist/benchmark/neonspark-sync.js +53 -0
  46. package/dist/benchmark/neonspark-sync.test.d.ts +1 -0
  47. package/dist/benchmark/neonspark-sync.test.js +20 -0
  48. package/dist/benchmark/report.d.ts +1 -0
  49. package/dist/benchmark/report.js +7 -0
  50. package/dist/benchmark/runner.d.ts +48 -0
  51. package/dist/benchmark/runner.js +302 -0
  52. package/dist/benchmark/runner.test.d.ts +1 -0
  53. package/dist/benchmark/runner.test.js +50 -0
  54. package/dist/benchmark/scoring.d.ts +16 -0
  55. package/dist/benchmark/scoring.js +27 -0
  56. package/dist/benchmark/scoring.test.d.ts +1 -0
  57. package/dist/benchmark/scoring.test.js +24 -0
  58. package/dist/benchmark/tool-runner.d.ts +6 -0
  59. package/dist/benchmark/tool-runner.js +17 -0
  60. package/dist/benchmark/types.d.ts +36 -0
  61. package/dist/benchmark/types.js +1 -0
  62. package/dist/cli/ai-context.d.ts +22 -0
  63. package/dist/cli/ai-context.js +184 -0
  64. package/dist/cli/ai-context.test.d.ts +1 -0
  65. package/dist/cli/ai-context.test.js +30 -0
  66. package/dist/cli/analyze-multi-scope-regression.test.d.ts +1 -0
  67. package/dist/cli/analyze-multi-scope-regression.test.js +22 -0
  68. package/dist/cli/analyze-options.d.ts +7 -0
  69. package/dist/cli/analyze-options.js +56 -0
  70. package/dist/cli/analyze-options.test.d.ts +1 -0
  71. package/dist/cli/analyze-options.test.js +36 -0
  72. package/dist/cli/analyze.d.ts +14 -0
  73. package/dist/cli/analyze.js +384 -0
  74. package/dist/cli/augment.d.ts +13 -0
  75. package/dist/cli/augment.js +33 -0
  76. package/dist/cli/benchmark-agent-context.d.ts +29 -0
  77. package/dist/cli/benchmark-agent-context.js +61 -0
  78. package/dist/cli/benchmark-agent-context.test.d.ts +1 -0
  79. package/dist/cli/benchmark-agent-context.test.js +80 -0
  80. package/dist/cli/benchmark-unity.d.ts +15 -0
  81. package/dist/cli/benchmark-unity.js +31 -0
  82. package/dist/cli/benchmark-unity.test.d.ts +1 -0
  83. package/dist/cli/benchmark-unity.test.js +18 -0
  84. package/dist/cli/claude-hooks.d.ts +22 -0
  85. package/dist/cli/claude-hooks.js +97 -0
  86. package/dist/cli/clean.d.ts +10 -0
  87. package/dist/cli/clean.js +60 -0
  88. package/dist/cli/eval-server.d.ts +30 -0
  89. package/dist/cli/eval-server.js +372 -0
  90. package/dist/cli/index.d.ts +2 -0
  91. package/dist/cli/index.js +182 -0
  92. package/dist/cli/list.d.ts +6 -0
  93. package/dist/cli/list.js +33 -0
  94. package/dist/cli/mcp.d.ts +8 -0
  95. package/dist/cli/mcp.js +34 -0
  96. package/dist/cli/repo-manager-alias.test.d.ts +1 -0
  97. package/dist/cli/repo-manager-alias.test.js +40 -0
  98. package/dist/cli/scope-filter.test.d.ts +1 -0
  99. package/dist/cli/scope-filter.test.js +49 -0
  100. package/dist/cli/serve.d.ts +4 -0
  101. package/dist/cli/serve.js +6 -0
  102. package/dist/cli/setup.d.ts +8 -0
  103. package/dist/cli/setup.js +311 -0
  104. package/dist/cli/setup.test.d.ts +1 -0
  105. package/dist/cli/setup.test.js +31 -0
  106. package/dist/cli/status.d.ts +6 -0
  107. package/dist/cli/status.js +27 -0
  108. package/dist/cli/tool.d.ts +40 -0
  109. package/dist/cli/tool.js +94 -0
  110. package/dist/cli/version.test.d.ts +1 -0
  111. package/dist/cli/version.test.js +19 -0
  112. package/dist/cli/wiki.d.ts +15 -0
  113. package/dist/cli/wiki.js +361 -0
  114. package/dist/config/ignore-service.d.ts +1 -0
  115. package/dist/config/ignore-service.js +210 -0
  116. package/dist/config/supported-languages.d.ts +12 -0
  117. package/dist/config/supported-languages.js +15 -0
  118. package/dist/core/augmentation/engine.d.ts +26 -0
  119. package/dist/core/augmentation/engine.js +213 -0
  120. package/dist/core/embeddings/embedder.d.ts +60 -0
  121. package/dist/core/embeddings/embedder.js +251 -0
  122. package/dist/core/embeddings/embedding-pipeline.d.ts +51 -0
  123. package/dist/core/embeddings/embedding-pipeline.js +329 -0
  124. package/dist/core/embeddings/index.d.ts +9 -0
  125. package/dist/core/embeddings/index.js +9 -0
  126. package/dist/core/embeddings/text-generator.d.ts +24 -0
  127. package/dist/core/embeddings/text-generator.js +182 -0
  128. package/dist/core/embeddings/types.d.ts +87 -0
  129. package/dist/core/embeddings/types.js +32 -0
  130. package/dist/core/graph/graph.d.ts +2 -0
  131. package/dist/core/graph/graph.js +66 -0
  132. package/dist/core/graph/types.d.ts +61 -0
  133. package/dist/core/graph/types.js +1 -0
  134. package/dist/core/ingestion/ast-cache.d.ts +11 -0
  135. package/dist/core/ingestion/ast-cache.js +34 -0
  136. package/dist/core/ingestion/call-processor.d.ts +15 -0
  137. package/dist/core/ingestion/call-processor.js +327 -0
  138. package/dist/core/ingestion/cluster-enricher.d.ts +38 -0
  139. package/dist/core/ingestion/cluster-enricher.js +170 -0
  140. package/dist/core/ingestion/community-processor.d.ts +39 -0
  141. package/dist/core/ingestion/community-processor.js +312 -0
  142. package/dist/core/ingestion/entry-point-scoring.d.ts +39 -0
  143. package/dist/core/ingestion/entry-point-scoring.js +260 -0
  144. package/dist/core/ingestion/filesystem-walker.d.ts +28 -0
  145. package/dist/core/ingestion/filesystem-walker.js +80 -0
  146. package/dist/core/ingestion/framework-detection.d.ts +39 -0
  147. package/dist/core/ingestion/framework-detection.js +235 -0
  148. package/dist/core/ingestion/heritage-processor.d.ts +20 -0
  149. package/dist/core/ingestion/heritage-processor.js +197 -0
  150. package/dist/core/ingestion/import-processor.d.ts +38 -0
  151. package/dist/core/ingestion/import-processor.js +778 -0
  152. package/dist/core/ingestion/parsing-processor.d.ts +15 -0
  153. package/dist/core/ingestion/parsing-processor.js +291 -0
  154. package/dist/core/ingestion/pipeline.d.ts +5 -0
  155. package/dist/core/ingestion/pipeline.js +323 -0
  156. package/dist/core/ingestion/process-processor.d.ts +51 -0
  157. package/dist/core/ingestion/process-processor.js +309 -0
  158. package/dist/core/ingestion/scope-filter.d.ts +25 -0
  159. package/dist/core/ingestion/scope-filter.js +100 -0
  160. package/dist/core/ingestion/structure-processor.d.ts +2 -0
  161. package/dist/core/ingestion/structure-processor.js +36 -0
  162. package/dist/core/ingestion/symbol-table.d.ts +33 -0
  163. package/dist/core/ingestion/symbol-table.js +38 -0
  164. package/dist/core/ingestion/tree-sitter-queries.d.ts +12 -0
  165. package/dist/core/ingestion/tree-sitter-queries.js +398 -0
  166. package/dist/core/ingestion/utils.d.ts +10 -0
  167. package/dist/core/ingestion/utils.js +50 -0
  168. package/dist/core/ingestion/workers/parse-worker.d.ts +59 -0
  169. package/dist/core/ingestion/workers/parse-worker.js +672 -0
  170. package/dist/core/ingestion/workers/worker-pool.d.ts +16 -0
  171. package/dist/core/ingestion/workers/worker-pool.js +120 -0
  172. package/dist/core/kuzu/csv-generator.d.ts +29 -0
  173. package/dist/core/kuzu/csv-generator.js +336 -0
  174. package/dist/core/kuzu/kuzu-adapter.d.ts +101 -0
  175. package/dist/core/kuzu/kuzu-adapter.js +753 -0
  176. package/dist/core/kuzu/schema.d.ts +53 -0
  177. package/dist/core/kuzu/schema.js +407 -0
  178. package/dist/core/search/bm25-index.d.ts +23 -0
  179. package/dist/core/search/bm25-index.js +95 -0
  180. package/dist/core/search/hybrid-search.d.ts +49 -0
  181. package/dist/core/search/hybrid-search.js +118 -0
  182. package/dist/core/tree-sitter/parser-loader.d.ts +4 -0
  183. package/dist/core/tree-sitter/parser-loader.js +44 -0
  184. package/dist/core/wiki/generator.d.ts +110 -0
  185. package/dist/core/wiki/generator.js +786 -0
  186. package/dist/core/wiki/graph-queries.d.ts +80 -0
  187. package/dist/core/wiki/graph-queries.js +238 -0
  188. package/dist/core/wiki/html-viewer.d.ts +10 -0
  189. package/dist/core/wiki/html-viewer.js +297 -0
  190. package/dist/core/wiki/llm-client.d.ts +40 -0
  191. package/dist/core/wiki/llm-client.js +162 -0
  192. package/dist/core/wiki/prompts.d.ts +53 -0
  193. package/dist/core/wiki/prompts.js +174 -0
  194. package/dist/lib/utils.d.ts +1 -0
  195. package/dist/lib/utils.js +3 -0
  196. package/dist/mcp/core/embedder.d.ts +27 -0
  197. package/dist/mcp/core/embedder.js +108 -0
  198. package/dist/mcp/core/kuzu-adapter.d.ts +34 -0
  199. package/dist/mcp/core/kuzu-adapter.js +231 -0
  200. package/dist/mcp/local/local-backend.d.ts +160 -0
  201. package/dist/mcp/local/local-backend.js +1646 -0
  202. package/dist/mcp/resources.d.ts +31 -0
  203. package/dist/mcp/resources.js +407 -0
  204. package/dist/mcp/server.d.ts +23 -0
  205. package/dist/mcp/server.js +251 -0
  206. package/dist/mcp/staleness.d.ts +15 -0
  207. package/dist/mcp/staleness.js +29 -0
  208. package/dist/mcp/tools.d.ts +24 -0
  209. package/dist/mcp/tools.js +195 -0
  210. package/dist/server/api.d.ts +10 -0
  211. package/dist/server/api.js +344 -0
  212. package/dist/server/mcp-http.d.ts +13 -0
  213. package/dist/server/mcp-http.js +100 -0
  214. package/dist/storage/git.d.ts +6 -0
  215. package/dist/storage/git.js +32 -0
  216. package/dist/storage/repo-manager.d.ts +125 -0
  217. package/dist/storage/repo-manager.js +257 -0
  218. package/dist/types/pipeline.d.ts +34 -0
  219. package/dist/types/pipeline.js +18 -0
  220. package/hooks/claude/gitnexus-hook.cjs +135 -0
  221. package/hooks/claude/pre-tool-use.sh +78 -0
  222. package/hooks/claude/session-start.sh +42 -0
  223. package/package.json +92 -0
  224. package/skills/gitnexus-cli.md +82 -0
  225. package/skills/gitnexus-debugging.md +89 -0
  226. package/skills/gitnexus-exploring.md +78 -0
  227. package/skills/gitnexus-guide.md +64 -0
  228. package/skills/gitnexus-impact-analysis.md +97 -0
  229. package/skills/gitnexus-refactoring.md +121 -0
  230. package/vendor/leiden/index.cjs +355 -0
  231. package/vendor/leiden/utils.cjs +392 -0
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Repository Manager
3
+ *
4
+ * Manages GitNexus index storage in .gitnexus/ at repo root.
5
+ * Also maintains a global registry at ~/.gitnexus/registry.json
6
+ * so the MCP server can discover indexed repos from any cwd.
7
+ */
8
+ import fs from 'fs/promises';
9
+ import path from 'path';
10
+ import os from 'os';
11
+ const REPO_ALIAS_REGEX = /^[a-zA-Z0-9._-]{3,64}$/;
12
+ function normalizeRepoAlias(repoAlias) {
13
+ if (!repoAlias)
14
+ return undefined;
15
+ const trimmed = repoAlias.trim();
16
+ if (!trimmed)
17
+ return undefined;
18
+ if (!REPO_ALIAS_REGEX.test(trimmed)) {
19
+ throw new Error('Invalid repo alias. Use ^[a-zA-Z0-9._-]{3,64}$');
20
+ }
21
+ return trimmed;
22
+ }
23
+ const GITNEXUS_DIR = '.gitnexus';
24
+ // ─── Local Storage Helpers ─────────────────────────────────────────────
25
+ /**
26
+ * Get the .gitnexus storage path for a repository
27
+ */
28
+ export const getStoragePath = (repoPath) => {
29
+ return path.join(path.resolve(repoPath), GITNEXUS_DIR);
30
+ };
31
+ /**
32
+ * Get paths to key storage files
33
+ */
34
+ export const getStoragePaths = (repoPath) => {
35
+ const storagePath = getStoragePath(repoPath);
36
+ return {
37
+ storagePath,
38
+ kuzuPath: path.join(storagePath, 'kuzu'),
39
+ metaPath: path.join(storagePath, 'meta.json'),
40
+ };
41
+ };
42
+ /**
43
+ * Load metadata from an indexed repo
44
+ */
45
+ export const loadMeta = async (storagePath) => {
46
+ try {
47
+ const metaPath = path.join(storagePath, 'meta.json');
48
+ const raw = await fs.readFile(metaPath, 'utf-8');
49
+ return JSON.parse(raw);
50
+ }
51
+ catch {
52
+ return null;
53
+ }
54
+ };
55
+ /**
56
+ * Save metadata to storage
57
+ */
58
+ export const saveMeta = async (storagePath, meta) => {
59
+ await fs.mkdir(storagePath, { recursive: true });
60
+ const metaPath = path.join(storagePath, 'meta.json');
61
+ await fs.writeFile(metaPath, JSON.stringify(meta, null, 2), 'utf-8');
62
+ };
63
+ /**
64
+ * Check if a path has a GitNexus index
65
+ */
66
+ export const hasIndex = async (repoPath) => {
67
+ const { metaPath } = getStoragePaths(repoPath);
68
+ try {
69
+ await fs.access(metaPath);
70
+ return true;
71
+ }
72
+ catch {
73
+ return false;
74
+ }
75
+ };
76
+ /**
77
+ * Load an indexed repo from a path
78
+ */
79
+ export const loadRepo = async (repoPath) => {
80
+ const paths = getStoragePaths(repoPath);
81
+ const meta = await loadMeta(paths.storagePath);
82
+ if (!meta)
83
+ return null;
84
+ return {
85
+ repoPath: path.resolve(repoPath),
86
+ ...paths,
87
+ meta,
88
+ };
89
+ };
90
+ /**
91
+ * Find .gitnexus by walking up from a starting path
92
+ */
93
+ export const findRepo = async (startPath) => {
94
+ let current = path.resolve(startPath);
95
+ const root = path.parse(current).root;
96
+ while (current !== root) {
97
+ const repo = await loadRepo(current);
98
+ if (repo)
99
+ return repo;
100
+ current = path.dirname(current);
101
+ }
102
+ return null;
103
+ };
104
+ /**
105
+ * Add .gitnexus to .gitignore if not already present
106
+ */
107
+ export const addToGitignore = async (repoPath) => {
108
+ const gitignorePath = path.join(repoPath, '.gitignore');
109
+ try {
110
+ const content = await fs.readFile(gitignorePath, 'utf-8');
111
+ if (content.includes(GITNEXUS_DIR))
112
+ return;
113
+ const newContent = content.endsWith('\n')
114
+ ? `${content}${GITNEXUS_DIR}\n`
115
+ : `${content}\n${GITNEXUS_DIR}\n`;
116
+ await fs.writeFile(gitignorePath, newContent, 'utf-8');
117
+ }
118
+ catch {
119
+ // .gitignore doesn't exist, create it
120
+ await fs.writeFile(gitignorePath, `${GITNEXUS_DIR}\n`, 'utf-8');
121
+ }
122
+ };
123
+ // ─── Global Registry (~/.gitnexus/registry.json) ───────────────────────
124
+ /**
125
+ * Get the path to the global GitNexus directory
126
+ */
127
+ export const getGlobalDir = () => {
128
+ if (process.env.GITNEXUS_HOME && process.env.GITNEXUS_HOME.trim()) {
129
+ return path.resolve(process.env.GITNEXUS_HOME);
130
+ }
131
+ return path.join(os.homedir(), '.gitnexus');
132
+ };
133
+ /**
134
+ * Get the path to the global registry file
135
+ */
136
+ export const getGlobalRegistryPath = () => {
137
+ return path.join(getGlobalDir(), 'registry.json');
138
+ };
139
+ /**
140
+ * Read the global registry. Returns empty array if not found.
141
+ */
142
+ export const readRegistry = async () => {
143
+ try {
144
+ const raw = await fs.readFile(getGlobalRegistryPath(), 'utf-8');
145
+ const data = JSON.parse(raw);
146
+ return Array.isArray(data) ? data : [];
147
+ }
148
+ catch {
149
+ return [];
150
+ }
151
+ };
152
+ /**
153
+ * Write the global registry to disk
154
+ */
155
+ const writeRegistry = async (entries) => {
156
+ const dir = getGlobalDir();
157
+ await fs.mkdir(dir, { recursive: true });
158
+ await fs.writeFile(getGlobalRegistryPath(), JSON.stringify(entries, null, 2), 'utf-8');
159
+ };
160
+ /**
161
+ * Register (add or update) a repo in the global registry.
162
+ * Called after `gitnexus analyze` completes.
163
+ */
164
+ export const registerRepo = async (repoPath, meta, options) => {
165
+ const resolved = path.resolve(repoPath);
166
+ const sourceName = path.basename(resolved);
167
+ const alias = normalizeRepoAlias(options?.repoAlias);
168
+ const name = alias || sourceName;
169
+ const { storagePath } = getStoragePaths(resolved);
170
+ const entries = await readRegistry();
171
+ if (alias) {
172
+ const aliasConflict = entries.find((e) => e.name === alias && path.resolve(e.path) !== resolved);
173
+ if (aliasConflict) {
174
+ throw new Error(`Repo alias "${alias}" is already registered for ${aliasConflict.path}`);
175
+ }
176
+ }
177
+ const existing = entries.findIndex((e) => path.resolve(e.path) === resolved);
178
+ const entry = {
179
+ name,
180
+ path: resolved,
181
+ storagePath,
182
+ indexedAt: meta.indexedAt,
183
+ lastCommit: meta.lastCommit,
184
+ sourceName,
185
+ alias,
186
+ stats: meta.stats,
187
+ };
188
+ if (existing >= 0) {
189
+ entries[existing] = entry;
190
+ }
191
+ else {
192
+ entries.push(entry);
193
+ }
194
+ await writeRegistry(entries);
195
+ return entry;
196
+ };
197
+ /**
198
+ * Remove a repo from the global registry.
199
+ * Called after `gitnexus clean`.
200
+ */
201
+ export const unregisterRepo = async (repoPath) => {
202
+ const resolved = path.resolve(repoPath);
203
+ const entries = await readRegistry();
204
+ const filtered = entries.filter((e) => path.resolve(e.path) !== resolved);
205
+ await writeRegistry(filtered);
206
+ };
207
+ /**
208
+ * List all registered repos from the global registry.
209
+ * Optionally validates that each entry's .gitnexus/ still exists.
210
+ */
211
+ export const listRegisteredRepos = async (opts) => {
212
+ const entries = await readRegistry();
213
+ if (!opts?.validate)
214
+ return entries;
215
+ // Validate each entry still has a .gitnexus/ directory
216
+ const valid = [];
217
+ for (const entry of entries) {
218
+ try {
219
+ await fs.access(path.join(entry.storagePath, 'meta.json'));
220
+ valid.push(entry);
221
+ }
222
+ catch {
223
+ // Index no longer exists — skip
224
+ }
225
+ }
226
+ // If we pruned any entries, save the cleaned registry
227
+ if (valid.length !== entries.length) {
228
+ await writeRegistry(valid);
229
+ }
230
+ return valid;
231
+ };
232
+ /**
233
+ * Get the path to the global CLI config file
234
+ */
235
+ export const getGlobalConfigPath = () => {
236
+ return path.join(getGlobalDir(), 'config.json');
237
+ };
238
+ /**
239
+ * Load CLI config from ~/.gitnexus/config.json
240
+ */
241
+ export const loadCLIConfig = async () => {
242
+ try {
243
+ const raw = await fs.readFile(getGlobalConfigPath(), 'utf-8');
244
+ return JSON.parse(raw);
245
+ }
246
+ catch {
247
+ return {};
248
+ }
249
+ };
250
+ /**
251
+ * Save CLI config to ~/.gitnexus/config.json
252
+ */
253
+ export const saveCLIConfig = async (config) => {
254
+ const dir = getGlobalDir();
255
+ await fs.mkdir(dir, { recursive: true });
256
+ await fs.writeFile(getGlobalConfigPath(), JSON.stringify(config, null, 2), 'utf-8');
257
+ };
@@ -0,0 +1,34 @@
1
+ import { GraphNode, GraphRelationship, KnowledgeGraph } from '../core/graph/types.js';
2
+ import { CommunityDetectionResult } from '../core/ingestion/community-processor.js';
3
+ import { ProcessDetectionResult } from '../core/ingestion/process-processor.js';
4
+ import type { ScopeSelectionDiagnostics } from '../core/ingestion/scope-filter.js';
5
+ export type PipelinePhase = 'idle' | 'extracting' | 'structure' | 'parsing' | 'imports' | 'calls' | 'heritage' | 'communities' | 'processes' | 'enriching' | 'complete' | 'error';
6
+ export interface PipelineProgress {
7
+ phase: PipelinePhase;
8
+ percent: number;
9
+ message: string;
10
+ detail?: string;
11
+ stats?: {
12
+ filesProcessed: number;
13
+ totalFiles: number;
14
+ nodesCreated: number;
15
+ };
16
+ }
17
+ export interface PipelineResult {
18
+ graph: KnowledgeGraph;
19
+ /** Absolute path to the repo root — used for lazy file reads during KuzuDB loading */
20
+ repoPath: string;
21
+ /** Total files scanned (for stats) */
22
+ totalFileCount: number;
23
+ communityResult?: CommunityDetectionResult;
24
+ processResult?: ProcessDetectionResult;
25
+ scopeDiagnostics?: ScopeSelectionDiagnostics;
26
+ }
27
+ export interface SerializablePipelineResult {
28
+ nodes: GraphNode[];
29
+ relationships: GraphRelationship[];
30
+ repoPath: string;
31
+ totalFileCount: number;
32
+ }
33
+ export declare const serializePipelineResult: (result: PipelineResult) => SerializablePipelineResult;
34
+ export declare const deserializePipelineResult: (serialized: SerializablePipelineResult, createGraph: () => KnowledgeGraph) => PipelineResult;
@@ -0,0 +1,18 @@
1
+ // Helper to convert PipelineResult to serializable format
2
+ export const serializePipelineResult = (result) => ({
3
+ nodes: [...result.graph.iterNodes()],
4
+ relationships: [...result.graph.iterRelationships()],
5
+ repoPath: result.repoPath,
6
+ totalFileCount: result.totalFileCount,
7
+ });
8
+ // Helper to reconstruct from serializable format (used in main thread)
9
+ export const deserializePipelineResult = (serialized, createGraph) => {
10
+ const graph = createGraph();
11
+ serialized.nodes.forEach(node => graph.addNode(node));
12
+ serialized.relationships.forEach(rel => graph.addRelationship(rel));
13
+ return {
14
+ graph,
15
+ repoPath: serialized.repoPath,
16
+ totalFileCount: serialized.totalFileCount,
17
+ };
18
+ };
@@ -0,0 +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();
@@ -0,0 +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
@@ -0,0 +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
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@veewo/gitnexus",
3
+ "version": "1.3.4",
4
+ "description": "Graph-powered code intelligence for AI agents. Index any codebase, query via MCP or CLI.",
5
+ "author": "Abhigyan Patwari",
6
+ "license": "PolyForm-Noncommercial-1.0.0",
7
+ "homepage": "https://github.com/abhigyanpatwari/GitNexus#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/abhigyanpatwari/GitNexus.git",
11
+ "directory": "gitnexus"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/abhigyanpatwari/GitNexus/issues"
15
+ },
16
+ "keywords": [
17
+ "mcp",
18
+ "model-context-protocol",
19
+ "code-intelligence",
20
+ "knowledge-graph",
21
+ "cursor",
22
+ "claude",
23
+ "ai-agent",
24
+ "gitnexus",
25
+ "static-analysis",
26
+ "codebase-indexing"
27
+ ],
28
+ "type": "module",
29
+ "bin": {
30
+ "gitnexus": "dist/cli/index.js"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "hooks",
35
+ "skills",
36
+ "vendor"
37
+ ],
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "dev": "tsx watch src/cli/index.ts",
41
+ "prepare": "npm run build",
42
+ "test:benchmark": "npm run build && node --test dist/benchmark/*.test.js dist/cli/*.test.js",
43
+ "benchmark:quick": "npm run build && node dist/cli/index.js benchmark-unity ../benchmarks/unity-baseline/v1 --profile quick --target-path ../benchmarks/fixtures/unity-mini",
44
+ "benchmark:full": "npm run build && node dist/cli/index.js benchmark-unity ../benchmarks/unity-baseline/v1 --profile full --target-path ../benchmarks/fixtures/unity-mini",
45
+ "benchmark:neonspark:full": "npm run build && node dist/cli/index.js benchmark-unity ../benchmarks/unity-baseline/neonspark-v1 --profile full --target-path /Volumes/Shuttle/unity-projects/neonspark --repo-alias neonspark-v1-subset --scope-manifest ../benchmarks/unity-baseline/neonspark-v1/sync-manifest.txt",
46
+ "benchmark:neonspark:quick": "npm run build && node dist/cli/index.js benchmark-unity ../benchmarks/unity-baseline/neonspark-v1 --profile quick --target-path /Volumes/Shuttle/unity-projects/neonspark --repo-alias neonspark-v1-subset --scope-manifest ../benchmarks/unity-baseline/neonspark-v1/sync-manifest.txt",
47
+ "benchmark:neonspark:v2:full": "npm run build && node dist/cli/index.js benchmark-unity ../benchmarks/unity-baseline/neonspark-v2 --profile full --target-path /Volumes/Shuttle/unity-projects/neonspark --repo-alias neonspark-v1-subset --scope-manifest ../benchmarks/unity-baseline/neonspark-v2/sync-manifest.txt",
48
+ "benchmark:neonspark:v2:quick": "npm run build && node dist/cli/index.js benchmark-unity ../benchmarks/unity-baseline/neonspark-v2 --profile quick --target-path /Volumes/Shuttle/unity-projects/neonspark --repo-alias neonspark-v1-subset --scope-manifest ../benchmarks/unity-baseline/neonspark-v2/sync-manifest.txt",
49
+ "benchmark:agent-context:quick": "npm run build && node dist/cli/index.js benchmark-agent-context ../benchmarks/agent-context/neonspark-refactor-v1 --profile quick --target-path /Volumes/Shuttle/unity-projects/neonspark --repo-alias neonspark-v1-subset --scope-manifest ../benchmarks/unity-baseline/neonspark-v2/sync-manifest.txt",
50
+ "benchmark:agent-context:full": "npm run build && node dist/cli/index.js benchmark-agent-context ../benchmarks/agent-context/neonspark-refactor-v1 --profile full --target-path /Volumes/Shuttle/unity-projects/neonspark --repo-alias neonspark-v1-subset --scope-manifest ../benchmarks/unity-baseline/neonspark-v2/sync-manifest.txt"
51
+ },
52
+ "dependencies": {
53
+ "@huggingface/transformers": "^3.0.0",
54
+ "@modelcontextprotocol/sdk": "^1.0.0",
55
+ "cli-progress": "^3.12.0",
56
+ "commander": "^12.0.0",
57
+ "cors": "^2.8.5",
58
+ "express": "^4.19.2",
59
+ "glob": "^11.0.0",
60
+ "graphology": "^0.25.4",
61
+ "graphology-indices": "^0.17.0",
62
+ "graphology-utils": "^2.3.0",
63
+ "kuzu": "^0.11.3",
64
+ "lru-cache": "^11.0.0",
65
+ "mnemonist": "^0.39.0",
66
+ "pandemonium": "^2.4.0",
67
+ "tree-sitter": "^0.21.0",
68
+ "tree-sitter-c": "^0.21.0",
69
+ "tree-sitter-c-sharp": "^0.21.0",
70
+ "tree-sitter-cpp": "^0.22.0",
71
+ "tree-sitter-go": "^0.21.0",
72
+ "tree-sitter-java": "^0.21.0",
73
+ "tree-sitter-javascript": "^0.21.0",
74
+ "tree-sitter-php": "^0.23.12",
75
+ "tree-sitter-python": "^0.21.0",
76
+ "tree-sitter-rust": "^0.21.0",
77
+ "tree-sitter-typescript": "^0.21.0",
78
+ "typescript": "^5.4.5",
79
+ "uuid": "^13.0.0"
80
+ },
81
+ "devDependencies": {
82
+ "@types/cli-progress": "^3.11.6",
83
+ "@types/cors": "^2.8.17",
84
+ "@types/express": "^4.17.21",
85
+ "@types/node": "^20.0.0",
86
+ "@types/uuid": "^10.0.0",
87
+ "tsx": "^4.0.0"
88
+ },
89
+ "engines": {
90
+ "node": ">=18.0.0"
91
+ }
92
+ }