gitnexus 1.5.2 → 1.6.0

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 (207) hide show
  1. package/README.md +10 -0
  2. package/dist/_shared/graph/types.d.ts +1 -1
  3. package/dist/_shared/graph/types.d.ts.map +1 -1
  4. package/dist/_shared/index.d.ts +1 -0
  5. package/dist/_shared/index.d.ts.map +1 -1
  6. package/dist/_shared/language-detection.d.ts.map +1 -1
  7. package/dist/_shared/language-detection.js +2 -0
  8. package/dist/_shared/language-detection.js.map +1 -1
  9. package/dist/_shared/languages.d.ts +1 -0
  10. package/dist/_shared/languages.d.ts.map +1 -1
  11. package/dist/_shared/languages.js +1 -0
  12. package/dist/_shared/languages.js.map +1 -1
  13. package/dist/_shared/lbug/schema-constants.d.ts +1 -1
  14. package/dist/_shared/lbug/schema-constants.d.ts.map +1 -1
  15. package/dist/_shared/lbug/schema-constants.js +3 -1
  16. package/dist/_shared/lbug/schema-constants.js.map +1 -1
  17. package/dist/_shared/mro-strategy.d.ts +19 -0
  18. package/dist/_shared/mro-strategy.d.ts.map +1 -0
  19. package/dist/_shared/mro-strategy.js +2 -0
  20. package/dist/_shared/mro-strategy.js.map +1 -0
  21. package/dist/cli/ai-context.d.ts +1 -0
  22. package/dist/cli/ai-context.js +28 -4
  23. package/dist/cli/analyze.d.ts +2 -0
  24. package/dist/cli/analyze.js +2 -1
  25. package/dist/cli/group.d.ts +2 -0
  26. package/dist/cli/group.js +233 -0
  27. package/dist/cli/index.js +3 -0
  28. package/dist/cli/serve.js +4 -1
  29. package/dist/cli/setup.js +34 -3
  30. package/dist/cli/wiki.js +15 -44
  31. package/dist/config/ignore-service.js +8 -3
  32. package/dist/core/augmentation/engine.js +1 -1
  33. package/dist/core/git-staleness.d.ts +13 -0
  34. package/dist/core/git-staleness.js +29 -0
  35. package/dist/core/group/bridge-db.d.ts +82 -0
  36. package/dist/core/group/bridge-db.js +460 -0
  37. package/dist/core/group/bridge-schema.d.ts +27 -0
  38. package/dist/core/group/bridge-schema.js +55 -0
  39. package/dist/core/group/config-parser.d.ts +3 -0
  40. package/dist/core/group/config-parser.js +83 -0
  41. package/dist/core/group/contract-extractor.d.ts +7 -0
  42. package/dist/core/group/contract-extractor.js +1 -0
  43. package/dist/core/group/extractors/grpc-extractor.d.ts +16 -0
  44. package/dist/core/group/extractors/grpc-extractor.js +264 -0
  45. package/dist/core/group/extractors/http-route-extractor.d.ts +24 -0
  46. package/dist/core/group/extractors/http-route-extractor.js +428 -0
  47. package/dist/core/group/extractors/topic-extractor.d.ts +9 -0
  48. package/dist/core/group/extractors/topic-extractor.js +234 -0
  49. package/dist/core/group/matching.d.ts +13 -0
  50. package/dist/core/group/matching.js +198 -0
  51. package/dist/core/group/normalization.d.ts +3 -0
  52. package/dist/core/group/normalization.js +115 -0
  53. package/dist/core/group/service-boundary-detector.d.ts +8 -0
  54. package/dist/core/group/service-boundary-detector.js +155 -0
  55. package/dist/core/group/service.d.ts +46 -0
  56. package/dist/core/group/service.js +160 -0
  57. package/dist/core/group/storage.d.ts +9 -0
  58. package/dist/core/group/storage.js +91 -0
  59. package/dist/core/group/sync.d.ts +21 -0
  60. package/dist/core/group/sync.js +148 -0
  61. package/dist/core/group/types.d.ts +130 -0
  62. package/dist/core/group/types.js +1 -0
  63. package/dist/core/ingestion/binding-accumulator.d.ts +207 -0
  64. package/dist/core/ingestion/binding-accumulator.js +332 -0
  65. package/dist/core/ingestion/call-processor.d.ts +155 -24
  66. package/dist/core/ingestion/call-processor.js +1129 -247
  67. package/dist/core/ingestion/class-extractors/generic.d.ts +2 -0
  68. package/dist/core/ingestion/class-extractors/generic.js +135 -0
  69. package/dist/core/ingestion/class-types.d.ts +34 -0
  70. package/dist/core/ingestion/class-types.js +1 -0
  71. package/dist/core/ingestion/entry-point-scoring.d.ts +1 -0
  72. package/dist/core/ingestion/entry-point-scoring.js +1 -0
  73. package/dist/core/ingestion/field-extractors/configs/helpers.d.ts +5 -1
  74. package/dist/core/ingestion/field-extractors/configs/helpers.js +13 -3
  75. package/dist/core/ingestion/field-types.d.ts +2 -2
  76. package/dist/core/ingestion/filesystem-walker.js +8 -0
  77. package/dist/core/ingestion/framework-detection.d.ts +1 -0
  78. package/dist/core/ingestion/framework-detection.js +1 -0
  79. package/dist/core/ingestion/heritage-processor.d.ts +8 -15
  80. package/dist/core/ingestion/heritage-processor.js +15 -28
  81. package/dist/core/ingestion/import-processor.d.ts +1 -11
  82. package/dist/core/ingestion/import-processor.js +0 -12
  83. package/dist/core/ingestion/import-resolvers/utils.js +1 -0
  84. package/dist/core/ingestion/import-resolvers/vue.d.ts +8 -0
  85. package/dist/core/ingestion/import-resolvers/vue.js +9 -0
  86. package/dist/core/ingestion/language-provider.d.ts +6 -3
  87. package/dist/core/ingestion/languages/c-cpp.js +168 -1
  88. package/dist/core/ingestion/languages/csharp.js +20 -0
  89. package/dist/core/ingestion/languages/dart.js +26 -4
  90. package/dist/core/ingestion/languages/go.js +22 -0
  91. package/dist/core/ingestion/languages/index.d.ts +1 -0
  92. package/dist/core/ingestion/languages/index.js +2 -0
  93. package/dist/core/ingestion/languages/java.js +17 -0
  94. package/dist/core/ingestion/languages/kotlin.js +24 -1
  95. package/dist/core/ingestion/languages/php.js +23 -11
  96. package/dist/core/ingestion/languages/python.js +9 -0
  97. package/dist/core/ingestion/languages/ruby.js +28 -0
  98. package/dist/core/ingestion/languages/rust.js +38 -0
  99. package/dist/core/ingestion/languages/swift.js +31 -0
  100. package/dist/core/ingestion/languages/typescript.d.ts +1 -0
  101. package/dist/core/ingestion/languages/typescript.js +54 -1
  102. package/dist/core/ingestion/languages/vue.d.ts +13 -0
  103. package/dist/core/ingestion/languages/vue.js +81 -0
  104. package/dist/core/ingestion/method-extractors/configs/c-cpp.d.ts +3 -0
  105. package/dist/core/ingestion/method-extractors/configs/c-cpp.js +387 -0
  106. package/dist/core/ingestion/method-extractors/configs/csharp.js +5 -1
  107. package/dist/core/ingestion/method-extractors/configs/dart.d.ts +2 -0
  108. package/dist/core/ingestion/method-extractors/configs/dart.js +376 -0
  109. package/dist/core/ingestion/method-extractors/configs/go.d.ts +2 -0
  110. package/dist/core/ingestion/method-extractors/configs/go.js +176 -0
  111. package/dist/core/ingestion/method-extractors/configs/jvm.js +13 -4
  112. package/dist/core/ingestion/method-extractors/configs/php.d.ts +2 -0
  113. package/dist/core/ingestion/method-extractors/configs/php.js +304 -0
  114. package/dist/core/ingestion/method-extractors/configs/python.d.ts +2 -0
  115. package/dist/core/ingestion/method-extractors/configs/python.js +309 -0
  116. package/dist/core/ingestion/method-extractors/configs/ruby.d.ts +2 -0
  117. package/dist/core/ingestion/method-extractors/configs/ruby.js +285 -0
  118. package/dist/core/ingestion/method-extractors/configs/rust.d.ts +2 -0
  119. package/dist/core/ingestion/method-extractors/configs/rust.js +195 -0
  120. package/dist/core/ingestion/method-extractors/configs/swift.d.ts +2 -0
  121. package/dist/core/ingestion/method-extractors/configs/swift.js +277 -0
  122. package/dist/core/ingestion/method-extractors/configs/typescript-javascript.d.ts +3 -0
  123. package/dist/core/ingestion/method-extractors/configs/typescript-javascript.js +338 -0
  124. package/dist/core/ingestion/method-extractors/generic.js +38 -15
  125. package/dist/core/ingestion/method-types.d.ts +25 -0
  126. package/dist/core/ingestion/model/field-registry.d.ts +18 -0
  127. package/dist/core/ingestion/model/field-registry.js +22 -0
  128. package/dist/core/ingestion/model/heritage-map.d.ts +70 -0
  129. package/dist/core/ingestion/model/heritage-map.js +159 -0
  130. package/dist/core/ingestion/model/index.d.ts +20 -0
  131. package/dist/core/ingestion/model/index.js +41 -0
  132. package/dist/core/ingestion/model/method-registry.d.ts +62 -0
  133. package/dist/core/ingestion/model/method-registry.js +130 -0
  134. package/dist/core/ingestion/model/registration-table.d.ts +139 -0
  135. package/dist/core/ingestion/model/registration-table.js +224 -0
  136. package/dist/core/ingestion/model/resolution-context.d.ts +93 -0
  137. package/dist/core/ingestion/model/resolution-context.js +337 -0
  138. package/dist/core/ingestion/model/resolve.d.ts +56 -0
  139. package/dist/core/ingestion/model/resolve.js +242 -0
  140. package/dist/core/ingestion/model/semantic-model.d.ts +86 -0
  141. package/dist/core/ingestion/model/semantic-model.js +120 -0
  142. package/dist/core/ingestion/model/symbol-table.d.ts +222 -0
  143. package/dist/core/ingestion/model/symbol-table.js +206 -0
  144. package/dist/core/ingestion/model/type-registry.d.ts +39 -0
  145. package/dist/core/ingestion/model/type-registry.js +62 -0
  146. package/dist/core/ingestion/mro-processor.d.ts +4 -3
  147. package/dist/core/ingestion/mro-processor.js +310 -106
  148. package/dist/core/ingestion/parsing-processor.d.ts +5 -4
  149. package/dist/core/ingestion/parsing-processor.js +210 -85
  150. package/dist/core/ingestion/pipeline.d.ts +2 -0
  151. package/dist/core/ingestion/pipeline.js +192 -68
  152. package/dist/core/ingestion/tree-sitter-queries.d.ts +6 -6
  153. package/dist/core/ingestion/tree-sitter-queries.js +37 -0
  154. package/dist/core/ingestion/type-env.d.ts +15 -2
  155. package/dist/core/ingestion/type-env.js +163 -102
  156. package/dist/core/ingestion/type-extractors/csharp.js +17 -0
  157. package/dist/core/ingestion/type-extractors/jvm.js +11 -0
  158. package/dist/core/ingestion/type-extractors/php.js +0 -55
  159. package/dist/core/ingestion/type-extractors/ruby.js +0 -32
  160. package/dist/core/ingestion/type-extractors/swift.js +13 -0
  161. package/dist/core/ingestion/type-extractors/types.d.ts +8 -8
  162. package/dist/core/ingestion/type-extractors/typescript.js +66 -69
  163. package/dist/core/ingestion/utils/ast-helpers.d.ts +33 -43
  164. package/dist/core/ingestion/utils/ast-helpers.js +129 -565
  165. package/dist/core/ingestion/utils/method-props.d.ts +32 -0
  166. package/dist/core/ingestion/utils/method-props.js +147 -0
  167. package/dist/core/ingestion/vue-sfc-extractor.d.ts +44 -0
  168. package/dist/core/ingestion/vue-sfc-extractor.js +94 -0
  169. package/dist/core/ingestion/workers/parse-worker.d.ts +31 -19
  170. package/dist/core/ingestion/workers/parse-worker.js +463 -198
  171. package/dist/core/lbug/lbug-adapter.d.ts +6 -0
  172. package/dist/core/lbug/lbug-adapter.js +68 -3
  173. package/dist/core/lbug/pool-adapter.d.ts +76 -0
  174. package/dist/core/lbug/pool-adapter.js +522 -0
  175. package/dist/core/run-analyze.d.ts +2 -0
  176. package/dist/core/run-analyze.js +1 -1
  177. package/dist/core/search/bm25-index.js +1 -1
  178. package/dist/core/tree-sitter/parser-loader.js +1 -0
  179. package/dist/core/wiki/graph-queries.js +1 -1
  180. package/dist/core/wiki/html-viewer.js +6 -4
  181. package/dist/core/wiki/llm-client.js +4 -6
  182. package/dist/mcp/core/embedder.js +6 -5
  183. package/dist/mcp/core/lbug-adapter.d.ts +3 -63
  184. package/dist/mcp/core/lbug-adapter.js +3 -484
  185. package/dist/mcp/local/local-backend.d.ts +31 -2
  186. package/dist/mcp/local/local-backend.js +255 -46
  187. package/dist/mcp/resources.js +5 -4
  188. package/dist/mcp/staleness.d.ts +3 -13
  189. package/dist/mcp/staleness.js +2 -31
  190. package/dist/mcp/tools.js +80 -4
  191. package/dist/server/analyze-job.d.ts +2 -0
  192. package/dist/server/analyze-job.js +4 -0
  193. package/dist/server/api.d.ts +20 -1
  194. package/dist/server/api.js +306 -71
  195. package/dist/server/git-clone.d.ts +2 -1
  196. package/dist/server/git-clone.js +98 -5
  197. package/dist/storage/git.d.ts +13 -0
  198. package/dist/storage/git.js +25 -0
  199. package/dist/storage/repo-manager.js +1 -1
  200. package/package.json +8 -2
  201. package/scripts/patch-tree-sitter-swift.cjs +78 -0
  202. package/dist/core/ingestion/named-binding-processor.d.ts +0 -18
  203. package/dist/core/ingestion/named-binding-processor.js +0 -42
  204. package/dist/core/ingestion/resolution-context.d.ts +0 -58
  205. package/dist/core/ingestion/resolution-context.js +0 -135
  206. package/dist/core/ingestion/symbol-table.d.ts +0 -79
  207. package/dist/core/ingestion/symbol-table.js +0 -115
