codegraphcontext 0.1.19__tar.gz → 0.1.21__tar.gz

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 (65) hide show
  1. {codegraphcontext-0.1.19/src/codegraphcontext.egg-info → codegraphcontext-0.1.21}/PKG-INFO +14 -13
  2. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/README.md +12 -11
  3. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/pyproject.toml +2 -2
  4. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/cli/cli_helpers.py +188 -0
  5. codegraphcontext-0.1.21/src/codegraphcontext/cli/config_manager.py +297 -0
  6. codegraphcontext-0.1.21/src/codegraphcontext/cli/main.py +1290 -0
  7. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/cli/setup_wizard.py +67 -3
  8. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/code_finder.py +72 -15
  9. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21/src/codegraphcontext.egg-info}/PKG-INFO +14 -13
  10. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext.egg-info/SOURCES.txt +1 -0
  11. codegraphcontext-0.1.19/src/codegraphcontext/cli/main.py +0 -306
  12. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/LICENSE +0 -0
  13. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/MANIFEST.in +0 -0
  14. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/setup.cfg +0 -0
  15. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/__init__.py +0 -0
  16. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/__main__.py +0 -0
  17. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/cli/__init__.py +0 -0
  18. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/cli/setup_macos.py +0 -0
  19. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/core/__init__.py +0 -0
  20. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/core/database.py +0 -0
  21. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/core/database_falkordb.py +0 -0
  22. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/core/falkor_worker.py +0 -0
  23. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/core/jobs.py +0 -0
  24. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/core/watcher.py +0 -0
  25. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/prompts.py +0 -0
  26. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/server.py +0 -0
  27. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/__init__.py +0 -0
  28. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/advanced_language_query_tool.py +0 -0
  29. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/graph_builder.py +0 -0
  30. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/c.py +0 -0
  31. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/cpp.py +0 -0
  32. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/csharp.py +0 -0
  33. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/go.py +0 -0
  34. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/java.py +0 -0
  35. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/javascript.py +0 -0
  36. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/php.py +0 -0
  37. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/python.py +0 -0
  38. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/ruby.py +0 -0
  39. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/rust.py +0 -0
  40. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/languages/typescript.py +0 -0
  41. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/package_resolver.py +0 -0
  42. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/c_toolkit.py +0 -0
  43. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/cpp_toolkit.py +0 -0
  44. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/csharp_toolkit.py +0 -0
  45. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/go_toolkit.py +0 -0
  46. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/java_toolkit.py +0 -0
  47. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/javascript_toolkit.py +0 -0
  48. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/python_toolkit.py +0 -0
  49. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/ruby_toolkit.py +0 -0
  50. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/rust_toolkit.py +0 -0
  51. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/query_tool_languages/typescript_toolkit.py +0 -0
  52. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/tools/system.py +0 -0
  53. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/utils/debug_log.py +0 -0
  54. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext/utils/tree_sitter_manager.py +0 -0
  55. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext.egg-info/dependency_links.txt +0 -0
  56. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext.egg-info/entry_points.txt +0 -0
  57. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext.egg-info/requires.txt +0 -0
  58. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/src/codegraphcontext.egg-info/top_level.txt +0 -0
  59. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/tests/test_cpp_parser.py +0 -0
  60. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/tests/test_database_validation.py +0 -0
  61. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/tests/test_end_to_end.py +0 -0
  62. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/tests/test_graph_indexing.py +0 -0
  63. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/tests/test_graph_indexing_js.py +0 -0
  64. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/tests/test_tree_sitter_manager.py +0 -0
  65. {codegraphcontext-0.1.19 → codegraphcontext-0.1.21}/tests/test_typescript_parser.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codegraphcontext
3
- Version: 0.1.19
3
+ Version: 0.1.21
4
4
  Summary: An MCP server that indexes local code into a graph database to provide context to AI assistants.
5
5
  Author-email: Shashank Shekhar Singh <shashankshekharsingh1205@gmail.com>
6
6
  License: MIT License
