mastiff 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.
- mastiff-0.1.0/.github/workflows/ci.yml +46 -0
- mastiff-0.1.0/.github/workflows/release.yml +37 -0
- mastiff-0.1.0/.gitignore +15 -0
- mastiff-0.1.0/LICENSE +21 -0
- mastiff-0.1.0/PKG-INFO +313 -0
- mastiff-0.1.0/README.md +271 -0
- mastiff-0.1.0/mastiff.yaml.example +62 -0
- mastiff-0.1.0/pyproject.toml +73 -0
- mastiff-0.1.0/src/mastiff/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/_internal/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/_internal/git.py +102 -0
- mastiff-0.1.0/src/mastiff/_internal/subprocess.py +87 -0
- mastiff-0.1.0/src/mastiff/analysis/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/analysis/categories.py +58 -0
- mastiff-0.1.0/src/mastiff/analysis/client.py +89 -0
- mastiff-0.1.0/src/mastiff/analysis/prompt.py +131 -0
- mastiff-0.1.0/src/mastiff/analysis/response.py +60 -0
- mastiff-0.1.0/src/mastiff/cli/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/cli/app.py +24 -0
- mastiff-0.1.0/src/mastiff/cli/commands/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/cli/commands/baseline.py +19 -0
- mastiff-0.1.0/src/mastiff/cli/commands/init.py +24 -0
- mastiff-0.1.0/src/mastiff/cli/commands/install.py +21 -0
- mastiff-0.1.0/src/mastiff/cli/commands/review.py +75 -0
- mastiff-0.1.0/src/mastiff/cli/commands/server.py +13 -0
- mastiff-0.1.0/src/mastiff/cli/output.py +68 -0
- mastiff-0.1.0/src/mastiff/config/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/config/defaults.py +78 -0
- mastiff-0.1.0/src/mastiff/config/loader.py +58 -0
- mastiff-0.1.0/src/mastiff/config/schema.py +157 -0
- mastiff-0.1.0/src/mastiff/context/__init__.py +1 -0
- mastiff-0.1.0/src/mastiff/context/cache.py +75 -0
- mastiff-0.1.0/src/mastiff/context/languages/__init__.py +1 -0
- mastiff-0.1.0/src/mastiff/context/languages/base.py +21 -0
- mastiff-0.1.0/src/mastiff/context/languages/generic.py +38 -0
- mastiff-0.1.0/src/mastiff/context/languages/python.py +47 -0
- mastiff-0.1.0/src/mastiff/context/languages/typescript.py +60 -0
- mastiff-0.1.0/src/mastiff/context/resolver.py +92 -0
- mastiff-0.1.0/src/mastiff/context/tracer.py +86 -0
- mastiff-0.1.0/src/mastiff/core/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/core/engine.py +115 -0
- mastiff-0.1.0/src/mastiff/core/fingerprint.py +26 -0
- mastiff-0.1.0/src/mastiff/core/models.py +79 -0
- mastiff-0.1.0/src/mastiff/core/pipeline.py +16 -0
- mastiff-0.1.0/src/mastiff/core/provider.py +15 -0
- mastiff-0.1.0/src/mastiff/core/severity.py +44 -0
- mastiff-0.1.0/src/mastiff/diff/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/diff/collector.py +41 -0
- mastiff-0.1.0/src/mastiff/diff/filter.py +87 -0
- mastiff-0.1.0/src/mastiff/diff/parser.py +130 -0
- mastiff-0.1.0/src/mastiff/integrations/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/integrations/lsp/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/integrations/lsp/debounce.py +49 -0
- mastiff-0.1.0/src/mastiff/integrations/lsp/diagnostics.py +43 -0
- mastiff-0.1.0/src/mastiff/integrations/lsp/scheduler.py +83 -0
- mastiff-0.1.0/src/mastiff/integrations/lsp/server.py +26 -0
- mastiff-0.1.0/src/mastiff/integrations/precommit.py +24 -0
- mastiff-0.1.0/src/mastiff/observability/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/observability/logger.py +38 -0
- mastiff-0.1.0/src/mastiff/observability/metrics.py +56 -0
- mastiff-0.1.0/src/mastiff/py.typed +0 -0
- mastiff-0.1.0/src/mastiff/security/__init__.py +0 -0
- mastiff-0.1.0/src/mastiff/security/patterns.py +40 -0
- mastiff-0.1.0/src/mastiff/security/redactor.py +93 -0
- mastiff-0.1.0/src/mastiff/security/sanitizer.py +71 -0
- mastiff-0.1.0/tests/conftest.py +1 -0
- mastiff-0.1.0/tests/unit/__init__.py +1 -0
- mastiff-0.1.0/tests/unit/languages/__init__.py +1 -0
- mastiff-0.1.0/tests/unit/languages/test_python_parser.py +60 -0
- mastiff-0.1.0/tests/unit/languages/test_typescript_parser.py +55 -0
- mastiff-0.1.0/tests/unit/test_analysis.py +270 -0
- mastiff-0.1.0/tests/unit/test_cli.py +241 -0
- mastiff-0.1.0/tests/unit/test_config.py +556 -0
- mastiff-0.1.0/tests/unit/test_context.py +317 -0
- mastiff-0.1.0/tests/unit/test_diff.py +342 -0
- mastiff-0.1.0/tests/unit/test_engine.py +225 -0
- mastiff-0.1.0/tests/unit/test_fingerprint.py +91 -0
- mastiff-0.1.0/tests/unit/test_integrations.py +231 -0
- mastiff-0.1.0/tests/unit/test_internal.py +184 -0
- mastiff-0.1.0/tests/unit/test_models.py +199 -0
- mastiff-0.1.0/tests/unit/test_observability.py +173 -0
- mastiff-0.1.0/tests/unit/test_pipeline.py +27 -0
- mastiff-0.1.0/tests/unit/test_provider.py +34 -0
- mastiff-0.1.0/tests/unit/test_security.py +189 -0
- mastiff-0.1.0/tests/unit/test_severity.py +59 -0
- mastiff-0.1.0/uv.lock +887 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ['3.12', '3.13', '3.14']
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python-version }}
|
|
22
|
+
- uses: astral-sh/setup-uv@v5
|
|
23
|
+
- run: uv sync --all-extras
|
|
24
|
+
- run: uv run pytest
|
|
25
|
+
|
|
26
|
+
lint:
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v4
|
|
30
|
+
- uses: actions/setup-python@v5
|
|
31
|
+
with:
|
|
32
|
+
python-version: '3.14'
|
|
33
|
+
- uses: astral-sh/setup-uv@v5
|
|
34
|
+
- run: uv sync --all-extras
|
|
35
|
+
- run: uv run ruff check .
|
|
36
|
+
|
|
37
|
+
typecheck:
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
- uses: actions/setup-python@v5
|
|
42
|
+
with:
|
|
43
|
+
python-version: '3.14'
|
|
44
|
+
- uses: astral-sh/setup-uv@v5
|
|
45
|
+
- run: uv sync --all-extras
|
|
46
|
+
- run: uv run mypy src/
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: Release to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: '3.14'
|
|
20
|
+
- uses: astral-sh/setup-uv@v5
|
|
21
|
+
- run: uv sync --all-extras
|
|
22
|
+
- run: uv run pytest
|
|
23
|
+
- run: uv run ruff check .
|
|
24
|
+
- run: uv run mypy src/
|
|
25
|
+
|
|
26
|
+
publish:
|
|
27
|
+
needs: test
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
environment: pypi
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@v4
|
|
32
|
+
- uses: actions/setup-python@v5
|
|
33
|
+
with:
|
|
34
|
+
python-version: '3.14'
|
|
35
|
+
- uses: astral-sh/setup-uv@v5
|
|
36
|
+
- run: uv build
|
|
37
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
mastiff-0.1.0/.gitignore
ADDED
mastiff-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mastiff Contributors
|
|
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.
|
mastiff-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mastiff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI code review agent that detects dangerous patterns in LLM-generated code
|
|
5
|
+
Project-URL: Homepage, https://github.com/yuuichieguchi/mastiff
|
|
6
|
+
Project-URL: Repository, https://github.com/yuuichieguchi/mastiff
|
|
7
|
+
Project-URL: Issues, https://github.com/yuuichieguchi/mastiff/issues
|
|
8
|
+
Author: Mastiff Contributors
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Requires-Dist: anthropic<1.0,>=0.42
|
|
21
|
+
Requires-Dist: click<9.0,>=8.1
|
|
22
|
+
Requires-Dist: pydantic<3.0,>=2.7
|
|
23
|
+
Requires-Dist: pyyaml<7.0,>=6.0
|
|
24
|
+
Requires-Dist: rich<14.0,>=13.0
|
|
25
|
+
Requires-Dist: tenacity<10.0,>=9.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: mypy>=1.13; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-mock>=3.14; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: respx>=0.22; extra == 'dev'
|
|
33
|
+
Requires-Dist: ruff>=0.8; extra == 'dev'
|
|
34
|
+
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
|
|
35
|
+
Provides-Extra: lsp
|
|
36
|
+
Requires-Dist: lsprotocol>=2024.0; extra == 'lsp'
|
|
37
|
+
Requires-Dist: pygls<3.0,>=2.0; extra == 'lsp'
|
|
38
|
+
Provides-Extra: tree-sitter
|
|
39
|
+
Requires-Dist: tree-sitter-typescript<0.24,>=0.23; extra == 'tree-sitter'
|
|
40
|
+
Requires-Dist: tree-sitter<0.24,>=0.23; extra == 'tree-sitter'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# Mastiff
|
|
44
|
+
|
|
45
|
+
[](https://pypi.org/project/mastiff/)
|
|
46
|
+
[](https://pypi.org/project/mastiff/)
|
|
47
|
+
[](LICENSE)
|
|
48
|
+
|
|
49
|
+
AI code review agent that detects dangerous patterns in LLM-generated code.
|
|
50
|
+
|
|
51
|
+
Mastiff analyzes git diffs using the Claude API to detect production-risk patterns across four categories — blocking/deadlocks, race conditions, performance degradation, and resource leaks — scoring each finding by severity and confidence.
|
|
52
|
+
|
|
53
|
+
## Why Mastiff?
|
|
54
|
+
|
|
55
|
+
LLM-generated code often looks correct at first glance but can contain subtle patterns that only manifest in production:
|
|
56
|
+
|
|
57
|
+
- **Event loop blocking** — synchronous calls in async contexts that freeze the application
|
|
58
|
+
- **Race conditions** — shared mutable state accessed without proper synchronization
|
|
59
|
+
- **O(n²) algorithms** — nested loops and unbounded queries that degrade with scale
|
|
60
|
+
- **Resource leaks** — file handles, connections, and sockets opened but never closed
|
|
61
|
+
|
|
62
|
+
Traditional linters catch syntax and style issues. Mastiff focuses specifically on the patterns LLMs tend to introduce — not to replace linters, but to complement them with production-risk awareness.
|
|
63
|
+
|
|
64
|
+
## What It Detects
|
|
65
|
+
|
|
66
|
+
| Category | Description | Examples |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| Blocking/Deadlock | Synchronous blocking calls in async contexts, potential deadlocks | `time.sleep()` in async, synchronous I/O in event loop, inconsistent lock ordering |
|
|
69
|
+
| Race Condition | Shared mutable state without synchronization, TOCTOU | Global variable from multiple threads without locks, non-atomic read-modify-write |
|
|
70
|
+
| Degradation | O(n²) algorithms, excessive allocations, unbounded growth | Nested loops, loading entire DB table into memory, missing pagination |
|
|
71
|
+
| Resource Leak | Resources opened but not properly closed | `open()` without context manager, DB connection not returned to pool |
|
|
72
|
+
|
|
73
|
+
## Quick Start
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install mastiff
|
|
77
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
78
|
+
mastiff review --staged
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Alternative installation methods:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pipx install mastiff
|
|
85
|
+
# or
|
|
86
|
+
uv tool install mastiff
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Get your API key at https://console.anthropic.com/
|
|
90
|
+
|
|
91
|
+
## Output Example
|
|
92
|
+
|
|
93
|
+
**Terminal (default):**
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
Review Findings
|
|
97
|
+
┏━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
|
|
98
|
+
┃ File ┃ Line ┃ Severity ┃ Category ┃ Title ┃ Confidence ┃
|
|
99
|
+
┡━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
|
|
100
|
+
│ api/users.py │ 42 │ critical │ blocking │ time.sleep in async handler │ 92% │
|
|
101
|
+
│ db/pool.py │ 15 │ warning │ resource_leak │ Connection not returned │ 78% │
|
|
102
|
+
└──────────────┴──────┴──────────┴───────────────┴────────────────────────────┴────────────┘
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**JSON (`--format json`):**
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"findings": [
|
|
110
|
+
{
|
|
111
|
+
"rule_id": "blocking-sync-sleep",
|
|
112
|
+
"category": "blocking",
|
|
113
|
+
"severity": "critical",
|
|
114
|
+
"file_path": "api/users.py",
|
|
115
|
+
"line_start": 42,
|
|
116
|
+
"title": "time.sleep in async handler",
|
|
117
|
+
"confidence": 0.92
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Usage
|
|
124
|
+
|
|
125
|
+
### CLI
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Review staged changes
|
|
129
|
+
mastiff review --staged
|
|
130
|
+
|
|
131
|
+
# Review a commit range
|
|
132
|
+
mastiff review HEAD~3..HEAD
|
|
133
|
+
|
|
134
|
+
# Choose review depth
|
|
135
|
+
mastiff review --staged --profile quick
|
|
136
|
+
|
|
137
|
+
# JSON output
|
|
138
|
+
mastiff review --staged --format json
|
|
139
|
+
|
|
140
|
+
# Strict mode: exit 1 on any finding
|
|
141
|
+
mastiff review --staged --strict
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Review profiles:**
|
|
145
|
+
|
|
146
|
+
| Profile | Diff budget | Context budget | Use case |
|
|
147
|
+
|---|---|---|---|
|
|
148
|
+
| quick | 5,000 tokens | 3,000 tokens | Pre-commit, editor saves |
|
|
149
|
+
| standard | 20,000 tokens | 15,000 tokens | PR review (default) |
|
|
150
|
+
| deep | 50,000 tokens | 30,000 tokens | Release audits |
|
|
151
|
+
|
|
152
|
+
### Pre-commit Hook
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Install the pre-commit hook
|
|
156
|
+
mastiff install
|
|
157
|
+
|
|
158
|
+
# Commits are automatically reviewed
|
|
159
|
+
git commit -m "feat: add user endpoint"
|
|
160
|
+
# → mastiff reviews staged changes
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
In CI environments (`CI=true`), the hook runs in strict mode and blocks on any finding. When a baseline exists, only new findings are reported.
|
|
164
|
+
|
|
165
|
+
### LSP Server (Experimental)
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
mastiff server
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Provides real-time diagnostics on file save (quick profile). Configure your editor's LSP client to connect to mastiff.
|
|
172
|
+
|
|
173
|
+
### With Claude Code
|
|
174
|
+
|
|
175
|
+
Mastiff is designed to review LLM-generated code. When using [Claude Code](https://docs.anthropic.com/en/docs/claude-code) as your development agent, Mastiff acts as an automated safety net that catches production-risk patterns before they reach your codebase.
|
|
176
|
+
|
|
177
|
+
**Pre-commit hook (recommended):**
|
|
178
|
+
|
|
179
|
+
Install the hook once and every commit Claude Code creates is automatically reviewed:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
mastiff install
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Claude Code commits through git, so the pre-commit hook runs transparently on every commit. Critical findings block the commit, giving you a chance to review before the code lands.
|
|
186
|
+
|
|
187
|
+
**CI integration:**
|
|
188
|
+
|
|
189
|
+
Add Mastiff to your CI pipeline to review every pull request that Claude Code opens:
|
|
190
|
+
|
|
191
|
+
```yaml
|
|
192
|
+
# .github/workflows/ci.yml
|
|
193
|
+
- run: pip install mastiff
|
|
194
|
+
- run: mastiff review origin/main..HEAD --strict --format json
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Manual review after a session:**
|
|
198
|
+
|
|
199
|
+
After Claude Code completes a task in a worktree, review all changes before merging:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
mastiff review main..HEAD --profile deep
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Baseline
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# Record current findings as baseline
|
|
209
|
+
mastiff baseline
|
|
210
|
+
|
|
211
|
+
# Only new findings are reported from now on
|
|
212
|
+
|
|
213
|
+
# Regenerate after refactoring
|
|
214
|
+
mastiff baseline --rebase
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The baseline uses fingerprint-based stable IDs that are independent of line numbers, so minor code shifts don't invalidate existing suppressions.
|
|
218
|
+
|
|
219
|
+
## Configuration
|
|
220
|
+
|
|
221
|
+
Generate a config file:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
mastiff init
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
This creates `mastiff.yaml` with documented defaults. Key settings:
|
|
228
|
+
|
|
229
|
+
```yaml
|
|
230
|
+
api:
|
|
231
|
+
model: claude-opus-4-20250514 # Claude model to use
|
|
232
|
+
|
|
233
|
+
detection:
|
|
234
|
+
min_confidence: 0.6 # Minimum confidence to report
|
|
235
|
+
|
|
236
|
+
security:
|
|
237
|
+
never_send_paths: # Files never sent to the API
|
|
238
|
+
- .env
|
|
239
|
+
- "*.pem"
|
|
240
|
+
- "*.key"
|
|
241
|
+
|
|
242
|
+
cost:
|
|
243
|
+
max_cost_usd_per_run: 1.00 # Per-run cost limit
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
All config models use Pydantic `extra="forbid"`, so typos in config keys are caught immediately.
|
|
247
|
+
|
|
248
|
+
## Security & Privacy
|
|
249
|
+
|
|
250
|
+
Mastiff sends code to the Claude API for analysis. Here is what it does to minimize exposure:
|
|
251
|
+
|
|
252
|
+
- **What is sent**: Only the diff is sent — never complete source files. Import tracing may include small fragments from related files, bounded by a token budget.
|
|
253
|
+
- **Automatic redaction**: Built-in regex patterns detect API keys, tokens, passwords, and private key headers. Detected values are replaced with `[REDACTED]` before sending. The Redactor also exposes Shannon entropy analysis for identifying high-entropy strings.
|
|
254
|
+
- **File exclusion**: The `never_send_paths` setting excludes sensitive file patterns (`.env`, `*.pem`, `*.key`, etc.) by default. These files are filtered out before any API call.
|
|
255
|
+
- **Output sanitization**: ANSI escape sequences and control characters are stripped from all output to prevent terminal injection.
|
|
256
|
+
- **Prompt injection defense**: User-supplied data (diffs, context) is wrapped in delimiter tags (`<diff>`, `<context>`) and the system prompt establishes reviewer-only behavior.
|
|
257
|
+
|
|
258
|
+
This is a best-effort approach to minimize sensitive data exposure. It does not guarantee that no secrets are sent. Review your `never_send_paths` configuration and consider the sensitivity of your codebase before use.
|
|
259
|
+
|
|
260
|
+
## Cost Control
|
|
261
|
+
|
|
262
|
+
Approximate cost per review (depends on diff size and Claude API pricing):
|
|
263
|
+
|
|
264
|
+
| Profile | Estimated cost |
|
|
265
|
+
|---|---|
|
|
266
|
+
| quick | ~$0.01–0.05 |
|
|
267
|
+
| standard | ~$0.05–0.30 |
|
|
268
|
+
| deep | ~$0.10–0.50 |
|
|
269
|
+
|
|
270
|
+
The `cost.max_cost_usd_per_run` setting (default: $1.00) enforces a per-run budget.
|
|
271
|
+
|
|
272
|
+
## Requirements
|
|
273
|
+
|
|
274
|
+
- Python >= 3.12
|
|
275
|
+
- [Anthropic API key](https://console.anthropic.com/)
|
|
276
|
+
- Git
|
|
277
|
+
|
|
278
|
+
**Optional extras:**
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
pip install "mastiff[tree-sitter]" # Enhanced import tracing
|
|
282
|
+
pip install "mastiff[lsp]" # LSP server support
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Development
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
git clone <repo> && cd mastiff
|
|
289
|
+
uv sync --all-extras
|
|
290
|
+
pytest # 277 tests
|
|
291
|
+
ruff check . # lint
|
|
292
|
+
mypy src/ # type check
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
**Package structure:**
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
src/mastiff/
|
|
299
|
+
├── _internal/ # Git and subprocess utilities
|
|
300
|
+
├── analysis/ # Categories, prompt building, LLM client
|
|
301
|
+
├── cli/ # Commands and terminal output
|
|
302
|
+
├── config/ # Schema, loader, defaults
|
|
303
|
+
├── context/ # Language parsers, import tracer, resolver
|
|
304
|
+
├── core/ # Engine, models, fingerprinting, severity
|
|
305
|
+
├── diff/ # Diff parsing, filtering, collection
|
|
306
|
+
├── integrations/ # Pre-commit hook, LSP server
|
|
307
|
+
├── observability/ # Logging and metrics
|
|
308
|
+
└── security/ # Secret patterns, redactor, sanitizer
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## License
|
|
312
|
+
|
|
313
|
+
[MIT](LICENSE)
|