Skip to content

feat: add AIDLC Code Reviewer tool#282

Open
ayushtr-aws wants to merge 2 commits into
mainfrom
feat/aidlc-codereview
Open

feat: add AIDLC Code Reviewer tool#282
ayushtr-aws wants to merge 2 commits into
mainfrom
feat/aidlc-codereview

Conversation

@ayushtr-aws
Copy link
Copy Markdown

Summary

Adds the AIDLC Code Reviewer — an automated, language-agnostic code quality analysis CLI tool that combines static analysis tools with AI-powered critical code analysis and business logic review. It produces structured HTML (for human review) and Markdown reports (for LLM review), designed to review code assets generated through the AI-DLC.

Changes

Introduces the scripts/aidlc-codereview/ package (41 files, ~9,000 lines) containing:

  • CLI entry point (runner.py) — orchestrates tool execution, AI analysis, and report generation
  • Agent layer (agent/) — Amazon Bedrock-powered agents for:
  • Critical code findings (COMPUTATION, CONTROL_FLOW, DATA_TRANSFORM)
  • Code structure critique (logging, scalability, efficiency, complexity, measurability, structure)
  • Business logic review (business rules, formulas, pricing logic, state machines, etc.)
  • Auto-generation of tool wrappers for unknown tools (with two-level verification)
  • Common layer (common/) — shared models, severity mapping, language detection, report generation (HTML + Markdown), CLI utilities
  • Tools layer (tools/) — dynamic tool registry with disk-based wrapper discovery
  • Configuration — review-config.yaml (tool list), agent-config.yaml (Bedrock model settings), system prompts for each agent
  • Documentation — README, SETUP guide (AWS credential configuration, troubleshooting), CHANGELOG, severity mapping policy

Key design decisions:

  • HIGH/CRITICAL severity reserved exclusively for security findings; non-security categories cap at MEDIUM
  • Tool wrappers are auto-generated via LLM on first run and cached for reuse
  • Reports split into technical (static tools + AI critique) and business logic (domain review) tracks
  • Supports Python, Java, and C# toolchains out of the box

User experience

Before: No automated code review tooling existed in the AIDLC workflow. Developers had to manually run individual static analysis tools, interpret raw output, and perform business logic review entirely by hand.

After: Developers run a single command to get a comprehensive code review:

# Install
pip install -e scripts/aidlc-codereview

# Run a full review
aidlc-code-reviewer ./src

# Output
Activating AIDLC Code Reviewer...
  Tools run: 5, Skipped: 2, Findings: 47
  Critical sections: 3
  Business logic findings: 12, Consistency issues: 2

  Reports:
    → Start here:          reports/code_review_summary_20260421_143000.html
    Technical (Markdown):  reports/code_review_technical_20260421_143000.md
    Business Logic (HTML): reports/code_review_business_20260421_143000.html

The summary HTML serves as the entry point, linking to detailed technical and business logic reports. Users can also run --technical-report or --business-report independently, use --preflight to verify AWS setup, or --no-generate to skip LLM-based wrapper generation.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

  • I have reviewed the contributing guidelines
  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented

Test Plan

Reviewers should verify:

  1. Installation — pip install -e scripts/aidlc-codereview completes without errors on Python 3.11+
  2. Pre-flight check — aidlc-code-reviewer --preflight validates AWS credentials and Bedrock model access (requires bedrock:InvokeModel permission)
  3. Technical report — aidlc-code-reviewer ./scripts/aidlc-codereview/src --technical-report runs built-in tools (bandit, ruff, mypy, radon, vulture) and produces HTML + Markdown output in ./reports/
  4. Business logic report — aidlc-code-reviewer ./scripts/aidlc-codereview/src --business-report produces the AI-driven domain review
  5. Auto-generation — Add an uncommented tool (e.g., pylint) to review-config.yaml and confirm the agent generates a wrapper in src/code_reviewer/tools/
  6. Severity policy — Confirm that non-security tools (ruff, mypy, radon) never produce HIGH/CRITICAL findings in the report
  7. No-generate mode — --no-generate skips tools without built-in wrappers gracefully
  8. Markdown lint — npx markdownlint-cli2 "scripts/aidlc-codereview/**/*.md" passes
  9. Report structure — Summary HTML links correctly to both detailed reports; all timestamps match

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

@ayushtr-aws ayushtr-aws requested a review from a team as a code owner May 18, 2026 21:53
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 18, 2026
Copy link
Copy Markdown

@github-advanced-security github-advanced-security AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep OSS found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new scripts/aidlc-codereview Python package that provides an AIDLC code-review CLI combining static-analysis tool execution, Bedrock-backed AI review agents, wrapper generation, and HTML/Markdown reporting.

