codegraph-cli 2.0.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.
- codegraph_cli/__init__.py +4 -0
- codegraph_cli/agents.py +191 -0
- codegraph_cli/bug_detector.py +386 -0
- codegraph_cli/chat_agent.py +352 -0
- codegraph_cli/chat_session.py +220 -0
- codegraph_cli/cli.py +330 -0
- codegraph_cli/cli_chat.py +367 -0
- codegraph_cli/cli_diagnose.py +133 -0
- codegraph_cli/cli_refactor.py +230 -0
- codegraph_cli/cli_setup.py +470 -0
- codegraph_cli/cli_test.py +177 -0
- codegraph_cli/cli_v2.py +267 -0
- codegraph_cli/codegen_agent.py +265 -0
- codegraph_cli/config.py +31 -0
- codegraph_cli/config_manager.py +341 -0
- codegraph_cli/context_manager.py +500 -0
- codegraph_cli/crew_agents.py +123 -0
- codegraph_cli/crew_chat.py +159 -0
- codegraph_cli/crew_tools.py +497 -0
- codegraph_cli/diff_engine.py +265 -0
- codegraph_cli/embeddings.py +241 -0
- codegraph_cli/graph_export.py +144 -0
- codegraph_cli/llm.py +642 -0
- codegraph_cli/models.py +47 -0
- codegraph_cli/models_v2.py +185 -0
- codegraph_cli/orchestrator.py +49 -0
- codegraph_cli/parser.py +800 -0
- codegraph_cli/performance_analyzer.py +223 -0
- codegraph_cli/project_context.py +230 -0
- codegraph_cli/rag.py +200 -0
- codegraph_cli/refactor_agent.py +452 -0
- codegraph_cli/security_scanner.py +366 -0
- codegraph_cli/storage.py +390 -0
- codegraph_cli/templates/graph_interactive.html +257 -0
- codegraph_cli/testgen_agent.py +316 -0
- codegraph_cli/validation_engine.py +285 -0
- codegraph_cli/vector_store.py +293 -0
- codegraph_cli-2.0.0.dist-info/METADATA +318 -0
- codegraph_cli-2.0.0.dist-info/RECORD +43 -0
- codegraph_cli-2.0.0.dist-info/WHEEL +5 -0
- codegraph_cli-2.0.0.dist-info/entry_points.txt +2 -0
- codegraph_cli-2.0.0.dist-info/licenses/LICENSE +21 -0
- codegraph_cli-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"""Vector store backed by LanceDB – serverless, local-first vector database.
|
|
2
|
+
|
|
3
|
+
Replaces the Chroma-based vector store with LanceDB which offers:
|
|
4
|
+
- Zero-server architecture (embedded, like SQLite for vectors)
|
|
5
|
+
- Native hybrid search (vector + SQL predicate filtering)
|
|
6
|
+
- Lance columnar format for fast scans and efficient storage
|
|
7
|
+
- Full-text search index support
|
|
8
|
+
|
|
9
|
+
All data stays on disk under the project directory.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import logging
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any, Dict, List, Optional
|
|
17
|
+
|
|
18
|
+
logger = logging.getLogger(__name__)
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
import lancedb # type: ignore[import-untyped]
|
|
22
|
+
import pyarrow as pa # type: ignore[import-untyped]
|
|
23
|
+
LANCE_AVAILABLE = True
|
|
24
|
+
except ImportError:
|
|
25
|
+
LANCE_AVAILABLE = False
|
|
26
|
+
|
|
27
|
+
# Keep legacy name for backward compatibility
|
|
28
|
+
CHROMA_AVAILABLE = LANCE_AVAILABLE # old code may check this
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class VectorStore:
|
|
32
|
+
"""LanceDB-backed vector store for code embeddings.
|
|
33
|
+
|
|
34
|
+
Drop-in replacement for the old Chroma-based ``VectorStore``.
|
|
35
|
+
The public API is unchanged so existing callers continue to work.
|
|
36
|
+
|
|
37
|
+
Schema per row:
|
|
38
|
+
|
|
39
|
+
======== ============ =====================================
|
|
40
|
+
Column Type Description
|
|
41
|
+
======== ============ =====================================
|
|
42
|
+
id utf8 Unique node identifier
|
|
43
|
+
vector float32[dim] Embedding vector
|
|
44
|
+
document utf8 Source code text
|
|
45
|
+
node_type utf8 function / class / module
|
|
46
|
+
file_path utf8 Relative file path
|
|
47
|
+
qualname utf8 Fully-qualified symbol name
|
|
48
|
+
name utf8 Short symbol name
|
|
49
|
+
======== ============ =====================================
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def __init__(self, project_dir: Path) -> None:
|
|
53
|
+
if not LANCE_AVAILABLE:
|
|
54
|
+
raise ImportError(
|
|
55
|
+
"lancedb is not installed. Install with: pip install lancedb pyarrow"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
self.project_dir = project_dir
|
|
59
|
+
self._lance_dir = project_dir / "lancedb"
|
|
60
|
+
self._lance_dir.mkdir(exist_ok=True, parents=True)
|
|
61
|
+
|
|
62
|
+
self._db: Any = lancedb.connect(str(self._lance_dir))
|
|
63
|
+
self._table: Optional[Any] = None
|
|
64
|
+
|
|
65
|
+
# Try to open existing table
|
|
66
|
+
try:
|
|
67
|
+
self._table = self._db.open_table("code_nodes")
|
|
68
|
+
except Exception:
|
|
69
|
+
self._table = None
|
|
70
|
+
|
|
71
|
+
# ------------------------------------------------------------------
|
|
72
|
+
# Write operations
|
|
73
|
+
# ------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
def add_nodes(
|
|
76
|
+
self,
|
|
77
|
+
node_ids: List[str],
|
|
78
|
+
embeddings: List[List[float]],
|
|
79
|
+
metadatas: List[Dict[str, str]],
|
|
80
|
+
documents: List[str],
|
|
81
|
+
) -> None:
|
|
82
|
+
"""Add or update node embeddings in the vector store.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
node_ids: Unique node identifiers.
|
|
86
|
+
embeddings: Embedding vectors (all same dimensionality).
|
|
87
|
+
metadatas: Per-node metadata dicts.
|
|
88
|
+
documents: Source code text per node.
|
|
89
|
+
"""
|
|
90
|
+
if not node_ids:
|
|
91
|
+
return
|
|
92
|
+
|
|
93
|
+
rows = [
|
|
94
|
+
{
|
|
95
|
+
"id": nid,
|
|
96
|
+
"vector": emb,
|
|
97
|
+
"document": doc,
|
|
98
|
+
"node_type": meta.get("node_type", ""),
|
|
99
|
+
"file_path": meta.get("file_path", ""),
|
|
100
|
+
"qualname": meta.get("qualname", ""),
|
|
101
|
+
"name": meta.get("name", ""),
|
|
102
|
+
}
|
|
103
|
+
for nid, emb, meta, doc in zip(node_ids, embeddings, metadatas, documents)
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
if self._table is None:
|
|
107
|
+
# First insert – create the table (schema inferred from data)
|
|
108
|
+
self._table = self._db.create_table(
|
|
109
|
+
"code_nodes", data=rows, mode="overwrite",
|
|
110
|
+
)
|
|
111
|
+
else:
|
|
112
|
+
# Subsequent inserts – upsert by deleting old IDs first
|
|
113
|
+
try:
|
|
114
|
+
existing_ids = set(node_ids)
|
|
115
|
+
for nid in existing_ids:
|
|
116
|
+
try:
|
|
117
|
+
self._table.delete(f'id = "{nid}"')
|
|
118
|
+
except Exception:
|
|
119
|
+
pass
|
|
120
|
+
except Exception:
|
|
121
|
+
pass
|
|
122
|
+
self._table.add(rows)
|
|
123
|
+
|
|
124
|
+
# ------------------------------------------------------------------
|
|
125
|
+
# Search
|
|
126
|
+
# ------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
def search(
|
|
129
|
+
self,
|
|
130
|
+
query_embedding: List[float],
|
|
131
|
+
n_results: int = 10,
|
|
132
|
+
where: Optional[Dict[str, str]] = None,
|
|
133
|
+
) -> Dict[str, Any]:
|
|
134
|
+
"""Vector similarity search with optional metadata filtering.
|
|
135
|
+
|
|
136
|
+
Returns a dict with keys ``ids``, ``distances``, ``metadatas``,
|
|
137
|
+
``documents`` – matching the legacy Chroma return format for
|
|
138
|
+
backward compatibility.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
query_embedding: Query vector.
|
|
142
|
+
n_results: Max results to return.
|
|
143
|
+
where: Optional metadata filter, e.g.
|
|
144
|
+
``{"node_type": "function"}``.
|
|
145
|
+
"""
|
|
146
|
+
empty: Dict[str, Any] = {
|
|
147
|
+
"ids": [[]], "distances": [[]], "metadatas": [[]], "documents": [[]],
|
|
148
|
+
}
|
|
149
|
+
if self._table is None:
|
|
150
|
+
return empty
|
|
151
|
+
|
|
152
|
+
try:
|
|
153
|
+
query = self._table.search(query_embedding).limit(n_results)
|
|
154
|
+
|
|
155
|
+
# Apply metadata filters as SQL WHERE clause
|
|
156
|
+
if where:
|
|
157
|
+
clauses = []
|
|
158
|
+
for key, value in where.items():
|
|
159
|
+
clauses.append(f'{key} = "{value}"')
|
|
160
|
+
if clauses:
|
|
161
|
+
query = query.where(" AND ".join(clauses))
|
|
162
|
+
|
|
163
|
+
results = query.to_list()
|
|
164
|
+
except Exception as exc:
|
|
165
|
+
logger.warning("LanceDB search failed: %s", exc)
|
|
166
|
+
return empty
|
|
167
|
+
|
|
168
|
+
ids: List[str] = []
|
|
169
|
+
distances: List[float] = []
|
|
170
|
+
metas: List[Dict[str, str]] = []
|
|
171
|
+
docs: List[str] = []
|
|
172
|
+
|
|
173
|
+
for row in results:
|
|
174
|
+
ids.append(row.get("id", ""))
|
|
175
|
+
distances.append(row.get("_distance", 0.0))
|
|
176
|
+
metas.append({
|
|
177
|
+
"node_type": row.get("node_type", ""),
|
|
178
|
+
"file_path": row.get("file_path", ""),
|
|
179
|
+
"qualname": row.get("qualname", ""),
|
|
180
|
+
"name": row.get("name", ""),
|
|
181
|
+
})
|
|
182
|
+
docs.append(row.get("document", ""))
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
"ids": [ids],
|
|
186
|
+
"distances": [distances],
|
|
187
|
+
"metadatas": [metas],
|
|
188
|
+
"documents": [docs],
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
def hybrid_search(
|
|
192
|
+
self,
|
|
193
|
+
query_embedding: List[float],
|
|
194
|
+
n_results: int = 10,
|
|
195
|
+
where_sql: Optional[str] = None,
|
|
196
|
+
) -> List[Dict[str, Any]]:
|
|
197
|
+
"""Hybrid search: vector similarity + arbitrary SQL filter.
|
|
198
|
+
|
|
199
|
+
Unlike :meth:`search`, this returns a plain list of dicts and
|
|
200
|
+
accepts a raw SQL ``WHERE`` clause for maximum flexibility.
|
|
201
|
+
|
|
202
|
+
Example::
|
|
203
|
+
|
|
204
|
+
store.hybrid_search(
|
|
205
|
+
vec, n_results=5, where_sql="file_path LIKE 'src/%'"
|
|
206
|
+
)
|
|
207
|
+
"""
|
|
208
|
+
if self._table is None:
|
|
209
|
+
return []
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
query = self._table.search(query_embedding).limit(n_results)
|
|
213
|
+
if where_sql:
|
|
214
|
+
query = query.where(where_sql)
|
|
215
|
+
return query.to_list()
|
|
216
|
+
except Exception as exc:
|
|
217
|
+
logger.warning("LanceDB hybrid search failed: %s", exc)
|
|
218
|
+
return []
|
|
219
|
+
|
|
220
|
+
# ------------------------------------------------------------------
|
|
221
|
+
# Point lookups
|
|
222
|
+
# ------------------------------------------------------------------
|
|
223
|
+
|
|
224
|
+
def get_node(self, node_id: str) -> Optional[Dict[str, Any]]:
|
|
225
|
+
"""Retrieve a single node by its ID."""
|
|
226
|
+
if self._table is None:
|
|
227
|
+
return None
|
|
228
|
+
try:
|
|
229
|
+
import pandas as pd # type: ignore[import-untyped]
|
|
230
|
+
df: pd.DataFrame = self._table.to_pandas()
|
|
231
|
+
match = df[df["id"] == node_id]
|
|
232
|
+
if match.empty:
|
|
233
|
+
return None
|
|
234
|
+
row = match.iloc[0].to_dict()
|
|
235
|
+
return {
|
|
236
|
+
"id": row["id"],
|
|
237
|
+
"embedding": row.get("vector"),
|
|
238
|
+
"metadata": {
|
|
239
|
+
"node_type": row.get("node_type", ""),
|
|
240
|
+
"file_path": row.get("file_path", ""),
|
|
241
|
+
"qualname": row.get("qualname", ""),
|
|
242
|
+
"name": row.get("name", ""),
|
|
243
|
+
},
|
|
244
|
+
"document": row.get("document", ""),
|
|
245
|
+
}
|
|
246
|
+
except Exception:
|
|
247
|
+
return None
|
|
248
|
+
|
|
249
|
+
# ------------------------------------------------------------------
|
|
250
|
+
# Delete / clear
|
|
251
|
+
# ------------------------------------------------------------------
|
|
252
|
+
|
|
253
|
+
def delete_nodes(self, node_ids: List[str]) -> None:
|
|
254
|
+
"""Delete nodes by ID."""
|
|
255
|
+
if not node_ids or self._table is None:
|
|
256
|
+
return
|
|
257
|
+
for nid in node_ids:
|
|
258
|
+
try:
|
|
259
|
+
self._table.delete(f'id = "{nid}"')
|
|
260
|
+
except Exception:
|
|
261
|
+
pass
|
|
262
|
+
|
|
263
|
+
def clear(self) -> None:
|
|
264
|
+
"""Drop all data and recreate an empty table."""
|
|
265
|
+
try:
|
|
266
|
+
self._db.drop_table("code_nodes")
|
|
267
|
+
except Exception:
|
|
268
|
+
pass
|
|
269
|
+
self._table = None
|
|
270
|
+
|
|
271
|
+
# ------------------------------------------------------------------
|
|
272
|
+
# Informational
|
|
273
|
+
# ------------------------------------------------------------------
|
|
274
|
+
|
|
275
|
+
def count(self) -> int:
|
|
276
|
+
"""Number of rows in the vector store."""
|
|
277
|
+
if self._table is None:
|
|
278
|
+
return 0
|
|
279
|
+
try:
|
|
280
|
+
return self._table.count_rows()
|
|
281
|
+
except Exception:
|
|
282
|
+
return 0
|
|
283
|
+
|
|
284
|
+
def peek(self, limit: int = 10) -> List[Dict[str, Any]]:
|
|
285
|
+
"""Return a sample of rows for debugging."""
|
|
286
|
+
if self._table is None:
|
|
287
|
+
return []
|
|
288
|
+
try:
|
|
289
|
+
import pandas as pd # type: ignore[import-untyped]
|
|
290
|
+
df: pd.DataFrame = self._table.to_pandas()
|
|
291
|
+
return df.head(limit).to_dict(orient="records")
|
|
292
|
+
except Exception:
|
|
293
|
+
return []
|
|
@@ -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,43 @@
|
|
|
1
|
+
codegraph_cli/__init__.py,sha256=RbUQDQExUJrOtUpjy4I7oXTwd1VT89usD5EJmSCngcs,78
|
|
2
|
+
codegraph_cli/agents.py,sha256=euxEz8LhHX3K9lpllUnAngU22oEP-ZwxeBDYDLCJgY8,6989
|
|
3
|
+
codegraph_cli/bug_detector.py,sha256=soT4luB5eQx6qrU5rgFCsG44rdo9jRpV0hn-b0f3LPo,16419
|
|
4
|
+
codegraph_cli/chat_agent.py,sha256=dbkEY3zaPJh0ztYaVkCwkTw5zSLGArHkChC_6JWOneg,13685
|
|
5
|
+
codegraph_cli/chat_session.py,sha256=GVey-hnfsa9fa6k2PY1sgy1wtrYSUHKE5cJDV2hG-tg,7038
|
|
6
|
+
codegraph_cli/cli.py,sha256=V3BdUTgGt5nBXFAsJu-qhM3uZx_c9DW4plnXfSKVy6I,10949
|
|
7
|
+
codegraph_cli/cli_chat.py,sha256=O6qujvTMQK3vovy5Di-__UlUuosacbcJX7pPudJPboc,14184
|
|
8
|
+
codegraph_cli/cli_diagnose.py,sha256=gT4qHayC_uWRMsr1Tf92BCFJfRcXAMq8XdEImatrSkU,4260
|
|
9
|
+
codegraph_cli/cli_refactor.py,sha256=_u5RvsF3-KV5C_QnErA4sowlkIAmlxSeLeWKBmSusCI,8176
|
|
10
|
+
codegraph_cli/cli_setup.py,sha256=SC_w0yEHkVBkfXVWx2OaIrQCC5NLouC5ciJ6QAEug1c,17527
|
|
11
|
+
codegraph_cli/cli_test.py,sha256=ZFPIRhbZ9YYIuSWJyPYLi9PEdHZAI9h8FkWXXRYfqcw,5561
|
|
12
|
+
codegraph_cli/cli_v2.py,sha256=iuw3h5gtvsTg5SdUFXSdLx1Ttiq-oUDM7ZugMqMfETg,9465
|
|
13
|
+
codegraph_cli/codegen_agent.py,sha256=F73YZIIVgE5pOvJsKBl0cv22VW3rP_SGj2viwZS-rqE,9193
|
|
14
|
+
codegraph_cli/config.py,sha256=os7C8-LBGwYFz84wjEnM-48jco-UUKN-I6PY1kufiCE,1072
|
|
15
|
+
codegraph_cli/config_manager.py,sha256=MzZffQC_OpN_Udcm8mhFiWlk_MX5ANW1hKNm5csvrSc,9805
|
|
16
|
+
codegraph_cli/context_manager.py,sha256=Bupg3pAQiDQH1owN4LAcWcpMLOGtwIWjvdzs5Cns61g,16819
|
|
17
|
+
codegraph_cli/crew_agents.py,sha256=PKb0skEmxBy2_Ryq67XccmPizLFLgPNs43xOqjSHcGM,6006
|
|
18
|
+
codegraph_cli/crew_chat.py,sha256=tdo8Zf9lOp5-XMdvNntLxo5hKrDcEOe3165cH22-nvQ,6149
|
|
19
|
+
codegraph_cli/crew_tools.py,sha256=wg39mkPDHeE2Wuy3q54xl5d243MHQZBcXCWR2rHrd3M,19339
|
|
20
|
+
codegraph_cli/diff_engine.py,sha256=VGwPG_pZFVz8lGuVHZz_0nhrDocglugw6TumMmnHdTY,8968
|
|
21
|
+
codegraph_cli/embeddings.py,sha256=DfbF4STJXioCU7DXMUQ0LJ3OjLS34ZxiZ5LYcTWny9c,8035
|
|
22
|
+
codegraph_cli/graph_export.py,sha256=gPyRrOc4_gnW-JaHmmp2pAD60PiZIj_uYA6b0xfU5O0,4562
|
|
23
|
+
codegraph_cli/llm.py,sha256=RpGjJKhUvejmtCHTb9FpGInwPtfaEkHBChBSBTwxUUo,23170
|
|
24
|
+
codegraph_cli/models.py,sha256=o6Wlu8TtWEPDWgq0AhB1xJtxzVfViBMQoCW_4AS29p0,794
|
|
25
|
+
codegraph_cli/models_v2.py,sha256=8zS16hT4SlIahMBwDZ7j4I8fdm3YyWv5qD0urJv1LsI,5521
|
|
26
|
+
codegraph_cli/orchestrator.py,sha256=ARVUpNR2EJIP5jw6CcYe9StqSRmtBAs_2TOIQF8ORwU,1802
|
|
27
|
+
codegraph_cli/parser.py,sha256=vtKOwirs30O9UxJ6siHzvEWLx4-PxMn5dAfhb42QBG4,29193
|
|
28
|
+
codegraph_cli/performance_analyzer.py,sha256=f9PNMZQ_8jWvzs4osPYgTW2eOsvDytIRmfWWO5DuWCs,10090
|
|
29
|
+
codegraph_cli/project_context.py,sha256=9tSEDEPRmfEQfLcyWXjPa8IGFC1sZI1ysochoxrm4y0,7672
|
|
30
|
+
codegraph_cli/rag.py,sha256=pePkEj8O1Xv1MGHr_KkByiLNNSqmek1nipJx4J_QTx8,7105
|
|
31
|
+
codegraph_cli/refactor_agent.py,sha256=ktQyhUn5YjhbXt7IVgKV7JgSZaT4AivWLLpMlZ7NLXw,16657
|
|
32
|
+
codegraph_cli/security_scanner.py,sha256=rPf8PcYMBllco4PkrxfILJEqKaj1UuEKqCupVycKpo8,15681
|
|
33
|
+
codegraph_cli/storage.py,sha256=XR_w6nJ_ge4r72bfxuuY8Zt8qi8CtHm4EE268EB5kBE,14340
|
|
34
|
+
codegraph_cli/testgen_agent.py,sha256=rqlKbLeEnjfzAZhQUXqLPwFKwRIpiHriTPxVgPCuR_g,10233
|
|
35
|
+
codegraph_cli/validation_engine.py,sha256=pzoRH_b06gWfiDZ5Yiecf0SWDWs4oJ66JokggGZZbaw,9029
|
|
36
|
+
codegraph_cli/vector_store.py,sha256=qbIBVDoNOha8JgZwrk7_Jdb7RMYUnBLphJfmqQdrVN4,9912
|
|
37
|
+
codegraph_cli/templates/graph_interactive.html,sha256=PFpU69DbY-Vkcu5UTiqOva_LrZjN2erdz7VXPgNSt6Q,7813
|
|
38
|
+
codegraph_cli-2.0.0.dist-info/licenses/LICENSE,sha256=3PiQTjpJW4DDJz8k5pk-WqX9TrVQD3fNrVNzbTEyW-A,1066
|
|
39
|
+
codegraph_cli-2.0.0.dist-info/METADATA,sha256=UJY9GJXu2iwKVX7V3_Iw8HdfyKEkzBsMyn-DuopVkHg,11024
|
|
40
|
+
codegraph_cli-2.0.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
41
|
+
codegraph_cli-2.0.0.dist-info/entry_points.txt,sha256=_p5CutxbiWjGVTx9GPeYJ30XOblccdf7SCCNtCkPnaA,45
|
|
42
|
+
codegraph_cli-2.0.0.dist-info/top_level.txt,sha256=XKmdlLsrhdgVW-pN4vzdo-ZTl-9_Rk94SXcM2YRAmHk,14
|
|
43
|
+
codegraph_cli-2.0.0.dist-info/RECORD,,
|
|
@@ -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 @@
|
|
|
1
|
+
codegraph_cli
|