Files
claude-plugin/plugins/reviews/skills/audit-code/scripts/runner.py
T
mroberts f5934181ec Move the code and terraform audits into the reviews plugin
Copy the standalone code-review and terraform-review skills into
plugins/reviews as audit-code and audit-terraform. The rename separates the
automated, linter-driven audits from the guided review-pr walkthrough that
already lived here.

Resolve bundled script paths through ${SKILL_DIR}, exported in a new step 0.
CLAUDE_PLUGIN_ROOT is not set in the Bash tool environment, so the obvious
substitution would have expanded to nothing and broken every collection
script invocation.

Replace the PLAN and DESIGN docs with READMEs written from the current
SKILL.md and scripts. The old docs had drifted badly: they named semgrep
where the code calls opengrep, scoped five review agents where there are
now eight, and predated Lua, PowerShell, and GitHub Actions support.

Add CONSISTENCY_NORMS to the audit-terraform agent inputs. The collection
script writes consistency_norms.json and the agent prompt declares it, but
SKILL.md never listed it, leaving the variable unsubstituted.

Drop the --ingest-verdicts instruction from both skills. review_stats.py
parses no arguments, so the ref-mode verdict template it told users to feed
back could never be read.

Point audit-terraform's smoke test at README.md and resolve its fixture
paths relative to the test file rather than an absolute home directory.

Tests: 197 passing (audit-code), 106 passing (audit-terraform).
2026-07-21 11:11:05 -05:00

71 lines
2.1 KiB
Python

"""Subprocess wrapper for external linters + parallel dispatch."""
from __future__ import annotations
import concurrent.futures as cf
import os
import shutil
import subprocess
from dataclasses import dataclass
from pathlib import Path
_DEFAULT_TIMEOUT = 180
_SKILL_VENV_BIN = Path(__file__).resolve().parent.parent / ".venv" / "bin"
@dataclass
class ToolResult:
binary: str
ran: bool
exit_code: int = -1
stdout: str = ""
stderr: str = ""
reason: str = ""
def resolve_tool(binary: str) -> str | None:
"""Resolve a tool name to an absolute path, preferring the skill's
`.venv/bin/` over the user's PATH. Returns None if not found anywhere.
"""
local = _SKILL_VENV_BIN / binary
if local.is_file() and os.access(local, os.X_OK):
return str(local)
return shutil.which(binary)
def tool_available(binary: str) -> bool:
return resolve_tool(binary) is not None
def run_tool(args: list[str], cwd: str, timeout: int = _DEFAULT_TIMEOUT) -> ToolResult:
binary = args[0]
resolved = resolve_tool(binary)
if resolved is None:
return ToolResult(binary=binary, ran=False, reason="not on PATH")
try:
result = subprocess.run(
[resolved, *args[1:]], cwd=cwd, capture_output=True, text=True,
check=False, timeout=timeout,
)
except subprocess.TimeoutExpired:
return ToolResult(binary=binary, ran=False, reason=f"timeout after {timeout}s")
return ToolResult(
binary=binary, ran=True,
exit_code=result.returncode,
stdout=result.stdout, stderr=result.stderr,
)
def run_tools_parallel(
jobs: list[tuple[list[str], str]], max_workers: int = 8,
) -> list[ToolResult]:
"""Run a list of (args, cwd) jobs in parallel. Order preserved."""
results: list[ToolResult] = [None] * len(jobs) # type: ignore[list-item]
with cf.ThreadPoolExecutor(max_workers=max_workers) as ex:
futures = {ex.submit(run_tool, a, c): i for i, (a, c) in enumerate(jobs)}
for fut in cf.as_completed(futures):
i = futures[fut]
results[i] = fut.result()
return results