Changes:

  • Introduces CLI orchestration, configuration loading, language detection, tool registry, report generation, and shared models/utilities.
  • Adds AI agent flows for wrapper generation, critical findings, structure critique, business logic review, and preflight validation.
  • Adds package metadata, lockfile, prompts, default configs, setup docs, license, notice, and changelog.

Reviewed changes

Copilot reviewed 40 out of 41 changed files in this pull request and generated 31 comments.

Show a summary per file
File Description
scripts/aidlc-codereview/.gitignore Ignores generated reports, Python artifacts, and generated wrappers.
scripts/aidlc-codereview/CHANGELOG.md Documents the initial 0.2.0 package changes.
scripts/aidlc-codereview/LICENSE Adds MIT-0 license text.
scripts/aidlc-codereview/NOTICE Adds package notice and third-party attribution summary.
scripts/aidlc-codereview/README.md Documents quick start, reports, usage, config, and project structure.
scripts/aidlc-codereview/config/agent-config.yaml Defines default Bedrock/AWS and wrapper-generation settings.
scripts/aidlc-codereview/config/review-config.yaml Defines default static-analysis tools.
scripts/aidlc-codereview/config/prompts/business-logic-review.md Adds prompt template for business logic review.
scripts/aidlc-codereview/config/prompts/critical-findings-v1.md Adds prompt template for critical code findings.
scripts/aidlc-codereview/config/prompts/structure-critique-v1.md Adds prompt template for structure critique.
scripts/aidlc-codereview/config/prompts/wrapper-generator-v1.md Adds prompt template for generated tool wrappers.
scripts/aidlc-codereview/docs/SETUP.md Adds detailed setup, AWS, CLI, generation, and troubleshooting docs.
scripts/aidlc-codereview/pyproject.toml Defines package metadata, dependencies, entry point, build, pytest, coverage, and mypy config.
scripts/aidlc-codereview/uv.lock Adds reproducible dependency lockfile.
scripts/aidlc-codereview/src/code_reviewer/__init__.py Defines package-level project/config path constants.
scripts/aidlc-codereview/src/code_reviewer/runner.py Implements CLI parsing, tool execution, AI analysis, report writing, and summary output.
scripts/aidlc-codereview/src/code_reviewer/agent/__init__.py Adds agent package marker.
scripts/aidlc-codereview/src/code_reviewer/agent/base_agent.py Adds shared Strands/Bedrock agent wrapper and retrying invocation.
scripts/aidlc-codereview/src/code_reviewer/agent/business_logic_agent.py Adds business logic prompt construction, model invocation, and response parsing.
scripts/aidlc-codereview/src/code_reviewer/agent/code_structure_agent.py Adds structure critique prompt construction, model invocation, and response parsing.
scripts/aidlc-codereview/src/code_reviewer/agent/config.py Loads agent configuration from YAML and environment variables.
scripts/aidlc-codereview/src/code_reviewer/agent/critical_findings_agent.py Collects source files and runs/parses critical findings analysis.
scripts/aidlc-codereview/src/code_reviewer/agent/models.py Defines wrapper generation and verification result models.
scripts/aidlc-codereview/src/code_reviewer/agent/preflight.py Adds dependency, AWS credential, Bedrock, and tool preflight checks.
scripts/aidlc-codereview/src/code_reviewer/agent/prompt_builder.py Assembles wrapper-generation prompts from templates and source context.
scripts/aidlc-codereview/src/code_reviewer/agent/response_parser.py Extracts Python code blocks from LLM responses.
scripts/aidlc-codereview/src/code_reviewer/agent/retry.py Classifies retryable and non-retryable Bedrock errors.
scripts/aidlc-codereview/src/code_reviewer/agent/verification.py Verifies generated wrappers statically and with live tool execution.
scripts/aidlc-codereview/src/code_reviewer/agent/wrapper_generator.py Generates, verifies, writes, imports, and registers tool wrappers.
scripts/aidlc-codereview/src/code_reviewer/common/__init__.py Adds common package marker.
scripts/aidlc-codereview/src/code_reviewer/common/cli.py Exposes the installed CLI entry point.
scripts/aidlc-codereview/src/code_reviewer/common/config.py Loads and validates review tool configuration.
scripts/aidlc-codereview/src/code_reviewer/common/language_detector.py Detects programming languages from file extensions.
scripts/aidlc-codereview/src/code_reviewer/common/models.py Defines findings, results, critique, and business review data models.
scripts/aidlc-codereview/src/code_reviewer/common/output.py Adds verbose output helpers.
scripts/aidlc-codereview/src/code_reviewer/common/report.py Generates technical, business, and summary reports in Markdown/HTML.
scripts/aidlc-codereview/src/code_reviewer/common/SEVERITY_MAPPING.md Documents severity mapping policy.
scripts/aidlc-codereview/src/code_reviewer/common/spinner.py Adds terminal spinner for long-running operations.
scripts/aidlc-codereview/src/code_reviewer/common/utils.py Adds subprocess/tool availability helpers.
scripts/aidlc-codereview/src/code_reviewer/tools/__init__.py Adds tool wrapper package marker.
scripts/aidlc-codereview/src/code_reviewer/tools/registry.py Adds dynamic tool wrapper discovery and registry lookup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/code_reviewer"]
Comment on lines +15 to +19
_EXAMPLE_WRAPPERS = {
"bandit (JSON)": _SRC_ROOT / "tools" / "bandit.py",
"checkstyle (XML)": _SRC_ROOT / "tools" / "checkstyle.py",
"vulture (text)": _SRC_ROOT / "tools" / "vulture.py",
}
Comment on lines +27 to +32
def _write_and_register(tool_name: str, source: str) -> Path:
"""Write wrapper source to tools/<name>.py and register it."""
# Sanitize name for filename
safe_name = tool_name.replace("-", "_").replace(" ", "_")
wrapper_path = _TOOLS_DIR / f"{safe_name}.py"
wrapper_path.write_text(source)
Comment on lines +27 to +30
def _try_load_from_disk(tool_name: str) -> ModuleType | None:
"""Try to load a wrapper from tools/<name>.py."""
safe_name = tool_name.replace("-", "_").replace(" ", "_")
wrapper_path = _TOOLS_DIR / f"{safe_name}.py"
Comment on lines +27 to +32
def _write_and_register(tool_name: str, source: str) -> Path:
"""Write wrapper source to tools/<name>.py and register it."""
# Sanitize name for filename
safe_name = tool_name.replace("-", "_").replace(" ", "_")
wrapper_path = _TOOLS_DIR / f"{safe_name}.py"
wrapper_path.write_text(source)
Comment on lines +22 to +27
with tempfile.NamedTemporaryFile(
mode="w", suffix=".py", prefix=f"{module_name}_", delete=False
) as f:
f.write(source)
f.flush()
tmp_path = f.name
Comment on lines +209 to +215
if (tool_path == file_path
or tool_path.endswith("/" + file_path)
or file_path.endswith("/" + tool_path)
or Path(tool_path).name == Path(file_path).name):
for f in tool_findings:
if start <= f.line <= end and f.severity not in _LOW_INFO_SEV:
matched.append(f)
Comment on lines +73 to +85
def _find_tool_findings_for_range(
file_path: str,
start: int,
end: int,
findings_by_file: dict[str, list[Finding]],
) -> list[Finding]:
"""Match tool findings by file path (handles absolute vs relative mismatch)."""
matched: list[Finding] = []
for tool_path, tool_findings in findings_by_file.items():
if (tool_path == file_path
or tool_path.endswith("/" + file_path)
or file_path.endswith("/" + tool_path)
or Path(tool_path).name == Path(file_path).name):
Comment on lines +316 to +323
biz_files = {
(Path(blf.file).name, blf.start_line)
for blf in business_logic_review.findings
}
tech_critical_findings = [
cf for cf in critical_findings
if (Path(cf.file).name, cf.start_line) not in biz_files
]
Comment on lines +153 to +182
# Level 2 verification (if tool is installed and target provided)
if target is not None:
v2, live_tool_result = verify_level2(source, tool_config.command, target)
if v2.passed:
logger.info("Level 2 (live) verification passed for %s", tool_name)
vprint(f" Level 2 (live) verification passed for '{tool_name}'", flush=True)
break # Both levels passed
else:
last_errors = v2.errors
last_error_level = 2
if attempt < max_retries:
logger.warning(
"Attempt %d: Level 2 verification failed (%s), retrying",
attempt + 1,
"; ".join(v2.errors),
)
continue
# Final attempt failed Level 2 — report failure
print(
f" Level 2 verification failed for '{tool_name}' "
f"after {max_retries + 1} attempts: {'; '.join(v2.errors)}",
flush=True,
)
return GenerationResult(
status=GenerationStatus.VERIFICATION_FAILED,
tool_name=tool_name,
verification=v2,
error=f"Level 2 verification failed: {'; '.join(v2.errors)}",
token_usage=token_usage,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants