gitnexus 1.4.7 → 1.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +22 -1
  2. package/dist/cli/ai-context.d.ts +1 -1
  3. package/dist/cli/ai-context.js +1 -1
  4. package/dist/cli/analyze.d.ts +2 -0
  5. package/dist/cli/analyze.js +54 -21
  6. package/dist/cli/index.js +2 -1
  7. package/dist/cli/setup.js +78 -1
  8. package/dist/config/supported-languages.d.ts +30 -0
  9. package/dist/config/supported-languages.js +30 -0
  10. package/dist/core/embeddings/embedder.d.ts +6 -1
  11. package/dist/core/embeddings/embedder.js +65 -5
  12. package/dist/core/embeddings/embedding-pipeline.js +11 -9
  13. package/dist/core/embeddings/http-client.d.ts +31 -0
  14. package/dist/core/embeddings/http-client.js +179 -0
  15. package/dist/core/embeddings/index.d.ts +1 -0
  16. package/dist/core/embeddings/index.js +1 -0
  17. package/dist/core/embeddings/types.d.ts +1 -1
  18. package/dist/core/graph/types.d.ts +2 -1
  19. package/dist/core/ingestion/ast-helpers.d.ts +80 -0
  20. package/dist/core/ingestion/ast-helpers.js +738 -0
  21. package/dist/core/ingestion/call-analysis.d.ts +73 -0
  22. package/dist/core/ingestion/call-analysis.js +490 -0
  23. package/dist/core/ingestion/call-processor.d.ts +48 -1
  24. package/dist/core/ingestion/call-processor.js +368 -7
  25. package/dist/core/ingestion/call-routing.d.ts +6 -0
  26. package/dist/core/ingestion/entry-point-scoring.js +36 -26
  27. package/dist/core/ingestion/framework-detection.d.ts +10 -2
  28. package/dist/core/ingestion/framework-detection.js +49 -12
  29. package/dist/core/ingestion/heritage-processor.js +47 -49
  30. package/dist/core/ingestion/import-processor.d.ts +1 -1
  31. package/dist/core/ingestion/import-processor.js +103 -194
  32. package/dist/core/ingestion/import-resolution.d.ts +101 -0
  33. package/dist/core/ingestion/import-resolution.js +251 -0
  34. package/dist/core/ingestion/language-config.d.ts +3 -0
  35. package/dist/core/ingestion/language-config.js +13 -0
  36. package/dist/core/ingestion/markdown-processor.d.ts +17 -0
  37. package/dist/core/ingestion/markdown-processor.js +124 -0
  38. package/dist/core/ingestion/mro-processor.js +8 -3
  39. package/dist/core/ingestion/named-binding-extraction.d.ts +9 -43
  40. package/dist/core/ingestion/named-binding-extraction.js +89 -79
  41. package/dist/core/ingestion/parsing-processor.d.ts +2 -2
  42. package/dist/core/ingestion/parsing-processor.js +14 -73
  43. package/dist/core/ingestion/pipeline.d.ts +10 -0
  44. package/dist/core/ingestion/pipeline.js +421 -4
  45. package/dist/core/ingestion/resolution-context.d.ts +5 -0
  46. package/dist/core/ingestion/resolution-context.js +7 -4
  47. package/dist/core/ingestion/resolvers/index.d.ts +1 -1
  48. package/dist/core/ingestion/resolvers/index.js +1 -1
  49. package/dist/core/ingestion/resolvers/jvm.d.ts +2 -1
  50. package/dist/core/ingestion/resolvers/jvm.js +25 -9
  51. package/dist/core/ingestion/resolvers/php.d.ts +14 -0
  52. package/dist/core/ingestion/resolvers/php.js +43 -3
  53. package/dist/core/ingestion/resolvers/utils.d.ts +5 -0
  54. package/dist/core/ingestion/resolvers/utils.js +16 -0
  55. package/dist/core/ingestion/symbol-table.d.ts +16 -0
  56. package/dist/core/ingestion/symbol-table.js +20 -6
  57. package/dist/core/ingestion/tree-sitter-queries.d.ts +4 -4
  58. package/dist/core/ingestion/tree-sitter-queries.js +43 -2
  59. package/dist/core/ingestion/type-env.d.ts +28 -1
  60. package/dist/core/ingestion/type-env.js +419 -96
  61. package/dist/core/ingestion/type-extractors/c-cpp.d.ts +5 -0
  62. package/dist/core/ingestion/type-extractors/c-cpp.js +119 -0
  63. package/dist/core/ingestion/type-extractors/csharp.js +149 -16
  64. package/dist/core/ingestion/type-extractors/index.d.ts +1 -1
  65. package/dist/core/ingestion/type-extractors/index.js +1 -1
  66. package/dist/core/ingestion/type-extractors/jvm.js +169 -66
  67. package/dist/core/ingestion/type-extractors/rust.js +35 -1
  68. package/dist/core/ingestion/type-extractors/shared.d.ts +0 -2
  69. package/dist/core/ingestion/type-extractors/shared.js +5 -10
  70. package/dist/core/ingestion/type-extractors/swift.js +7 -6
  71. package/dist/core/ingestion/type-extractors/types.d.ts +37 -7
  72. package/dist/core/ingestion/type-extractors/typescript.js +141 -9
  73. package/dist/core/ingestion/utils.d.ts +2 -120
  74. package/dist/core/ingestion/utils.js +3 -1051
  75. package/dist/core/ingestion/workers/parse-worker.d.ts +13 -4
  76. package/dist/core/ingestion/workers/parse-worker.js +66 -87
  77. package/dist/core/lbug/csv-generator.js +18 -1
  78. package/dist/core/lbug/lbug-adapter.d.ts +10 -0
  79. package/dist/core/lbug/lbug-adapter.js +69 -4
  80. package/dist/core/lbug/schema.d.ts +5 -3
  81. package/dist/core/lbug/schema.js +26 -2
  82. package/dist/mcp/core/embedder.js +11 -3
  83. package/dist/mcp/core/lbug-adapter.js +12 -1
  84. package/dist/mcp/local/local-backend.d.ts +22 -0
  85. package/dist/mcp/local/local-backend.js +133 -29
  86. package/dist/mcp/resources.js +2 -0
  87. package/dist/mcp/tools.js +2 -2
  88. package/dist/server/api.d.ts +19 -1
  89. package/dist/server/api.js +66 -6
  90. package/dist/storage/git.d.ts +12 -0
  91. package/dist/storage/git.js +21 -0
  92. package/package.json +10 -2
