tokenwise-cli 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.
- tokenwise_cli-0.1.0/.github/workflows/ci.yml +106 -0
- tokenwise_cli-0.1.0/.github/workflows/codeql.yml +35 -0
- tokenwise_cli-0.1.0/.github/workflows/dependency-review.yml +26 -0
- tokenwise_cli-0.1.0/.github/workflows/release.yml +96 -0
- tokenwise_cli-0.1.0/.github/workflows/scorecard.yml +47 -0
- tokenwise_cli-0.1.0/.gitignore +48 -0
- tokenwise_cli-0.1.0/CONTRIBUTING.md +74 -0
- tokenwise_cli-0.1.0/LICENSE +21 -0
- tokenwise_cli-0.1.0/Makefile +62 -0
- tokenwise_cli-0.1.0/PKG-INFO +203 -0
- tokenwise_cli-0.1.0/README.md +162 -0
- tokenwise_cli-0.1.0/SECURITY.md +52 -0
- tokenwise_cli-0.1.0/THREAT_MODEL.md +93 -0
- tokenwise_cli-0.1.0/pyproject.toml +102 -0
- tokenwise_cli-0.1.0/src/tokenwise/__init__.py +1 -0
- tokenwise_cli-0.1.0/src/tokenwise/analyzer.py +216 -0
- tokenwise_cli-0.1.0/src/tokenwise/cli.py +218 -0
- tokenwise_cli-0.1.0/src/tokenwise/dashboard.py +193 -0
- tokenwise_cli-0.1.0/src/tokenwise/parser.py +166 -0
- tokenwise_cli-0.1.0/src/tokenwise/pricing.py +76 -0
- tokenwise_cli-0.1.0/src/tokenwise/security.py +153 -0
- tokenwise_cli-0.1.0/src/tokenwise/storage.py +46 -0
- tokenwise_cli-0.1.0/tests/__init__.py +0 -0
- tokenwise_cli-0.1.0/tests/test_parser.py +220 -0
- tokenwise_cli-0.1.0/tests/test_security.py +246 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["main"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["main"]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
name: "Python ${{ matrix.python-version }} / ${{ matrix.os }}"
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
20
|
+
os: [ubuntu-latest, macos-latest]
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
|
|
25
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
26
|
+
uses: actions/setup-python@v5
|
|
27
|
+
with:
|
|
28
|
+
python-version: ${{ matrix.python-version }}
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: pip install -e ".[dev]"
|
|
32
|
+
|
|
33
|
+
- name: Run tests with coverage
|
|
34
|
+
run: pytest --cov=tokenwise --cov-report=term-missing --cov-fail-under=80
|
|
35
|
+
|
|
36
|
+
- name: Upload coverage report
|
|
37
|
+
if: matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest'
|
|
38
|
+
uses: actions/upload-artifact@v4
|
|
39
|
+
with:
|
|
40
|
+
name: coverage-report
|
|
41
|
+
path: htmlcov/
|
|
42
|
+
|
|
43
|
+
lint:
|
|
44
|
+
name: Lint & type-check
|
|
45
|
+
runs-on: ubuntu-latest
|
|
46
|
+
|
|
47
|
+
steps:
|
|
48
|
+
- uses: actions/checkout@v4
|
|
49
|
+
|
|
50
|
+
- name: Set up Python 3.13
|
|
51
|
+
uses: actions/setup-python@v5
|
|
52
|
+
with:
|
|
53
|
+
python-version: "3.13"
|
|
54
|
+
|
|
55
|
+
- name: Install dependencies
|
|
56
|
+
run: pip install -e ".[dev]"
|
|
57
|
+
|
|
58
|
+
- name: ruff check
|
|
59
|
+
run: ruff check src/ tests/
|
|
60
|
+
|
|
61
|
+
- name: ruff format (check only)
|
|
62
|
+
run: ruff format --check src/ tests/
|
|
63
|
+
|
|
64
|
+
- name: mypy
|
|
65
|
+
run: mypy src/
|
|
66
|
+
|
|
67
|
+
security:
|
|
68
|
+
name: Security audit
|
|
69
|
+
runs-on: ubuntu-latest
|
|
70
|
+
|
|
71
|
+
steps:
|
|
72
|
+
- uses: actions/checkout@v4
|
|
73
|
+
|
|
74
|
+
- name: Set up Python 3.13
|
|
75
|
+
uses: actions/setup-python@v5
|
|
76
|
+
with:
|
|
77
|
+
python-version: "3.13"
|
|
78
|
+
|
|
79
|
+
- name: Install dependencies
|
|
80
|
+
run: pip install -e ".[dev]"
|
|
81
|
+
|
|
82
|
+
- name: bandit static analysis
|
|
83
|
+
run: bandit -r src/ -c pyproject.toml
|
|
84
|
+
|
|
85
|
+
- name: pip-audit (vulnerability scan)
|
|
86
|
+
# CVE-2026-3219 affects pip itself with no available fix version.
|
|
87
|
+
# It is not a dependency of tokenwise (runtime or dev).
|
|
88
|
+
run: pip-audit --ignore-vuln CVE-2026-3219
|
|
89
|
+
|
|
90
|
+
- name: Grep check — no network imports
|
|
91
|
+
run: |
|
|
92
|
+
echo "Checking for forbidden network imports..."
|
|
93
|
+
if grep -rE "import (requests|urllib|httpx|socket|http\.client|aiohttp|ssl)" src/; then
|
|
94
|
+
echo "FAIL: network import found in src/"
|
|
95
|
+
exit 1
|
|
96
|
+
fi
|
|
97
|
+
echo "OK: no network imports found"
|
|
98
|
+
|
|
99
|
+
- name: Grep check — no eval/exec/pickle/subprocess
|
|
100
|
+
run: |
|
|
101
|
+
echo "Checking for forbidden execution primitives..."
|
|
102
|
+
if grep -rE "\b(eval|exec|pickle|subprocess|os\.system)\(" src/; then
|
|
103
|
+
echo "FAIL: forbidden execution primitive found in src/"
|
|
104
|
+
exit 1
|
|
105
|
+
fi
|
|
106
|
+
echo "OK: no forbidden execution primitives found"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: CodeQL
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["main"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["main"]
|
|
8
|
+
schedule:
|
|
9
|
+
# Run every Monday at 08:00 UTC
|
|
10
|
+
- cron: "0 8 * * 1"
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
actions: read
|
|
14
|
+
contents: read
|
|
15
|
+
security-events: write
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
analyze:
|
|
19
|
+
name: Analyze (Python)
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
|
|
25
|
+
- name: Initialize CodeQL
|
|
26
|
+
uses: github/codeql-action/init@v3
|
|
27
|
+
with:
|
|
28
|
+
languages: python
|
|
29
|
+
# Use the default query suite — includes security-and-quality checks.
|
|
30
|
+
queries: security-and-quality
|
|
31
|
+
|
|
32
|
+
- name: Perform CodeQL Analysis
|
|
33
|
+
uses: github/codeql-action/analyze@v3
|
|
34
|
+
with:
|
|
35
|
+
category: "/language:python"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Dependency Review
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: ["main"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
pull-requests: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
dependency-review:
|
|
13
|
+
name: Dependency Review
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Dependency Review
|
|
19
|
+
uses: actions/dependency-review-action@v4
|
|
20
|
+
with:
|
|
21
|
+
# Block PRs that introduce packages with HIGH or CRITICAL vulnerabilities.
|
|
22
|
+
fail-on-severity: high
|
|
23
|
+
# Comment on the PR with a summary of new dependencies and their licenses.
|
|
24
|
+
comment-summary-in-pr: always
|
|
25
|
+
# Deny packages with these licenses (non-permissive or incompatible with MIT).
|
|
26
|
+
deny-licenses: GPL-3.0, AGPL-3.0
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# Triggered when a version tag is pushed (e.g. v0.1.0).
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
tags:
|
|
7
|
+
- "v*.*.*"
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
# Required for OIDC Trusted Publishing — no API token needed in secrets.
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build:
|
|
16
|
+
name: Build distribution
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python 3.13
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.13"
|
|
26
|
+
|
|
27
|
+
- name: Install build tools
|
|
28
|
+
run: pip install build
|
|
29
|
+
|
|
30
|
+
- name: Build wheel and sdist
|
|
31
|
+
run: python -m build
|
|
32
|
+
|
|
33
|
+
- name: Upload distribution artifacts
|
|
34
|
+
uses: actions/upload-artifact@v4
|
|
35
|
+
with:
|
|
36
|
+
name: dist
|
|
37
|
+
path: dist/
|
|
38
|
+
|
|
39
|
+
publish-pypi:
|
|
40
|
+
name: Publish to PyPI
|
|
41
|
+
needs: build
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
environment:
|
|
44
|
+
name: pypi
|
|
45
|
+
url: https://pypi.org/project/tokenwise/
|
|
46
|
+
|
|
47
|
+
steps:
|
|
48
|
+
- name: Download distribution artifacts
|
|
49
|
+
uses: actions/download-artifact@v4
|
|
50
|
+
with:
|
|
51
|
+
name: dist
|
|
52
|
+
path: dist/
|
|
53
|
+
|
|
54
|
+
# Trusted Publishing (OIDC) — no API token required.
|
|
55
|
+
#
|
|
56
|
+
# To configure on PyPI:
|
|
57
|
+
# 1. Go to https://pypi.org/manage/account/publishing/
|
|
58
|
+
# 2. Add a new "pending publisher" with:
|
|
59
|
+
# - PyPI project name: tokenwise
|
|
60
|
+
# - Owner: sowmithkuppa
|
|
61
|
+
# - Repository: tokenwise
|
|
62
|
+
# - Workflow filename: release.yml
|
|
63
|
+
# - Environment name: pypi
|
|
64
|
+
# 3. That's it — no secret tokens needed.
|
|
65
|
+
- name: Publish to PyPI
|
|
66
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
67
|
+
# No api_token needed — OIDC identity is exchanged automatically.
|
|
68
|
+
|
|
69
|
+
sign-sigstore:
|
|
70
|
+
name: Sign with Sigstore
|
|
71
|
+
needs: build
|
|
72
|
+
runs-on: ubuntu-latest
|
|
73
|
+
|
|
74
|
+
permissions:
|
|
75
|
+
contents: write # to upload the signed artifacts to the GitHub release
|
|
76
|
+
id-token: write # for Sigstore OIDC signing
|
|
77
|
+
|
|
78
|
+
steps:
|
|
79
|
+
- name: Download distribution artifacts
|
|
80
|
+
uses: actions/download-artifact@v4
|
|
81
|
+
with:
|
|
82
|
+
name: dist
|
|
83
|
+
path: dist/
|
|
84
|
+
|
|
85
|
+
- name: Sign artifacts with Sigstore
|
|
86
|
+
uses: sigstore/gh-action-sigstore-python@v3
|
|
87
|
+
with:
|
|
88
|
+
inputs: dist/*.whl dist/*.tar.gz
|
|
89
|
+
|
|
90
|
+
- name: Upload signed artifacts to GitHub Release
|
|
91
|
+
uses: softprops/action-gh-release@v2
|
|
92
|
+
with:
|
|
93
|
+
files: |
|
|
94
|
+
dist/*.whl
|
|
95
|
+
dist/*.tar.gz
|
|
96
|
+
dist/*.sigstore.json
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: OpenSSF Scorecard
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["main"]
|
|
6
|
+
schedule:
|
|
7
|
+
# Run every Monday at 08:30 UTC
|
|
8
|
+
- cron: "30 8 * * 1"
|
|
9
|
+
# Allow manual triggers
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
permissions: read-all
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
analysis:
|
|
16
|
+
name: Scorecard analysis
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
|
|
19
|
+
permissions:
|
|
20
|
+
security-events: write
|
|
21
|
+
id-token: write # required for publishing results
|
|
22
|
+
contents: read
|
|
23
|
+
actions: read
|
|
24
|
+
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
|
+
with:
|
|
28
|
+
persist-credentials: false
|
|
29
|
+
|
|
30
|
+
- name: Run analysis
|
|
31
|
+
uses: ossf/scorecard-action@v2.4.0
|
|
32
|
+
with:
|
|
33
|
+
results_file: results.sarif
|
|
34
|
+
results_format: sarif
|
|
35
|
+
publish_results: true
|
|
36
|
+
|
|
37
|
+
- name: Upload artifact
|
|
38
|
+
uses: actions/upload-artifact@v4
|
|
39
|
+
with:
|
|
40
|
+
name: SARIF file
|
|
41
|
+
path: results.sarif
|
|
42
|
+
retention-days: 5
|
|
43
|
+
|
|
44
|
+
- name: Upload to code-scanning
|
|
45
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
46
|
+
with:
|
|
47
|
+
sarif_file: results.sarif
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Virtual environments
|
|
2
|
+
.venv/
|
|
3
|
+
.venv*/
|
|
4
|
+
venv/
|
|
5
|
+
env/
|
|
6
|
+
|
|
7
|
+
# Python bytecode
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.py[cod]
|
|
10
|
+
*.pyo
|
|
11
|
+
|
|
12
|
+
# Distribution / packaging
|
|
13
|
+
dist/
|
|
14
|
+
build/
|
|
15
|
+
*.egg-info/
|
|
16
|
+
*.egg
|
|
17
|
+
*.whl
|
|
18
|
+
MANIFEST
|
|
19
|
+
|
|
20
|
+
# Testing
|
|
21
|
+
.pytest_cache/
|
|
22
|
+
.coverage
|
|
23
|
+
.coverage.*
|
|
24
|
+
htmlcov/
|
|
25
|
+
.tox/
|
|
26
|
+
|
|
27
|
+
# Type checking
|
|
28
|
+
.mypy_cache/
|
|
29
|
+
.dmypy.json
|
|
30
|
+
|
|
31
|
+
# Ruff cache
|
|
32
|
+
.ruff_cache/
|
|
33
|
+
|
|
34
|
+
# Security / audit tools
|
|
35
|
+
.bandit/
|
|
36
|
+
|
|
37
|
+
# tokenwise local cache
|
|
38
|
+
.tokenwise/
|
|
39
|
+
|
|
40
|
+
# Environment files (never commit secrets)
|
|
41
|
+
.env
|
|
42
|
+
.env.*
|
|
43
|
+
|
|
44
|
+
# macOS
|
|
45
|
+
.DS_Store
|
|
46
|
+
|
|
47
|
+
# Compiled extensions
|
|
48
|
+
*.so
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributing to tokenwise
|
|
2
|
+
|
|
3
|
+
Thank you for helping improve tokenwise.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/sowmithkuppa/tokenwise.git
|
|
9
|
+
cd tokenwise
|
|
10
|
+
python3.13 -m venv .venv # Python 3.10+ required
|
|
11
|
+
source .venv/bin/activate
|
|
12
|
+
pip install -e ".[dev]"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Running tests
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pytest # run all tests
|
|
19
|
+
pytest tests/test_security.py # run security tests only
|
|
20
|
+
pytest --cov=tokenwise # with coverage
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Lint and type-check
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
ruff check src/ tests/ # linter
|
|
27
|
+
ruff format src/ tests/ # formatter
|
|
28
|
+
mypy src/ # type checker
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Security checks (run before every PR)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
make verify # runs all of the above + bandit + pip-audit + grep checks
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or individually:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
bandit -r src/ -c pyproject.toml
|
|
41
|
+
|
|
42
|
+
pip-audit
|
|
43
|
+
|
|
44
|
+
# No network imports
|
|
45
|
+
grep -rE "import (requests|urllib|httpx|socket|http)" src/
|
|
46
|
+
|
|
47
|
+
# No forbidden execution primitives
|
|
48
|
+
grep -rE "\b(eval|exec|pickle|subprocess)\b" src/
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Security review expectations for PRs
|
|
52
|
+
|
|
53
|
+
Every PR that touches `src/` must pass `make verify` locally before requesting review.
|
|
54
|
+
|
|
55
|
+
PRs that modify any of the following require an explicit explanation in the PR description:
|
|
56
|
+
- `src/tokenwise/security.py`
|
|
57
|
+
- `src/tokenwise/parser.py` (the module with read access to `~/.claude/`)
|
|
58
|
+
- `src/tokenwise/storage.py` (the module with write access to `~/.tokenwise/`)
|
|
59
|
+
- `.github/workflows/` (any CI change)
|
|
60
|
+
- `pyproject.toml` (dependency changes)
|
|
61
|
+
|
|
62
|
+
New runtime dependencies require justification: what does it do, why is it needed, and why can't we use stdlib?
|
|
63
|
+
|
|
64
|
+
## Pricing updates
|
|
65
|
+
|
|
66
|
+
To update model pricing, edit `src/tokenwise/pricing.py`. Update the date comment at the top and verify the numbers match https://www.anthropic.com/pricing. Include the source URL in your PR description.
|
|
67
|
+
|
|
68
|
+
## Commit style
|
|
69
|
+
|
|
70
|
+
Use imperative mood: `Add X`, `Fix Y`, `Update Z`. Keep the subject line under 72 characters.
|
|
71
|
+
|
|
72
|
+
## Code style
|
|
73
|
+
|
|
74
|
+
This project uses `ruff` for formatting and linting. Run `ruff format src/ tests/` before committing. Comments in source code should explain *why*, not *what*. No block comments for obvious code.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sowmith Kuppa
|
|
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,62 @@
|
|
|
1
|
+
.PHONY: test lint typecheck audit grep-check verify clean
|
|
2
|
+
|
|
3
|
+
# ── Setup ────────────────────────────────────────────────────────────────────
|
|
4
|
+
# Assumes a venv exists. Run: python3.13 -m venv .venv && pip install -e ".[dev]"
|
|
5
|
+
VENV_BIN ?= .venv/bin
|
|
6
|
+
PYTHON := $(VENV_BIN)/python
|
|
7
|
+
PIP := $(VENV_BIN)/pip
|
|
8
|
+
|
|
9
|
+
# ── Individual targets ───────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
test:
|
|
12
|
+
$(VENV_BIN)/pytest --tb=short -q
|
|
13
|
+
|
|
14
|
+
test-cov:
|
|
15
|
+
$(VENV_BIN)/pytest --cov=tokenwise --cov-report=term-missing --cov-fail-under=80
|
|
16
|
+
|
|
17
|
+
lint:
|
|
18
|
+
$(VENV_BIN)/ruff check src/ tests/
|
|
19
|
+
$(VENV_BIN)/ruff format --check src/ tests/
|
|
20
|
+
|
|
21
|
+
typecheck:
|
|
22
|
+
$(VENV_BIN)/mypy src/
|
|
23
|
+
|
|
24
|
+
audit:
|
|
25
|
+
$(VENV_BIN)/bandit -r src/ -c pyproject.toml
|
|
26
|
+
# CVE-2026-3219 affects pip itself (no fix version exists yet — it's the
|
|
27
|
+
# package manager in our dev venv, not a runtime dependency of tokenwise).
|
|
28
|
+
$(VENV_BIN)/pip-audit --ignore-vuln CVE-2026-3219
|
|
29
|
+
|
|
30
|
+
grep-check:
|
|
31
|
+
@echo "── Checking for forbidden network imports ──────────────────────────"
|
|
32
|
+
@if grep -rE "import (requests|urllib|httpx|socket|http\.client|aiohttp|ssl)" src/; then \
|
|
33
|
+
echo "FAIL: network import found in src/"; exit 1; \
|
|
34
|
+
else echo "OK: no network imports"; fi
|
|
35
|
+
|
|
36
|
+
@echo "── Checking for forbidden execution primitives ─────────────────────"
|
|
37
|
+
@if grep -rE "\b(eval|exec|pickle|subprocess|os\.system)\b" src/; then \
|
|
38
|
+
echo "FAIL: forbidden primitive found in src/"; exit 1; \
|
|
39
|
+
else echo "OK: no eval/exec/pickle/subprocess/os.system"; fi
|
|
40
|
+
|
|
41
|
+
@echo "── Checking for write-mode opens ───────────────────────────────────"
|
|
42
|
+
@if grep -rE "open\(.*['\"][wa+]" src/tokenwise/parser.py; then \
|
|
43
|
+
echo "FAIL: write-mode open found in parser.py"; exit 1; \
|
|
44
|
+
else echo "OK: no write-mode opens in parser.py"; fi
|
|
45
|
+
|
|
46
|
+
# ── The one command a skeptical user should run ──────────────────────────────
|
|
47
|
+
verify: lint typecheck test audit grep-check
|
|
48
|
+
@echo ""
|
|
49
|
+
@echo "╔══════════════════════════════════════════════════════╗"
|
|
50
|
+
@echo "║ All security checks passed. ║"
|
|
51
|
+
@echo "║ ║"
|
|
52
|
+
@echo "║ • No network imports in source ║"
|
|
53
|
+
@echo "║ • No eval/exec/pickle/subprocess ║"
|
|
54
|
+
@echo "║ • No write-mode opens on ~/.claude/ ║"
|
|
55
|
+
@echo "║ • bandit: no security issues ║"
|
|
56
|
+
@echo "║ • pip-audit: no known vulnerabilities ║"
|
|
57
|
+
@echo "║ • All 25 tests pass ║"
|
|
58
|
+
@echo "╚══════════════════════════════════════════════════════╝"
|
|
59
|
+
|
|
60
|
+
clean:
|
|
61
|
+
rm -rf dist/ build/ *.egg-info .coverage htmlcov/ .pytest_cache/
|
|
62
|
+
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
|