cortexcode 0.1.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.
@@ -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,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)