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
4 changes: 2 additions & 2 deletions docs/CLI_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3805,7 +3805,7 @@ devops ai review path [OPTIONS] <targets>
| `--no-cache` | `boolean` | - | Bypass LLM response cache and force fresh inference. |
| `--force`, `-f` | `boolean` | - | Force fresh review execution without cache. |
| `--append-cache` | `boolean` | - | Append cached response to the LLM prompt as context instead of using it directly as the final response. |
| `--watch`, `-w` | `boolean` | - | Continuously watch target paths for changes and re-run reviews. |
| `--watch`, `-w` | `boolean` | - | Continuously watch target paths for changes and review only the changed files. |
| `--debounce-ms` | `integer` | `500` | Debounce window in milliseconds for filesystem watcher. |
| `--concurrency`, `-c` | `integer` | - | Max concurrent workers for parallel review. Through the gateway it is capped at the gateway's backend slots. |
| `--parallel` / `--no-parallel` | `boolean` | `True` | Execute multi-file review stages concurrently using async worker pool. |
Expand Down Expand Up @@ -5556,7 +5556,7 @@ devops review path [OPTIONS] <targets>
| `--no-cache` | `boolean` | - | Bypass LLM response cache and force fresh inference. |
| `--force`, `-f` | `boolean` | - | Force fresh review execution without cache. |
| `--append-cache` | `boolean` | - | Append cached response to the LLM prompt as context instead of using it directly as the final response. |
| `--watch`, `-w` | `boolean` | - | Continuously watch target paths for changes and re-run reviews. |
| `--watch`, `-w` | `boolean` | - | Continuously watch target paths for changes and review only the changed files. |
| `--debounce-ms` | `integer` | `500` | Debounce window in milliseconds for filesystem watcher. |
| `--concurrency`, `-c` | `integer` | - | Max concurrent workers for parallel review. Through the gateway it is capped at the gateway's backend slots. |
| `--parallel` / `--no-parallel` | `boolean` | `True` | Execute multi-file review stages concurrently using async worker pool. |
Expand Down
2 changes: 1 addition & 1 deletion docs/MCP_TOOLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,7 @@ Review source files directly (no git required).
| `no_cache` | `boolean` | No | `False` | Bypass LLM response cache and force fresh inference. |
| `force` | `boolean` | No | `False` | Force fresh review execution without cache. |
| `append_cache` | `boolean` | No | `False` | Append cached response to the LLM prompt as context instead of using it directly as the final response. |
| `watch` | `boolean` | No | `False` | Continuously watch target paths for changes and re-run reviews. |
| `watch` | `boolean` | No | `False` | Continuously watch target paths for changes and review only the changed files. |
| `debounce_ms` | `integer` | No | `500` | Debounce window in milliseconds for filesystem watcher. |
| `concurrency` | `integer` | No | - | Max concurrent workers for parallel review. Through the gateway it is capped at the gateway's backend slots. |
| `parallel` | `boolean` | No | `True` | Execute multi-file review stages concurrently using async worker pool. |
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ devops ai review path [OPTIONS] <targets>
| `--no-cache` | `boolean` | - | Bypass LLM response cache and force fresh inference. |
| `--force`, `-f` | `boolean` | - | Force fresh review execution without cache. |
| `--append-cache` | `boolean` | - | Append cached response to the LLM prompt as context instead of using it directly as the final response. |
| `--watch`, `-w` | `boolean` | - | Continuously watch target paths for changes and re-run reviews. |
| `--watch`, `-w` | `boolean` | - | Continuously watch target paths for changes and review only the changed files. |
| `--debounce-ms` | `integer` | `500` | Debounce window in milliseconds for filesystem watcher. |
| `--concurrency`, `-c` | `integer` | - | Max concurrent workers for parallel review. Through the gateway it is capped at the gateway's backend slots. |
| `--parallel` / `--no-parallel` | `boolean` | `True` | Execute multi-file review stages concurrently using async worker pool. |
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/review.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ devops review path [OPTIONS] <targets>
| `--no-cache` | `boolean` | - | Bypass LLM response cache and force fresh inference. |
| `--force`, `-f` | `boolean` | - | Force fresh review execution without cache. |
| `--append-cache` | `boolean` | - | Append cached response to the LLM prompt as context instead of using it directly as the final response. |
| `--watch`, `-w` | `boolean` | - | Continuously watch target paths for changes and re-run reviews. |
| `--watch`, `-w` | `boolean` | - | Continuously watch target paths for changes and review only the changed files. |
| `--debounce-ms` | `integer` | `500` | Debounce window in milliseconds for filesystem watcher. |
| `--concurrency`, `-c` | `integer` | - | Max concurrent workers for parallel review. Through the gateway it is capped at the gateway's backend slots. |
| `--parallel` / `--no-parallel` | `boolean` | `True` | Execute multi-file review stages concurrently using async worker pool. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Design

