@veewo/gitnexus 1.3.11 → 1.4.6-rc

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 (181) hide show
  1. package/README.md +37 -80
  2. package/dist/benchmark/agent-context/tool-runner.js +2 -2
  3. package/dist/benchmark/neonspark-candidates.js +3 -3
  4. package/dist/benchmark/tool-runner.js +2 -2
  5. package/dist/cli/ai-context.d.ts +2 -1
  6. package/dist/cli/ai-context.js +16 -12
  7. package/dist/cli/analyze.d.ts +2 -0
  8. package/dist/cli/analyze.js +68 -48
  9. package/dist/cli/augment.js +1 -1
  10. package/dist/cli/eval-server.d.ts +8 -1
  11. package/dist/cli/eval-server.js +30 -13
  12. package/dist/cli/index.js +28 -82
  13. package/dist/cli/lazy-action.d.ts +6 -0
  14. package/dist/cli/lazy-action.js +18 -0
  15. package/dist/cli/mcp.js +3 -1
  16. package/dist/cli/setup.js +87 -48
  17. package/dist/cli/setup.test.js +18 -13
  18. package/dist/cli/skill-gen.d.ts +26 -0
  19. package/dist/cli/skill-gen.js +549 -0
  20. package/dist/cli/status.js +13 -4
  21. package/dist/cli/tool.d.ts +3 -2
  22. package/dist/cli/tool.js +50 -16
  23. package/dist/cli/wiki.js +8 -4
  24. package/dist/config/ignore-service.d.ts +25 -0
  25. package/dist/config/ignore-service.js +76 -0
  26. package/dist/config/supported-languages.d.ts +4 -1
  27. package/dist/config/supported-languages.js +3 -2
  28. package/dist/core/augmentation/engine.js +94 -67
  29. package/dist/core/embeddings/embedder.d.ts +1 -1
  30. package/dist/core/embeddings/embedder.js +1 -1
  31. package/dist/core/embeddings/embedding-pipeline.d.ts +3 -3
  32. package/dist/core/embeddings/embedding-pipeline.js +52 -25
  33. package/dist/core/embeddings/types.d.ts +1 -1
  34. package/dist/core/graph/types.d.ts +7 -2
  35. package/dist/core/ingestion/ast-cache.js +3 -2
  36. package/dist/core/ingestion/call-processor.d.ts +8 -6
  37. package/dist/core/ingestion/call-processor.js +468 -206
  38. package/dist/core/ingestion/call-routing.d.ts +53 -0
  39. package/dist/core/ingestion/call-routing.js +108 -0
  40. package/dist/core/ingestion/constants.d.ts +16 -0
  41. package/dist/core/ingestion/constants.js +16 -0
  42. package/dist/core/ingestion/entry-point-scoring.d.ts +2 -1
  43. package/dist/core/ingestion/entry-point-scoring.js +116 -23
  44. package/dist/core/ingestion/export-detection.d.ts +18 -0
  45. package/dist/core/ingestion/export-detection.js +231 -0
  46. package/dist/core/ingestion/filesystem-walker.js +4 -3
  47. package/dist/core/ingestion/framework-detection.d.ts +19 -4
  48. package/dist/core/ingestion/framework-detection.js +182 -6
  49. package/dist/core/ingestion/heritage-processor.d.ts +13 -5
  50. package/dist/core/ingestion/heritage-processor.js +109 -55
  51. package/dist/core/ingestion/import-processor.d.ts +16 -20
  52. package/dist/core/ingestion/import-processor.js +199 -579
  53. package/dist/core/ingestion/language-config.d.ts +46 -0
  54. package/dist/core/ingestion/language-config.js +167 -0
  55. package/dist/core/ingestion/mro-processor.d.ts +45 -0
  56. package/dist/core/ingestion/mro-processor.js +369 -0
  57. package/dist/core/ingestion/named-binding-extraction.d.ts +61 -0
  58. package/dist/core/ingestion/named-binding-extraction.js +363 -0
  59. package/dist/core/ingestion/parsing-processor.d.ts +4 -1
  60. package/dist/core/ingestion/parsing-processor.js +107 -109
  61. package/dist/core/ingestion/pipeline.d.ts +6 -3
  62. package/dist/core/ingestion/pipeline.js +208 -114
  63. package/dist/core/ingestion/process-processor.js +8 -2
  64. package/dist/core/ingestion/resolution-context.d.ts +53 -0
  65. package/dist/core/ingestion/resolution-context.js +132 -0
  66. package/dist/core/ingestion/resolvers/csharp.d.ts +22 -0
  67. package/dist/core/ingestion/resolvers/csharp.js +109 -0
  68. package/dist/core/ingestion/resolvers/go.d.ts +19 -0
  69. package/dist/core/ingestion/resolvers/go.js +42 -0
  70. package/dist/core/ingestion/resolvers/index.d.ts +18 -0
  71. package/dist/core/ingestion/resolvers/index.js +13 -0
  72. package/dist/core/ingestion/resolvers/jvm.d.ts +23 -0
  73. package/dist/core/ingestion/resolvers/jvm.js +87 -0
  74. package/dist/core/ingestion/resolvers/php.d.ts +15 -0
  75. package/dist/core/ingestion/resolvers/php.js +35 -0
  76. package/dist/core/ingestion/resolvers/python.d.ts +19 -0
  77. package/dist/core/ingestion/resolvers/python.js +52 -0
  78. package/dist/core/ingestion/resolvers/ruby.d.ts +12 -0
  79. package/dist/core/ingestion/resolvers/ruby.js +15 -0
  80. package/dist/core/ingestion/resolvers/rust.d.ts +15 -0
  81. package/dist/core/ingestion/resolvers/rust.js +73 -0
  82. package/dist/core/ingestion/resolvers/standard.d.ts +28 -0
  83. package/dist/core/ingestion/resolvers/standard.js +123 -0
  84. package/dist/core/ingestion/resolvers/utils.d.ts +33 -0
  85. package/dist/core/ingestion/resolvers/utils.js +122 -0
  86. package/dist/core/ingestion/symbol-table.d.ts +21 -1
  87. package/dist/core/ingestion/symbol-table.js +40 -12
  88. package/dist/core/ingestion/tree-sitter-queries.d.ts +13 -10
  89. package/dist/core/ingestion/tree-sitter-queries.js +297 -7
  90. package/dist/core/ingestion/type-env.d.ts +49 -0
  91. package/dist/core/ingestion/type-env.js +611 -0
  92. package/dist/core/ingestion/type-extractors/c-cpp.d.ts +2 -0
  93. package/dist/core/ingestion/type-extractors/c-cpp.js +385 -0
  94. package/dist/core/ingestion/type-extractors/csharp.d.ts +2 -0
  95. package/dist/core/ingestion/type-extractors/csharp.js +383 -0
  96. package/dist/core/ingestion/type-extractors/go.d.ts +2 -0
  97. package/dist/core/ingestion/type-extractors/go.js +467 -0
  98. package/dist/core/ingestion/type-extractors/index.d.ts +22 -0
  99. package/dist/core/ingestion/type-extractors/index.js +31 -0
  100. package/dist/core/ingestion/type-extractors/jvm.d.ts +3 -0
  101. package/dist/core/ingestion/type-extractors/jvm.js +681 -0
  102. package/dist/core/ingestion/type-extractors/php.d.ts +2 -0
  103. package/dist/core/ingestion/type-extractors/php.js +549 -0
  104. package/dist/core/ingestion/type-extractors/python.d.ts +2 -0
  105. package/dist/core/ingestion/type-extractors/python.js +406 -0
  106. package/dist/core/ingestion/type-extractors/ruby.d.ts +2 -0
  107. package/dist/core/ingestion/type-extractors/ruby.js +389 -0
  108. package/dist/core/ingestion/type-extractors/rust.d.ts +2 -0
  109. package/dist/core/ingestion/type-extractors/rust.js +449 -0
  110. package/dist/core/ingestion/type-extractors/shared.d.ts +133 -0
  111. package/dist/core/ingestion/type-extractors/shared.js +703 -0
  112. package/dist/core/ingestion/type-extractors/swift.d.ts +2 -0
  113. package/dist/core/ingestion/type-extractors/swift.js +137 -0
  114. package/dist/core/ingestion/type-extractors/types.d.ts +127 -0
  115. package/dist/core/ingestion/type-extractors/typescript.d.ts +2 -0
  116. package/dist/core/ingestion/type-extractors/typescript.js +494 -0
  117. package/dist/core/ingestion/utils.d.ts +103 -0
  118. package/dist/core/ingestion/utils.js +1085 -4
  119. package/dist/core/ingestion/workers/parse-worker.d.ts +51 -4
  120. package/dist/core/ingestion/workers/parse-worker.js +634 -222
  121. package/dist/core/ingestion/workers/worker-pool.js +8 -0
  122. package/dist/core/{kuzu → lbug}/csv-generator.d.ts +12 -10
  123. package/dist/core/{kuzu → lbug}/csv-generator.js +82 -101
  124. package/dist/core/{kuzu/kuzu-adapter.d.ts → lbug/lbug-adapter.d.ts} +20 -25
  125. package/dist/core/{kuzu/kuzu-adapter.js → lbug/lbug-adapter.js} +150 -122
  126. package/dist/core/{kuzu → lbug}/schema.d.ts +4 -4
  127. package/dist/core/{kuzu → lbug}/schema.js +23 -22
  128. package/dist/core/lbug/schema.test.d.ts +1 -0
  129. package/dist/core/search/bm25-index.d.ts +4 -4
  130. package/dist/core/search/bm25-index.js +12 -11
  131. package/dist/core/search/hybrid-search.d.ts +2 -2
  132. package/dist/core/search/hybrid-search.js +6 -6
  133. package/dist/core/tree-sitter/parser-loader.d.ts +1 -0
  134. package/dist/core/tree-sitter/parser-loader.js +19 -0
  135. package/dist/core/wiki/generator.d.ts +2 -2
  136. package/dist/core/wiki/generator.js +6 -6
  137. package/dist/core/wiki/graph-queries.d.ts +4 -4
  138. package/dist/core/wiki/graph-queries.js +7 -7
  139. package/dist/mcp/compatible-stdio-transport.d.ts +25 -0
  140. package/dist/mcp/compatible-stdio-transport.js +200 -0
  141. package/dist/mcp/core/{kuzu-adapter.d.ts → lbug-adapter.d.ts} +11 -10
  142. package/dist/mcp/core/lbug-adapter.js +327 -0
  143. package/dist/mcp/local/local-backend.d.ts +21 -16
  144. package/dist/mcp/local/local-backend.js +306 -706
  145. package/dist/mcp/local/unity-parity-seed-loader.d.ts +6 -1
  146. package/dist/mcp/local/unity-parity-seed-loader.js +119 -9
  147. package/dist/mcp/local/unity-parity-seed-loader.test.js +95 -7
  148. package/dist/mcp/resources.js +2 -2
  149. package/dist/mcp/server.js +28 -13
  150. package/dist/mcp/staleness.js +2 -2
  151. package/dist/mcp/tools.js +12 -3
  152. package/dist/server/api.js +12 -12
  153. package/dist/server/mcp-http.d.ts +1 -1
  154. package/dist/server/mcp-http.js +1 -1
  155. package/dist/storage/git.js +4 -1
  156. package/dist/storage/repo-manager.d.ts +20 -2
  157. package/dist/storage/repo-manager.js +74 -4
  158. package/dist/types/pipeline.d.ts +1 -1
  159. package/hooks/claude/gitnexus-hook.cjs +149 -46
  160. package/hooks/claude/pre-tool-use.sh +2 -1
  161. package/hooks/claude/session-start.sh +0 -0
  162. package/package.json +20 -4
  163. package/scripts/patch-tree-sitter-swift.cjs +74 -0
  164. package/skills/gitnexus-cli.md +8 -8
  165. package/skills/gitnexus-debugging.md +1 -1
  166. package/skills/gitnexus-exploring.md +1 -1
  167. package/skills/gitnexus-guide.md +1 -1
  168. package/skills/gitnexus-impact-analysis.md +1 -1
  169. package/skills/gitnexus-pr-review.md +163 -0
  170. package/skills/gitnexus-refactoring.md +1 -1
  171. package/dist/cli/claude-hooks.d.ts +0 -22
  172. package/dist/cli/claude-hooks.js +0 -97
  173. package/dist/mcp/core/kuzu-adapter.js +0 -231
  174. /package/dist/core/{kuzu/csv-generator.test.d.ts → ingestion/type-extractors/types.js} +0 -0
  175. /package/dist/core/{kuzu/relationship-pair-buckets.test.d.ts → lbug/csv-generator.test.d.ts} +0 -0
  176. /package/dist/core/{kuzu → lbug}/csv-generator.test.js +0 -0
  177. /package/dist/core/{kuzu → lbug}/relationship-pair-buckets.d.ts +0 -0
  178. /package/dist/core/{kuzu → lbug}/relationship-pair-buckets.js +0 -0
  179. /package/dist/core/{kuzu/schema.test.d.ts → lbug/relationship-pair-buckets.test.d.ts} +0 -0
  180. /package/dist/core/{kuzu → lbug}/relationship-pair-buckets.test.js +0 -0
  181. /package/dist/core/{kuzu → lbug}/schema.test.js +0 -0