@@ -33,7 +33,7 @@ Classifier: Operating System :: OS Independent
33
33
  Classifier: Development Status :: 3 - Alpha
34
34
  Classifier: Intended Audience :: Developers
35
35
  Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
36
- Requires-Python: >=3.9
36
+ Requires-Python: >=3.10
37
37
  Description-Content-Type: text/markdown
38
38
  License-File: LICENSE
39
39
  Requires-Dist: neo4j>=5.15.0
@@ -82,7 +82,7 @@ Dynamic: license-file
82
82
 
83
83
 
84
84
 
85
- An MCP server that indexes local code into a graph database to provide context to AI assistants.
85
+ A powerful **MCP server** and **CLI tool** that indexes local code into a graph database to provide context to AI assistants and developers. Use it as a standalone CLI for code analysis or connect it to your favorite AI IDE via MCP.
86
86
 
87
87
  ### Indexing a codebase
88
88
  ![Indexing using an MCP client](https://github.com/Shashankss1205/CodeGraphContext/blob/main/images/Indexing.gif)
@@ -91,7 +91,7 @@ An MCP server that indexes local code into a graph database to provide context t
91
91
  ![Using the MCP server](https://github.com/Shashankss1205/CodeGraphContext/blob/main/images/Usecase.gif)
92
92
 
93
93
  ## Project Details
94
- - **Version:** 0.1.19
94
+ - **Version:** 0.1.21
95
95
  - **Authors:** Shashank Shekhar Singh <shashankshekharsingh1205@gmail.com>
96
96
  - **License:** MIT License (See [LICENSE](LICENSE) for details)
97
97
  - **Website:** [CodeGraphContext](http://codegraphcontext.vercel.app/)
@@ -105,6 +105,7 @@ An MCP server that indexes local code into a graph database to provide context t
105
105
  - **Relationship Analysis:** Query for callers, callees, class hierarchies, call chains and more.
106
106
  - **Live Updates:** Watches local files for changes and automatically updates the graph.
107
107
  - **Interactive Setup:** A user-friendly command-line wizard for easy setup.
108
+ - **Dual Mode:** Works as a standalone **CLI tool** for developers and as an **MCP server** for AI agents.
108
109
  - **Multi-Language Support:** Full support for 11 programming languages.
109
110
  - **Flexible Database Backend:** Choose between Neo4j or FalkorDB Lite.
110
111
 
@@ -143,8 +144,8 @@ CodeGraphContext supports two graph database backends:
143
144
  - Perfect for quick testing and development
144
145
  - Automatically installed when using Python 3.12 or higher
145
146
 
146
- The `cgc setup` wizard helps you configure neo4j database backend while the falkordb database is
147
- supported inherently.
147
+ The `cgc neo4j setup` wizard helps you configure neo4j database backend while the falkordb database is
148
+ supported inherently (enabled by default).
148
149
 
149
150
  ## Used By
150
151
 
@@ -173,13 +174,13 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
173
174
  - `nbconvert>=7.16.6`
174
175
  - `pathspec>=0.12.1`
175
176
 
176
- **Note:** Python 3.9+ is supported, including Python 3.13 and 3.14.
177
+ **Note:** Python 3.10-3.14 is supported.
177
178
 
178
179
  ## Getting Started
179
180
 
180
181
  1. **Install:** `pip install codegraphcontext`
181
- 2. **Setup:** `cgc setup`
182
- This interactive command guides you through configuring your Neo4j database connection and automatically setting up your IDE.
182
+ 2. **Setup:** `cgc mcp setup`
183
+ This command configures your IDE to work with CodeGraphContext. To configure a Neo4j database, use `cgc neo4j setup`.
183
184
 
184
185
  <details>
185
186
  <summary>⚙️ Troubleshooting: In case, command <code>cgc</code> not found</summary>
@@ -217,7 +218,7 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
217
218
 
218
219
  **Database Configuration:**
219
220
  * **Local Setup (Docker Recommended):** Helps you set up a local Neo4j instance using Docker. Requires Docker and Docker Compose to be installed.
220
- * **Local Setup (Linux Binary):** For Debian-based Linux systems (like Ubuntu), `cgc setup` can automate the installation of Neo4j. Requires `sudo` privileges.
221
+ * **Local Setup (Linux Binary):** For Debian-based Linux systems (like Ubuntu), `cgc neo4j setup` can automate the installation of Neo4j. Requires `sudo` privileges.
221
222
  * **Hosted Setup:** Allows you to connect to an existing remote Neo4j database (e.g., Neo4j AuraDB).
222
223
 
223
224
  **IDE/CLI Configuration:**
@@ -232,12 +233,12 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
232
233
  * RooCode
233
234
  * Amazon Q Developer
234
235
 
235
- Upon successful configuration, `cgc setup` will generate and place the necessary configuration files:
236
+ Upon successful configuration, `cgc mcp setup` will generate and place the necessary configuration files:
236
237
  * It creates an `mcp.json` file in your current directory for reference.
237
238
  * It stores your Neo4j credentials securely in `~/.codegraphcontext/.env`.
238
239
  * It updates the settings file of your chosen IDE/CLI (e.g., `.claude.json` or VS Code's `settings.json`).
239
240
 
240
- 3. **Start:** `cgc start`
241
+ 3. **Start:** `cgc mcp start`
241
242
 
242
243
  ## Ignoring Files (`.cgcignore`)
243
244
 
@@ -259,7 +260,7 @@ You can tell CodeGraphContext to ignore specific files and directories by creati
259
260
 
260
261
  ## MCP Client Configuration
261
262
 
262
- The `cgc setup` command attempts to automatically configure your IDE/CLI. If you choose not to use the automatic setup, or if your tool is not supported, you can configure it manually.
263
+ The `cgc mcp setup` command attempts to automatically configure your IDE/CLI. If you choose not to use the automatic setup, or if your tool is not supported, you can configure it manually.
263
264
 
264
265
  Add the following server configuration to your client's settings file (e.g., VS Code's `settings.json` or `.claude.json`):
265
266
 
@@ -20,7 +20,7 @@
20
20
 
21
21
 
22
22
 
23
- An MCP server that indexes local code into a graph database to provide context to AI assistants.
23
+ A powerful **MCP server** and **CLI tool** that indexes local code into a graph database to provide context to AI assistants and developers. Use it as a standalone CLI for code analysis or connect it to your favorite AI IDE via MCP.
24
24
 
25
25
  ### Indexing a codebase
26
26
  ![Indexing using an MCP client](https://github.com/Shashankss1205/CodeGraphContext/blob/main/images/Indexing.gif)
@@ -29,7 +29,7 @@ An MCP server that indexes local code into a graph database to provide context t
29
29
  ![Using the MCP server](https://github.com/Shashankss1205/CodeGraphContext/blob/main/images/Usecase.gif)
30
30
 
31
31
  ## Project Details
32
- - **Version:** 0.1.19
32
+ - **Version:** 0.1.21
33
33
  - **Authors:** Shashank Shekhar Singh <shashankshekharsingh1205@gmail.com>
34
34
  - **License:** MIT License (See [LICENSE](LICENSE) for details)
35
35
  - **Website:** [CodeGraphContext](http://codegraphcontext.vercel.app/)
@@ -43,6 +43,7 @@ An MCP server that indexes local code into a graph database to provide context t
43
43
  - **Relationship Analysis:** Query for callers, callees, class hierarchies, call chains and more.
44
44
  - **Live Updates:** Watches local files for changes and automatically updates the graph.
45
45
  - **Interactive Setup:** A user-friendly command-line wizard for easy setup.
46
+ - **Dual Mode:** Works as a standalone **CLI tool** for developers and as an **MCP server** for AI agents.
46
47
  - **Multi-Language Support:** Full support for 11 programming languages.
47
48
  - **Flexible Database Backend:** Choose between Neo4j or FalkorDB Lite.
48
49
 
@@ -81,8 +82,8 @@ CodeGraphContext supports two graph database backends:
81
82
  - Perfect for quick testing and development
82
83
  - Automatically installed when using Python 3.12 or higher
83
84
 
84
- The `cgc setup` wizard helps you configure neo4j database backend while the falkordb database is
85
- supported inherently.
85
+ The `cgc neo4j setup` wizard helps you configure neo4j database backend while the falkordb database is
86
+ supported inherently (enabled by default).
86
87
 
87
88
  ## Used By
88
89
 
@@ -111,13 +112,13 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
111
112
  - `nbconvert>=7.16.6`
112
113
  - `pathspec>=0.12.1`
113
114
 
114
- **Note:** Python 3.9+ is supported, including Python 3.13 and 3.14.
115
+ **Note:** Python 3.10-3.14 is supported.
115
116
 
116
117
  ## Getting Started
117
118
 
118
119
  1. **Install:** `pip install codegraphcontext`
119
- 2. **Setup:** `cgc setup`
120
- This interactive command guides you through configuring your Neo4j database connection and automatically setting up your IDE.
120
+ 2. **Setup:** `cgc mcp setup`
121
+ This command configures your IDE to work with CodeGraphContext. To configure a Neo4j database, use `cgc neo4j setup`.
121
122
 
122
123
  <details>
123
124
  <summary>⚙️ Troubleshooting: In case, command <code>cgc</code> not found</summary>
@@ -155,7 +156,7 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
155
156
 
156
157
  **Database Configuration:**
157
158
  * **Local Setup (Docker Recommended):** Helps you set up a local Neo4j instance using Docker. Requires Docker and Docker Compose to be installed.
158
- * **Local Setup (Linux Binary):** For Debian-based Linux systems (like Ubuntu), `cgc setup` can automate the installation of Neo4j. Requires `sudo` privileges.
159
+ * **Local Setup (Linux Binary):** For Debian-based Linux systems (like Ubuntu), `cgc neo4j setup` can automate the installation of Neo4j. Requires `sudo` privileges.
159
160
  * **Hosted Setup:** Allows you to connect to an existing remote Neo4j database (e.g., Neo4j AuraDB).
160
161
 
161
162
  **IDE/CLI Configuration:**
@@ -170,12 +171,12 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
170
171
  * RooCode
171
172
  * Amazon Q Developer
172
173
 
173
- Upon successful configuration, `cgc setup` will generate and place the necessary configuration files:
174
+ Upon successful configuration, `cgc mcp setup` will generate and place the necessary configuration files:
174
175
  * It creates an `mcp.json` file in your current directory for reference.
175
176
  * It stores your Neo4j credentials securely in `~/.codegraphcontext/.env`.
176
177
  * It updates the settings file of your chosen IDE/CLI (e.g., `.claude.json` or VS Code's `settings.json`).
177
178
 
178
- 3. **Start:** `cgc start`
179
+ 3. **Start:** `cgc mcp start`
179
180
 
180
181
  ## Ignoring Files (`.cgcignore`)
181
182
 
@@ -197,7 +198,7 @@ You can tell CodeGraphContext to ignore specific files and directories by creati
197
198
 
198
199
  ## MCP Client Configuration
199
200
 
200
- The `cgc setup` command attempts to automatically configure your IDE/CLI. If you choose not to use the automatic setup, or if your tool is not supported, you can configure it manually.
201
+ The `cgc mcp setup` command attempts to automatically configure your IDE/CLI. If you choose not to use the automatic setup, or if your tool is not supported, you can configure it manually.
201
202
 
202
203
  Add the following server configuration to your client's settings file (e.g., VS Code's `settings.json` or `.claude.json`):
203
204
 
@@ -1,11 +1,11 @@
1
1
  [project]
2
2
  name = "codegraphcontext"
3
- version = "0.1.19"
3
+ version = "0.1.21"
4
4
  description = "An MCP server that indexes local code into a graph database to provide context to AI assistants."
5
5
  authors = [{ name = "Shashank Shekhar Singh", email = "shashankshekharsingh1205@gmail.com" }]
6
6
  readme = "README.md"
7
7
  license = { file = "LICENSE" }
8
- requires-python = ">=3.9"
8
+ requires-python = ">=3.10"
9
9
  classifiers = [
10
10
  "Programming Language :: Python :: 3",
11
11
  "License :: OSI Approved :: MIT License",
@@ -324,3 +324,191 @@ def _visualize_falkordb(db_manager):
324
324
  db_manager.close_driver()
325
325
 
326
326
 
327
+ def reindex_helper(path: str):
328
+ """Force re-index by deleting and rebuilding the repository."""
329
+ time_start = time.time()
330
+ services = _initialize_services()
331
+ if not all(services):
332
+ return
333
+
334
+ db_manager, graph_builder, code_finder = services
335
+ path_obj = Path(path).resolve()
336
+
337
+ if not path_obj.exists():
338
+ console.print(f"[red]Error: Path does not exist: {path_obj}[/red]")
339
+ db_manager.close_driver()
340
+ return
341
+
342
+ # Check if already indexed
343
+ indexed_repos = code_finder.list_indexed_repositories()
344
+ repo_exists = any(Path(repo["path"]).resolve() == path_obj for repo in indexed_repos)
345
+
346
+ if repo_exists:
347
+ console.print(f"[yellow]Deleting existing index for: {path_obj}[/yellow]")
348
+ try:
349
+ graph_builder.delete_repository_from_graph(str(path_obj))
350
+ console.print("[green]✓[/green] Deleted old index")
351
+ except Exception as e:
352
+ console.print(f"[red]Error deleting old index: {e}[/red]")
353
+ db_manager.close_driver()
354
+ return
355
+
356
+ console.print(f"[cyan]Re-indexing: {path_obj}[/cyan]")
357
+ console.print("[yellow]This may take a few minutes for large repositories...[/yellow]")
358
+
359
+ async def do_index():
360
+ await graph_builder.build_graph_from_path_async(path_obj, is_dependency=False)
361
+
362
+ try:
363
+ asyncio.run(do_index())
364
+ time_end = time.time()
365
+ elapsed = time_end - time_start
366
+ console.print(f"[green]Successfully re-indexed: {path} in {elapsed:.2f} seconds[/green]")
367
+ except Exception as e:
368
+ console.print(f"[bold red]An error occurred during re-indexing:[/bold red] {e}")
369
+ finally:
370
+ db_manager.close_driver()
371
+
372
+
373
+ def update_helper(path: str):
374
+ """Update/refresh index for a path (alias for reindex)."""
375
+ console.print("[cyan]Updating repository index...[/cyan]")
376
+ reindex_helper(path)
377
+
378
+
379
+ def clean_helper():
380
+ """Remove orphaned nodes and relationships from the database."""
381
+ services = _initialize_services()
382
+ if not all(services):
383
+ return
384
+
385
+ db_manager, _, _ = services
386
+
387
+ console.print("[cyan]🧹 Cleaning database (removing orphaned nodes)...[/cyan]")
388
+
389
+ try:
390
+ with db_manager.get_driver().session() as session:
391
+ # Find and delete orphaned nodes (nodes not connected to any repository)
392
+ query = """
393
+ MATCH (n)
394
+ WHERE NOT (n:Repository) AND NOT EXISTS((n)-[]-(:Repository))
395
+ WITH n LIMIT 1000
396
+ DETACH DELETE n
397
+ RETURN count(n) as deleted
398
+ """
399
+ result = session.run(query)
400
+ record = result.single()
401
+ deleted_count = record["deleted"] if record else 0
402
+
403
+ if deleted_count > 0:
404
+ console.print(f"[green]✓[/green] Deleted {deleted_count} orphaned nodes")
405
+ else:
406
+ console.print("[green]✓[/green] No orphaned nodes found")
407
+
408
+ # Clean up any duplicate relationships (if any)
409
+ console.print("[dim]Checking for duplicate relationships...[/dim]")
410
+ # Note: This is database-specific and might not work for all backends
411
+
412
+ console.print("[green]✅ Database cleanup complete![/green]")
413
+ except Exception as e:
414
+ console.print(f"[bold red]An error occurred during cleanup:[/bold red] {e}")
415
+ finally:
416
+ db_manager.close_driver()
417
+
418
+
419
+ def stats_helper(path: str = None):
420
+ """Show indexing statistics for a repository or overall."""
421
+ services = _initialize_services()
422
+ if not all(services):
423
+ return
424
+
425
+ db_manager, _, code_finder = services
426
+
427
+ try:
428
+ if path:
429
+ # Stats for specific repository
430
+ path_obj = Path(path).resolve()
431
+ console.print(f"[cyan]📊 Statistics for: {path_obj}[/cyan]\n")
432
+
433
+ with db_manager.get_driver().session() as session:
434
+ # Get repository node
435
+ repo_query = """
436
+ MATCH (r:Repository {path: $path})
437
+ RETURN r
438
+ """
439
+ result = session.run(repo_query, path=str(path_obj))
440
+ if not result.single():
441
+ console.print(f"[red]Repository not found: {path_obj}[/red]")
442
+ return
443
+
444
+ # Get stats
445
+ stats_query = """
446
+ MATCH (r:Repository {path: $path})-[:CONTAINS]->(f:File)
447
+ WITH r, count(f) as file_count, f
448
+ OPTIONAL MATCH (f)-[:CONTAINS]->(func:Function)
449
+ OPTIONAL MATCH (f)-[:CONTAINS]->(cls:Class)
450
+ OPTIONAL MATCH (f)-[:IMPORTS]->(m:Module)
451
+ RETURN
452
+ file_count,
453
+ count(DISTINCT func) as function_count,
454
+ count(DISTINCT cls) as class_count,
455
+ count(DISTINCT m) as module_count
456
+ """
457
+ result = session.run(stats_query, path=str(path_obj))
458
+ record = result.single()
459
+
460
+ table = Table(show_header=True, header_style="bold magenta")
461
+ table.add_column("Metric", style="cyan")
462
+ table.add_column("Count", style="green", justify="right")
463
+
464
+ table.add_row("Files", str(record["file_count"] if record else 0))
465
+ table.add_row("Functions", str(record["function_count"] if record else 0))
466
+ table.add_row("Classes", str(record["class_count"] if record else 0))
467
+ table.add_row("Imported Modules", str(record["module_count"] if record else 0))
468
+
469
+ console.print(table)
470
+ else:
471
+ # Overall stats
472
+ console.print("[cyan]📊 Overall Database Statistics[/cyan]\n")
473
+
474
+ with db_manager.get_driver().session() as session:
475
+ # Get overall counts
476
+ stats_query = """
477
+ MATCH (r:Repository)
478
+ WITH count(r) as repo_count
479
+ MATCH (f:File)
480
+ WITH repo_count, count(f) as file_count
481
+ MATCH (func:Function)
482
+ WITH repo_count, file_count, count(func) as function_count
483
+ MATCH (cls:Class)
484
+ WITH repo_count, file_count, function_count, count(cls) as class_count
485
+ MATCH (m:Module)
486
+ RETURN
487
+ repo_count,
488
+ file_count,
489
+ function_count,
490
+ class_count,
491
+ count(m) as module_count
492
+ """
493
+ result = session.run(stats_query)
494
+ record = result.single()
495
+
496
+ if record:
497
+ table = Table(show_header=True, header_style="bold magenta")
498
+ table.add_column("Metric", style="cyan")
499
+ table.add_column("Count", style="green", justify="right")
500
+
501
+ table.add_row("Repositories", str(record["repo_count"]))
502
+ table.add_row("Files", str(record["file_count"]))
503
+ table.add_row("Functions", str(record["function_count"]))
504
+ table.add_row("Classes", str(record["class_count"]))
505
+ table.add_row("Modules", str(record["module_count"]))
506
+
507
+ console.print(table)
508
+ else:
509
+ console.print("[yellow]No data indexed yet.[/yellow]")
510
+
511
+ except Exception as e:
512
+ console.print(f"[bold red]An error occurred:[/bold red] {e}")
513
+ finally:
514
+ db_manager.close_driver()