Detect changes and produce risk-scored review guidance. [REVIEW] Primary tool for code review. Maps git diffs to affected functions, flows, communities, and test coverage gaps. Returns priority-ordered review guidance with risk scores. Args: base: Git ref to diff against
(
base: str = "HEAD~1",
changed_files: list[str] | None = None,
include_source: bool = False,
max_depth: int = 2,
repo_root: str | None = None,
detail_level: str = "standard",
)
| 354 | |
| 355 | |
| 356 | def detect_changes_func( |
| 357 | base: str = "HEAD~1", |
| 358 | changed_files: list[str] | None = None, |
| 359 | include_source: bool = False, |
| 360 | max_depth: int = 2, |
| 361 | repo_root: str | None = None, |
| 362 | detail_level: str = "standard", |
| 363 | ) -> dict[str, Any]: |
| 364 | """Detect changes and produce risk-scored review guidance. |
| 365 | |
| 366 | [REVIEW] Primary tool for code review. Maps git diffs to affected |
| 367 | functions, flows, communities, and test coverage gaps. Returns |
| 368 | priority-ordered review guidance with risk scores. |
| 369 | |
| 370 | Args: |
| 371 | base: Git ref to diff against (default: HEAD~1). |
| 372 | changed_files: Explicit list of changed file paths (relative to repo |
| 373 | root). Auto-detected from git diff if omitted. |
| 374 | include_source: If True, include source code snippets for changed |
| 375 | functions. Default: False. |
| 376 | max_depth: Impact radius depth for BFS traversal. Default: 2. |
| 377 | repo_root: Repository root path. Auto-detected if omitted. |
| 378 | detail_level: Output detail level. "standard" returns full analysis; |
| 379 | "minimal" returns only summary, risk_score, changed_file_count, |
| 380 | test_gap_count, and top 3 review priorities (text only). |
| 381 | Default: "standard". |
| 382 | |
| 383 | Returns: |
| 384 | Risk-scored analysis with changed functions, affected flows, |
| 385 | test gaps, and review priorities. |
| 386 | """ |
| 387 | store, root = _get_store(repo_root) |
| 388 | try: |
| 389 | # Detect changed files if not provided. |
| 390 | if changed_files is None: |
| 391 | changed_files = get_changed_files(root, base) |
| 392 | if not changed_files: |
| 393 | changed_files = get_staged_and_unstaged(root) |
| 394 | |
| 395 | if not changed_files: |
| 396 | return { |
| 397 | "status": "ok", |
| 398 | "summary": "No changed files detected.", |
| 399 | "risk_score": 0.0, |
| 400 | "changed_functions": [], |
| 401 | "affected_flows": [], |
| 402 | "test_gaps": [], |
| 403 | "review_priorities": [], |
| 404 | } |
| 405 | |
| 406 | original_tokens = estimate_file_tokens(root, changed_files) |
| 407 | |
| 408 | # Convert to absolute paths for graph lookup. |
| 409 | abs_files = [str(root / f) for f in changed_files] |
| 410 | |
| 411 | # Parse diff ranges for line-level mapping. |
| 412 | diff_ranges = parse_diff_ranges(str(root), base) |
| 413 | # Remap to absolute paths so they match graph file_paths. |