@zuvia-software-solutions/code-mapper 1.4.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 (213) hide show
  1. package/README.md +215 -0
  2. package/dist/cli/ai-context.d.ts +19 -0
  3. package/dist/cli/ai-context.js +168 -0
  4. package/dist/cli/analyze.d.ts +7 -0
  5. package/dist/cli/analyze.js +325 -0
  6. package/dist/cli/augment.d.ts +7 -0
  7. package/dist/cli/augment.js +27 -0
  8. package/dist/cli/clean.d.ts +5 -0
  9. package/dist/cli/clean.js +56 -0
  10. package/dist/cli/eval-server.d.ts +25 -0
  11. package/dist/cli/eval-server.js +365 -0
  12. package/dist/cli/index.d.ts +6 -0
  13. package/dist/cli/index.js +102 -0
  14. package/dist/cli/lazy-action.d.ts +6 -0
  15. package/dist/cli/lazy-action.js +19 -0
  16. package/dist/cli/list.d.ts +2 -0
  17. package/dist/cli/list.js +27 -0
  18. package/dist/cli/mcp.d.ts +8 -0
  19. package/dist/cli/mcp.js +35 -0
  20. package/dist/cli/refresh.d.ts +12 -0
  21. package/dist/cli/refresh.js +165 -0
  22. package/dist/cli/serve.d.ts +5 -0
  23. package/dist/cli/serve.js +8 -0
  24. package/dist/cli/setup.d.ts +6 -0
  25. package/dist/cli/setup.js +218 -0
  26. package/dist/cli/status.d.ts +2 -0
  27. package/dist/cli/status.js +33 -0
  28. package/dist/cli/tool.d.ts +28 -0
  29. package/dist/cli/tool.js +87 -0
  30. package/dist/config/ignore-service.d.ts +32 -0
  31. package/dist/config/ignore-service.js +282 -0
  32. package/dist/config/supported-languages.d.ts +23 -0
  33. package/dist/config/supported-languages.js +52 -0
  34. package/dist/core/augmentation/engine.d.ts +22 -0
  35. package/dist/core/augmentation/engine.js +232 -0
  36. package/dist/core/embeddings/embedder.d.ts +35 -0
  37. package/dist/core/embeddings/embedder.js +171 -0
  38. package/dist/core/embeddings/embedding-pipeline.d.ts +41 -0
  39. package/dist/core/embeddings/embedding-pipeline.js +402 -0
  40. package/dist/core/embeddings/index.d.ts +5 -0
  41. package/dist/core/embeddings/index.js +6 -0
  42. package/dist/core/embeddings/text-generator.d.ts +20 -0
  43. package/dist/core/embeddings/text-generator.js +159 -0
  44. package/dist/core/embeddings/types.d.ts +60 -0
  45. package/dist/core/embeddings/types.js +23 -0
  46. package/dist/core/graph/graph.d.ts +4 -0
  47. package/dist/core/graph/graph.js +65 -0
  48. package/dist/core/graph/types.d.ts +69 -0
  49. package/dist/core/graph/types.js +3 -0
  50. package/dist/core/incremental/child-process.d.ts +8 -0
  51. package/dist/core/incremental/child-process.js +649 -0
  52. package/dist/core/incremental/refresh-coordinator.d.ts +32 -0
  53. package/dist/core/incremental/refresh-coordinator.js +147 -0
  54. package/dist/core/incremental/types.d.ts +78 -0
  55. package/dist/core/incremental/types.js +153 -0
  56. package/dist/core/incremental/watcher.d.ts +63 -0
  57. package/dist/core/incremental/watcher.js +338 -0
  58. package/dist/core/ingestion/ast-cache.d.ts +12 -0
  59. package/dist/core/ingestion/ast-cache.js +34 -0
  60. package/dist/core/ingestion/call-processor.d.ts +34 -0
  61. package/dist/core/ingestion/call-processor.js +937 -0
  62. package/dist/core/ingestion/call-routing.d.ts +40 -0
  63. package/dist/core/ingestion/call-routing.js +97 -0
  64. package/dist/core/ingestion/cluster-enricher.d.ts +30 -0
  65. package/dist/core/ingestion/cluster-enricher.js +151 -0
  66. package/dist/core/ingestion/community-processor.d.ts +26 -0
  67. package/dist/core/ingestion/community-processor.js +272 -0
  68. package/dist/core/ingestion/constants.d.ts +5 -0
  69. package/dist/core/ingestion/constants.js +8 -0
  70. package/dist/core/ingestion/entry-point-scoring.d.ts +23 -0
  71. package/dist/core/ingestion/entry-point-scoring.js +317 -0
  72. package/dist/core/ingestion/export-detection.d.ts +11 -0
  73. package/dist/core/ingestion/export-detection.js +203 -0
  74. package/dist/core/ingestion/filesystem-walker.d.ts +18 -0
  75. package/dist/core/ingestion/filesystem-walker.js +64 -0
  76. package/dist/core/ingestion/framework-detection.d.ts +42 -0
  77. package/dist/core/ingestion/framework-detection.js +405 -0
  78. package/dist/core/ingestion/heritage-processor.d.ts +15 -0
  79. package/dist/core/ingestion/heritage-processor.js +237 -0
  80. package/dist/core/ingestion/import-processor.d.ts +31 -0
  81. package/dist/core/ingestion/import-processor.js +416 -0
  82. package/dist/core/ingestion/language-config.d.ts +32 -0
  83. package/dist/core/ingestion/language-config.js +161 -0
  84. package/dist/core/ingestion/mro-processor.d.ts +32 -0
  85. package/dist/core/ingestion/mro-processor.js +343 -0
  86. package/dist/core/ingestion/named-binding-extraction.d.ts +51 -0
  87. package/dist/core/ingestion/named-binding-extraction.js +343 -0
  88. package/dist/core/ingestion/parsing-processor.d.ts +20 -0
  89. package/dist/core/ingestion/parsing-processor.js +282 -0
  90. package/dist/core/ingestion/pipeline.d.ts +3 -0
  91. package/dist/core/ingestion/pipeline.js +416 -0
  92. package/dist/core/ingestion/process-processor.d.ts +42 -0
  93. package/dist/core/ingestion/process-processor.js +357 -0
  94. package/dist/core/ingestion/resolution-context.d.ts +40 -0
  95. package/dist/core/ingestion/resolution-context.js +171 -0
  96. package/dist/core/ingestion/resolvers/csharp.d.ts +10 -0
  97. package/dist/core/ingestion/resolvers/csharp.js +101 -0
  98. package/dist/core/ingestion/resolvers/go.d.ts +8 -0
  99. package/dist/core/ingestion/resolvers/go.js +33 -0
  100. package/dist/core/ingestion/resolvers/index.d.ts +14 -0
  101. package/dist/core/ingestion/resolvers/index.js +10 -0
  102. package/dist/core/ingestion/resolvers/jvm.d.ts +9 -0
  103. package/dist/core/ingestion/resolvers/jvm.js +74 -0
  104. package/dist/core/ingestion/resolvers/php.d.ts +7 -0
  105. package/dist/core/ingestion/resolvers/php.js +30 -0
  106. package/dist/core/ingestion/resolvers/ruby.d.ts +9 -0
  107. package/dist/core/ingestion/resolvers/ruby.js +13 -0
  108. package/dist/core/ingestion/resolvers/rust.d.ts +5 -0
  109. package/dist/core/ingestion/resolvers/rust.js +62 -0
  110. package/dist/core/ingestion/resolvers/standard.d.ts +16 -0
  111. package/dist/core/ingestion/resolvers/standard.js +144 -0
  112. package/dist/core/ingestion/resolvers/utils.d.ts +18 -0
  113. package/dist/core/ingestion/resolvers/utils.js +113 -0
  114. package/dist/core/ingestion/structure-processor.d.ts +4 -0
  115. package/dist/core/ingestion/structure-processor.js +39 -0
  116. package/dist/core/ingestion/symbol-table.d.ts +34 -0
  117. package/dist/core/ingestion/symbol-table.js +48 -0
  118. package/dist/core/ingestion/tree-sitter-queries.d.ts +20 -0
  119. package/dist/core/ingestion/tree-sitter-queries.js +691 -0
  120. package/dist/core/ingestion/type-env.d.ts +52 -0
  121. package/dist/core/ingestion/type-env.js +349 -0
  122. package/dist/core/ingestion/type-extractors/c-cpp.d.ts +4 -0
  123. package/dist/core/ingestion/type-extractors/c-cpp.js +214 -0
  124. package/dist/core/ingestion/type-extractors/csharp.d.ts +4 -0
  125. package/dist/core/ingestion/type-extractors/csharp.js +224 -0
  126. package/dist/core/ingestion/type-extractors/go.d.ts +4 -0
  127. package/dist/core/ingestion/type-extractors/go.js +261 -0
  128. package/dist/core/ingestion/type-extractors/index.d.ts +20 -0
  129. package/dist/core/ingestion/type-extractors/index.js +30 -0
  130. package/dist/core/ingestion/type-extractors/jvm.d.ts +5 -0
  131. package/dist/core/ingestion/type-extractors/jvm.js +386 -0
  132. package/dist/core/ingestion/type-extractors/php.d.ts +4 -0
  133. package/dist/core/ingestion/type-extractors/php.js +280 -0
  134. package/dist/core/ingestion/type-extractors/python.d.ts +4 -0
  135. package/dist/core/ingestion/type-extractors/python.js +175 -0
  136. package/dist/core/ingestion/type-extractors/ruby.d.ts +12 -0
  137. package/dist/core/ingestion/type-extractors/ruby.js +218 -0
  138. package/dist/core/ingestion/type-extractors/rust.d.ts +4 -0
  139. package/dist/core/ingestion/type-extractors/rust.js +290 -0
  140. package/dist/core/ingestion/type-extractors/shared.d.ts +81 -0
  141. package/dist/core/ingestion/type-extractors/shared.js +322 -0
  142. package/dist/core/ingestion/type-extractors/swift.d.ts +4 -0
  143. package/dist/core/ingestion/type-extractors/swift.js +140 -0
  144. package/dist/core/ingestion/type-extractors/types.d.ts +111 -0
  145. package/dist/core/ingestion/type-extractors/types.js +4 -0
  146. package/dist/core/ingestion/type-extractors/typescript.d.ts +4 -0
  147. package/dist/core/ingestion/type-extractors/typescript.js +227 -0
  148. package/dist/core/ingestion/utils.d.ts +73 -0
  149. package/dist/core/ingestion/utils.js +992 -0
  150. package/dist/core/ingestion/workers/parse-worker.d.ts +99 -0
  151. package/dist/core/ingestion/workers/parse-worker.js +1055 -0
  152. package/dist/core/ingestion/workers/worker-pool.d.ts +15 -0
  153. package/dist/core/ingestion/workers/worker-pool.js +123 -0
  154. package/dist/core/lbug/csv-generator.d.ts +28 -0
  155. package/dist/core/lbug/csv-generator.js +355 -0
  156. package/dist/core/lbug/lbug-adapter.d.ts +96 -0
  157. package/dist/core/lbug/lbug-adapter.js +753 -0
  158. package/dist/core/lbug/schema.d.ts +46 -0
  159. package/dist/core/lbug/schema.js +402 -0
  160. package/dist/core/search/bm25-index.d.ts +20 -0
  161. package/dist/core/search/bm25-index.js +123 -0
  162. package/dist/core/search/hybrid-search.d.ts +32 -0
  163. package/dist/core/search/hybrid-search.js +131 -0
  164. package/dist/core/search/query-cache.d.ts +18 -0
  165. package/dist/core/search/query-cache.js +47 -0
  166. package/dist/core/search/query-expansion.d.ts +19 -0
  167. package/dist/core/search/query-expansion.js +75 -0
  168. package/dist/core/search/reranker.d.ts +29 -0
  169. package/dist/core/search/reranker.js +122 -0
  170. package/dist/core/search/types.d.ts +154 -0
  171. package/dist/core/search/types.js +51 -0
  172. package/dist/core/semantic/tsgo-service.d.ts +67 -0
  173. package/dist/core/semantic/tsgo-service.js +355 -0
  174. package/dist/core/tree-sitter/parser-loader.d.ts +12 -0
  175. package/dist/core/tree-sitter/parser-loader.js +71 -0
  176. package/dist/lib/memory-guard.d.ts +35 -0
  177. package/dist/lib/memory-guard.js +70 -0
  178. package/dist/lib/utils.d.ts +3 -0
  179. package/dist/lib/utils.js +6 -0
  180. package/dist/mcp/compatible-stdio-transport.d.ts +32 -0
  181. package/dist/mcp/compatible-stdio-transport.js +209 -0
  182. package/dist/mcp/core/embedder.d.ts +24 -0
  183. package/dist/mcp/core/embedder.js +168 -0
  184. package/dist/mcp/core/lbug-adapter.d.ts +29 -0
  185. package/dist/mcp/core/lbug-adapter.js +330 -0
  186. package/dist/mcp/local/local-backend.d.ts +188 -0
  187. package/dist/mcp/local/local-backend.js +2759 -0
  188. package/dist/mcp/resources.d.ts +22 -0
  189. package/dist/mcp/resources.js +379 -0
  190. package/dist/mcp/server.d.ts +10 -0
  191. package/dist/mcp/server.js +217 -0
  192. package/dist/mcp/staleness.d.ts +10 -0
  193. package/dist/mcp/staleness.js +25 -0
  194. package/dist/mcp/tools.d.ts +21 -0
  195. package/dist/mcp/tools.js +202 -0
  196. package/dist/server/api.d.ts +5 -0
  197. package/dist/server/api.js +340 -0
  198. package/dist/server/mcp-http.d.ts +7 -0
  199. package/dist/server/mcp-http.js +95 -0
  200. package/dist/storage/git.d.ts +6 -0
  201. package/dist/storage/git.js +35 -0
  202. package/dist/storage/repo-manager.d.ts +87 -0
  203. package/dist/storage/repo-manager.js +249 -0
  204. package/dist/types/pipeline.d.ts +35 -0
  205. package/dist/types/pipeline.js +20 -0
  206. package/hooks/claude/code-mapper-hook.cjs +238 -0
  207. package/hooks/claude/pre-tool-use.sh +79 -0
  208. package/hooks/claude/session-start.sh +42 -0
  209. package/models/mlx-embedder.py +185 -0
  210. package/package.json +100 -0
  211. package/scripts/patch-tree-sitter-swift.cjs +74 -0
  212. package/vendor/leiden/index.cjs +355 -0
  213. package/vendor/leiden/utils.cjs +392 -0
