code-graph-builder 0.2.0__py3-none-any.whl

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 (93) hide show
  1. code_graph_builder/__init__.py +82 -0
  2. code_graph_builder/builder.py +366 -0
  3. code_graph_builder/cgb_cli.py +32 -0
  4. code_graph_builder/cli.py +564 -0
  5. code_graph_builder/commands_cli.py +1288 -0
  6. code_graph_builder/config.py +340 -0
  7. code_graph_builder/constants.py +708 -0
  8. code_graph_builder/embeddings/__init__.py +40 -0
  9. code_graph_builder/embeddings/qwen3_embedder.py +573 -0
  10. code_graph_builder/embeddings/vector_store.py +584 -0
  11. code_graph_builder/examples/__init__.py +0 -0
  12. code_graph_builder/examples/example_configuration.py +276 -0
  13. code_graph_builder/examples/example_kuzu_usage.py +109 -0
  14. code_graph_builder/examples/example_semantic_search_full.py +347 -0
  15. code_graph_builder/examples/generate_wiki.py +915 -0
  16. code_graph_builder/examples/graph_export_example.py +100 -0
  17. code_graph_builder/examples/rag_example.py +206 -0
  18. code_graph_builder/examples/test_cli_demo.py +129 -0
  19. code_graph_builder/examples/test_embedding_api.py +153 -0
  20. code_graph_builder/examples/test_kuzu_local.py +190 -0
  21. code_graph_builder/examples/test_rag_redis.py +390 -0
  22. code_graph_builder/graph_updater.py +605 -0
  23. code_graph_builder/guidance/__init__.py +1 -0
  24. code_graph_builder/guidance/agent.py +123 -0
  25. code_graph_builder/guidance/prompts.py +74 -0
  26. code_graph_builder/guidance/toolset.py +264 -0
  27. code_graph_builder/language_spec.py +536 -0
  28. code_graph_builder/mcp/__init__.py +21 -0
  29. code_graph_builder/mcp/api_doc_generator.py +764 -0
  30. code_graph_builder/mcp/file_editor.py +207 -0
  31. code_graph_builder/mcp/pipeline.py +777 -0
  32. code_graph_builder/mcp/server.py +161 -0
  33. code_graph_builder/mcp/tools.py +1800 -0
  34. code_graph_builder/models.py +115 -0
  35. code_graph_builder/parser_loader.py +344 -0
  36. code_graph_builder/parsers/__init__.py +7 -0
  37. code_graph_builder/parsers/call_processor.py +306 -0
  38. code_graph_builder/parsers/call_resolver.py +139 -0
  39. code_graph_builder/parsers/definition_processor.py +796 -0
  40. code_graph_builder/parsers/factory.py +119 -0
  41. code_graph_builder/parsers/import_processor.py +293 -0
  42. code_graph_builder/parsers/structure_processor.py +145 -0
  43. code_graph_builder/parsers/type_inference.py +143 -0
  44. code_graph_builder/parsers/utils.py +134 -0
  45. code_graph_builder/rag/__init__.py +68 -0
  46. code_graph_builder/rag/camel_agent.py +429 -0
  47. code_graph_builder/rag/client.py +298 -0
  48. code_graph_builder/rag/config.py +239 -0
  49. code_graph_builder/rag/cypher_generator.py +67 -0
  50. code_graph_builder/rag/llm_backend.py +210 -0
  51. code_graph_builder/rag/markdown_generator.py +352 -0
  52. code_graph_builder/rag/prompt_templates.py +440 -0
  53. code_graph_builder/rag/rag_engine.py +640 -0
  54. code_graph_builder/rag/review_report.md +172 -0
  55. code_graph_builder/rag/tests/__init__.py +3 -0
  56. code_graph_builder/rag/tests/test_camel_agent.py +313 -0
  57. code_graph_builder/rag/tests/test_client.py +221 -0
  58. code_graph_builder/rag/tests/test_config.py +177 -0
  59. code_graph_builder/rag/tests/test_markdown_generator.py +240 -0
  60. code_graph_builder/rag/tests/test_prompt_templates.py +160 -0
  61. code_graph_builder/services/__init__.py +39 -0
  62. code_graph_builder/services/graph_service.py +465 -0
  63. code_graph_builder/services/kuzu_service.py +665 -0
  64. code_graph_builder/services/memory_service.py +171 -0
  65. code_graph_builder/settings.py +75 -0
  66. code_graph_builder/tests/ACCEPTANCE_CRITERIA_PHASE2.md +401 -0
  67. code_graph_builder/tests/__init__.py +1 -0
  68. code_graph_builder/tests/run_acceptance_check.py +378 -0
  69. code_graph_builder/tests/test_api_find.py +231 -0
  70. code_graph_builder/tests/test_api_find_integration.py +226 -0
  71. code_graph_builder/tests/test_basic.py +78 -0
  72. code_graph_builder/tests/test_c_api_extraction.py +388 -0
  73. code_graph_builder/tests/test_call_resolution_scenarios.py +504 -0
  74. code_graph_builder/tests/test_embedder.py +411 -0
  75. code_graph_builder/tests/test_integration_semantic.py +434 -0
  76. code_graph_builder/tests/test_mcp_protocol.py +298 -0
  77. code_graph_builder/tests/test_mcp_user_flow.py +190 -0
  78. code_graph_builder/tests/test_rag.py +404 -0
  79. code_graph_builder/tests/test_settings.py +135 -0
  80. code_graph_builder/tests/test_step1_graph_build.py +264 -0
  81. code_graph_builder/tests/test_step2_api_docs.py +323 -0
  82. code_graph_builder/tests/test_step3_embedding.py +278 -0
  83. code_graph_builder/tests/test_vector_store.py +552 -0
  84. code_graph_builder/tools/__init__.py +40 -0
  85. code_graph_builder/tools/graph_query.py +495 -0
  86. code_graph_builder/tools/semantic_search.py +387 -0
  87. code_graph_builder/types.py +333 -0
  88. code_graph_builder/utils/__init__.py +0 -0
  89. code_graph_builder/utils/path_utils.py +30 -0
  90. code_graph_builder-0.2.0.dist-info/METADATA +321 -0
  91. code_graph_builder-0.2.0.dist-info/RECORD +93 -0
  92. code_graph_builder-0.2.0.dist-info/WHEEL +4 -0
  93. code_graph_builder-0.2.0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,708 @@
