Team Ai
Apppublic

Dave-13/DevSecOps

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
main.py66 linesDownload Raw Back to root
1#!/usr/bin/env python32"""3Autonomous Debugging + Secure Patch Agent — CLI entrypoint4Usage:5  python main.py6  python main.py --code examples/buggy_app.py --logs examples/sample.log7"""8import argparse9import json10import sys11import os12 13# ── load example assets ────────────────────────────────────────────────────14EXAMPLE_CODE = open(os.path.join(os.path.dirname(__file__), "examples/buggy_app.py")).read()15EXAMPLE_TEST = open(os.path.join(os.path.dirname(__file__), "examples/test_buggy_app.py")).read()16EXAMPLE_LOGS = """\17Traceback (most recent call last):18  File "buggy_app.py", line 22, in calculate_ratio19    return a / b20ZeroDivisionError: division by zero21CRITICAL sql_query="SELECT * FROM users WHERE username = '' OR 1=1 --'"22WARNING eval called with external input23"""24 25def main():26    parser = argparse.ArgumentParser(description="DevSecOps AI Patch Agent")27    parser.add_argument("--code", help="Path to buggy Python file")28    parser.add_argument("--logs", help="Path to log file")29    parser.add_argument("--tests", help="Path to pytest test file")30    args = parser.parse_args()31 32    code = open(args.code).read() if args.code else EXAMPLE_CODE33    logs = open(args.logs).read() if args.logs else EXAMPLE_LOGS34    test_code = open(args.tests).read() if args.tests else EXAMPLE_TEST35 36    if not os.environ.get("ANTHROPIC_API_KEY"):37        print("ERROR: ANTHROPIC_API_KEY environment variable not set.", file=sys.stderr)38        sys.exit(1)39 40    print("\n" + "═" * 60)41    print("  DevSecOps AI — Autonomous Debugging + Patch Agent")42    print("═" * 60 + "\n")43 44    from core.orchestrator import run45    report = run(code, logs, test_code)46 47    print("\n" + "═" * 60)48    print("  FINAL REPORT")49    print("═" * 60)50    print(json.dumps(report, indent=2))51 52    if report["status"] == "success":53        print("\n✅  Patch applied successfully.")54        print(f"    Tests passed : {report['tests_passed']}")55        print(f"    Secure       : {report['secure']}")56        print(f"    Retries      : {report['retries']}")57        print(f"    Reward       : {report['reward']}")58    else:59        print("\n❌  Agent could not find a valid patch.")60 61    return 0 if report["status"] == "success" else 162 63 64if __name__ == "__main__":65    sys.exit(main())66