orchestrata_tools.backcompat.code_review
Reference › orchestrata_tools › backcompat › code_review
This module is a command-line wrapper that keeps the old code-review.py interface alive. Nothing imports it, and tests/test_orchestrata_tools_backcompat.py covers it.
main loads the AST file (default plans/ast-ultimate.json), builds an ASTIndex, runs CodeReviewer.review_codebase from code_reviewer, and flattens all issues. --format selects text (a count plus the first 50 issues), json (rule, message, severity and location per issue), or markdown (issues grouped by severity, at most 20 each). Output goes to the --output file or to standard output.
At a glance
| Source | src/orchestrata_tools/backcompat/code_review.py |
| Lines of code | 69 |
| Classes | 0 |
| Functions | 1 |
| Imports (internal) | orchestrata_tools.parser, orchestrata_tools.reviewer |
| Imported by | none |
| Tests that import it | tests/test_orchestrata_tools_backcompat.py |
Class diagram
No classes; see Functions.
Dependency diagram
API
Functions
| Function | Signature | Summary |
|---|---|---|
main |
main(argv: list[str] | None = None) -> int |
Source
#!/usr/bin/env python3
"""Backward-compatible wrapper for code-review.py."""
from __future__ import annotations
import argparse
import json
import sys
from orchestrata_tools.parser import ASTIndex, JSONASTLoader
from orchestrata_tools.reviewer import CodeReviewer
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="Code Quality Review")
parser.add_argument("--ast", default="plans/ast-ultimate.json")
parser.add_argument("--output", "-o")
parser.add_argument(
"--format", choices=["json", "markdown", "text"], default="text"
)
args = parser.parse_args(argv)
ast = JSONASTLoader().load(args.ast)
index = ASTIndex(ast)
reviewer = CodeReviewer(index)
reports = reviewer.review_codebase()
all_issues = [issue for report in reports for issue in report.issues]
if args.format == "json":
output = json.dumps(
[
{
"rule": i.rule,
"message": i.message,
"severity": i.severity.value,
"location": i.location,
}
for i in all_issues
],
indent=2,
)
elif args.format == "markdown":
lines = ["# Code Review Report", ""]
for sev in ["critical", "high", "medium", "low", "info"]:
issues = [i for i in all_issues if i.severity.value == sev]
if issues:
lines.append(f"## {sev.upper()}")
for i in issues[:20]:
lines.append(f"- **{i.rule}** ({i.location}): {i.message}")
lines.append("")
output = "\n".join(lines)
else:
lines = [f"Code Review: {len(all_issues)} issues found", ""]
for i in all_issues[:50]:
lines.append(f"[{i.severity.value}] {i.rule}: {i.message} ({i.location})")
output = "\n".join(lines)
if args.output:
with open(args.output, "w") as f:
f.write(output)
else:
print(output)
return 0
if __name__ == "__main__":
sys.exit(main())