@@ -0,0 +1,73 @@
1
+ import type { SyntaxNode } from './ast-helpers.js';
2
+ /** Node types representing call expressions across supported languages. */
3
+ export declare const CALL_EXPRESSION_TYPES: Set<string>;
4
+ /**
5
+ * Hard limit on chain depth to prevent runaway recursion.
6
+ * For `a.b().c().d()`, the chain has depth 2 (b and c before d).
7
+ */
8
+ export declare const MAX_CHAIN_DEPTH = 3;
9
+ /**
10
+ * Count direct arguments for a call expression across common tree-sitter grammars.
11
+ * Returns undefined when the argument container cannot be located cheaply.
12
+ */
13
+ export declare const countCallArguments: (callNode: SyntaxNode | null | undefined) => number | undefined;
14
+ type CallForm = 'free' | 'member' | 'constructor';
15
+ /**
16
+ * Infer whether a captured call site is a free call, member call, or constructor.
17
+ * Returns undefined if the form cannot be determined.
18
+ *
19
+ * Works by inspecting the AST structure between callNode (@call) and nameNode (@call.name).
20
+ * No tree-sitter query changes needed — the distinction is in the node types.
21
+ */
22
+ export declare const inferCallForm: (callNode: SyntaxNode, nameNode: SyntaxNode) => CallForm | undefined;
23
+ export declare const extractReceiverName: (nameNode: SyntaxNode) => string | undefined;
24
+ /**
25
+ * Extract the raw receiver AST node for a member call.
26
+ * Unlike extractReceiverName, this returns the receiver node regardless of its type —
27
+ * including call_expression / method_invocation nodes that appear in chained calls
28
+ * like `svc.getUser().save()`.
29
+ *
30
+ * Returns undefined when the call is not a member call or when no receiver node
31
+ * can be found (e.g. top-level free calls).
32
+ */
33
+ export declare const extractReceiverNode: (nameNode: SyntaxNode) => SyntaxNode | undefined;
34
+ /** One step in a mixed receiver chain. */
35
+ export type MixedChainStep = {
36
+ kind: 'field' | 'call';
37
+ name: string;
38
+ };
39
+ /**
40
+ * Walk a receiver AST node that is itself a call expression, accumulating the
41
+ * chain of intermediate method names up to MAX_CHAIN_DEPTH.
42
+ *
43
+ * For `svc.getUser().save()`, called with the receiver of `save` (getUser() call):
44
+ * returns { chain: ['getUser'], baseReceiverName: 'svc' }
45
+ *
46
+ * For `a.b().c().d()`, called with the receiver of `d` (c() call):
47
+ * returns { chain: ['b', 'c'], baseReceiverName: 'a' }
48
+ */
49
+ export declare function extractCallChain(receiverCallNode: SyntaxNode): {
50
+ chain: string[];
51
+ baseReceiverName: string | undefined;
52
+ } | undefined;
53
+ /**
54
+ * Walk a receiver AST node that may interleave field accesses and method calls,
55
+ * building a unified chain of steps up to MAX_CHAIN_DEPTH.
56
+ *
57
+ * For `svc.getUser().address.save()`, called with the receiver of `save`
58
+ * (`svc.getUser().address`, a field access node):
59
+ * returns { chain: [{ kind:'call', name:'getUser' }, { kind:'field', name:'address' }],
60
+ * baseReceiverName: 'svc' }
61
+ *
62
+ * For `user.getAddress().city.getName()`, called with receiver of `getName`
63
+ * (`user.getAddress().city`):
64
+ * returns { chain: [{ kind:'call', name:'getAddress' }, { kind:'field', name:'city' }],
65
+ * baseReceiverName: 'user' }
66
+ *
67
+ * Pure field chains and pure call chains are special cases (all steps same kind).
68
+ */
69
+ export declare function extractMixedChain(receiverNode: SyntaxNode): {
70
+ chain: MixedChainStep[];
71
+ baseReceiverName: string | undefined;
72
+ } | undefined;
73
+ export {};
@@ -0,0 +1,490 @@
1
+ import { CALL_ARGUMENT_LIST_TYPES } from './ast-helpers.js';
2
+ /** Node types representing call expressions across supported languages. */
3
+ export const CALL_EXPRESSION_TYPES = new Set([
4
+ 'call_expression', // TS/JS/C/C++/Go/Rust
5
+ 'method_invocation', // Java
6
+ 'member_call_expression', // PHP
7
+ 'nullsafe_member_call_expression', // PHP ?.
8
+ 'call', // Python/Ruby
9
+ 'invocation_expression', // C#
10
+ ]);
11
+ /**
12
+ * Hard limit on chain depth to prevent runaway recursion.
13
+ * For `a.b().c().d()`, the chain has depth 2 (b and c before d).
14
+ */
15
+ export const MAX_CHAIN_DEPTH = 3;
16
+ /**
17
+ * Count direct arguments for a call expression across common tree-sitter grammars.
18
+ * Returns undefined when the argument container cannot be located cheaply.
19
+ */
20
+ export const countCallArguments = (callNode) => {
21
+ if (!callNode)
22
+ return undefined;
23
+ // Direct field or direct child (most languages)
24
+ let argsNode = callNode.childForFieldName('arguments')
25
+ ?? callNode.children.find((child) => CALL_ARGUMENT_LIST_TYPES.has(child.type));
26
+ // Kotlin/Swift: call_expression → call_suffix → value_arguments
27
+ // Search one level deeper for languages that wrap arguments in a suffix node
28
+ if (!argsNode) {
29
+ for (const child of callNode.children) {
30
+ if (!child.isNamed)
31
+ continue;
32
+ const nested = child.children.find((gc) => CALL_ARGUMENT_LIST_TYPES.has(gc.type));
33
+ if (nested) {
34
+ argsNode = nested;
35
+ break;
36
+ }
37
+ }
38
+ }
39
+ if (!argsNode)
40
+ return undefined;
41
+ let count = 0;
42
+ for (const child of argsNode.children) {
43
+ if (!child.isNamed)
44
+ continue;
45
+ if (child.type === 'comment')
46
+ continue;
47
+ count++;
48
+ }
49
+ return count;
50
+ };
51
+ // ── Call-form discrimination (Phase 1, Step D) ─────────────────────────
52
+ /**
53
+ * AST node types that indicate a member-access wrapper around the callee name.
54
+ * When nameNode.parent.type is one of these, the call is a member call.
55
+ */
56
+ const MEMBER_ACCESS_NODE_TYPES = new Set([
57
+ 'member_expression', // TS/JS: obj.method()
58
+ 'attribute', // Python: obj.method()
59
+ 'member_access_expression', // C#: obj.Method()
60
+ 'field_expression', // Rust/C++: obj.method() / ptr->method()
61
+ 'selector_expression', // Go: obj.Method()
62
+ 'navigation_suffix', // Kotlin/Swift: obj.method() — nameNode sits inside navigation_suffix
63
+ 'member_binding_expression', // C#: user?.Method() — null-conditional access
64
+ ]);
65
+ /**
66
+ * Call node types that are inherently constructor invocations.
67
+ * Only includes patterns that the tree-sitter queries already capture as @call.
68
+ */
69
+ const CONSTRUCTOR_CALL_NODE_TYPES = new Set([
70
+ 'constructor_invocation', // Kotlin: Foo()
71
+ 'new_expression', // TS/JS/C++: new Foo()
72
+ 'object_creation_expression', // Java/C#/PHP: new Foo()
73
+ 'implicit_object_creation_expression', // C# 9: User u = new(...)
74
+ 'composite_literal', // Go: User{...}
75
+ 'struct_expression', // Rust: User { ... }
76
+ ]);
77
+ /**
78
+ * AST node types for scoped/qualified calls (e.g., Foo::new() in Rust, Foo::bar() in C++).
79
+ */
80
+ const SCOPED_CALL_NODE_TYPES = new Set([
81
+ 'scoped_identifier', // Rust: Foo::new()
82
+ 'qualified_identifier', // C++: ns::func()
83
+ ]);
84
+ /**
85
+ * Infer whether a captured call site is a free call, member call, or constructor.
86
+ * Returns undefined if the form cannot be determined.
87
+ *
88
+ * Works by inspecting the AST structure between callNode (@call) and nameNode (@call.name).
89
+ * No tree-sitter query changes needed — the distinction is in the node types.
90
+ */
91
+ export const inferCallForm = (callNode, nameNode) => {
92
+ // 1. Constructor: callNode itself is a constructor invocation (Kotlin)
93
+ if (CONSTRUCTOR_CALL_NODE_TYPES.has(callNode.type)) {
94
+ return 'constructor';
95
+ }
96
+ // 2. Member call: nameNode's parent is a member-access wrapper
97
+ const nameParent = nameNode.parent;
98
+ if (nameParent && MEMBER_ACCESS_NODE_TYPES.has(nameParent.type)) {
99
+ return 'member';
100
+ }
101
+ // 3. PHP: the callNode itself distinguishes member vs free calls
102
+ if (callNode.type === 'member_call_expression' || callNode.type === 'nullsafe_member_call_expression') {
103
+ return 'member';
104
+ }
105
+ if (callNode.type === 'scoped_call_expression') {
106
+ return 'member'; // static call Foo::bar()
107
+ }
108
+ // 4. Java method_invocation: member if it has an 'object' field
109
+ if (callNode.type === 'method_invocation' && callNode.childForFieldName('object')) {
110
+ return 'member';
111
+ }
112
+ // 4b. Ruby call with receiver: obj.method
113
+ if (callNode.type === 'call' && callNode.childForFieldName('receiver')) {
114
+ return 'member';
115
+ }
116
+ // 5. Scoped calls (Rust Foo::new(), C++ ns::func()): treat as free
117
+ // The receiver is a type, not an instance — handled differently in Phase 3
118
+ if (nameParent && SCOPED_CALL_NODE_TYPES.has(nameParent.type)) {
119
+ return 'free';
120
+ }
121
+ // 6. Default: if nameNode is a direct child of callNode, it's a free call
122
+ if (nameNode.parent === callNode || nameParent?.parent === callNode) {
123
+ return 'free';
124
+ }
125
+ return undefined;
126
+ };
127
+ /**
128
+ * Extract the receiver identifier for member calls.
129
+ * Only captures simple identifiers — returns undefined for complex expressions
130
+ * like getUser().save() or arr[0].method().
131
+ */
132
+ const SIMPLE_RECEIVER_TYPES = new Set([
133
+ 'identifier',
134
+ 'simple_identifier',
135
+ 'variable_name', // PHP $variable (tree-sitter-php)
136
+ 'name', // PHP name node
137
+ 'this', // TS/JS/Java/C# this.method()
138
+ 'self', // Rust/Python self.method()
139
+ 'super', // TS/JS/Java/Kotlin/Ruby super.method()
140
+ 'super_expression', // Kotlin wraps super in super_expression
141
+ 'base', // C# base.Method()
142
+ 'parent', // PHP parent::method()
143
+ 'constant', // Ruby CONSTANT.method() (uppercase identifiers)
144
+ ]);
145
+ export const extractReceiverName = (nameNode) => {
146
+ const parent = nameNode.parent;
147
+ if (!parent)
148
+ return undefined;
149
+ // PHP: member_call_expression / nullsafe_member_call_expression — receiver is on the callNode
150
+ // Java: method_invocation — receiver is the 'object' field on callNode
151
+ // For these, parent of nameNode is the call itself, so check the call's object field
152
+ const callNode = parent.parent ?? parent;
153
+ let receiver = null;
154
+ // Try standard field names used across grammars
155
+ receiver = parent.childForFieldName('object') // TS/JS member_expression, Python attribute, PHP, Java
156
+ ?? parent.childForFieldName('value') // Rust field_expression
157
+ ?? parent.childForFieldName('operand') // Go selector_expression
158
+ ?? parent.childForFieldName('expression') // C# member_access_expression
159
+ ?? parent.childForFieldName('argument'); // C++ field_expression
160
+ // Java method_invocation: 'object' field is on the callNode, not on nameNode's parent
161
+ if (!receiver && callNode.type === 'method_invocation') {
162
+ receiver = callNode.childForFieldName('object');
163
+ }
164
+ // PHP: member_call_expression has 'object' on the call node
165
+ if (!receiver && (callNode.type === 'member_call_expression' || callNode.type === 'nullsafe_member_call_expression')) {
166
+ receiver = callNode.childForFieldName('object');
167
+ }
168
+ // Ruby: call node has 'receiver' field
169
+ if (!receiver && parent.type === 'call') {
170
+ receiver = parent.childForFieldName('receiver');
171
+ }
172
+ // PHP scoped_call_expression (parent::method(), self::method()):
173
+ // nameNode's direct parent IS the scoped_call_expression (name is a direct child)
174
+ if (!receiver && (parent.type === 'scoped_call_expression' || callNode.type === 'scoped_call_expression')) {
175
+ const scopedCall = parent.type === 'scoped_call_expression' ? parent : callNode;
176
+ receiver = scopedCall.childForFieldName('scope');
177
+ // relative_scope wraps 'parent'/'self'/'static' — unwrap to get the keyword
178
+ if (receiver?.type === 'relative_scope') {
179
+ receiver = receiver.firstChild;
180
+ }
181
+ }
182
+ // C# null-conditional: user?.Save() → conditional_access_expression wraps member_binding_expression
183
+ if (!receiver && parent.type === 'member_binding_expression') {
184
+ const condAccess = parent.parent;
185
+ if (condAccess?.type === 'conditional_access_expression') {
186
+ receiver = condAccess.firstNamedChild;
187
+ }
188
+ }
189
+ // Kotlin/Swift: navigation_expression target is the first child
190
+ if (!receiver && parent.type === 'navigation_suffix') {
191
+ const navExpr = parent.parent;
192
+ if (navExpr?.type === 'navigation_expression') {
193
+ // First named child is the target (receiver)
194
+ for (const child of navExpr.children) {
195
+ if (child.isNamed && child !== parent) {
196
+ receiver = child;
197
+ break;
198
+ }
199
+ }
200
+ }
201
+ }
202
+ if (!receiver)
203
+ return undefined;
204
+ // Only capture simple identifiers — refuse complex expressions
205
+ if (SIMPLE_RECEIVER_TYPES.has(receiver.type)) {
206
+ return receiver.text;
207
+ }
208
+ // Python super().method(): receiver is a call node `super()` — extract the function name
209
+ if (receiver.type === 'call') {
210
+ const func = receiver.childForFieldName('function');
211
+ if (func?.text === 'super')
212
+ return 'super';
213
+ }
214
+ return undefined;
215
+ };
216
+ /**
217
+ * Extract the raw receiver AST node for a member call.
218
+ * Unlike extractReceiverName, this returns the receiver node regardless of its type —
219
+ * including call_expression / method_invocation nodes that appear in chained calls
220
+ * like `svc.getUser().save()`.
221
+ *
222
+ * Returns undefined when the call is not a member call or when no receiver node
223
+ * can be found (e.g. top-level free calls).
224
+ */
225
+ export const extractReceiverNode = (nameNode) => {
226
+ const parent = nameNode.parent;
227
+ if (!parent)
228
+ return undefined;
229
+ const callNode = parent.parent ?? parent;
230
+ let receiver = null;
231
+ receiver = parent.childForFieldName('object')
232
+ ?? parent.childForFieldName('value')
233
+ ?? parent.childForFieldName('operand')
234
+ ?? parent.childForFieldName('expression')
235
+ ?? parent.childForFieldName('argument');
236
+ if (!receiver && callNode.type === 'method_invocation') {
237
+ receiver = callNode.childForFieldName('object');
238
+ }
239
+ if (!receiver && (callNode.type === 'member_call_expression' || callNode.type === 'nullsafe_member_call_expression')) {
240
+ receiver = callNode.childForFieldName('object');
241
+ }
242
+ if (!receiver && parent.type === 'call') {
243
+ receiver = parent.childForFieldName('receiver');
244
+ }
245
+ if (!receiver && (parent.type === 'scoped_call_expression' || callNode.type === 'scoped_call_expression')) {
246
+ const scopedCall = parent.type === 'scoped_call_expression' ? parent : callNode;
247
+ receiver = scopedCall.childForFieldName('scope');
248
+ if (receiver?.type === 'relative_scope') {
249
+ receiver = receiver.firstChild;
250
+ }
251
+ }
252
+ if (!receiver && parent.type === 'member_binding_expression') {
253
+ const condAccess = parent.parent;
254
+ if (condAccess?.type === 'conditional_access_expression') {
255
+ receiver = condAccess.firstNamedChild;
256
+ }
257
+ }
258
+ if (!receiver && parent.type === 'navigation_suffix') {
259
+ const navExpr = parent.parent;
260
+ if (navExpr?.type === 'navigation_expression') {
261
+ for (const child of navExpr.children) {
262
+ if (child.isNamed && child !== parent) {
263
+ receiver = child;
264
+ break;
265
+ }
266
+ }
267
+ }
268
+ }
269
+ return receiver ?? undefined;
270
+ };
271
+ // ── Chained-call extraction ───────────────────────────────────────────────
272
+ /** Node types representing member/field access across languages. */
273
+ const FIELD_ACCESS_NODE_TYPES = new Set([
274
+ 'member_expression', // TS/JS
275
+ 'member_access_expression', // C#
276
+ 'selector_expression', // Go
277
+ 'field_expression', // Rust/C++
278
+ 'field_access', // Java
279
+ 'attribute', // Python
280
+ 'navigation_expression', // Kotlin/Swift
281
+ 'member_binding_expression', // C# null-conditional (user?.Address)
282
+ ]);
283
+ /**
284
+ * Walk a receiver AST node that is itself a call expression, accumulating the
285
+ * chain of intermediate method names up to MAX_CHAIN_DEPTH.
286
+ *
287
+ * For `svc.getUser().save()`, called with the receiver of `save` (getUser() call):
288
+ * returns { chain: ['getUser'], baseReceiverName: 'svc' }
289
+ *
290
+ * For `a.b().c().d()`, called with the receiver of `d` (c() call):
291
+ * returns { chain: ['b', 'c'], baseReceiverName: 'a' }
292
+ */
293
+ export function extractCallChain(receiverCallNode) {
294
+ const chain = [];
295
+ let current = receiverCallNode;
296
+ while (CALL_EXPRESSION_TYPES.has(current.type) && chain.length < MAX_CHAIN_DEPTH) {
297
+ // Extract the method name from this call node.
298
+ const funcNode = current.childForFieldName?.('function')
299
+ ?? current.childForFieldName?.('name')
300
+ ?? current.childForFieldName?.('method'); // Ruby `call` node
301
+ let methodName;
302
+ let innerReceiver = null;
303
+ if (funcNode) {
304
+ // member_expression / attribute: last named child is the method identifier
305
+ methodName = funcNode.lastNamedChild?.text ?? funcNode.text;
306
+ }
307
+ // Kotlin/Swift: call_expression exposes callee as firstNamedChild, not a field.
308
+ // navigation_expression: method name is in navigation_suffix → simple_identifier.
309
+ if (!funcNode && current.type === 'call_expression') {
310
+ const callee = current.firstNamedChild;
311
+ if (callee?.type === 'navigation_expression') {
312
+ const suffix = callee.lastNamedChild;
313
+ if (suffix?.type === 'navigation_suffix') {
314
+ methodName = suffix.lastNamedChild?.text;
315
+ // The receiver is the part of navigation_expression before the suffix
316
+ for (let i = 0; i < callee.namedChildCount; i++) {
317
+ const child = callee.namedChild(i);
318
+ if (child && child.type !== 'navigation_suffix') {
319
+ innerReceiver = child;
320
+ break;
321
+ }
322
+ }
323
+ }
324
+ }
325
+ }
326
+ if (!methodName)
327
+ break;
328
+ chain.unshift(methodName); // build chain outermost-last
329
+ // Walk into the receiver of this call to continue the chain
330
+ if (!innerReceiver && funcNode) {
331
+ innerReceiver = funcNode.childForFieldName?.('object')
332
+ ?? funcNode.childForFieldName?.('value')
333
+ ?? funcNode.childForFieldName?.('operand')
334
+ ?? funcNode.childForFieldName?.('expression');
335
+ }
336
+ // Java method_invocation: object field is on the call node
337
+ if (!innerReceiver && current.type === 'method_invocation') {
338
+ innerReceiver = current.childForFieldName?.('object');
339
+ }
340
+ // PHP member_call_expression
341
+ if (!innerReceiver && (current.type === 'member_call_expression' || current.type === 'nullsafe_member_call_expression')) {
342
+ innerReceiver = current.childForFieldName?.('object');
343
+ }
344
+ // Ruby `call` node: receiver field is on the call node itself
345
+ if (!innerReceiver && current.type === 'call') {
346
+ innerReceiver = current.childForFieldName?.('receiver');
347
+ }
348
+ if (!innerReceiver)
349
+ break;
350
+ if (CALL_EXPRESSION_TYPES.has(innerReceiver.type)) {
351
+ current = innerReceiver; // continue walking
352
+ }
353
+ else {
354
+ // Reached a simple identifier — the base receiver
355
+ return { chain, baseReceiverName: innerReceiver.text || undefined };
356
+ }
357
+ }
358
+ return chain.length > 0 ? { chain, baseReceiverName: undefined } : undefined;
359
+ }
360
+ /**
361
+ * Walk a receiver AST node that may interleave field accesses and method calls,
362
+ * building a unified chain of steps up to MAX_CHAIN_DEPTH.
363
+ *
364
+ * For `svc.getUser().address.save()`, called with the receiver of `save`
365
+ * (`svc.getUser().address`, a field access node):
366
+ * returns { chain: [{ kind:'call', name:'getUser' }, { kind:'field', name:'address' }],
367
+ * baseReceiverName: 'svc' }
368
+ *
369
+ * For `user.getAddress().city.getName()`, called with receiver of `getName`
370
+ * (`user.getAddress().city`):
371
+ * returns { chain: [{ kind:'call', name:'getAddress' }, { kind:'field', name:'city' }],
372
+ * baseReceiverName: 'user' }
373
+ *
374
+ * Pure field chains and pure call chains are special cases (all steps same kind).
375
+ */
376
+ export function extractMixedChain(receiverNode) {
377
+ const chain = [];
378
+ let current = receiverNode;
379
+ while (chain.length < MAX_CHAIN_DEPTH) {
380
+ if (CALL_EXPRESSION_TYPES.has(current.type)) {
381
+ // ── Call expression: extract method name + inner receiver ────────────
382
+ const funcNode = current.childForFieldName?.('function')
383
+ ?? current.childForFieldName?.('name')
384
+ ?? current.childForFieldName?.('method');
385
+ let methodName;
386
+ let innerReceiver = null;
387
+ if (funcNode) {
388
+ methodName = funcNode.lastNamedChild?.text ?? funcNode.text;
389
+ }
390
+ // Kotlin/Swift: call_expression → navigation_expression
391
+ if (!funcNode && current.type === 'call_expression') {
392
+ const callee = current.firstNamedChild;
393
+ if (callee?.type === 'navigation_expression') {
394
+ const suffix = callee.lastNamedChild;
395
+ if (suffix?.type === 'navigation_suffix') {
396
+ methodName = suffix.lastNamedChild?.text;
397
+ for (let i = 0; i < callee.namedChildCount; i++) {
398
+ const child = callee.namedChild(i);
399
+ if (child && child.type !== 'navigation_suffix') {
400
+ innerReceiver = child;
401
+ break;
402
+ }
403
+ }
404
+ }
405
+ }
406
+ }
407
+ if (!methodName)
408
+ break;
409
+ chain.unshift({ kind: 'call', name: methodName });
410
+ if (!innerReceiver && funcNode) {
411
+ innerReceiver = funcNode.childForFieldName?.('object')
412
+ ?? funcNode.childForFieldName?.('value')
413
+ ?? funcNode.childForFieldName?.('operand')
414
+ ?? funcNode.childForFieldName?.('argument') // C/C++ field_expression
415
+ ?? funcNode.childForFieldName?.('expression')
416
+ ?? null;
417
+ }
418
+ if (!innerReceiver && current.type === 'method_invocation') {
419
+ innerReceiver = current.childForFieldName?.('object') ?? null;
420
+ }
421
+ if (!innerReceiver && (current.type === 'member_call_expression' || current.type === 'nullsafe_member_call_expression')) {
422
+ innerReceiver = current.childForFieldName?.('object') ?? null;
423
+ }
424
+ if (!innerReceiver && current.type === 'call') {
425
+ innerReceiver = current.childForFieldName?.('receiver') ?? null;
426
+ }
427
+ if (!innerReceiver)
428
+ break;
429
+ if (CALL_EXPRESSION_TYPES.has(innerReceiver.type) || FIELD_ACCESS_NODE_TYPES.has(innerReceiver.type)) {
430
+ current = innerReceiver;
431
+ }
432
+ else {
433
+ return { chain, baseReceiverName: innerReceiver.text || undefined };
434
+ }
435
+ }
436
+ else if (FIELD_ACCESS_NODE_TYPES.has(current.type)) {
437
+ // ── Field/member access: extract property name + inner object ─────────
438
+ let propertyName;
439
+ let innerObject = null;
440
+ if (current.type === 'navigation_expression') {
441
+ for (const child of current.children ?? []) {
442
+ if (child.type === 'navigation_suffix') {
443
+ for (const sc of child.children ?? []) {
444
+ if (sc.isNamed && sc.type !== '.') {
445
+ propertyName = sc.text;
446
+ break;
447
+ }
448
+ }
449
+ }
450
+ else if (child.isNamed && !innerObject) {
451
+ innerObject = child;
452
+ }
453
+ }
454
+ }
455
+ else if (current.type === 'attribute') {
456
+ innerObject = current.childForFieldName?.('object') ?? null;
457
+ propertyName = current.childForFieldName?.('attribute')?.text;
458
+ }
459
+ else {
460
+ innerObject = current.childForFieldName?.('object')
461
+ ?? current.childForFieldName?.('value')
462
+ ?? current.childForFieldName?.('operand')
463
+ ?? current.childForFieldName?.('argument') // C/C++ field_expression
464
+ ?? current.childForFieldName?.('expression')
465
+ ?? null;
466
+ propertyName = (current.childForFieldName?.('property')
467
+ ?? current.childForFieldName?.('field')
468
+ ?? current.childForFieldName?.('name'))?.text;
469
+ }
470
+ if (!propertyName)
471
+ break;
472
+ chain.unshift({ kind: 'field', name: propertyName });
473
+ if (!innerObject)
474
+ break;
475
+ if (CALL_EXPRESSION_TYPES.has(innerObject.type) || FIELD_ACCESS_NODE_TYPES.has(innerObject.type)) {
476
+ current = innerObject;
477
+ }
478
+ else {
479
+ return { chain, baseReceiverName: innerObject.text || undefined };
480
+ }
481
+ }
482
+ else {
483
+ // Simple identifier — this is the base receiver
484
+ return chain.length > 0
485
+ ? { chain, baseReceiverName: current.text || undefined }
486
+ : undefined;
487
+ }
488
+ }
489
+ return chain.length > 0 ? { chain, baseReceiverName: undefined } : undefined;
490
+ }
@@ -1,11 +1,58 @@
1
1
  import { KnowledgeGraph } from '../graph/types.js';
