contextly 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,42 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual Environment
24
+ .env
25
+ .venv
26
+ env/
27
+ venv/
28
+ ENV/
29
+
30
+ # IDE
31
+ .idea/
32
+ .vscode/
33
+ *.swp
34
+ *.swo
35
+
36
+ # Project specific
37
+ .contextly/
38
+ *.db
39
+ embeddings/
40
+
41
+ # Misc
42
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Contextly Team
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,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: contextly
3
+ Version: 0.1.0
4
+ Summary: AI Context Engine for Developers
5
+ Project-URL: Homepage, https://github.com/contextly/contextly
6
+ Project-URL: Repository, https://github.com/contextly/contextly
7
+ Project-URL: Documentation, https://github.com/contextly/contextly#readme
8
+ Project-URL: Bug Tracker, https://github.com/contextly/contextly/issues
9
+ Author-email: Contextly Team <team@contextly.dev>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai,analysis,code,context,development,documentation,llm
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Topic :: Software Development :: Documentation
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: aiohttp>=3.8.0
25
+ Requires-Dist: aiosqlite>=0.19.0
26
+ Requires-Dist: asyncio>=3.4.3
27
+ Requires-Dist: cachetools>=5.3.2
28
+ Requires-Dist: chromadb>=0.4.0
29
+ Requires-Dist: colorama>=0.4.6
30
+ Requires-Dist: huggingface-hub>=0.19.0
31
+ Requires-Dist: openai>=1.0.0
32
+ Requires-Dist: pydantic>=2.0.0
33
+ Requires-Dist: python-dotenv>=1.0.0
34
+ Requires-Dist: pyyaml>=6.0.0
35
+ Requires-Dist: requests>=2.31.0
36
+ Requires-Dist: rich>=13.0.0
37
+ Requires-Dist: sentence-transformers>=2.2.0
38
+ Requires-Dist: tiktoken>=0.5.1
39
+ Requires-Dist: tokenizers>=0.15.0
40
+ Requires-Dist: toml>=0.10.2
41
+ Requires-Dist: tqdm>=4.66.1
42
+ Requires-Dist: transformers>=4.35.0
43
+ Requires-Dist: typer>=0.9.0
44
+ Provides-Extra: dev
45
+ Requires-Dist: black>=23.0.0; extra == 'dev'
46
+ Requires-Dist: isort>=5.12.0; extra == 'dev'
47
+ Requires-Dist: mypy>=1.5.0; extra == 'dev'
48
+ Requires-Dist: pre-commit>=3.3.0; extra == 'dev'
49
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
50
+ Provides-Extra: test
51
+ Requires-Dist: black>=23.0.0; extra == 'test'
52
+ Requires-Dist: isort>=5.12.0; extra == 'test'
53
+ Requires-Dist: mypy>=1.5.0; extra == 'test'
54
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'test'
55
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
56
+ Requires-Dist: pytest>=7.0.0; extra == 'test'
57
+ Requires-Dist: ruff>=0.1.0; extra == 'test'
58
+ Description-Content-Type: text/markdown
59
+
60
+ # 🧠 Contextly - The AI Context Engine for Developers
61
+
62
+ > "Know your code. Know your configs. Instantly."
63
+
64
+ Contextly is your terminal-native AI that helps you understand your codebase and configuration environment with natural-language queries and AI-powered explanations.
65
+
66
+ ## 🎯 Features
67
+
68
+ - **Natural Language Queries**: Ask questions about your code in plain English
69
+ - **Configuration Management**: Compare and analyze config files (env, json, yaml, etc.)
70
+ - **Semantic Code Search**: Find relevant code snippets by describing what you're looking for
71
+ - **Offline Support**: Built-in local LLM integration with Ollama
72
+ - **Multi-Language Support**: Works with Python, JavaScript, TypeScript, and more
73
+ - **Privacy-Focused**: Your code never leaves your machine (when using local LLMs)
74
+ - **VSCode-Friendly**: All features work directly in your terminal or VS Code
75
+
76
+ ## ⚡ Quick Start
77
+
78
+ 1. **Installation**
79
+ ```bash
80
+ pip install contextly
81
+ ```
82
+
83
+ 2. **Setup (Optional)**
84
+ ```bash
85
+ # Configure local LLM (recommended)
86
+ brew install ollama
87
+ ollama pull codellama
88
+
89
+ # Or set up OpenAI (optional)
90
+ export OPENAI_API_KEY=your_api_key
91
+ ```
92
+
93
+ 3. **Initialize in Your Repo**
94
+ ```bash
95
+ cd your-project
96
+ contextly sync
97
+ ```
98
+
99
+ ## 💡 Usage
100
+
101
+ ### Ask Questions About Your Code
102
+
103
+ ```bash
104
+ # General questions
105
+ contextly ask "How is user authentication handled?"
106
+ contextly ask "What's the database schema like?"
107
+
108
+ # Specific file questions
109
+ contextly ask "What does the login function in auth.py do?"
110
+
111
+ # Architecture questions
112
+ contextly ask "What's the overall project structure?"
113
+ ```
114
+
115
+ ### Search Code Semantically
116
+
117
+ ```bash
118
+ # Find relevant code
119
+ contextly search "password hashing implementation"
120
+ contextly search "database connection setup"
121
+ ```
122
+
123
+ ### Analyze Specific Code
124
+
125
+ ```bash
126
+ # Get explanation for code at a specific line
127
+ contextly explain src/auth.py:42
128
+
129
+ # Understand a function or class
130
+ contextly explain src/models.py:15
131
+ ```
132
+
133
+ ### Compare Config Files
134
+
135
+ ```bash
136
+ # Compare different environment files
137
+ contextly diff .env.dev .env.prod
138
+
139
+ # Compare any config files
140
+ contextly diff config/local.yml config/prod.yml
141
+ ```
142
+
143
+ ## ⚙️ Configuration
144
+
145
+ Contextly can be configured via environment variables or a `contextly.yml` file in your project root:
146
+
147
+ ```yaml
148
+ # contextly.yml
149
+ llm:
150
+ provider: ollama # or 'openai'
151
+ model: codellama # or 'gpt-4' for OpenAI
152
+ temperature: 0.2
153
+
154
+ embedding:
155
+ model: all-MiniLM-L6-v2 # Default embedding model
156
+ cache_dir: .contextly # Where to store the vector index
157
+
158
+ parsers:
159
+ python:
160
+ enabled: true
161
+ javascript:
162
+ enabled: true
163
+ config:
164
+ enabled: true
165
+ extensions: ['.json', '.yml', '.yaml', '.env', '.toml']
166
+ ```
167
+
168
+ ### Environment Variables
169
+
170
+ - `CONTEXTLY_LLM_PROVIDER`: 'ollama' or 'openai'
171
+ - `CONTEXTLY_MODEL`: LLM model to use
172
+ - `OPENAI_API_KEY`: Required if using OpenAI
173
+ - `CONTEXTLY_CACHE_DIR`: Where to store the vector index
174
+
175
+ ## �️ How It Works
176
+
177
+ Contextly works by:
178
+
179
+ 1. **Parsing**: Analyzes your code and config files using language-specific parsers
180
+ 2. **Embedding**: Creates vector embeddings of your code using SentenceTransformers
181
+ 3. **Indexing**: Stores embeddings in a local ChromaDB for fast retrieval
182
+ 4. **Reasoning**: Uses local or cloud LLMs to understand and explain code
183
+
184
+ ## 🤝 Contributing
185
+
186
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for:
187
+
188
+ - Setting up the development environment
189
+ - Running tests
190
+ - Code style guidelines
191
+ - Pull request process
192
+
193
+ ## 📝 License
194
+
195
+ MIT License - see [LICENSE](LICENSE) for details.
196
+
197
+ ## 🙋 FAQ
198
+
199
+ **Q: How does offline mode work?**
200
+ A: When using Ollama as the LLM provider, all processing happens locally. Your code never leaves your machine.
201
+
202
+ **Q: What languages are supported?**
203
+ A: Currently Python, JavaScript, TypeScript, and various config formats (JSON, YAML, TOML, ENV). More coming soon!
204
+
205
+ **Q: How can I customize the LLM responses?**
206
+ A: Adjust the `temperature` setting in your config. Lower values (0.1-0.3) give more precise answers, higher values more creative ones.
207
+
208
+ **Q: Where is data stored?**
209
+ A: By default, the vector index is stored in `.contextly/` in your project root. This can be configured via `CONTEXTLY_CACHE_DIR`.
@@ -0,0 +1,150 @@
1
+ # 🧠 Contextly - The AI Context Engine for Developers
2
+
3
+ > "Know your code. Know your configs. Instantly."
4
+
5
+ Contextly is your terminal-native AI that helps you understand your codebase and configuration environment with natural-language queries and AI-powered explanations.
6
+
7
+ ## 🎯 Features
8
+
9
+ - **Natural Language Queries**: Ask questions about your code in plain English
10
+ - **Configuration Management**: Compare and analyze config files (env, json, yaml, etc.)
11
+ - **Semantic Code Search**: Find relevant code snippets by describing what you're looking for
12
+ - **Offline Support**: Built-in local LLM integration with Ollama
13
+ - **Multi-Language Support**: Works with Python, JavaScript, TypeScript, and more
14
+ - **Privacy-Focused**: Your code never leaves your machine (when using local LLMs)
15
+ - **VSCode-Friendly**: All features work directly in your terminal or VS Code
16
+
17
+ ## ⚡ Quick Start
18
+
19
+ 1. **Installation**
20
+ ```bash
21
+ pip install contextly
22
+ ```
23
+
24
+ 2. **Setup (Optional)**
25
+ ```bash
26
+ # Configure local LLM (recommended)
27
+ brew install ollama
28
+ ollama pull codellama
29
+
30
+ # Or set up OpenAI (optional)
31
+ export OPENAI_API_KEY=your_api_key
32
+ ```
33
+
34
+ 3. **Initialize in Your Repo**
35
+ ```bash
36
+ cd your-project
37
+ contextly sync
38
+ ```
39
+
40
+ ## 💡 Usage
41
+
42
+ ### Ask Questions About Your Code
43
+
44
+ ```bash
45
+ # General questions
46
+ contextly ask "How is user authentication handled?"
47
+ contextly ask "What's the database schema like?"
48
+
49
+ # Specific file questions
50
+ contextly ask "What does the login function in auth.py do?"
51
+
52
+ # Architecture questions
53
+ contextly ask "What's the overall project structure?"
54
+ ```
55
+
56
+ ### Search Code Semantically
57
+
58
+ ```bash
59
+ # Find relevant code
60
+ contextly search "password hashing implementation"
61
+ contextly search "database connection setup"
62
+ ```
63
+
64
+ ### Analyze Specific Code
65
+
66
+ ```bash
67
+ # Get explanation for code at a specific line
68
+ contextly explain src/auth.py:42
69
+
70
+ # Understand a function or class
71
+ contextly explain src/models.py:15
72
+ ```
73
+
74
+ ### Compare Config Files
75
+
76
+ ```bash
77
+ # Compare different environment files
78
+ contextly diff .env.dev .env.prod
79
+
80
+ # Compare any config files
81
+ contextly diff config/local.yml config/prod.yml
82
+ ```
83
+
84
+ ## ⚙️ Configuration
85
+
86
+ Contextly can be configured via environment variables or a `contextly.yml` file in your project root:
87
+
88
+ ```yaml
89
+ # contextly.yml
90
+ llm:
91
+ provider: ollama # or 'openai'
92
+ model: codellama # or 'gpt-4' for OpenAI
93
+ temperature: 0.2
94
+
95
+ embedding:
96
+ model: all-MiniLM-L6-v2 # Default embedding model
97
+ cache_dir: .contextly # Where to store the vector index
98
+
99
+ parsers:
100
+ python:
101
+ enabled: true
102
+ javascript:
103
+ enabled: true
104
+ config:
105
+ enabled: true
106
+ extensions: ['.json', '.yml', '.yaml', '.env', '.toml']
107
+ ```
108
+
109
+ ### Environment Variables
110
+
111
+ - `CONTEXTLY_LLM_PROVIDER`: 'ollama' or 'openai'
112
+ - `CONTEXTLY_MODEL`: LLM model to use
113
+ - `OPENAI_API_KEY`: Required if using OpenAI
114
+ - `CONTEXTLY_CACHE_DIR`: Where to store the vector index
115
+
116
+ ## �️ How It Works
117
+
118
+ Contextly works by:
119
+
120
+ 1. **Parsing**: Analyzes your code and config files using language-specific parsers
121
+ 2. **Embedding**: Creates vector embeddings of your code using SentenceTransformers
122
+ 3. **Indexing**: Stores embeddings in a local ChromaDB for fast retrieval
123
+ 4. **Reasoning**: Uses local or cloud LLMs to understand and explain code
124
+
125
+ ## 🤝 Contributing
126
+
127
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for:
128
+
129
+ - Setting up the development environment
130
+ - Running tests
131
+ - Code style guidelines
132
+ - Pull request process
133
+
134
+ ## 📝 License
135
+
136
+ MIT License - see [LICENSE](LICENSE) for details.
137
+
138
+ ## 🙋 FAQ
139
+
140
+ **Q: How does offline mode work?**
141
+ A: When using Ollama as the LLM provider, all processing happens locally. Your code never leaves your machine.
142
+
143
+ **Q: What languages are supported?**
144
+ A: Currently Python, JavaScript, TypeScript, and various config formats (JSON, YAML, TOML, ENV). More coming soon!
145
+
146
+ **Q: How can I customize the LLM responses?**
147
+ A: Adjust the `temperature` setting in your config. Lower values (0.1-0.3) give more precise answers, higher values more creative ones.
148
+
149
+ **Q: Where is data stored?**
150
+ A: By default, the vector index is stored in `.contextly/` in your project root. This can be configured via `CONTEXTLY_CACHE_DIR`.
@@ -0,0 +1,110 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "contextly"
7
+ version = "0.1.0"
8
+ authors = [
9
+ { name = "Contextly Team", email = "team@contextly.dev" },
10
+ ]
11
+ description = "AI Context Engine for Developers"
12
+ readme = "README.md"
13
+ requires-python = ">=3.9"
14
+ license = "MIT"
15
+ keywords = ["ai", "context", "code", "development", "llm", "documentation", "analysis"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Operating System :: OS Independent",
23
+ "Development Status :: 4 - Beta",
24
+ "Intended Audience :: Developers",
25
+ "Topic :: Software Development :: Libraries :: Python Modules",
26
+ "Topic :: Software Development :: Documentation",
27
+ ]
28
+
29
+ dependencies = [
30
+ "typer>=0.9.0",
31
+ "rich>=13.0.0",
32
+ "sentence-transformers>=2.2.0",
33
+ "chromadb>=0.4.0",
34
+ "pyyaml>=6.0.0",
35
+ "python-dotenv>=1.0.0",
36
+ "toml>=0.10.2",
37
+ "pydantic>=2.0.0",
38
+ "openai>=1.0.0",
39
+ "requests>=2.31.0",
40
+ "colorama>=0.4.6",
41
+ "aiohttp>=3.8.0",
42
+ "huggingface-hub>=0.19.0",
43
+ "tokenizers>=0.15.0",
44
+ "transformers>=4.35.0",
45
+ "asyncio>=3.4.3",
46
+ "aiosqlite>=0.19.0",
47
+ "tiktoken>=0.5.1",
48
+ "tqdm>=4.66.1",
49
+ "cachetools>=5.3.2",
50
+ ]
51
+
52
+ [project.optional-dependencies]
53
+ test = [
54
+ "pytest>=7.0.0",
55
+ "pytest-cov>=4.0.0",
56
+ "pytest-asyncio>=0.21.0",
57
+ "black>=23.0.0",
58
+ "isort>=5.12.0",
59
+ "mypy>=1.5.0",
60
+ "ruff>=0.1.0",
61
+ ]
62
+
63
+ dev = [
64
+ "pre-commit>=3.3.0",
65
+ "black>=23.0.0",
66
+ "isort>=5.12.0",
67
+ "mypy>=1.5.0",
68
+ "ruff>=0.1.0",
69
+ ]
70
+
71
+ [project.scripts]
72
+ contextly = "contextly.cli:app"
73
+
74
+ [project.urls]
75
+ Homepage = "https://github.com/contextly/contextly"
76
+ Repository = "https://github.com/contextly/contextly"
77
+ Documentation = "https://github.com/contextly/contextly#readme"
78
+ "Bug Tracker" = "https://github.com/contextly/contextly/issues"
79
+
80
+ [tool.pytest.ini_options]
81
+ testpaths = ["tests"]
82
+ python_files = ["test_*.py"]
83
+ addopts = "--cov=contextly --cov-report=term-missing"
84
+
85
+ [tool.black]
86
+ line-length = 100
87
+ target-version = ['py39']
88
+ include = '\.pyi?$'
89
+
90
+ [tool.isort]
91
+ profile = "black"
92
+ line_length = 100
93
+ multi_line_output = 3
94
+
95
+ [tool.mypy]
96
+ python_version = "3.9"
97
+ disallow_untyped_defs = true
98
+ disallow_incomplete_defs = true
99
+ check_untyped_defs = true
100
+ disallow_untyped_decorators = true
101
+ no_implicit_optional = true
102
+ warn_redundant_casts = true
103
+ warn_return_any = true
104
+ warn_unused_ignores = true
105
+ warn_unused_configs = true
106
+
107
+ [tool.ruff]
108
+ line-length = 100
109
+ target-version = "py39"
110
+ select = ["E", "F", "B", "I", "UP"]
@@ -0,0 +1,5 @@
1
+ """
2
+ Contextly - The AI Context Engine for Developers
3
+ """
4
+
5
+ __version__ = "0.1.0"
@@ -0,0 +1,85 @@
1
+ """
2
+ Core business logic for Contextly commands.
3
+ """
4
+
5
+ from pathlib import Path
6
+ from typing import Dict, Any, Optional
7
+
8
+ from .core.analyzer import CodeAnalyzer
9
+ from .core.embeddings import EmbeddingEngine
10
+ from .core.sync import RepoSync
11
+ from .llm.manager import LLMManager
12
+
13
+ class Contextly:
14
+ """Main class coordinating Contextly's functionality."""
15
+
16
+ def __init__(self, repo_path: Optional[Path] = None, model: Optional[str] = None):
17
+ self.repo_path = repo_path or Path.cwd()
18
+ self.llm_manager = LLMManager(model)
19
+ self.analyzer = CodeAnalyzer(self.repo_path)
20
+ self.embedding_engine = EmbeddingEngine(self.repo_path)
21
+ self.repo_sync = RepoSync(self.repo_path)
22
+
23
+ def ask(self, question: str) -> Dict[str, Any]:
24
+ """Answer questions about the codebase."""
25
+ # Initialize if needed
26
+ if not hasattr(self, '_initialized'):
27
+ self.embedding_engine.initialize()
28
+ self._initialized = True
29
+
30
+ # Search for relevant code
31
+ search_results = self.embedding_engine.search(question)
32
+
33
+ # Build context from search results
34
+ context = []
35
+ for result in search_results['results']:
36
+ context.append(f"From {result['file']}:\n{result['content']}\n")
37
+
38
+ # Generate answer using LLM
39
+ prompt = f"Question: {question}\n\nContext from codebase:\n{''.join(context)}\n\nAnswer:"
40
+ answer = self.analyzer.llm.generate(prompt)
41
+
42
+ return {
43
+ 'answer': answer,
44
+ 'context': search_results
45
+ }
46
+
47
+ def explain(self, location: str) -> str:
48
+ """Explain code at specific location."""
49
+ file_path, line_number = location.split(':')
50
+ return self.analyzer.explain_code(file_path, int(line_number))
51
+
52
+ def search(self, term: str) -> Dict[str, Any]:
53
+ """Semantic search across codebase."""
54
+ if not hasattr(self, '_initialized'):
55
+ self.embedding_engine.initialize()
56
+ self._initialized = True
57
+
58
+ results = self.embedding_engine.search(term)
59
+ return {
60
+ 'query': results['query'],
61
+ 'results': results['results']
62
+ }
63
+
64
+ def diff(self, path1: Path, path2: Path) -> Dict[str, Any]:
65
+ """Compare configuration files."""
66
+ return self.analyzer.compare_configs(path1, path2)
67
+
68
+ def sync(self) -> None:
69
+ """Build or rebuild the embedding index."""
70
+ # Scan repository
71
+ files = list(self.repo_sync.scan_files())
72
+
73
+ # Build index
74
+ index = self.repo_sync.index_repository()
75
+
76
+ # Initialize embedding engine
77
+ self.embedding_engine.initialize()
78
+
79
+ # Convert index to list of documents
80
+ docs = []
81
+ for file_path, file_data in index.items():
82
+ docs.extend(file_data.get('chunks', []))
83
+
84
+ # Embed documents
85
+ self.embedding_engine.embed_documents(docs)