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).
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
"""Append one subagent_run row per agent after the fan-out completes.
|
||||
|
||||
The orchestrator calls this once after all subagents return. It scans
|
||||
<output-dir>/findings-<agent>.json for each agent listed in the
|
||||
--usage-json payload, counts findings, and writes a subagent_run row to
|
||||
runs.jsonl using token / duration metadata supplied by the orchestrator.
|
||||
|
||||
Usage:
|
||||
|
||||
python scripts/log-run.py \\
|
||||
--output-dir <OUTPUT> --run-id <hex> --repo <path> --mode <local|ref> \\
|
||||
--usage-json - <<JSON
|
||||
{
|
||||
"walkthrough-reviewer": {"model":"sonnet","input_tokens":1234,"output_tokens":567,"duration_ms":4500},
|
||||
"security-triage-reviewer":{"model":"sonnet","input_tokens":2345,"output_tokens":678,"duration_ms":5200}
|
||||
}
|
||||
JSON
|
||||
|
||||
`--log-path` defaults to ~/.claude/cache/audit-code/runs.jsonl.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from scripts.telemetry import append_subagent_run
|
||||
|
||||
_DEFAULT_LOG = Path.home() / ".claude/cache/audit-code/runs.jsonl"
|
||||
|
||||
|
||||
def _count_findings(path: Path) -> int:
|
||||
if not path.exists():
|
||||
return 0
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except json.JSONDecodeError:
|
||||
return 0
|
||||
if isinstance(data, dict):
|
||||
findings = data.get("findings")
|
||||
if isinstance(findings, list):
|
||||
return len(findings)
|
||||
elif isinstance(data, list):
|
||||
return len(data)
|
||||
return 0
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
p = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
p.add_argument("--output-dir", required=True, type=Path)
|
||||
p.add_argument("--run-id", required=True)
|
||||
p.add_argument("--repo", required=True)
|
||||
p.add_argument("--mode", required=True, choices=["local", "ref"])
|
||||
p.add_argument("--log-path", type=Path, default=_DEFAULT_LOG)
|
||||
p.add_argument("--usage-json", required=True,
|
||||
help="Path to JSON file, or '-' for stdin.")
|
||||
args = p.parse_args(argv)
|
||||
|
||||
raw = sys.stdin.read() if args.usage_json == "-" else Path(args.usage_json).read_text(encoding="utf-8")
|
||||
usage = json.loads(raw)
|
||||
if not isinstance(usage, dict):
|
||||
print("usage-json must be a JSON object keyed by agent name", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
for agent, meta in usage.items():
|
||||
if not isinstance(meta, dict):
|
||||
print(f"skipping {agent}: usage entry not an object", file=sys.stderr)
|
||||
continue
|
||||
findings_path = args.output_dir / f"findings-{agent}.json"
|
||||
append_subagent_run(
|
||||
args.log_path,
|
||||
run_id=args.run_id, repo=args.repo, mode=args.mode, agent=agent,
|
||||
model=str(meta.get("model", "?")),
|
||||
input_tokens=int(meta.get("input_tokens", 0)),
|
||||
output_tokens=int(meta.get("output_tokens", 0)),
|
||||
duration_ms=int(meta.get("duration_ms", 0)),
|
||||
finding_count=_count_findings(findings_path),
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
Reference in New Issue
Block a user