2
2
  import { ASTCache } from './ast-cache.js';
3
+ import type { SymbolTable } from './symbol-table.js';
3
4
  import type { ResolutionContext } from './resolution-context.js';
4
5
  import type { ExtractedCall, ExtractedAssignment, ExtractedHeritage, ExtractedRoute, FileConstructorBindings } from './workers/parse-worker.js';
6
+ /** Per-file resolved type bindings for exported symbols.
7
+ * Populated during call processing, consumed by Phase 14 re-resolution pass. */
8
+ export type ExportedTypeMap = Map<string, Map<string, string>>;
9
+ /** Build a map of imported callee names → return types for cross-file call-result binding.
10
+ * Consulted ONLY when SymbolTable has no unambiguous local match (local-first principle). */
11
+ export declare function buildImportedReturnTypes(filePath: string, namedImportMap: ReadonlyMap<string, ReadonlyMap<string, {
12
+ sourcePath: string;
13
+ exportedName: string;
14
+ }>>, symbolTable: {
15
+ lookupExactFull(filePath: string, name: string): {
16
+ returnType?: string;
17
+ } | undefined;
18
+ }): ReadonlyMap<string, string>;
19
+ /** Build cross-file RAW return types for imported callables.
20
+ * Unlike buildImportedReturnTypes (which stores extractReturnTypeName output),
21
+ * this stores the raw declared return type string (e.g., 'User[]', 'List<User>').
22
+ * Used by lookupRawReturnType for for-loop element extraction via extractElementTypeFromString. */
23
+ export declare function buildImportedRawReturnTypes(filePath: string, namedImportMap: ReadonlyMap<string, ReadonlyMap<string, {
24
+ sourcePath: string;
25
+ exportedName: string;
26
+ }>>, symbolTable: {
27
+ lookupExactFull(filePath: string, name: string): {
28
+ returnType?: string;
29
+ } | undefined;
30
+ }): ReadonlyMap<string, string>;
31
+ /** Build ExportedTypeMap from graph nodes — used for worker path where TypeEnv
32
+ * is not available in the main thread. Collects returnType/declaredType from
33
+ * exported symbols that have callables with known return types. */
34
+ export declare function buildExportedTypeMapFromGraph(graph: KnowledgeGraph, symbolTable: SymbolTable): ExportedTypeMap;
35
+ /** Seed cross-file receiver types into pre-extracted call records.
36
+ * Fills missing receiverTypeName for single-hop imported variables
37
+ * using ExportedTypeMap + namedImportMap — zero disk I/O, zero AST re-parsing.
38
+ * Mutates calls in-place. Runs BEFORE processCallsFromExtracted. */
39
+ export declare function seedCrossFileReceiverTypes(calls: ExtractedCall[], namedImportMap: ReadonlyMap<string, ReadonlyMap<string, {
40
+ sourcePath: string;
41
+ exportedName: string;
42
+ }>>, exportedTypeMap: ReadonlyMap<string, ReadonlyMap<string, string>>): {
43
+ enrichedCount: number;
44
+ };
5
45
  export declare const processCalls: (graph: KnowledgeGraph, files: {
6
46
  path: string;
7
47
  content: string;
8
- }[], astCache: ASTCache, ctx: ResolutionContext, onProgress?: (current: number, total: number) => void) => Promise<ExtractedHeritage[]>;
48
+ }[], astCache: ASTCache, ctx: ResolutionContext, onProgress?: (current: number, total: number) => void, exportedTypeMap?: ExportedTypeMap,
49
+ /** Phase 14: pre-resolved cross-file bindings to seed into buildTypeEnv. Keyed by filePath → Map<localName, typeName>. */
50
+ importedBindingsMap?: ReadonlyMap<string, ReadonlyMap<string, string>>,
51
+ /** Phase 14 E3: cross-file return types for imported callables. Keyed by filePath → Map<calleeName, returnType>.
52
+ * Consulted ONLY when SymbolTable has no unambiguous match (local-first principle). */
53
+ importedReturnTypesMap?: ReadonlyMap<string, ReadonlyMap<string, string>>,
54
+ /** Phase 14 E3: cross-file RAW return types for for-loop element extraction. Keyed by filePath → Map<calleeName, rawReturnType>. */
55
+ importedRawReturnTypesMap?: ReadonlyMap<string, ReadonlyMap<string, string>>) => Promise<ExtractedHeritage[]>;
9
56
  /**
10
57
  * Fast path: resolve pre-extracted call sites from workers.
11
58
  * No AST parsing — workers already extracted calledName + sourceId.