Metadata-Version: 2.4
Name: codetrace-ai
Version: 0.1.2
Summary: A Static + LLM Hybrid CLI for reverse-engineering legacy codebases.
Author-email: Viraj Sawant <sawantviraj465@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/Viraj465/codetrace-ai
Project-URL: Repository, https://github.com/Viraj465/codetrace-ai
Project-URL: Bug Tracker, https://github.com/Viraj465/codetrace-ai/issues
Project-URL: Changelog, https://github.com/Viraj465/codetrace-ai/releases
Keywords: cli,ai,static-analysis,llm,langgraph,codetrace,reverse-engineering,mcp,tree-sitter,rag,agent,chromadb
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: rich>=14.3.3
Requires-Dist: pydantic>=2.12.5
Requires-Dist: typer[all]>=0.24.1
Requires-Dist: langchain>=1.2.10
Requires-Dist: langchain-core>=1.2.16
Requires-Dist: langchain-groq>=1.1.2
Requires-Dist: langchain-community>=0.4.1
Requires-Dist: langchain-chroma>=1.1.0
Requires-Dist: python-dotenv>=1.2.1
Requires-Dist: tree-sitter>=0.25.2
Requires-Dist: tree-sitter-python
Requires-Dist: tree-sitter-javascript
Requires-Dist: tree-sitter-typescript
Requires-Dist: tree-sitter-java
Requires-Dist: tree-sitter-go
Requires-Dist: tree-sitter-c
Requires-Dist: tree-sitter-cpp
Requires-Dist: tree-sitter-rust
Requires-Dist: tree-sitter-php
Requires-Dist: tree-sitter-html
Requires-Dist: tree-sitter-json
Requires-Dist: tree-sitter-css
Requires-Dist: torch==2.5.1
Requires-Dist: sentence-transformers==3.4.1
Requires-Dist: transformers==4.48.3
Requires-Dist: langchain-huggingface>=1.2.0
Requires-Dist: langchain-google-genai>=4.2.1
Requires-Dist: langchain-openai>=1.1.10
Requires-Dist: langchain-anthropic>=1.3.4
Requires-Dist: chromadb>=1.5.2
Requires-Dist: networkx>=3.6.1
Requires-Dist: fastapi>=0.134.0
Requires-Dist: langgraph>=1.0.10
Requires-Dist: langsmith>=0.7.9
Requires-Dist: watchfiles>=1.1.1
Requires-Dist: tiktoken>=0.12.0
Requires-Dist: uvicorn>=0.41.0
Requires-Dist: markitdown>=0.1.5
Requires-Dist: nest-asyncio>=1.6.0
Requires-Dist: pyvis>=0.3.2
Requires-Dist: flashrank>=0.2.10
Requires-Dist: mcp>=1.26.0
Requires-Dist: langchain-ollama>=1.0.1
Provides-Extra: dev
Requires-Dist: pytest>=9.0.2; extra == "dev"
Requires-Dist: pytest-asyncio>=1.3.0; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: isort; extra == "dev"

# 🧠 Codetrace-ai

