gitnexus 1.6.0 → 1.6.2-rc.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.
Files changed (145) hide show
  1. package/README.md +73 -0
  2. package/dist/cli/analyze.js +50 -3
  3. package/dist/core/group/extractors/fs-utils.d.ts +10 -0
  4. package/dist/core/group/extractors/fs-utils.js +24 -0
  5. package/dist/core/group/extractors/grpc-extractor.d.ts +17 -8
  6. package/dist/core/group/extractors/grpc-extractor.js +328 -191
  7. package/dist/core/group/extractors/grpc-patterns/go.d.ts +2 -0
  8. package/dist/core/group/extractors/grpc-patterns/go.js +97 -0
  9. package/dist/core/group/extractors/grpc-patterns/index.d.ts +19 -0
  10. package/dist/core/group/extractors/grpc-patterns/index.js +46 -0
  11. package/dist/core/group/extractors/grpc-patterns/java.d.ts +2 -0
  12. package/dist/core/group/extractors/grpc-patterns/java.js +173 -0
  13. package/dist/core/group/extractors/grpc-patterns/node.d.ts +4 -0
  14. package/dist/core/group/extractors/grpc-patterns/node.js +290 -0
  15. package/dist/core/group/extractors/grpc-patterns/proto.d.ts +9 -0
  16. package/dist/core/group/extractors/grpc-patterns/proto.js +134 -0
  17. package/dist/core/group/extractors/grpc-patterns/python.d.ts +2 -0
  18. package/dist/core/group/extractors/grpc-patterns/python.js +67 -0
  19. package/dist/core/group/extractors/grpc-patterns/types.d.ts +50 -0
  20. package/dist/core/group/extractors/grpc-patterns/types.js +1 -0
  21. package/dist/core/group/extractors/http-patterns/go.d.ts +2 -0
  22. package/dist/core/group/extractors/http-patterns/go.js +215 -0
  23. package/dist/core/group/extractors/http-patterns/index.d.ts +17 -0
  24. package/dist/core/group/extractors/http-patterns/index.js +44 -0
  25. package/dist/core/group/extractors/http-patterns/java.d.ts +2 -0
  26. package/dist/core/group/extractors/http-patterns/java.js +253 -0
  27. package/dist/core/group/extractors/http-patterns/node.d.ts +4 -0
  28. package/dist/core/group/extractors/http-patterns/node.js +354 -0
  29. package/dist/core/group/extractors/http-patterns/php.d.ts +2 -0
  30. package/dist/core/group/extractors/http-patterns/php.js +70 -0
  31. package/dist/core/group/extractors/http-patterns/python.d.ts +2 -0
  32. package/dist/core/group/extractors/http-patterns/python.js +133 -0
  33. package/dist/core/group/extractors/http-patterns/types.d.ts +61 -0
  34. package/dist/core/group/extractors/http-patterns/types.js +1 -0
  35. package/dist/core/group/extractors/http-route-extractor.d.ts +10 -13
  36. package/dist/core/group/extractors/http-route-extractor.js +231 -238
  37. package/dist/core/group/extractors/manifest-extractor.d.ts +54 -0
  38. package/dist/core/group/extractors/manifest-extractor.js +277 -0
  39. package/dist/core/group/extractors/topic-extractor.d.ts +0 -1
  40. package/dist/core/group/extractors/topic-extractor.js +55 -192
  41. package/dist/core/group/extractors/topic-patterns/go.d.ts +2 -0
  42. package/dist/core/group/extractors/topic-patterns/go.js +120 -0
  43. package/dist/core/group/extractors/topic-patterns/index.d.ts +14 -0
  44. package/dist/core/group/extractors/topic-patterns/index.js +38 -0
  45. package/dist/core/group/extractors/topic-patterns/java.d.ts +2 -0
  46. package/dist/core/group/extractors/topic-patterns/java.js +80 -0
  47. package/dist/core/group/extractors/topic-patterns/node.d.ts +4 -0
  48. package/dist/core/group/extractors/topic-patterns/node.js +155 -0
  49. package/dist/core/group/extractors/topic-patterns/python.d.ts +2 -0
  50. package/dist/core/group/extractors/topic-patterns/python.js +116 -0
  51. package/dist/core/group/extractors/topic-patterns/types.d.ts +25 -0
  52. package/dist/core/group/extractors/topic-patterns/types.js +10 -0
  53. package/dist/core/group/extractors/tree-sitter-scanner.d.ts +113 -0
  54. package/dist/core/group/extractors/tree-sitter-scanner.js +94 -0
  55. package/dist/core/ingestion/binding-accumulator.d.ts +22 -17
  56. package/dist/core/ingestion/binding-accumulator.js +29 -25
  57. package/dist/core/ingestion/cobol-processor.d.ts +1 -1
  58. package/dist/core/ingestion/import-processor.js +1 -1
  59. package/dist/core/ingestion/language-config.js +1 -1
  60. package/dist/core/ingestion/language-provider.d.ts +32 -5
  61. package/dist/core/ingestion/languages/c-cpp.js +2 -2
  62. package/dist/core/ingestion/languages/dart.d.ts +1 -1
  63. package/dist/core/ingestion/languages/dart.js +2 -2
  64. package/dist/core/ingestion/languages/go.d.ts +1 -1
  65. package/dist/core/ingestion/languages/go.js +2 -2
  66. package/dist/core/ingestion/languages/ruby.js +16 -1
  67. package/dist/core/ingestion/languages/swift.d.ts +1 -1
  68. package/dist/core/ingestion/languages/swift.js +2 -2
  69. package/dist/core/ingestion/markdown-processor.d.ts +1 -1
  70. package/dist/core/ingestion/method-extractors/configs/jvm.js +1 -0
  71. package/dist/core/ingestion/method-extractors/configs/ruby.js +1 -0
  72. package/dist/core/ingestion/method-extractors/generic.d.ts +6 -0
  73. package/dist/core/ingestion/method-extractors/generic.js +48 -4
  74. package/dist/core/ingestion/method-types.d.ts +4 -0
  75. package/dist/core/ingestion/model/resolve.js +103 -48
  76. package/dist/core/ingestion/model/semantic-model.d.ts +1 -1
  77. package/dist/core/ingestion/model/semantic-model.js +1 -1
  78. package/dist/core/ingestion/model/symbol-table.d.ts +7 -7
  79. package/dist/core/ingestion/model/symbol-table.js +7 -7
  80. package/dist/core/ingestion/mro-processor.d.ts +1 -1
  81. package/dist/core/ingestion/mro-processor.js +1 -1
  82. package/dist/core/ingestion/parsing-processor.js +54 -42
  83. package/dist/core/ingestion/pipeline-phases/cobol.d.ts +16 -0
  84. package/dist/core/ingestion/pipeline-phases/cobol.js +45 -0
  85. package/dist/core/ingestion/pipeline-phases/communities.d.ts +16 -0
  86. package/dist/core/ingestion/pipeline-phases/communities.js +62 -0
  87. package/dist/core/ingestion/pipeline-phases/cross-file-impl.d.ts +17 -0
  88. package/dist/core/ingestion/pipeline-phases/cross-file-impl.js +156 -0
  89. package/dist/core/ingestion/pipeline-phases/cross-file.d.ts +37 -0
  90. package/dist/core/ingestion/pipeline-phases/cross-file.js +63 -0
  91. package/dist/core/ingestion/pipeline-phases/index.d.ts +21 -0
  92. package/dist/core/ingestion/pipeline-phases/index.js +22 -0
  93. package/dist/core/ingestion/pipeline-phases/markdown.d.ts +17 -0
  94. package/dist/core/ingestion/pipeline-phases/markdown.js +33 -0
  95. package/dist/core/ingestion/pipeline-phases/mro.d.ts +18 -0
  96. package/dist/core/ingestion/pipeline-phases/mro.js +36 -0
  97. package/dist/core/ingestion/pipeline-phases/orm-extraction.d.ts +22 -0
  98. package/dist/core/ingestion/pipeline-phases/orm-extraction.js +92 -0
  99. package/dist/core/ingestion/pipeline-phases/orm.d.ts +15 -0
  100. package/dist/core/ingestion/pipeline-phases/orm.js +74 -0
  101. package/dist/core/ingestion/pipeline-phases/parse-impl.d.ts +47 -0
  102. package/dist/core/ingestion/pipeline-phases/parse-impl.js +437 -0
  103. package/dist/core/ingestion/pipeline-phases/parse.d.ts +49 -0
  104. package/dist/core/ingestion/pipeline-phases/parse.js +33 -0
  105. package/dist/core/ingestion/pipeline-phases/processes.d.ts +16 -0
  106. package/dist/core/ingestion/pipeline-phases/processes.js +143 -0
  107. package/dist/core/ingestion/pipeline-phases/routes.d.ts +21 -0
  108. package/dist/core/ingestion/pipeline-phases/routes.js +243 -0
  109. package/dist/core/ingestion/pipeline-phases/runner.d.ts +22 -0
  110. package/dist/core/ingestion/pipeline-phases/runner.js +203 -0
  111. package/dist/core/ingestion/pipeline-phases/scan.d.ts +21 -0
  112. package/dist/core/ingestion/pipeline-phases/scan.js +46 -0
  113. package/dist/core/ingestion/pipeline-phases/structure.d.ts +27 -0
  114. package/dist/core/ingestion/pipeline-phases/structure.js +35 -0
  115. package/dist/core/ingestion/pipeline-phases/tools.d.ts +20 -0
  116. package/dist/core/ingestion/pipeline-phases/tools.js +79 -0
  117. package/dist/core/ingestion/pipeline-phases/types.d.ts +79 -0
  118. package/dist/core/ingestion/pipeline-phases/types.js +37 -0
  119. package/dist/core/ingestion/pipeline-phases/wildcard-synthesis.d.ts +70 -0
  120. package/dist/core/ingestion/pipeline-phases/wildcard-synthesis.js +312 -0
  121. package/dist/core/ingestion/pipeline.d.ts +16 -10
  122. package/dist/core/ingestion/pipeline.js +66 -1534
  123. package/dist/core/ingestion/process-processor.js +1 -1
  124. package/dist/core/ingestion/tree-sitter-queries.d.ts +2 -2
  125. package/dist/core/ingestion/tree-sitter-queries.js +69 -0
  126. package/dist/core/ingestion/utils/ast-helpers.d.ts +1 -3
  127. package/dist/core/ingestion/utils/ast-helpers.js +48 -21
  128. package/dist/core/ingestion/utils/env.d.ts +10 -0
  129. package/dist/core/ingestion/utils/env.js +10 -0
  130. package/dist/core/ingestion/utils/graph-sort.d.ts +58 -0
  131. package/dist/core/ingestion/utils/graph-sort.js +100 -0
  132. package/dist/core/ingestion/workers/parse-worker.js +12 -8
  133. package/dist/core/lbug/lbug-adapter.d.ts +28 -0
  134. package/dist/core/lbug/lbug-adapter.js +162 -57
  135. package/package.json +3 -3
  136. package/vendor/tree-sitter-proto/binding.gyp +30 -0
  137. package/vendor/tree-sitter-proto/bindings/node/binding.cc +20 -0
  138. package/vendor/tree-sitter-proto/bindings/node/index.d.ts +28 -0
  139. package/vendor/tree-sitter-proto/bindings/node/index.js +7 -0
  140. package/vendor/tree-sitter-proto/package.json +18 -0
  141. package/vendor/tree-sitter-proto/src/node-types.json +1145 -0
  142. package/vendor/tree-sitter-proto/src/parser.c +10149 -0
  143. package/vendor/tree-sitter-proto/src/tree_sitter/alloc.h +54 -0
  144. package/vendor/tree-sitter-proto/src/tree_sitter/array.h +291 -0
  145. package/vendor/tree-sitter-proto/src/tree_sitter/parser.h +266 -0
