snipcontext 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,51 @@
1
+ # OS-generated files
2
+ .DS_Store
3
+ Thumbs.db
4
+
5
+ # Editor and IDE directories
6
+ .vscode/
7
+ .idea/
8
+ *.swp
9
+ *.swo
10
+
11
+ # Logs
12
+ *.log
13
+ logs/
14
+
15
+ # Environment variables and local config
16
+ .env
17
+ .env.*
18
+ *.local
19
+
20
+ # Dependency directories
21
+ node_modules/
22
+ .vendor/
23
+
24
+ # Build and distribution artifacts
25
+ dist/
26
+ build/
27
+ out/
28
+ coverage/
29
+ *.tmp
30
+ *.temp
31
+
32
+ # Python
33
+ __pycache__/
34
+ *.py[cod]
35
+ .venv/
36
+ venv/
37
+
38
+ # Java
39
+ *.class
40
+
41
+ # Go
42
+ bin/
43
+
44
+ # Rust
45
+ target/
46
+
47
+ # Package manager lockfiles for library templates (optional)
48
+ # Uncomment as needed for application repos:
49
+ # package-lock.json
50
+ # yarn.lock
51
+ # pnpm-lock.yaml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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,426 @@
1
+ Metadata-Version: 2.4
2
+ Name: snipcontext
3
+ Version: 0.1.0
4
+ Summary: AI-powered code snippet & context manager with local semantic search
5
+ Project-URL: Homepage, https://github.com/billybox1926-jpg/snipcontext
6
+ Project-URL: Documentation, https://github.com/billybox1926-jpg/snipcontext/blob/main/docs
7
+ Project-URL: Repository, https://github.com/billybox1926-jpg/snipcontext
8
+ Project-URL: Issues, https://github.com/billybox1926-jpg/snipcontext/issues
9
+ Project-URL: Changelog, https://github.com/billybox1926-jpg/snipcontext/blob/main/CHANGELOG.md
10
+ Author: SnipContext Contributors
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: ai,code,context,developer-tools,embeddings,llm,productivity,semantic-search,snippet
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Software Development :: Code Generators
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Classifier: Topic :: Utilities
26
+ Requires-Python: >=3.9
27
+ Requires-Dist: cryptography<44.0,>=42.0
28
+ Requires-Dist: faiss-cpu>=1.8.0
29
+ Requires-Dist: platformdirs<5.0,>=4.0
30
+ Requires-Dist: pydantic-settings<3.0,>=2.0
31
+ Requires-Dist: pydantic<3.0,>=2.0
32
+ Requires-Dist: python-ulid<3.0,>=2.0
33
+ Requires-Dist: pyyaml<7.0,>=6.0
34
+ Requires-Dist: rich<14.0,>=13.0
35
+ Requires-Dist: sentence-transformers<4.0,>=3.0
36
+ Requires-Dist: typer[all]>=0.12.0
37
+ Requires-Dist: watchdog<5.0,>=4.0
38
+ Provides-Extra: dev
39
+ Requires-Dist: mkdocs-material<10.0,>=9.5; extra == 'dev'
40
+ Requires-Dist: mkdocs<2.0,>=1.6; extra == 'dev'
41
+ Requires-Dist: mypy<2.0,>=1.10; extra == 'dev'
42
+ Requires-Dist: pre-commit<4.0,>=3.7; extra == 'dev'
43
+ Requires-Dist: pytest-asyncio<1.0,>=0.23; extra == 'dev'
44
+ Requires-Dist: pytest-cov<6.0,>=5.0; extra == 'dev'
45
+ Requires-Dist: pytest-mock<4.0,>=3.14; extra == 'dev'
46
+ Requires-Dist: pytest<9.0,>=8.0; extra == 'dev'
47
+ Requires-Dist: ruff>=0.5.0; extra == 'dev'
48
+ Description-Content-Type: text/markdown
49
+
50
+ # SnipContext
51
+
52
+ [![PyPI version](https://img.shields.io/pypi/v/snipcontext)](https://pypi.org/project/snipcontext/)
53
+ [![CI Status](https://img.shields.io/github/actions/status/billybox1926-jpg/snipcontext/ci)](https://github.com/billybox1926-jpg/snipcontext/actions/workflows/ci.yml)
54
+ [![License](https://img.shields.io/github/license/billybox1926-jpg/snipcontext)](LICENSE)
55
+ [![Python](https://img.shields.io/pypi/pyversions/snipcontext)](https://pypi.org/project/snipcontext/)
56
+ [![Downloads](https://img.shields.io/pypi/dm/snipcontext)](https://pypi.org/project/snipcontext/)
57
+
58
+ **AI-powered code snippet & context manager.**
59
+
60
+ Save, search, tag, and instantly inject your best boilerplate, patterns, and context into any LLM (Claude, Cursor, Grok, Windsurf, etc.).
61
+
62
+ > **Local-first** — Open source — Built for humans + AI agents
63
+
64
+ ---
65
+
66
+ ## Why SnipContext?
67
+
68
+ - **Stop rewriting** the same auth flows, component patterns, or utility functions
69
+ - **Stop feeding LLMs** messy or outdated code from your clipboard history
70
+ - **Build your personal/team "second brain"** of high-quality, reusable code
71
+ - **Semantic search** finds code by meaning, not just keywords
72
+ - **LLM-optimized exports** format your snippets for maximum comprehension
73
+
74
+ ---
75
+
76
+ ## Key Features
77
+
78
+ | Feature | Status |
79
+ |---------|--------|
80
+ | Rich snippet saving with tags, metadata, and versioning | ✅ |
81
+ | **Semantic search** with local embeddings (sentence-transformers + FAISS) | ✅ |
82
+ | **Hybrid search** — semantic + keyword with configurable weights | ✅ |
83
+ | One-command export optimized for major LLMs | ✅ |
84
+ | CLI + Library support (Python) | ✅ |
85
+ | Plugin system for new providers and exporters | ✅ |
86
+ | Git-friendly, local-first storage | ✅ |
87
+ | Import/export for backup and sharing | ✅ |
88
+
89
+ ### Supported LLM Providers
90
+
91
+ | Provider | Format | Best For |
92
+ |----------|--------|----------|
93
+ | **Generic** | Markdown | Universal compatibility |
94
+ | **Claude** | XML documents | Anthropic Claude |
95
+ | **Cursor** | File-style headers | Cursor IDE |
96
+ | **OpenAI** | Delineated sections | ChatGPT / GPT-4 |
97
+
98
+ ---
99
+
100
+ ## Quick Start
101
+
102
+ ### Installation
103
+
104
+ ```bash
105
+ # From PyPI (recommended)
106
+ pip install snipcontext
107
+
108
+ # Or with uv
109
+ uv tool install snipcontext
110
+
111
+ # From source (after cloning)
112
+ pip install -e ".[dev]"
113
+
114
+ # Or install directly from GitHub
115
+ pip install git+https://github.com/billybox1926-jpg/snipcontext.git
116
+ ```
117
+
118
+ #### Windows Users: Use `snipcontext` instead of `sc`
119
+
120
+ Windows has a built-in `sc.exe` (Service Control) that shadows the `sc` CLI entry point. Use the full command name instead:
121
+
122
+ ```bash
123
+ snipcontext add "print('hello')" --title "Hello" --tag python
124
+ snipcontext search "hello world"
125
+ snipcontext list
126
+ snipcontext stats
127
+ ```
128
+
129
+ Or run via module:
130
+
131
+ ```bash
132
+ python -m snipcontext add "print('hello')" --title "Hello" --tag python
133
+ ```
134
+
135
+ #### Verify Installation
136
+
137
+ ```bash
138
+ snipcontext --help # or: python -m snipcontext --help
139
+ snipcontext providers # List available export providers
140
+ ```
141
+
142
+ ### CLI Usage
143
+
144
+ > **Note:** On Windows, use `snipcontext` instead of `sc` (see [Installation](#installation)).
145
+
146
+ ```bash
147
+ # Add a snippet
148
+ snipcontext add "def authenticate(token):\n return jwt.decode(token, SECRET)" \
149
+ --title "JWT Authentication" \
150
+ --desc "Decode and verify JWT tokens" \
151
+ --lang python \
152
+ --tag auth --tag jwt --tag security
153
+
154
+ # Search semantically
155
+ snipcontext search "how to validate auth tokens"
156
+
157
+ # Search by tag
158
+ snipcontext search "auth" --mode tag
159
+
160
+ # Export for Claude
161
+ snipcontext search "authentication" --provider claude --output context.xml
162
+
163
+ # List all snippets
164
+ snipcontext list
165
+
166
+ # Show stats
167
+ snipcontext stats
168
+ ```
169
+
170
+ ### Library Usage
171
+
172
+ ```python
173
+ from snipcontext.core.models import Snippet, SnippetMetadata, Language
174
+ from snipcontext.core.storage import StorageEngine
175
+ from snipcontext.core.search import HybridSearch
176
+ from snipcontext.config.settings import get_config
177
+
178
+ # Initialize
179
+ config = get_config()
180
+ storage = StorageEngine(config)
181
+
182
+ # Create and save a snippet
183
+ snippet = Snippet(
184
+ content="def memoize(fn):\n cache = {}\n ...",
185
+ metadata=SnippetMetadata(
186
+ title="Memoization Decorator",
187
+ description="Cache function results",
188
+ language=Language.PYTHON,
189
+ ),
190
+ tags=["python", "decorator", "performance"],
191
+ )
192
+ storage.save(snippet)
193
+
194
+ # Search with semantic understanding
195
+ searcher = HybridSearch(config)
196
+ searcher.index_snippets(storage.list_all())
197
+ results = searcher.search("cache function results decorator")
198
+
199
+ for r in results:
200
+ print(f"{r.score:.3f} | {r.snippet.metadata.title}")
201
+ ```
202
+
203
+ ---
204
+
205
+ ## 🔐 Encryption at Rest
206
+
207
+ SnipContext supports **Fernet (AES-128)** encryption for sensitive snippets. When enabled, snippet content is encrypted at rest using a key derived from a passphrase via PBKDF2 (100k iterations).
208
+
209
+ ### Enable Encryption
210
+
211
+ ```bash
212
+ # Enable encryption (required)
213
+ export SNIPCONTEXT_ENCRYPT_ENABLED=true
214
+
215
+ # Set passphrase (used for key derivation)
216
+ export SNIPCONTEXT_ENCRYPTION_PASSPHRASE="your-secure-passphrase"
217
+
218
+ # Optional: persist salt to config (auto-generated if omitted)
219
+ export SNIPCONTEXT_ENCRYPT_KEY_SALT="base64-encoded-salt"
220
+ ```
221
+
222
+ ### Encrypt Snippets
223
+
224
+ ```bash
225
+ # Encrypt a new snippet
226
+ snipcontext add "api_key = 'sk-12345'" \
227
+ --title "API Key" \
228
+ --tag secret \
229
+ --encrypt
230
+
231
+ # Mark as sensitive (auto-enables encryption)
232
+ snipcontext add "password = 'secret123'" \
233
+ --title "DB Password" \
234
+ --sensitive
235
+ ```
236
+
237
+ ### Decrypt for Viewing/Editing
238
+
239
+ ```bash
240
+ # Decrypt for viewing
241
+ snipcontext decrypt <snippet-id>
242
+
243
+ # Encrypt an existing snippet
244
+ snipcontext encrypt <snippet-id>
245
+ ```
246
+
247
+ > **Note:** When encrypted, the plaintext `content` is cleared from storage. The `encrypted_content` field stores the encrypted data. Use `sc decrypt <id>` to restore plaintext for editing.
248
+
249
+ ---
250
+
251
+ ## 🔄 Index Rebuild & Resilience
252
+
253
+ SnipContext automatically detects and recovers from index corruption. The `HybridSearch` engine validates index integrity on load and rebuilds automatically when needed.
254
+
255
+ ### Manual Rebuild
256
+
257
+ ```bash
258
+ # Check if rebuild is needed (skips if index is valid)
259
+ snipcontext rebuild-index
260
+
261
+ # Force rebuild (useful after corruption, dependency changes, or mode switches)
262
+ snipcontext rebuild-index --force
263
+ ```
264
+
265
+ ### Auto-Recovery
266
+
267
+ The search engine automatically:
268
+ 1. **Validates index integrity** on load (checks ID map lengths, matrix dimensions)
269
+ 2. **Cleans up corrupted files** (deletes mismatched/corrupted index files)
270
+ 3. **Falls back gracefully** — if semantic index unavailable, runs keyword-only search
271
+ 4. **Rebuilds on demand** — `index_snippets()` auto-loads existing indices before rebuilding
272
+
273
+ ### Watchdog / Real-time Indexing
274
+
275
+ Run `sc watch` to monitor the snippets directory and automatically reindex when files change:
276
+
277
+ ```bash
278
+ sc watch
279
+ ```
280
+
281
+ Disable via config if you prefer manual rebuilds only:
282
+
283
+ ```bash
284
+ export SNIPCONTEXT_WATCHDOG_ENABLED=false
285
+ ```
286
+
287
+ ---
288
+
289
+ ## Architecture
290
+
291
+ ```
292
+ CLI (Typer + Rich)
293
+
294
+ ├── Providers (Claude XML / Cursor / OpenAI / Generic Markdown)
295
+
296
+ ├── Search Engine
297
+ │ ├── Semantic: sentence-transformers + FAISS
298
+ │ ├── Keyword: TF-IDF (scikit-learn)
299
+ │ └── Hybrid: configurable weighted fusion
300
+
301
+ ├── Storage Engine
302
+ │ └── Git-friendly JSON files per snippet
303
+
304
+ └── Data Models (Pydantic v2)
305
+ └── Snippet / SnippetMetadata / SnippetVersion
306
+ ```
307
+
308
+ See [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) for detailed design documentation.
309
+
310
+ ---
311
+
312
+ ## Configuration
313
+
314
+ SnipContext uses environment variables and a YAML config file:
315
+
316
+ ```bash
317
+ # Use GPU for embeddings
318
+ export SNIPCONTEXT_EMBED_DEVICE="cuda"
319
+
320
+ # Change embedding model
321
+ export SNIPCONTEXT_EMBED_MODEL_NAME="all-mpnet-base-v2"
322
+
323
+ # Adjust search weights
324
+ export SNIPCONTEXT_SEARCH_SEMANTIC_WEIGHT="0.8"
325
+ ```
326
+
327
+ Or edit `~/.config/SnipContext/snipcontext.yaml`:
328
+
329
+ ```yaml
330
+ embedding:
331
+ model_name: "all-MiniLM-L6-v2"
332
+ device: "cpu"
333
+
334
+ search:
335
+ default_mode: "hybrid"
336
+ semantic_weight: 0.7
337
+ keyword_weight: 0.3
338
+ top_k: 10
339
+ ```
340
+
341
+ ---
342
+
343
+ ## Development
344
+
345
+ ```bash
346
+ # Clone
347
+ git clone https://github.com/billybox1926-jpg/snipcontext.git
348
+ cd snipcontext
349
+
350
+ # Install dev dependencies
351
+ pip install -e ".[dev]"
352
+
353
+ # Run tests
354
+ pytest
355
+
356
+ # Run with coverage
357
+ pytest --cov=snipcontext
358
+
359
+ # Linting
360
+ ruff check .
361
+ mypy .
362
+
363
+ # Install pre-commit hooks
364
+ pre-commit install
365
+ ```
366
+
367
+ ---
368
+
369
+ ## Roadmap
370
+
371
+ - [x] Core snippet CRUD with git-friendly storage
372
+ - [x] Semantic + hybrid search with local embeddings
373
+ - [x] LLM-optimized export providers (Claude, Cursor, OpenAI, Generic)
374
+ - [x] Rich CLI with Typer
375
+ - [x] Plugin system with entry points
376
+ - [x] Python library distribution (PyPI)
377
+ - [ ] Real-time index updates (currently requires rebuild)
378
+ - [ ] Import from GitHub Gists
379
+ - [ ] Import from Git repositories
380
+ - [ ] Snippet templates and scaffolding
381
+ - [ ] Team sharing via git-sync
382
+ - [ ] VS Code extension
383
+
384
+ ---
385
+
386
+ ## Project Structure
387
+
388
+ ```
389
+ snipcontext/
390
+ ├── snipcontext/ # Python package
391
+ │ ├── __init__.py # Package exports
392
+ │ ├── __main__.py # python -m snipcontext
393
+ │ ├── core/ # Core engine (models, storage, search)
394
+ │ │ ├── models.py # Pydantic data models
395
+ │ │ ├── storage.py # Git-friendly JSON storage
396
+ │ │ └── search.py # Semantic + hybrid search
397
+ │ ├── providers/ # LLM export providers
398
+ │ │ ├── base.py # Provider interface
399
+ │ │ ├── claude.py # Anthropic Claude XML
400
+ │ │ ├── cursor.py # Cursor IDE format
401
+ │ │ ├── openai.py # OpenAI format
402
+ │ │ └── generic.py # Universal Markdown
403
+ │ ├── plugins/ # Plugin system
404
+ │ │ └── base.py # Plugin base + manager
405
+ │ ├── config/ # Configuration
406
+ │ │ └── settings.py # Pydantic Settings
407
+ │ └── cli/ # Command-line interface
408
+ │ └── main.py # Typer CLI commands
409
+ ├── tests/ # Comprehensive test suite
410
+ ├── docs/ # Documentation
411
+ │ ├── ARCHITECTURE.md # Design docs
412
+ │ ├── API.md # Python API reference
413
+ │ └── MAINTAINER.md # Maintainer guide
414
+ ├── pyproject.toml # Modern Python packaging
415
+ └── README.md # This file
416
+ ```
417
+
418
+ ---
419
+
420
+ ## License
421
+
422
+ MIT License — see [LICENSE](LICENSE) for details.
423
+
424
+ ## Contributing
425
+
426
+ Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) first. New contributors should check out our [Good First Issues](../../issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22).