code-memory 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.
- .github/workflows/ci.yml +71 -0
- .github/workflows/publish.yml +33 -0
- .gitignore +40 -0
- .python-version +1 -0
- CHANGELOG.md +43 -0
- CONTRIBUTING.md +133 -0
- LICENSE +21 -0
- Makefile +33 -0
- PKG-INFO +275 -0
- README.md +233 -0
- code_memory-0.1.0.dist-info/METADATA +275 -0
- code_memory-0.1.0.dist-info/RECORD +37 -0
- code_memory-0.1.0.dist-info/WHEEL +4 -0
- code_memory-0.1.0.dist-info/entry_points.txt +2 -0
- code_memory-0.1.0.dist-info/licenses/LICENSE +21 -0
- db.py +403 -0
- doc_parser.py +494 -0
- errors.py +115 -0
- git_search.py +313 -0
- logging_config.py +191 -0
- parser.py +392 -0
- prompts/milestone_1.xml +62 -0
- prompts/milestone_2.xml +246 -0
- prompts/milestone_3.xml +214 -0
- prompts/milestone_4.xml +453 -0
- prompts/milestone_5.xml +599 -0
- pyproject.toml +92 -0
- queries.py +446 -0
- server.py +299 -0
- tests/__init__.py +1 -0
- tests/conftest.py +192 -0
- tests/test_errors.py +112 -0
- tests/test_logging.py +169 -0
- tests/test_tools.py +114 -0
- tests/test_validation.py +216 -0
- uv.lock +1921 -0
- validation.py +316 -0
.github/workflows/ci.yml
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.13"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
23
|
+
run: uv python install ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: uv sync --all-extras
|
|
27
|
+
|
|
28
|
+
- name: Run linting
|
|
29
|
+
run: uv run ruff check .
|
|
30
|
+
|
|
31
|
+
- name: Run tests
|
|
32
|
+
run: uv run pytest tests/ -v --tb=short
|
|
33
|
+
|
|
34
|
+
build:
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
needs: test
|
|
37
|
+
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
|
|
41
|
+
- name: Install uv
|
|
42
|
+
uses: astral-sh/setup-uv@v4
|
|
43
|
+
|
|
44
|
+
- name: Build package
|
|
45
|
+
run: uv build
|
|
46
|
+
|
|
47
|
+
- name: Upload artifacts
|
|
48
|
+
uses: actions/upload-artifact@v4
|
|
49
|
+
with:
|
|
50
|
+
name: dist
|
|
51
|
+
path: dist/
|
|
52
|
+
|
|
53
|
+
publish:
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
needs: build
|
|
56
|
+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
|
57
|
+
|
|
58
|
+
steps:
|
|
59
|
+
- uses: actions/checkout@v4
|
|
60
|
+
|
|
61
|
+
- name: Install uv
|
|
62
|
+
uses: astral-sh/setup-uv@v4
|
|
63
|
+
|
|
64
|
+
- name: Download artifacts
|
|
65
|
+
uses: actions/download-artifact@v4
|
|
66
|
+
with:
|
|
67
|
+
name: dist
|
|
68
|
+
path: dist/
|
|
69
|
+
|
|
70
|
+
- name: Publish to PyPI
|
|
71
|
+
run: uv publish --token ${{ secrets.PYPI_TOKEN }}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
name: Build and publish
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write # Required for PyPI trusted publishing
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout code
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Install uv
|
|
21
|
+
uses: astral-sh/setup-uv@v5
|
|
22
|
+
with:
|
|
23
|
+
enable-cache: true
|
|
24
|
+
|
|
25
|
+
# uv python install ensures the required python version is available
|
|
26
|
+
- name: Set up Python
|
|
27
|
+
run: uv python install
|
|
28
|
+
|
|
29
|
+
- name: Build package
|
|
30
|
+
run: uv build
|
|
31
|
+
|
|
32
|
+
- name: Publish to PyPI
|
|
33
|
+
run: uv publish
|
.gitignore
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# ── Python ─────────────────────────────────────────────────────────────
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
*.egg
|
|
9
|
+
|
|
10
|
+
# ── Virtual environments ──────────────────────────────────────────────
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
ENV/
|
|
14
|
+
|
|
15
|
+
# ── SQLite databases ─────────────────────────────────────────────────
|
|
16
|
+
*.db
|
|
17
|
+
*.db-shm
|
|
18
|
+
*.db-wal
|
|
19
|
+
*.db-journal
|
|
20
|
+
*.sqlite
|
|
21
|
+
*.sqlite3
|
|
22
|
+
|
|
23
|
+
# ── IDE ───────────────────────────────────────────────────────────────
|
|
24
|
+
.vscode/
|
|
25
|
+
.idea/
|
|
26
|
+
*.swp
|
|
27
|
+
*.swo
|
|
28
|
+
*~
|
|
29
|
+
|
|
30
|
+
# ── OS ────────────────────────────────────────────────────────────────
|
|
31
|
+
.DS_Store
|
|
32
|
+
Thumbs.db
|
|
33
|
+
|
|
34
|
+
# ── Testing / Coverage ───────────────────────────────────────────────
|
|
35
|
+
.pytest_cache/
|
|
36
|
+
.coverage
|
|
37
|
+
htmlcov/
|
|
38
|
+
|
|
39
|
+
# ── uv lock (keep in repo) ───────────────────────────────────────────
|
|
40
|
+
# uv.lock is committed intentionally
|
.python-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2025-02-22
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release
|
|
12
|
+
- `search_code` tool with hybrid retrieval (BM25 + vector + RRF fusion)
|
|
13
|
+
- Find symbol definitions with semantic search
|
|
14
|
+
- Find cross-references to symbols
|
|
15
|
+
- Get file structure (all symbols in a file)
|
|
16
|
+
- `search_docs` tool for documentation search
|
|
17
|
+
- Index markdown files and READMEs
|
|
18
|
+
- Extract docstrings from code symbols
|
|
19
|
+
- Hybrid search over documentation chunks
|
|
20
|
+
- `search_history` tool for Git history search
|
|
21
|
+
- Search commit messages
|
|
22
|
+
- Get file history with rename tracking
|
|
23
|
+
- Run git blame with line range support
|
|
24
|
+
- Get detailed commit information
|
|
25
|
+
- `index_codebase` tool for code and documentation indexing
|
|
26
|
+
- Multi-language AST parsing with tree-sitter
|
|
27
|
+
- Supports Python, JavaScript/TypeScript, Java, Kotlin, Go, Rust, C/C++, Ruby
|
|
28
|
+
- Incremental indexing (skips unchanged files)
|
|
29
|
+
- Generates embeddings for semantic search
|
|
30
|
+
- Production hardening
|
|
31
|
+
- Structured error handling with custom exceptions
|
|
32
|
+
- Input validation with clear error messages
|
|
33
|
+
- Configurable logging via `CODE_MEMORY_LOG_LEVEL` environment variable
|
|
34
|
+
- CI/CD with GitHub Actions
|
|
35
|
+
- Test suite with pytest
|
|
36
|
+
|
|
37
|
+
### Dependencies
|
|
38
|
+
- mcp[cli] - Model Context Protocol server
|
|
39
|
+
- sqlite-vec - Vector search extension for SQLite
|
|
40
|
+
- sentence-transformers - Local embedding model (all-MiniLM-L6-v2)
|
|
41
|
+
- tree-sitter + language packages - Multi-language AST parsing
|
|
42
|
+
- gitpython - Git operations
|
|
43
|
+
- markdown-it-py - Markdown parsing
|
CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Contributing to code-memory
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to code-memory! This document provides guidelines and instructions for contributing.
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- Python >= 3.13
|
|
10
|
+
- [uv](https://docs.astral.sh/uv/) package manager
|
|
11
|
+
|
|
12
|
+
### Clone and Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Clone the repository
|
|
16
|
+
git clone https://github.com/kapillamba4/code-memory.git
|
|
17
|
+
cd code-memory
|
|
18
|
+
|
|
19
|
+
# Install dependencies (including dev dependencies)
|
|
20
|
+
uv sync --all-extras
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Run the Server
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Run the MCP server
|
|
27
|
+
uv run mcp run server.py
|
|
28
|
+
|
|
29
|
+
# Run with MCP Inspector for debugging
|
|
30
|
+
uv run mcp dev server.py
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Development Workflow
|
|
34
|
+
|
|
35
|
+
### Running Tests
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Run all tests
|
|
39
|
+
uv run pytest tests/ -v
|
|
40
|
+
|
|
41
|
+
# Run with coverage
|
|
42
|
+
uv run pytest tests/ -v --cov --cov-report=term-missing
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Linting and Formatting
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Run ruff linter
|
|
49
|
+
uv run ruff check .
|
|
50
|
+
|
|
51
|
+
# Run ruff formatter
|
|
52
|
+
uv run ruff format .
|
|
53
|
+
|
|
54
|
+
# Run type checking
|
|
55
|
+
uv run mypy .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Building
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Build the package
|
|
62
|
+
uv build
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Code Style
|
|
66
|
+
|
|
67
|
+
- Follow [PEP 8](https://peps.python.org/pep-0008/) conventions
|
|
68
|
+
- Maximum line length is 100 characters
|
|
69
|
+
- Use type hints for function parameters and return types
|
|
70
|
+
- Write docstrings for public functions and classes
|
|
71
|
+
|
|
72
|
+
## Project Structure
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
code-memory/
|
|
76
|
+
├── server.py # MCP server entry point
|
|
77
|
+
├── db.py # SQLite database layer
|
|
78
|
+
├── parser.py # Tree-sitter code parser
|
|
79
|
+
├── doc_parser.py # Markdown documentation parser
|
|
80
|
+
├── queries.py # Hybrid retrieval query layer
|
|
81
|
+
├── git_search.py # Git history search module
|
|
82
|
+
├── errors.py # Custom exception hierarchy
|
|
83
|
+
├── validation.py # Input validation functions
|
|
84
|
+
├── logging_config.py # Structured logging configuration
|
|
85
|
+
├── tests/ # Test suite
|
|
86
|
+
├── prompts/ # Milestone prompt files
|
|
87
|
+
└── pyproject.toml # Project configuration
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Pull Request Process
|
|
91
|
+
|
|
92
|
+
1. Fork the repository
|
|
93
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
94
|
+
3. Make your changes
|
|
95
|
+
4. Run tests and linting (`uv run pytest && uv run ruff check .`)
|
|
96
|
+
5. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
97
|
+
6. Push to the branch (`git push origin feature/amazing-feature`)
|
|
98
|
+
7. Open a Pull Request
|
|
99
|
+
|
|
100
|
+
### PR Guidelines
|
|
101
|
+
|
|
102
|
+
- Include a clear description of the changes
|
|
103
|
+
- Reference any related issues
|
|
104
|
+
- Ensure all tests pass
|
|
105
|
+
- Add tests for new functionality
|
|
106
|
+
- Update documentation if needed
|
|
107
|
+
|
|
108
|
+
## Adding New Features
|
|
109
|
+
|
|
110
|
+
### Adding a New Tool
|
|
111
|
+
|
|
112
|
+
1. Add the tool function in `server.py` with the `@mcp.tool()` decorator
|
|
113
|
+
2. Add input validation using functions from `validation.py`
|
|
114
|
+
3. Wrap the implementation in error handling
|
|
115
|
+
4. Add logging using `ToolLogger`
|
|
116
|
+
5. Write tests in `tests/test_tools.py`
|
|
117
|
+
|
|
118
|
+
### Adding a New Language Parser
|
|
119
|
+
|
|
120
|
+
1. Add the tree-sitter language package to `pyproject.toml`
|
|
121
|
+
2. Update the language registry in `parser.py`
|
|
122
|
+
3. Add node-type mappings for the new language
|
|
123
|
+
4. Write tests for the new language
|
|
124
|
+
|
|
125
|
+
## Environment Variables
|
|
126
|
+
|
|
127
|
+
| Variable | Description | Default |
|
|
128
|
+
|----------|-------------|---------|
|
|
129
|
+
| `CODE_MEMORY_LOG_LEVEL` | Logging verbosity (DEBUG, INFO, WARNING, ERROR) | INFO |
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
By contributing to code-memory, you agree that your contributions will be licensed under the MIT License.
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kapil Lamba
|
|
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.
|
Makefile
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.PHONY: run dev inspect lint format test clean help
|
|
2
|
+
|
|
3
|
+
# ── Server ─────────────────────────────────────────────────────────────
|
|
4
|
+
run: ## Run the MCP server (stdio transport)
|
|
5
|
+
uv run mcp run server.py
|
|
6
|
+
|
|
7
|
+
dev: ## Run with MCP Inspector for interactive debugging
|
|
8
|
+
uv run mcp dev server.py
|
|
9
|
+
|
|
10
|
+
# ── Code Quality ───────────────────────────────────────────────────────
|
|
11
|
+
lint: ## Run ruff linter
|
|
12
|
+
uv run ruff check .
|
|
13
|
+
|
|
14
|
+
format: ## Auto-format with ruff
|
|
15
|
+
uv run ruff format .
|
|
16
|
+
|
|
17
|
+
# ── Testing ────────────────────────────────────────────────────────────
|
|
18
|
+
test: ## Run test suite
|
|
19
|
+
uv run pytest -v
|
|
20
|
+
|
|
21
|
+
# ── Housekeeping ───────────────────────────────────────────────────────
|
|
22
|
+
clean: ## Remove caches and build artifacts
|
|
23
|
+
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
|
24
|
+
find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
|
|
25
|
+
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
|
|
26
|
+
rm -rf dist/ build/
|
|
27
|
+
|
|
28
|
+
# ── Help ───────────────────────────────────────────────────────────────
|
|
29
|
+
help: ## Show this help message
|
|
30
|
+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
|
|
31
|
+
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
|
|
32
|
+
|
|
33
|
+
.DEFAULT_GOAL := help
|
PKG-INFO
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: code-memory
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A deterministic, high-precision code intelligence MCP server
|
|
5
|
+
Project-URL: Homepage, https://github.com/kapillamba4/code-memory
|
|
6
|
+
Project-URL: Documentation, https://github.com/kapillamba4/code-memory#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/kapillamba4/code-memory.git
|
|
8
|
+
Project-URL: Issues, https://github.com/kapillamba4/code-memory/issues
|
|
9
|
+
Author-email: Kapil Lambert <kapillamba4@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.13
|
|
19
|
+
Requires-Dist: gitpython>=3.1.46
|
|
20
|
+
Requires-Dist: markdown-it-py>=4.0.0
|
|
21
|
+
Requires-Dist: mcp[cli]>=1.26.0
|
|
22
|
+
Requires-Dist: sentence-transformers>=5.2.3
|
|
23
|
+
Requires-Dist: sqlite-vec>=0.1.6
|
|
24
|
+
Requires-Dist: tree-sitter-c>=0.24.1
|
|
25
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4
|
|
26
|
+
Requires-Dist: tree-sitter-go>=0.25.0
|
|
27
|
+
Requires-Dist: tree-sitter-java>=0.23.5
|
|
28
|
+
Requires-Dist: tree-sitter-javascript>=0.25.0
|
|
29
|
+
Requires-Dist: tree-sitter-kotlin>=1.1.0
|
|
30
|
+
Requires-Dist: tree-sitter-python>=0.25.0
|
|
31
|
+
Requires-Dist: tree-sitter-ruby>=0.23.1
|
|
32
|
+
Requires-Dist: tree-sitter-rust>=0.24.0
|
|
33
|
+
Requires-Dist: tree-sitter-typescript>=0.23.2
|
|
34
|
+
Requires-Dist: tree-sitter>=0.25.2
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: mypy>=1.13.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
40
|
+
Requires-Dist: ruff>=0.8.0; extra == 'dev'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# code-memory
|
|
44
|
+
|
|
45
|
+
A deterministic, high-precision **code intelligence layer** exposed as a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server.
|
|
46
|
+
|
|
47
|
+
`code-memory` gives your AI coding assistant structured access to your codebase through three focused pathways — eliminating context-window bloat and vague "search everything" queries.
|
|
48
|
+
|
|
49
|
+
## Architecture: Progressive Disclosure
|
|
50
|
+
|
|
51
|
+
Instead of a single monolithic search, `code-memory` routes queries through **three purpose-built tools**:
|
|
52
|
+
|
|
53
|
+
| Question Type | Tool | Data Source |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| **"Where / What / How?"** — find definitions, references, structure, semantic search | `search_code` | BM25 + Dense Vector (SQLite vec) |
|
|
56
|
+
| **"Architecture / Patterns"** — understand architecture, explain workflows | `search_docs` | Semantic / Fuzzy |
|
|
57
|
+
| **"Who / Why?"** — debug regressions, understand intent | `search_history` | Git + BM25 + Dense Vector (SQLite vec) |
|
|
58
|
+
| **"Setup / Prepare"** — index parsing & embedding generation | `index_codebase` | AST Parser + `sentence-transformers` |
|
|
59
|
+
|
|
60
|
+
This forces the LLM to pick the *right retrieval strategy* before any data is fetched.
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
### From PyPI (Recommended)
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Install with pip
|
|
68
|
+
pip install code-memory
|
|
69
|
+
|
|
70
|
+
# Or with uvx (for MCP hosts)
|
|
71
|
+
uvx code-memory
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### From Source
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Clone the repo
|
|
78
|
+
git clone https://github.com/kapillamba4/code-memory.git
|
|
79
|
+
cd code-memory
|
|
80
|
+
|
|
81
|
+
# Install dependencies
|
|
82
|
+
uv sync
|
|
83
|
+
|
|
84
|
+
# Run the MCP server (stdio transport)
|
|
85
|
+
uv run mcp run server.py
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Quickstart
|
|
89
|
+
|
|
90
|
+
### Prerequisites
|
|
91
|
+
|
|
92
|
+
- Python ≥ 3.13
|
|
93
|
+
- [`uv`](https://docs.astral.sh/uv/) package manager (recommended) or pip
|
|
94
|
+
|
|
95
|
+
### Install & Run
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Install from PyPI
|
|
99
|
+
pip install code-memory
|
|
100
|
+
|
|
101
|
+
# Or run directly with uvx
|
|
102
|
+
uvx code-memory
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Development
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Run with the MCP Inspector for interactive debugging
|
|
109
|
+
uv run mcp dev server.py
|
|
110
|
+
|
|
111
|
+
# Run tests
|
|
112
|
+
uv run pytest tests/ -v
|
|
113
|
+
|
|
114
|
+
# Lint and format
|
|
115
|
+
uv run ruff check .
|
|
116
|
+
uv run ruff format .
|
|
117
|
+
|
|
118
|
+
# Build package
|
|
119
|
+
uv build
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Configure Your MCP Host
|
|
123
|
+
|
|
124
|
+
### Gemini CLI / Gemini Code Assist
|
|
125
|
+
|
|
126
|
+
Add to your MCP settings (e.g. `~/.gemini/settings.json`):
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"mcpServers": {
|
|
131
|
+
"code-memory": {
|
|
132
|
+
"command": "uvx",
|
|
133
|
+
"args": ["code-memory"]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Claude Desktop
|
|
140
|
+
|
|
141
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"mcpServers": {
|
|
146
|
+
"code-memory": {
|
|
147
|
+
"command": "uvx",
|
|
148
|
+
"args": ["code-memory"]
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### VS Code (Copilot / Continue)
|
|
155
|
+
|
|
156
|
+
Add to `.vscode/mcp.json` in your workspace:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"servers": {
|
|
161
|
+
"code-memory": {
|
|
162
|
+
"command": "uvx",
|
|
163
|
+
"args": ["code-memory"]
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Configuration
|
|
170
|
+
|
|
171
|
+
### Environment Variables
|
|
172
|
+
|
|
173
|
+
| Variable | Description | Default |
|
|
174
|
+
|----------|-------------|---------|
|
|
175
|
+
| `CODE_MEMORY_LOG_LEVEL` | Logging verbosity (DEBUG, INFO, WARNING, ERROR) | INFO |
|
|
176
|
+
|
|
177
|
+
Example:
|
|
178
|
+
```bash
|
|
179
|
+
CODE_MEMORY_LOG_LEVEL=DEBUG uvx code-memory
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Tools
|
|
183
|
+
|
|
184
|
+
### `index_codebase`
|
|
185
|
+
|
|
186
|
+
Indexes or re-indexes source files and documentation in the given directory. Run this before using `search_code` or `search_docs` to ensure the database is up to date. Uses tree-sitter for language-agnostic structural extraction and generates dense vector embeddings using `sentence-transformers` (runs locally, in-process) for semantic search.
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
index_codebase(directory=".")
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### `search_code`
|
|
193
|
+
|
|
194
|
+
Perform semantic search and find structural code definitions, locate where functions/classes are defined, or map out dependency references (call graphs). Uses hybrid retrieval (BM25 + vector embeddings) to find exact matches and semantic similarities.
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
search_code(query="parse python files", search_type="definition")
|
|
198
|
+
search_code(query="how do we establish the database connection", search_type="references")
|
|
199
|
+
search_code(query="src/auth/", search_type="file_structure")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### `search_docs`
|
|
203
|
+
|
|
204
|
+
Understand the codebase conceptually — how things work, architectural patterns, SOPs. Searches markdown documentation, READMEs, and docstrings extracted from code.
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
search_docs(query="how does the authentication flow work?")
|
|
208
|
+
search_docs(query="installation instructions", top_k=5)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### `search_history`
|
|
212
|
+
|
|
213
|
+
Debug regressions and understand developer intent through Git history.
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
search_history(query="fix login timeout", search_type="commits")
|
|
217
|
+
search_history(query="src/auth/login.py", search_type="file_history", target_file="src/auth/login.py")
|
|
218
|
+
search_history(query="server.py", search_type="blame", target_file="server.py", line_start=1, line_end=20)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Project Structure
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
code-memory/
|
|
225
|
+
├── server.py # MCP server entry point (FastMCP)
|
|
226
|
+
├── db.py # SQLite database layer with sqlite-vec
|
|
227
|
+
├── parser.py # Tree-sitter-based code parser
|
|
228
|
+
├── doc_parser.py # Markdown documentation parser
|
|
229
|
+
├── queries.py # Hybrid retrieval query layer
|
|
230
|
+
├── git_search.py # Git history search module
|
|
231
|
+
├── errors.py # Custom exception hierarchy
|
|
232
|
+
├── validation.py # Input validation functions
|
|
233
|
+
├── logging_config.py # Structured logging configuration
|
|
234
|
+
├── tests/ # Test suite
|
|
235
|
+
├── pyproject.toml # Project metadata & dependencies
|
|
236
|
+
└── prompts/ # Milestone prompt engineering files
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Troubleshooting
|
|
240
|
+
|
|
241
|
+
### "Git repository not found" error
|
|
242
|
+
|
|
243
|
+
Make sure you're running `search_history` from within a git repository. The tool searches upward from the current directory to find `.git`.
|
|
244
|
+
|
|
245
|
+
### Empty search results
|
|
246
|
+
|
|
247
|
+
Run `index_codebase(directory=".")` first to index your code and documentation. The index is stored locally in `code_memory.db`.
|
|
248
|
+
|
|
249
|
+
### Slow indexing
|
|
250
|
+
|
|
251
|
+
Indexing generates embeddings using a local sentence-transformers model. The first run downloads the model (~90MB). Subsequent runs are faster.
|
|
252
|
+
|
|
253
|
+
### Embedding model errors
|
|
254
|
+
|
|
255
|
+
Ensure you have enough disk space and memory. The `all-MiniLM-L6-v2` model requires ~500MB RAM when loaded.
|
|
256
|
+
|
|
257
|
+
## Roadmap
|
|
258
|
+
|
|
259
|
+
- [x] **Milestone 1** — Project scaffolding & MCP protocol wiring
|
|
260
|
+
- [x] **Milestone 2** — Implement `search_code` with AST parsing + SQLite + `sqlite-vec`
|
|
261
|
+
- [x] **Milestone 3** — Implement `search_history` with Git integration
|
|
262
|
+
- [x] **Milestone 4** — Implement `search_docs` with semantic search
|
|
263
|
+
- [x] **Milestone 5** — Production hardening & packaging
|
|
264
|
+
|
|
265
|
+
## Contributing
|
|
266
|
+
|
|
267
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
|
|
268
|
+
|
|
269
|
+
## Changelog
|
|
270
|
+
|
|
271
|
+
See [CHANGELOG.md](CHANGELOG.md) for version history.
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|