@@ -1,9 +1,558 @@
1
1
  import { SupportedLanguages } from '../../config/supported-languages.js';
2
+ import { generateId } from '../../lib/utils.js';
3
+ /**
4
+ * Ordered list of definition capture keys for tree-sitter query matches.
5
+ * Used to extract the definition node from a capture map.
6
+ */
7
+ export const DEFINITION_CAPTURE_KEYS = [
8
+ 'definition.function',
9
+ 'definition.class',
10
+ 'definition.interface',
11
+ 'definition.method',
12
+ 'definition.struct',
13
+ 'definition.enum',
14
+ 'definition.namespace',
15
+ 'definition.module',
16
+ 'definition.trait',
17
+ 'definition.impl',
18
+ 'definition.type',
19
+ 'definition.const',
20
+ 'definition.static',
21
+ 'definition.typedef',
22
+ 'definition.macro',
23
+ 'definition.union',
24
+ 'definition.property',
25
+ 'definition.record',
26
+ 'definition.delegate',
27
+ 'definition.annotation',
28
+ 'definition.constructor',
29
+ 'definition.template',
30
+ ];
31
+ /** Extract the definition node from a tree-sitter query capture map. */
32
+ export const getDefinitionNodeFromCaptures = (captureMap) => {
33
+ for (const key of DEFINITION_CAPTURE_KEYS) {
34
+ if (captureMap[key])
35
+ return captureMap[key];
36
+ }
37
+ return null;
38
+ };
39
+ /**
40
+ * Node types that represent function/method definitions across languages.
41
+ * Used to find the enclosing function for a call site.
42
+ */
43
+ export const FUNCTION_NODE_TYPES = new Set([
44
+ // TypeScript/JavaScript
45
+ 'function_declaration',
46
+ 'arrow_function',
47
+ 'function_expression',
48
+ 'method_definition',
49
+ 'generator_function_declaration',
50
+ // Python
51
+ 'function_definition',
52
+ // Common async variants
53
+ 'async_function_declaration',
54
+ 'async_arrow_function',
55
+ // Java
56
+ 'method_declaration',
57
+ 'constructor_declaration',
58
+ // C/C++
59
+ // 'function_definition' already included above
60
+ // Go
61
+ // 'method_declaration' already included from Java
62
+ // C#
63
+ 'local_function_statement',
64
+ // Rust
65
+ 'function_item',
66
+ 'impl_item', // Methods inside impl blocks
67
+ // PHP
68
+ 'anonymous_function',
69
+ // Kotlin
70
+ 'lambda_literal',
71
+ // Swift
72
+ 'init_declaration',
73
+ 'deinit_declaration',
74
+ // Ruby
75
+ 'method', // def foo
76
+ 'singleton_method', // def self.foo
77
+ ]);
78
+ /**
79
+ * Node types for standard function declarations that need C/C++ declarator handling.
80
+ * Used by extractFunctionName to determine how to extract the function name.
81
+ */
82
+ export const FUNCTION_DECLARATION_TYPES = new Set([
83
+ 'function_declaration',
84
+ 'function_definition',
85
+ 'async_function_declaration',
86
+ 'generator_function_declaration',
87
+ 'function_item',
88
+ ]);
89
+ /**
90
+ * Built-in function/method names that should not be tracked as call targets.
91
+ * Covers JS/TS, Python, Kotlin, C/C++, PHP, Swift standard library functions.
92
+ */
93
+ export const BUILT_IN_NAMES = new Set([
94
+ // JavaScript/TypeScript
95
+ 'console', 'log', 'warn', 'error', 'info', 'debug',
96
+ 'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval',
97
+ 'parseInt', 'parseFloat', 'isNaN', 'isFinite',
98
+ 'encodeURI', 'decodeURI', 'encodeURIComponent', 'decodeURIComponent',
99
+ 'JSON', 'parse', 'stringify',
100
+ 'Object', 'Array', 'String', 'Number', 'Boolean', 'Symbol', 'BigInt',
101
+ 'Map', 'Set', 'WeakMap', 'WeakSet',
102
+ 'Promise', 'resolve', 'reject', 'then', 'catch', 'finally',
103
+ 'Math', 'Date', 'RegExp', 'Error',
104
+ 'require', 'import', 'export', 'fetch', 'Response', 'Request',
105
+ 'useState', 'useEffect', 'useCallback', 'useMemo', 'useRef', 'useContext',
106
+ 'useReducer', 'useLayoutEffect', 'useImperativeHandle', 'useDebugValue',
107
+ 'createElement', 'createContext', 'createRef', 'forwardRef', 'memo', 'lazy',
108
+ 'map', 'filter', 'reduce', 'forEach', 'find', 'findIndex', 'some', 'every',
109
+ 'includes', 'indexOf', 'slice', 'splice', 'concat', 'join', 'split',
110
+ 'push', 'pop', 'shift', 'unshift', 'sort', 'reverse',
111
+ 'keys', 'values', 'entries', 'assign', 'freeze', 'seal',
112
+ 'hasOwnProperty', 'toString', 'valueOf',
113
+ // Python
114
+ 'print', 'len', 'range', 'str', 'int', 'float', 'list', 'dict', 'set', 'tuple',
115
+ 'append', 'extend', 'update',
116
+ // NOTE: 'open', 'read', 'write', 'close' removed — these are real C POSIX syscalls
117
+ 'type', 'isinstance', 'issubclass', 'getattr', 'setattr', 'hasattr',
118
+ 'enumerate', 'zip', 'sorted', 'reversed', 'min', 'max', 'sum', 'abs',
119
+ // Kotlin stdlib
120
+ 'println', 'print', 'readLine', 'require', 'requireNotNull', 'check', 'assert', 'lazy', 'error',
121
+ 'listOf', 'mapOf', 'setOf', 'mutableListOf', 'mutableMapOf', 'mutableSetOf',
122
+ 'arrayOf', 'sequenceOf', 'also', 'apply', 'run', 'with', 'takeIf', 'takeUnless',
123
+ 'TODO', 'buildString', 'buildList', 'buildMap', 'buildSet',
124
+ 'repeat', 'synchronized',
125
+ // Kotlin coroutine builders & scope functions
126
+ 'launch', 'async', 'runBlocking', 'withContext', 'coroutineScope',
127
+ 'supervisorScope', 'delay',
128
+ // Kotlin Flow operators
129
+ 'flow', 'flowOf', 'collect', 'emit', 'onEach', 'catch',
130
+ 'buffer', 'conflate', 'distinctUntilChanged',
131
+ 'flatMapLatest', 'flatMapMerge', 'combine',
132
+ 'stateIn', 'shareIn', 'launchIn',
133
+ // Kotlin infix stdlib functions
134
+ 'to', 'until', 'downTo', 'step',
135
+ // C/C++ standard library
136
+ 'printf', 'fprintf', 'sprintf', 'snprintf', 'vprintf', 'vfprintf', 'vsprintf', 'vsnprintf',
137
+ 'scanf', 'fscanf', 'sscanf',
138
+ 'malloc', 'calloc', 'realloc', 'free', 'memcpy', 'memmove', 'memset', 'memcmp',
139
+ 'strlen', 'strcpy', 'strncpy', 'strcat', 'strncat', 'strcmp', 'strncmp', 'strstr', 'strchr', 'strrchr',
140
+ 'atoi', 'atol', 'atof', 'strtol', 'strtoul', 'strtoll', 'strtoull', 'strtod',
141
+ 'sizeof', 'offsetof', 'typeof',
142
+ 'assert', 'abort', 'exit', '_exit',
143
+ 'fopen', 'fclose', 'fread', 'fwrite', 'fseek', 'ftell', 'rewind', 'fflush', 'fgets', 'fputs',
144
+ // Linux kernel common macros/helpers (not real call targets)
145
+ 'likely', 'unlikely', 'BUG', 'BUG_ON', 'WARN', 'WARN_ON', 'WARN_ONCE',
146
+ 'IS_ERR', 'PTR_ERR', 'ERR_PTR', 'IS_ERR_OR_NULL',
147
+ 'ARRAY_SIZE', 'container_of', 'list_for_each_entry', 'list_for_each_entry_safe',
148
+ 'min', 'max', 'clamp', 'abs', 'swap',
149
+ 'pr_info', 'pr_warn', 'pr_err', 'pr_debug', 'pr_notice', 'pr_crit', 'pr_emerg',
150
+ 'printk', 'dev_info', 'dev_warn', 'dev_err', 'dev_dbg',
151
+ 'GFP_KERNEL', 'GFP_ATOMIC',
152
+ 'spin_lock', 'spin_unlock', 'spin_lock_irqsave', 'spin_unlock_irqrestore',
153
+ 'mutex_lock', 'mutex_unlock', 'mutex_init',
154
+ 'kfree', 'kmalloc', 'kzalloc', 'kcalloc', 'krealloc', 'kvmalloc', 'kvfree',
155
+ 'get', 'put',
156
+ // C# / .NET built-ins
157
+ 'Console', 'WriteLine', 'ReadLine', 'Write',
158
+ 'Task', 'Run', 'Wait', 'WhenAll', 'WhenAny', 'FromResult', 'Delay', 'ContinueWith',
159
+ 'ConfigureAwait', 'GetAwaiter', 'GetResult',
160
+ 'ToString', 'GetType', 'Equals', 'GetHashCode', 'ReferenceEquals',
161
+ 'Add', 'Remove', 'Contains', 'Clear', 'Count', 'Any', 'All',
162
+ 'Where', 'Select', 'SelectMany', 'OrderBy', 'OrderByDescending', 'GroupBy',
163
+ 'First', 'FirstOrDefault', 'Single', 'SingleOrDefault', 'Last', 'LastOrDefault',
164
+ 'ToList', 'ToArray', 'ToDictionary', 'AsEnumerable', 'AsQueryable',
165
+ 'Aggregate', 'Sum', 'Average', 'Min', 'Max', 'Distinct', 'Skip', 'Take',
166
+ 'String', 'Format', 'IsNullOrEmpty', 'IsNullOrWhiteSpace', 'Concat', 'Join',
167
+ 'Trim', 'TrimStart', 'TrimEnd', 'Split', 'Replace', 'StartsWith', 'EndsWith',
168
+ 'Convert', 'ToInt32', 'ToDouble', 'ToBoolean', 'ToByte',
169
+ 'Math', 'Abs', 'Ceiling', 'Floor', 'Round', 'Pow', 'Sqrt',
170
+ 'Dispose', 'Close',
171
+ 'TryParse', 'Parse',
172
+ 'AddRange', 'RemoveAt', 'RemoveAll', 'FindAll', 'Exists', 'TrueForAll',
173
+ 'ContainsKey', 'TryGetValue', 'AddOrUpdate',
174
+ 'Throw', 'ThrowIfNull',
175
+ // PHP built-ins
176
+ 'echo', 'isset', 'empty', 'unset', 'list', 'array', 'compact', 'extract',
177
+ 'count', 'strlen', 'strpos', 'strrpos', 'substr', 'strtolower', 'strtoupper', 'trim',
178
+ 'ltrim', 'rtrim', 'str_replace', 'str_contains', 'str_starts_with', 'str_ends_with',
179
+ 'sprintf', 'vsprintf', 'printf', 'number_format',
180
+ 'array_map', 'array_filter', 'array_reduce', 'array_push', 'array_pop', 'array_shift',
181
+ 'array_unshift', 'array_slice', 'array_splice', 'array_merge', 'array_keys', 'array_values',
182
+ 'array_key_exists', 'in_array', 'array_search', 'array_unique', 'usort', 'rsort',
183
+ 'json_encode', 'json_decode', 'serialize', 'unserialize',
184
+ 'intval', 'floatval', 'strval', 'boolval', 'is_null', 'is_string', 'is_int', 'is_array',
185
+ 'is_object', 'is_numeric', 'is_bool', 'is_float',
186
+ 'var_dump', 'print_r', 'var_export',
187
+ 'date', 'time', 'strtotime', 'mktime', 'microtime',
188
+ 'file_exists', 'file_get_contents', 'file_put_contents', 'is_file', 'is_dir',
189
+ 'preg_match', 'preg_match_all', 'preg_replace', 'preg_split',
190
+ 'header', 'session_start', 'session_destroy', 'ob_start', 'ob_end_clean', 'ob_get_clean',
191
+ 'dd', 'dump',
192
+ // Swift/iOS built-ins and standard library
193
+ 'print', 'debugPrint', 'dump', 'fatalError', 'precondition', 'preconditionFailure',
194
+ 'assert', 'assertionFailure', 'NSLog',
195
+ 'abs', 'min', 'max', 'zip', 'stride', 'sequence', 'repeatElement',
196
+ 'swap', 'withUnsafePointer', 'withUnsafeMutablePointer', 'withUnsafeBytes',
197
+ 'autoreleasepool', 'unsafeBitCast', 'unsafeDowncast', 'numericCast',
198
+ 'type', 'MemoryLayout',
199
+ // Swift collection/string methods (common noise)
200
+ 'map', 'flatMap', 'compactMap', 'filter', 'reduce', 'forEach', 'contains',
201
+ 'first', 'last', 'prefix', 'suffix', 'dropFirst', 'dropLast',
202
+ 'sorted', 'reversed', 'enumerated', 'joined', 'split',
203
+ 'append', 'insert', 'remove', 'removeAll', 'removeFirst', 'removeLast',
204
+ 'isEmpty', 'count', 'index', 'startIndex', 'endIndex',
205
+ // UIKit/Foundation common methods (noise in call graph)
206
+ 'addSubview', 'removeFromSuperview', 'layoutSubviews', 'setNeedsLayout',
207
+ 'layoutIfNeeded', 'setNeedsDisplay', 'invalidateIntrinsicContentSize',
208
+ 'addTarget', 'removeTarget', 'addGestureRecognizer',
209
+ 'addConstraint', 'addConstraints', 'removeConstraint', 'removeConstraints',
210
+ 'NSLocalizedString', 'Bundle',
211
+ 'reloadData', 'reloadSections', 'reloadRows', 'performBatchUpdates',
212
+ 'register', 'dequeueReusableCell', 'dequeueReusableSupplementaryView',
213
+ 'beginUpdates', 'endUpdates', 'insertRows', 'deleteRows', 'insertSections', 'deleteSections',
214
+ 'present', 'dismiss', 'pushViewController', 'popViewController', 'popToRootViewController',
215
+ 'performSegue', 'prepare',
216
+ // GCD / async
217
+ 'DispatchQueue', 'async', 'sync', 'asyncAfter',
218
+ 'Task', 'withCheckedContinuation', 'withCheckedThrowingContinuation',
219
+ // Combine
220
+ 'sink', 'store', 'assign', 'receive', 'subscribe',
221
+ // Notification / KVO
222
+ 'addObserver', 'removeObserver', 'post', 'NotificationCenter',
223
+ // Rust standard library (common noise in call graphs)
224
+ 'unwrap', 'expect', 'unwrap_or', 'unwrap_or_else', 'unwrap_or_default',
225
+ 'ok', 'err', 'is_ok', 'is_err', 'map', 'map_err', 'and_then', 'or_else',
226
+ 'clone', 'to_string', 'to_owned', 'into', 'from', 'as_ref', 'as_mut',
227
+ 'iter', 'into_iter', 'collect', 'map', 'filter', 'fold', 'for_each',
228
+ 'len', 'is_empty', 'push', 'pop', 'insert', 'remove', 'contains',
229
+ 'format', 'write', 'writeln', 'panic', 'unreachable', 'todo', 'unimplemented',
230
+ 'vec', 'println', 'eprintln', 'dbg',
231
+ 'lock', 'read', 'write', 'try_lock',
232
+ 'spawn', 'join', 'sleep',
233
+ 'Some', 'None', 'Ok', 'Err',
234
+ // Ruby built-ins and Kernel methods
235
+ 'puts', 'p', 'pp', 'raise', 'fail',
236
+ 'require', 'require_relative', 'load', 'autoload',
237
+ 'include', 'extend', 'prepend',
238
+ 'attr_accessor', 'attr_reader', 'attr_writer',
239
+ 'public', 'private', 'protected', 'module_function',
240
+ 'lambda', 'proc', 'block_given?',
241
+ 'nil?', 'is_a?', 'kind_of?', 'instance_of?', 'respond_to?',
242
+ 'freeze', 'frozen?', 'dup', 'tap', 'yield_self',
243
+ // Ruby enumerables
244
+ 'each', 'select', 'reject', 'detect', 'collect',
245
+ 'inject', 'flat_map', 'each_with_object', 'each_with_index',
246
+ 'any?', 'all?', 'none?', 'count', 'first', 'last',
247
+ 'sort_by', 'min_by', 'max_by',
248
+ 'group_by', 'partition', 'compact', 'flatten', 'uniq',
249
+ ]);
250
+ /** Check if a name is a built-in function or common noise that should be filtered out */
251
+ export const isBuiltInOrNoise = (name) => BUILT_IN_NAMES.has(name);
252
+ /** AST node types that represent a class-like container (for HAS_METHOD edge extraction) */
253
+ export const CLASS_CONTAINER_TYPES = new Set([
254
+ 'class_declaration', 'abstract_class_declaration',
255
+ 'interface_declaration', 'struct_declaration', 'record_declaration',
256
+ 'class_specifier', 'struct_specifier',
257
+ 'impl_item', 'trait_item',
258
+ 'class_definition',
259
+ 'trait_declaration',
260
+ 'protocol_declaration',
261
+ // Ruby
262
+ 'class',
263
+ 'module',
264
+ // Kotlin
265
+ 'object_declaration',
266
+ 'companion_object',
267
+ ]);
268
+ export const CONTAINER_TYPE_TO_LABEL = {
269
+ class_declaration: 'Class',
270
+ abstract_class_declaration: 'Class',
271
+ interface_declaration: 'Interface',
272
+ struct_declaration: 'Struct',
273
+ struct_specifier: 'Struct',
274
+ class_specifier: 'Class',
275
+ class_definition: 'Class',
276
+ impl_item: 'Impl',
277
+ trait_item: 'Trait',
278
+ trait_declaration: 'Trait',
279
+ record_declaration: 'Record',
280
+ protocol_declaration: 'Interface',
281
+ class: 'Class',
282
+ module: 'Module',
283
+ object_declaration: 'Class',
284
+ companion_object: 'Class',
285
+ };
286
+ /** Walk up AST to find enclosing class/struct/interface/impl, return its generateId or null.
287
+ * For Go method_declaration nodes, extracts receiver type (e.g. `func (u *User) Save()` → User struct). */
288
+ export const findEnclosingClassId = (node, filePath) => {
289
+ let current = node.parent;
290
+ while (current) {
291
+ // Go: method_declaration has a receiver parameter with the struct type
292
+ if (current.type === 'method_declaration') {
293
+ const receiver = current.childForFieldName?.('receiver');
294
+ if (receiver) {
295
+ // receiver is a parameter_list: (u *User) or (u User)
296
+ const paramDecl = receiver.namedChildren?.find?.((c) => c.type === 'parameter_declaration');
297
+ if (paramDecl) {
298
+ const typeNode = paramDecl.childForFieldName?.('type');
299
+ if (typeNode) {
300
+ // Unwrap pointer_type (*User → User)
301
+ const inner = typeNode.type === 'pointer_type' ? typeNode.firstNamedChild : typeNode;
302
+ if (inner && (inner.type === 'type_identifier' || inner.type === 'identifier')) {
303
+ return generateId('Struct', `${filePath}:${inner.text}`);
304
+ }
305
+ }
306
+ }
307
+ }
308
+ }
309
+ if (CLASS_CONTAINER_TYPES.has(current.type)) {
310
+ // Rust impl_item: for `impl Trait for Struct {}`, pick the type after `for`
311
+ if (current.type === 'impl_item') {
312
+ const children = current.children ?? [];
313
+ const forIdx = children.findIndex((c) => c.text === 'for');
314
+ if (forIdx !== -1) {
315
+ const nameNode = children.slice(forIdx + 1).find((c) => c.type === 'type_identifier' || c.type === 'identifier');
316
+ if (nameNode) {
317
+ return generateId('Impl', `${filePath}:${nameNode.text}`);
318
+ }
319
+ }
320
+ // Fall through: plain `impl Struct {}` — use first type_identifier below
321
+ }
322
+ const nameNode = current.childForFieldName?.('name')
323
+ ?? current.children?.find((c) => c.type === 'type_identifier' || c.type === 'identifier' || c.type === 'name' || c.type === 'constant');
324
+ if (nameNode) {
325
+ const label = CONTAINER_TYPE_TO_LABEL[current.type] || 'Class';
326
+ return generateId(label, `${filePath}:${nameNode.text}`);
327
+ }
328
+ }
329
+ current = current.parent;
330
+ }
331
+ return null;
332
+ };
333
+ /**
334
+ * Extract function name and label from a function_definition or similar AST node.
335
+ * Handles C/C++ qualified_identifier (ClassName::MethodName) and other language patterns.
336
+ */
337
+ export const extractFunctionName = (node) => {
338
+ let funcName = null;
339
+ let label = 'Function';
340
+ // Swift init/deinit
341
+ if (node.type === 'init_declaration' || node.type === 'deinit_declaration') {
342
+ return {
343
+ funcName: node.type === 'init_declaration' ? 'init' : 'deinit',
344
+ label: 'Constructor',
345
+ };
346
+ }
347
+ if (FUNCTION_DECLARATION_TYPES.has(node.type)) {
348
+ // C/C++: function_definition -> [pointer_declarator ->] function_declarator -> qualified_identifier/identifier
349
+ // Unwrap pointer_declarator / reference_declarator wrappers to reach function_declarator
350
+ let declarator = node.childForFieldName?.('declarator');
351
+ if (!declarator) {
352
+ for (let i = 0; i < node.childCount; i++) {
353
+ const c = node.child(i);
354
+ if (c?.type === 'function_declarator') {
355
+ declarator = c;
356
+ break;
357
+ }
358
+ }
359
+ }
360
+ while (declarator && (declarator.type === 'pointer_declarator' || declarator.type === 'reference_declarator')) {
361
+ let nextDeclarator = declarator.childForFieldName?.('declarator');
362
+ if (!nextDeclarator) {
363
+ for (let i = 0; i < declarator.childCount; i++) {
364
+ const c = declarator.child(i);
365
+ if (c?.type === 'function_declarator' || c?.type === 'pointer_declarator' || c?.type === 'reference_declarator') {
366
+ nextDeclarator = c;
367
+ break;
368
+ }
369
+ }
370
+ }
371
+ declarator = nextDeclarator;
372
+ }
373
+ if (declarator) {
374
+ let innerDeclarator = declarator.childForFieldName?.('declarator');
375
+ if (!innerDeclarator) {
376
+ for (let i = 0; i < declarator.childCount; i++) {
377
+ const c = declarator.child(i);
378
+ if (c?.type === 'qualified_identifier' || c?.type === 'identifier' || c?.type === 'parenthesized_declarator') {
379
+ innerDeclarator = c;
380
+ break;
381
+ }
382
+ }
383
+ }
384
+ if (innerDeclarator?.type === 'qualified_identifier') {
385
+ let nameNode = innerDeclarator.childForFieldName?.('name');
386
+ if (!nameNode) {
387
+ for (let i = 0; i < innerDeclarator.childCount; i++) {
388
+ const c = innerDeclarator.child(i);
389
+ if (c?.type === 'identifier') {
390
+ nameNode = c;
391
+ break;
392
+ }
393
+ }
394
+ }
395
+ if (nameNode?.text) {
396
+ funcName = nameNode.text;
397
+ label = 'Method';
398
+ }
399
+ }
400
+ else if (innerDeclarator?.type === 'identifier') {
401
+ funcName = innerDeclarator.text;
402
+ }
403
+ else if (innerDeclarator?.type === 'parenthesized_declarator') {
404
+ let nestedId = null;
405
+ for (let i = 0; i < innerDeclarator.childCount; i++) {
406
+ const c = innerDeclarator.child(i);
407
+ if (c?.type === 'qualified_identifier' || c?.type === 'identifier') {
408
+ nestedId = c;
409
+ break;
410
+ }
411
+ }
412
+ if (nestedId?.type === 'qualified_identifier') {
413
+ let nameNode = nestedId.childForFieldName?.('name');
414
+ if (!nameNode) {
415
+ for (let i = 0; i < nestedId.childCount; i++) {
416
+ const c = nestedId.child(i);
417
+ if (c?.type === 'identifier') {
418
+ nameNode = c;
419
+ break;
420
+ }
421
+ }
422
+ }
423
+ if (nameNode?.text) {
424
+ funcName = nameNode.text;
425
+ label = 'Method';
426
+ }
427
+ }
428
+ else if (nestedId?.type === 'identifier') {
429
+ funcName = nestedId.text;
430
+ }
431
+ }
432
+ }
433
+ // Fallback for other languages (Kotlin uses simple_identifier, Swift uses simple_identifier)
434
+ if (!funcName) {
435
+ let nameNode = node.childForFieldName?.('name');
436
+ if (!nameNode) {
437
+ for (let i = 0; i < node.childCount; i++) {
438
+ const c = node.child(i);
439
+ if (c?.type === 'identifier' || c?.type === 'property_identifier' || c?.type === 'simple_identifier') {
440
+ nameNode = c;
441
+ break;
442
+ }
443
+ }
444
+ }
445
+ funcName = nameNode?.text;
446
+ }
447
+ }
448
+ else if (node.type === 'impl_item') {
449
+ let funcItem = null;
450
+ for (let i = 0; i < node.childCount; i++) {
451
+ const c = node.child(i);
452
+ if (c?.type === 'function_item') {
453
+ funcItem = c;
454
+ break;
455
+ }
456
+ }
457
+ if (funcItem) {
458
+ let nameNode = funcItem.childForFieldName?.('name');
459
+ if (!nameNode) {
460
+ for (let i = 0; i < funcItem.childCount; i++) {
461
+ const c = funcItem.child(i);
462
+ if (c?.type === 'identifier') {
463
+ nameNode = c;
464
+ break;
465
+ }
466
+ }
467
+ }
468
+ funcName = nameNode?.text;
469
+ label = 'Method';
470
+ }
471
+ }
472
+ else if (node.type === 'method_definition') {
473
+ let nameNode = node.childForFieldName?.('name');
474
+ if (!nameNode) {
475
+ for (let i = 0; i < node.childCount; i++) {
476
+ const c = node.child(i);
477
+ if (c?.type === 'property_identifier') {
478
+ nameNode = c;
479
+ break;
480
+ }
481
+ }
482
+ }
483
+ funcName = nameNode?.text;
484
+ label = 'Method';
485
+ }
486
+ else if (node.type === 'method_declaration' || node.type === 'constructor_declaration') {
487
+ let nameNode = node.childForFieldName?.('name');
488
+ if (!nameNode) {
489
+ for (let i = 0; i < node.childCount; i++) {
490
+ const c = node.child(i);
491
+ if (c?.type === 'identifier') {
492
+ nameNode = c;
493
+ break;
494
+ }
495
+ }
496
+ }
497
+ funcName = nameNode?.text;
498
+ label = 'Method';
499
+ }
500
+ else if (node.type === 'arrow_function' || node.type === 'function_expression') {
501
+ const parent = node.parent;
502
+ if (parent?.type === 'variable_declarator') {
503
+ let nameNode = parent.childForFieldName?.('name');
504
+ if (!nameNode) {
505
+ for (let i = 0; i < parent.childCount; i++) {
506
+ const c = parent.child(i);
507
+ if (c?.type === 'identifier') {
508
+ nameNode = c;
509
+ break;
510
+ }
511
+ }
512
+ }
513
+ funcName = nameNode?.text;
514
+ }
515
+ }
516
+ else if (node.type === 'method' || node.type === 'singleton_method') {
517
+ let nameNode = node.childForFieldName?.('name');
518
+ if (!nameNode) {
519
+ for (let i = 0; i < node.childCount; i++) {
520
+ const c = node.child(i);
521
+ if (c?.type === 'identifier') {
522
+ nameNode = c;
523
+ break;
524
+ }
525
+ }
526
+ }
527
+ funcName = nameNode?.text;
528
+ label = 'Method';
529
+ }
530
+ return { funcName, label };
531
+ };
2
532
  /**
3
533
  * Yield control to the event loop so spinners/progress can render.
4
534
  * Call periodically in hot loops to prevent UI freezes.
5
535
  */
