cortexcode 0.1.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.
- cortexcode/__init__.py +3 -0
- cortexcode/analysis.py +331 -0
- cortexcode/cli.py +845 -0
- cortexcode/context.py +298 -0
- cortexcode/dashboard.py +152 -0
- cortexcode/docs.py +1266 -0
- cortexcode/git_diff.py +157 -0
- cortexcode/indexer.py +1860 -0
- cortexcode/lsp_server.py +315 -0
- cortexcode/mcp_server.py +455 -0
- cortexcode/plugins.py +188 -0
- cortexcode/semantic_search.py +237 -0
- cortexcode/vuln_scan.py +241 -0
- cortexcode/watcher.py +122 -0
- cortexcode/workspace.py +180 -0
- cortexcode-0.1.0.dist-info/METADATA +448 -0
- cortexcode-0.1.0.dist-info/RECORD +21 -0
- cortexcode-0.1.0.dist-info/WHEEL +5 -0
- cortexcode-0.1.0.dist-info/entry_points.txt +2 -0
- cortexcode-0.1.0.dist-info/licenses/LICENSE +21 -0
- cortexcode-0.1.0.dist-info/top_level.txt +1 -0
cortexcode/workspace.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""Multi-repo workspace support - index and query across multiple repositories."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from cortexcode.indexer import CodeIndexer
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Workspace:
|
|
11
|
+
"""Manage multiple repositories as a single workspace."""
|
|
12
|
+
|
|
13
|
+
CONFIG_FILE = ".cortexcode-workspace.json"
|
|
14
|
+
|
|
15
|
+
def __init__(self, workspace_root: Path | None = None):
|
|
16
|
+
self.workspace_root = workspace_root or Path.cwd()
|
|
17
|
+
self.repos: list[dict[str, Any]] = []
|
|
18
|
+
self.merged_index: dict[str, Any] = {}
|
|
19
|
+
|
|
20
|
+
def load_config(self) -> bool:
|
|
21
|
+
"""Load workspace config from disk."""
|
|
22
|
+
config_path = self.workspace_root / self.CONFIG_FILE
|
|
23
|
+
if not config_path.exists():
|
|
24
|
+
return False
|
|
25
|
+
try:
|
|
26
|
+
data = json.loads(config_path.read_text(encoding="utf-8"))
|
|
27
|
+
self.repos = data.get("repos", [])
|
|
28
|
+
return True
|
|
29
|
+
except (json.JSONDecodeError, OSError):
|
|
30
|
+
return False
|
|
31
|
+
|
|
32
|
+
def save_config(self) -> None:
|
|
33
|
+
"""Save workspace config to disk."""
|
|
34
|
+
config_path = self.workspace_root / self.CONFIG_FILE
|
|
35
|
+
data = {"repos": self.repos}
|
|
36
|
+
config_path.write_text(json.dumps(data, indent=2), encoding="utf-8")
|
|
37
|
+
|
|
38
|
+
def add_repo(self, path: str, alias: str | None = None) -> dict:
|
|
39
|
+
"""Add a repository to the workspace."""
|
|
40
|
+
repo_path = Path(path).resolve()
|
|
41
|
+
if not repo_path.is_dir():
|
|
42
|
+
raise ValueError(f"Not a directory: {repo_path}")
|
|
43
|
+
|
|
44
|
+
# Check not already added
|
|
45
|
+
for r in self.repos:
|
|
46
|
+
if Path(r["path"]).resolve() == repo_path:
|
|
47
|
+
raise ValueError(f"Already in workspace: {repo_path}")
|
|
48
|
+
|
|
49
|
+
repo = {
|
|
50
|
+
"path": str(repo_path),
|
|
51
|
+
"alias": alias or repo_path.name,
|
|
52
|
+
}
|
|
53
|
+
self.repos.append(repo)
|
|
54
|
+
self.save_config()
|
|
55
|
+
return repo
|
|
56
|
+
|
|
57
|
+
def remove_repo(self, alias_or_path: str) -> bool:
|
|
58
|
+
"""Remove a repository from the workspace."""
|
|
59
|
+
resolved = None
|
|
60
|
+
try:
|
|
61
|
+
resolved = Path(alias_or_path).resolve()
|
|
62
|
+
except Exception:
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
for i, r in enumerate(self.repos):
|
|
66
|
+
if r["alias"] == alias_or_path or (resolved and Path(r["path"]).resolve() == resolved):
|
|
67
|
+
self.repos.pop(i)
|
|
68
|
+
self.save_config()
|
|
69
|
+
return True
|
|
70
|
+
return False
|
|
71
|
+
|
|
72
|
+
def list_repos(self) -> list[dict]:
|
|
73
|
+
"""List all repos in workspace."""
|
|
74
|
+
result = []
|
|
75
|
+
for r in self.repos:
|
|
76
|
+
p = Path(r["path"])
|
|
77
|
+
index_path = p / ".cortexcode" / "index.json"
|
|
78
|
+
indexed = index_path.exists()
|
|
79
|
+
result.append({
|
|
80
|
+
"alias": r["alias"],
|
|
81
|
+
"path": r["path"],
|
|
82
|
+
"indexed": indexed,
|
|
83
|
+
})
|
|
84
|
+
return result
|
|
85
|
+
|
|
86
|
+
def index_all(self, incremental: bool = True) -> dict[str, int]:
|
|
87
|
+
"""Index all repos in the workspace. Returns {alias: symbol_count}."""
|
|
88
|
+
results = {}
|
|
89
|
+
for r in self.repos:
|
|
90
|
+
repo_path = Path(r["path"])
|
|
91
|
+
if not repo_path.is_dir():
|
|
92
|
+
results[r["alias"]] = -1
|
|
93
|
+
continue
|
|
94
|
+
|
|
95
|
+
idx = CodeIndexer()
|
|
96
|
+
index = idx.index_directory(repo_path, incremental=incremental)
|
|
97
|
+
|
|
98
|
+
output_dir = repo_path / ".cortexcode"
|
|
99
|
+
output_dir.mkdir(exist_ok=True)
|
|
100
|
+
(output_dir / "index.json").write_text(
|
|
101
|
+
json.dumps(index, indent=2, default=str), encoding="utf-8"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
results[r["alias"]] = len(index.get("symbols", []))
|
|
105
|
+
|
|
106
|
+
return results
|
|
107
|
+
|
|
108
|
+
def get_merged_index(self) -> dict[str, Any]:
|
|
109
|
+
"""Load and merge indices from all repos into a single view."""
|
|
110
|
+
merged_files = {}
|
|
111
|
+
merged_call_graph = {}
|
|
112
|
+
merged_symbols = []
|
|
113
|
+
merged_file_deps = {}
|
|
114
|
+
languages = set()
|
|
115
|
+
|
|
116
|
+
for r in self.repos:
|
|
117
|
+
repo_path = Path(r["path"])
|
|
118
|
+
index_path = repo_path / ".cortexcode" / "index.json"
|
|
119
|
+
if not index_path.exists():
|
|
120
|
+
continue
|
|
121
|
+
|
|
122
|
+
try:
|
|
123
|
+
index = json.loads(index_path.read_text(encoding="utf-8"))
|
|
124
|
+
except (json.JSONDecodeError, OSError):
|
|
125
|
+
continue
|
|
126
|
+
|
|
127
|
+
alias = r["alias"]
|
|
128
|
+
|
|
129
|
+
# Prefix files with repo alias
|
|
130
|
+
for rel_path, file_data in index.get("files", {}).items():
|
|
131
|
+
prefixed = f"{alias}/{rel_path}"
|
|
132
|
+
merged_files[prefixed] = file_data
|
|
133
|
+
|
|
134
|
+
# Merge call graph
|
|
135
|
+
for caller, callees in index.get("call_graph", {}).items():
|
|
136
|
+
prefixed_caller = f"{alias}:{caller}"
|
|
137
|
+
merged_call_graph[prefixed_caller] = [f"{alias}:{c}" for c in callees]
|
|
138
|
+
|
|
139
|
+
# Merge symbols
|
|
140
|
+
for sym in index.get("symbols", []):
|
|
141
|
+
sym_copy = dict(sym)
|
|
142
|
+
if "file" in sym_copy:
|
|
143
|
+
sym_copy["file"] = f"{alias}/{sym_copy['file']}"
|
|
144
|
+
sym_copy["repo"] = alias
|
|
145
|
+
merged_symbols.append(sym_copy)
|
|
146
|
+
|
|
147
|
+
# Merge file deps
|
|
148
|
+
for f, deps in index.get("file_dependencies", {}).items():
|
|
149
|
+
prefixed_f = f"{alias}/{f}"
|
|
150
|
+
merged_file_deps[prefixed_f] = [f"{alias}/{d}" for d in deps]
|
|
151
|
+
|
|
152
|
+
languages.update(index.get("languages", []))
|
|
153
|
+
|
|
154
|
+
self.merged_index = {
|
|
155
|
+
"files": merged_files,
|
|
156
|
+
"call_graph": merged_call_graph,
|
|
157
|
+
"symbols": merged_symbols,
|
|
158
|
+
"file_dependencies": merged_file_deps,
|
|
159
|
+
"languages": sorted(languages),
|
|
160
|
+
"project_root": str(self.workspace_root),
|
|
161
|
+
"repos": [r["alias"] for r in self.repos],
|
|
162
|
+
}
|
|
163
|
+
return self.merged_index
|
|
164
|
+
|
|
165
|
+
def search_across_repos(self, query: str, max_results: int = 20) -> list[dict]:
|
|
166
|
+
"""Search symbols across all repos."""
|
|
167
|
+
if not self.merged_index:
|
|
168
|
+
self.get_merged_index()
|
|
169
|
+
|
|
170
|
+
query_lower = query.lower()
|
|
171
|
+
results = []
|
|
172
|
+
|
|
173
|
+
for sym in self.merged_index.get("symbols", []):
|
|
174
|
+
name = sym.get("name", "")
|
|
175
|
+
if query_lower in name.lower():
|
|
176
|
+
results.append(sym)
|
|
177
|
+
if len(results) >= max_results:
|
|
178
|
+
break
|
|
179
|
+
|
|
180
|
+
return results
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cortexcode
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight code indexing for AI assistants — save 90%+ tokens with structured context
|
|
5
|
+
Author-email: CortexCode <dev@cortexcode.io>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/cortexcode/cortexcode
|
|
8
|
+
Project-URL: Repository, https://github.com/cortexcode/cortexcode
|
|
9
|
+
Project-URL: Documentation, https://github.com/cortexcode/cortexcode#readme
|
|
10
|
+
Project-URL: Issues, https://github.com/cortexcode/cortexcode/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/cortexcode/cortexcode/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: code-index,ast,copilot,cursor,rag,ai-assistant,tree-sitter,code-analysis,token-savings,context-provider
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: tree-sitter>=0.21.0
|
|
26
|
+
Requires-Dist: tree-sitter-python>=0.23.0
|
|
27
|
+
Requires-Dist: tree-sitter-javascript>=0.23.0
|
|
28
|
+
Requires-Dist: tree-sitter-typescript>=0.23.0
|
|
29
|
+
Requires-Dist: tree-sitter-go>=0.23.0
|
|
30
|
+
Requires-Dist: tree-sitter-rust>=0.23.0
|
|
31
|
+
Requires-Dist: tree-sitter-java>=0.23.0
|
|
32
|
+
Requires-Dist: tree-sitter-c-sharp>=0.23.0
|
|
33
|
+
Requires-Dist: click>=8.1.0
|
|
34
|
+
Requires-Dist: watchdog>=4.0.0
|
|
35
|
+
Requires-Dist: rich>=13.0.0
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
39
|
+
Requires-Dist: ruff>=0.3.0; extra == "dev"
|
|
40
|
+
Provides-Extra: ai
|
|
41
|
+
Requires-Dist: tiktoken>=0.7.0; extra == "ai"
|
|
42
|
+
Provides-Extra: mobile
|
|
43
|
+
Requires-Dist: tree-sitter-kotlin>=0.1.0; extra == "mobile"
|
|
44
|
+
Requires-Dist: tree-sitter-swift>=0.6.0; extra == "mobile"
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
<p align="center">
|
|
48
|
+
<h1 align="center">CortexCode</h1>
|
|
49
|
+
<p align="center">
|
|
50
|
+
<strong>Lightweight code indexing for AI assistants</strong><br>
|
|
51
|
+
Save 90%+ tokens by giving AI agents structured context instead of raw source files.
|
|
52
|
+
</p>
|
|
53
|
+
</p>
|
|
54
|
+
|
|
55
|
+
<p align="center">
|
|
56
|
+
<a href="https://pypi.org/project/cortexcode/"><img src="https://img.shields.io/pypi/v/cortexcode?style=flat-square&color=blue" alt="PyPI"></a>
|
|
57
|
+
<a href="https://pypi.org/project/cortexcode/"><img src="https://img.shields.io/pypi/pyversions/cortexcode?style=flat-square" alt="Python"></a>
|
|
58
|
+
<a href="https://github.com/cortexcode/cortexcode/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="License"></a>
|
|
59
|
+
<a href="https://github.com/cortexcode/cortexcode"><img src="https://img.shields.io/github/stars/cortexcode/cortexcode?style=flat-square" alt="Stars"></a>
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## The Problem
|
|
65
|
+
|
|
66
|
+
AI coding assistants (Copilot, Cursor, Windsurf, etc.) need to understand your codebase. The current approach: **dump entire source files into the context window**. This is:
|
|
67
|
+
|
|
68
|
+
- **Expensive** — A 150-file project can cost 200K+ tokens per query
|
|
69
|
+
- **Slow** — More tokens = slower responses
|
|
70
|
+
- **Wasteful** — Most of those tokens are irrelevant to the question
|
|
71
|
+
|
|
72
|
+
## The Solution
|
|
73
|
+
|
|
74
|
+
CortexCode indexes your codebase using **AST parsing** (tree-sitter) and provides a structured, searchable index. Instead of feeding 200K tokens of raw code, you feed **~500 tokens of relevant context**.
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
┌─────────────────────────────────────────────────┐
|
|
78
|
+
│ Without CortexCode With CortexCode │
|
|
79
|
+
│ │
|
|
80
|
+
│ 200,000 tokens → 500 tokens │
|
|
81
|
+
│ $0.006/query → $0.00002/query │
|
|
82
|
+
│ All files dumped → Only relevant syms │
|
|
83
|
+
│ No structure → Call graph + types │
|
|
84
|
+
└─────────────────────────────────────────────────┘
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Run `cortexcode stats` on your project to see your actual savings.
|
|
88
|
+
|
|
89
|
+
## Quick Start
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Install from PyPI
|
|
93
|
+
pip install cortexcode
|
|
94
|
+
|
|
95
|
+
# Or install from source
|
|
96
|
+
git clone https://github.com/cortexcode/cortexcode.git
|
|
97
|
+
cd cortexcode && pip install -e .
|
|
98
|
+
|
|
99
|
+
# Index your project
|
|
100
|
+
cd your-project
|
|
101
|
+
cortexcode index
|
|
102
|
+
|
|
103
|
+
# See token savings
|
|
104
|
+
cortexcode stats
|
|
105
|
+
|
|
106
|
+
# Get context for AI
|
|
107
|
+
cortexcode context "handleAuth"
|
|
108
|
+
|
|
109
|
+
# Generate interactive docs
|
|
110
|
+
cortexcode docs --open
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Features
|
|
114
|
+
|
|
115
|
+
### Multi-Language AST Indexing
|
|
116
|
+
|
|
117
|
+
Parses source code into structured symbols using tree-sitter grammars.
|
|
118
|
+
|
|
119
|
+
| Language | Extensions | Frameworks Detected |
|
|
120
|
+
|----------|-----------|-------------------|
|
|
121
|
+
| Python | `.py` | FastAPI, Django |
|
|
122
|
+
| JavaScript | `.js`, `.jsx` | React, Express, Angular |
|
|
123
|
+
| TypeScript | `.ts`, `.tsx` | Next.js, NestJS, Angular |
|
|
124
|
+
| Go | `.go` | — |
|
|
125
|
+
| Rust | `.rs` | — |
|
|
126
|
+
| Java | `.java` | Spring Boot |
|
|
127
|
+
| C# | `.cs` | ASP.NET |
|
|
128
|
+
|
|
129
|
+
### What Gets Indexed
|
|
130
|
+
|
|
131
|
+
- **Symbols** — Functions, classes, methods with parameters and return types
|
|
132
|
+
- **Call Graph** — Which functions call which (and who calls them)
|
|
133
|
+
- **Imports/Exports** — Module dependencies
|
|
134
|
+
- **API Routes** — Express, FastAPI, NestJS, Spring Boot endpoints
|
|
135
|
+
- **Entities** — Database models and ORM definitions
|
|
136
|
+
- **Framework Detection** — React components, Angular services, etc.
|
|
137
|
+
|
|
138
|
+
### Token Savings
|
|
139
|
+
|
|
140
|
+
CortexCode dramatically reduces the tokens needed to give AI assistants useful context:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
$ cortexcode stats
|
|
144
|
+
|
|
145
|
+
╭──────── Token Savings Analysis ────────╮
|
|
146
|
+
│ Source files 154 files │
|
|
147
|
+
│ Raw project tokens 203,847 │
|
|
148
|
+
│ Full index tokens 45,291 │
|
|
149
|
+
│ Context query tokens 487 │
|
|
150
|
+
│ │
|
|
151
|
+
│ Tokens saved 203,360 │
|
|
152
|
+
│ Savings 99.8% │
|
|
153
|
+
│ Compression ratio 418.6x │
|
|
154
|
+
╰─────────────────────────────────────────╯
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Interactive HTML Documentation
|
|
158
|
+
|
|
159
|
+
Generate a full interactive documentation site with:
|
|
160
|
+
|
|
161
|
+
- **File tree** browser
|
|
162
|
+
- **Symbol list** with filtering
|
|
163
|
+
- **D3.js call graph** visualization (draggable nodes)
|
|
164
|
+
- **Global search** across all symbols
|
|
165
|
+
- **Import/Export** browser
|
|
166
|
+
- **API route** listing
|
|
167
|
+
- **Framework** detection summary
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
cortexcode docs --open
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Incremental Indexing
|
|
174
|
+
|
|
175
|
+
Only re-index files that changed since last run:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
cortexcode index -i # Skip unchanged files
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### VS Code Extension
|
|
182
|
+
|
|
183
|
+
The bundled VS Code extension provides:
|
|
184
|
+
|
|
185
|
+
- **Hover tooltips** — Hover any symbol to see type, params, callers
|
|
186
|
+
- **Go to definition** — Ctrl+Click using indexed data
|
|
187
|
+
- **Context panel** — View symbol details in a side panel
|
|
188
|
+
- **Status bar** — Shows indexed symbol count
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
cd cortexcode-vscode
|
|
192
|
+
npm install && npm run compile
|
|
193
|
+
# Press F5 to launch in VS Code
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Commands
|
|
197
|
+
|
|
198
|
+
| Command | Description |
|
|
199
|
+
|---------|-------------|
|
|
200
|
+
| `cortexcode index [path]` | Index a directory |
|
|
201
|
+
| `cortexcode index -i` | Incremental index (changed files only) |
|
|
202
|
+
| `cortexcode context [query]` | Get relevant context for AI |
|
|
203
|
+
| `cortexcode context [query] --tokens` | Show token savings for query |
|
|
204
|
+
| `cortexcode search [query]` | Grep-like symbol search with type/file filters |
|
|
205
|
+
| `cortexcode find [query]` | Semantic search by meaning ("auth handler") |
|
|
206
|
+
| `cortexcode diff` | Show changed symbols since last commit |
|
|
207
|
+
| `cortexcode diff --ref HEAD~3` | Compare against any git ref |
|
|
208
|
+
| `cortexcode stats` | Show project stats and token savings |
|
|
209
|
+
| `cortexcode scan` | Scan dependencies for security warnings |
|
|
210
|
+
| `cortexcode docs --open` | Generate and open interactive docs |
|
|
211
|
+
| `cortexcode dead-code` | Detect potentially unused symbols |
|
|
212
|
+
| `cortexcode complexity` | Analyze code complexity (cyclomatic, nesting, line count) |
|
|
213
|
+
| `cortexcode complexity --min-score 50` | Show only high-complexity functions |
|
|
214
|
+
| `cortexcode impact <symbol>` | Change impact analysis — what breaks if you modify a symbol |
|
|
215
|
+
| `cortexcode dashboard` | Launch live dashboard with auto-refresh on index changes |
|
|
216
|
+
| `cortexcode workspace init` | Initialize a multi-repo workspace |
|
|
217
|
+
| `cortexcode workspace add <path>` | Add a repo to the workspace |
|
|
218
|
+
| `cortexcode workspace list` | List repos in workspace |
|
|
219
|
+
| `cortexcode workspace index` | Index all workspace repos |
|
|
220
|
+
| `cortexcode workspace search <q>` | Search symbols across all repos |
|
|
221
|
+
| `cortexcode watch` | Auto-reindex on file changes |
|
|
222
|
+
| `cortexcode mcp` | Start MCP server for AI agent integration |
|
|
223
|
+
| `cortexcode lsp` | Start Language Server Protocol server |
|
|
224
|
+
|
|
225
|
+
## How AI Agents Use This
|
|
226
|
+
|
|
227
|
+
### 1. Context Command (simplest)
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# Paste this output into your AI chat
|
|
231
|
+
cortexcode context "useAuth" --tokens
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### 2. JSON Index (programmatic)
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
import json
|
|
238
|
+
|
|
239
|
+
index = json.load(open('.cortexcode/index.json'))
|
|
240
|
+
|
|
241
|
+
# Get all functions
|
|
242
|
+
for path, data in index['files'].items():
|
|
243
|
+
for sym in data['symbols']:
|
|
244
|
+
print(f"{sym['type']}: {sym['name']} in {path}:{sym['line']}")
|
|
245
|
+
|
|
246
|
+
# Trace call graph
|
|
247
|
+
for caller, callees in index['call_graph'].items():
|
|
248
|
+
for callee in callees:
|
|
249
|
+
print(f"{caller} -> {callee}")
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### 3. MCP Server
|
|
253
|
+
|
|
254
|
+
AI agents can query the index directly via the Model Context Protocol:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
# Start the MCP server (stdin/stdout)
|
|
258
|
+
cortexcode mcp
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Configuration Examples:**
|
|
262
|
+
|
|
263
|
+
```json
|
|
264
|
+
// Claude Desktop (claude_desktop_config.json)
|
|
265
|
+
{
|
|
266
|
+
"mcpServers": {
|
|
267
|
+
"cortexcode": {
|
|
268
|
+
"command": "cortexcode",
|
|
269
|
+
"args": ["mcp"]
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Cursor / Windsurf
|
|
275
|
+
{
|
|
276
|
+
"mcpServers": {
|
|
277
|
+
"cortexcode": {
|
|
278
|
+
"command": "cortexcode",
|
|
279
|
+
"args": ["mcp"]
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Open WebUI / AnythingLLM
|
|
285
|
+
{
|
|
286
|
+
"mcpServers": {
|
|
287
|
+
"cortexcode": {
|
|
288
|
+
"command": "cortexcode",
|
|
289
|
+
"args": ["mcp"]
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Available MCP tools:
|
|
296
|
+
- **`cortexcode_search`** — Search symbols by name
|
|
297
|
+
- **`cortexcode_context`** — Get rich context with callers/callees
|
|
298
|
+
- **`cortexcode_file_symbols`** — List all symbols in a file
|
|
299
|
+
- **`cortexcode_call_graph`** — Trace call graph for a symbol
|
|
300
|
+
- **`cortexcode_diff`** — Get changed symbols since last commit
|
|
301
|
+
- **`cortexcode_stats`** — Get project statistics
|
|
302
|
+
- **`cortexcode_deadcode`** — Find potentially unused symbols
|
|
303
|
+
- **`cortexcode_complexity`** — Find most complex functions
|
|
304
|
+
- **`cortexcode_impact`** — Analyze change impact of a symbol
|
|
305
|
+
- **`cortexcode_file_deps`** — Get file dependency graph
|
|
306
|
+
|
|
307
|
+
### 4. LSP Server
|
|
308
|
+
|
|
309
|
+
Any LSP-compatible editor can use CortexCode for hover, go-to-definition, and document symbols:
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
cortexcode lsp
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### 5. Git Diff Context
|
|
316
|
+
|
|
317
|
+
See only what changed — perfect for code review:
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
# What symbols changed since last commit?
|
|
321
|
+
cortexcode diff
|
|
322
|
+
|
|
323
|
+
# Compare against a branch
|
|
324
|
+
cortexcode diff --ref main
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### 6. Copilot Chat (`@cortexcode`)
|
|
328
|
+
|
|
329
|
+
In VS Code with the CortexCode extension, use `@cortexcode` in Copilot Chat:
|
|
330
|
+
|
|
331
|
+
```
|
|
332
|
+
@cortexcode search handleAuth
|
|
333
|
+
@cortexcode /context authentication
|
|
334
|
+
@cortexcode /impact createUser
|
|
335
|
+
@cortexcode /deadcode
|
|
336
|
+
@cortexcode /complexity
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Commands:
|
|
340
|
+
- **`/search`** — Find symbols by name
|
|
341
|
+
- **`/context`** — Get ranked context for a query (relevance + call graph connectivity)
|
|
342
|
+
- **`/impact`** — Change impact analysis (direct/indirect callers, affected files/tests)
|
|
343
|
+
- **`/deadcode`** — List potentially unused symbols
|
|
344
|
+
- **`/complexity`** — Show most complex functions by params + outgoing calls
|
|
345
|
+
|
|
346
|
+
### 7. Semantic Search
|
|
347
|
+
|
|
348
|
+
Find symbols by meaning, not just name:
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
cortexcode find "authentication handler"
|
|
352
|
+
cortexcode find "database models"
|
|
353
|
+
cortexcode find "user login flow"
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### 8. Code Analysis
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# Find unused symbols
|
|
360
|
+
cortexcode dead-code
|
|
361
|
+
|
|
362
|
+
# Show top 10 most complex functions
|
|
363
|
+
cortexcode complexity --top 10
|
|
364
|
+
|
|
365
|
+
# What breaks if I change createUser?
|
|
366
|
+
cortexcode impact createUser
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Index Format
|
|
370
|
+
|
|
371
|
+
The index is stored at `.cortexcode/index.json`:
|
|
372
|
+
|
|
373
|
+
```json
|
|
374
|
+
{
|
|
375
|
+
"project_root": "/path/to/project",
|
|
376
|
+
"last_indexed": "2024-03-01T12:00:00",
|
|
377
|
+
"languages": ["javascript", "typescript", "python"],
|
|
378
|
+
"files": {
|
|
379
|
+
"src/auth.ts": {
|
|
380
|
+
"symbols": [
|
|
381
|
+
{
|
|
382
|
+
"name": "AuthService",
|
|
383
|
+
"type": "class",
|
|
384
|
+
"line": 10,
|
|
385
|
+
"params": [],
|
|
386
|
+
"calls": ["validateToken", "hashPassword"]
|
|
387
|
+
}
|
|
388
|
+
],
|
|
389
|
+
"imports": [{ "module": "bcrypt", "imported": ["hash", "compare"] }],
|
|
390
|
+
"exports": [{ "name": "AuthService", "type": "class" }],
|
|
391
|
+
"api_routes": [{ "method": "POST", "path": "/auth/login" }]
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
"call_graph": {
|
|
395
|
+
"AuthService": ["validateToken", "hashPassword"],
|
|
396
|
+
"validateToken": ["jwt.verify"]
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
## Configuration
|
|
402
|
+
|
|
403
|
+
CortexCode respects `.gitignore` files (including nested ones) and has built-in ignore patterns for:
|
|
404
|
+
|
|
405
|
+
- `node_modules/`, `__pycache__/`, `.git/`
|
|
406
|
+
- Build directories (`dist/`, `build/`, `.next/`)
|
|
407
|
+
- IDE files (`.idea/`, `.vscode/`)
|
|
408
|
+
- Package manager files (`vendor/`, `.venv/`)
|
|
409
|
+
|
|
410
|
+
## Roadmap
|
|
411
|
+
|
|
412
|
+
- [x] MCP server for direct AI agent integration
|
|
413
|
+
- [x] Tiktoken-based accurate token counting
|
|
414
|
+
- [x] Semantic search over symbols (TF-IDF + synonym expansion)
|
|
415
|
+
- [x] Cross-file type inference
|
|
416
|
+
- [x] Git diff-aware context (show only changed symbols)
|
|
417
|
+
- [x] Language server protocol (LSP) support
|
|
418
|
+
- [x] Dependency vulnerability scanning
|
|
419
|
+
- [x] CI/CD integration (GitHub Action)
|
|
420
|
+
- [x] Multi-repo workspace support
|
|
421
|
+
- [x] Custom plugin system for framework-specific extractors
|
|
422
|
+
- [x] Web dashboard for index visualization
|
|
423
|
+
- [x] Flutter/Dart language support (regex-based)
|
|
424
|
+
- [x] React Native / Expo framework detection
|
|
425
|
+
- [x] Native Android (Kotlin/Java) framework detection
|
|
426
|
+
- [x] Native iOS (Swift/SwiftUI/UIKit) framework detection
|
|
427
|
+
- [x] Django / Flask framework detection
|
|
428
|
+
- [ ] VS Code Marketplace publishing
|
|
429
|
+
- [ ] OpenAI embedding-based semantic search
|
|
430
|
+
|
|
431
|
+
## Contributing
|
|
432
|
+
|
|
433
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
# Development install
|
|
437
|
+
pip install -e ".[dev]"
|
|
438
|
+
|
|
439
|
+
# Run tests
|
|
440
|
+
pytest
|
|
441
|
+
|
|
442
|
+
# Lint
|
|
443
|
+
ruff check cortexcode/
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
## License
|
|
447
|
+
|
|
448
|
+
MIT — See [LICENSE](LICENSE)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
cortexcode/__init__.py,sha256=6dAo1HGYcfh35uqvPmnci9spfrTgF-OK1vvZ16iwN1I,87
|
|
2
|
+
cortexcode/analysis.py,sha256=25c8UBLNhYqWn2qOVp1wU05be9Pt_AZmp27XMDM3ysU,11503
|
|
3
|
+
cortexcode/cli.py,sha256=uG2e-hIv75q7CbbvaCwXros2qVj5wRYVrnVysmIwjYc,30751
|
|
4
|
+
cortexcode/context.py,sha256=8L4VlXamEYl9rImeGOxW9DhoYBhMuZQi5-mhhSSjOAw,9765
|
|
5
|
+
cortexcode/dashboard.py,sha256=NNK4EhgBo3gBuwwntT5wIi7ZlX1ThHVlbxn6q0c-HdE,5361
|
|
6
|
+
cortexcode/docs.py,sha256=OGrHnWE3qh_rgILMALxt2m2RLa3KE8WfYhFALPF1Nn0,65410
|
|
7
|
+
cortexcode/git_diff.py,sha256=YEEZM2yKYztE-T7rI5iBf2NluY4G1WIjlp-DprZ-6Rs,5742
|
|
8
|
+
cortexcode/indexer.py,sha256=R178y_PKgLjmasyE3ftQjDRA3AxaeI_qyd93pJZLHZQ,81924
|
|
9
|
+
cortexcode/lsp_server.py,sha256=mAPk78OVWQodBjBI3WhqEjrwjXrb0MF630IYDZ8_MLM,11102
|
|
10
|
+
cortexcode/mcp_server.py,sha256=h18bZQ6_6zZVmQfTnQYiP4XGZmzfKBVZZfJQra12cy4,18866
|
|
11
|
+
cortexcode/plugins.py,sha256=6WsmnvRT7D_coxD6YgwB-Dpu_iKOS89FNnT-gkgK4-8,6298
|
|
12
|
+
cortexcode/semantic_search.py,sha256=PO1FjbQhKf6EGfwtwHcdqVXL5W_xMr4e7GxuctdrFzM,8745
|
|
13
|
+
cortexcode/vuln_scan.py,sha256=edU6viXXPLxHdlwDons05g9tLrGuLdPvrNDY-QcqPlU,8539
|
|
14
|
+
cortexcode/watcher.py,sha256=PdY54UzzA70Ff3og2Vv6jE-hzppJRZKpxE4tK8iDVNo,3672
|
|
15
|
+
cortexcode/workspace.py,sha256=ewm5UW_9NQJ0EgjPm46zHMIpZft5UMAlBuX7tt8LWbA,6463
|
|
16
|
+
cortexcode-0.1.0.dist-info/licenses/LICENSE,sha256=DWE8vkHgP2ChQTJHFWtrutLbuHQUBsU_InyfesP4neo,1067
|
|
17
|
+
cortexcode-0.1.0.dist-info/METADATA,sha256=5-ym5wsy3CBFKULNsY3teKAF-5TBM9w7h2qkQqofokw,14707
|
|
18
|
+
cortexcode-0.1.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
19
|
+
cortexcode-0.1.0.dist-info/entry_points.txt,sha256=ZqCHJQMwlffLmdD1m6nyemXlk0M4GWntSH2QORXfNJo,51
|
|
20
|
+
cortexcode-0.1.0.dist-info/top_level.txt,sha256=r8FxzjLfKhRXXcORnECtGo7i2zKYXlV7v1XnIJ0SOc0,11
|
|
21
|
+
cortexcode-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CortexCode
|
|
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
|
+
cortexcode
|