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
63 changes: 63 additions & 0 deletions docs/config/review_code_paths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Selective Code Review: Include/Exclude Paths

Metis now supports fine-grained control over which files are targeted during a code review. By utilizing `review_code_include_paths` and `review_code_exclude_paths` in your configuration, you can focus the engine on critical business logic while skipping boilerplate, definitions, and tests.

## Overview

These settings allow you to filter files **specifically for the review process** without removing them from the project's broader context. This ensures that Metis stays fast and the results remain relevant.

- **`review_code_include_paths`**: Limits the review to specific directories or files.
- **`review_code_exclude_paths`**: Explicitly skips specific files or patterns during the review phase.

The **`review_code_include_paths`** and **`review_code_exclude_paths`** configurations utilize standard **gitignore-style** pattern matching.

---

## Why use this instead of `.metisignore`?

It is important to distinguish between these configuration options and the global `.metisignore` file:

| Feature | Scope | Impact on Context |
| :--- | :--- | :--- |
| **`.metisignore`** | **Global** | Files are completely invisible. They are not indexed and cannot be used by the model at all (e.g., `.venv`, `dist`, `node_modules`). |
| **Review Paths** | **Command-Specific** | Files are skipped by the `review_code` logic, but **remain available** as "Relevant Context" (via embeddings or tools) to help the AI understand the code it *is* reviewing. |

**The Logic:** You generally don't want Metis to waste time looking for bugs in a `.d.ts` or `interface.ts` file. However, if Metis is reviewing a service that imports those types, it still needs to be able to "see" those files to understand the data structures.

---

## Configuration

Add these options to your `metis.yaml` file under the `metis_engine` block.

### Example Configuration

```yaml
metis_engine:
# Only run reviews within the backend folder
# Where the Core Logic resides
review_code_include_paths:
- 'backend/'

# Skip files that don't require logic analysis
review_code_exclude_paths:
- 'dto/'
- '*.d.ts'
- '*.spec.ts'
- '*.fixture.ts'
- '*.dto.ts'
- '*.interface.ts'
- '*.type.ts'
- '*.schema.ts'
- 'backend/test/'
- 'e2e/'
```
View other examples for focused review at the `examples/focused_review_code` folder.

## Key Benefits

- **Focused Reviews**: Configure Metis to only review Core Logic, suchs as specific apps inside your big monorepo.
- **Significant Speed Increase**: Metis avoids reviewing definition files and tests.
- **Noise Reduction**: Prevents "false positive" issues or irrelevant suggestions on generated code, type interfaces, or DTOs where logic-based review is unnecessary.
- **Preserved Context**: Unlike a global ignore, the AI still has access to these files to provide better context for the logic it is actually reviewing.
29 changes: 29 additions & 0 deletions examples/focused_review_code/metis_typescript_example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
metis_engine:

# Only review code inside the "backend" folder
review_code_include_paths:
- 'backend/'

# Don't review dtos, schemas, tests...
review_code_exclude_paths:
- 'dto/'
- '*.d.ts'
- '*.spec.ts'
- '*.fixture.ts'
- '*.dto.ts'
- '*.const.ts'
- '*.interface.ts'
- '*.model.ts'
- '*.type.ts'
- '*.request.ts'
- '*.response.ts'
- '*.response.api.ts'
- '*.params.ts'
- '*.schema.ts'
- '*.mapper.ts'
- '*.store.ts'
- 'e2e_ssr/'
- 'e2e/'
- '*.e2e-spec.ts'
- 'backend/test'
- 'schema.ts'
6 changes: 6 additions & 0 deletions src/metis/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ def load_runtime_config(config_path=None, enable_psql=False):
},
)
runtime["metisignore_file"] = engine_cfg.get("metisignore_file", None)
runtime["review_code_include_paths"] = engine_cfg.get(
"review_code_include_paths", []
)
runtime["review_code_exclude_paths"] = engine_cfg.get(
"review_code_exclude_paths", []
)

# Query config
query_cfg = cfg.get("query", {})
Expand Down
38 changes: 28 additions & 10 deletions src/metis/engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,25 @@ def __init__(
self._review_graph = None
self._ask_graph = None
self.metisignore_file = kwargs.get("metisignore_file") or ".metisignore"
self.review_code_include_paths = kwargs.get("review_code_include_paths", [])
self.review_code_exclude_paths = kwargs.get("review_code_exclude_paths", [])

def load_metisignore(self):
def load_metisignore(self) -> pathspec.GitIgnoreSpec | None:
"""
Load metisignore file and return a PathSpec matcher.
Load metisignore file and return a GitIgnoreSpec matcher.
Args:
metisignore: Path to a file that have the ignore regex ( use the .gitignore syntax )
Returns:
pathspec.PathSpec object or None if file doesn't exist
pathspec.GitIgnoreSpec object or None if file doesn't exist
"""
try:
if not self.metisignore_file:
logger.info("No MetisIgnore file provided")
return None
with open(self.metisignore_file, "r") as f:
spec = pathspec.PathSpec.from_lines("gitwildmatch", f)
spec = pathspec.GitIgnoreSpec.from_lines(f)
logger.info(f"MetisIgnore file loaded: {self.metisignore_file}")
return spec
except FileNotFoundError:
Expand Down Expand Up @@ -340,19 +342,35 @@ def review_file(self, file_path):
def get_code_files(self):
"""
Return a list of file names in the self.codebase_path folder.
Evaulate the path with metisignore file if requested
Evaluate the path with metisignore file, include/exclude paths if requested
"""
base_path = os.path.abspath(self.codebase_path)
metisignore_spec = self.load_metisignore()
include_spec = None
if self.review_code_include_paths:
include_spec = pathspec.GitIgnoreSpec.from_lines(
self.review_code_include_paths
)
exclude_spec = None
if self.review_code_exclude_paths:
exclude_spec = pathspec.GitIgnoreSpec.from_lines(
self.review_code_exclude_paths
)
file_list = []
for root, _, files in os.walk(base_path):
for file in files:
full_path = os.path.join(root, file)
ext = os.path.splitext(file)[1].lower()
if ext in self.code_exts and (
not metisignore_spec
or not metisignore_spec.match_file(os.path.join(root, file))
):
file_list.append(os.path.join(root, file))
if ext not in self.code_exts:
continue
rel_path = os.path.relpath(full_path, base_path)
if metisignore_spec and metisignore_spec.match_file(rel_path):
continue
if include_spec and not include_spec.match_file(rel_path):
continue
if exclude_spec and exclude_spec.match_file(rel_path):
continue
file_list.append(full_path)
return file_list

def review_code(self):
Expand Down