6
536
  export const yieldToEventLoop = () => new Promise(resolve => setImmediate(resolve));
537
+ /** Ruby extensionless filenames recognised as Ruby source */
538
+ const RUBY_EXTENSIONLESS_FILES = new Set(['Rakefile', 'Gemfile', 'Guardfile', 'Vagrantfile', 'Brewfile']);
539
+ /**
540
+ * Find a child of `childType` within a sibling node of `siblingType`.
541
+ * Used for Kotlin AST traversal where visibility_modifier lives inside a modifiers sibling.
542
+ */
543
+ export const findSiblingChild = (parent, siblingType, childType) => {
544
+ for (let i = 0; i < parent.childCount; i++) {
545
+ const sibling = parent.child(i);
546
+ if (sibling?.type === siblingType) {
547
+ for (let j = 0; j < sibling.childCount; j++) {
548
+ const child = sibling.child(j);
549
+ if (child?.type === childType)
550
+ return child;
551
+ }
552
+ }
553
+ }
554
+ return null;
555
+ };
7
556
  /**
8
557
  * Map file extension to SupportedLanguage enum
9
558
  */
@@ -24,12 +573,14 @@ export const getLanguageFromFilename = (filename) => {
24
573
  // Java
25
574
  if (filename.endsWith('.java'))
26
575
  return SupportedLanguages.Java;
27
- // C (source and headers)
28
- if (filename.endsWith('.c') || filename.endsWith('.h'))
576
+ // C source files
577
+ if (filename.endsWith('.c'))
29
578
  return SupportedLanguages.C;
30
- // C++ (all common extensions)
579
+ // C++ (all common extensions, including .h)
580
+ // .h is parsed as C++ because tree-sitter-cpp is a strict superset of C, so pure-C
581
+ // headers parse correctly, and C++ headers (classes, templates) are handled properly.
31
582
  if (filename.endsWith('.cpp') || filename.endsWith('.cc') || filename.endsWith('.cxx') ||
32
- filename.endsWith('.hpp') || filename.endsWith('.hxx') || filename.endsWith('.hh'))
583
+ filename.endsWith('.h') || filename.endsWith('.hpp') || filename.endsWith('.hxx') || filename.endsWith('.hh'))
33
584
  return SupportedLanguages.CPlusPlus;
