codetrust 1.5.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.
- codetrust-1.5.0/.cursorrules +49 -0
- codetrust-1.5.0/.github/workflows/ci.yml +65 -0
- codetrust-1.5.0/.github/workflows/codetrust-scan.yml +87 -0
- codetrust-1.5.0/.gitignore +48 -0
- codetrust-1.5.0/CHANGELOG.md +156 -0
- codetrust-1.5.0/CLAUDE.md +216 -0
- codetrust-1.5.0/Dockerfile +39 -0
- codetrust-1.5.0/LICENSE +21 -0
- codetrust-1.5.0/PKG-INFO +265 -0
- codetrust-1.5.0/PLAN.md +457 -0
- codetrust-1.5.0/PRODUCT.md +552 -0
- codetrust-1.5.0/Procfile +1 -0
- codetrust-1.5.0/README.md +217 -0
- codetrust-1.5.0/SPEC.md +758 -0
- codetrust-1.5.0/action/action.yml +64 -0
- codetrust-1.5.0/action/entrypoint.sh +41 -0
- codetrust-1.5.0/action/scan.py +270 -0
- codetrust-1.5.0/action/scan_runner.py +315 -0
- codetrust-1.5.0/action.yml +92 -0
- codetrust-1.5.0/alembic/README +1 -0
- codetrust-1.5.0/alembic/env.py +86 -0
- codetrust-1.5.0/alembic/script.py.mako +28 -0
- codetrust-1.5.0/alembic/versions/b74aff4dff57_initial_schema_users_api_keys_scan_logs_.py +102 -0
- codetrust-1.5.0/alembic.ini +149 -0
- codetrust-1.5.0/codetrust/.gitignore +45 -0
- codetrust-1.5.0/dashboard/next.config.js +9 -0
- codetrust-1.5.0/dashboard/package-lock.json +6378 -0
- codetrust-1.5.0/dashboard/package.json +33 -0
- codetrust-1.5.0/dashboard/postcss.config.js +6 -0
- codetrust-1.5.0/dashboard/prisma/schema.prisma +55 -0
- codetrust-1.5.0/dashboard/src/app/api/auth/[...nextauth]/route.ts +6 -0
- codetrust-1.5.0/dashboard/src/app/api/webhooks/stripe/route.ts +52 -0
- codetrust-1.5.0/dashboard/src/app/dashboard/api-keys/page.tsx +26 -0
- codetrust-1.5.0/dashboard/src/app/dashboard/layout.tsx +23 -0
- codetrust-1.5.0/dashboard/src/app/dashboard/page.tsx +60 -0
- codetrust-1.5.0/dashboard/src/app/dashboard/settings/page.tsx +22 -0
- codetrust-1.5.0/dashboard/src/app/globals.css +26 -0
- codetrust-1.5.0/dashboard/src/app/layout.tsx +23 -0
- codetrust-1.5.0/dashboard/src/app/login/page.tsx +34 -0
- codetrust-1.5.0/dashboard/src/app/page.tsx +118 -0
- codetrust-1.5.0/dashboard/src/app/pricing/page.tsx +114 -0
- codetrust-1.5.0/dashboard/src/components/api-key-manager.tsx +171 -0
- codetrust-1.5.0/dashboard/src/components/dashboard-nav.tsx +69 -0
- codetrust-1.5.0/dashboard/src/components/providers.tsx +7 -0
- codetrust-1.5.0/dashboard/src/components/scan-history.tsx +87 -0
- codetrust-1.5.0/dashboard/src/components/settings-form.tsx +112 -0
- codetrust-1.5.0/dashboard/src/components/usage-chart.tsx +48 -0
- codetrust-1.5.0/dashboard/src/lib/api.ts +166 -0
- codetrust-1.5.0/dashboard/src/lib/auth.ts +48 -0
- codetrust-1.5.0/dashboard/src/lib/prisma.ts +11 -0
- codetrust-1.5.0/dashboard/tailwind.config.ts +28 -0
- codetrust-1.5.0/dashboard/tsconfig.json +40 -0
- codetrust-1.5.0/docker-compose.yml +57 -0
- codetrust-1.5.0/extension/.eslintrc.json +30 -0
- codetrust-1.5.0/extension/.gitignore +4 -0
- codetrust-1.5.0/extension/.vscodeignore +9 -0
- codetrust-1.5.0/extension/README.md +64 -0
- codetrust-1.5.0/extension/out/api-client.d.ts +36 -0
- codetrust-1.5.0/extension/out/api-client.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/api-client.js +169 -0
- codetrust-1.5.0/extension/out/api-client.js.map +1 -0
- codetrust-1.5.0/extension/out/code-actions.d.ts +26 -0
- codetrust-1.5.0/extension/out/code-actions.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/code-actions.js +201 -0
- codetrust-1.5.0/extension/out/code-actions.js.map +1 -0
- codetrust-1.5.0/extension/out/commands.d.ts +20 -0
- codetrust-1.5.0/extension/out/commands.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/commands.js +302 -0
- codetrust-1.5.0/extension/out/commands.js.map +1 -0
- codetrust-1.5.0/extension/out/config.d.ts +8 -0
- codetrust-1.5.0/extension/out/config.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/config.js +58 -0
- codetrust-1.5.0/extension/out/config.js.map +1 -0
- codetrust-1.5.0/extension/out/diagnostics.d.ts +28 -0
- codetrust-1.5.0/extension/out/diagnostics.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/diagnostics.js +181 -0
- codetrust-1.5.0/extension/out/diagnostics.js.map +1 -0
- codetrust-1.5.0/extension/out/embedded-scanner.d.ts +14 -0
- codetrust-1.5.0/extension/out/embedded-scanner.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/embedded-scanner.js +180 -0
- codetrust-1.5.0/extension/out/embedded-scanner.js.map +1 -0
- codetrust-1.5.0/extension/out/extension.d.ts +16 -0
- codetrust-1.5.0/extension/out/extension.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/extension.js +122 -0
- codetrust-1.5.0/extension/out/extension.js.map +1 -0
- codetrust-1.5.0/extension/out/parsers.d.ts +15 -0
- codetrust-1.5.0/extension/out/parsers.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/parsers.js +176 -0
- codetrust-1.5.0/extension/out/parsers.js.map +1 -0
- codetrust-1.5.0/extension/out/status-bar.d.ts +22 -0
- codetrust-1.5.0/extension/out/status-bar.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/status-bar.js +126 -0
- codetrust-1.5.0/extension/out/status-bar.js.map +1 -0
- codetrust-1.5.0/extension/out/test/runTest.d.ts +6 -0
- codetrust-1.5.0/extension/out/test/runTest.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/test/runTest.js +56 -0
- codetrust-1.5.0/extension/out/test/runTest.js.map +1 -0
- codetrust-1.5.0/extension/out/test/suite/api-client.test.d.ts +6 -0
- codetrust-1.5.0/extension/out/test/suite/api-client.test.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/test/suite/api-client.test.js +104 -0
- codetrust-1.5.0/extension/out/test/suite/api-client.test.js.map +1 -0
- codetrust-1.5.0/extension/out/test/suite/index.d.ts +5 -0
- codetrust-1.5.0/extension/out/test/suite/index.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/test/suite/index.js +67 -0
- codetrust-1.5.0/extension/out/test/suite/index.js.map +1 -0
- codetrust-1.5.0/extension/out/test/suite/parsers.test.d.ts +6 -0
- codetrust-1.5.0/extension/out/test/suite/parsers.test.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/test/suite/parsers.test.js +178 -0
- codetrust-1.5.0/extension/out/test/suite/parsers.test.js.map +1 -0
- codetrust-1.5.0/extension/out/test/suite/types.test.d.ts +5 -0
- codetrust-1.5.0/extension/out/test/suite/types.test.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/test/suite/types.test.js +78 -0
- codetrust-1.5.0/extension/out/test/suite/types.test.js.map +1 -0
- codetrust-1.5.0/extension/out/types.d.ts +125 -0
- codetrust-1.5.0/extension/out/types.d.ts.map +1 -0
- codetrust-1.5.0/extension/out/types.js +20 -0
- codetrust-1.5.0/extension/out/types.js.map +1 -0
- codetrust-1.5.0/extension/package-lock.json +5186 -0
- codetrust-1.5.0/extension/package.json +152 -0
- codetrust-1.5.0/extension/src/api-client.ts +182 -0
- codetrust-1.5.0/extension/src/code-actions.ts +249 -0
- codetrust-1.5.0/extension/src/commands.ts +418 -0
- codetrust-1.5.0/extension/src/config.ts +25 -0
- codetrust-1.5.0/extension/src/diagnostics.ts +213 -0
- codetrust-1.5.0/extension/src/embedded-scanner.ts +202 -0
- codetrust-1.5.0/extension/src/extension.ts +120 -0
- codetrust-1.5.0/extension/src/parsers.ts +222 -0
- codetrust-1.5.0/extension/src/status-bar.ts +112 -0
- codetrust-1.5.0/extension/src/test/runTest.ts +23 -0
- codetrust-1.5.0/extension/src/test/suite/api-client.test.ts +75 -0
- codetrust-1.5.0/extension/src/test/suite/index.ts +28 -0
- codetrust-1.5.0/extension/src/test/suite/parsers.test.ts +165 -0
- codetrust-1.5.0/extension/src/test/suite/types.test.ts +53 -0
- codetrust-1.5.0/extension/src/types.ts +157 -0
- codetrust-1.5.0/extension/tsconfig.json +27 -0
- codetrust-1.5.0/hooks/pre-commit +117 -0
- codetrust-1.5.0/pyproject.toml +108 -0
- codetrust-1.5.0/railway.toml +11 -0
- codetrust-1.5.0/sandbox/go/Dockerfile +10 -0
- codetrust-1.5.0/sandbox/node/Dockerfile +9 -0
- codetrust-1.5.0/sandbox/python/Dockerfile +15 -0
- codetrust-1.5.0/sandbox/rust/Dockerfile +10 -0
- codetrust-1.5.0/setup.sh +184 -0
- codetrust-1.5.0/smoke_test.sh +102 -0
- codetrust-1.5.0/src/__init__.py +1 -0
- codetrust-1.5.0/src/api.py +1155 -0
- codetrust-1.5.0/src/cli.py +460 -0
- codetrust-1.5.0/src/config.py +93 -0
- codetrust-1.5.0/src/formatters/__init__.py +1 -0
- codetrust-1.5.0/src/formatters/sarif.py +184 -0
- codetrust-1.5.0/src/models/__init__.py +1 -0
- codetrust-1.5.0/src/models/database.py +127 -0
- codetrust-1.5.0/src/models/enums.py +63 -0
- codetrust-1.5.0/src/models/requests.py +198 -0
- codetrust-1.5.0/src/models/responses.py +274 -0
- codetrust-1.5.0/src/rules/__init__.py +1 -0
- codetrust-1.5.0/src/rules/anti_patterns.py +110 -0
- codetrust-1.5.0/src/rules/enterprise.py +35 -0
- codetrust-1.5.0/src/server.py +767 -0
- codetrust-1.5.0/src/services/__init__.py +1 -0
- codetrust-1.5.0/src/services/ast_analyzer.py +612 -0
- codetrust-1.5.0/src/services/auth.py +128 -0
- codetrust-1.5.0/src/services/billing.py +148 -0
- codetrust-1.5.0/src/services/cache.py +97 -0
- codetrust-1.5.0/src/services/database.py +342 -0
- codetrust-1.5.0/src/services/docker_verify.py +232 -0
- codetrust-1.5.0/src/services/rate_limiter.py +65 -0
- codetrust-1.5.0/src/services/registry.py +771 -0
- codetrust-1.5.0/src/services/sandbox.py +270 -0
- codetrust-1.5.0/src/services/static_analyzer.py +337 -0
- codetrust-1.5.0/src/templates/CLAUDE.md +42 -0
- codetrust-1.5.0/src/templates/__init__.py +1 -0
- codetrust-1.5.0/src/templates/codetrust-scan.yml +35 -0
- codetrust-1.5.0/src/templates/cursorrules +11 -0
- codetrust-1.5.0/src/templates/pre-commit +59 -0
- codetrust-1.5.0/src/utils/__init__.py +1 -0
- codetrust-1.5.0/src/utils/parsers.py +552 -0
- codetrust-1.5.0/src/utils/similarity.py +310 -0
- codetrust-1.5.0/tests/__init__.py +0 -0
- codetrust-1.5.0/tests/conftest.py +40 -0
- codetrust-1.5.0/tests/test_api_endpoints.py +492 -0
- codetrust-1.5.0/tests/test_ast.py +778 -0
- codetrust-1.5.0/tests/test_auth_service.py +240 -0
- codetrust-1.5.0/tests/test_billing.py +257 -0
- codetrust-1.5.0/tests/test_cache.py +96 -0
- codetrust-1.5.0/tests/test_dashboard_api.py +242 -0
- codetrust-1.5.0/tests/test_database.py +332 -0
- codetrust-1.5.0/tests/test_deep_scan.py +325 -0
- codetrust-1.5.0/tests/test_docker.py +332 -0
- codetrust-1.5.0/tests/test_github_action.py +431 -0
- codetrust-1.5.0/tests/test_go_rust_registry.py +558 -0
- codetrust-1.5.0/tests/test_models.py +393 -0
- codetrust-1.5.0/tests/test_parsers.py +262 -0
- codetrust-1.5.0/tests/test_rate_limit.py +147 -0
- codetrust-1.5.0/tests/test_registry.py +527 -0
- codetrust-1.5.0/tests/test_sandbox.py +976 -0
- codetrust-1.5.0/tests/test_sarif.py +388 -0
- codetrust-1.5.0/tests/test_similarity.py +98 -0
- codetrust-1.5.0/tests/test_static.py +339 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# .cursorrules — CodeTrust Enforcement for Cursor AI
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
# These rules apply to ALL AI agents working in this project
|
|
6
|
+
|
|
7
|
+
# They mirror CLAUDE.md enforcement but in Cursor's format
|
|
8
|
+
|
|
9
|
+
## MANDATORY: CodeTrust Enforcement Protocol
|
|
10
|
+
|
|
11
|
+
Before writing ANY code:
|
|
12
|
+
|
|
13
|
+
1. Call codetrust_pre_action with a description of what you plan to do
|
|
14
|
+
2. If verdict is BLOCK → stop and fix the plan
|
|
15
|
+
3. If verdict is WARN → acknowledge each warning
|
|
16
|
+
|
|
17
|
+
After writing or modifying ANY file:
|
|
18
|
+
|
|
19
|
+
1. Call codetrust_static_scan on every file you changed
|
|
20
|
+
2. Call codetrust_deep_scan if you created new files or modified imports
|
|
21
|
+
3. If any finding has severity BLOCK → fix immediately
|
|
22
|
+
4. If any finding has severity WARN → fix or explain
|
|
23
|
+
|
|
24
|
+
Before committing:
|
|
25
|
+
|
|
26
|
+
1. Call codetrust_post_action with repo root and list of changed files
|
|
27
|
+
2. All BLOCK findings must be resolved — zero tolerance
|
|
28
|
+
3. Run ruff check src/ tests/ — zero warnings
|
|
29
|
+
|
|
30
|
+
## Absolute Prohibitions (enforced by CodeTrust pre-commit hook)
|
|
31
|
+
|
|
32
|
+
- No eval() or exec()
|
|
33
|
+
- No hardcoded secrets (use environment variables)
|
|
34
|
+
- No heredocs (use template files)
|
|
35
|
+
- No pickle.load with untrusted data
|
|
36
|
+
- No SQL string formatting (use parameterized queries)
|
|
37
|
+
- No print() — use structlog
|
|
38
|
+
- No wildcard imports
|
|
39
|
+
- No bare except:
|
|
40
|
+
- No Any types
|
|
41
|
+
- No mutable default arguments
|
|
42
|
+
|
|
43
|
+
## Quality Standards
|
|
44
|
+
|
|
45
|
+
- Every function has type annotations
|
|
46
|
+
- Every public function has a docstring
|
|
47
|
+
- Max 40 lines per function
|
|
48
|
+
- All external HTTP calls wrapped in try/except
|
|
49
|
+
- All Pydantic models use strict=True
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
security-events: write
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
lint-and-test:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install -e ".[dev]"
|
|
28
|
+
|
|
29
|
+
- name: Lint with ruff
|
|
30
|
+
run: ruff check src/ tests/
|
|
31
|
+
|
|
32
|
+
- name: Run tests
|
|
33
|
+
run: pytest tests/ -v --tb=short
|
|
34
|
+
|
|
35
|
+
codetrust-scan:
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
needs: lint-and-test
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
|
|
41
|
+
- name: Set up Python
|
|
42
|
+
uses: actions/setup-python@v5
|
|
43
|
+
with:
|
|
44
|
+
python-version: "3.12"
|
|
45
|
+
|
|
46
|
+
- name: Install dependencies
|
|
47
|
+
run: |
|
|
48
|
+
python -m pip install --upgrade pip
|
|
49
|
+
pip install -e ".[dev]"
|
|
50
|
+
|
|
51
|
+
- name: Run CodeTrust Scan
|
|
52
|
+
uses: ./
|
|
53
|
+
with:
|
|
54
|
+
scan-type: "static"
|
|
55
|
+
language: "python"
|
|
56
|
+
path: "src/"
|
|
57
|
+
fail-on: "block"
|
|
58
|
+
sarif-file: "codetrust-results.sarif"
|
|
59
|
+
|
|
60
|
+
- name: Upload SARIF
|
|
61
|
+
if: always()
|
|
62
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
63
|
+
with:
|
|
64
|
+
sarif_file: codetrust-results.sarif
|
|
65
|
+
continue-on-error: true
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
name: CodeTrust Scan
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
push:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
pull-requests: write
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
codetrust-scan:
|
|
15
|
+
name: CodeTrust Quality Gate
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0 # Full history for diff
|
|
23
|
+
|
|
24
|
+
- name: Set up Python
|
|
25
|
+
uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.12"
|
|
28
|
+
|
|
29
|
+
- name: Install CodeTrust
|
|
30
|
+
run: pip install httpx
|
|
31
|
+
|
|
32
|
+
- name: Get changed files
|
|
33
|
+
id: changed
|
|
34
|
+
run: |
|
|
35
|
+
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
36
|
+
FILES=$(git diff --name-only --diff-filter=ACM ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -E '\.(py|js|ts|go|rs|java|sh)$' || true)
|
|
37
|
+
else
|
|
38
|
+
FILES=$(git diff --name-only --diff-filter=ACM HEAD~1 HEAD | grep -E '\.(py|js|ts|go|rs|java|sh)$' || true)
|
|
39
|
+
fi
|
|
40
|
+
echo "files<<EOF" >> $GITHUB_OUTPUT
|
|
41
|
+
echo "$FILES" >> $GITHUB_OUTPUT
|
|
42
|
+
echo "EOF" >> $GITHUB_OUTPUT
|
|
43
|
+
|
|
44
|
+
- name: Run CodeTrust Scan
|
|
45
|
+
id: scan
|
|
46
|
+
env:
|
|
47
|
+
CODETRUST_API_URL: ${{ secrets.CODETRUST_API_URL || 'https://codetrust-api-production.up.railway.app' }}
|
|
48
|
+
CODETRUST_API_KEY: ${{ secrets.CODETRUST_API_KEY }}
|
|
49
|
+
CHANGED_FILES: ${{ steps.changed.outputs.files }}
|
|
50
|
+
run: python action/scan.py
|
|
51
|
+
|
|
52
|
+
- name: Post PR Comment
|
|
53
|
+
if: github.event_name == 'pull_request' && always()
|
|
54
|
+
uses: actions/github-script@v7
|
|
55
|
+
with:
|
|
56
|
+
script: |
|
|
57
|
+
const fs = require('fs');
|
|
58
|
+
if (!fs.existsSync('codetrust-report.md')) return;
|
|
59
|
+
const body = fs.readFileSync('codetrust-report.md', 'utf8');
|
|
60
|
+
|
|
61
|
+
// Find existing CodeTrust comment
|
|
62
|
+
const { data: comments } = await github.rest.issues.listComments({
|
|
63
|
+
owner: context.repo.owner,
|
|
64
|
+
repo: context.repo.repo,
|
|
65
|
+
issue_number: context.issue.number,
|
|
66
|
+
});
|
|
67
|
+
const existing = comments.find(c =>
|
|
68
|
+
c.body.includes('<!-- codetrust-scan -->')
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const commentBody = `<!-- codetrust-scan -->\n${body}`;
|
|
72
|
+
|
|
73
|
+
if (existing) {
|
|
74
|
+
await github.rest.issues.updateComment({
|
|
75
|
+
owner: context.repo.owner,
|
|
76
|
+
repo: context.repo.repo,
|
|
77
|
+
comment_id: existing.id,
|
|
78
|
+
body: commentBody,
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
await github.rest.issues.createComment({
|
|
82
|
+
owner: context.repo.owner,
|
|
83
|
+
repo: context.repo.repo,
|
|
84
|
+
issue_number: context.issue.number,
|
|
85
|
+
body: commentBody,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
*.egg-info/
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
.eggs/
|
|
10
|
+
|
|
11
|
+
# Virtual environments
|
|
12
|
+
.venv/
|
|
13
|
+
venv/
|
|
14
|
+
env/
|
|
15
|
+
|
|
16
|
+
# IDE
|
|
17
|
+
.vscode/
|
|
18
|
+
.idea/
|
|
19
|
+
*.swp
|
|
20
|
+
*.swo
|
|
21
|
+
|
|
22
|
+
# OS
|
|
23
|
+
.DS_Store
|
|
24
|
+
Thumbs.db
|
|
25
|
+
|
|
26
|
+
# Environment
|
|
27
|
+
.env
|
|
28
|
+
.env.*
|
|
29
|
+
*.secret
|
|
30
|
+
*.pem
|
|
31
|
+
*.key
|
|
32
|
+
|
|
33
|
+
# Testing
|
|
34
|
+
.pytest_cache/
|
|
35
|
+
htmlcov/
|
|
36
|
+
.coverage
|
|
37
|
+
coverage.xml
|
|
38
|
+
|
|
39
|
+
# Docker
|
|
40
|
+
docker-compose.override.yml
|
|
41
|
+
|
|
42
|
+
# Session log (private, never committed)
|
|
43
|
+
SESSION_LOG.md
|
|
44
|
+
|
|
45
|
+
# Node (in case of front-end components)
|
|
46
|
+
node_modules/
|
|
47
|
+
codetrust.db
|
|
48
|
+
codetrust-report.md
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to CodeTrust will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.5.0] - 2026-02-11
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **VS Code / Cursor Extension** (Phase 10) — editor extension for inline code verification
|
|
13
|
+
- `extension/` TypeScript project with full VS Code extension scaffolding
|
|
14
|
+
- Scan on save — automatic static analysis when saving supported files
|
|
15
|
+
- Command palette: Scan File, Deep Scan, Verify Imports, Verify Dockerfile, Clear Diagnostics
|
|
16
|
+
- Inline diagnostics — findings shown as squiggly lines (error/warning/info severity)
|
|
17
|
+
- Quick-fix code actions — suppress rules, apply suggestions, remove problematic lines
|
|
18
|
+
- Status bar — shows last scan verdict (PASS/WARN/BLOCK) with click-to-scan
|
|
19
|
+
- Import verification — extracts imports from Python, JS/TS, Go, Rust and verifies against registries
|
|
20
|
+
- Docker verification — parses FROM directives and validates images/tags
|
|
21
|
+
- Configurable settings: API URL, API key, scan type, severity threshold, language filter, timeout
|
|
22
|
+
- API client using Node.js native http/https (zero runtime dependencies)
|
|
23
|
+
- Parser utilities for Python, JavaScript/TypeScript, Go, Rust imports and Dockerfile images
|
|
24
|
+
- 3 test suites (parser tests, API client tests, type tests)
|
|
25
|
+
- ESLint, TypeScript strict mode, source maps
|
|
26
|
+
|
|
27
|
+
## [1.4.0] - 2026-02-11
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- **Dashboard (Next.js 14+)** (Phase 9) — web dashboard for API key management and usage analytics
|
|
32
|
+
- Landing page with hero section and feature cards
|
|
33
|
+
- Pricing page with Free / Pro / Enterprise tier comparison
|
|
34
|
+
- GitHub OAuth login via NextAuth.js with Prisma adapter
|
|
35
|
+
- Dashboard overview with stats cards, usage chart, and scan history table
|
|
36
|
+
- API key management — create, list, revoke keys (`ct_live_` format, SHA-256 hashed)
|
|
37
|
+
- Account settings page with profile, subscription, and danger zone
|
|
38
|
+
- Tailwind CSS styling with dark-mode-ready custom palette
|
|
39
|
+
- **Stripe Billing** — subscription management with checkout, portal, and webhooks
|
|
40
|
+
- `src/services/billing.py` — `BillingService` wrapping Stripe SDK
|
|
41
|
+
- Checkout sessions, customer portal, subscription status, plan limits
|
|
42
|
+
- Webhook handler for `checkout.session.completed` and `customer.subscription.deleted`
|
|
43
|
+
- Plan limits: FREE=100, PRO=10,000, ENTERPRISE=100,000 scans/day
|
|
44
|
+
- **Database layer (SQLAlchemy 2.0 async)** — persistent storage for users, keys, scans
|
|
45
|
+
- `src/models/database.py` — `User`, `ApiKeyRecord`, `ScanLog`, `UsageDay` ORM models
|
|
46
|
+
- `src/services/database.py` — async CRUD service (~280 lines)
|
|
47
|
+
- PostgreSQL (asyncpg) for production, SQLite (aiosqlite) for tests
|
|
48
|
+
- **8 new API endpoints** — dashboard backend
|
|
49
|
+
- `POST /v1/api-keys`, `GET /v1/api-keys`, `DELETE /v1/api-keys/{key_id}`
|
|
50
|
+
- `GET /v1/scans/history`, `GET /v1/usage`
|
|
51
|
+
- `POST /v1/billing/checkout`, `POST /v1/billing/portal`, `POST /v1/webhooks/stripe`
|
|
52
|
+
- CORS middleware for dashboard cross-origin requests
|
|
53
|
+
- Docker Compose: added PostgreSQL 16 service with health checks
|
|
54
|
+
- 66 new tests (30 database + 22 billing + 15 dashboard API) — **476 tests total**
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- `PlanTier` and `ScanType` enums added to `src/models/enums.py`
|
|
59
|
+
- Config expanded: database, Stripe, OAuth, JWT, dashboard settings
|
|
60
|
+
- `pyproject.toml`: added sqlalchemy, asyncpg, stripe, aiosqlite dependencies
|
|
61
|
+
|
|
62
|
+
## [1.3.0] - 2026-02-11
|
|
63
|
+
|
|
64
|
+
### Added
|
|
65
|
+
|
|
66
|
+
- **GitHub Action for CI/CD** (Phase 8) — reusable composite action for PR scanning
|
|
67
|
+
- `action.yml` with configurable inputs: scan-type, fail-on threshold, language, SARIF output
|
|
68
|
+
- `action/entrypoint.sh` entry script and `action/scan_runner.py` Python runner
|
|
69
|
+
- Language-aware file discovery with exclusion patterns (.git, .venv, node_modules, etc.)
|
|
70
|
+
- GitHub workflow annotations (`::error::`, `::warning::`) for inline PR feedback
|
|
71
|
+
- **SARIF v2.1.0 output** — standard format for GitHub Security tab integration
|
|
72
|
+
- `src/formatters/sarif.py` — converts Finding objects to SARIF JSON
|
|
73
|
+
- `POST /v1/scan/static/sarif` and `POST /v1/scan/deep/sarif` API endpoints
|
|
74
|
+
- `codetrust_sarif_export` MCP tool
|
|
75
|
+
- Security-severity mapping (BLOCK→high, WARN→medium, INFO→low)
|
|
76
|
+
- **CI pipeline** — `.github/workflows/ci.yml` with lint, test, and self-scan jobs
|
|
77
|
+
- 77 new tests (45 GitHub Action + 32 SARIF) — **410 tests total**
|
|
78
|
+
|
|
79
|
+
## [1.2.0] - 2026-02-10
|
|
80
|
+
|
|
81
|
+
### Added
|
|
82
|
+
|
|
83
|
+
- **Sandbox Execution** (Phase 7) — isolated Docker container code execution (Layer 4)
|
|
84
|
+
- `src/services/sandbox.py` — `SandboxService` with inline and file execution strategies
|
|
85
|
+
- Security: `--network=none`, `--read-only`, `--memory=256m`, `--pids-limit=64`
|
|
86
|
+
- Supported languages: Python, JavaScript, TypeScript, Go, Rust
|
|
87
|
+
- `sandbox/` directory with 4 Dockerfiles (python, node, go, rust)
|
|
88
|
+
- `POST /v1/sandbox/run` API endpoint
|
|
89
|
+
- `codetrust_sandbox_run` MCP tool
|
|
90
|
+
- Sandbox layer integrated into deep scan (optional `sandbox_run` field)
|
|
91
|
+
- 63 new sandbox tests — **333 tests total**
|
|
92
|
+
|
|
93
|
+
## [1.0.1] - 2026-02-10
|
|
94
|
+
|
|
95
|
+
### Added
|
|
96
|
+
|
|
97
|
+
- **Go & Rust Registry Support** (Phase 5) — extended registry verification to two new ecosystems
|
|
98
|
+
- `verify_go_module()` — verification against proxy.golang.org with version check
|
|
99
|
+
- `verify_crates_package()` — verification against crates.io with version check
|
|
100
|
+
- `extract_go_imports()` — regex parser for `import "..."` and `import (...)` blocks, skips stdlib
|
|
101
|
+
- `extract_rust_imports()` — regex parser for `use crate::` and `extern crate`, skips std/core/alloc
|
|
102
|
+
- `parse_go_mod()` — parses `require (...)` blocks to module→version mapping
|
|
103
|
+
- `parse_cargo_toml()` — parses `[dependencies]` to crate→version mapping
|
|
104
|
+
- Fuzzy matching suggestions for Go modules and Rust crates (top 200+ each)
|
|
105
|
+
- crates.io User-Agent header (`CodeTrust/1.0.0`)
|
|
106
|
+
- Language routing: `Language.GO` → Go proxy, `Language.RUST` → crates.io
|
|
107
|
+
- Comprehensive tests for Go/Rust verification, import extraction, manifest parsing
|
|
108
|
+
|
|
109
|
+
## [1.1.0] - 2026-02-10
|
|
110
|
+
|
|
111
|
+
### Added
|
|
112
|
+
|
|
113
|
+
- **AST Parsing with tree-sitter** (Phase 6) — deep code analysis via Abstract Syntax Trees (Layer 3)
|
|
114
|
+
- `src/services/ast_analyzer.py` — cyclomatic complexity, unused variables, unreachable code, deep nesting
|
|
115
|
+
- Supports Python, JavaScript, TypeScript, Go, Rust via tree-sitter grammars
|
|
116
|
+
- `POST /v1/scan/ast` API endpoint
|
|
117
|
+
- `codetrust_ast_scan` MCP tool
|
|
118
|
+
- AST layer integrated into deep scan
|
|
119
|
+
- 270 tests total after Phase 6
|
|
120
|
+
|
|
121
|
+
## [1.0.0] - 2026-02-10
|
|
122
|
+
|
|
123
|
+
### Added
|
|
124
|
+
|
|
125
|
+
- **Static Analysis Engine** — 35+ anti-pattern rules with BLOCK/WARN/INFO severity levels
|
|
126
|
+
- Heredoc detection, hardcoded secrets, eval/exec, SQL injection, pickle.load
|
|
127
|
+
- Bare except, wildcard imports, Any types, mutable defaults, magic numbers
|
|
128
|
+
- Function length checking (40-line threshold)
|
|
129
|
+
- **Package Registry Verification** — verify imports against real registries
|
|
130
|
+
- PyPI support for Python packages
|
|
131
|
+
- npm support for JavaScript/TypeScript packages
|
|
132
|
+
- Version mismatch detection
|
|
133
|
+
- Typosquatting suggestions via fuzzy matching
|
|
134
|
+
- **Docker Image Verification** — verify base images and tags exist on Docker Hub
|
|
135
|
+
- FROM statement parsing with multi-stage build support
|
|
136
|
+
- Available tag suggestions for unknown tags
|
|
137
|
+
- **Enterprise Structure Validation** — check repos for required files
|
|
138
|
+
- README, LICENSE, tests, .gitignore, pyproject.toml / package.json
|
|
139
|
+
- **Deep Scan** — combined all-layer analysis in a single pass
|
|
140
|
+
- **FastAPI HTTP API** with 5 endpoints
|
|
141
|
+
- `GET /v1/status` — health check
|
|
142
|
+
- `POST /v1/verify/imports` — package verification
|
|
143
|
+
- `POST /v1/verify/dockerfile` — Docker verification
|
|
144
|
+
- `POST /v1/scan/static` — static analysis
|
|
145
|
+
- `POST /v1/scan/deep` — full deep scan
|
|
146
|
+
- **MCP Server** with 7 tools for Claude Code integration
|
|
147
|
+
- `codetrust_static_scan`, `codetrust_pre_action`, `codetrust_post_action`
|
|
148
|
+
- `codetrust_list_rules`, `codetrust_verify_imports`
|
|
149
|
+
- `codetrust_verify_dockerfile`, `codetrust_deep_scan`
|
|
150
|
+
- **Redis caching** with TTL management and graceful degradation
|
|
151
|
+
- **X-API-Key authentication** (optional — skipped in local dev)
|
|
152
|
+
- **Pre-commit hook** with BLOCK/WARN pattern scanning
|
|
153
|
+
- **Docker Compose** stack for API + Redis
|
|
154
|
+
- **Railway deployment** configuration (railway.toml + Procfile)
|
|
155
|
+
- **Multi-stage Dockerfile** with non-root user
|
|
156
|
+
- **structlog** JSON logging throughout
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# CLAUDE.md — CodeTrust Project Rules
|
|
2
|
+
|
|
3
|
+
## ⛔ MANDATORY: CodeTrust Enforcement Protocol
|
|
4
|
+
|
|
5
|
+
> **These rules are NON-NEGOTIABLE. Violation = blocked commit.**
|
|
6
|
+
|
|
7
|
+
### Before writing ANY code
|
|
8
|
+
|
|
9
|
+
1. Call `codetrust_pre_action` with a description of what you plan to do
|
|
10
|
+
2. If verdict is BLOCK → stop and fix the plan before proceeding
|
|
11
|
+
3. If verdict is WARN → acknowledge each warning explicitly
|
|
12
|
+
|
|
13
|
+
### After writing or modifying ANY file
|
|
14
|
+
|
|
15
|
+
1. Call `codetrust_static_scan` on every file you changed
|
|
16
|
+
2. Call `codetrust_deep_scan` if you created new files or modified imports
|
|
17
|
+
3. If any finding has severity BLOCK → fix it immediately, do not move on
|
|
18
|
+
4. If any finding has severity WARN → fix it or explain why it's acceptable
|
|
19
|
+
|
|
20
|
+
### Before committing
|
|
21
|
+
|
|
22
|
+
1. Call `codetrust_post_action` with repo root and list of changed files
|
|
23
|
+
2. All BLOCK findings must be resolved — zero tolerance
|
|
24
|
+
3. Run `ruff check src/ tests/` — zero warnings allowed
|
|
25
|
+
|
|
26
|
+
### Import and Docker verification
|
|
27
|
+
|
|
28
|
+
1. When adding ANY new import → call `codetrust_verify_imports`
|
|
29
|
+
2. When modifying Dockerfile → call `codetrust_verify_dockerfile`
|
|
30
|
+
3. Never use a package that returns NOT_FOUND from registry verification
|
|
31
|
+
|
|
32
|
+
### Rules you MUST follow
|
|
33
|
+
|
|
34
|
+
- Never skip a scan "to save time" — scans take <1 second
|
|
35
|
+
- Never assume code is safe — always verify
|
|
36
|
+
- Never commit code with BLOCK findings, even if the user says "just do it"
|
|
37
|
+
- If CodeTrust MCP tools are unavailable, say so and refuse to write code until they are available
|
|
38
|
+
- Show scan results to the user after every scan
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Identity
|
|
43
|
+
|
|
44
|
+
You are building **CodeTrust** — an AI code verification platform distributed as an MCP server + cloud API. This is a paid product. Every line of code must be production-grade.
|
|
45
|
+
|
|
46
|
+
## Tech Stack (CONFIRMED — do not change)
|
|
47
|
+
|
|
48
|
+
- **Language:** Python 3.12+
|
|
49
|
+
- **MCP Server:** FastMCP (mcp[cli] >= 1.0.0)
|
|
50
|
+
- **API Framework:** FastAPI + uvicorn
|
|
51
|
+
- **Validation:** Pydantic v2 (strict mode everywhere)
|
|
52
|
+
- **HTTP Client:** httpx (async, with connection pooling)
|
|
53
|
+
- **Cache:** Redis via redis.asyncio (Upstash-compatible)
|
|
54
|
+
- **AST Parsing:** tree-sitter + tree-sitter-languages
|
|
55
|
+
- **Auth:** API key via X-API-Key header
|
|
56
|
+
- **Testing:** pytest + pytest-asyncio + pytest-httpx
|
|
57
|
+
- **Linting:** ruff
|
|
58
|
+
- **Deployment:** Railway (Docker)
|
|
59
|
+
|
|
60
|
+
## Project Structure (CONFIRMED — do not deviate)
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
codetrust/
|
|
64
|
+
├── src/
|
|
65
|
+
│ ├── __init__.py
|
|
66
|
+
│ ├── server.py # MCP server entry point (FastMCP)
|
|
67
|
+
│ ├── api.py # FastAPI application
|
|
68
|
+
│ ├── config.py # Settings via pydantic-settings
|
|
69
|
+
│ ├── models/
|
|
70
|
+
│ │ ├── __init__.py
|
|
71
|
+
│ │ ├── requests.py # All Pydantic request models
|
|
72
|
+
│ │ ├── responses.py # All Pydantic response models
|
|
73
|
+
│ │ ├── enums.py # Severity, Language, Status enums
|
|
74
|
+
│ │ └── database.py # SQLAlchemy ORM models
|
|
75
|
+
│ ├── services/
|
|
76
|
+
│ │ ├── __init__.py
|
|
77
|
+
│ │ ├── static_analyzer.py # Layer 1: Regex anti-pattern engine
|
|
78
|
+
│ │ ├── ast_analyzer.py # Layer 3: tree-sitter AST analysis
|
|
79
|
+
│ │ ├── registry.py # Layer 2: Package registry verification
|
|
80
|
+
│ │ ├── docker_verify.py # Layer 2: Docker image/tag verification
|
|
81
|
+
│ │ ├── sandbox.py # Layer 4: Isolated Docker sandbox execution
|
|
82
|
+
│ │ ├── cache.py # Redis caching layer
|
|
83
|
+
│ │ ├── database.py # Async database service (SQLAlchemy)
|
|
84
|
+
│ │ └── billing.py # Stripe billing integration
|
|
85
|
+
│ ├── formatters/
|
|
86
|
+
│ │ ├── __init__.py
|
|
87
|
+
│ │ └── sarif.py # SARIF v2.1.0 output formatter
|
|
88
|
+
│ ├── utils/
|
|
89
|
+
│ │ ├── __init__.py
|
|
90
|
+
│ │ ├── parsers.py # Import extraction, requirements parsing
|
|
91
|
+
│ │ └── similarity.py # Fuzzy matching for "did you mean?"
|
|
92
|
+
│ └── rules/
|
|
93
|
+
│ ├── __init__.py
|
|
94
|
+
│ ├── anti_patterns.py # Anti-pattern rule definitions
|
|
95
|
+
│ └── enterprise.py # Enterprise file/structure rules
|
|
96
|
+
├── tests/
|
|
97
|
+
│ ├── __init__.py
|
|
98
|
+
│ ├── conftest.py # Shared fixtures
|
|
99
|
+
│ ├── test_static.py # Layer 1 tests
|
|
100
|
+
│ ├── test_registry.py # Layer 2 registry tests
|
|
101
|
+
│ ├── test_docker.py # Layer 2 docker tests
|
|
102
|
+
│ ├── test_models.py # Pydantic model tests
|
|
103
|
+
│ ├── test_api_endpoints.py # FastAPI endpoint tests
|
|
104
|
+
│ ├── test_deep_scan.py # Deep scan integration tests
|
|
105
|
+
│ ├── test_cache.py # Cache service tests (fakeredis)
|
|
106
|
+
│ ├── test_similarity.py # Fuzzy matching tests
|
|
107
|
+
│ ├── test_parsers.py # Parser utility tests
|
|
108
|
+
│ ├── test_sarif.py # SARIF formatter tests
|
|
109
|
+
│ ├── test_sandbox.py # Sandbox service tests
|
|
110
|
+
│ ├── test_billing.py # Billing service tests
|
|
111
|
+
│ └── test_database.py # Database service tests
|
|
112
|
+
├── extension/ # VS Code extension (TypeScript)
|
|
113
|
+
├── dashboard/ # Next.js admin dashboard
|
|
114
|
+
├── action/ # GitHub Action for CI integration
|
|
115
|
+
├── sandbox/ # Sandbox Dockerfile definitions
|
|
116
|
+
├── hooks/ # Git hooks (pre-commit)
|
|
117
|
+
├── pyproject.toml
|
|
118
|
+
├── Dockerfile
|
|
119
|
+
├── docker-compose.yml
|
|
120
|
+
├── .env.example
|
|
121
|
+
├── .gitignore
|
|
122
|
+
├── README.md
|
|
123
|
+
├── CHANGELOG.md
|
|
124
|
+
├── LICENSE
|
|
125
|
+
├── PLAN.md
|
|
126
|
+
├── SPEC.md
|
|
127
|
+
├── Procfile
|
|
128
|
+
└── railway.toml
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Absolute Prohibitions
|
|
132
|
+
|
|
133
|
+
- ❌ No `print()` — use `structlog` for all logging
|
|
134
|
+
- ❌ No `Any` types — explicit types on everything
|
|
135
|
+
- ❌ No `eval()` / `exec()`
|
|
136
|
+
- ❌ No hardcoded URLs — all registry URLs in config.py
|
|
137
|
+
- ❌ No hardcoded secrets — all via environment variables
|
|
138
|
+
- ❌ No wildcard imports
|
|
139
|
+
- ❌ No synchronous HTTP calls — all httpx calls must be async
|
|
140
|
+
- ❌ No bare `except:` — always catch specific exceptions
|
|
141
|
+
- ❌ No mutable default arguments
|
|
142
|
+
- ❌ No string concatenation for URLs — use httpx URL building or f-strings with validated inputs
|
|
143
|
+
|
|
144
|
+
## Required Practices
|
|
145
|
+
|
|
146
|
+
- ✅ Every function has type annotations on all parameters and return type
|
|
147
|
+
- ✅ Every public function and class has a docstring
|
|
148
|
+
- ✅ Every external HTTP call wrapped in try/except with timeout
|
|
149
|
+
- ✅ Every Pydantic model uses `model_config = ConfigDict(strict=True)`
|
|
150
|
+
- ✅ Every API endpoint has response_model defined
|
|
151
|
+
- ✅ Constants in UPPER_SNAKE_CASE at module level
|
|
152
|
+
- ✅ Max 40 lines per function — split if longer
|
|
153
|
+
- ✅ All registry URLs defined in config.py as class attributes
|
|
154
|
+
- ✅ All cache TTLs defined as constants in config.py
|
|
155
|
+
- ✅ Use `structlog` with JSON output for all logging
|
|
156
|
+
|
|
157
|
+
## Build Order
|
|
158
|
+
|
|
159
|
+
**Read PLAN.md for the exact build sequence. Build one phase at a time. Do not skip ahead.**
|
|
160
|
+
|
|
161
|
+
Phase 1 → Phase 2 → Phase 3 → Phase 4. Each phase has acceptance criteria that must pass before moving on.
|
|
162
|
+
|
|
163
|
+
## Testing Rules
|
|
164
|
+
|
|
165
|
+
- Every service module must have a corresponding test file
|
|
166
|
+
- Use `pytest-httpx` to mock all external HTTP calls — never hit real registries in tests
|
|
167
|
+
- Use `fakeredis` for cache tests — never require a running Redis
|
|
168
|
+
- Minimum: every public function has at least one happy-path and one error-path test
|
|
169
|
+
- Run `ruff check src/` before committing — zero warnings allowed
|
|
170
|
+
|
|
171
|
+
## Error Handling Pattern
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from src.models.enums import Severity
|
|
175
|
+
from src.models.responses import Finding
|
|
176
|
+
|
|
177
|
+
# Every verification function returns list[Finding], never raises
|
|
178
|
+
async def verify_something(input: SomeInput) -> list[Finding]:
|
|
179
|
+
findings: list[Finding] = []
|
|
180
|
+
try:
|
|
181
|
+
result = await _do_check(input)
|
|
182
|
+
if not result.valid:
|
|
183
|
+
findings.append(Finding(
|
|
184
|
+
rule_id="check_name",
|
|
185
|
+
severity=Severity.BLOCK,
|
|
186
|
+
message="Clear description of what's wrong",
|
|
187
|
+
suggestion="What to do instead",
|
|
188
|
+
))
|
|
189
|
+
except httpx.TimeoutException:
|
|
190
|
+
findings.append(Finding(
|
|
191
|
+
rule_id="check_name",
|
|
192
|
+
severity=Severity.WARN,
|
|
193
|
+
message="Could not verify — registry timeout",
|
|
194
|
+
))
|
|
195
|
+
except httpx.HTTPError as exc:
|
|
196
|
+
findings.append(Finding(
|
|
197
|
+
rule_id="check_name",
|
|
198
|
+
severity=Severity.WARN,
|
|
199
|
+
message=f"Could not verify — HTTP error: {exc}",
|
|
200
|
+
))
|
|
201
|
+
return findings
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Configuration Pattern
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
# All config via pydantic-settings, never scattered
|
|
208
|
+
from pydantic_settings import BaseSettings
|
|
209
|
+
|
|
210
|
+
class Settings(BaseSettings):
|
|
211
|
+
model_config = ConfigDict(env_prefix="CODETRUST_")
|
|
212
|
+
|
|
213
|
+
redis_url: str = "redis://localhost:6379"
|
|
214
|
+
api_key: str = "" # Required in production
|
|
215
|
+
# ... etc
|
|
216
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
FROM python:3.12-slim AS builder
|
|
2
|
+
|
|
3
|
+
WORKDIR /app
|
|
4
|
+
|
|
5
|
+
# Install build dependencies
|
|
6
|
+
COPY pyproject.toml .
|
|
7
|
+
COPY src/ src/
|
|
8
|
+
COPY README.md .
|
|
9
|
+
|
|
10
|
+
RUN pip install --no-cache-dir .
|
|
11
|
+
|
|
12
|
+
# --- Production image ---
|
|
13
|
+
FROM python:3.12-slim
|
|
14
|
+
|
|
15
|
+
LABEL maintainer="Said <said@maketheplay.ai>"
|
|
16
|
+
LABEL description="CodeTrust — AI code verification platform"
|
|
17
|
+
|
|
18
|
+
WORKDIR /app
|
|
19
|
+
|
|
20
|
+
# Copy installed packages and application code
|
|
21
|
+
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
|
22
|
+
COPY --from=builder /usr/local/bin /usr/local/bin
|
|
23
|
+
COPY --from=builder /app /app
|
|
24
|
+
|
|
25
|
+
# Copy Alembic config for migrations
|
|
26
|
+
COPY alembic.ini .
|
|
27
|
+
COPY alembic/ alembic/
|
|
28
|
+
|
|
29
|
+
# Environment defaults
|
|
30
|
+
ENV CODETRUST_HOST=0.0.0.0 \
|
|
31
|
+
CODETRUST_PORT=8000 \
|
|
32
|
+
CODETRUST_DEBUG=false \
|
|
33
|
+
CODETRUST_REDIS_URL=redis://redis:6379
|
|
34
|
+
|
|
35
|
+
EXPOSE 8000
|
|
36
|
+
|
|
37
|
+
# Default: run the FastAPI server
|
|
38
|
+
# Override with: docker run codetrust python -m src.server (for MCP mode)
|
|
39
|
+
CMD ["sh", "-c", "alembic upgrade head && uvicorn src.api:app --host 0.0.0.0 --port 8000"]
|
codetrust-1.5.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CodeTrust
|
|
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.
|