## Context

`devops review path --watch` continuously monitors target paths for changes.
The watcher detects changed paths and passes them to `_on_change(changed)`.
Previously, `_on_change` ignored the changed paths and executed a full review over all target directories.

## Goals / Non-Goals

**Goals:**

- Filter watched file changes to existing, reviewable files that reside under target paths and match patterns.
- Review only the filtered changed files in a single review session.
- Skip deleted files without raising an error.
- Print one informational line and run no review session when no reviewable files changed.
- Keep all other review settings (stage flags, personas, concurrency, clients) identical to the main target configuration.

**Non-Goals:**

- Modifying `review branch` or `review pr`, which do not provide `--watch`.
- Running an initial full review before the first change event.

## Decisions

- **Filter changed paths against targets and review criteria in `_prepare_watch_content`.**
A helper function resolves each changed path, checks existence, confirms containment under one of `path_targets`, applies `--pattern` glob matching, checks git ignore rules, and filters secret-scan-only files.
- **Deduplicate and sort reviewable files.**
Sorting files ensures deterministic page order for testing and reporting.
- **Print one line and skip review when no reviewable files change.**
When `changed` contains only deleted files, ignored files, or non-matching patterns, the command prints `MESSAGES.review.no_reviewable_files_changed` and returns to watching.
- **Pass filtered pages to `_execute_current_review`.**
`_execute_current_review` accepts an optional `pages` list. When provided, it preserves `target_dir`, `target_ref`, and review settings while substituting the specific file pages.

## Risks / Trade-offs

- [A changed file imports symbols from an unchanged file] → The unchanged file is not re-reviewed, matching single-file path review behavior. Linked file lookups and repository RAG remain available.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Proposal

## Why

Issue #1067: `devops review path --watch` reviews every target again whenever any watched file changes.
When a person saves one file in a watched directory, the command runs a full review of all files under the targets.
With the reply cache on, pre-analysis, static analysis, and verification still process all files and write a new session for all files.
With cache disabled or forced, every page calls the model again.

## What Changes

- On a change, `devops review path --watch` reviews only the changed files that still exist, lie under one of the targets, and pass `--pattern` and reviewable-file filters.
- A deleted file is skipped. A change with no reviewable file prints one line and runs no review.
- The command applies the same stage flags, personas, concurrency, and clients to the changed files.
- `HELP.options.watch` states that each change reviews only the changed files.
- A unit test verifies that `review path --watch` passes only changed files to the review workflow and runs no review when only a deleted file changes.

## Capabilities

### New Capabilities

- `review-path-watch`: path review watch mode filters change events to review only existing reviewable files under target paths.

### Modified Capabilities

None.

## Impact

- Code: `src/devops_cli/commands/review.py`, `src/devops_cli/ai/review/runner.py`, `src/devops_cli/lang/en/help.py`, `src/devops_cli/lang/en/messages.py`.
- Tests: `tests/test_review.py`.
- Documentation: `docs/CLI_REFERENCE.md`, `docs/MCP_TOOLS.md`, `docs/commands/ai.md`, `docs/commands/review.md`, regenerated via `devops docs generate --sync-readme`.

## Feasibility

- `DebouncedFileWatcher` in `src/devops_cli/watchers/file_watcher.py` already delivers the modified `list[Path]` to `on_change`.
- In `src/devops_cli/commands/review.py`, `_on_change(changed)` ignored `changed` and called `_execute_current_review()`, which reviewed all targets.
- Target boundaries, relative paths, pattern matching, git-ignore rules, and `is_secret_scan_only` exist in `src/devops_cli/ai/review/runner.py` and `src/devops_cli/review/targets.py`.
- Passing changed files through review filtering satisfies the acceptance criteria without external dependencies or breaking changes.

## Existing Tool Considered

`DebouncedFileWatcher` is the repository's file watching abstraction based on `os.walk` and file modification timestamps. No new file watching tool is needed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Spec Delta

## Purpose

`devops review path --watch` monitors target paths and reviews only the files that changed on each change event.

## ADDED Requirements

### Requirement: Path review watch mode reviews only changed files
When `devops review path` runs with `--watch`, each filesystem change SHALL review only the changed files that exist, lie under one of the target paths, and pass `--pattern` and reviewable-file filters. A change with no reviewable files SHALL print one line and run no review session.

#### Scenario: Watched directory contains modified reviewable file
- **WHEN** `devops review path` runs with `--watch` on a directory holding multiple files, and one file changes
- **THEN** the review workflow receives pages for only the changed file

#### Scenario: Watched change contains only non-reviewable or deleted files
- **WHEN** `devops review path` runs with `--watch` and a change event contains only deleted files or files that pass no reviewable filters
- **THEN** no review workflow runs and the command prints that no reviewable files changed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Tasks