@@ -1,6 +1,6 @@
1
1
  // gitnexus/src/core/ingestion/method-extractors/generic.ts
2
- /** Owner node types where member functions are effectively static (JVM semantics). */
3
- const STATIC_OWNER_TYPES = new Set(['companion_object', 'object_declaration']);
2
+ /** Owner node types where member functions are effectively static (JVM/Ruby semantics). */
3
+ const STATIC_OWNER_TYPES = new Set(['companion_object', 'object_declaration', 'singleton_class']);
4
4
  /**
5
5
  * Create a MethodExtractor from a declarative config.
6
6
  */
@@ -16,18 +16,26 @@ export function createMethodExtractor(config) {
16
16
  extract(node, context) {
17
17
  if (!typeDeclarationSet.has(node.type))
18
18
  return null;
19
- // Resolve owner name: field-based → type_identifier → simple_identifier → "Companion"
19
+ // Resolve owner name: config hook → field-based → type_identifier → simple_identifier → "Companion"
20
20
  let ownerName;
21
- const nameField = node.childForFieldName('name');
22
- if (nameField) {
23
- ownerName = nameField.text;
21
+ if (config.extractOwnerName) {
22
+ ownerName = config.extractOwnerName(node);
24
23
  }
25
- else {
26
- for (let i = 0; i < node.namedChildCount; i++) {
27
- const child = node.namedChild(i);
28
- if (child && (child.type === 'type_identifier' || child.type === 'simple_identifier')) {
29
- ownerName = child.text;
30
- break;
24
+ if (!ownerName) {
25
+ const nameField = node.childForFieldName('name');
26
+ if (nameField) {
27
+ ownerName = nameField.text;
28
+ }
29
+ else {
30
+ for (let i = 0; i < node.namedChildCount; i++) {
31
+ const child = node.namedChild(i);
32
+ if (child &&
33
+ (child.type === 'type_identifier' ||
34
+ child.type === 'simple_identifier' ||
35
+ child.type === 'identifier')) {
36
+ ownerName = child.text;
37
+ break;
38
+ }
31
39
  }
32
40
  }
33
41
  }
@@ -50,6 +58,12 @@ export function createMethodExtractor(config) {
50
58
  }
51
59
  return { ownerName, methods };
52
60
  },
61
+ extractFromNode(node, context) {
62
+ if (!methodNodeSet.has(node.type))
63
+ return null;
64
+ return buildMethod(node, node, context, config);
65
+ },
66
+ ...(config.extractFunctionName ? { extractFunctionName: config.extractFunctionName } : {}),
53
67
  };
54
68
  }
55
69
  function findBodies(node, bodyNodeSet) {
@@ -77,19 +91,27 @@ function findBodies(node, bodyNodeSet) {
77
91
  }
78
92
  return result;
79
93
  }
80
- function addNestedBodies(parent, bodyNodeSet, out) {
94
+ function addNestedBodies(parent, bodyNodeSet, out, seen) {
95
+ const visited = seen ?? new Set(out);
81
96
  for (let i = 0; i < parent.namedChildCount; i++) {
82
97
  const child = parent.namedChild(i);
83
- if (child && bodyNodeSet.has(child.type) && !out.includes(child)) {
98
+ if (child && bodyNodeSet.has(child.type) && !visited.has(child)) {
99
+ visited.add(child);
84
100
  out.push(child);
85
101
  }
86
102
  }
87
103
  }
88
104
  function extractMethodsFromBody(body, ownerNode, context, config, methodNodeSet, out) {
89
105
  for (let i = 0; i < body.namedChildCount; i++) {
90
- const child = body.namedChild(i);
106
+ let child = body.namedChild(i);
91
107
  if (!child)
92
108
  continue;
109
+ // C++ template methods are wrapped in template_declaration — unwrap to the inner node
110
+ if (child.type === 'template_declaration') {
111
+ const inner = child.namedChildren.find((c) => methodNodeSet.has(c.type));
112
+ if (inner)
113
+ child = inner;
114
+ }
93
115
  if (methodNodeSet.has(child.type)) {
94
116
  const method = buildMethod(child, ownerNode, context, config);
95
117
  if (method)
@@ -130,6 +152,7 @@ function buildMethod(node, ownerNode, context, config) {
130
152
  ...(config.isOverride?.(node) ? { isOverride: true } : {}),
131
153
  ...(config.isAsync?.(node) ? { isAsync: true } : {}),
132
154
  ...(config.isPartial?.(node) ? { isPartial: true } : {}),
155
+ ...(config.isConst?.(node) ? { isConst: true } : {}),
133
156
  annotations: config.extractAnnotations?.(node) ?? [],
134
157
  sourceFile: context.filePath,
135
158
  line: node.startPosition.row + 1,
@@ -5,6 +5,10 @@ export type MethodVisibility = FieldVisibility;
5
5
  export interface ParameterInfo {
6
6
  name: string;
7
7
  type: string | null;
8
+ /** Full type text including generic/template args (e.g. 'vector<int>', 'List<String>').
9
+ * Used by typeTagForId for overload disambiguation where generic args matter.
10
+ * Falls back to `type` when not set. */
11
+ rawType?: string | null;
8
12
  isOptional: boolean;
9
13
  isVariadic: boolean;
10
14
  }
@@ -21,6 +25,7 @@ export interface MethodInfo {
21
25
  isOverride?: boolean;
22
26
  isAsync?: boolean;
23
27
  isPartial?: boolean;
28
+ isConst?: boolean;
24
29
  annotations: string[];
25
30
  sourceFile: string;
26
31
  line: number;
@@ -37,6 +42,17 @@ export interface MethodExtractor {
37
42
  language: SupportedLanguages;
38
43
  extract(node: SyntaxNode, context: MethodExtractorContext): ExtractedMethods | null;
39
44
  isTypeDeclaration(node: SyntaxNode): boolean;
45
+ /** Extract method info from a standalone method node (e.g. Go top-level method_declaration). */
46
+ extractFromNode?(node: SyntaxNode, context: MethodExtractorContext): MethodInfo | null;
47
+ /** Extract function name + label from an AST node during parent-walk.
48
+ * Languages with non-standard AST structures (e.g. C/C++ declarator
49
+ * unwrapping, Swift init/deinit, Rust impl_item) provide this hook
50
+ * to replace the generic name-field lookup.
51
+ * Return null to fall through to the generic extractor. */
52
+ extractFunctionName?(node: SyntaxNode): {
53
+ funcName: string | null;
54
+ label: import('../../_shared/index.js').NodeLabel;
55
+ } | null;
40
56
  }
41
57
  export interface MethodExtractionConfig {
42
58
  language: SupportedLanguages;
@@ -56,6 +72,15 @@ export interface MethodExtractionConfig {
56
72
  isOverride?: (node: SyntaxNode) => boolean;
57
73
  isAsync?: (node: SyntaxNode) => boolean;
58
74
  isPartial?: (node: SyntaxNode) => boolean;
75
+ isConst?: (node: SyntaxNode) => boolean;
76
+ /** Resolve the owner name from a standalone method node (e.g. Go receiver type). */
77
+ extractOwnerName?: (node: SyntaxNode) => string | undefined;
59
78
  /** Extract a primary constructor from the owner node itself (e.g. C# 12 class Point(int x, int y)). */
60
79
  extractPrimaryConstructor?: (ownerNode: SyntaxNode, context: MethodExtractorContext) => MethodInfo | null;
80
+ /** Extract function name + label from an AST node during parent-walk.
81
+ * Passed through to the MethodExtractor by createMethodExtractor. */
82
+ extractFunctionName?: (node: SyntaxNode) => {
83
+ funcName: string | null;
84
+ label: import('../../_shared/index.js').NodeLabel;
85
+ } | null;
61
86
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Field Registry
3
+ *
4
+ * Owner-scoped field/property index extracted from SymbolTable.
5
+ * Stores Property symbols keyed by `ownerNodeId\0fieldName` for O(1) lookup.
6
+ */
7
+ import type { SymbolDefinition } from './symbol-table.js';
8
+ export interface FieldRegistry {
9
+ /** Look up a field/property by its owning class nodeId and field name. */
10
+ lookupFieldByOwner(ownerNodeId: string, fieldName: string): SymbolDefinition | undefined;
11
+ }
12
+ export interface MutableFieldRegistry extends FieldRegistry {
13
+ /** Register a field/property under its owner. */
14
+ register(ownerNodeId: string, fieldName: string, def: SymbolDefinition): void;
15
+ /** Clear all entries. */
16
+ clear(): void;
17
+ }
18
+ export declare const createFieldRegistry: () => MutableFieldRegistry;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Field Registry
3
+ *
4
+ * Owner-scoped field/property index extracted from SymbolTable.
5
+ * Stores Property symbols keyed by `ownerNodeId\0fieldName` for O(1) lookup.
6
+ */
7
+ // ---------------------------------------------------------------------------
8
+ // Factory
9
+ // ---------------------------------------------------------------------------
10
+ export const createFieldRegistry = () => {
11
+ const fieldByOwner = new Map();
12
+ const lookupFieldByOwner = (ownerNodeId, fieldName) => {
13
+ return fieldByOwner.get(`${ownerNodeId}\0${fieldName}`);
14
+ };
15
+ const register = (ownerNodeId, fieldName, def) => {
16
+ fieldByOwner.set(`${ownerNodeId}\0${fieldName}`, def);
17
+ };
18
+ const clear = () => {
19
+ fieldByOwner.clear();
20
+ };
21
+ return { lookupFieldByOwner, register, clear };
22
+ };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Heritage Map
3
+ *
4
+ * Unified inheritance data structure built from accumulated
5
+ * {@link ExtractedHeritage} records **after all chunks complete** (between
6
+ * chunk processing and call resolution). Consumes `ExtractedHeritage[]` and
7
+ * resolves type names to nodeIds via `lookupClassByName`, NOT graph-edge
8
+ * queries.
9
+ *
10
+ * Combines two concerns:
11
+ * 1. **Parent/ancestor lookup** (MRO-aware method resolution)
12
+ * 2. **Implementor lookup** (interface dispatch — which files contain
13
+ * classes implementing a given interface)
14
+ */
15
+ import type { ResolutionContext } from './resolution-context.js';
16
+ import { type SupportedLanguages } from '../../../_shared/index.js';
17
+ export interface ExtractedHeritage {
18
+ filePath: string;
19
+ className: string;
20
+ parentName: string;
21
+ /** 'extends' | 'implements' | 'trait-impl' | 'include' | 'extend' | 'prepend' */
22
+ kind: string;
23
+ }
24
+ export interface HeritageResolutionStrategy {
25
+ /** If set and the parent name matches, force IMPLEMENTS even when the
26
+ * symbol is unresolved (e.g. `/^I[A-Z]/` for C# / Java). */
27
+ readonly interfaceNamePattern?: RegExp;
28
+ /** Fallback edge for unresolved parents when the name pattern doesn't
29
+ * match (Swift uses 'IMPLEMENTS' for protocol conformance). */
30
+ readonly defaultEdge: 'EXTENDS' | 'IMPLEMENTS';
31
+ }
32
+ /** Callback used by `buildHeritageMap` to look up the resolution strategy
33
+ * for a given language. Injected by callers so the model module doesn't
34
+ * depend on `../languages/index.js`. */
35
+ export type HeritageStrategyLookup = (lang: SupportedLanguages) => HeritageResolutionStrategy;
36
+ /**
37
+ * Determine whether a heritage.extends capture is actually an IMPLEMENTS
38
+ * relationship. Consults the symbol table first (authoritative — Tier 1 /
39
+ * Tier 2 resolution); falls back to the injected {@link HeritageResolutionStrategy}
40
+ * heuristics for external symbols not present in the graph.
41
+ */
42
+ export declare const resolveExtendsType: (parentName: string, currentFilePath: string, ctx: ResolutionContext, strategy: HeritageResolutionStrategy) => {
43
+ type: "EXTENDS" | "IMPLEMENTS";
44
+ idPrefix: string;
45
+ };
46
+ export interface HeritageMap {
47
+ /** Direct parents of `childNodeId` (extends + implements + trait-impl). */
48
+ getParents(childNodeId: string): string[];
49
+ /** Full ancestor chain (BFS, bounded depth, cycle-safe). */
50
+ getAncestors(childNodeId: string): string[];
51
+ /**
52
+ * File paths of classes that directly implement or extend-as-interface the
53
+ * given interface/abstract-class **name**. Replaces the standalone
54
+ * `ImplementorMap` — used by interface-dispatch in call resolution.
55
+ */
56
+ getImplementorFiles(interfaceName: string): ReadonlySet<string>;
57
+ }
58
+ /**
59
+ * Build a HeritageMap from accumulated ExtractedHeritage records.
60
+ *
61
+ * Resolves class/interface/struct/trait names to nodeIds via
62
+ * `ctx.model.types.lookupClassByName`. When a name resolves to multiple
63
+ * candidates, all are recorded (partial-class / cross-file scenario).
64
+ * Unresolvable names are silently skipped — a missing parent is better
65
+ * than a wrong edge.
66
+ *
67
+ * Also builds the implementor index (interface name → implementing file
68
+ * paths) used by interface-dispatch in call resolution.
69
+ */
70
+ export declare const buildHeritageMap: (heritage: readonly ExtractedHeritage[], ctx: ResolutionContext, getHeritageStrategy?: HeritageStrategyLookup) => HeritageMap;
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Heritage Map
3
+ *
4
+ * Unified inheritance data structure built from accumulated
5
+ * {@link ExtractedHeritage} records **after all chunks complete** (between
6
+ * chunk processing and call resolution). Consumes `ExtractedHeritage[]` and
7
+ * resolves type names to nodeIds via `lookupClassByName`, NOT graph-edge
8
+ * queries.
9
+ *
10
+ * Combines two concerns:
11
+ * 1. **Parent/ancestor lookup** (MRO-aware method resolution)
12
+ * 2. **Implementor lookup** (interface dispatch — which files contain
13
+ * classes implementing a given interface)
14
+ */
15
+ import { getLanguageFromFilename } from '../../../_shared/index.js';
16
+ /**
17
+ * Determine whether a heritage.extends capture is actually an IMPLEMENTS
18
+ * relationship. Consults the symbol table first (authoritative — Tier 1 /
19
+ * Tier 2 resolution); falls back to the injected {@link HeritageResolutionStrategy}
20
+ * heuristics for external symbols not present in the graph.
21
+ */
22
+ export const resolveExtendsType = (parentName, currentFilePath, ctx, strategy) => {
23
+ const resolved = ctx.resolve(parentName, currentFilePath);
24
+ if (resolved && resolved.candidates.length > 0) {
25
+ const isInterface = resolved.candidates[0].type === 'Interface';
26
+ return isInterface
27
+ ? { type: 'IMPLEMENTS', idPrefix: 'Interface' }
28
+ : { type: 'EXTENDS', idPrefix: 'Class' };
29
+ }
30
+ // Unresolved symbol — fall back to strategy heuristics.
31
+ if (strategy.interfaceNamePattern?.test(parentName)) {
32
+ return { type: 'IMPLEMENTS', idPrefix: 'Interface' };
33
+ }
34
+ if (strategy.defaultEdge === 'IMPLEMENTS') {
35
+ return { type: 'IMPLEMENTS', idPrefix: 'Interface' };
36
+ }
37
+ return { type: 'EXTENDS', idPrefix: 'Class' };
38
+ };
39
+ // ---------------------------------------------------------------------------
40
+ // Public types
41
+ // ---------------------------------------------------------------------------
42
+ /** Maximum ancestor chain depth to prevent runaway traversal. */
43
+ const MAX_ANCESTOR_DEPTH = 32;
44
+ /** Shared empty set returned when no implementors are found. */
45
+ const EMPTY_SET = new Set();
46
+ /** Default strategy used when `buildHeritageMap` is called without an
47
+ * explicit `getHeritageStrategy` callback — the fallback for a language
48
+ * whose provider sets no interface-name pattern and no non-default
49
+ * `heritageDefaultEdge`. */
50
+ const DEFAULT_HERITAGE_STRATEGY = { defaultEdge: 'EXTENDS' };
51
+ // ---------------------------------------------------------------------------
52
+ // Builder
53
+ // ---------------------------------------------------------------------------
54
+ /**
55
+ * Build a HeritageMap from accumulated ExtractedHeritage records.
56
+ *
57
+ * Resolves class/interface/struct/trait names to nodeIds via
58
+ * `ctx.model.types.lookupClassByName`. When a name resolves to multiple
59
+ * candidates, all are recorded (partial-class / cross-file scenario).
60
+ * Unresolvable names are silently skipped — a missing parent is better
61
+ * than a wrong edge.
62
+ *
63
+ * Also builds the implementor index (interface name → implementing file
64
+ * paths) used by interface-dispatch in call resolution.
65
+ */
66
+ export const buildHeritageMap = (heritage, ctx, getHeritageStrategy) => {
67
+ // childNodeId → Set<parentNodeId> (Set to deduplicate cross-chunk duplicates)
68
+ const directParents = new Map();
69
+ // interfaceName → Set<filePath> (implementor lookup for interface dispatch)
70
+ const implementorFiles = new Map();
71
+ for (const h of heritage) {
72
+ // ── Parent lookup (nodeId-based) ────────────────────────────────
73
+ const childDefs = ctx.model.types.lookupClassByName(h.className);
74
+ const parentDefs = ctx.model.types.lookupClassByName(h.parentName);
75
+ if (childDefs.length > 0 && parentDefs.length > 0) {
76
+ for (const child of childDefs) {
77
+ for (const parent of parentDefs) {
78
+ // Skip self-references
79
+ if (child.nodeId === parent.nodeId)
80
+ continue;
81
+ let parents = directParents.get(child.nodeId);
82
+ if (!parents) {
83
+ parents = new Set();
84
+ directParents.set(child.nodeId, parents);
85
+ }
86
+ parents.add(parent.nodeId);
87
+ }
88
+ }
89
+ }
90
+ // ── Implementor index (name-based) ──────────────────────────────
91
+ //
92
+ // Known limitation: Rust `kind: 'trait-impl'` entries are intentionally NOT
93
+ // added to the implementor index. Interface dispatch resolution currently
94
+ // does not traverse Rust trait objects, so recording them here would
95
+ // inflate the index without a consumer. Revisit if/when trait-object
96
+ // dispatch is added.
97
+ //
98
+ // Known limitation: `getImplementorFiles` is keyed by interface **name**
99
+ // (string), so two interfaces with the same unqualified name in different
100
+ // packages (e.g. `pkgA.IRepository` vs `pkgB.IRepository`) collide.
101
+ let isImpl = false;
102
+ if (h.kind === 'implements') {
103
+ isImpl = true;
104
+ }
105
+ else if (h.kind === 'extends') {
106
+ const lang = getLanguageFromFilename(h.filePath);
107
+ if (lang) {
108
+ const strategy = getHeritageStrategy?.(lang) ?? DEFAULT_HERITAGE_STRATEGY;
109
+ const { type } = resolveExtendsType(h.parentName, h.filePath, ctx, strategy);
110
+ isImpl = type === 'IMPLEMENTS';
111
+ }
112
+ }
113
+ if (isImpl) {
114
+ let files = implementorFiles.get(h.parentName);
115
+ if (!files) {
116
+ files = new Set();
117
+ implementorFiles.set(h.parentName, files);
118
+ }
119
+ files.add(h.filePath);
120
+ }
121
+ }
122
+ // --- Public API ---------------------------------------------------
123
+ const getParents = (childNodeId) => {
124
+ const parents = directParents.get(childNodeId);
125
+ return parents ? [...parents] : [];
126
+ };
127
+ const getAncestors = (childNodeId) => {
128
+ const result = [];
129
+ const visited = new Set();
130
+ visited.add(childNodeId); // prevent cycles through the start node
131
+ // BFS with bounded depth
132
+ let frontier = getParents(childNodeId);
133
+ let depth = 0;
134
+ while (frontier.length > 0 && depth < MAX_ANCESTOR_DEPTH) {
135
+ const nextFrontier = [];
136
+ for (const parentId of frontier) {
137
+ if (visited.has(parentId))
138
+ continue;
139
+ visited.add(parentId);
140
+ result.push(parentId);
141
+ // Expand parent's own parents for next level
142
+ const grandparents = directParents.get(parentId);
143
+ if (grandparents) {
144
+ for (const gp of grandparents) {
145
+ if (!visited.has(gp))
146
+ nextFrontier.push(gp);
147
+ }
148
+ }
149
+ }
150
+ frontier = nextFrontier;
151
+ depth++;
152
+ }
153
+ return result;
154
+ };
155
+ const getImplementorFiles = (interfaceName) => {
156
+ return implementorFiles.get(interfaceName) ?? EMPTY_SET;
157
+ };
158
+ return { getParents, getAncestors, getImplementorFiles };
159
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Semantic Model — public module surface.
3
+ *
4
+ * Barrel re-export for the `model/` module. Consumers outside `model/`
5
+ * should import from this file rather than reaching into individual
6
+ * registry files.
7
+ *
8
+ * The model is owner-scoped type/method/field knowledge layered above
9
+ * `SymbolTable`. File-indexed and name-keyed callable lookups stay in
10
+ * `SymbolTable` by design.
11
+ */
12
+ export { type SemanticModel, type MutableSemanticModel, createSemanticModel, } from './semantic-model.js';
13
+ export { type SymbolTableReader, type SymbolTableWriter, createSymbolTable, } from './symbol-table.js';
14
+ export { type TypeRegistry, type MutableTypeRegistry, createTypeRegistry, } from './type-registry.js';
15
+ export { type MethodRegistry, type MutableMethodRegistry, createMethodRegistry, } from './method-registry.js';
16
+ export { type FieldRegistry, type MutableFieldRegistry, createFieldRegistry, } from './field-registry.js';
17
+ export { lookupMethodByOwnerWithMRO } from './resolve.js';
18
+ export { type NamedImportBinding, type NamedImportMap, isFileInPackageDir, } from './resolution-context.js';
19
+ export { type ExtractedHeritage, type HeritageResolutionStrategy, type HeritageStrategyLookup, } from './heritage-map.js';
20
+ export { CALLABLE_ONLY_LABELS, INERT_LABELS, DISPATCH_LABELS, ALL_NODE_LABELS, type LabelBehavior, } from './registration-table.js';
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Semantic Model — public module surface.
3
+ *
4
+ * Barrel re-export for the `model/` module. Consumers outside `model/`
5
+ * should import from this file rather than reaching into individual
6
+ * registry files.
7
+ *
8
+ * The model is owner-scoped type/method/field knowledge layered above
9
+ * `SymbolTable`. File-indexed and name-keyed callable lookups stay in
10
+ * `SymbolTable` by design.
11
+ */
12
+ // Unified semantic model (factory + interfaces). SemanticModel is the
13
+ // top-level container and owns the file/callable SymbolTable as a
14
+ // nested `symbols` field.
15
+ export { createSemanticModel, } from './semantic-model.js';
16
+ // SymbolTable is exclusively owned by SemanticModel. Re-exported here
17
+ // for the rare caller that needs the file/callable interface in
18
+ // isolation (e.g. tests).
19
+ export { createSymbolTable, } from './symbol-table.js';
20
+ // Type registry (classes, structs, interfaces, enums, records, impls)
21
+ export { createTypeRegistry, } from './type-registry.js';
22
+ // Method registry (owner-scoped methods with arity-aware overload lookup)
23
+ export { createMethodRegistry, } from './method-registry.js';
24
+ // Field registry (owner-scoped fields/properties)
25
+ export { createFieldRegistry, } from './field-registry.js';
26
+ // MRO-aware method resolution (C3, first-wins, leftmost-base, implements-split,
27
+ // qualified-syntax). Pure function that depends only on the model + HeritageMap.
28
+ // `MroStrategy` itself lives in `gitnexus-shared`; re-exported here for
29
+ // consumers that reach model behavior through the barrel.
30
+ export { lookupMethodByOwnerWithMRO } from './resolve.js';
31
+ // Named-import types and package-dir helper. Re-exported so barrel
32
+ // consumers don't need to reach into a specific model file.
33
+ export { isFileInPackageDir, } from './resolution-context.js';
34
+ // Behavior-grouped dispatch table for SymbolTable.add() routing.
35
+ // See registration-table.ts module JSDoc for the behavior group taxonomy
36
+ // and "how to add a new NodeLabel" checklist.
37
+ // NOTE: createRegistrationTable, RegistrationHook, and RegistrationTableDeps
38
+ // are deliberately NOT re-exported here — they are factory internals of
39
+ // SemanticModel and should only be imported directly from registration-table.js
40
+ // by semantic-model.ts and the registration-table.test.ts file.
41
+ export { CALLABLE_ONLY_LABELS, INERT_LABELS, DISPATCH_LABELS, ALL_NODE_LABELS, } from './registration-table.js';
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Method Registry
3
+ *
4
+ * Owner-scoped method index extracted from SymbolTable.
5
+ * Stores Method/Constructor/Function-with-ownerId symbols keyed by
6
+ * `ownerNodeId\0methodName` for O(1) lookup. Supports overloads
7
+ * (array values) and arity-based filtering.
8
+ */
9
+ import type { SymbolDefinition } from './symbol-table.js';
10
+ export interface MethodRegistry {
11
+ /**
12
+ * Look up a method by owner class + name, optionally filtered by arity.
13
+ *
14
+ * When `argCount` is provided, overloads whose parameter count doesn't
15
+ * accommodate the call's argument count are filtered out before the
16
+ * returnType dedup runs. This lets D0 (`resolveMemberCall`) disambiguate
17
+ * arity-differing overloads (e.g. C++ `greet()` vs `greet(string)`) that
18
+ * would otherwise collide on the shared `ownerId + methodName` key.
19
+ *
20
+ * Same-arity, same-returnType overloads (e.g. `save(int)` vs `save(String)`,
21
+ * both returning `void`) still collapse to the first match — callers must
22
+ * gate D0 on overload concern before invoking this function for that case.
23
+ */
24
+ lookupMethodByOwner(ownerNodeId: string, methodName: string, argCount?: number): SymbolDefinition | undefined;
25
+ /**
26
+ * Flat-by-name lookup across all owners. Returns every method registered
27
+ * with the given unqualified name, in registration order, accumulated
28
+ * across owners and overloads.
29
+ *
30
+ * Required by Tier 3 global resolution: Method and Constructor do not
31
+ * land in `SymbolTable.callableByName`, so Tier 3 reaches them through
32
+ * this flat index instead. Returns `[]` on miss — never `undefined` —
33
+ * so callers can concatenate without null checks.
34
+ *
35
+ * Reference identity: each returned def is the same object reference
36
+ * stored under `lookupMethodByOwner`, so a method symbol occupies one
37
+ * allocation reachable from two indexes.
38
+ */
39
+ lookupMethodByName(name: string): readonly SymbolDefinition[];
40
+ /**
41
+ * True iff at least one registered def has `type === 'Function'` — i.e.,
42
+ * a Python/Rust/Kotlin class method emitted by the worker as
43
+ * `Function + ownerId` rather than as a strict `Method` label. Such defs
44
+ * are double-indexed: they land in `SymbolTable.callableByName` (via the
45
+ * Function callable-index gate) AND in this registry (via the
46
+ * dispatch-key normalization in `wrappedAdd`). Tier 3 resolution must
47
+ * then dedup the two indexes by nodeId.
48
+ *
49
+ * When this flag is false, the callable and method indexes are
50
+ * guaranteed disjoint and Tier 3 can skip the dedup pass entirely.
51
+ * The flag is monotonic (false→true once, never back) for the lifetime
52
+ * of the MethodRegistry.
53
+ */
54
+ readonly hasFunctionMethods: boolean;
55
+ }
56
+ export interface MutableMethodRegistry extends MethodRegistry {
57
+ /** Register a method under its owner. Supports multiple overloads. */
58
+ register(ownerNodeId: string, methodName: string, def: SymbolDefinition): void;
59
+ /** Clear all entries. */
60
+ clear(): void;
61
+ }
62
+ export declare const createMethodRegistry: () => MutableMethodRegistry;