Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ on:
jobs:
test:
runs-on: ubuntu-24.04
env:
UV_PYTHON: ${{ matrix.python-version }}
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
python-version: ['3.11', '3.12', '3.13']

steps:
- name: Checkout repository
Expand All @@ -29,7 +31,7 @@ jobs:

- name: Install dependencies
run: |
uv sync --all-extras
uv sync --all-extras --python "${{ matrix.python-version }}"

- name: Run tests
run: |
Expand All @@ -44,7 +46,7 @@ jobs:
uv run ruff check src/devscope tests

- name: Upload coverage to Codecov
if: matrix.python-version == '3.9'
if: matrix.python-version == '3.11'
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9
3.11
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ devscope demo
```

The demo needs no repository or Git. Its sample paths, history and coverage are
clearly labelled synthetic. Python 3.9+ is required; Git is needed for real PR
clearly labelled synthetic. Python 3.11+ is required; Git is needed for real PR
reviews. Already installed? Run `pipx upgrade devscope`.

![Terminal demo: prioritized files, evidence and next commands](https://raw.githubusercontent.com/EhsanAzish80/Devscope/main/docs/assets/terminal-demo.jpg)
Expand All @@ -26,6 +26,7 @@ reviews. Already installed? Run `pipx upgrade devscope`.
| --- | --- | --- |
| Understand a repository | [Explore a repository](#explore-a-repository) | Modules, entry-point candidates, test locations and declared commands |
| Focus a code review | [Review a PR](#review-a-pr) | Changed files ranked with size, history, co-change and optional coverage evidence |
| Give an AI coding agent local history | [Connect an MCP client](#connect-an-mcp-client) | Six read-only tools for changes, co-change, fix facts, owners and blast radius |
| Share results with reviewers | [Add to GitHub Actions](#add-to-github-actions) | An updated PR comment and downloadable HTML/JSON/Markdown reports |

## Explore a repository
Expand Down Expand Up @@ -67,6 +68,32 @@ report data, with no external scripts or fonts.
[Download the standalone sample HTML](https://github.com/EhsanAzish80/Devscope/releases/download/v0.3.0/devscope-demo.html)
· [View its structured data](https://github.com/EhsanAzish80/Devscope/blob/main/docs/assets/demo.json)

## Connect an MCP client

Install a project-local MCP entry for Claude Code, Cursor or Codex:

```bash
devscope mcp install --client claude-code --path .
# or: cursor, codex
# without a persistent install: add --command uvx
```

The installer preserves existing configuration and refuses to replace an existing
`devscope` entry. The server exposes six read-only tools: `review_changes`,
`cochange`, `file_risk`, `fix_history`, `owners` and `blast_radius`. It reads local
Git history without running repository code or using the network. A cold history
index builds in the background; retry the tool when it returns `index_building`.
The `file_risk` compatibility name currently returns fix SHAs, churn and owners,
not a risk score. Codex reads `.codex/config.toml` only after the project is trusted.

For a lightweight pre-commit or agent hook, check all working-tree files without blocking by
default:

```bash
devscope check . --working-tree --format claude-stop
devscope check . --working-tree --format claude-stop --strict # opt-in blocking mode
```

## Add to GitHub Actions

Save this as `.github/workflows/devscope.yml`. This starts with **advisory** review;
Expand Down
15 changes: 15 additions & 0 deletions examples/claude-code-stop-hook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"hooks": {
"Stop": [
{
"hooks": [
{
"command": "devscope check --working-tree --format claude-stop",
"type": "command"
}
],
"matcher": ""
}
]
}
}
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "devscope"
version = "0.3.0"
description = "Local PR review guidance, repository onboarding, coverage evidence and offline reports"
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.11"
authors = [
{ name = "devscope contributors" }
]
Expand All @@ -16,8 +16,6 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand All @@ -28,9 +26,9 @@ dependencies = [
"click>=8.1.0",
"rich>=13.0.0",
"gitpython>=3.1.0",
"pathspec>=0.11.0",
"pathspec>=1.1.0",
"platformdirs>=4.0.0",
"tomli>=2.0; python_version < '3.11'",
"mcp>=2,<3",
]

[project.urls]
Expand Down Expand Up @@ -62,7 +60,7 @@ packages = ["src/devscope"]

[tool.ruff]
line-length = 100
target-version = "py39"
target-version = "py311"
src = ["src", "tests"]

[tool.ruff.lint]
Expand All @@ -87,7 +85,7 @@ ignore = [
"tests/**/*.py" = ["ARG"]

[tool.mypy]
python_version = "3.9"
python_version = "3.11"
strict = true
warn_return_any = true
warn_unused_configs = true
Expand Down
9 changes: 4 additions & 5 deletions src/devscope/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import time
from collections import defaultdict
from pathlib import Path
from typing import Optional

try:
import git
Expand Down Expand Up @@ -105,9 +104,9 @@ def __init__(
root_path: Path,
detect_git: bool = True,
enable_intelligence: bool = True,
cache_manager: Optional[CacheManager] = None,
cache_manager: CacheManager | None = None,
max_hotspots: int = 10,
config: Optional[ReviewConfig] = None,
config: ReviewConfig | None = None,
):
"""Initialize the analyzer.

Expand All @@ -124,8 +123,8 @@ def __init__(
self.detect_git = detect_git
self.enable_intelligence = enable_intelligence
self.cache_manager = cache_manager
self.repo_name: Optional[str] = None
self.git_root: Optional[Path] = None
self.repo_name: str | None = None
self.git_root: Path | None = None

if detect_git and HAS_GIT:
self._detect_git_repo()
Expand Down
22 changes: 8 additions & 14 deletions src/devscope/analyzers/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

import json
import re
import sys
import tomllib
from pathlib import Path
from typing import Optional

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

from devscope.models import DependencyInfo

Expand Down Expand Up @@ -51,7 +45,7 @@ def detect_all(self) -> list[DependencyInfo]:

return dependencies

def _detect_python_poetry(self) -> Optional[DependencyInfo]:
def _detect_python_poetry(self) -> DependencyInfo | None:
"""Detect Python dependencies from pyproject.toml."""
pyproject_path = self.root_path / "pyproject.toml"
if not pyproject_path.exists():
Expand Down Expand Up @@ -83,7 +77,7 @@ def _detect_python_poetry(self) -> Optional[DependencyInfo]:

return None

def _detect_python_requirements(self) -> Optional[DependencyInfo]:
def _detect_python_requirements(self) -> DependencyInfo | None:
"""Detect Python dependencies from requirements.txt."""
req_path = self.root_path / "requirements.txt"
if not req_path.exists():
Expand Down Expand Up @@ -114,7 +108,7 @@ def _detect_python_requirements(self) -> Optional[DependencyInfo]:

return None

def _detect_javascript(self) -> Optional[DependencyInfo]:
def _detect_javascript(self) -> DependencyInfo | None:
"""Detect JavaScript dependencies from package.json."""
package_path = self.root_path / "package.json"
if not package_path.exists():
Expand Down Expand Up @@ -145,7 +139,7 @@ def _detect_javascript(self) -> Optional[DependencyInfo]:

return None

def _detect_rust(self) -> Optional[DependencyInfo]:
def _detect_rust(self) -> DependencyInfo | None:
"""Detect Rust dependencies from Cargo.toml."""
cargo_path = self.root_path / "Cargo.toml"
if not cargo_path.exists():
Expand Down Expand Up @@ -184,7 +178,7 @@ def _detect_rust(self) -> Optional[DependencyInfo]:

return None

def _detect_go(self) -> Optional[DependencyInfo]:
def _detect_go(self) -> DependencyInfo | None:
"""Detect Go dependencies from go.mod."""
go_mod_path = self.root_path / "go.mod"
if not go_mod_path.exists():
Expand Down Expand Up @@ -221,7 +215,7 @@ def _detect_go(self) -> Optional[DependencyInfo]:

return None

def _detect_swift(self) -> Optional[DependencyInfo]:
def _detect_swift(self) -> DependencyInfo | None:
"""Detect Swift dependencies from Package.swift."""
package_path = self.root_path / "Package.swift"
if not package_path.exists():
Expand Down Expand Up @@ -253,7 +247,7 @@ def _detect_swift(self) -> Optional[DependencyInfo]:

return None

def _detect_cocoapods(self) -> Optional[DependencyInfo]:
def _detect_cocoapods(self) -> DependencyInfo | None:
"""Detect CocoaPods dependencies from Podfile."""
podfile_path = self.root_path / "Podfile"
if not podfile_path.exists():
Expand Down
12 changes: 6 additions & 6 deletions src/devscope/analyzers/git_intel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Extended git intelligence for repository metrics."""

from datetime import datetime, timezone
from datetime import UTC, datetime
from pathlib import Path
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING

try:
import git
Expand All @@ -28,7 +28,7 @@ def __init__(self, root_path: Path):
root_path: Root directory of the project
"""
self.root_path = root_path
self.repo: Optional[Repo] = None
self.repo: Repo | None = None
self._initialize_repo()

def _initialize_repo(self) -> None:
Expand Down Expand Up @@ -115,7 +115,7 @@ def _get_contributor_count(self) -> int:
except (git.GitCommandError, AttributeError, ValueError):
return 0

def _get_days_since_last_commit(self) -> Optional[int]:
def _get_days_since_last_commit(self) -> int | None:
"""Get the number of days since the last commit.

Returns:
Expand All @@ -131,8 +131,8 @@ def _get_days_since_last_commit(self) -> Optional[int]:
return None

# Calculate days since last commit
committed_date = datetime.fromtimestamp(last_commit.committed_date, tz=timezone.utc)
now = datetime.now(timezone.utc)
committed_date = datetime.fromtimestamp(last_commit.committed_date, tz=UTC)
now = datetime.now(UTC)
delta = now - committed_date

return delta.days
Expand Down
10 changes: 5 additions & 5 deletions src/devscope/bench/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def fit_global(rows: list[ReplayRow], corpus_shas: dict[str, str]) -> dict[str,
matrix = [_vector(row, stats) for row in training]
labels = [1.0 if row.bug_lines > 0 else 0.0 for row in training]
weights, intercept = _logistic_fit(matrix, labels)
raw = [intercept + sum(weight * value for weight, value in zip(weights, vector)) for vector in matrix]
raw = [intercept + sum(weight * value for weight, value in zip(weights, vector, strict=False)) for vector in matrix]
platt_slope, platt_intercept = _platt_fit(raw, labels)
return {
"fitted": True,
"intercept": intercept,
"weights": dict(zip(FEATURES, weights)),
"weights": dict(zip(FEATURES, weights, strict=False)),
"standardization": stats,
"platt": {"slope": platt_slope, "intercept": platt_intercept},
"corpus_shas": dict(sorted(corpus_shas.items())),
Expand Down Expand Up @@ -94,8 +94,8 @@ def _logistic_fit(matrix: list[list[float]], labels: list[float]) -> tuple[list[
gradients = [0.0] * len(weights)
intercept_gradient = 0.0
rate = 0.08 / math.sqrt(1.0 + iteration / 50)
for vector, label in zip(matrix, labels):
prediction = _sigmoid(intercept + sum(a * b for a, b in zip(weights, vector)))
for vector, label in zip(matrix, labels, strict=False):
prediction = _sigmoid(intercept + sum(a * b for a, b in zip(weights, vector, strict=False)))
weight = positive_weight if label else 1.0
error = (prediction - label) * weight
intercept_gradient += error
Expand All @@ -114,7 +114,7 @@ def _platt_fit(raw: list[float], labels: list[float]) -> tuple[float, float]:
slope_gradient = 0.0
intercept_gradient = 0.0
rate = 0.05 / math.sqrt(1.0 + iteration / 50)
for score, label in zip(raw, labels):
for score, label in zip(raw, labels, strict=False):
error = _sigmoid(slope * score + intercept) - label
slope_gradient += error * score
intercept_gradient += error
Expand Down
9 changes: 4 additions & 5 deletions src/devscope/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import Optional

logger = logging.getLogger(__name__)

Expand All @@ -17,7 +16,7 @@ class CacheEntry:
size_bytes: int
mtime: float
lines: int
language: Optional[str]
language: str | None

def is_valid(self, actual_size: int, actual_mtime: float) -> bool:
"""Check if cache entry is still valid for the file."""
Expand Down Expand Up @@ -108,7 +107,7 @@ def _save_cache(self) -> None:
except OSError as e:
logger.warning(f"Failed to save cache: {e}")

def get(self, file_path: Path) -> Optional[CacheEntry]:
def get(self, file_path: Path) -> CacheEntry | None:
"""Get cached entry for a file if valid.

Args:
Expand Down Expand Up @@ -141,7 +140,7 @@ def get(self, file_path: Path) -> Optional[CacheEntry]:
self.stats.misses += 1
return None

def set(self, file_path: Path, lines: int, language: Optional[str]) -> None:
def set(self, file_path: Path, lines: int, language: str | None) -> None:
"""Store analysis results in cache.

Args:
Expand Down Expand Up @@ -184,7 +183,7 @@ def save(self) -> None:
"""Persist cache to disk."""
self._save_cache()

def get_cache_dir(self, repo_root: Optional[Path] = None) -> Path:
def get_cache_dir(self, repo_root: Path | None = None) -> Path:
"""Get appropriate cache directory.

Args:
Expand Down
Loading
Loading