scripts.review-tools

Reference › scripts › review-tools

scripts/review-tools.py is the global code review tool: a short script usable from any directory where orchestrata-tools is installed. A human runs it. It uses SourceASTParser and ASTIndex from orchestrata_tools.parser and CodeReviewer and TestReviewer from orchestrata_tools.reviewer. For the project's own test rules see test-review.

It takes one optional argument, a target directory (default the current directory). find_project_root locates the project root, falling back to the target. The script parses the code, prints the class and line counts, and runs CodeReviewer, printing up to 20 issues as severity, rule and message. It then parses the tests directory (or the root if there is none), runs TestReviewer and prints up to 15 issues. It only reads, and writes nothing.

At a glance

Source scripts/review-tools.py
Lines of code 69
Classes 0
Functions 2
Imports (internal) orchestrata_tools.parser, orchestrata_tools.reviewer
Imported by none
Tests that import it none

Class diagram

No classes; see Functions.

Dependency diagram

Dependency diagram scripts.review-tools

API

Functions

Function Signature Summary
find_project_root find_project_root() -> Path | None
main main() -> None

Source

Permalink: https://gitlab.com/MSamy/orchestrata-ultimate-architecture/-/blob/a4cbc2bdf/scripts/review-tools.py

#!/usr/bin/env python3
"""Global code review tool — usable from any directory with orchestrata-tools installed.

Usage:
    review-tools src/           # Run full code review on a directory
    review-tools --test tests/  # Run test purity review
    review-tools --all .        # Run both code + test review
"""

import sys
from pathlib import Path


def find_project_root() -> Path | None:
    current = Path.cwd().resolve()
    for parent in [current, *current.parents]:
        if (parent / "pyproject.toml").exists():
            return parent
    return None


def main() -> None:
    target = sys.argv[1] if len(sys.argv) > 1 else "."
    root = find_project_root()
    if root is None:
        root = Path(target).resolve()

    from orchestrata_tools.parser import ASTIndex, SourceASTParser
    from orchestrata_tools.reviewer import CodeReviewer, TestReviewer

    parser = SourceASTParser()
    codebase = parser.parse_directory(str(root))
    index = ASTIndex(codebase)

    print(
        f"=== CODE REVIEW: {codebase.total_classes} classes, {codebase.total_loc} LOC ===\n"
    )

    reviewer = CodeReviewer(index)
    reports = reviewer.review_codebase()
    issues = [issue for report in reports for issue in report.issues]

    if issues:
        for issue in issues[:20]:
            print(f"[{issue.severity.value}] {issue.rule}: {issue.message}")
        if len(issues) > 20:
            print(f"... and {len(issues) - 20} more issues")
    else:
        print("No issues found.")

    print("\n=== TEST REVIEW ===")
    tests_root = root / "tests" if (root / "tests").exists() else root
    test_codebase = parser.parse_directory(str(tests_root))
    test_index = ASTIndex(test_codebase)
    test_reviewer = TestReviewer(test_index)
    test_reports = test_reviewer.review_codebase()
    test_issues = [issue for report in test_reports for issue in report.issues]

    if test_issues:
        for issue in test_issues[:15]:
            print(f"[{issue.severity.value}] {issue.rule}: {issue.message}")
        if len(test_issues) > 15:
            print(f"... and {len(test_issues) - 15} more issues")
    else:
        print("No test issues found.")


if __name__ == "__main__":
    main()