34
585
  // C#
35
586
  if (filename.endsWith('.cs'))
@@ -40,11 +591,541 @@ export const getLanguageFromFilename = (filename) => {
40
591
  // Rust
41
592
  if (filename.endsWith('.rs'))
42
593
  return SupportedLanguages.Rust;
594
+ // Kotlin
595
+ if (filename.endsWith('.kt') || filename.endsWith('.kts'))
596
+ return SupportedLanguages.Kotlin;
43
597
  // PHP (all common extensions)
44
598
  if (filename.endsWith('.php') || filename.endsWith('.phtml') ||
45
599
  filename.endsWith('.php3') || filename.endsWith('.php4') ||
46
600
  filename.endsWith('.php5') || filename.endsWith('.php8')) {
47
601
  return SupportedLanguages.PHP;
48
602
  }
603
+ // Ruby (extensions)
604
+ if (filename.endsWith('.rb') || filename.endsWith('.rake') || filename.endsWith('.gemspec')) {
605
+ return SupportedLanguages.Ruby;
606
+ }
607
+ // Ruby (extensionless files)
608
+ const basename = filename.split('/').pop() || filename;
609
+ if (RUBY_EXTENSIONLESS_FILES.has(basename)) {
610
+ return SupportedLanguages.Ruby;
611
+ }
612
+ // Swift (extensions)
613
+ if (filename.endsWith('.swift'))
614
+ return SupportedLanguages.Swift;
49
615
  return null;
50
616
  };
