codegraphcontext-rust 0.5.5__cp310-cp310-win_amd64.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 (101) hide show
  1. codegraphcontext/__init__.py +2 -0
  2. codegraphcontext/__main__.py +5 -0
  3. codegraphcontext/_cgc_rust.cp310-win_amd64.pyd +0 -0
  4. codegraphcontext/cli/__init__.py +1 -0
  5. codegraphcontext/cli/cli_helpers.py +774 -0
  6. codegraphcontext/cli/config_manager.py +1051 -0
  7. codegraphcontext/cli/main.py +2386 -0
  8. codegraphcontext/cli/registry_commands.py +404 -0
  9. codegraphcontext/cli/setup_macos.py +93 -0
  10. codegraphcontext/cli/setup_wizard.py +991 -0
  11. codegraphcontext/cli/visualizer.py +50 -0
  12. codegraphcontext/core/__init__.py +165 -0
  13. codegraphcontext/core/bundle_registry.py +181 -0
  14. codegraphcontext/core/cgc_bundle.py +858 -0
  15. codegraphcontext/core/cgcignore.py +118 -0
  16. codegraphcontext/core/database.py +273 -0
  17. codegraphcontext/core/database_falkordb.py +480 -0
  18. codegraphcontext/core/database_falkordb_remote.py +199 -0
  19. codegraphcontext/core/database_kuzu.py +636 -0
  20. codegraphcontext/core/falkor_worker.py +132 -0
  21. codegraphcontext/core/jobs.py +132 -0
  22. codegraphcontext/core/watcher.py +260 -0
  23. codegraphcontext/prompts.py +125 -0
  24. codegraphcontext/server.py +471 -0
  25. codegraphcontext/tool_definitions.py +220 -0
  26. codegraphcontext/tools/__init__.py +0 -0
  27. codegraphcontext/tools/advanced_language_query_tool.py +103 -0
  28. codegraphcontext/tools/code_finder.py +1160 -0
  29. codegraphcontext/tools/graph_builder.py +337 -0
  30. codegraphcontext/tools/handlers/analysis_handlers.py +114 -0
  31. codegraphcontext/tools/handlers/indexing_handlers.py +116 -0
  32. codegraphcontext/tools/handlers/management_handlers.py +339 -0
  33. codegraphcontext/tools/handlers/query_handlers.py +83 -0
  34. codegraphcontext/tools/handlers/watcher_handlers.py +83 -0
  35. codegraphcontext/tools/indexing/__init__.py +1 -0
  36. codegraphcontext/tools/indexing/constants.py +25 -0
  37. codegraphcontext/tools/indexing/discovery.py +64 -0
  38. codegraphcontext/tools/indexing/engine.py +109 -0
  39. codegraphcontext/tools/indexing/persistence/__init__.py +3 -0
  40. codegraphcontext/tools/indexing/persistence/parquet_loader.py +643 -0
  41. codegraphcontext/tools/indexing/persistence/writer.py +1114 -0
  42. codegraphcontext/tools/indexing/pipeline.py +171 -0
  43. codegraphcontext/tools/indexing/pre_scan.py +105 -0
  44. codegraphcontext/tools/indexing/resolution/__init__.py +8 -0
  45. codegraphcontext/tools/indexing/resolution/calls.py +253 -0
  46. codegraphcontext/tools/indexing/resolution/inheritance.py +91 -0
  47. codegraphcontext/tools/indexing/sanitize.py +41 -0
  48. codegraphcontext/tools/indexing/schema.py +79 -0
  49. codegraphcontext/tools/indexing/schema_contract.py +44 -0
  50. codegraphcontext/tools/indexing/scip_pipeline.py +140 -0
  51. codegraphcontext/tools/languages/c.py +563 -0
  52. codegraphcontext/tools/languages/cpp.py +616 -0
  53. codegraphcontext/tools/languages/csharp.py +551 -0
  54. codegraphcontext/tools/languages/dart.py +378 -0
  55. codegraphcontext/tools/languages/elixir.py +460 -0
  56. codegraphcontext/tools/languages/go.py +499 -0
  57. codegraphcontext/tools/languages/haskell.py +426 -0
  58. codegraphcontext/tools/languages/java.py +500 -0
  59. codegraphcontext/tools/languages/javascript.py +589 -0
  60. codegraphcontext/tools/languages/kotlin.py +640 -0
  61. codegraphcontext/tools/languages/perl.py +260 -0
  62. codegraphcontext/tools/languages/php.py +519 -0
  63. codegraphcontext/tools/languages/python.py +576 -0
  64. codegraphcontext/tools/languages/ruby.py +537 -0
  65. codegraphcontext/tools/languages/rust.py +295 -0
  66. codegraphcontext/tools/languages/scala.py +519 -0
  67. codegraphcontext/tools/languages/swift.py +491 -0
  68. codegraphcontext/tools/languages/typescript.py +575 -0
  69. codegraphcontext/tools/languages/typescriptjsx.py +151 -0
  70. codegraphcontext/tools/package_resolver.py +472 -0
  71. codegraphcontext/tools/query_tool_languages/c_toolkit.py +5 -0
  72. codegraphcontext/tools/query_tool_languages/cpp_toolkit.py +87 -0
  73. codegraphcontext/tools/query_tool_languages/csharp_toolkit.py +5 -0
  74. codegraphcontext/tools/query_tool_languages/dart_toolkit.py +5 -0
  75. codegraphcontext/tools/query_tool_languages/go_toolkit.py +5 -0
  76. codegraphcontext/tools/query_tool_languages/haskell_toolkit.py +5 -0
  77. codegraphcontext/tools/query_tool_languages/java_toolkit.py +5 -0
  78. codegraphcontext/tools/query_tool_languages/javascript_toolkit.py +5 -0
  79. codegraphcontext/tools/query_tool_languages/perl_toolkit.py +5 -0
  80. codegraphcontext/tools/query_tool_languages/python_toolkit.py +5 -0
  81. codegraphcontext/tools/query_tool_languages/ruby_toolkit.py +5 -0
  82. codegraphcontext/tools/query_tool_languages/rust_toolkit.py +5 -0
  83. codegraphcontext/tools/query_tool_languages/scala_toolkit.py +5 -0
  84. codegraphcontext/tools/query_tool_languages/swift_toolkit.py +5 -0
  85. codegraphcontext/tools/query_tool_languages/typescript_toolkit.py +5 -0
  86. codegraphcontext/tools/scip_indexer.py +467 -0
  87. codegraphcontext/tools/scip_pb2.py +2455 -0
  88. codegraphcontext/tools/system.py +133 -0
  89. codegraphcontext/tools/tree_sitter_parser.py +103 -0
  90. codegraphcontext/utils/debug_log.py +90 -0
  91. codegraphcontext/utils/path_ignore.py +55 -0
  92. codegraphcontext/utils/repo_path.py +27 -0
  93. codegraphcontext/utils/tree_sitter_manager.py +285 -0
  94. codegraphcontext/utils/visualize_graph.py +0 -0
  95. codegraphcontext/viz/server.py +282 -0
  96. codegraphcontext_rust-0.5.5.dist-info/METADATA +537 -0
  97. codegraphcontext_rust-0.5.5.dist-info/RECORD +101 -0
  98. codegraphcontext_rust-0.5.5.dist-info/WHEEL +4 -0
  99. codegraphcontext_rust-0.5.5.dist-info/entry_points.txt +3 -0
  100. codegraphcontext_rust-0.5.5.dist-info/licenses/LICENSE +21 -0
  101. codegraphcontext_rust-0.5.5.dist-info/sboms/cgc-python.cyclonedx.json +2333 -0