1
+ """Code Graph Builder - Constants."""
2
+
3
+ from enum import StrEnum
4
+ from typing import NamedTuple
5
+
6
+
7
+ class UniqueKeyType(StrEnum):
8
+ NAME = "name"
9
+ PATH = "path"
10
+ QUALIFIED_NAME = "qualified_name"
11
+
12
+
13
+ class NodeLabel(StrEnum):
14
+ PROJECT = "Project"
15
+ PACKAGE = "Package"
16
+ FOLDER = "Folder"
17
+ FILE = "File"
18
+ MODULE = "Module"
19
+ CLASS = "Class"
20
+ FUNCTION = "Function"
21
+ METHOD = "Method"
22
+ INTERFACE = "Interface"
23
+ ENUM = "Enum"
24
+ TYPE = "Type"
25
+ UNION = "Union"
26
+ MODULE_INTERFACE = "ModuleInterface"
27
+ MODULE_IMPLEMENTATION = "ModuleImplementation"
28
+ EXTERNAL_PACKAGE = "ExternalPackage"
29
+
30
+
31
+ class RelationshipType(StrEnum):
32
+ CONTAINS_PACKAGE = "CONTAINS_PACKAGE"
33
+ CONTAINS_FOLDER = "CONTAINS_FOLDER"
34
+ CONTAINS_FILE = "CONTAINS_FILE"
35
+ CONTAINS_MODULE = "CONTAINS_MODULE"
36
+ DEFINES = "DEFINES"
37
+ DEFINES_METHOD = "DEFINES_METHOD"
38
+ IMPORTS = "IMPORTS"
39
+ EXPORTS = "EXPORTS"
40
+ EXPORTS_MODULE = "EXPORTS_MODULE"
41
+ IMPLEMENTS_MODULE = "IMPLEMENTS_MODULE"
42
+ INHERITS = "INHERITS"
43
+ IMPLEMENTS = "IMPLEMENTS"
44
+ OVERRIDES = "OVERRIDES"
45
+ CALLS = "CALLS"
46
+ DEPENDS_ON_EXTERNAL = "DEPENDS_ON_EXTERNAL"
47
+
48
+
49
+ class SupportedLanguage(StrEnum):
50
+ PYTHON = "python"
51
+ JS = "javascript"
52
+ TS = "typescript"
53
+ RUST = "rust"
54
+ GO = "go"
55
+ SCALA = "scala"
56
+ JAVA = "java"
57
+ C = "c"
58
+ CPP = "cpp"
59
+ CSHARP = "c-sharp"
60
+ PHP = "php"
61
+ LUA = "lua"
62
+
63
+
64
+ class LanguageStatus(StrEnum):
65
+ FULL = "Fully Supported"
66
+ DEV = "In Development"
67
+
68
+
69
+ class LanguageMetadata(NamedTuple):
70
+ status: LanguageStatus
71
+ additional_features: str
72
+ display_name: str
73
+
74
+
75
+ LANGUAGE_METADATA: dict[SupportedLanguage, LanguageMetadata] = {
76
+ SupportedLanguage.PYTHON: LanguageMetadata(
77
+ LanguageStatus.FULL,
78
+ "Type inference, decorators, nested functions",
79
+ "Python",
80
+ ),
81
+ SupportedLanguage.JS: LanguageMetadata(
82
+ LanguageStatus.FULL,
83
+ "ES6 modules, CommonJS, prototype methods, object methods, arrow functions",
84
+ "JavaScript",
85
+ ),
86
+ SupportedLanguage.TS: LanguageMetadata(
87
+ LanguageStatus.FULL,
88
+ "Interfaces, type aliases, enums, namespaces, ES6/CommonJS modules",
89
+ "TypeScript",
90
+ ),
91
+ SupportedLanguage.CPP: LanguageMetadata(
92
+ LanguageStatus.FULL,
93
+ "Constructors, destructors, operator overloading, templates, lambdas, C++20 modules, namespaces",
94
+ "C++",
95
+ ),
96
+ SupportedLanguage.LUA: LanguageMetadata(
97
+ LanguageStatus.FULL,
98
+ "Local/global functions, metatables, closures, coroutines",
99
+ "Lua",
100
+ ),
101
+ SupportedLanguage.RUST: LanguageMetadata(
102
+ LanguageStatus.FULL,
103
+ "impl blocks, associated functions",
104
+ "Rust",
105
+ ),
106
+ SupportedLanguage.JAVA: LanguageMetadata(
107
+ LanguageStatus.FULL,
108
+ "Generics, annotations, modern features (records/sealed classes), concurrency, reflection",
109
+ "Java",
110
+ ),
111
+ SupportedLanguage.C: LanguageMetadata(
112
+ LanguageStatus.FULL,
113
+ "Functions, structs, unions, enums, function pointers",
114
+ "C",
115
+ ),
116
+ SupportedLanguage.GO: LanguageMetadata(
117
+ LanguageStatus.DEV,
118
+ "Methods, type declarations",
119
+ "Go",
120
+ ),
121
+ SupportedLanguage.SCALA: LanguageMetadata(
122
+ LanguageStatus.DEV,
123
+ "Case classes, objects",
124
+ "Scala",
125
+ ),
126
+ SupportedLanguage.CSHARP: LanguageMetadata(
127
+ LanguageStatus.DEV,
128
+ "Classes, interfaces, generics (planned)",
129
+ "C#",
130
+ ),
131
+ SupportedLanguage.PHP: LanguageMetadata(
132
+ LanguageStatus.DEV,
133
+ "Classes, functions, namespaces",
134
+ "PHP",
135
+ ),
136
+ }
137
+
138
+
139
+ # Node unique key mapping
140
+ _NODE_LABEL_UNIQUE_KEYS: dict[NodeLabel, UniqueKeyType] = {
141
+ NodeLabel.PROJECT: UniqueKeyType.NAME,
142
+ NodeLabel.PACKAGE: UniqueKeyType.QUALIFIED_NAME,
143
+ NodeLabel.FOLDER: UniqueKeyType.PATH,
144
+ NodeLabel.FILE: UniqueKeyType.PATH,
145
+ NodeLabel.MODULE: UniqueKeyType.QUALIFIED_NAME,
146
+ NodeLabel.CLASS: UniqueKeyType.QUALIFIED_NAME,
147
+ NodeLabel.FUNCTION: UniqueKeyType.QUALIFIED_NAME,
148
+ NodeLabel.METHOD: UniqueKeyType.QUALIFIED_NAME,
149
+ NodeLabel.INTERFACE: UniqueKeyType.QUALIFIED_NAME,
150
+ NodeLabel.ENUM: UniqueKeyType.QUALIFIED_NAME,
151
+ NodeLabel.TYPE: UniqueKeyType.QUALIFIED_NAME,
152
+ NodeLabel.UNION: UniqueKeyType.QUALIFIED_NAME,
153
+ NodeLabel.MODULE_INTERFACE: UniqueKeyType.QUALIFIED_NAME,
154
+ NodeLabel.MODULE_IMPLEMENTATION: UniqueKeyType.QUALIFIED_NAME,
155
+ NodeLabel.EXTERNAL_PACKAGE: UniqueKeyType.NAME,
156
+ }
157
+
158
+ NODE_UNIQUE_CONSTRAINTS: dict[str, str] = {
159
+ label.value: key.value for label, key in _NODE_LABEL_UNIQUE_KEYS.items()
160
+ }
161
+
162
+ # File extensions
163
+ EXT_PY = ".py"
164
+ EXT_JS = ".js"
165
+ EXT_JSX = ".jsx"
166
+ EXT_TS = ".ts"
167
+ EXT_TSX = ".tsx"
168
+ EXT_RS = ".rs"
169
+ EXT_GO = ".go"
170
+ EXT_SCALA = ".scala"
171
+ EXT_SC = ".sc"
172
+ EXT_JAVA = ".java"
173
+ EXT_C = ".c"
174
+ EXT_CPP = ".cpp"
175
+ EXT_H = ".h"
176
+ EXT_HPP = ".hpp"
177
+ EXT_CC = ".cc"
178
+ EXT_CXX = ".cxx"
179
+ EXT_HXX = ".hxx"
180
+ EXT_HH = ".hh"
181
+ EXT_IXX = ".ixx"
182
+ EXT_CPPM = ".cppm"
183
+ EXT_CCM = ".ccm"
184
+ EXT_CS = ".cs"
185
+ EXT_PHP = ".php"
186
+ EXT_LUA = ".lua"
187
+
188
+ # Extension tuples by language
189
+ PY_EXTENSIONS = (EXT_PY,)
190
+ JS_EXTENSIONS = (EXT_JS, EXT_JSX)
191
+ TS_EXTENSIONS = (EXT_TS, EXT_TSX)
192
+ RS_EXTENSIONS = (EXT_RS,)
193
+ GO_EXTENSIONS = (EXT_GO,)
194
+ SCALA_EXTENSIONS = (EXT_SCALA, EXT_SC)
195
+ JAVA_EXTENSIONS = (EXT_JAVA,)
196
+ C_EXTENSIONS = (EXT_C, EXT_H)
197
+ CPP_EXTENSIONS = (
198
+ EXT_CPP, EXT_H, EXT_HPP, EXT_CC, EXT_CXX, EXT_HXX, EXT_HH, EXT_IXX, EXT_CPPM, EXT_CCM
199
+ )
200
+ CS_EXTENSIONS = (EXT_CS,)
201
+ PHP_EXTENSIONS = (EXT_PHP,)
202
+ LUA_EXTENSIONS = (EXT_LUA,)
203
+
204
+ # Package indicator files
205
+ PKG_INIT_PY = "__init__.py"
206
+ PKG_CARGO_TOML = "Cargo.toml"
207
+ PKG_CMAKE_LISTS = "CMakeLists.txt"
208
+ PKG_MAKEFILE = "Makefile"
209
+
210
+ # File names
211
+ INIT_PY = "__init__.py"
212
+ MOD_RS = "mod.rs"
213
+
214
+ # Encoding
215
+ ENCODING_UTF8 = "utf-8"
216
+
217
+ # Separators
218
+ SEPARATOR_DOT = "."
219
+ SEPARATOR_SLASH = "/"
220
+
221
+ # Path navigation
222
+ PATH_CURRENT_DIR = "."
223
+ PATH_PARENT_DIR = ".."
224
+ GLOB_ALL = "*"
225
+
226
+ # Trie internal keys
227
+ TRIE_TYPE_KEY = "__type__"
228
+ TRIE_QN_KEY = "__qn__"
229
+ TRIE_INTERNAL_PREFIX = "__"
230
+
231
+ # Property keys
232
+ KEY_NODES = "nodes"
233
+ KEY_RELATIONSHIPS = "relationships"
234
+ KEY_NODE_ID = "node_id"
235
+ KEY_LABELS = "labels"
236
+ KEY_PROPERTIES = "properties"
237
+ KEY_FROM_ID = "from_id"
238
+ KEY_TO_ID = "to_id"
239
+ KEY_TYPE = "type"
240
+ KEY_METADATA = "metadata"
241
+ KEY_TOTAL_NODES = "total_nodes"
242
+ KEY_TOTAL_RELATIONSHIPS = "total_relationships"
243
+ KEY_NODE_LABELS = "node_labels"
244
+ KEY_RELATIONSHIP_TYPES = "relationship_types"
245
+ KEY_EXPORTED_AT = "exported_at"
246
+ KEY_PARSER = "parser"
247
+ KEY_NAME = "name"
248
+ KEY_QUALIFIED_NAME = "qualified_name"
249
+ KEY_START_LINE = "start_line"
250
+ KEY_END_LINE = "end_line"
251
+ KEY_PATH = "path"
252
+ KEY_EXTENSION = "extension"
253
+ KEY_MODULE_TYPE = "module_type"
254
+ KEY_IMPLEMENTS_MODULE = "implements_module"
255
+ KEY_PROPS = "props"
256
+ KEY_CREATED = "created"
257
+ KEY_FROM_VAL = "from_val"
258
+ KEY_TO_VAL = "to_val"
259
+ KEY_VERSION_SPEC = "version_spec"
260
+ KEY_PREFIX = "prefix"
261
+ KEY_PROJECT_NAME = "project_name"
262
+ KEY_IS_EXTERNAL = "is_external"
263
+ KEY_PARAMETERS = "parameters"
264
+ KEY_DECORATORS = "decorators"
265
+ KEY_DOCSTRING = "docstring"
266
+ KEY_IS_EXPORTED = "is_exported"
267
+ KEY_RETURN_TYPE = "return_type"
268
+ KEY_SIGNATURE = "signature"
269
+ KEY_VISIBILITY = "visibility"
270
+ KEY_MEMBERS = "members"
271
+ KEY_KIND = "kind"
272
+
273
+ # Node type constants
274
+ NODE_PROJECT = NodeLabel.PROJECT
275
+ REL_TYPE_CALLS = "CALLS"
276
+
277
+ # Error substrings
278
+ ERR_SUBSTR_ALREADY_EXISTS = "already exists"
279
+ ERR_SUBSTR_CONSTRAINT = "constraint"
280
+
281
+ # Dependency files
282
+ DEPENDENCY_FILES = frozenset({
283
+ "pyproject.toml",
284
+ "requirements.txt",
285
+ "package.json",
286
+ "cargo.toml",
287
+ "go.mod",
288
+ "gemfile",
289
+ "composer.json",
290
+ })
291
+ CSPROJ_SUFFIX = ".csproj"
292
+ EXCLUDED_DEPENDENCY_NAMES = frozenset({"python", "php"})
293
+
294
+ # Cypher queries
295
+ CYPHER_DEFAULT_LIMIT = 50
296
+
297
+ # Byte size constants
298
+ BYTES_PER_MB = 1024 * 1024
299
+
300
+ # Method signature formatting
301
+ EMPTY_PARENS = "()"
302
+ DOCSTRING_STRIP_CHARS = "'\" \\n"
303
+
304
+ # Inline module path prefix
305
+ INLINE_MODULE_PATH_PREFIX = "inline_module_"
306
+
307
+ # Index file names
308
+ INDEX_INIT = "__init__"
309
+ INDEX_INDEX = "index"
310
+ INDEX_MOD = "mod"
311
+
312
+ # AST field names for name extraction
313
+ NAME_FIELDS = ("identifier", "name", "id")
314
+
315
+ # Tree-sitter field name constants
316
+ FIELD_OBJECT = "object"
317
+ FIELD_PROPERTY = "property"
318
+ FIELD_NAME = "name"
319
+ FIELD_ALIAS = "alias"
320
+ FIELD_MODULE_NAME = "module_name"
321
+ FIELD_ARGUMENTS = "arguments"
322
+ FIELD_BODY = "body"
323
+ FIELD_CONSTRUCTOR = "constructor"
324
+ FIELD_DECLARATOR = "declarator"
325
+ FIELD_PARAMETERS = "parameters"
326
+ FIELD_TYPE = "type"
327
+ FIELD_VALUE = "value"
328
+ FIELD_LEFT = "left"
329
+ FIELD_RIGHT = "right"
330
+ FIELD_FIELD = "field"
331
+ FIELD_SUPERCLASS = "superclass"
332
+ FIELD_SUPERCLASSES = "superclasses"
333
+ FIELD_INTERFACES = "interfaces"
334
+
335
+ # Tree-sitter AST node type constants
336
+ FUNCTION_NODES_BASIC = ("function_declaration", "function_definition")
337
+ FUNCTION_NODES_LAMBDA = (
338
+ "lambda_expression",
339
+ "arrow_function",
340
+ "anonymous_function",
341
+ "closure_expression",
342
+ )
343
+ FUNCTION_NODES_METHOD = (
344
+ "method_declaration",
345
+ "constructor_declaration",
346
+ "destructor_declaration",
347
+ )
348
+ FUNCTION_NODES_TEMPLATE = (
349
+ "template_declaration",
350
+ "function_signature_item",
351
+ "function_signature",
352
+ )
353
+ FUNCTION_NODES_GENERATOR = ("generator_function_declaration", "function_expression")
354
+
355
+ CLASS_NODES_BASIC = ("class_declaration", "class_definition")
356
+ CLASS_NODES_STRUCT = ("struct_declaration", "struct_specifier", "struct_item")
357
+ CLASS_NODES_INTERFACE = ("interface_declaration", "trait_declaration", "trait_item")
358
+ CLASS_NODES_ENUM = ("enum_declaration", "enum_item", "enum_specifier")
359
+ CLASS_NODES_TYPE_ALIAS = ("type_alias_declaration", "type_item")
360
+ CLASS_NODES_UNION = ("union_specifier", "union_item")
361
+
362
+ CALL_NODES_BASIC = ("call_expression", "function_call")
363
+ CALL_NODES_METHOD = (
364
+ "method_invocation",
365
+ "member_call_expression",
366
+ "field_expression",
367
+ )
368
+ CALL_NODES_OPERATOR = ("binary_expression", "unary_expression", "update_expression")
369
+ CALL_NODES_SPECIAL = ("new_expression", "delete_expression", "macro_invocation")
370
+
371
+ IMPORT_NODES_STANDARD = ("import_declaration", "import_statement")
372
+ IMPORT_NODES_FROM = ("import_from_statement",)
373
+ IMPORT_NODES_MODULE = ("lexical_declaration", "export_statement")
374
+ IMPORT_NODES_INCLUDE = ("preproc_include",)
375
+ IMPORT_NODES_USING = ("using_directive",)
376
+
377
+ # JS/TS specific node types
378
+ JS_TS_FUNCTION_NODES = (
379
+ "function_declaration",
380
+ "generator_function_declaration",
381
+ "function_expression",
382
+ "arrow_function",
383
+ "method_definition",
384
+ )
385
+ JS_TS_CLASS_NODES = ("class_declaration", "class")
386
+ JS_TS_IMPORT_NODES = ("import_statement", "lexical_declaration", "export_statement")
387
+ JS_TS_LANGUAGES = frozenset({SupportedLanguage.JS, SupportedLanguage.TS})
388
+
389
+ # C++ import node types
390
+ CPP_IMPORT_NODES = ("preproc_include", "template_function", "declaration")
391
+
392
+ # Parser loader paths and args
393
+ GRAMMARS_DIR = "grammars"
394
+ TREE_SITTER_PREFIX = "tree-sitter-"
395
+ TREE_SITTER_MODULE_PREFIX = "tree_sitter_"
396
+ BINDINGS_DIR = "bindings"
397
+ SETUP_PY = "setup.py"
398
+ BUILD_EXT_CMD = "build_ext"
399
+ INPLACE_FLAG = "--inplace"
400
+ LANG_ATTR_PREFIX = "language_"
401
+ LANG_ATTR_TYPESCRIPT = "language_typescript"
402
+
403
+
404
+ class TreeSitterModule(StrEnum):
405
+ PYTHON = "tree_sitter_python"
406
+ JS = "tree_sitter_javascript"
407
+ TS = "tree_sitter_typescript"
408
+ RUST = "tree_sitter_rust"
409
+ GO = "tree_sitter_go"
410
+ SCALA = "tree_sitter_scala"
411
+ JAVA = "tree_sitter_java"
412
+ C = "tree_sitter_c"
413
+ CPP = "tree_sitter_cpp"
414
+ LUA = "tree_sitter_lua"
415
+
416
+
417
+ # Query dict keys
418
+ QUERY_FUNCTIONS = "functions"
419
+ QUERY_CLASSES = "classes"
420
+ QUERY_CALLS = "calls"
421
+ QUERY_IMPORTS = "imports"
422
+ QUERY_LOCALS = "locals"
423
+ QUERY_CONFIG = "config"
424
+ QUERY_LANGUAGE = "language"
425
+ QUERY_TYPEDEFS = "typedefs"
426
+ QUERY_MACROS = "macros"
427
+
428
+ # Query capture names
429
+ CAPTURE_FUNCTION = "function"
430
+ CAPTURE_CLASS = "class"
431
+ CAPTURE_CALL = "call"
432
+ CAPTURE_IMPORT = "import"
433
+ CAPTURE_IMPORT_FROM = "import_from"
434
+ CAPTURE_TYPEDEF = "typedef"
435
+ CAPTURE_MACRO = "macro"
436
+
437
+ # Locals query patterns for JS/TS
438
+ JS_LOCALS_PATTERN = """
439
+ ; Variable definitions
440
+ (variable_declarator name: (identifier) @local.definition)
441
+ (function_declaration name: (identifier) @local.definition)
442
+ (class_declaration name: (identifier) @local.definition)
443
+
444
+ ; Variable references
445
+ (identifier) @local.reference
446
+ """
447
+
448
+ TS_LOCALS_PATTERN = """
449
+ ; Variable definitions (TypeScript has multiple declaration types)
450
+ (variable_declarator name: (identifier) @local.definition)
451
+ (lexical_declaration (variable_declarator name: (identifier) @local.definition))
452
+ (variable_declaration (variable_declarator name: (identifier) @local.definition))
453
+
454
+ ; Function definitions
455
+ (function_declaration name: (identifier) @local.definition)
456
+
457
+ ; Class definitions (uses type_identifier for class names)
458
+ (class_declaration name: (type_identifier) @local.definition)
459
+
460
+ ; Variable references
461
+ (identifier) @local.reference
462
+ """
463
+
464
+ # Ignore patterns
465
+ IGNORE_PATTERNS = frozenset({
466
+ ".cache", ".claude", ".eclipse", ".eggs", ".env", ".git", ".gradle", ".hg",
467
+ ".idea", ".maven", ".mypy_cache", ".nox", ".npm", ".nyc_output", ".pnpm-store",
468
+ ".pytest_cache", ".qdrant_code_embeddings", ".ruff_cache", ".svn", ".tmp", ".tox",
469
+ ".venv", ".vs", ".vscode", ".yarn", "__pycache__", "bin", "bower_components",
470
+ "build", "coverage", "dist", "env", "htmlcov", "node_modules", "obj", "out",
471
+ "Pods", "site-packages", "target", "temp", "tmp", "vendor", "venv",
472
+ })
473
+ IGNORE_SUFFIXES = frozenset({".tmp", "~", ".pyc", ".pyo", ".o", ".a", ".so", ".dll", ".class"})
474
+
475
+ # Binary extensions
476
+ BINARY_EXTENSIONS = frozenset({
477
+ ".pdf", ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".ico", ".tiff", ".webp",
478
+ })
479
+
480
+ # Cypher response cleaning
481
+ CYPHER_PREFIX = "cypher"
482
+ CYPHER_SEMICOLON = ";"
483
+ CYPHER_BACKTICK = "`"
484
+ CYPHER_MATCH_KEYWORD = "MATCH"
485
+
486
+ # Method name constants
487
+ METHOD_FIND_WITH_PREFIX = "find_with_prefix"
488
+ METHOD_ITEMS = "items"
489
+
490
+ # JSON formatting
491
+ JSON_INDENT = 2
492
+
493
+ # Character constants
494
+ CHAR_HYPHEN = "-"
495
+ CHAR_UNDERSCORE = "_"
496
+ CHAR_SEMICOLON = ";"
497
+ CHAR_COMMA = ","
498
+ CHAR_COLON = ":"
499
+ CHAR_ANGLE_OPEN = "<"
500
+ CHAR_ANGLE_CLOSE = ">"
501
+ CHAR_PAREN_OPEN = "("
502
+ CHAR_PAREN_CLOSE = ")"
503
+ CHAR_SPACE = " "
504
+ SEPARATOR_COMMA_SPACE = ", "
505
+ PUNCTUATION_TYPES = (CHAR_PAREN_OPEN, CHAR_PAREN_CLOSE, CHAR_COMMA)
506
+
507
+ # Regex patterns
508
+ REGEX_METHOD_CHAIN_SUFFIX = r"\)\.[^)]*$"
509
+ REGEX_FINAL_METHOD_CAPTURE = r"\.([^.()]+)$"
510
+
511
+ # Default names
512
+ DEFAULT_NAME = "Unknown"
513
+ TEXT_UNKNOWN = "unknown"
514
+
515
+ # Language specs
516
+ SPEC_PY_FUNCTION_TYPES = (
517
+ "function_definition",
518
+ "lambda",
519
+ )
520
+ SPEC_PY_CLASS_TYPES = ("class_definition",)
521
+ SPEC_PY_MODULE_TYPES = ("module",)
522
+ SPEC_PY_CALL_TYPES = ("call",)
523
+ SPEC_PY_IMPORT_TYPES = ("import_statement",)
524
+ SPEC_PY_IMPORT_FROM_TYPES = ("import_from_statement",)
525
+ SPEC_PY_PACKAGE_INDICATORS = frozenset({PKG_INIT_PY})
526
+
527
+ SPEC_JS_MODULE_TYPES = ("program",)
528
+ SPEC_JS_CALL_TYPES = ("call_expression",)
529
+
530
+ SPEC_RS_FUNCTION_TYPES = (
531
+ "function_item",
532
+ "function_signature_item",
533
+ "closure_expression",
534
+ )
535
+ SPEC_RS_CLASS_TYPES = (
536
+ "struct_item",
537
+ "enum_item",
538
+ "union_item",
539
+ "trait_item",
540
+ "type_item",
541
+ "impl_item",
542
+ )
543
+ SPEC_RS_MODULE_TYPES = ("mod_item", "source_file")
544
+ SPEC_RS_CALL_TYPES = ("call_expression", "macro_invocation")
545
+ SPEC_RS_IMPORT_TYPES = ("use_declaration",)
546
+ SPEC_RS_IMPORT_FROM_TYPES = ("use_declaration",)
547
+ SPEC_RS_PACKAGE_INDICATORS = frozenset({PKG_CARGO_TOML})
548
+
549
+ SPEC_GO_FUNCTION_TYPES = ("function_declaration", "method_declaration")
550
+ SPEC_GO_CLASS_TYPES = ("type_declaration",)
551
+ SPEC_GO_MODULE_TYPES = ("source_file",)
552
+ SPEC_GO_CALL_TYPES = ("call_expression",)
553
+ SPEC_GO_IMPORT_TYPES = ("import_declaration",)
554
+
555
+ SPEC_SCALA_FUNCTION_TYPES = (
556
+ "function_definition",
557
+ "macro_definition",
558
+ )
559
+ SPEC_SCALA_CLASS_TYPES = (
560
+ "class_definition",
561
+ "trait_definition",
562
+ "object_definition",
563
+ "enum_definition",
564
+ "case_class_definition",
565
+ )
566
+ SPEC_SCALA_MODULE_TYPES = ("compilation_unit",)
567
+ SPEC_SCALA_CALL_TYPES = ("call_expression",)
568
+ SPEC_SCALA_IMPORT_TYPES = ("import_declaration",)
569
+
570
+ SPEC_JAVA_FUNCTION_TYPES = (
571
+ "method_declaration",
572
+ "constructor_declaration",
573
+ )
574
+ SPEC_JAVA_CLASS_TYPES = (
575
+ "class_declaration",
576
+ "interface_declaration",
577
+ "enum_declaration",
578
+ "annotation_type_declaration",
579
+ "record_declaration",
580
+ )
581
+ SPEC_JAVA_MODULE_TYPES = ("program",)
582
+ SPEC_JAVA_CALL_TYPES = ("method_invocation", "object_creation_expression")
583
+ SPEC_JAVA_IMPORT_TYPES = ("import_declaration",)
584
+
585
+ # C language specific
586
+ SPEC_C_FUNCTION_TYPES = (
587
+ "function_definition",
588
+ "declaration",
589
+ )
590
+ SPEC_C_CLASS_TYPES = (
591
+ "struct_specifier",
592
+ "union_specifier",
593
+ "enum_specifier",
594
+ )
595
+ SPEC_C_MODULE_TYPES = ("translation_unit",)
596
+ SPEC_C_CALL_TYPES = ("call_expression",)
597
+ SPEC_C_IMPORT_TYPES = ("preproc_include",)
598
+ SPEC_C_TYPEDEF_TYPES = ("type_definition",)
599
+ SPEC_C_MACRO_TYPES = ("preproc_def", "preproc_function_def")
600
+ SPEC_C_PACKAGE_INDICATORS = frozenset({PKG_MAKEFILE, "configure.ac", "configure.in"})
601
+
602
+ SPEC_CPP_FUNCTION_TYPES = (
603
+ "function_definition",
604
+ "template_declaration",
605
+ "lambda_expression",
606
+ )
607
+ SPEC_CPP_CLASS_TYPES = (
608
+ "class_specifier",
609
+ "struct_specifier",
610
+ "union_specifier",
611
+ "enum_specifier",
612
+ )
613
+ SPEC_CPP_MODULE_TYPES = ("translation_unit",)
614
+ SPEC_CPP_CALL_TYPES = (
615
+ "call_expression",
616
+ "binary_expression",
617
+ "unary_expression",
618
+ )
619
+ SPEC_CPP_IMPORT_TYPES = ("preproc_include",)
620
+ SPEC_CPP_PACKAGE_INDICATORS = frozenset({PKG_CMAKE_LISTS, PKG_MAKEFILE})
621
+
622
+ SPEC_CS_FUNCTION_TYPES = (
623
+ "method_declaration",
624
+ "constructor_declaration",
625
+ "destructor_declaration",
626
+ )
627
+ SPEC_CS_CLASS_TYPES = (
628
+ "class_declaration",
629
+ "interface_declaration",
630
+ "struct_declaration",
631
+ "enum_declaration",
632
+ )
633
+ SPEC_CS_MODULE_TYPES = ("compilation_unit",)
634
+ SPEC_CS_CALL_TYPES = ("invocation_expression", "object_creation_expression")
635
+
636
+ SPEC_PHP_FUNCTION_TYPES = ("function_definition", "method_declaration")
637
+ SPEC_PHP_CLASS_TYPES = ("class_declaration", "interface_declaration", "trait_declaration")
638
+ SPEC_PHP_MODULE_TYPES = ("program",)
639
+ SPEC_PHP_CALL_TYPES = ("function_call_expression", "member_call_expression")
640
+
641
+ SPEC_LUA_FUNCTION_TYPES = (
642
+ "function_declaration",
643
+ "local_function_declaration",
644
+ )
645
+ SPEC_LUA_CLASS_TYPES = ("table_constructor",)
646
+ SPEC_LUA_MODULE_TYPES = ("program",)
647
+ SPEC_LUA_CALL_TYPES = ("function_call",)
648
+ SPEC_LUA_IMPORT_TYPES = ("require_expression",)
649
+
650
+ # FQN scope types
651
+ FQN_PY_SCOPE_TYPES = ("class_definition", "function_definition")
652
+ FQN_PY_FUNCTION_TYPES = ("function_definition", "lambda")
653
+
654
+ FQN_JS_SCOPE_TYPES = ("class_declaration", "class", "function_declaration", "function_expression", "arrow_function", "method_definition")
655
+ FQN_JS_FUNCTION_TYPES = JS_TS_FUNCTION_NODES
656
+
657
+ FQN_TS_SCOPE_TYPES = FQN_JS_SCOPE_TYPES + ("interface_declaration", "enum_declaration", "type_alias_declaration")
658
+ FQN_TS_FUNCTION_TYPES = JS_TS_FUNCTION_NODES + ("function_signature",)
659
+
660
+ FQN_RS_SCOPE_TYPES = ("impl_item", "trait_item", "function_item", "mod_item")
661
+ FQN_RS_FUNCTION_TYPES = ("function_item", "function_signature_item", "closure_expression")
662
+
663
+ FQN_JAVA_SCOPE_TYPES = SPEC_JAVA_CLASS_TYPES
664
+ FQN_JAVA_FUNCTION_TYPES = SPEC_JAVA_FUNCTION_TYPES
665
+
666
+ FQN_CPP_SCOPE_TYPES = SPEC_CPP_CLASS_TYPES + ("namespace_definition",)
667
+ FQN_CPP_FUNCTION_TYPES = SPEC_CPP_FUNCTION_TYPES
668
+
669
+ FQN_LUA_SCOPE_TYPES = ("function_declaration", "local_function_declaration")
670
+ FQN_LUA_FUNCTION_TYPES = SPEC_LUA_FUNCTION_TYPES
671
+
672
+ FQN_GO_SCOPE_TYPES = ("type_declaration", "function_declaration")
673
+ FQN_GO_FUNCTION_TYPES = SPEC_GO_FUNCTION_TYPES
674
+
675
+ FQN_SCALA_SCOPE_TYPES = SPEC_SCALA_CLASS_TYPES
676
+ FQN_SCALA_FUNCTION_TYPES = SPEC_SCALA_FUNCTION_TYPES
677
+
678
+ FQN_CS_SCOPE_TYPES = SPEC_CS_CLASS_TYPES
679
+ FQN_CS_FUNCTION_TYPES = SPEC_CS_FUNCTION_TYPES
680
+
681
+ FQN_PHP_SCOPE_TYPES = SPEC_PHP_CLASS_TYPES + ("namespace_definition",)
682
+ FQN_PHP_FUNCTION_TYPES = SPEC_PHP_FUNCTION_TYPES
683
+
684
+ # Tree-sitter type constants
685
+ TS_TYPE_IDENTIFIER = "type_identifier"
686
+ TS_IDENTIFIER = "identifier"
687
+ TS_PY_EXPRESSION_STATEMENT = "expression_statement"
688
+ TS_PY_STRING = "string"
689
+ TS_CPP_FUNCTION_DEFINITION = "function_definition"
690
+ TS_CPP_FUNCTION_DECLARATOR = "function_declarator"
691
+
692
+ # JS name node types
693
+ JS_NAME_NODE_TYPES = JS_TS_FUNCTION_NODES + JS_TS_CLASS_NODES
694
+
695
+ # Rust type node types
696
+ RS_TYPE_NODE_TYPES = ("function_item", "struct_item", "enum_item", "trait_item", "impl_item", "type_item")
697
+ RS_IDENT_NODE_TYPES = ("mod_item",)
698
+
699
+ # C++ name node types
700
+ CPP_NAME_NODE_TYPES = SPEC_CPP_FUNCTION_TYPES + SPEC_CPP_CLASS_TYPES
701
+
702
+ # TS specific node types
703
+ TS_FUNCTION_SIGNATURE = "function_signature"
704
+ TS_ABSTRACT_CLASS_DECLARATION = "abstract_class_declaration"
705
+ TS_ENUM_DECLARATION = "enum_declaration"
706
+ TS_INTERFACE_DECLARATION = "interface_declaration"
707
+ TS_TYPE_ALIAS_DECLARATION = "type_alias_declaration"
708
+ TS_INTERNAL_MODULE = "internal_module"