codeshield-ai 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.
- codeshield/__init__.py +62 -0
- codeshield/api_server.py +438 -0
- codeshield/cli.py +48 -0
- codeshield/contextvault/__init__.py +1 -0
- codeshield/contextvault/capture.py +174 -0
- codeshield/contextvault/restore.py +115 -0
- codeshield/mcp/__init__.py +1 -0
- codeshield/mcp/hooks.py +65 -0
- codeshield/mcp/server.py +319 -0
- codeshield/styleforge/__init__.py +1 -0
- codeshield/styleforge/corrector.py +298 -0
- codeshield/trustgate/__init__.py +1 -0
- codeshield/trustgate/checker.py +384 -0
- codeshield/trustgate/sandbox.py +101 -0
- codeshield/utils/__init__.py +9 -0
- codeshield/utils/daytona.py +233 -0
- codeshield/utils/leanmcp.py +258 -0
- codeshield/utils/llm.py +423 -0
- codeshield/utils/metrics.py +543 -0
- codeshield/utils/token_optimizer.py +605 -0
- codeshield_ai-0.1.0.dist-info/METADATA +565 -0
- codeshield_ai-0.1.0.dist-info/RECORD +24 -0
- codeshield_ai-0.1.0.dist-info/WHEEL +4 -0
- codeshield_ai-0.1.0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codeshield-ai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The Complete AI Coding Safety Net - Verify, Enforce, Remember
|
|
5
|
+
Project-URL: Homepage, https://github.com/Erebuzzz/CodeShield
|
|
6
|
+
Project-URL: Documentation, https://codeshield-five.vercel.app/
|
|
7
|
+
Project-URL: Repository, https://github.com/Erebuzzz/CodeShield.git
|
|
8
|
+
Project-URL: Issues, https://github.com/Erebuzzz/CodeShield/issues
|
|
9
|
+
Author-email: CodeShield Team <codeshield@example.com>
|
|
10
|
+
Maintainer: Erebuzzz
|
|
11
|
+
License: MIT
|
|
12
|
+
Keywords: ai,ai-safety,code-analysis,code-verification,developer-tools,llm,mcp
|
|
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.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Classifier: Topic :: Software Development :: Testing
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: daytona-sdk>=0.1.0
|
|
26
|
+
Requires-Dist: fastapi>=0.100.0
|
|
27
|
+
Requires-Dist: httpx>=0.25.0
|
|
28
|
+
Requires-Dist: mcp>=1.0.0
|
|
29
|
+
Requires-Dist: pydantic>=2.0.0
|
|
30
|
+
Requires-Dist: rich>=13.0.0
|
|
31
|
+
Requires-Dist: tree-sitter-javascript>=0.20.0
|
|
32
|
+
Requires-Dist: tree-sitter-python>=0.20.0
|
|
33
|
+
Requires-Dist: tree-sitter>=0.20.0
|
|
34
|
+
Requires-Dist: uvicorn>=0.20.0
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: build>=1.0.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
39
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
40
|
+
Requires-Dist: twine>=4.0.0; extra == 'dev'
|
|
41
|
+
Provides-Extra: server
|
|
42
|
+
Requires-Dist: fastapi>=0.100.0; extra == 'server'
|
|
43
|
+
Requires-Dist: uvicorn>=0.20.0; extra == 'server'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# CodeShield
|
|
47
|
+
|
|
48
|
+
> **An intelligent security layer for AI-generated code.** CodeShield validates, formats, and secures code before it enters your production environment, acting as a firewall for your development workflow.
|
|
49
|
+
|
|
50
|
+
[](https://codeshield-five.vercel.app/)
|
|
51
|
+
[](https://python.org)
|
|
52
|
+
[](LICENSE)
|
|
53
|
+
|
|
54
|
+
**Built for AI Vibe Coding Hackathon 2026** β *Stop getting betrayed by 90% correct code.*
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## π― What CodeShield Does
|
|
59
|
+
|
|
60
|
+
CodeShield intercepts AI-generated code and ensures it's:
|
|
61
|
+
- **Safe** β No malicious imports, infinite loops, or dangerous operations
|
|
62
|
+
- **Correct** β Syntax validated, missing imports detected and auto-fixed
|
|
63
|
+
- **Consistent** β Matches your codebase's naming conventions
|
|
64
|
+
- **Efficient** β Optimized token usage with caching and local processing
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## ποΈ Architecture
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
72
|
+
β CodeShield β
|
|
73
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
74
|
+
β β
|
|
75
|
+
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββ β
|
|
76
|
+
β β TrustGate β β StyleForge β β ContextVault β β
|
|
77
|
+
β β (Security) β β (Style) β β (Memory) β β
|
|
78
|
+
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββββ¬ββββββββββ β
|
|
79
|
+
β β β β β
|
|
80
|
+
β ββββββββββββββββββββΌββββββββββββββββββββββ β
|
|
81
|
+
β β β
|
|
82
|
+
β ββββββββββΌβββββββββ β
|
|
83
|
+
β β LLM Client β β
|
|
84
|
+
β β (Multi-Provider)β β
|
|
85
|
+
β ββββββββββ¬βββββββββ β
|
|
86
|
+
β β β
|
|
87
|
+
β ββββββββββββββββββββΌβββββββββββββββββββ β
|
|
88
|
+
β β β β β
|
|
89
|
+
β ββββββΌβββββ βββββββΌββββββ βββββββΌββββββ β
|
|
90
|
+
β βCometAPI β β Novita.ai β β AIML API β β
|
|
91
|
+
β β(Primary)β β(Secondary)β β(Fallback) β β
|
|
92
|
+
β βββββββββββ βββββββββββββ βββββββββββββ β
|
|
93
|
+
β β
|
|
94
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
95
|
+
β Token Optimizer β Metrics Collector β LeanMCP β Daytona β
|
|
96
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## β¨ Core Features
|
|
102
|
+
|
|
103
|
+
### π‘οΈ TrustGate β Security Verification
|
|
104
|
+
|
|
105
|
+
Validates generated code in an isolated sandbox environment:
|
|
106
|
+
|
|
107
|
+
| Feature | Description |
|
|
108
|
+
|---------|-------------|
|
|
109
|
+
| **Syntax Validation** | AST parsing to catch syntax errors before execution |
|
|
110
|
+
| **Import Detection** | Identifies missing imports with auto-fix capability |
|
|
111
|
+
| **Undefined Names** | Detects potentially undefined variables |
|
|
112
|
+
| **Sandbox Execution** | Runs code in Daytona's isolated environment |
|
|
113
|
+
| **Confidence Scoring** | 0-100% confidence score based on issue severity |
|
|
114
|
+
| **Auto-Fix** | Automatically adds missing imports |
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from codeshield.trustgate.checker import verify_code
|
|
118
|
+
|
|
119
|
+
code = """
|
|
120
|
+
def fetch_data(url):
|
|
121
|
+
return requests.get(url).json()
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
result = verify_code(code, auto_fix=True)
|
|
125
|
+
print(f"Valid: {result.is_valid}") # False (missing import)
|
|
126
|
+
print(f"Confidence: {result.confidence_score:.0%}") # 80%
|
|
127
|
+
print(result.fixed_code) # Includes 'import requests'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Detection Capabilities:**
|
|
131
|
+
- β Missing standard library imports (os, json, re, etc.)
|
|
132
|
+
- β Missing third-party imports (requests, numpy, pandas, etc.)
|
|
133
|
+
- β Syntax errors (missing colons, unmatched brackets)
|
|
134
|
+
- β Indentation errors
|
|
135
|
+
- β Undefined variable usage
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
### π¨ StyleForge β Convention Enforcement
|
|
140
|
+
|
|
141
|
+
Analyzes your codebase to detect and enforce naming conventions:
|
|
142
|
+
|
|
143
|
+
| Feature | Description |
|
|
144
|
+
|---------|-------------|
|
|
145
|
+
| **Pattern Detection** | Automatically detects snake_case, camelCase, PascalCase |
|
|
146
|
+
| **Codebase Analysis** | Scans up to 50 files to determine dominant style |
|
|
147
|
+
| **Auto-Correction** | Converts names to match project conventions |
|
|
148
|
+
| **Typo Detection** | Finds similar existing names that might be typos |
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from codeshield.styleforge.corrector import check_style
|
|
152
|
+
|
|
153
|
+
code = """
|
|
154
|
+
def GetUserData(userName):
|
|
155
|
+
totalValue = calculateTotal(userName)
|
|
156
|
+
return totalValue
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
result = check_style(code, codebase_path="./src")
|
|
160
|
+
print(result.conventions_detected) # {'functions': 'snake_case', ...}
|
|
161
|
+
print(result.corrected_code) # Uses snake_case throughout
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Supported Conventions:**
|
|
165
|
+
- `snake_case` β Python standard (PEP 8)
|
|
166
|
+
- `camelCase` β JavaScript/Java style
|
|
167
|
+
- `PascalCase` β Class names
|
|
168
|
+
- `SCREAMING_SNAKE_CASE` β Constants
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### πΎ ContextVault β State Persistence
|
|
173
|
+
|
|
174
|
+
Saves your development state like a game save file:
|
|
175
|
+
|
|
176
|
+
| Feature | Description |
|
|
177
|
+
|---------|-------------|
|
|
178
|
+
| **State Capture** | Saves open files, cursor position, notes |
|
|
179
|
+
| **SQLite Storage** | Persistent local database |
|
|
180
|
+
| **Instant Restore** | One-click context restoration |
|
|
181
|
+
| **AI Briefing** | LLM-generated summary when restoring |
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from codeshield.contextvault.capture import save_context, list_contexts
|
|
185
|
+
from codeshield.contextvault.restore import restore_context
|
|
186
|
+
|
|
187
|
+
# Save current state
|
|
188
|
+
save_context(
|
|
189
|
+
name="auth-refactor",
|
|
190
|
+
files=["src/auth.py", "tests/test_auth.py"],
|
|
191
|
+
cursor={"file": "src/auth.py", "line": 42, "column": 10},
|
|
192
|
+
notes="Fixing token expiration logic"
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
# List all contexts
|
|
196
|
+
contexts = list_contexts()
|
|
197
|
+
|
|
198
|
+
# Restore with AI briefing
|
|
199
|
+
result = restore_context("auth-refactor")
|
|
200
|
+
print(result["briefing"]) # "You were working on auth token logic..."
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
### β‘ Token Efficiency β Up to 90% Savings
|
|
206
|
+
|
|
207
|
+
Advanced optimization system to minimize LLM token usage:
|
|
208
|
+
|
|
209
|
+
| Optimization | Savings | How It Works |
|
|
210
|
+
|-------------|---------|--------------|
|
|
211
|
+
| **Local Processing** | 100% | Fix common imports without LLM calls |
|
|
212
|
+
| **Prompt Compression** | 40-60% | Shorter prompts, same results |
|
|
213
|
+
| **Dynamic max_tokens** | 50-75% | Adaptive limits based on task |
|
|
214
|
+
| **Model Tiering** | 30-50% | Cheap models for simple tasks |
|
|
215
|
+
| **Response Caching** | 100% | SQLite cache for repeated requests |
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from codeshield.utils.token_optimizer import LocalProcessor, get_token_optimizer
|
|
219
|
+
|
|
220
|
+
# Local fix (0 tokens!)
|
|
221
|
+
code = "x = json.loads(data)"
|
|
222
|
+
issues = ["Missing import: json"]
|
|
223
|
+
|
|
224
|
+
if LocalProcessor.can_fix_locally(code, issues):
|
|
225
|
+
fixed = LocalProcessor.fix_locally(code, issues)
|
|
226
|
+
# Result: "import json\nx = json.loads(data)"
|
|
227
|
+
# Tokens used: 0
|
|
228
|
+
|
|
229
|
+
# Check efficiency stats
|
|
230
|
+
optimizer = get_token_optimizer()
|
|
231
|
+
stats = optimizer.get_stats()
|
|
232
|
+
print(f"Cache hit rate: {stats['cache_hit_rate']}%")
|
|
233
|
+
print(f"Tokens saved: {stats['tokens_saved_by_cache']}")
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Supported Local Fixes (35+ imports):**
|
|
237
|
+
`json`, `os`, `sys`, `re`, `math`, `random`, `datetime`, `time`, `pathlib`, `typing`, `dataclasses`, `collections`, `itertools`, `functools`, `requests`, `httpx`, `asyncio`, `logging`, `subprocess`, `tempfile`, `shutil`, `glob`, `csv`, `sqlite3`, `hashlib`, `base64`, `copy`, `io`, `threading`, `uuid`, `enum`, `abc`, `contextlib`, `pydantic`, `fastapi`, `flask`, `numpy`, `pandas`, `pytest`
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
### π Metrics & Observability
|
|
242
|
+
|
|
243
|
+
Real-time, transparent statistics tracking:
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
from codeshield.utils.metrics import get_metrics
|
|
247
|
+
|
|
248
|
+
metrics = get_metrics()
|
|
249
|
+
summary = metrics.get_summary()
|
|
250
|
+
|
|
251
|
+
# TrustGate metrics
|
|
252
|
+
print(f"Detection rate: {summary['trustgate']['detection_rate']}%")
|
|
253
|
+
print(f"Fix success rate: {summary['trustgate']['fix_success_rate']}%")
|
|
254
|
+
print(f"Sandbox success rate: {summary['trustgate']['sandbox_success_rate']}%")
|
|
255
|
+
|
|
256
|
+
# Token metrics
|
|
257
|
+
print(f"Token efficiency: {summary['tokens']['token_efficiency']}")
|
|
258
|
+
print(f"Estimated cost: ${summary['tokens']['estimated_cost_usd']}")
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Tracked Metrics:**
|
|
262
|
+
- TrustGate: verifications, detections, fixes, sandbox results
|
|
263
|
+
- StyleForge: checks, conventions detected, corrections
|
|
264
|
+
- ContextVault: saves, restores, success rates
|
|
265
|
+
- Tokens: input/output, efficiency ratio, cost estimates
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## π Integrations
|
|
270
|
+
|
|
271
|
+
CodeShield requires these services for full functionality:
|
|
272
|
+
|
|
273
|
+
| Service | Purpose | Environment Variable |
|
|
274
|
+
|---------|---------|---------------------|
|
|
275
|
+
| **[CometAPI](https://apidoc.cometapi.com/)** | Primary LLM (100+ models) | `COMETAPI_KEY` |
|
|
276
|
+
| **[Novita.ai](https://novita.ai/docs)** | Secondary LLM (cost-effective) | `NOVITA_API_KEY` |
|
|
277
|
+
| **[AIML API](https://aimlapi.com/)** | Fallback LLM | `AIML_API_KEY` |
|
|
278
|
+
| **[Daytona](https://daytona.io/docs)** | Sandbox execution | `DAYTONA_API_KEY`, `DAYTONA_API_URL` |
|
|
279
|
+
| **[LeanMCP](https://docs.leanmcp.com/)** | MCP deployment & observability | See [LeanMCP Deployment](#-leanmcp-deployment) |
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## π LeanMCP Deployment
|
|
284
|
+
|
|
285
|
+
CodeShield can be deployed to [LeanMCP Platform](https://ship.leanmcp.com) for production-grade MCP infrastructure with built-in observability.
|
|
286
|
+
|
|
287
|
+
### Quick Deploy
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
# Install LeanMCP CLI
|
|
291
|
+
npm install -g @leanmcp/cli
|
|
292
|
+
|
|
293
|
+
# Login to LeanMCP
|
|
294
|
+
leanmcp login
|
|
295
|
+
|
|
296
|
+
# Deploy CodeShield MCP Server
|
|
297
|
+
cd leanmcp
|
|
298
|
+
npm install
|
|
299
|
+
leanmcp deploy .
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Your MCP server will be live at `https://codeshield.leanmcp.link/mcp`
|
|
303
|
+
|
|
304
|
+
### What You Get
|
|
305
|
+
|
|
306
|
+
| Feature | Description |
|
|
307
|
+
|---------|-------------|
|
|
308
|
+
| **Edge Deployment** | Auto-scaling across 30+ global regions |
|
|
309
|
+
| **Built-in Monitoring** | Tool analytics, latency metrics, error tracking |
|
|
310
|
+
| **Zero DevOps** | No infrastructure to manage |
|
|
311
|
+
| **MCP Protocol** | Full support for Claude, Cursor, Windsurf, etc. |
|
|
312
|
+
|
|
313
|
+
### Architecture
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
MCP Clients β LeanMCP Platform β CodeShield TypeScript MCP β Python Backend
|
|
317
|
+
(Edge Deployment) (leanmcp/ folder) (api_server.py)
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Connect Your MCP Client
|
|
321
|
+
|
|
322
|
+
**Claude Desktop** (`claude_desktop_config.json`):
|
|
323
|
+
```json
|
|
324
|
+
{
|
|
325
|
+
"mcpServers": {
|
|
326
|
+
"codeshield": {
|
|
327
|
+
"url": "https://codeshield.leanmcp.link/mcp"
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
See [leanmcp/README.md](leanmcp/README.md) for full deployment documentation
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## π Installation
|
|
338
|
+
|
|
339
|
+
### Prerequisites
|
|
340
|
+
- Python 3.9+
|
|
341
|
+
- Node.js 18+ (for frontend)
|
|
342
|
+
|
|
343
|
+
### Setup
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
# Clone repository
|
|
347
|
+
git clone https://github.com/Erebuzzz/CodeShield.git
|
|
348
|
+
cd CodeShield
|
|
349
|
+
|
|
350
|
+
# Install Python dependencies
|
|
351
|
+
pip install -e .
|
|
352
|
+
|
|
353
|
+
# Configure environment
|
|
354
|
+
cp .env.example .env
|
|
355
|
+
# Edit .env with your API keys
|
|
356
|
+
|
|
357
|
+
# (Optional) Install frontend dependencies
|
|
358
|
+
cd frontend && npm install
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Environment Variables
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
# .env
|
|
365
|
+
COMETAPI_KEY=sk-your-cometapi-key
|
|
366
|
+
NOVITA_API_KEY=sk_your-novita-key
|
|
367
|
+
AIML_API_KEY=your-aiml-key
|
|
368
|
+
DAYTONA_API_KEY=dtn_your-daytona-key
|
|
369
|
+
DAYTONA_API_URL=https://app.daytona.io/api
|
|
370
|
+
LEANMCP_KEY=leanmcp_your-key
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## π Usage
|
|
376
|
+
|
|
377
|
+
### Python API
|
|
378
|
+
|
|
379
|
+
```python
|
|
380
|
+
# Security verification
|
|
381
|
+
from codeshield.trustgate.checker import verify_code
|
|
382
|
+
result = verify_code("print('hello')", auto_fix=True)
|
|
383
|
+
|
|
384
|
+
# Full sandbox verification
|
|
385
|
+
from codeshield.trustgate.sandbox import full_verification
|
|
386
|
+
result = full_verification("print('hello')")
|
|
387
|
+
|
|
388
|
+
# Style checking
|
|
389
|
+
from codeshield.styleforge.corrector import check_style
|
|
390
|
+
result = check_style("def MyFunc(): pass", "./src")
|
|
391
|
+
|
|
392
|
+
# Context management
|
|
393
|
+
from codeshield.contextvault.capture import save_context
|
|
394
|
+
save_context(name="my-task", files=["main.py"])
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### REST API
|
|
398
|
+
|
|
399
|
+
```bash
|
|
400
|
+
# Start server
|
|
401
|
+
python -m uvicorn codeshield.api_server:app --reload
|
|
402
|
+
|
|
403
|
+
# Verify code
|
|
404
|
+
curl -X POST http://localhost:8000/api/verify \
|
|
405
|
+
-H "Content-Type: application/json" \
|
|
406
|
+
-d '{"code": "print(x)", "auto_fix": true}'
|
|
407
|
+
|
|
408
|
+
# Check style
|
|
409
|
+
curl -X POST http://localhost:8000/api/style \
|
|
410
|
+
-H "Content-Type: application/json" \
|
|
411
|
+
-d '{"code": "def MyFunc(): pass", "codebase_path": "."}'
|
|
412
|
+
|
|
413
|
+
# Get metrics
|
|
414
|
+
curl http://localhost:8000/api/metrics
|
|
415
|
+
|
|
416
|
+
# Get token efficiency
|
|
417
|
+
curl http://localhost:8000/api/tokens/efficiency
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### MCP Server (Claude/Cursor)
|
|
421
|
+
|
|
422
|
+
Add to your MCP settings:
|
|
423
|
+
|
|
424
|
+
```json
|
|
425
|
+
{
|
|
426
|
+
"mcpServers": {
|
|
427
|
+
"codeshield": {
|
|
428
|
+
"command": "python",
|
|
429
|
+
"args": ["-m", "codeshield.mcp.server"],
|
|
430
|
+
"cwd": "${workspaceFolder}",
|
|
431
|
+
"env": {
|
|
432
|
+
"PYTHONPATH": "${workspaceFolder}/src"
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**Available MCP Tools:**
|
|
440
|
+
|
|
441
|
+
| Tool | Description |
|
|
442
|
+
|------|-------------|
|
|
443
|
+
| `verify_code` | Fast static analysis |
|
|
444
|
+
| `full_verify` | Static + sandbox execution |
|
|
445
|
+
| `check_style` | Convention enforcement |
|
|
446
|
+
| `save_context` | Save coding state |
|
|
447
|
+
| `restore_context` | Restore with AI briefing |
|
|
448
|
+
| `list_contexts` | List saved contexts |
|
|
449
|
+
| `mcp_health` | Server health check |
|
|
450
|
+
| `test_llm_connection` | Test LLM providers |
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
## π§ͺ Testing
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
# Run all tests (70 tests)
|
|
458
|
+
pytest tests/ -v
|
|
459
|
+
|
|
460
|
+
# Run specific test suites
|
|
461
|
+
pytest tests/test_trustgate.py -v
|
|
462
|
+
pytest tests/test_styleforge.py -v
|
|
463
|
+
pytest tests/test_comprehensive.py -v
|
|
464
|
+
|
|
465
|
+
# Quick demo
|
|
466
|
+
python test_quick.py
|
|
467
|
+
|
|
468
|
+
# Token efficiency demo
|
|
469
|
+
python demo_token_efficiency.py
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
## π Project Structure
|
|
475
|
+
|
|
476
|
+
```
|
|
477
|
+
CodeShield/
|
|
478
|
+
βββ src/codeshield/
|
|
479
|
+
β βββ trustgate/ # Security verification
|
|
480
|
+
β β βββ checker.py # Syntax, import, undefined detection
|
|
481
|
+
β β βββ sandbox.py # Daytona sandbox integration
|
|
482
|
+
β βββ styleforge/ # Style enforcement
|
|
483
|
+
β β βββ corrector.py # Convention detection & correction
|
|
484
|
+
β βββ contextvault/ # State persistence
|
|
485
|
+
β β βββ capture.py # Save context
|
|
486
|
+
β β βββ restore.py # Restore with briefing
|
|
487
|
+
β βββ mcp/ # MCP server (Python)
|
|
488
|
+
β β βββ server.py # FastMCP implementation
|
|
489
|
+
β βββ utils/
|
|
490
|
+
β β βββ llm.py # Multi-provider LLM client
|
|
491
|
+
β β βββ metrics.py # Statistics tracking
|
|
492
|
+
β β βββ token_optimizer.py # Token efficiency
|
|
493
|
+
β β βββ daytona.py # Sandbox client
|
|
494
|
+
β β βββ leanmcp.py # Observability client
|
|
495
|
+
β βββ api_server.py # FastAPI HTTP server
|
|
496
|
+
β βββ cli.py # Command-line interface
|
|
497
|
+
βββ leanmcp/ # LeanMCP TypeScript MCP Server
|
|
498
|
+
β βββ main.ts # Entry point
|
|
499
|
+
β βββ leanmcp.config.js # Deployment config
|
|
500
|
+
β βββ mcp/ # MCP services
|
|
501
|
+
β βββ verification/ # TrustGate tools
|
|
502
|
+
β βββ styleforge/ # Style tools
|
|
503
|
+
β βββ contextvault/ # Context tools
|
|
504
|
+
β βββ health/ # Health & metrics
|
|
505
|
+
βββ frontend/ # React/TypeScript UI
|
|
506
|
+
βββ tests/ # Comprehensive test suite
|
|
507
|
+
βββ examples/ # Sample code
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
## π§ API Endpoints
|
|
513
|
+
|
|
514
|
+
### Core Endpoints
|
|
515
|
+
|
|
516
|
+
| Method | Endpoint | Description |
|
|
517
|
+
|--------|----------|-------------|
|
|
518
|
+
| `GET` | `/api/health` | Server health check |
|
|
519
|
+
| `POST` | `/api/verify` | Verify code |
|
|
520
|
+
| `POST` | `/api/style` | Check style conventions |
|
|
521
|
+
| `POST` | `/api/context/save` | Save context |
|
|
522
|
+
| `POST` | `/api/context/restore` | Restore context |
|
|
523
|
+
| `GET` | `/api/contexts` | List contexts |
|
|
524
|
+
|
|
525
|
+
### Observability Endpoints
|
|
526
|
+
|
|
527
|
+
| Method | Endpoint | Description |
|
|
528
|
+
|--------|----------|-------------|
|
|
529
|
+
| `GET` | `/api/metrics` | Full metrics summary |
|
|
530
|
+
| `GET` | `/api/metrics/trustgate` | TrustGate stats |
|
|
531
|
+
| `GET` | `/api/metrics/styleforge` | StyleForge stats |
|
|
532
|
+
| `GET` | `/api/metrics/tokens` | Token usage |
|
|
533
|
+
| `GET` | `/api/tokens/efficiency` | Optimization stats |
|
|
534
|
+
| `GET` | `/api/providers/status` | LLM provider status |
|
|
535
|
+
| `GET` | `/api/providers/test` | Test LLM connectivity |
|
|
536
|
+
| `GET` | `/api/integrations/status` | All integrations status |
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
## π€ Built With
|
|
541
|
+
|
|
542
|
+
| Sponsor | Integration |
|
|
543
|
+
|---------|-------------|
|
|
544
|
+
| **[Daytona](https://daytona.io)** | Sandboxed code execution |
|
|
545
|
+
| **[LeanMCP](https://leanmcp.com)** | MCP observability platform |
|
|
546
|
+
| **[CometAPI](https://cometapi.com)** | Unified AI gateway |
|
|
547
|
+
| **[Novita.ai](https://novita.ai)** | Cost-effective inference |
|
|
548
|
+
|
|
549
|
+
---
|
|
550
|
+
|
|
551
|
+
## π License
|
|
552
|
+
|
|
553
|
+
MIT License β see [LICENSE](LICENSE) for details.
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
## π Support
|
|
558
|
+
|
|
559
|
+
- π [Documentation](https://codeshield-five.vercel.app/)
|
|
560
|
+
- π [Issue Tracker](https://github.com/Erebuzzz/CodeShield/issues)
|
|
561
|
+
- π¬ [Discussions](https://github.com/Erebuzzz/CodeShield/discussions)
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
|
|
565
|
+
**CodeShield** β *Because AI-generated code should be verified, not trusted.*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
codeshield/__init__.py,sha256=kJzD4tSE8kQSImrNd2-O8okdS1QP87TuV5TEr0DwBGc,1702
|
|
2
|
+
codeshield/api_server.py,sha256=PSz5progvu9-nZhh2b4ELIICqS7ALcGPkaFy7S2lC_k,13538
|
|
3
|
+
codeshield/cli.py,sha256=fAYVAQeE_diYhYjsULiWc9JYpB8rFqUik45RiCM0vcI,1583
|
|
4
|
+
codeshield/contextvault/__init__.py,sha256=OLR6fF_NBugWInAeBq1hcWEMREGW-nCroRo2YAW7fbI,44
|
|
5
|
+
codeshield/contextvault/capture.py,sha256=SzgNs9fpR0gyDgkCLS8Z66poR66T19WspsRD48NgAKo,4194
|
|
6
|
+
codeshield/contextvault/restore.py,sha256=g5tl6yyUcQPOq_3rM2kJ3lAy0G9GBuTR4IK_VYr9Bk8,3354
|
|
7
|
+
codeshield/mcp/__init__.py,sha256=Kwb_hfJv6QpEfE5BtBx0CxY_zVZNkgKUvT4wqJC0VJ8,25
|
|
8
|
+
codeshield/mcp/hooks.py,sha256=eXFJLJHAWsubGQ6d_aUB-WfjeCgmoNxZ6TyHsdFFWhs,2033
|
|
9
|
+
codeshield/mcp/server.py,sha256=LHNQKoo02CL08tJ8nap7Bkm1DIf1tHVBpjxTonTnt7M,11201
|
|
10
|
+
codeshield/styleforge/__init__.py,sha256=fWcSlQRZsh70r2Oylf6oOPwhrS8HUN_5S1Tyu-rQojg,50
|
|
11
|
+
codeshield/styleforge/corrector.py,sha256=XPjIvvU1RkZ_d4zgmmmE-H6peibD9I3XiHjTmataMOM,9912
|
|
12
|
+
codeshield/trustgate/__init__.py,sha256=HLeDxHUJ2MS6KWF6A2TR0Qj4UeiF8J8XWO7cg1dxJ3g,44
|
|
13
|
+
codeshield/trustgate/checker.py,sha256=vAyeVEkaWDfaRG9jQBNOngfWhvrDOjnqlOrHtiJF7H8,12284
|
|
14
|
+
codeshield/trustgate/sandbox.py,sha256=YBnY0Qvt0HT9NZsn2AIoXh7erfvxU7xfSNWcThAi3hE,3109
|
|
15
|
+
codeshield/utils/__init__.py,sha256=eAOHAPHvkoTeZpVh09ueb7k15HonXmIJVc0IAVx0XMA,358
|
|
16
|
+
codeshield/utils/daytona.py,sha256=PfP2AATZzEbrqoxQU89z-KU47k_ssx8b-zBBbTrn0eU,7485
|
|
17
|
+
codeshield/utils/leanmcp.py,sha256=XwvhJMQhl4BGOjSg6HxBg-Rekqx5gihPkIA0gM0RMBQ,8588
|
|
18
|
+
codeshield/utils/llm.py,sha256=Afh1bq2Y2GOml8h20NIgIkMXFE6pZ2jROTmJKyePNj0,16191
|
|
19
|
+
codeshield/utils/metrics.py,sha256=_qGBYY7ieDUqxqrZj32WY7JBGTWpalTcd_VEv_ufTmo,20665
|
|
20
|
+
codeshield/utils/token_optimizer.py,sha256=Q5LnQBNbPQ-wMc8dh3iaI5oSxQ6xuhKe5huuUFXR1BU,21560
|
|
21
|
+
codeshield_ai-0.1.0.dist-info/METADATA,sha256=OoN1YoIA7DlleQic3ZKLyjHgAWMuNgd7GeiCfBzre1c,19622
|
|
22
|
+
codeshield_ai-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
23
|
+
codeshield_ai-0.1.0.dist-info/entry_points.txt,sha256=o51TYP15HPpd6IwegCw7PVoh7jBMK7lKqfVoubG6upk,98
|
|
24
|
+
codeshield_ai-0.1.0.dist-info/RECORD,,
|