codegraph-cli 2.0.0__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.
- codegraph_cli-2.0.0/LICENSE +21 -0
- codegraph_cli-2.0.0/PKG-INFO +318 -0
- codegraph_cli-2.0.0/README.md +266 -0
- codegraph_cli-2.0.0/codegraph_cli/__init__.py +4 -0
- codegraph_cli-2.0.0/codegraph_cli/agents.py +191 -0
- codegraph_cli-2.0.0/codegraph_cli/bug_detector.py +386 -0
- codegraph_cli-2.0.0/codegraph_cli/chat_agent.py +352 -0
- codegraph_cli-2.0.0/codegraph_cli/chat_session.py +220 -0
- codegraph_cli-2.0.0/codegraph_cli/cli.py +330 -0
- codegraph_cli-2.0.0/codegraph_cli/cli_chat.py +367 -0
- codegraph_cli-2.0.0/codegraph_cli/cli_diagnose.py +133 -0
- codegraph_cli-2.0.0/codegraph_cli/cli_refactor.py +230 -0
- codegraph_cli-2.0.0/codegraph_cli/cli_setup.py +470 -0
- codegraph_cli-2.0.0/codegraph_cli/cli_test.py +177 -0
- codegraph_cli-2.0.0/codegraph_cli/cli_v2.py +267 -0
- codegraph_cli-2.0.0/codegraph_cli/codegen_agent.py +265 -0
- codegraph_cli-2.0.0/codegraph_cli/config.py +31 -0
- codegraph_cli-2.0.0/codegraph_cli/config_manager.py +341 -0
- codegraph_cli-2.0.0/codegraph_cli/context_manager.py +500 -0
- codegraph_cli-2.0.0/codegraph_cli/crew_agents.py +123 -0
- codegraph_cli-2.0.0/codegraph_cli/crew_chat.py +159 -0
- codegraph_cli-2.0.0/codegraph_cli/crew_tools.py +497 -0
- codegraph_cli-2.0.0/codegraph_cli/diff_engine.py +265 -0
- codegraph_cli-2.0.0/codegraph_cli/embeddings.py +241 -0
- codegraph_cli-2.0.0/codegraph_cli/graph_export.py +144 -0
- codegraph_cli-2.0.0/codegraph_cli/llm.py +642 -0
- codegraph_cli-2.0.0/codegraph_cli/models.py +47 -0
- codegraph_cli-2.0.0/codegraph_cli/models_v2.py +185 -0
- codegraph_cli-2.0.0/codegraph_cli/orchestrator.py +49 -0
- codegraph_cli-2.0.0/codegraph_cli/parser.py +800 -0
- codegraph_cli-2.0.0/codegraph_cli/performance_analyzer.py +223 -0
- codegraph_cli-2.0.0/codegraph_cli/project_context.py +230 -0
- codegraph_cli-2.0.0/codegraph_cli/rag.py +200 -0
- codegraph_cli-2.0.0/codegraph_cli/refactor_agent.py +452 -0
- codegraph_cli-2.0.0/codegraph_cli/security_scanner.py +366 -0
- codegraph_cli-2.0.0/codegraph_cli/storage.py +390 -0
- codegraph_cli-2.0.0/codegraph_cli/templates/graph_interactive.html +257 -0
- codegraph_cli-2.0.0/codegraph_cli/testgen_agent.py +316 -0
- codegraph_cli-2.0.0/codegraph_cli/validation_engine.py +285 -0
- codegraph_cli-2.0.0/codegraph_cli/vector_store.py +293 -0
- codegraph_cli-2.0.0/codegraph_cli.egg-info/PKG-INFO +318 -0
- codegraph_cli-2.0.0/codegraph_cli.egg-info/SOURCES.txt +53 -0
- codegraph_cli-2.0.0/codegraph_cli.egg-info/dependency_links.txt +1 -0
- codegraph_cli-2.0.0/codegraph_cli.egg-info/entry_points.txt +2 -0
- codegraph_cli-2.0.0/codegraph_cli.egg-info/requires.txt +25 -0
- codegraph_cli-2.0.0/codegraph_cli.egg-info/top_level.txt +1 -0
- codegraph_cli-2.0.0/pyproject.toml +107 -0
- codegraph_cli-2.0.0/setup.cfg +4 -0
- codegraph_cli-2.0.0/tests/test_agents.py +146 -0
- codegraph_cli-2.0.0/tests/test_bug_detector.py +171 -0
- codegraph_cli-2.0.0/tests/test_cli.py +237 -0
- codegraph_cli-2.0.0/tests/test_parser.py +174 -0
- codegraph_cli-2.0.0/tests/test_security_scanner.py +163 -0
- codegraph_cli-2.0.0/tests/test_storage.py +285 -0
- codegraph_cli-2.0.0/tests/test_vector_store.py +205 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ali Nasir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codegraph-cli
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: AI-powered code intelligence CLI with multi-agent analysis, impact graphs, and conversational coding.
|
|
5
|
+
Author-email: Ali Nasir <ali@codegraph.dev>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/al1-nasir/codegraph-cli
|
|
8
|
+
Project-URL: Documentation, https://github.com/al1-nasir/codegraph-cli#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/al1-nasir/codegraph-cli
|
|
10
|
+
Project-URL: Issues, https://github.com/al1-nasir/codegraph-cli/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/al1-nasir/codegraph-cli/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: code-analysis,code-intelligence,cli,ai,code-graph,rag,impact-analysis,refactoring,crewai,multi-agent
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
16
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Environment :: Console
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: requests>=2.31.0
|
|
30
|
+
Requires-Dist: typer<1.0.0,>=0.12.0
|
|
31
|
+
Requires-Dist: toml>=0.10.2
|
|
32
|
+
Requires-Dist: lancedb>=0.4.0
|
|
33
|
+
Requires-Dist: pyarrow>=14.0.0
|
|
34
|
+
Requires-Dist: sentence-transformers>=2.2.0
|
|
35
|
+
Requires-Dist: tree-sitter>=0.24.0
|
|
36
|
+
Requires-Dist: tree-sitter-python>=0.23.0
|
|
37
|
+
Requires-Dist: tree-sitter-javascript>=0.23.0
|
|
38
|
+
Requires-Dist: tree-sitter-typescript>=0.23.0
|
|
39
|
+
Requires-Dist: litellm>=1.30.0
|
|
40
|
+
Provides-Extra: crew
|
|
41
|
+
Requires-Dist: crewai>=0.80.0; extra == "crew"
|
|
42
|
+
Provides-Extra: dev
|
|
43
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
44
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
45
|
+
Requires-Dist: pytest-mock>=3.11.0; extra == "dev"
|
|
46
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
47
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
48
|
+
Provides-Extra: all
|
|
49
|
+
Requires-Dist: crewai>=0.80.0; extra == "all"
|
|
50
|
+
Requires-Dist: google-generativeai>=0.5.0; extra == "all"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# CodeGraph CLI
|
|
54
|
+
|
|
55
|
+
**Code intelligence from the terminal. Semantic search, impact analysis, multi-agent code generation, and conversational coding — all backed by your choice of LLM.**
|
|
56
|
+
|
|
57
|
+
[](LICENSE)
|
|
58
|
+
[](https://www.python.org)
|
|
59
|
+
[](https://github.com/al1-nasir/codegraph-cli)
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Overview
|
|
64
|
+
|
|
65
|
+
CodeGraph CLI (`cg`) parses your codebase into a semantic graph, then exposes that graph through search, impact analysis, visualization, and a conversational interface. It supports six LLM providers and optionally runs a CrewAI multi-agent system that can read, write, patch, and rollback files autonomously.
|
|
66
|
+
|
|
67
|
+
Core capabilities:
|
|
68
|
+
|
|
69
|
+
- **Semantic Search** — find code by meaning, not string matching
|
|
70
|
+
- **Impact Analysis** — trace multi-hop dependencies before making changes
|
|
71
|
+
- **Graph Visualization** — interactive HTML and Graphviz DOT exports
|
|
72
|
+
- **Conversational Chat** — natural language coding sessions with RAG context
|
|
73
|
+
- **Multi-Agent System** — CrewAI-powered agents for code generation, refactoring, and analysis
|
|
74
|
+
- **File Rollback** — automatic backups before every file modification
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install codegraph-cli
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
With CrewAI multi-agent support:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install codegraph-cli[crew]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
For development:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
git clone https://github.com/al1-nasir/codegraph-cli.git
|
|
94
|
+
cd codegraph-cli
|
|
95
|
+
pip install -e ".[dev]"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Quick Start
|
|
101
|
+
|
|
102
|
+
### 1. Configure your LLM provider
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
cg setup
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
This runs an interactive wizard that writes configuration to `~/.codegraph/config.toml`. Alternatively, switch providers directly:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
cg set-llm openrouter
|
|
112
|
+
cg set-llm groq
|
|
113
|
+
cg set-llm ollama
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 2. Index a project
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
cg index /path/to/project --name myproject
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
This parses the source tree using tree-sitter, builds a dependency graph in SQLite, and generates embeddings for semantic search.
|
|
123
|
+
|
|
124
|
+
### 3. Use it
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
cg search "authentication logic"
|
|
128
|
+
cg impact UserService --hops 3
|
|
129
|
+
cg graph process_payment --depth 2
|
|
130
|
+
cg chat start
|
|
131
|
+
cg chat start --crew # multi-agent mode
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Supported LLM Providers
|
|
137
|
+
|
|
138
|
+
| Provider | Type | Configuration |
|
|
139
|
+
|----------|------|---------------|
|
|
140
|
+
| Ollama | Local, free | `cg set-llm ollama` |
|
|
141
|
+
| Groq | Cloud, free tier | `cg set-llm groq` |
|
|
142
|
+
| OpenAI | Cloud | `cg set-llm openai` |
|
|
143
|
+
| Anthropic | Cloud | `cg set-llm anthropic` |
|
|
144
|
+
| Gemini | Cloud | `cg set-llm gemini` |
|
|
145
|
+
| OpenRouter | Cloud, multi-model | `cg set-llm openrouter` |
|
|
146
|
+
|
|
147
|
+
All configuration is stored in `~/.codegraph/config.toml`. No environment variables required.
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
cg show-llm # view current provider, model, and endpoint
|
|
151
|
+
cg unset-llm # reset to defaults
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Commands
|
|
157
|
+
|
|
158
|
+
### Project Management
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
cg index <path> [--name NAME] # parse and index a codebase
|
|
162
|
+
cg list-projects # list all indexed projects
|
|
163
|
+
cg load-project <name> # switch active project
|
|
164
|
+
cg current-project # print active project name
|
|
165
|
+
cg delete-project <name> # remove a project index
|
|
166
|
+
cg merge-projects <src> <dst> # merge two project graphs
|
|
167
|
+
cg unload-project # unload without deleting
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Search and Analysis
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
cg search <query> [--top-k N] # semantic search across the graph
|
|
174
|
+
cg impact <symbol> [--hops N] # multi-hop dependency impact analysis
|
|
175
|
+
cg graph <symbol> [--depth N] # ASCII dependency graph
|
|
176
|
+
cg rag-context <query> [--top-k N] # raw RAG retrieval for debugging
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Graph Export
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
cg export-graph --format html # interactive vis.js visualization
|
|
183
|
+
cg export-graph --format dot # Graphviz DOT format
|
|
184
|
+
cg export-graph MyClass -f html -o out.html # focused subgraph
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Interactive Chat
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
cg chat start # start or resume a session
|
|
191
|
+
cg chat start --new # force a new session
|
|
192
|
+
cg chat start --crew # multi-agent mode (CrewAI)
|
|
193
|
+
cg chat start -s <id> # resume a specific session
|
|
194
|
+
cg chat list # list all sessions
|
|
195
|
+
cg chat delete <id> # delete a session
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
In-chat commands:
|
|
199
|
+
|
|
200
|
+
| Command | Mode | Description |
|
|
201
|
+
|---------|------|-------------|
|
|
202
|
+
| `/help` | Both | Show available commands |
|
|
203
|
+
| `/clear` | Both | Clear conversation history |
|
|
204
|
+
| `/new` | Both | Start a fresh session |
|
|
205
|
+
| `/exit` | Both | Save and exit |
|
|
206
|
+
| `/apply` | Standard | Apply pending code proposal |
|
|
207
|
+
| `/preview` | Standard | Preview pending file changes |
|
|
208
|
+
| `/backups` | Crew | List all file backups |
|
|
209
|
+
| `/rollback <file>` | Crew | Restore a file from backup |
|
|
210
|
+
| `/undo <file>` | Crew | Alias for rollback |
|
|
211
|
+
|
|
212
|
+
### Code Generation (v2)
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
cg v2 generate "add a REST endpoint for user deletion"
|
|
216
|
+
cg v2 review src/auth.py --check-security
|
|
217
|
+
cg v2 refactor rename-symbol OldName NewName
|
|
218
|
+
cg v2 refactor extract-function target_fn 45 60
|
|
219
|
+
cg v2 test unit process_payment
|
|
220
|
+
cg v2 diagnose check src/
|
|
221
|
+
cg v2 diagnose fix src/auth.py
|
|
222
|
+
cg v2 rollback <file>
|
|
223
|
+
cg v2 list-backups
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Multi-Agent System
|
|
229
|
+
|
|
230
|
+
When you run `cg chat start --crew`, CodeGraph launches a CrewAI pipeline with four specialized agents:
|
|
231
|
+
|
|
232
|
+
| Agent | Role | Tools |
|
|
233
|
+
|-------|------|-------|
|
|
234
|
+
| Project Coordinator | Routes tasks to the right specialist | Delegation only |
|
|
235
|
+
| File System Engineer | File I/O, directory traversal, backups | list_directory, read_file, write_file, patch_file, delete_file, rollback_file, file_tree |
|
|
236
|
+
| Senior Software Developer | Code generation, refactoring, bug fixes | All tools (file ops + code analysis) |
|
|
237
|
+
| Code Intelligence Analyst | Search, dependency tracing, explanations | search_code, grep, project_summary, read_file |
|
|
238
|
+
|
|
239
|
+
Every file modification automatically creates a timestamped backup in `~/.codegraph/backups/`. Files can be rolled back to any previous state via `/rollback` or `cg v2 rollback`.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Architecture
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
CLI Layer (Typer)
|
|
247
|
+
|
|
|
248
|
+
+-- MCPOrchestrator ----------> GraphStore (SQLite)
|
|
249
|
+
| | |
|
|
250
|
+
| +-- Parser (tree-sitter) +-- VectorStore (LanceDB)
|
|
251
|
+
| +-- RAGRetriever |
|
|
252
|
+
| +-- LLM Adapter +-- Embeddings
|
|
253
|
+
|
|
|
254
|
+
+-- ChatAgent (standard mode)
|
|
255
|
+
|
|
|
256
|
+
+-- CrewChatAgent (--crew mode)
|
|
257
|
+
|
|
|
258
|
+
+-- Coordinator Agent
|
|
259
|
+
+-- File System Agent -----> 8 file operation tools
|
|
260
|
+
+-- Code Gen Agent --------> all 11 tools
|
|
261
|
+
+-- Code Analysis Agent ---> 3 search/analysis tools
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Parser**: tree-sitter grammars for Python, JavaScript, and TypeScript. Extracts modules, classes, functions, imports, and call relationships into a directed graph.
|
|
265
|
+
|
|
266
|
+
**Storage**: SQLite for the code graph (nodes + edges), LanceDB for vector embeddings. All data stored under `~/.codegraph/`.
|
|
267
|
+
|
|
268
|
+
**LLM Adapter**: Unified interface across six providers. For CrewAI, models are routed through LiteLLM. Configuration is read exclusively from `~/.codegraph/config.toml`.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Project Structure
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
codegraph_cli/
|
|
276
|
+
cli.py # main Typer application, all top-level commands
|
|
277
|
+
cli_chat.py # interactive chat REPL with styled output
|
|
278
|
+
cli_setup.py # setup wizard, set-llm, unset-llm, show-llm
|
|
279
|
+
cli_v2.py # v2 code generation commands
|
|
280
|
+
config.py # loads config from TOML
|
|
281
|
+
config_manager.py # TOML read/write, provider validation
|
|
282
|
+
llm.py # multi-provider LLM adapter
|
|
283
|
+
parser.py # tree-sitter AST parsing
|
|
284
|
+
storage.py # SQLite graph store
|
|
285
|
+
embeddings.py # hash-based embedding model
|
|
286
|
+
rag.py # RAG retriever
|
|
287
|
+
vector_store.py # LanceDB vector store
|
|
288
|
+
orchestrator.py # coordinates parsing, search, impact
|
|
289
|
+
graph_export.py # DOT and HTML export
|
|
290
|
+
project_context.py # unified file access layer
|
|
291
|
+
crew_tools.py # 11 CrewAI tools (file ops + analysis)
|
|
292
|
+
crew_agents.py # 4 specialized CrewAI agents
|
|
293
|
+
crew_chat.py # CrewAI orchestrator with rollback
|
|
294
|
+
chat_agent.py # standard chat agent
|
|
295
|
+
chat_session.py # session persistence
|
|
296
|
+
models.py # core data models
|
|
297
|
+
models_v2.py # v2 models (ChatSession, CodeProposal)
|
|
298
|
+
templates/
|
|
299
|
+
graph_interactive.html # vis.js graph template
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Development
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
git clone https://github.com/al1-nasir/codegraph-cli.git
|
|
308
|
+
cd codegraph-cli
|
|
309
|
+
python -m venv .venv && source .venv/bin/activate
|
|
310
|
+
pip install -e ".[dev,crew]"
|
|
311
|
+
pytest
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## License
|
|
317
|
+
|
|
318
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# CodeGraph CLI
|
|
2
|
+
|
|
3
|
+
**Code intelligence from the terminal. Semantic search, impact analysis, multi-agent code generation, and conversational coding — all backed by your choice of LLM.**
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://www.python.org)
|
|
7
|
+
[](https://github.com/al1-nasir/codegraph-cli)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
CodeGraph CLI (`cg`) parses your codebase into a semantic graph, then exposes that graph through search, impact analysis, visualization, and a conversational interface. It supports six LLM providers and optionally runs a CrewAI multi-agent system that can read, write, patch, and rollback files autonomously.
|
|
14
|
+
|
|
15
|
+
Core capabilities:
|
|
16
|
+
|
|
17
|
+
- **Semantic Search** — find code by meaning, not string matching
|
|
18
|
+
- **Impact Analysis** — trace multi-hop dependencies before making changes
|
|
19
|
+
- **Graph Visualization** — interactive HTML and Graphviz DOT exports
|
|
20
|
+
- **Conversational Chat** — natural language coding sessions with RAG context
|
|
21
|
+
- **Multi-Agent System** — CrewAI-powered agents for code generation, refactoring, and analysis
|
|
22
|
+
- **File Rollback** — automatic backups before every file modification
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install codegraph-cli
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
With CrewAI multi-agent support:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install codegraph-cli[crew]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For development:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
git clone https://github.com/al1-nasir/codegraph-cli.git
|
|
42
|
+
cd codegraph-cli
|
|
43
|
+
pip install -e ".[dev]"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
### 1. Configure your LLM provider
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
cg setup
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This runs an interactive wizard that writes configuration to `~/.codegraph/config.toml`. Alternatively, switch providers directly:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cg set-llm openrouter
|
|
60
|
+
cg set-llm groq
|
|
61
|
+
cg set-llm ollama
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. Index a project
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
cg index /path/to/project --name myproject
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
This parses the source tree using tree-sitter, builds a dependency graph in SQLite, and generates embeddings for semantic search.
|
|
71
|
+
|
|
72
|
+
### 3. Use it
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
cg search "authentication logic"
|
|
76
|
+
cg impact UserService --hops 3
|
|
77
|
+
cg graph process_payment --depth 2
|
|
78
|
+
cg chat start
|
|
79
|
+
cg chat start --crew # multi-agent mode
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Supported LLM Providers
|
|
85
|
+
|
|
86
|
+
| Provider | Type | Configuration |
|
|
87
|
+
|----------|------|---------------|
|
|
88
|
+
| Ollama | Local, free | `cg set-llm ollama` |
|
|
89
|
+
| Groq | Cloud, free tier | `cg set-llm groq` |
|
|
90
|
+
| OpenAI | Cloud | `cg set-llm openai` |
|
|
91
|
+
| Anthropic | Cloud | `cg set-llm anthropic` |
|
|
92
|
+
| Gemini | Cloud | `cg set-llm gemini` |
|
|
93
|
+
| OpenRouter | Cloud, multi-model | `cg set-llm openrouter` |
|
|
94
|
+
|
|
95
|
+
All configuration is stored in `~/.codegraph/config.toml`. No environment variables required.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
cg show-llm # view current provider, model, and endpoint
|
|
99
|
+
cg unset-llm # reset to defaults
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Commands
|
|
105
|
+
|
|
106
|
+
### Project Management
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
cg index <path> [--name NAME] # parse and index a codebase
|
|
110
|
+
cg list-projects # list all indexed projects
|
|
111
|
+
cg load-project <name> # switch active project
|
|
112
|
+
cg current-project # print active project name
|
|
113
|
+
cg delete-project <name> # remove a project index
|
|
114
|
+
cg merge-projects <src> <dst> # merge two project graphs
|
|
115
|
+
cg unload-project # unload without deleting
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Search and Analysis
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
cg search <query> [--top-k N] # semantic search across the graph
|
|
122
|
+
cg impact <symbol> [--hops N] # multi-hop dependency impact analysis
|
|
123
|
+
cg graph <symbol> [--depth N] # ASCII dependency graph
|
|
124
|
+
cg rag-context <query> [--top-k N] # raw RAG retrieval for debugging
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Graph Export
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
cg export-graph --format html # interactive vis.js visualization
|
|
131
|
+
cg export-graph --format dot # Graphviz DOT format
|
|
132
|
+
cg export-graph MyClass -f html -o out.html # focused subgraph
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Interactive Chat
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
cg chat start # start or resume a session
|
|
139
|
+
cg chat start --new # force a new session
|
|
140
|
+
cg chat start --crew # multi-agent mode (CrewAI)
|
|
141
|
+
cg chat start -s <id> # resume a specific session
|
|
142
|
+
cg chat list # list all sessions
|
|
143
|
+
cg chat delete <id> # delete a session
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
In-chat commands:
|
|
147
|
+
|
|
148
|
+
| Command | Mode | Description |
|
|
149
|
+
|---------|------|-------------|
|
|
150
|
+
| `/help` | Both | Show available commands |
|
|
151
|
+
| `/clear` | Both | Clear conversation history |
|
|
152
|
+
| `/new` | Both | Start a fresh session |
|
|
153
|
+
| `/exit` | Both | Save and exit |
|
|
154
|
+
| `/apply` | Standard | Apply pending code proposal |
|
|
155
|
+
| `/preview` | Standard | Preview pending file changes |
|
|
156
|
+
| `/backups` | Crew | List all file backups |
|
|
157
|
+
| `/rollback <file>` | Crew | Restore a file from backup |
|
|
158
|
+
| `/undo <file>` | Crew | Alias for rollback |
|
|
159
|
+
|
|
160
|
+
### Code Generation (v2)
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
cg v2 generate "add a REST endpoint for user deletion"
|
|
164
|
+
cg v2 review src/auth.py --check-security
|
|
165
|
+
cg v2 refactor rename-symbol OldName NewName
|
|
166
|
+
cg v2 refactor extract-function target_fn 45 60
|
|
167
|
+
cg v2 test unit process_payment
|
|
168
|
+
cg v2 diagnose check src/
|
|
169
|
+
cg v2 diagnose fix src/auth.py
|
|
170
|
+
cg v2 rollback <file>
|
|
171
|
+
cg v2 list-backups
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Multi-Agent System
|
|
177
|
+
|
|
178
|
+
When you run `cg chat start --crew`, CodeGraph launches a CrewAI pipeline with four specialized agents:
|
|
179
|
+
|
|
180
|
+
| Agent | Role | Tools |
|
|
181
|
+
|-------|------|-------|
|
|
182
|
+
| Project Coordinator | Routes tasks to the right specialist | Delegation only |
|
|
183
|
+
| File System Engineer | File I/O, directory traversal, backups | list_directory, read_file, write_file, patch_file, delete_file, rollback_file, file_tree |
|
|
184
|
+
| Senior Software Developer | Code generation, refactoring, bug fixes | All tools (file ops + code analysis) |
|
|
185
|
+
| Code Intelligence Analyst | Search, dependency tracing, explanations | search_code, grep, project_summary, read_file |
|
|
186
|
+
|
|
187
|
+
Every file modification automatically creates a timestamped backup in `~/.codegraph/backups/`. Files can be rolled back to any previous state via `/rollback` or `cg v2 rollback`.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Architecture
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
CLI Layer (Typer)
|
|
195
|
+
|
|
|
196
|
+
+-- MCPOrchestrator ----------> GraphStore (SQLite)
|
|
197
|
+
| | |
|
|
198
|
+
| +-- Parser (tree-sitter) +-- VectorStore (LanceDB)
|
|
199
|
+
| +-- RAGRetriever |
|
|
200
|
+
| +-- LLM Adapter +-- Embeddings
|
|
201
|
+
|
|
|
202
|
+
+-- ChatAgent (standard mode)
|
|
203
|
+
|
|
|
204
|
+
+-- CrewChatAgent (--crew mode)
|
|
205
|
+
|
|
|
206
|
+
+-- Coordinator Agent
|
|
207
|
+
+-- File System Agent -----> 8 file operation tools
|
|
208
|
+
+-- Code Gen Agent --------> all 11 tools
|
|
209
|
+
+-- Code Analysis Agent ---> 3 search/analysis tools
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Parser**: tree-sitter grammars for Python, JavaScript, and TypeScript. Extracts modules, classes, functions, imports, and call relationships into a directed graph.
|
|
213
|
+
|
|
214
|
+
**Storage**: SQLite for the code graph (nodes + edges), LanceDB for vector embeddings. All data stored under `~/.codegraph/`.
|
|
215
|
+
|
|
216
|
+
**LLM Adapter**: Unified interface across six providers. For CrewAI, models are routed through LiteLLM. Configuration is read exclusively from `~/.codegraph/config.toml`.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Project Structure
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
codegraph_cli/
|
|
224
|
+
cli.py # main Typer application, all top-level commands
|
|
225
|
+
cli_chat.py # interactive chat REPL with styled output
|
|
226
|
+
cli_setup.py # setup wizard, set-llm, unset-llm, show-llm
|
|
227
|
+
cli_v2.py # v2 code generation commands
|
|
228
|
+
config.py # loads config from TOML
|
|
229
|
+
config_manager.py # TOML read/write, provider validation
|
|
230
|
+
llm.py # multi-provider LLM adapter
|
|
231
|
+
parser.py # tree-sitter AST parsing
|
|
232
|
+
storage.py # SQLite graph store
|
|
233
|
+
embeddings.py # hash-based embedding model
|
|
234
|
+
rag.py # RAG retriever
|
|
235
|
+
vector_store.py # LanceDB vector store
|
|
236
|
+
orchestrator.py # coordinates parsing, search, impact
|
|
237
|
+
graph_export.py # DOT and HTML export
|
|
238
|
+
project_context.py # unified file access layer
|
|
239
|
+
crew_tools.py # 11 CrewAI tools (file ops + analysis)
|
|
240
|
+
crew_agents.py # 4 specialized CrewAI agents
|
|
241
|
+
crew_chat.py # CrewAI orchestrator with rollback
|
|
242
|
+
chat_agent.py # standard chat agent
|
|
243
|
+
chat_session.py # session persistence
|
|
244
|
+
models.py # core data models
|
|
245
|
+
models_v2.py # v2 models (ChatSession, CodeProposal)
|
|
246
|
+
templates/
|
|
247
|
+
graph_interactive.html # vis.js graph template
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Development
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
git clone https://github.com/al1-nasir/codegraph-cli.git
|
|
256
|
+
cd codegraph-cli
|
|
257
|
+
python -m venv .venv && source .venv/bin/activate
|
|
258
|
+
pip install -e ".[dev,crew]"
|
|
259
|
+
pytest
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
MIT. See [LICENSE](LICENSE).
|