617
+ const CALL_ARGUMENT_LIST_TYPES = new Set([
618
+ 'arguments',
619
+ 'argument_list',
620
+ 'value_arguments',
621
+ ]);
622
+ /**
623
+ * Extract parameter count and return type text from an AST method/function node.
624
+ * Works across languages by looking for common AST patterns.
625
+ */
626
+ export const extractMethodSignature = (node) => {
627
+ let parameterCount = 0;
628
+ let returnType;
629
+ let isVariadic = false;
630
+ if (!node)
631
+ return { parameterCount, returnType };
632
+ const paramListTypes = new Set([
633
+ 'formal_parameters', 'parameters', 'parameter_list',
634
+ 'function_parameters', 'method_parameters', 'function_value_parameters',
635
+ ]);
636
+ // Node types that indicate variadic/rest parameters
637
+ const VARIADIC_PARAM_TYPES = new Set([
638
+ 'variadic_parameter_declaration', // Go: ...string
639
+ 'variadic_parameter', // Rust: extern "C" fn(...)
640
+ 'spread_parameter', // Java: Object... args
641
+ 'list_splat_pattern', // Python: *args
642
+ 'dictionary_splat_pattern', // Python: **kwargs
643
+ ]);
644
+ const findParameterList = (current) => {
645
+ for (const child of current.children) {
646
+ if (paramListTypes.has(child.type))
647
+ return child;
648
+ }
649
+ for (const child of current.children) {
650
+ const nested = findParameterList(child);
651
+ if (nested)
652
+ return nested;
653
+ }
654
+ return null;
655
+ };
656
+ const parameterList = (paramListTypes.has(node.type) ? node // node itself IS the parameter list (e.g. C# primary constructors)
657
+ : node.childForFieldName?.('parameters')
658
+ ?? findParameterList(node));
659
+ if (parameterList && paramListTypes.has(parameterList.type)) {
660
+ for (const param of parameterList.namedChildren) {
661
+ if (param.type === 'comment')
662
+ continue;
663
+ if (param.text === 'self' || param.text === '&self' || param.text === '&mut self' ||
664
+ param.type === 'self_parameter') {
665
+ continue;
666
+ }
667
+ // Check for variadic parameter types
668
+ if (VARIADIC_PARAM_TYPES.has(param.type)) {
669
+ isVariadic = true;
670
+ continue;
671
+ }
672
+ // TypeScript/JavaScript: rest parameter — required_parameter containing rest_pattern
673
+ if (param.type === 'required_parameter' || param.type === 'optional_parameter') {
674
+ for (const child of param.children) {
675
+ if (child.type === 'rest_pattern') {
676
+ isVariadic = true;
677
+ break;
678
+ }
679
+ }
680
+ if (isVariadic)
681
+ continue;
682
+ }
683
+ // Kotlin: vararg modifier on a regular parameter
684
+ if (param.type === 'parameter' || param.type === 'formal_parameter') {
685
+ const prev = param.previousSibling;
686
+ if (prev?.type === 'parameter_modifiers' && prev.text.includes('vararg')) {
687
+ isVariadic = true;
688
+ }
689
+ }
690
+ parameterCount++;
691
+ }
692
+ // C/C++: bare `...` token in parameter list (not a named child — check all children)
693
+ if (!isVariadic) {
694
+ for (const child of parameterList.children) {
695
+ if (!child.isNamed && child.text === '...') {
696
+ isVariadic = true;
697
+ break;
698
+ }
699
+ }
700
+ }
701
+ }
702
+ // Return type extraction — language-specific field names
703
+ // Go: 'result' field is either a type_identifier or parameter_list (multi-return)
704
+ const goResult = node.childForFieldName?.('result');
705
+ if (goResult) {
706
+ if (goResult.type === 'parameter_list') {
707
+ // Multi-return: extract first parameter's type only (e.g. (*User, error) → *User)
708
+ const firstParam = goResult.firstNamedChild;
709
+ if (firstParam?.type === 'parameter_declaration') {
710
+ const typeNode = firstParam.childForFieldName('type');
711
+ if (typeNode)
712
+ returnType = typeNode.text;
713
+ }
714
+ else if (firstParam) {
715
+ // Unnamed return types: (string, error) — first child is a bare type node
716
+ returnType = firstParam.text;
717
+ }
718
+ }
719
+ else {
720
+ returnType = goResult.text;
721
+ }
722
+ }
723
+ // Rust: 'return_type' field — the value IS the type node (e.g. primitive_type, type_identifier).
724
+ // Skip if the node is a type_annotation (TS/Python), which is handled by the generic loop below.
725
+ if (!returnType) {
726
+ const rustReturn = node.childForFieldName?.('return_type');
727
+ if (rustReturn && rustReturn.type !== 'type_annotation') {
728
+ returnType = rustReturn.text;
729
+ }
730
+ }
731
+ // C/C++: 'type' field on function_definition
732
+ if (!returnType) {
733
+ const cppType = node.childForFieldName?.('type');
734
+ if (cppType && cppType.text !== 'void') {
735
+ returnType = cppType.text;
736
+ }
737
+ }
738
+ // C#: 'returns' field on method_declaration
739
+ if (!returnType) {
740
+ const csReturn = node.childForFieldName?.('returns');
741
+ if (csReturn && csReturn.text !== 'void') {
742
+ returnType = csReturn.text;
743
+ }
744
+ }
745
+ // TS/Rust/Python/C#/Kotlin: type_annotation or return_type child
746
+ if (!returnType) {
747
+ for (const child of node.children) {
748
+ if (child.type === 'type_annotation' || child.type === 'return_type') {
749
+ const typeNode = child.children.find((c) => c.isNamed);
750
+ if (typeNode)
751
+ returnType = typeNode.text;
752
+ }
753
+ }
754
+ }
755
+ // Kotlin: fun getUser(): User — return type is a bare user_type child of
756
+ // function_declaration. The Kotlin grammar does NOT wrap it in type_annotation
757
+ // or return_type; it appears as a direct child after function_value_parameters.
758
+ // Note: Kotlin uses function_value_parameters (not a field), so we find it by type.
759
+ if (!returnType) {
760
+ let paramsEnd = -1;
761
+ for (let i = 0; i < node.childCount; i++) {
762
+ const child = node.child(i);
763
+ if (!child)
764
+ continue;
765
+ if (child.type === 'function_value_parameters' || child.type === 'value_parameters') {
766
+ paramsEnd = child.endIndex;
767
+ }
768
+ if (paramsEnd >= 0 && child.type === 'user_type' && child.startIndex > paramsEnd) {
769
+ returnType = child.text;
770
+ break;
771
+ }
772
+ }
773
+ }
774
+ if (isVariadic)
775
+ parameterCount = undefined;
776
+ return { parameterCount, returnType };
777
+ };
778
+ /**
779
+ * Count direct arguments for a call expression across common tree-sitter grammars.
780
+ * Returns undefined when the argument container cannot be located cheaply.
781
+ */
782
+ export const countCallArguments = (callNode) => {
783
+ if (!callNode)
784
+ return undefined;
785
+ // Direct field or direct child (most languages)
786
+ let argsNode = callNode.childForFieldName('arguments')
787
+ ?? callNode.children.find((child) => CALL_ARGUMENT_LIST_TYPES.has(child.type));
788
+ // Kotlin/Swift: call_expression → call_suffix → value_arguments
789
+ // Search one level deeper for languages that wrap arguments in a suffix node
790
+ if (!argsNode) {
791
+ for (const child of callNode.children) {
792
+ if (!child.isNamed)
793
+ continue;
794
+ const nested = child.children.find((gc) => CALL_ARGUMENT_LIST_TYPES.has(gc.type));
795
+ if (nested) {
796
+ argsNode = nested;
797
+ break;
798
+ }
799
+ }
800
+ }
801
+ if (!argsNode)
802
+ return undefined;
803
+ let count = 0;
804
+ for (const child of argsNode.children) {
805
+ if (!child.isNamed)
806
+ continue;
807
+ if (child.type === 'comment')
808
+ continue;
809
+ count++;
810
+ }
811
+ return count;
812
+ };
813
+ // ── Call-form discrimination (Phase 1, Step D) ─────────────────────────
814
+ /**
815
+ * AST node types that indicate a member-access wrapper around the callee name.
816
+ * When nameNode.parent.type is one of these, the call is a member call.
817
+ */
818
+ const MEMBER_ACCESS_NODE_TYPES = new Set([
819
+ 'member_expression', // TS/JS: obj.method()
820
+ 'attribute', // Python: obj.method()
821
+ 'member_access_expression', // C#: obj.Method()
822
+ 'field_expression', // Rust/C++: obj.method() / ptr->method()
823
+ 'selector_expression', // Go: obj.Method()
824
+ 'navigation_suffix', // Kotlin/Swift: obj.method() — nameNode sits inside navigation_suffix
825
+ 'member_binding_expression', // C#: user?.Method() — null-conditional access
826
+ ]);
827
+ /**
828
+ * Call node types that are inherently constructor invocations.
829
+ * Only includes patterns that the tree-sitter queries already capture as @call.
830
+ */
831
+ const CONSTRUCTOR_CALL_NODE_TYPES = new Set([
832
+ 'constructor_invocation', // Kotlin: Foo()
833
+ 'new_expression', // TS/JS/C++: new Foo()
834
+ 'object_creation_expression', // Java/C#/PHP: new Foo()
835
+ 'implicit_object_creation_expression', // C# 9: User u = new(...)
836
+ 'composite_literal', // Go: User{...}
837
+ 'struct_expression', // Rust: User { ... }
838
+ ]);
839
+ /**
840
+ * AST node types for scoped/qualified calls (e.g., Foo::new() in Rust, Foo::bar() in C++).
841
+ */
842
+ const SCOPED_CALL_NODE_TYPES = new Set([
843
+ 'scoped_identifier', // Rust: Foo::new()
844
+ 'qualified_identifier', // C++: ns::func()
845
+ ]);
846
+ /**
847
+ * Infer whether a captured call site is a free call, member call, or constructor.
848
+ * Returns undefined if the form cannot be determined.
849
+ *
850
+ * Works by inspecting the AST structure between callNode (@call) and nameNode (@call.name).
851
+ * No tree-sitter query changes needed — the distinction is in the node types.
852
+ */
853
+ export const inferCallForm = (callNode, nameNode) => {
854
+ // 1. Constructor: callNode itself is a constructor invocation (Kotlin)
855
+ if (CONSTRUCTOR_CALL_NODE_TYPES.has(callNode.type)) {
856
+ return 'constructor';
857
+ }
858
+ // 2. Member call: nameNode's parent is a member-access wrapper
859
+ const nameParent = nameNode.parent;
860
+ if (nameParent && MEMBER_ACCESS_NODE_TYPES.has(nameParent.type)) {
861
+ return 'member';
862
+ }
863
+ // 3. PHP: the callNode itself distinguishes member vs free calls
864
+ if (callNode.type === 'member_call_expression' || callNode.type === 'nullsafe_member_call_expression') {
865
+ return 'member';
866
+ }
867
+ if (callNode.type === 'scoped_call_expression') {
868
+ return 'member'; // static call Foo::bar()
869
+ }
870
+ // 4. Java method_invocation: member if it has an 'object' field
871
+ if (callNode.type === 'method_invocation' && callNode.childForFieldName('object')) {
872
+ return 'member';
873
+ }
874
+ // 4b. Ruby call with receiver: obj.method
875
+ if (callNode.type === 'call' && callNode.childForFieldName('receiver')) {
876
+ return 'member';
877
+ }
878
+ // 5. Scoped calls (Rust Foo::new(), C++ ns::func()): treat as free
879
+ // The receiver is a type, not an instance — handled differently in Phase 3
880
+ if (nameParent && SCOPED_CALL_NODE_TYPES.has(nameParent.type)) {
881
+ return 'free';
882
+ }
883
+ // 6. Default: if nameNode is a direct child of callNode, it's a free call
884
+ if (nameNode.parent === callNode || nameParent?.parent === callNode) {
885
+ return 'free';
886
+ }
887
+ return undefined;
888
+ };
889
+ /**
890
+ * Extract the receiver identifier for member calls.
891
+ * Only captures simple identifiers — returns undefined for complex expressions
892
+ * like getUser().save() or arr[0].method().
893
+ */
894
+ const SIMPLE_RECEIVER_TYPES = new Set([
895
+ 'identifier',
896
+ 'simple_identifier',
897
+ 'variable_name', // PHP $variable (tree-sitter-php)
898
+ 'name', // PHP name node
899
+ 'this', // TS/JS/Java/C# this.method()
900
+ 'self', // Rust/Python self.method()
901
+ 'super', // TS/JS/Java/Kotlin/Ruby super.method()
902
+ 'super_expression', // Kotlin wraps super in super_expression
903
+ 'base', // C# base.Method()
904
+ 'parent', // PHP parent::method()
905
+ 'constant', // Ruby CONSTANT.method() (uppercase identifiers)
906
+ ]);
907
+ export const extractReceiverName = (nameNode) => {
908
+ const parent = nameNode.parent;
909
+ if (!parent)
910
+ return undefined;
911
+ // PHP: member_call_expression / nullsafe_member_call_expression — receiver is on the callNode
912
+ // Java: method_invocation — receiver is the 'object' field on callNode
913
+ // For these, parent of nameNode is the call itself, so check the call's object field
914
+ const callNode = parent.parent ?? parent;
915
+ let receiver = null;
916
+ // Try standard field names used across grammars
917
+ receiver = parent.childForFieldName('object') // TS/JS member_expression, Python attribute, PHP, Java
918
+ ?? parent.childForFieldName('value') // Rust field_expression
919
+ ?? parent.childForFieldName('operand') // Go selector_expression
920
+ ?? parent.childForFieldName('expression') // C# member_access_expression
921
+ ?? parent.childForFieldName('argument'); // C++ field_expression
922
+ // Java method_invocation: 'object' field is on the callNode, not on nameNode's parent
923
+ if (!receiver && callNode.type === 'method_invocation') {
924
+ receiver = callNode.childForFieldName('object');
925
+ }
926
+ // PHP: member_call_expression has 'object' on the call node
927
+ if (!receiver && (callNode.type === 'member_call_expression' || callNode.type === 'nullsafe_member_call_expression')) {
928
+ receiver = callNode.childForFieldName('object');
929
+ }
930
+ // Ruby: call node has 'receiver' field
931
+ if (!receiver && parent.type === 'call') {
932
+ receiver = parent.childForFieldName('receiver');
933
+ }
934
+ // PHP scoped_call_expression (parent::method(), self::method()):
935
+ // nameNode's direct parent IS the scoped_call_expression (name is a direct child)
936
+ if (!receiver && (parent.type === 'scoped_call_expression' || callNode.type === 'scoped_call_expression')) {
937
+ const scopedCall = parent.type === 'scoped_call_expression' ? parent : callNode;
938
+ receiver = scopedCall.childForFieldName('scope');
939
+ // relative_scope wraps 'parent'/'self'/'static' — unwrap to get the keyword
940
+ if (receiver?.type === 'relative_scope') {
941
+ receiver = receiver.firstChild;
942
+ }
943
+ }
944
+ // C# null-conditional: user?.Save() → conditional_access_expression wraps member_binding_expression
945
+ if (!receiver && parent.type === 'member_binding_expression') {
946
+ const condAccess = parent.parent;
947
+ if (condAccess?.type === 'conditional_access_expression') {
948
+ receiver = condAccess.firstNamedChild;
949
+ }
950
+ }
951
+ // Kotlin/Swift: navigation_expression target is the first child
952
+ if (!receiver && parent.type === 'navigation_suffix') {
953
+ const navExpr = parent.parent;
954
+ if (navExpr?.type === 'navigation_expression') {
955
+ // First named child is the target (receiver)
956
+ for (const child of navExpr.children) {
957
+ if (child.isNamed && child !== parent) {
958
+ receiver = child;
959
+ break;
960
+ }
961
+ }
962
+ }
963
+ }
964
+ if (!receiver)
965
+ return undefined;
966
+ // Only capture simple identifiers — refuse complex expressions
967
+ if (SIMPLE_RECEIVER_TYPES.has(receiver.type)) {
968
+ return receiver.text;
969
+ }
970
+ // Python super().method(): receiver is a call node `super()` — extract the function name
971
+ if (receiver.type === 'call') {
972
+ const func = receiver.childForFieldName('function');
973
+ if (func?.text === 'super')
974
+ return 'super';
975
+ }
976
+ return undefined;
977
+ };
978
+ /**
979
+ * Extract the raw receiver AST node for a member call.
980
+ * Unlike extractReceiverName, this returns the receiver node regardless of its type —
981
+ * including call_expression / method_invocation nodes that appear in chained calls
982
+ * like `svc.getUser().save()`.
983
+ *
984
+ * Returns undefined when the call is not a member call or when no receiver node
985
+ * can be found (e.g. top-level free calls).
986
+ */
987
+ export const extractReceiverNode = (nameNode) => {
988
+ const parent = nameNode.parent;
989
+ if (!parent)
990
+ return undefined;
991
+ const callNode = parent.parent ?? parent;
992
+ let receiver = null;
993
+ receiver = parent.childForFieldName('object')
994
+ ?? parent.childForFieldName('value')
995
+ ?? parent.childForFieldName('operand')
996
+ ?? parent.childForFieldName('expression')
997
+ ?? parent.childForFieldName('argument');
998
+ if (!receiver && callNode.type === 'method_invocation') {
999
+ receiver = callNode.childForFieldName('object');
1000
+ }
1001
+ if (!receiver && (callNode.type === 'member_call_expression' || callNode.type === 'nullsafe_member_call_expression')) {
1002
+ receiver = callNode.childForFieldName('object');
1003
+ }
1004
+ if (!receiver && parent.type === 'call') {
1005
+ receiver = parent.childForFieldName('receiver');
1006
+ }
1007
+ if (!receiver && (parent.type === 'scoped_call_expression' || callNode.type === 'scoped_call_expression')) {
1008
+ const scopedCall = parent.type === 'scoped_call_expression' ? parent : callNode;
1009
+ receiver = scopedCall.childForFieldName('scope');
1010
+ if (receiver?.type === 'relative_scope') {
1011
+ receiver = receiver.firstChild;
1012
+ }
1013
+ }
1014
+ if (!receiver && parent.type === 'member_binding_expression') {
1015
+ const condAccess = parent.parent;
1016
+ if (condAccess?.type === 'conditional_access_expression') {
1017
+ receiver = condAccess.firstNamedChild;
1018
+ }
1019
+ }
1020
+ if (!receiver && parent.type === 'navigation_suffix') {
1021
+ const navExpr = parent.parent;
1022
+ if (navExpr?.type === 'navigation_expression') {
1023
+ for (const child of navExpr.children) {
1024
+ if (child.isNamed && child !== parent) {
1025
+ receiver = child;
1026
+ break;
1027
+ }
1028
+ }
1029
+ }
1030
+ }
1031
+ return receiver ?? undefined;
1032
+ };
1033
+ export const isVerboseIngestionEnabled = () => {
1034
+ const raw = process.env.GITNEXUS_VERBOSE;
1035
+ if (!raw)
1036
+ return false;
1037
+ const value = raw.toLowerCase();
1038
+ return value === '1' || value === 'true' || value === 'yes';
1039
+ };
1040
+ // ── Chained-call extraction ───────────────────────────────────────────────
1041
+ /** Node types representing call expressions across supported languages. */
1042
+ export const CALL_EXPRESSION_TYPES = new Set([
1043
+ 'call_expression', // TS/JS/C/C++/Go/Rust
1044
+ 'method_invocation', // Java
1045
+ 'member_call_expression', // PHP
1046
+ 'nullsafe_member_call_expression', // PHP ?.
1047
+ 'call', // Python/Ruby
1048
+ 'invocation_expression', // C#
1049
+ ]);
1050
+ /**
1051
+ * Hard limit on chain depth to prevent runaway recursion.
1052
+ * For `a.b().c().d()`, the chain has depth 2 (b and c before d).
1053
+ */
1054
+ export const MAX_CHAIN_DEPTH = 3;
1055
+ /**
1056
+ * Walk a receiver AST node that is itself a call expression, accumulating the
1057
+ * chain of intermediate method names up to MAX_CHAIN_DEPTH.
1058
+ *
1059
+ * For `svc.getUser().save()`, called with the receiver of `save` (getUser() call):
1060
+ * returns { chain: ['getUser'], baseReceiverName: 'svc' }
1061
+ *
1062
+ * For `a.b().c().d()`, called with the receiver of `d` (c() call):
1063
+ * returns { chain: ['b', 'c'], baseReceiverName: 'a' }
1064
+ */
1065
+ export function extractCallChain(receiverCallNode) {
1066
+ const chain = [];
1067
+ let current = receiverCallNode;
1068
+ while (CALL_EXPRESSION_TYPES.has(current.type) && chain.length < MAX_CHAIN_DEPTH) {
1069
+ // Extract the method name from this call node.
1070
+ const funcNode = current.childForFieldName?.('function')
1071
+ ?? current.childForFieldName?.('name')
1072
+ ?? current.childForFieldName?.('method'); // Ruby `call` node
1073
+ let methodName;
1074
+ let innerReceiver = null;
1075
+ if (funcNode) {
1076
+ // member_expression / attribute: last named child is the method identifier
1077
+ methodName = funcNode.lastNamedChild?.text ?? funcNode.text;
1078
+ }
1079
+ // Kotlin/Swift: call_expression exposes callee as firstNamedChild, not a field.
1080
+ // navigation_expression: method name is in navigation_suffix → simple_identifier.
1081
+ if (!funcNode && current.type === 'call_expression') {
1082
+ const callee = current.firstNamedChild;
1083
+ if (callee?.type === 'navigation_expression') {
1084
+ const suffix = callee.lastNamedChild;
1085
+ if (suffix?.type === 'navigation_suffix') {
1086
+ methodName = suffix.lastNamedChild?.text;
1087
+ // The receiver is the part of navigation_expression before the suffix
1088
+ for (let i = 0; i < callee.namedChildCount; i++) {
1089
+ const child = callee.namedChild(i);
1090
+ if (child && child.type !== 'navigation_suffix') {
1091
+ innerReceiver = child;
1092
+ break;
1093
+ }
1094
+ }
1095
+ }
1096
+ }
1097
+ }
1098
+ if (!methodName)
1099
+ break;
1100
+ chain.unshift(methodName); // build chain outermost-last
1101
+ // Walk into the receiver of this call to continue the chain
1102
+ if (!innerReceiver && funcNode) {
1103
+ innerReceiver = funcNode.childForFieldName?.('object')
1104
+ ?? funcNode.childForFieldName?.('value')
1105
+ ?? funcNode.childForFieldName?.('operand')
1106
+ ?? funcNode.childForFieldName?.('expression');
1107
+ }
1108
+ // Java method_invocation: object field is on the call node
1109
+ if (!innerReceiver && current.type === 'method_invocation') {
1110
+ innerReceiver = current.childForFieldName?.('object');
1111
+ }
1112
+ // PHP member_call_expression
1113
+ if (!innerReceiver && (current.type === 'member_call_expression' || current.type === 'nullsafe_member_call_expression')) {
1114
+ innerReceiver = current.childForFieldName?.('object');
1115
+ }
1116
+ // Ruby `call` node: receiver field is on the call node itself
1117
+ if (!innerReceiver && current.type === 'call') {
1118
+ innerReceiver = current.childForFieldName?.('receiver');
1119
+ }
1120
+ if (!innerReceiver)
1121
+ break;
1122
+ if (CALL_EXPRESSION_TYPES.has(innerReceiver.type)) {
1123
+ current = innerReceiver; // continue walking
1124
+ }
1125
+ else {
1126
+ // Reached a simple identifier — the base receiver
1127
+ return { chain, baseReceiverName: innerReceiver.text || undefined };
1128
+ }
1129
+ }
1130
+ return chain.length > 0 ? { chain, baseReceiverName: undefined } : undefined;
1131
+ }