@@ -0,0 +1,79 @@
1
+ """Create constraints and indexes for graph backends (Neo4j / Falkor-style Cypher)."""
2
+
3
+ from typing import Any
4
+
5
+ from ...utils.debug_log import info_logger, warning_logger
6
+
7
+
8
+ def create_graph_schema(driver: Any, db_manager: Any) -> None:
9
+ """Create constraints and indexes. *driver* must support .session() context manager."""
10
+ with driver.session() as session:
11
+ try:
12
+ session.run(
13
+ "CREATE CONSTRAINT repository_path IF NOT EXISTS FOR (r:Repository) REQUIRE r.path IS UNIQUE"
14
+ )
15
+ session.run("CREATE CONSTRAINT path IF NOT EXISTS FOR (f:File) REQUIRE f.path IS UNIQUE")
16
+ session.run(
17
+ "CREATE CONSTRAINT directory_path IF NOT EXISTS FOR (d:Directory) REQUIRE d.path IS UNIQUE"
18
+ )
19
+ session.run(
20
+ "CREATE CONSTRAINT function_unique IF NOT EXISTS FOR (f:Function) REQUIRE (f.name, f.path, f.line_number) IS UNIQUE"
21
+ )
22
+ session.run(
23
+ "CREATE CONSTRAINT class_unique IF NOT EXISTS FOR (c:Class) REQUIRE (c.name, c.path, c.line_number) IS UNIQUE"
24
+ )
25
+ session.run(
26
+ "CREATE CONSTRAINT trait_unique IF NOT EXISTS FOR (t:Trait) REQUIRE (t.name, t.path, t.line_number) IS UNIQUE"
27
+ )
28
+ session.run(
29
+ "CREATE CONSTRAINT interface_unique IF NOT EXISTS FOR (i:Interface) REQUIRE (i.name, i.path, i.line_number) IS UNIQUE"
30
+ )
31
+ session.run(
32
+ "CREATE CONSTRAINT macro_unique IF NOT EXISTS FOR (m:Macro) REQUIRE (m.name, m.path, m.line_number) IS UNIQUE"
33
+ )
34
+ session.run(
35
+ "CREATE CONSTRAINT variable_unique IF NOT EXISTS FOR (v:Variable) REQUIRE (v.name, v.path, v.line_number) IS UNIQUE"
36
+ )
37
+ session.run("CREATE CONSTRAINT module_name IF NOT EXISTS FOR (m:Module) REQUIRE m.name IS UNIQUE")
38
+ session.run(
39
+ "CREATE CONSTRAINT struct_cpp IF NOT EXISTS FOR (cstruct: Struct) REQUIRE (cstruct.name, cstruct.path, cstruct.line_number) IS UNIQUE"
40
+ )
41
+ session.run(
42
+ "CREATE CONSTRAINT enum_cpp IF NOT EXISTS FOR (cenum: Enum) REQUIRE (cenum.name, cenum.path, cenum.line_number) IS UNIQUE"
43
+ )
44
+ session.run(
45
+ "CREATE CONSTRAINT union_cpp IF NOT EXISTS FOR (cunion: Union) REQUIRE (cunion.name, cunion.path, cunion.line_number) IS UNIQUE"
46
+ )
47
+ session.run(
48
+ "CREATE CONSTRAINT annotation_unique IF NOT EXISTS FOR (a:Annotation) REQUIRE (a.name, a.path, a.line_number) IS UNIQUE"
49
+ )
50
+ session.run(
51
+ "CREATE CONSTRAINT record_unique IF NOT EXISTS FOR (r:Record) REQUIRE (r.name, r.path, r.line_number) IS UNIQUE"
52
+ )
53
+ session.run(
54
+ "CREATE CONSTRAINT property_unique IF NOT EXISTS FOR (p:Property) REQUIRE (p.name, p.path, p.line_number) IS UNIQUE"
55
+ )
56
+
57
+ session.run("CREATE INDEX function_lang IF NOT EXISTS FOR (f:Function) ON (f.lang)")
58
+ session.run("CREATE INDEX class_lang IF NOT EXISTS FOR (c:Class) ON (c.lang)")
59
+ session.run("CREATE INDEX annotation_lang IF NOT EXISTS FOR (a:Annotation) ON (a.lang)")
60
+
61
+ is_falkordb = getattr(db_manager, "get_backend_type", lambda: "neo4j")() != "neo4j"
62
+ if is_falkordb:
63
+ for label in ["Function", "Class"]:
64
+ try:
65
+ session.run(
66
+ f"CALL db.idx.fulltext.createNodeIndex('{label}', 'name', 'source', 'docstring')"
67
+ )
68
+ except Exception:
69
+ pass
70
+ else:
71
+ session.run("""
72
+ CREATE FULLTEXT INDEX code_search_index IF NOT EXISTS
73
+ FOR (n:Function|Class|Variable)
74
+ ON EACH [n.name, n.source, n.docstring]
75
+ """)
76
+
77
+ info_logger("Database schema verified/created successfully")
78
+ except Exception as e:
79
+ warning_logger(f"Schema creation warning: {e}")
@@ -0,0 +1,44 @@
1
+ """
2
+ Semantic graph contract: labels, relationship types, and merge keys used by indexing.
3
+
4
+ Backends must produce nodes/relationships consistent with this contract so MCP
5
+ and query tools remain stable. This module is documentation + test hooks only.
6
+ """
7
+
8
+ # Node labels written by the indexing pipeline (excluding dynamic query-only uses)
9
+ NODE_LABELS = frozenset({
10
+ "Repository",
11
+ "Directory",
12
+ "File",
13
+ "Function",
14
+ "Class",
15
+ "Trait",
16
+ "Variable",
17
+ "Interface",
18
+ "Macro",
19
+ "Struct",
20
+ "Enum",
21
+ "Union",
22
+ "Record",
23
+ "Property",
24
+ "Annotation",
25
+ "Module",
26
+ "Parameter",
27
+ })
28
+
29
+ RELATIONSHIP_TYPES = frozenset({
30
+ "CONTAINS",
31
+ "CALLS",
32
+ "IMPORTS",
33
+ "INHERITS",
34
+ "HAS_PARAMETER",
35
+ "INCLUDES",
36
+ "IMPLEMENTS",
37
+ })
38
+
39
+ # Identity properties used in MERGE for code entities (path = absolute file path)
40
+ FUNCTION_MERGE_KEYS = ("name", "path", "line_number")
41
+ CLASS_MERGE_KEYS = ("name", "path", "line_number")
42
+ FILE_MERGE_KEYS = ("path",)
43
+ REPOSITORY_MERGE_KEYS = ("path",)
44
+ DIRECTORY_MERGE_KEYS = ("path",)
@@ -0,0 +1,140 @@
1
+ """SCIP-based indexing orchestration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import tempfile
7
+ from datetime import datetime
8
+ from pathlib import Path
9
+ from typing import Any, Callable, Dict, Optional
10
+
11
+ from ...core.jobs import JobManager, JobStatus
12
+ from ...utils.debug_log import debug_log, error_logger, info_logger, warning_logger
13
+ from ...utils.path_ignore import file_path_has_ignore_dir_segment
14
+ from .persistence.writer import GraphWriter
15
+ from .pre_scan import pre_scan_for_imports
16
+ from .resolution.inheritance import build_inheritance_and_csharp_files
17
+
18
+
19
+ def name_from_symbol(symbol: str) -> str:
20
+ import re
21
+
22
+ s = symbol.rstrip(".#")
23
+ s = re.sub(r"\(\)\.?$", "", s)
24
+ parts = re.split(r"[/#]", s)
25
+ last = parts[-1] if parts else symbol
26
+ return last or symbol
27
+
28
+
29
+ async def run_scip_index_async(
30
+ path: Path,
31
+ is_dependency: bool,
32
+ job_id: Optional[str],
33
+ lang: str,
34
+ writer: GraphWriter,
35
+ job_manager: JobManager,
36
+ parsers_keys: Any,
37
+ get_parser: Callable[[str], Any],
38
+ scip_indexer_mod: Any,
39
+ ) -> None:
40
+ """Run SCIP CLI, write graph, supplement with Tree-sitter, write SCIP CALLS edges."""
41
+ ScipIndexer = scip_indexer_mod.ScipIndexer
42
+ ScipIndexParser = scip_indexer_mod.ScipIndexParser
43
+
44
+ if job_id:
45
+ job_manager.update_job(job_id, status=JobStatus.RUNNING)
46
+
47
+ writer.add_repository_to_graph(path, is_dependency)
48
+ repo_name = path.name
49
+
50
+ try:
51
+ with tempfile.TemporaryDirectory(prefix="cgc_scip_") as tmpdir:
52
+ scip_file = ScipIndexer().run(path, lang, Path(tmpdir))
53
+
54
+ if not scip_file:
55
+ warning_logger(
56
+ f"SCIP indexer produced no output for {path}. "
57
+ "Falling back to Tree-sitter."
58
+ )
59
+ raise RuntimeError("SCIP produced no index — triggering Tree-sitter fallback")
60
+
61
+ scip_data = ScipIndexParser().parse(scip_file, path)
62
+
63
+ if not scip_data:
64
+ raise RuntimeError("SCIP parse returned empty result")
65
+
66
+ files_data = scip_data.get("files", {})
67
+ file_paths = [Path(p) for p in files_data.keys() if Path(p).exists()]
68
+
69
+ imports_map = pre_scan_for_imports(file_paths, parsers_keys, get_parser)
70
+
71
+ if job_id:
72
+ job_manager.update_job(job_id, total_files=len(files_data))
73
+
74
+ processed = 0
75
+ index_root = path.resolve()
76
+ for abs_path_str, file_data in files_data.items():
77
+ file_path = Path(abs_path_str)
78
+ if file_path.is_file() and file_path_has_ignore_dir_segment(file_path, index_root):
79
+ continue
80
+ file_data["repo_path"] = str(index_root)
81
+ if job_id:
82
+ job_manager.update_job(job_id, current_file=abs_path_str)
83
+
84
+ ts_parser = get_parser(file_path.suffix)
85
+ if file_path.exists() and ts_parser:
86
+ try:
87
+ ts_data = ts_parser.parse(file_path, is_dependency, index_source=True)
88
+ if "error" not in ts_data:
89
+ ts_funcs = {f["name"]: f for f in ts_data.get("functions", [])}
90
+ for f in file_data.get("functions", []):
91
+ ts_f = ts_funcs.get(f["name"])
92
+ if ts_f:
93
+ f.update(
94
+ {
95
+ "source": ts_f.get("source"),
96
+ "cyclomatic_complexity": ts_f.get("cyclomatic_complexity", 1),
97
+ "decorators": ts_f.get("decorators", []),
98
+ }
99
+ )
100
+
101
+ ts_classes = {c["name"]: c for c in ts_data.get("classes", [])}
102
+ for c in file_data.get("classes", []):
103
+ ts_c = ts_classes.get(c["name"])
104
+ if ts_c:
105
+ c["bases"] = ts_c.get("bases", [])
106
+
107
+ file_data["imports"] = ts_data.get("imports", [])
108
+ file_data["variables"] = ts_data.get("variables", [])
109
+ except Exception as e:
110
+ debug_log(f"Tree-sitter supplement failed for {abs_path_str}: {e}")
111
+
112
+ writer.add_file_to_graph(file_data, repo_name, imports_map)
113
+
114
+ processed += 1
115
+ if job_id:
116
+ job_manager.update_job(job_id, processed_files=processed)
117
+ if processed % 50 == 0:
118
+ await asyncio.sleep(0)
119
+
120
+ info_logger(
121
+ f"[INHERITS] Resolving inheritance links across {len(files_data)} files..."
122
+ )
123
+ inheritance_batch, csharp_files = build_inheritance_and_csharp_files(
124
+ list(files_data.values()), imports_map
125
+ )
126
+ writer.write_inheritance_links(inheritance_batch, csharp_files, imports_map)
127
+
128
+ writer.write_scip_call_edges(files_data, name_from_symbol)
129
+
130
+ if job_id:
131
+ job_manager.update_job(job_id, status=JobStatus.COMPLETED, end_time=datetime.now())
132
+
133
+ except RuntimeError:
134
+ raise
135
+ except Exception as e:
136
+ error_logger(f"SCIP indexing failed for {path}: {e}")
137
+ if job_id:
138
+ job_manager.update_job(
139
+ job_id, status=JobStatus.FAILED, end_time=datetime.now(), errors=[str(e)]
140
+ )