package/README.md CHANGED
@@ -234,6 +234,79 @@ Installed automatically by both `gitnexus analyze` (per-repo) and `gitnexus setu
234
234
  - Node.js >= 18
235
235
  - Git repository (uses git for commit tracking)
236
236
 
237
+ ## Release candidates
238
+
239
+ Stable releases publish to the default `latest` dist-tag. When a pull request
240
+ with non-documentation changes merges into `main`, an automated workflow also
241
+ publishes a prerelease build under the `rc` dist-tag, so early adopters can
242
+ try in-flight fixes without waiting for the next stable cut. (Docs-only
243
+ merges are skipped.)
244
+
245
+ ```bash
246
+ # Try the latest release candidate (pre-stable — may change at any time)
247
+ npm install -g gitnexus@rc
248
+ # — or —
249
+ npx gitnexus@rc analyze
250
+ ```
251
+
252
+ Release-candidate versions follow the standard semver prerelease format
253
+ `X.Y.Z-rc.N`, where `X.Y.Z` is the next stable target (bumped from the
254
+ current `latest` by patch by default; `minor` or `major` when kicking off a
255
+ bigger cycle) and `N` increments per published rc. Example sequence:
256
+ `1.6.2-rc.1`, `1.6.2-rc.2`, …, then once `1.6.2` ships stable,
257
+ `1.6.3-rc.1`. See the [Releases page](https://github.com/abhigyanpatwari/GitNexus/releases)
258
+ for the full list; stable `latest` is unaffected.
259
+
260
+ ## Troubleshooting
261
+
262
+ ### `Cannot destructure property 'package' of 'node.target' as it is null`
263
+
264
+ This crash was caused by a dependency URL format that is incompatible with
265
+ certain npm/arborist versions ([npm/cli#8126](https://github.com/npm/cli/issues/8126)).
266
+ It is fixed in **gitnexus v1.6.2+**. Upgrade to the latest version:
267
+
268
+ ```bash
269
+ npx gitnexus@latest analyze # always uses the newest release
270
+ # — or —
271
+ npm install -g gitnexus@latest # upgrade a global install
272
+ ```
273
+
274
+ If you still hit npm install issues after upgrading, these generic workarounds
275
+ may help:
276
+
277
+ ```bash
278
+ npm install -g npm@latest # update npm itself
279
+ npm cache clean --force # clear a possibly corrupt cache
280
+ ```
281
+
282
+ ### Installation fails with native module errors
283
+
284
+ Some optional language grammars (Dart, Kotlin, Swift) require native compilation. If they fail, GitNexus still works — those languages will be skipped.
285
+
286
+ If `npm install -g gitnexus` fails on native modules:
287
+
288
+ ```bash
289
+ # Ensure build tools are available (Linux/macOS)
290
+ # Ubuntu/Debian: sudo apt install python3 make g++
291
+ # macOS: xcode-select --install
292
+
293
+ # Retry installation
294
+ npm install -g gitnexus
295
+ ```
296
+
297
+ ### Analysis runs out of memory
298
+
299
+ For very large repositories:
300
+
301
+ ```bash
302
+ # Increase Node.js heap size
303
+ NODE_OPTIONS="--max-old-space-size=16384" npx gitnexus analyze
304
+
305
+ # Exclude large directories
306
+ echo "vendor/" >> .gitnexusignore
307
+ echo "dist/" >> .gitnexusignore
308
+ ```
309
+
237
310
  ## Privacy
238
311
 
239
312
  - All processing happens locally on your machine
@@ -18,7 +18,10 @@ import { runFullAnalysis } from '../core/run-analyze.js';
18
18
  import fs from 'fs/promises';
19
19
  const HEAP_MB = 8192;
20
20
  const HEAP_FLAG = `--max-old-space-size=${HEAP_MB}`;
21
- /** Re-exec the process with an 8GB heap if we're currently below that. */
21
+ /** Increase default stack size (KB) to prevent stack overflow on deep class hierarchies. */
22
+ const STACK_KB = 4096;
23
+ const STACK_FLAG = `--stack-size=${STACK_KB}`;
24
+ /** Re-exec the process with an 8GB heap and larger stack if we're currently below that. */
22
25
  function ensureHeap() {
23
26
  const nodeOpts = process.env.NODE_OPTIONS || '';
24
27
  if (nodeOpts.includes('--max-old-space-size'))
@@ -26,8 +29,13 @@ function ensureHeap() {
26
29
  const v8Heap = v8.getHeapStatistics().heap_size_limit;
27
30
  if (v8Heap >= HEAP_MB * 1024 * 1024 * 0.9)
28
31
  return false;
32
+ // --stack-size is a V8 flag not allowed in NODE_OPTIONS on Node 24+,
33
+ // so pass it only as a direct CLI argument, not via the environment.
34
+ const cliFlags = [HEAP_FLAG];
35
+ if (!nodeOpts.includes('--stack-size'))
36
+ cliFlags.push(STACK_FLAG);
29
37
  try {
30
- execFileSync(process.execPath, [HEAP_FLAG, ...process.argv.slice(1)], {
38
+ execFileSync(process.execPath, [...cliFlags, ...process.argv.slice(1)], {
31
39
  stdio: 'inherit',
32
40
  env: { ...process.env, NODE_OPTIONS: `${nodeOpts} ${HEAP_FLAG}`.trim() },
33
41
  });
@@ -222,7 +230,46 @@ export const analyzeCommand = async (inputPath, options) => {
222
230
  console.warn = origWarn;
223
231
  console.error = origError;
224
232
  bar.stop();
225
- console.error(`\n Analysis failed: ${err.message}\n`);
233
+ const msg = err.message || String(err);
234
+ console.error(`\n Analysis failed: ${msg}\n`);
235
+ // Provide helpful guidance for known failure modes
236
+ if (msg.includes('Maximum call stack size exceeded') ||
237
+ msg.includes('call stack') ||
238
+ msg.includes('Map maximum size') ||
239
+ msg.includes('Invalid array length') ||
240
+ msg.includes('Invalid string length') ||
241
+ msg.includes('allocation failed') ||
242
+ msg.includes('heap out of memory') ||
243
+ msg.includes('JavaScript heap')) {
244
+ console.error(' This error typically occurs on very large repositories.');
245
+ console.error(' Suggestions:');
246
+ console.error(' 1. Add large vendored/generated directories to .gitnexusignore');
247
+ console.error(' 2. Increase Node.js heap: NODE_OPTIONS="--max-old-space-size=16384"');
248
+ console.error(' 3. Increase stack size: NODE_OPTIONS="--stack-size=4096"');
249
+ console.error('');
250
+ }
251
+ else if (msg.includes('ERESOLVE') || msg.includes('Could not resolve dependency')) {
252
+ // Note: the original arborist "Cannot destructure property 'package' of
253
+ // 'node.target'" crash happens inside npm *before* gitnexus code runs,
254
+ // so it can't be caught here. This branch handles dependency-resolution
255
+ // errors that surface at runtime (e.g. dynamic require failures).
256
+ console.error(' This looks like an npm dependency resolution issue.');
257
+ console.error(' Suggestions:');
258
+ console.error(' 1. Clear the npm cache: npm cache clean --force');
259
+ console.error(' 2. Update npm: npm install -g npm@latest');
260
+ console.error(' 3. Reinstall gitnexus: npm install -g gitnexus@latest');
261
+ console.error(' 4. Or try npx directly: npx gitnexus@latest analyze');
262
+ console.error('');
263
+ }
264
+ else if (msg.includes('MODULE_NOT_FOUND') ||
265
+ msg.includes('Cannot find module') ||
266
+ msg.includes('ERR_MODULE_NOT_FOUND')) {
267
+ console.error(' A required module could not be loaded. The installation may be corrupt.');
268
+ console.error(' Suggestions:');
269
+ console.error(' 1. Reinstall: npm install -g gitnexus@latest');
270
+ console.error(' 2. Clear cache: npm cache clean --force && npx gitnexus@latest analyze');
271
+ console.error('');
272
+ }
226
273
  process.exitCode = 1;
227
274
  return;
228
275
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Safely read a file inside a repo, rejecting any path that escapes
3
+ * `repoPath` via `..` traversal or absolute segments. Returns `null` if
4
+ * the path is outside the repo or the file can't be read.
5
+ *
6
+ * Used by every source-scan extractor under this directory. Kept as a
7
+ * single shared implementation so the path-traversal guard (security-
8
+ * sensitive) lives in exactly one place.
9
+ */
10
+ export declare function readSafe(repoPath: string, rel: string): string | null;
@@ -0,0 +1,24 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ /**
4
+ * Safely read a file inside a repo, rejecting any path that escapes
5
+ * `repoPath` via `..` traversal or absolute segments. Returns `null` if
6
+ * the path is outside the repo or the file can't be read.
7
+ *
8
+ * Used by every source-scan extractor under this directory. Kept as a
9
+ * single shared implementation so the path-traversal guard (security-
10
+ * sensitive) lives in exactly one place.
11
+ */
12
+ export function readSafe(repoPath, rel) {
13
+ const abs = path.resolve(repoPath, rel);
14
+ const base = path.resolve(repoPath);
15
+ const relToBase = path.relative(base, abs);
16
+ if (relToBase.startsWith('..') || path.isAbsolute(relToBase))
17
+ return null;
18
+ try {
19
+ return fs.readFileSync(abs, 'utf-8');
20
+ }
21
+ catch {
22
+ return null;
23
+ }
24
+ }
@@ -1,16 +1,25 @@
1
1
  import type { ContractExtractor, CypherExecutor } from '../contract-extractor.js';
2
2
  import type { ExtractedContract, RepoHandle } from '../types.js';
3
+ export interface ProtoServiceInfo {
4
+ package: string;
5
+ serviceName: string;
6
+ methods: string[];
7
+ protoPath: string;
8
+ }
9
+ export declare function buildProtoMap(repoPath: string): Promise<Map<string, ProtoServiceInfo[]>>;
10
+ export declare function resolveProtoConflict(serviceName: string, sourceFilePath: string, candidates: ProtoServiceInfo[]): ProtoServiceInfo | null;
11
+ export declare function serviceContractId(pkg: string, serviceName: string): string;
3
12
  export declare class GrpcExtractor implements ContractExtractor {
4
13
  type: "grpc";
5
14
  canExtract(_repo: RepoHandle): Promise<boolean>;
6
15
  extract(_dbExecutor: CypherExecutor | null, repoPath: string, _repo: RepoHandle): Promise<ExtractedContract[]>;
7
- private parseProtoFile;
8
- private scanGoProviders;
9
- private scanGoConsumers;
10
- private scanJavaProviders;
11
- private scanJavaConsumers;
12
- private scanPythonProviders;
13
- private scanPythonConsumers;
14
- private scanTsProviders;
16
+ /**
17
+ * Convert a plugin `GrpcDetection` into a concrete `ExtractedContract`
18
+ * by resolving the short service name against the proto map, building
19
+ * either a service-level (`grpc::pkg.Svc/*`) or method-level
20
+ * (`grpc::pkg.Svc/Method`) contract id, and selecting confidence
21
+ * based on whether the proto map had an entry.
22
+ */
23
+ private detectionToContract;
15
24
  private dedupe;
16
25
  }