[![PyPI version](https://img.shields.io/pypi/v/codetrace-ai.svg)](https://pypi.org/project/codetrace-ai/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Downloads](https://static.pepy.tech/badge/codetrace-ai)](https://pepy.tech/project/codetrace-ai)

**The Autonomous System Architect for your Terminal and IDE.**

Codetrace-ai is a deeply integrated, privacy-first AI agent that understands your entire codebase. 

Unlike standard AI coding assistants that rely on naive text chunking, Codetrace builds a **"Hybrid Brain"**—combining a semantic Vector Database (ChromaDB) with a structural Graph Database (SQLite + NetworkX) using Tree-sitter. It doesn't just read your code; it understands what calls what, who owns what, and what breaks if you change something.

## 🎥 Action in Demo

[![Watch Demo](https://img.youtube.com/vi/p2KxkdbD93s/0.jpg)](https://www.youtube.com/watch?v=p2KxkdbD93s)

---

## ✨ What Codetrace Can Do For You
Codetrace acts as a highly knowledgeable senior engineer on your project, capable of:

- **Autonomous Code Research:** Ask a question, and the agent proactively uses tools to search, read files, and analyze the codebase to find the exact answer.
- **Structural Call Graph Mapping:** Navigates class and function definitions across 6+ languages (Python, JS, TS, Java, C++, Go) to see exactly how your application is wired.
- **Blast Radius Analysis:** Analyzes the impact of code modifications before you make them, preventing unintended breakages.
- **Proposing Code Edits:** Automatically writes and presents interactive code changes in the terminal, giving you a diff preview to approve or decline before saving.
- **Smart Delta Syncing:** Reacts to changes in your code using SHA-256 hashing to lightning-fast re-indexes only the files you touched.
- **IDE Context Injection (MCP):** Connects its powerful hybrid brain directly into Cursor, Windsurf, or Claude Code for in-editor assistance.

---

## 🔒 100% Local and Air-Gapped Capable

Codetrace-ai is built with a **Privacy-First** architecture. All parsing, embedding, and graph mapping happens directly on your machine.

**It can be used 100% offline with zero internet connection**, subject to the following terms and conditions:

1. **Local LLM Required:** You must configure a local Large Language Model via a provider like **Ollama** (e.g., `llama3.2` or `deepseek-coder`).
2. **Initial Model Download:** By default, the system requires a brief initial internet connection to download local HuggingFace embedding models (`bge-small` and `e5-small`).
3. **True Air-Gapped Setup:** If your machine has absolute zero internet access, you must:
   - Run `codetrace init` once on a connected machine to cache the embedding models.
   - Transfer the cache folder (`~/.cache/huggingface/hub` on Mac/Linux or `C:\Users\<username>\.cache\huggingface\hub` on Windows) to the offline machine via USB.
4. **Offline Flag:** You must explicitly pass the `--offline` flag to strictly block internal telemetry and external requests (`codetrace init --offline` and `codetrace chat --offline`).

---

## 🚀 Installation

Requires Python 3.10+

```bash
pip install codetrace-ai
```

---

## ⚡ Quick Start

The ultimate frictionless setup. Navigate to any local codebase and type:

```bash
cd /path/to/your/project
codetrace init
- codetrace index . *(run this once at start and then only if you have added new files to the project)*
codetrace chat
```

*(Note: `codetrace init` configures your provider, downloads models, indexes your code, and registers the MCP server in one go!)*

---

## 🛠️ CLI Command Reference

Below is a quick reference of all available Codetrace commands and their 1-line descriptions:

- `codetrace init` — Configures the LLM provider, downloads models, indexes the codebase, and registers MCP.
- `codetrace chat` — Launches the interactive autonomous AI chat loop for your codebase.
- `codetrace index <PATH>` — Forces a re-scan of a local folder or clones and indexes a GitHub URL.
- `codetrace config` — View or update your LLM provider and API key configuration.
- `codetrace visualize` — Generates and opens an interactive HTML graph map of your code architecture.
- `codetrace history` — Lists all past architectural chat sessions for the current project.
- `codetrace export <ID>` — Exports a specific chat session to the terminal or saves it as a Markdown file.

---

## 🔌 IDE Integration (MCP)

Codetrace-ai acts as a **Model Context Protocol (MCP)** server. Running `codetrace init` automatically installs this configuration into Cursor and Claude Code. You do not need to configure anything manually.

Once connected, your IDE gains access to specialized tools:
`search_codebase` (semantic search) • `get_symbol_relations` (call graphs) • `analyze_impact` (blast radius) • `write_file` (propose edits) • `git_diff` 

**Using Windsurf?**
Windsurf does not support auto-registration yet. You can add Codetrace manually. 
1. Open your `mcp.json` file in Windsurf.
2. Add the following to your `mcpServers` block:
```json
"codetrace": {
  "command": "python",
  "args": [
    "/absolute/path/to/your/project/codetrace_mcp/server.py",
    "--project",
    "/absolute/path/to/your/project"
  ]
}
```

---

## 📂 File Structure

After initialization, your project will look like this:

```
your-project/
├── .codetrace/            ← created by codetrace
│   ├── chroma/            ← vector embeddings (ChromaDB)
│   ├── graph_metadata.db  ← code graph (SQLite)
│   └── chat_history.db    ← chat sessions (SQLite)
├── src/
├── ...
└── your code files
```

*(Global config is stored in `~/.codetrace/config.json`)*

*Run `codetrace chat` to start the interactive AI chat loop for your codebase. Once started, you can ask questions about your code and the AI will use its tools to find the answers and provide them to you in a conversational format. You can also use the `/clear` command to start a new session without exiting the chat.*
*For first time to see if all files are indexed correctly or not ask: `inspect_index`*
*To see the call graph of your code ask: `visualize`*