## 1. Failing tests first

- [x] 1.1 Write `test_review_path_watch_reviews_only_changed_files` and `test_review_path_watch_skips_deleted_files_and_runs_no_review` in `tests/test_review.py`, and verify failure on current code with `uv run devops ci fail-to-pass --base origin/main`

## 2. Implementation

- [x] 2.1 Update `HELP.options.watch` in `src/devops_cli/lang/en/help.py` and add `no_reviewable_files_changed` in `src/devops_cli/lang/en/messages.py`
- [x] 2.2 Implement `_prepare_watch_content` in `src/devops_cli/ai/review/runner.py` to filter changed paths and construct review pages
- [x] 2.3 Update `path()` in `src/devops_cli/commands/review.py` to use `_prepare_watch_content` in `_on_change` and pass pages to `_execute_current_review`
- [x] 2.4 Verify tests pass locally with `uv run devops ci test tests/test_review.py`

## 3. Documentation and validation

- [x] 3.1 Regenerate CLI documentation with `uv run devops docs generate --sync-readme` and verify with `uv run devops docs check`
- [x] 3.2 Validate OpenSpec artifacts with `uv run devops openspec check`
- [x] 3.3 Run full quality gates with `uv run devops ci`
- [x] 3.4 Archive OpenSpec change with `uv run devops openspec archive 1067-watch-changed-files`
17 changes: 17 additions & 0 deletions openspec/specs/review-path-watch/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# review-path-watch Specification

## Purpose
`devops review path --watch` monitors target paths and reviews only the files that changed on each change event.

## Requirements

### Requirement: Path review watch mode reviews only changed files
When `devops review path` runs with `--watch`, each filesystem change SHALL review only the changed files that exist, lie under one of the target paths, and pass `--pattern` and reviewable-file filters. A change with no reviewable files SHALL print one line and run no review session.

#### Scenario: Watched directory contains modified reviewable file
- **WHEN** `devops review path` runs with `--watch` on a directory holding multiple files, and one file changes
- **THEN** the review workflow receives pages for only the changed file

#### Scenario: Watched change contains only non-reviewable or deleted files
- **WHEN** `devops review path` runs with `--watch` and a change event contains only deleted files or files that pass no reviewable filters
- **THEN** no review workflow runs and the command prints that no reviewable files changed
79 changes: 79 additions & 0 deletions src/devops_cli/ai/review/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,85 @@ def _prepare_path_content(
return pages, title, routed


def _is_watch_candidate_included(
file_path: Path,
target_root: Path,
pattern: str,
) -> bool:
"""Predicate determining if a changed file should be included in a watch review."""
from devops_cli.config.constants import CONST_MAX_FILE_SIZE_BYTES

if not file_path.is_file():
return False
repo_root = _git_repo_root(target_root) or find_repo_root(file_path)
if is_ignored_by_git(repo_root, file_path):
return False
if target_root.is_dir():
try:
rel = file_path.relative_to(target_root)
except ValueError:
return False
if not rel.match(pattern):
return False
try:
if file_path.stat().st_size > CONST_MAX_FILE_SIZE_BYTES:
return False
except OSError:
return False
file_label = _review_label(file_path, target_root, repo_root)
if is_secret_scan_only(file_label):
return False
return True


def _find_matching_watch_target(
file_path: Path,
resolved_targets: Sequence[Path],
pattern: str,
) -> Path | None:
"""Find the target containing file_path that accepts it for review."""
for target in resolved_targets:
if target.is_file() and file_path == target:
if _is_watch_candidate_included(file_path, target, pattern):
return target
elif target.is_dir() and file_path.is_relative_to(target):
if _is_watch_candidate_included(file_path, target, pattern):
return target
return None


def _prepare_watch_content(
changed_paths: Sequence[Path],
path_targets: Sequence[Path],
pattern: str,
*,
working_directory: Path,
) -> list[str]:
"""Prepare paginated pages for changed files in a watch session."""
resolved_targets = [(working_directory / t).resolve() for t in path_targets]
included_files: list[tuple[Path, Path]] = []
seen: set[Path] = set()

for raw in changed_paths:
try:
resolved = raw.resolve()
except OSError:
continue
if resolved in seen:
continue
target = _find_matching_watch_target(resolved, resolved_targets, pattern)
if target is not None:
seen.add(resolved)
included_files.append((resolved, target))

included_files.sort(key=lambda item: item[0])
blocks: list[str] = []
for file_path, target in included_files:
blocks.extend(_file_blocks(target, [file_path]))

return [redact_text(b) for b in blocks]


def _get_current_git_branch(repo_path: Path) -> str:
"""Return active git branch name if HEAD is attached, otherwise empty string."""
proc = _run_subprocess(
Expand Down
Loading
Loading