Spaces:
Running
Running
| """CLI entry point for CodeTribunal.""" | |
| import json | |
| import sys | |
| from pathlib import Path | |
| import click | |
| from code_tribunal.config import TribunalConfig | |
| from code_tribunal.evidence import gather_evidence_parallel | |
| from code_tribunal.courtroom import Courtroom | |
| def main(path: str, output: str | None, evidence_only: bool, parallel: bool) -> None: | |
| """Put your code on trial. PATH is the directory or zip to investigate.""" | |
| config = TribunalConfig() | |
| if not config.is_configured: | |
| click.echo("Error: ZAI_API_KEY not set. Configure .env file.") | |
| sys.exit(1) | |
| click.echo("=" * 60) | |
| click.echo(" CODETRIBUNAL — THE AI COURTROOM") | |
| click.echo("=" * 60) | |
| if evidence_only: | |
| from code_tribunal.evidence import gather_evidence | |
| click.echo("\n[Phase 1] Gathering evidence with GritQL...") | |
| if parallel: | |
| report = gather_evidence_parallel(path) | |
| else: | |
| report = gather_evidence(path) | |
| click.echo(report.to_text()) | |
| if output: | |
| Path(output).write_text(json.dumps({ | |
| "findings": [str(f) for f in report.findings], | |
| "stats": { | |
| "files": report.file_count, | |
| "total": len(report.findings), | |
| "by_severity": {s: len(i) for s, i in report.findings_by_severity.items()}, | |
| }, | |
| }, indent=2)) | |
| click.echo(f"\nReport saved to {output}") | |
| return | |
| courtroom = Courtroom(config) | |
| click.echo("\nRunning full pipeline...\n") | |
| for event in courtroom.run(path): | |
| click.echo(f" [{event.phase.value}] {event.status}") | |
| state = courtroom.pipeline.state | |
| if state and state.verdict: | |
| click.echo("\n" + "=" * 60) | |
| click.echo(" VERDICT") | |
| click.echo("=" * 60) | |
| click.echo(state.verdict) | |
| if output and state: | |
| Path(output).write_text(json.dumps({ | |
| "evidence": state.evidence_report, | |
| "investigation": state.investigation_reports, | |
| "transcript": state.trial_transcript, | |
| "verdict": state.verdict, | |
| "report": state.report, | |
| "stats": { | |
| "files_scanned": state.files_scanned, | |
| "total_findings": state.total_findings, | |
| }, | |
| }, indent=2, default=str)) | |
| click.echo(f"\nFull report saved to {output}") | |
| if __name__ == "__main__": | |
| main() | |