Sentinel is a deterministic static analysis CLI for Python codebases. It parses source files into AST, computes maintainability-oriented metrics, and produces structured outputs for terminal, JSON, and Markdown workflows.
- Python 3.10+
- pip
git clone https://github.com/vikky781/Sentinel.git
cd Sentinel
python -m pip install --upgrade pip
pip install -e .pip install pytest pytest-covSentinel follows strict separation of concerns:
parser: AST parsing and structural extraction onlyanalysis: metric computation onlyscoring: risk and score computation onlyreporting: formatting and report generation onlyai: optional interpretation layer onlycli: orchestration and user interaction only
- CLI receives
analyze <path>input. - Parser loads and parses
.pyfile to AST. - Analysis modules compute independent metrics.
- Scoring computes maintainability score and risk.
- Reporting renders summary/JSON/Markdown outputs.
- AI reviewer can optionally generate narrative review.
sentinel analyze path/to/file.pysentinel analyze path/to/file.py --jsonsentinel analyze path/to/file.py --report report.mdsentinel analyze path/to/file.py --aisentinel analyze path/to/file.py --json --report report.md --aiSentinel computes deterministic static metrics:
- Base value per function:
1 - Increment rules:
+1forif+1forfor+1forwhile+1forexcept+1per additionalBoolOpoperand
- Maximum DFS nesting depth per function
- Tracked control-flow nodes include:
if,for,while,with,try,async for,async with
- Direct recursion only
- Function is marked recursive if it calls itself by name
- Dictionary-based caller-to-callees mapping
- Captures simple and dotted call targets where statically resolvable
- Detects top-level assignment targets only (
Assign,AnnAssign,AugAssign)
Score uses a weighted penalty model:
penalty = (avg_complexity * 4.0) + (avg_nesting * 6.0) + (globals_count * 2.0)
score = clamp(100.0 - penalty, 0.0, 100.0)
Risk bands:
LOWfor score >= 70MEDIUMfor score >= 40 and < 70HIGHfor score < 40
AI in Sentinel is strictly optional and isolated in ai/reviewer.py.
- Input contract: structured JSON dictionary only
- If AI is disabled: deterministic summary is returned
- If AI is enabled but unavailable/misconfigured: deterministic fallback is returned
- Core static analysis path remains deterministic and does not require AI
Set environment variables:
SENTINEL_AI_BASE_URLSENTINEL_AI_API_KEYSENTINEL_AI_MODEL
- Keep modules isolated by responsibility
- Do not move logic across parser/analysis/scoring/reporting/ai/cli boundaries
- Preserve deterministic behavior in core analysis and scoring paths
- Add explicit type hints and production-grade docstrings
- Never swallow exceptions silently
pytest -q
pytest --cov=src/sentinel --cov-report=term-missing --cov-fail-under=85- Workflow installs project dependencies
- Test suite must pass
- Coverage must remain at or above
85%
- Keep change scope minimal and intentional
- Include or update tests for behavior changes
- Ensure CLI behavior remains stable unless explicitly changed
- Ensure no unrelated files are modified
Licensed under Apache 2.0. See LICENSE.