@@ -0,0 +1,691 @@
1
+ // code-mapper/src/core/ingestion/tree-sitter-queries.ts
2
+ /**
3
+ * @file Tree-sitter S-expression queries for extracting definitions, imports, calls, and heritage
4
+ * @description Queries are designed for compatibility across standard tree-sitter grammars;
5
+ * some grammars (typescript vs tsx vs javascript) have slightly different node types
6
+ */
7
+ import { SupportedLanguages } from '../../config/supported-languages.js';
8
+ // TypeScript queries (tree-sitter-typescript)
9
+ export const TYPESCRIPT_QUERIES = `
10
+ (class_declaration
11
+ name: (type_identifier) @name) @definition.class
12
+
13
+ (interface_declaration
14
+ name: (type_identifier) @name) @definition.interface
15
+
16
+ (function_declaration
17
+ name: (identifier) @name) @definition.function
18
+
19
+ (method_definition
20
+ name: (property_identifier) @name) @definition.method
21
+
22
+ (lexical_declaration
23
+ (variable_declarator
24
+ name: (identifier) @name
25
+ value: (arrow_function))) @definition.function
26
+
27
+ (lexical_declaration
28
+ (variable_declarator
29
+ name: (identifier) @name
30
+ value: (function_expression))) @definition.function
31
+
32
+ (export_statement
33
+ declaration: (lexical_declaration
34
+ (variable_declarator
35
+ name: (identifier) @name
36
+ value: (arrow_function)))) @definition.function
37
+
38
+ (export_statement
39
+ declaration: (lexical_declaration
40
+ (variable_declarator
41
+ name: (identifier) @name
42
+ value: (function_expression)))) @definition.function
43
+
44
+ (import_statement
45
+ source: (string) @import.source) @import
46
+
47
+ ; Re-export statements: export { X } from './y'
48
+ (export_statement
49
+ source: (string) @import.source) @import
50
+
51
+ (call_expression
52
+ function: (identifier) @call.name) @call
53
+
54
+ (call_expression
55
+ function: (member_expression
56
+ property: (property_identifier) @call.name)) @call
57
+
58
+ ; B3: Dynamic import calls: const { foo } = await import('./module.js')
59
+ (call_expression
60
+ function: (import) @call.name) @call
61
+
62
+ ; Constructor calls: new Foo()
63
+ (new_expression
64
+ constructor: (identifier) @call.name) @call
65
+
66
+ ; Heritage queries - class extends
67
+ (class_declaration
68
+ name: (type_identifier) @heritage.class
69
+ (class_heritage
70
+ (extends_clause
71
+ value: (identifier) @heritage.extends))) @heritage
72
+
73
+ ; Heritage queries - class implements interface
74
+ (class_declaration
75
+ name: (type_identifier) @heritage.class
76
+ (class_heritage
77
+ (implements_clause
78
+ (type_identifier) @heritage.implements))) @heritage.impl
79
+ `;
80
+ // JavaScript queries (tree-sitter-javascript)
81
+ export const JAVASCRIPT_QUERIES = `
82
+ (class_declaration
83
+ name: (identifier) @name) @definition.class
84
+
85
+ (function_declaration
86
+ name: (identifier) @name) @definition.function
87
+
88
+ (method_definition
89
+ name: (property_identifier) @name) @definition.method
90
+
91
+ (lexical_declaration
92
+ (variable_declarator
93
+ name: (identifier) @name
94
+ value: (arrow_function))) @definition.function
95
+
96
+ (lexical_declaration
97
+ (variable_declarator
98
+ name: (identifier) @name
99
+ value: (function_expression))) @definition.function
100
+
101
+ (export_statement
102
+ declaration: (lexical_declaration
103
+ (variable_declarator
104
+ name: (identifier) @name
105
+ value: (arrow_function)))) @definition.function
106
+
107
+ (export_statement
108
+ declaration: (lexical_declaration
109
+ (variable_declarator
110
+ name: (identifier) @name
111
+ value: (function_expression)))) @definition.function
112
+
113
+ (import_statement
114
+ source: (string) @import.source) @import
115
+
116
+ ; Re-export statements: export { X } from './y'
117
+ (export_statement
118
+ source: (string) @import.source) @import
119
+
120
+ (call_expression
121
+ function: (identifier) @call.name) @call
122
+
123
+ (call_expression
124
+ function: (member_expression
125
+ property: (property_identifier) @call.name)) @call
126
+
127
+ ; B3: Dynamic import calls: const { foo } = await import('./module.js')
128
+ (call_expression
129
+ function: (import) @call.name) @call
130
+
131
+ ; Constructor calls: new Foo()
132
+ (new_expression
133
+ constructor: (identifier) @call.name) @call
134
+
135
+ ; Heritage queries - class extends (JavaScript uses different AST than TypeScript)
136
+ ; In tree-sitter-javascript, class_heritage directly contains the parent identifier
137
+ (class_declaration
138
+ name: (identifier) @heritage.class
139
+ (class_heritage
140
+ (identifier) @heritage.extends)) @heritage
141
+ `;
142
+ // Python queries (tree-sitter-python)
143
+ export const PYTHON_QUERIES = `
144
+ (class_definition
145
+ name: (identifier) @name) @definition.class
146
+
147
+ (function_definition
148
+ name: (identifier) @name) @definition.function
149
+
150
+ (import_statement
151
+ name: (dotted_name) @import.source) @import
152
+
153
+ (import_from_statement
154
+ module_name: (dotted_name) @import.source) @import
155
+
156
+ (import_from_statement
157
+ module_name: (relative_import) @import.source) @import
158
+
159
+ (call
160
+ function: (identifier) @call.name) @call
161
+
162
+ (call
163
+ function: (attribute
164
+ attribute: (identifier) @call.name)) @call
165
+
166
+ ; Heritage queries - Python class inheritance
167
+ (class_definition
168
+ name: (identifier) @heritage.class
169
+ superclasses: (argument_list
170
+ (identifier) @heritage.extends)) @heritage
171
+ `;
172
+ // Java queries (tree-sitter-java)
173
+ export const JAVA_QUERIES = `
174
+ ; Classes, Interfaces, Enums, Annotations
175
+ (class_declaration name: (identifier) @name) @definition.class
176
+ (interface_declaration name: (identifier) @name) @definition.interface
177
+ (enum_declaration name: (identifier) @name) @definition.enum
178
+ (annotation_type_declaration name: (identifier) @name) @definition.annotation
179
+
180
+ ; Methods & Constructors
181
+ (method_declaration name: (identifier) @name) @definition.method
182
+ (constructor_declaration name: (identifier) @name) @definition.constructor
183
+
184
+ ; Imports - capture any import declaration child as source
185
+ (import_declaration (_) @import.source) @import
186
+
187
+ ; Calls
188
+ (method_invocation name: (identifier) @call.name) @call
189
+ (method_invocation object: (_) name: (identifier) @call.name) @call
190
+
191
+ ; Constructor calls: new Foo()
192
+ (object_creation_expression type: (type_identifier) @call.name) @call
193
+
194
+ ; Heritage - extends class
195
+ (class_declaration name: (identifier) @heritage.class
196
+ (superclass (type_identifier) @heritage.extends)) @heritage
197
+
198
+ ; Heritage - implements interfaces
199
+ (class_declaration name: (identifier) @heritage.class
200
+ (super_interfaces (type_list (type_identifier) @heritage.implements))) @heritage.impl
201
+ `;
202
+ // C queries (tree-sitter-c)
203
+ export const C_QUERIES = `
204
+ ; Functions (direct declarator)
205
+ (function_definition declarator: (function_declarator declarator: (identifier) @name)) @definition.function
206
+ (declaration declarator: (function_declarator declarator: (identifier) @name)) @definition.function
207
+
208
+ ; Functions returning pointers (pointer_declarator wraps function_declarator)
209
+ (function_definition declarator: (pointer_declarator declarator: (function_declarator declarator: (identifier) @name))) @definition.function
210
+ (declaration declarator: (pointer_declarator declarator: (function_declarator declarator: (identifier) @name))) @definition.function
211
+
212
+ ; Functions returning double pointers (nested pointer_declarator)
213
+ (function_definition declarator: (pointer_declarator declarator: (pointer_declarator declarator: (function_declarator declarator: (identifier) @name)))) @definition.function
214
+
215
+ ; Structs, Unions, Enums, Typedefs
216
+ (struct_specifier name: (type_identifier) @name) @definition.struct
217
+ (union_specifier name: (type_identifier) @name) @definition.union
218
+ (enum_specifier name: (type_identifier) @name) @definition.enum
219
+ (type_definition declarator: (type_identifier) @name) @definition.typedef
220
+
221
+ ; Macros
222
+ (preproc_function_def name: (identifier) @name) @definition.macro
223
+ (preproc_def name: (identifier) @name) @definition.macro
224
+
225
+ ; Includes
226
+ (preproc_include path: (_) @import.source) @import
227
+
228
+ ; Calls
229
+ (call_expression function: (identifier) @call.name) @call
230
+ (call_expression function: (field_expression field: (field_identifier) @call.name)) @call
231
+ `;
232
+ // Go queries (tree-sitter-go)
233
+ export const GO_QUERIES = `
234
+ ; Functions & Methods
235
+ (function_declaration name: (identifier) @name) @definition.function
236
+ (method_declaration name: (field_identifier) @name) @definition.method
237
+
238
+ ; Types
239
+ (type_declaration (type_spec name: (type_identifier) @name type: (struct_type))) @definition.struct
240
+ (type_declaration (type_spec name: (type_identifier) @name type: (interface_type))) @definition.interface
241
+
242
+ ; Imports
243
+ (import_declaration (import_spec path: (interpreted_string_literal) @import.source)) @import
244
+ (import_declaration (import_spec_list (import_spec path: (interpreted_string_literal) @import.source))) @import
245
+
246
+ ; Struct embedding (anonymous fields = inheritance)
247
+ (type_declaration
248
+ (type_spec
249
+ name: (type_identifier) @heritage.class
250
+ type: (struct_type
251
+ (field_declaration_list
252
+ (field_declaration
253
+ type: (type_identifier) @heritage.extends))))) @definition.struct
254
+
255
+ ; Calls
256
+ (call_expression function: (identifier) @call.name) @call
257
+ (call_expression function: (selector_expression field: (field_identifier) @call.name)) @call
258
+
259
+ ; Struct literal construction: User{Name: "Alice"}
260
+ (composite_literal type: (type_identifier) @call.name) @call
261
+ `;
262
+ // C++ queries (tree-sitter-cpp)
263
+ export const CPP_QUERIES = `
264
+ ; Classes, Structs, Namespaces
265
+ (class_specifier name: (type_identifier) @name) @definition.class
266
+ (struct_specifier name: (type_identifier) @name) @definition.struct
267
+ (namespace_definition name: (namespace_identifier) @name) @definition.namespace
268
+ (enum_specifier name: (type_identifier) @name) @definition.enum
269
+
270
+ ; Typedefs and unions (common in C-style headers and mixed C/C++ code)
271
+ (type_definition declarator: (type_identifier) @name) @definition.typedef
272
+ (union_specifier name: (type_identifier) @name) @definition.union
273
+
274
+ ; Macros
275
+ (preproc_function_def name: (identifier) @name) @definition.macro
276
+ (preproc_def name: (identifier) @name) @definition.macro
277
+
278
+ ; Functions & Methods (direct declarator)
279
+ (function_definition declarator: (function_declarator declarator: (identifier) @name)) @definition.function
280
+ (function_definition declarator: (function_declarator declarator: (qualified_identifier name: (identifier) @name))) @definition.method
281
+
282
+ ; Functions/methods returning pointers (pointer_declarator wraps function_declarator)
283
+ (function_definition declarator: (pointer_declarator declarator: (function_declarator declarator: (identifier) @name))) @definition.function
284
+ (function_definition declarator: (pointer_declarator declarator: (function_declarator declarator: (qualified_identifier name: (identifier) @name)))) @definition.method
285
+
286
+ ; Functions/methods returning double pointers (nested pointer_declarator)
287
+ (function_definition declarator: (pointer_declarator declarator: (pointer_declarator declarator: (function_declarator declarator: (identifier) @name)))) @definition.function
288
+ (function_definition declarator: (pointer_declarator declarator: (pointer_declarator declarator: (function_declarator declarator: (qualified_identifier name: (identifier) @name))))) @definition.method
289
+
290
+ ; Functions/methods returning references (reference_declarator wraps function_declarator)
291
+ (function_definition declarator: (reference_declarator (function_declarator declarator: (identifier) @name))) @definition.function
292
+ (function_definition declarator: (reference_declarator (function_declarator declarator: (qualified_identifier name: (identifier) @name)))) @definition.method
293
+
294
+ ; Destructors (destructor_name is distinct from identifier in tree-sitter-cpp)
295
+ (function_definition declarator: (function_declarator declarator: (qualified_identifier name: (destructor_name) @name))) @definition.method
296
+
297
+ ; Function declarations / prototypes (common in headers)
298
+ (declaration declarator: (function_declarator declarator: (identifier) @name)) @definition.function
299
+ (declaration declarator: (pointer_declarator declarator: (function_declarator declarator: (identifier) @name))) @definition.function
300
+
301
+ ; Inline class method declarations (inside class body, no body: void Foo();)
302
+ (field_declaration declarator: (function_declarator declarator: (identifier) @name)) @definition.method
303
+
304
+ ; Inline class method definitions (inside class body, with body: void Foo() { ... })
305
+ (field_declaration_list
306
+ (function_definition
307
+ declarator: (function_declarator
308
+ declarator: [(field_identifier) (identifier) (operator_name) (destructor_name)] @name)) @definition.method)
309
+
310
+ ; Templates
311
+ (template_declaration (class_specifier name: (type_identifier) @name)) @definition.template
312
+ (template_declaration (function_definition declarator: (function_declarator declarator: (identifier) @name))) @definition.template
313
+
314
+ ; Includes
315
+ (preproc_include path: (_) @import.source) @import
316
+
317
+ ; Calls
318
+ (call_expression function: (identifier) @call.name) @call
319
+ (call_expression function: (field_expression field: (field_identifier) @call.name)) @call
320
+ (call_expression function: (qualified_identifier name: (identifier) @call.name)) @call
321
+ (call_expression function: (template_function name: (identifier) @call.name)) @call
322
+
323
+ ; Constructor calls: new User()
324
+ (new_expression type: (type_identifier) @call.name) @call
325
+
326
+ ; Heritage
327
+ (class_specifier name: (type_identifier) @heritage.class
328
+ (base_class_clause (type_identifier) @heritage.extends)) @heritage
329
+ (class_specifier name: (type_identifier) @heritage.class
330
+ (base_class_clause (access_specifier) (type_identifier) @heritage.extends)) @heritage
331
+ `;
332
+ // C# queries (tree-sitter-c-sharp)
333
+ export const CSHARP_QUERIES = `
334
+ ; Types
335
+ (class_declaration name: (identifier) @name) @definition.class
336
+ (interface_declaration name: (identifier) @name) @definition.interface
337
+ (struct_declaration name: (identifier) @name) @definition.struct
338
+ (enum_declaration name: (identifier) @name) @definition.enum
339
+ (record_declaration name: (identifier) @name) @definition.record
340
+ (delegate_declaration name: (identifier) @name) @definition.delegate
341
+
342
+ ; Namespaces (block form and C# 10+ file-scoped form)
343
+ (namespace_declaration name: (identifier) @name) @definition.namespace
344
+ (namespace_declaration name: (qualified_name) @name) @definition.namespace
345
+ (file_scoped_namespace_declaration name: (identifier) @name) @definition.namespace
346
+ (file_scoped_namespace_declaration name: (qualified_name) @name) @definition.namespace
347
+
348
+ ; Methods & Properties
349
+ (method_declaration name: (identifier) @name) @definition.method
350
+ (local_function_statement name: (identifier) @name) @definition.function
351
+ (constructor_declaration name: (identifier) @name) @definition.constructor
352
+ (property_declaration name: (identifier) @name) @definition.property
353
+
354
+ ; Primary constructors (C# 12): class User(string name, int age) { }
355
+ (class_declaration name: (identifier) @name (parameter_list) @definition.constructor)
356
+ (record_declaration name: (identifier) @name (parameter_list) @definition.constructor)
357
+
358
+ ; Using
359
+ (using_directive (qualified_name) @import.source) @import
360
+ (using_directive (identifier) @import.source) @import
361
+
362
+ ; Calls
363
+ (invocation_expression function: (identifier) @call.name) @call
364
+ (invocation_expression function: (member_access_expression name: (identifier) @call.name)) @call
365
+
366
+ ; Null-conditional method calls: user?.Save()
367
+ ; Parses as: invocation_expression → conditional_access_expression → member_binding_expression → identifier
368
+ (invocation_expression
369
+ function: (conditional_access_expression
370
+ (member_binding_expression
371
+ (identifier) @call.name))) @call
372
+
373
+ ; Constructor calls: new Foo() and new Foo { Props }
374
+ (object_creation_expression type: (identifier) @call.name) @call
375
+
376
+ ; Target-typed new (C# 9): User u = new("x", 5)
377
+ (variable_declaration type: (identifier) @call.name (variable_declarator (implicit_object_creation_expression) @call))
378
+
379
+ ; Heritage
380
+ (class_declaration name: (identifier) @heritage.class
381
+ (base_list (identifier) @heritage.extends)) @heritage
382
+ (class_declaration name: (identifier) @heritage.class
383
+ (base_list (generic_name (identifier) @heritage.extends))) @heritage
384
+ `;
385
+ // Rust queries (tree-sitter-rust)
386
+ export const RUST_QUERIES = `
387
+ ; Functions & Items
388
+ (function_item name: (identifier) @name) @definition.function
389
+ (struct_item name: (type_identifier) @name) @definition.struct
390
+ (enum_item name: (type_identifier) @name) @definition.enum
391
+ (trait_item name: (type_identifier) @name) @definition.trait
392
+ (impl_item type: (type_identifier) @name !trait) @definition.impl
393
+ (impl_item type: (generic_type type: (type_identifier) @name) !trait) @definition.impl
394
+ (mod_item name: (identifier) @name) @definition.module
395
+
396
+ ; Type aliases, const, static, macros
397
+ (type_item name: (type_identifier) @name) @definition.type
398
+ (const_item name: (identifier) @name) @definition.const
399
+ (static_item name: (identifier) @name) @definition.static
400
+ (macro_definition name: (identifier) @name) @definition.macro
401
+
402
+ ; Use statements
403
+ (use_declaration argument: (_) @import.source) @import
404
+
405
+ ; Calls
406
+ (call_expression function: (identifier) @call.name) @call
407
+ (call_expression function: (field_expression field: (field_identifier) @call.name)) @call
408
+ (call_expression function: (scoped_identifier name: (identifier) @call.name)) @call
409
+ (call_expression function: (generic_function function: (identifier) @call.name)) @call
410
+
411
+ ; Struct literal construction: User { name: value }
412
+ (struct_expression name: (type_identifier) @call.name) @call
413
+
414
+ ; Heritage (trait implementation) — all combinations of concrete/generic trait × concrete/generic type
415
+ (impl_item trait: (type_identifier) @heritage.trait type: (type_identifier) @heritage.class) @heritage
416
+ (impl_item trait: (generic_type type: (type_identifier) @heritage.trait) type: (type_identifier) @heritage.class) @heritage
417
+ (impl_item trait: (type_identifier) @heritage.trait type: (generic_type type: (type_identifier) @heritage.class)) @heritage
418
+ (impl_item trait: (generic_type type: (type_identifier) @heritage.trait) type: (generic_type type: (type_identifier) @heritage.class)) @heritage
419
+ `;
420
+ // PHP queries (tree-sitter-php, php_only grammar)
421
+ export const PHP_QUERIES = `
422
+ ; ── Namespace ────────────────────────────────────────────────────────────────
423
+ (namespace_definition
424
+ name: (namespace_name) @name) @definition.namespace
425
+
426
+ ; ── Classes ──────────────────────────────────────────────────────────────────
427
+ (class_declaration
428
+ name: (name) @name) @definition.class
429
+
430
+ ; ── Interfaces ───────────────────────────────────────────────────────────────
431
+ (interface_declaration
432
+ name: (name) @name) @definition.interface
433
+
434
+ ; ── Traits ───────────────────────────────────────────────────────────────────
435
+ (trait_declaration
436
+ name: (name) @name) @definition.trait
437
+
438
+ ; ── Enums (PHP 8.1) ──────────────────────────────────────────────────────────
439
+ (enum_declaration
440
+ name: (name) @name) @definition.enum
441
+
442
+ ; ── Top-level functions ───────────────────────────────────────────────────────
443
+ (function_definition
444
+ name: (name) @name) @definition.function
445
+
446
+ ; ── Methods (including constructors) ─────────────────────────────────────────
447
+ (method_declaration
448
+ name: (name) @name) @definition.method
449
+
450
+ ; ── Class properties (including Eloquent $fillable, $casts, etc.) ────────────
451
+ (property_declaration
452
+ (property_element
453
+ (variable_name
454
+ (name) @name))) @definition.property
455
+
456
+ ; ── Imports: use statements ──────────────────────────────────────────────────
457
+ ; Simple: use App\\Models\\User;
458
+ (namespace_use_declaration
459
+ (namespace_use_clause
460
+ (qualified_name) @import.source)) @import
461
+
462
+ ; ── Function/method calls ────────────────────────────────────────────────────
463
+ ; Regular function call: foo()
464
+ (function_call_expression
465
+ function: (name) @call.name) @call
466
+
467
+ ; Method call: $obj->method()
468
+ (member_call_expression
469
+ name: (name) @call.name) @call
470
+
471
+ ; Nullsafe method call: $obj?->method()
472
+ (nullsafe_member_call_expression
473
+ name: (name) @call.name) @call
474
+
475
+ ; Static call: Foo::bar() (php_only uses scoped_call_expression)
476
+ (scoped_call_expression
477
+ name: (name) @call.name) @call
478
+
479
+ ; Constructor call: new User()
480
+ (object_creation_expression (name) @call.name) @call
481
+
482
+ ; ── Heritage: extends ────────────────────────────────────────────────────────
483
+ (class_declaration
484
+ name: (name) @heritage.class
485
+ (base_clause
486
+ [(name) (qualified_name)] @heritage.extends)) @heritage
487
+
488
+ ; ── Heritage: implements ─────────────────────────────────────────────────────
489
+ (class_declaration
490
+ name: (name) @heritage.class
491
+ (class_interface_clause
492
+ [(name) (qualified_name)] @heritage.implements)) @heritage.impl
493
+
494
+ ; ── Heritage: use trait (must capture enclosing class name) ──────────────────
495
+ (class_declaration
496
+ name: (name) @heritage.class
497
+ body: (declaration_list
498
+ (use_declaration
499
+ [(name) (qualified_name)] @heritage.trait))) @heritage
500
+ `;
501
+ // Ruby queries (tree-sitter-ruby)
502
+ // Ruby uses `call` for require, include, extend, prepend, attr_* etc
503
+ // All captured as @call and routed in JS post-processing
504
+ export const RUBY_QUERIES = `
505
+ ; ── Modules ──────────────────────────────────────────────────────────────────
506
+ (module
507
+ name: (constant) @name) @definition.module
508
+
509
+ ; ── Classes ──────────────────────────────────────────────────────────────────
510
+ (class
511
+ name: (constant) @name) @definition.class
512
+
513
+ ; ── Instance methods ─────────────────────────────────────────────────────────
514
+ (method
515
+ name: (identifier) @name) @definition.method
516
+
517
+ ; ── Singleton (class-level) methods ──────────────────────────────────────────
518
+ (singleton_method
519
+ name: (identifier) @name) @definition.method
520
+
521
+ ; ── All calls (require, include, attr_*, and regular calls routed in JS) ─────
522
+ (call
523
+ method: (identifier) @call.name) @call
524
+
525
+ ; ── Bare calls without parens (identifiers at statement level are method calls) ─
526
+ ; NOTE: This may over-capture variable reads as calls (e.g. 'result' at
527
+ ; statement level). Ruby's grammar makes bare identifiers ambiguous — they
528
+ ; could be local variables or zero-arity method calls. Post-processing via
529
+ ; isBuiltInOrNoise and symbol resolution filtering suppresses most false
530
+ ; positives, but a variable name that coincidentally matches a method name
531
+ ; elsewhere may produce a false CALLS edge.
532
+ (body_statement
533
+ (identifier) @call.name @call)
534
+
535
+ ; ── Heritage: class < SuperClass ─────────────────────────────────────────────
536
+ (class
537
+ name: (constant) @heritage.class
538
+ superclass: (superclass
539
+ (constant) @heritage.extends)) @heritage
540
+ `;
541
+ // Kotlin queries (fwcd/tree-sitter-kotlin)
542
+ // Based on official tags.scm; functions use simple_identifier, classes use type_identifier
543
+ export const KOTLIN_QUERIES = `
544
+ ; ── Interfaces ─────────────────────────────────────────────────────────────
545
+ ; tree-sitter-kotlin (fwcd) has no interface_declaration node type.
546
+ ; Interfaces are class_declaration nodes with an anonymous "interface" keyword child.
547
+ (class_declaration
548
+ "interface"
549
+ (type_identifier) @name) @definition.interface
550
+
551
+ ; ── Classes (regular, data, sealed, enum) ────────────────────────────────
552
+ ; All have the anonymous "class" keyword child. enum class has both
553
+ ; "enum" and "class" children — the "class" child still matches.
554
+ (class_declaration
555
+ "class"
556
+ (type_identifier) @name) @definition.class
557
+
558
+ ; ── Object declarations (Kotlin singletons) ──────────────────────────────
559
+ (object_declaration
560
+ (type_identifier) @name) @definition.class
561
+
562
+ ; ── Companion objects (named only) ───────────────────────────────────────
563
+ (companion_object
564
+ (type_identifier) @name) @definition.class
565
+
566
+ ; ── Functions (top-level, member, extension) ──────────────────────────────
567
+ (function_declaration
568
+ (simple_identifier) @name) @definition.function
569
+
570
+ ; ── Properties ───────────────────────────────────────────────────────────
571
+ (property_declaration
572
+ (variable_declaration
573
+ (simple_identifier) @name)) @definition.property
574
+
575
+ ; ── Enum entries ─────────────────────────────────────────────────────────
576
+ (enum_entry
577
+ (simple_identifier) @name) @definition.enum
578
+
579
+ ; ── Type aliases ─────────────────────────────────────────────────────────
580
+ (type_alias
581
+ (type_identifier) @name) @definition.type
582
+
583
+ ; ── Imports ──────────────────────────────────────────────────────────────
584
+ (import_header
585
+ (identifier) @import.source) @import
586
+
587
+ ; ── Function calls (direct) ──────────────────────────────────────────────
588
+ (call_expression
589
+ (simple_identifier) @call.name) @call
590
+
591
+ ; ── Method calls (via navigation: obj.method()) ──────────────────────────
592
+ (call_expression
593
+ (navigation_expression
594
+ (navigation_suffix
595
+ (simple_identifier) @call.name))) @call
596
+
597
+ ; ── Constructor invocations ──────────────────────────────────────────────
598
+ (constructor_invocation
599
+ (user_type
600
+ (type_identifier) @call.name)) @call
601
+
602
+ ; ── Infix function calls (e.g., a to b, x until y) ──────────────────────
603
+ (infix_expression
604
+ (simple_identifier) @call.name) @call
605
+
606
+ ; ── Heritage: extends / implements via delegation_specifier ──────────────
607
+ ; Interface implementation (bare user_type): class Foo : Bar
608
+ (class_declaration
609
+ (type_identifier) @heritage.class
610
+ (delegation_specifier
611
+ (user_type (type_identifier) @heritage.extends))) @heritage
612
+
613
+ ; Class extension (constructor_invocation): class Foo : Bar()
614
+ (class_declaration
615
+ (type_identifier) @heritage.class
616
+ (delegation_specifier
617
+ (constructor_invocation
618
+ (user_type (type_identifier) @heritage.extends)))) @heritage
619
+ `;
620
+ // Swift queries (tree-sitter-swift)
621
+ export const SWIFT_QUERIES = `
622
+ ; Classes
623
+ (class_declaration "class" name: (type_identifier) @name) @definition.class
624
+
625
+ ; Structs
626
+ (class_declaration "struct" name: (type_identifier) @name) @definition.struct
627
+
628
+ ; Enums
629
+ (class_declaration "enum" name: (type_identifier) @name) @definition.enum
630
+
631
+ ; Extensions (mapped to class — no dedicated label in schema)
632
+ (class_declaration "extension" name: (user_type (type_identifier) @name)) @definition.class
633
+
634
+ ; Actors
635
+ (class_declaration "actor" name: (type_identifier) @name) @definition.class
636
+
637
+ ; Protocols (mapped to interface)
638
+ (protocol_declaration name: (type_identifier) @name) @definition.interface
639
+
640
+ ; Type aliases
641
+ (typealias_declaration name: (type_identifier) @name) @definition.type
642
+
643
+ ; Functions (top-level and methods)
644
+ (function_declaration name: (simple_identifier) @name) @definition.function
645
+
646
+ ; Protocol method declarations
647
+ (protocol_function_declaration name: (simple_identifier) @name) @definition.method
648
+
649
+ ; Initializers
650
+ (init_declaration) @definition.constructor
651
+
652
+ ; Properties (stored and computed)
653
+ (property_declaration (pattern (simple_identifier) @name)) @definition.property
654
+
655
+ ; Imports
656
+ (import_declaration (identifier (simple_identifier) @import.source)) @import
657
+
658
+ ; Calls - direct function calls
659
+ (call_expression (simple_identifier) @call.name) @call
660
+
661
+ ; Calls - member/navigation calls (obj.method())
662
+ (call_expression (navigation_expression (navigation_suffix (simple_identifier) @call.name))) @call
663
+
664
+ ; Heritage - class/struct/enum inheritance and protocol conformance
665
+ (class_declaration name: (type_identifier) @heritage.class
666
+ (inheritance_specifier inherits_from: (user_type (type_identifier) @heritage.extends))) @heritage
667
+
668
+ ; Heritage - protocol inheritance
669
+ (protocol_declaration name: (type_identifier) @heritage.class
670
+ (inheritance_specifier inherits_from: (user_type (type_identifier) @heritage.extends))) @heritage
671
+
672
+ ; Heritage - extension protocol conformance (e.g. extension Foo: SomeProtocol)
673
+ ; Extensions wrap the name in user_type unlike class/struct/enum declarations
674
+ (class_declaration "extension" name: (user_type (type_identifier) @heritage.class)
675
+ (inheritance_specifier inherits_from: (user_type (type_identifier) @heritage.extends))) @heritage
676
+ `;
677
+ export const LANGUAGE_QUERIES = {
678
+ [SupportedLanguages.TypeScript]: TYPESCRIPT_QUERIES,
679
+ [SupportedLanguages.JavaScript]: JAVASCRIPT_QUERIES,
680
+ [SupportedLanguages.Python]: PYTHON_QUERIES,
681
+ [SupportedLanguages.Java]: JAVA_QUERIES,
682
+ [SupportedLanguages.C]: C_QUERIES,
683
+ [SupportedLanguages.Go]: GO_QUERIES,
684
+ [SupportedLanguages.CPlusPlus]: CPP_QUERIES,
685
+ [SupportedLanguages.CSharp]: CSHARP_QUERIES,
686
+ [SupportedLanguages.Ruby]: RUBY_QUERIES,
687
+ [SupportedLanguages.Rust]: RUST_QUERIES,
688
+ [SupportedLanguages.PHP]: PHP_QUERIES,
689
+ [SupportedLanguages.Kotlin]: KOTLIN_QUERIES,
690
+ [SupportedLanguages.Swift]: SWIFT_QUERIES,
691
+ };