Spaces:
Configuration error
Configuration error
Download artifacts/bounty-agent/autonomy_engine.py from Cryptostoner/New.space: direct link, hf CLI and curl.
- Browser
- Download file 14 kB
-
https://huggingface.co/spaces/Cryptostoner/New.space/resolve/main/artifacts/bounty-agent/autonomy_engine.py
- Command line
-
hf download hf://spaces/Cryptostoner/New.space/artifacts/bounty-agent/autonomy_engine.py
-
curl -L -o autonomy_engine.py https://huggingface.co/spaces/Cryptostoner/New.space/resolve/main/artifacts/bounty-agent/autonomy_engine.py
14 kB
| import json | |
| import os | |
| import time | |
| from dataclasses import dataclass, asdict | |
| from pathlib import Path | |
| from typing import Any, Literal | |
| from pydantic import BaseModel, Field | |
| STATE_DIR = Path(os.environ.get("V2_STATE_DIR", "/app/runtime")) | |
| MISSION_DIR = STATE_DIR / "autonomy_missions" | |
| MISSION_DIR.mkdir(parents=True, exist_ok=True) | |
| AutonomyMode = Literal["observe", "prepare", "execute"] | |
| class PlatformCapability: | |
| platform: str | |
| lane: str | |
| revenue_type: str | |
| auth_methods: list[str] | |
| autonomous_actions: list[str] | |
| human_blockers: list[str] | |
| required_env: list[str] | |
| optional_env: list[str] | |
| default_goal: str | |
| risk_level: str = "medium" | |
| PLATFORMS: list[PlatformCapability] = [ | |
| PlatformCapability( | |
| platform="hackerone", | |
| lane="bug_bounty", | |
| revenue_type="vulnerability_report_reward", | |
| auth_methods=["api_key", "stored_browser_session"], | |
| autonomous_actions=["program discovery", "scope review", "report preparation", "api submission when program handle is known"], | |
| human_blockers=["MFA", "CAPTCHA", "program terms acceptance", "account challenge"], | |
| required_env=["HACKERONE_USERNAME", "HACKERONE_API_KEY"], | |
| optional_env=["V2_DEFAULT_PROGRAM_HANDLE"], | |
| default_goal="Find a valid HackerOne program task, run bounty workflow, generate report, and submit when program handle is configured.", | |
| ), | |
| PlatformCapability( | |
| platform="bugcrowd", | |
| lane="bug_bounty", | |
| revenue_type="vulnerability_report_reward", | |
| auth_methods=["api_token", "stored_browser_session"], | |
| autonomous_actions=["program discovery", "scope review", "report preparation", "api submission when program id is known"], | |
| human_blockers=["MFA", "CAPTCHA", "program terms acceptance", "account challenge"], | |
| required_env=["BUGCROWD_API_TOKEN"], | |
| optional_env=["BUGCROWD_AUTHORIZATION_TOKEN", "V2_DEFAULT_PROGRAM_HANDLE"], | |
| default_goal="Find a valid Bugcrowd program task, run bounty workflow, generate report, and submit when program id is configured.", | |
| ), | |
| PlatformCapability( | |
| platform="yeswehack", | |
| lane="bug_bounty", | |
| revenue_type="vulnerability_report_reward", | |
| auth_methods=["api_token", "account_credentials", "stored_browser_session"], | |
| autonomous_actions=["program discovery", "scope review", "report preparation", "api submission when program handle is known"], | |
| human_blockers=["MFA", "CAPTCHA", "program terms acceptance", "account challenge"], | |
| required_env=["YESWEHACK_TOKEN"], | |
| optional_env=["YESWEHACK_EMAIL", "YESWEHACK_PASSWORD", "V2_DEFAULT_PROGRAM_HANDLE"], | |
| default_goal="Find a valid YesWeHack program task, run bounty workflow, generate report, and submit when program handle is configured.", | |
| ), | |
| PlatformCapability( | |
| platform="intigriti", | |
| lane="bug_bounty", | |
| revenue_type="vulnerability_report_reward", | |
| auth_methods=["api_token_if_available", "stored_browser_session"], | |
| autonomous_actions=["program discovery", "scope review", "report preparation", "authenticated portal submission queue"], | |
| human_blockers=["MFA", "CAPTCHA", "program terms acceptance", "account challenge"], | |
| required_env=["INTIGRITI_TOKEN"], | |
| optional_env=["INTIGRITI_EMAIL", "INTIGRITI_PASSWORD", "V2_DEFAULT_PROGRAM_HANDLE"], | |
| default_goal="Find a valid Intigriti program task, run bounty workflow, generate report, and queue portal submission with correct bounty tags.", | |
| ), | |
| PlatformCapability( | |
| platform="hackenproof", | |
| lane="bug_bounty", | |
| revenue_type="vulnerability_report_reward", | |
| auth_methods=["api_token_if_available", "stored_browser_session", "account_credentials"], | |
| autonomous_actions=["program discovery", "scope review", "report preparation", "authenticated portal submission queue"], | |
| human_blockers=["MFA", "CAPTCHA", "program terms acceptance", "account challenge"], | |
| required_env=["HACKENPROOF_TOKEN"], | |
| optional_env=["HACKENPROOF_EMAIL", "HACKENPROOF_PASSWORD", "V2_DEFAULT_PROGRAM_HANDLE"], | |
| default_goal="Find a valid HackenProof program task, run bounty workflow, generate report, and queue portal submission with correct bounty tags.", | |
| ), | |
| PlatformCapability( | |
| platform="cow", | |
| lane="payment_verification", | |
| revenue_type="solver_or_order_verification_task", | |
| auth_methods=["public_api"], | |
| autonomous_actions=["read-only order lookup", "trade verification", "next-stage gating"], | |
| human_blockers=["unknown order uid", "provider outage"], | |
| required_env=["COW_API_BASE_URL"], | |
| optional_env=["COW_NETWORK_8453"], | |
| default_goal="Run CoW Protocol order/trade verification and create a next-stage decision without spending gas.", | |
| risk_level="low", | |
| ), | |
| PlatformCapability( | |
| platform="coinbase_base", | |
| lane="payment_verification", | |
| revenue_type="backend_payment_verification_task", | |
| auth_methods=["coinbase_cdp", "base_rpc", "wallet_context"], | |
| autonomous_actions=["transaction receipt verification", "confirmation tracking", "stage gating"], | |
| human_blockers=["missing tx hash", "missing wallet authorization", "unknown gas"], | |
| required_env=["BASE_MAINNET_RPC"], | |
| optional_env=["COINBASE_API_KEY_NAME", "COINBASE_API_KEY_PRIVATE_KEY", "WALLET_PRIVATE_KEY"], | |
| default_goal="Verify Base/Coinbase payment evidence and produce an auto-submission stage decision under the gas ceiling.", | |
| risk_level="low", | |
| ), | |
| PlatformCapability( | |
| platform="x402_bankr_skyfire", | |
| lane="monetization", | |
| revenue_type="paid_agent_service_or_payment_verification", | |
| auth_methods=["api_key", "account_id", "stored_browser_session"], | |
| autonomous_actions=["manifest exposure", "payment metadata verification", "service readiness reporting"], | |
| human_blockers=["seller account approval", "KYC", "terms acceptance", "Google account challenge"], | |
| required_env=["X402_SERVICE_PRICE_USDC"], | |
| optional_env=["BANKR_API_KEY", "SKYFIRE_API_KEY", "SKYFIRE_ACCOUNT_ID", "SKYFIRE_BUYER_TOKEN", "SKYFIRE_SELLER_TOKEN"], | |
| default_goal="Review x402/Bankr/Skyfire monetization readiness and queue missing authenticated setup steps.", | |
| ), | |
| ] | |
| class AutonomyMissionRequest(BaseModel): | |
| mode: AutonomyMode = "prepare" | |
| platforms: list[str] = Field(default_factory=list) | |
| max_tasks: int = Field(default=5, ge=1, le=25) | |
| objective: str = "Run the highest-readiness revenue tasks and preserve bounty identifiers through report submission." | |
| include_signup_preparation: bool = True | |
| def _configured(name: str) -> bool: | |
| return bool(os.environ.get(name, "").strip()) | |
| def _score_platform(capability: PlatformCapability) -> dict[str, Any]: | |
| required_ready = [name for name in capability.required_env if _configured(name)] | |
| optional_ready = [name for name in capability.optional_env if _configured(name)] | |
| required_count = len(capability.required_env) | |
| required_ratio = len(required_ready) / required_count if required_count else 1.0 | |
| optional_bonus = min(0.25, len(optional_ready) * 0.05) | |
| score = round(min(1.0, required_ratio + optional_bonus), 2) | |
| hard_blockers = [name for name in capability.required_env if not _configured(name)] | |
| human_required = bool(hard_blockers) or any(blocker in {"MFA", "CAPTCHA", "KYC", "terms acceptance", "program terms acceptance"} for blocker in capability.human_blockers) | |
| if score >= 0.85: | |
| readiness = "ready" | |
| elif score >= 0.45: | |
| readiness = "partial" | |
| else: | |
| readiness = "blocked" | |
| return { | |
| "platform": capability.platform, | |
| "lane": capability.lane, | |
| "revenue_type": capability.revenue_type, | |
| "readiness": readiness, | |
| "score": score, | |
| "configured_required": required_ready, | |
| "configured_optional": optional_ready, | |
| "missing_required": hard_blockers, | |
| "auth_methods": capability.auth_methods, | |
| "autonomous_actions": capability.autonomous_actions, | |
| "human_blockers": capability.human_blockers, | |
| "human_required": human_required, | |
| "risk_level": capability.risk_level, | |
| } | |
| def autonomy_status() -> dict[str, Any]: | |
| platforms = [_score_platform(item) for item in PLATFORMS] | |
| ready = [item for item in platforms if item["readiness"] == "ready"] | |
| partial = [item for item in platforms if item["readiness"] == "partial"] | |
| blocked = [item for item in platforms if item["readiness"] == "blocked"] | |
| return { | |
| "generated_at": time.time(), | |
| "mode_contract": { | |
| "observe": "read-only discovery and readiness reporting", | |
| "prepare": "create task plans, reports, and queueable handoffs without irreversible external effects", | |
| "execute": "use configured APIs/sessions for allowed platform actions; report MFA/CAPTCHA/KYC/consent blockers", | |
| }, | |
| "autonomy_score": round((len(ready) + len(partial) * 0.5) / len(platforms), 2), | |
| "ready_count": len(ready), | |
| "partial_count": len(partial), | |
| "blocked_count": len(blocked), | |
| "platforms": platforms, | |
| "human_interaction_policy": [ | |
| "MFA/CAPTCHA/KYC/consent/account challenges are reported, not bypassed", | |
| "live submissions require platform adapter plus program handle", | |
| "stored browser sessions can be reused when deliberately provided", | |
| "unknown gas or gas above $0.08 blocks on-chain action", | |
| ], | |
| } | |
| def build_mission(request: AutonomyMissionRequest) -> dict[str, Any]: | |
| wanted = {item.lower() for item in request.platforms} | |
| scored = autonomy_status()["platforms"] | |
| selected = [item for item in scored if not wanted or item["platform"] in wanted or item["lane"] in wanted] | |
| selected.sort(key=lambda item: (item["readiness"] != "ready", -item["score"], item["platform"])) | |
| selected = selected[: request.max_tasks] | |
| tasks = [] | |
| for item in selected: | |
| capability = next(cap for cap in PLATFORMS if cap.platform == item["platform"]) | |
| tags = [f"autonomy-{request.mode}", f"lane-{capability.lane}", f"platform-{capability.platform}"] | |
| if capability.lane == "bug_bounty": | |
| tags.append(f"bounty-{capability.platform}") | |
| goal = capability.default_goal | |
| if request.objective: | |
| goal = f"{goal} Objective: {request.objective}" | |
| if request.include_signup_preparation and item["human_required"]: | |
| goal = f"{goal} Also prepare the exact authenticated setup/signup requirements and stop at MFA/CAPTCHA/KYC/consent blockers." | |
| tasks.append({ | |
| "platform": capability.platform, | |
| "lane": capability.lane, | |
| "readiness": item["readiness"], | |
| "score": item["score"], | |
| "goal": goal, | |
| "tags": tags, | |
| "mode": request.mode, | |
| "can_execute_now": request.mode == "execute" and item["readiness"] == "ready", | |
| "will_queue_if_blocked": True, | |
| "missing_required": item["missing_required"], | |
| "human_blockers": item["human_blockers"], | |
| }) | |
| mission = { | |
| "mission_id": f"mission-{int(time.time())}", | |
| "created_at": time.time(), | |
| "mode": request.mode, | |
| "objective": request.objective, | |
| "tasks": tasks, | |
| "summary": { | |
| "total_tasks": len(tasks), | |
| "ready_tasks": sum(1 for task in tasks if task["readiness"] == "ready"), | |
| "blocked_or_partial": sum(1 for task in tasks if task["readiness"] != "ready"), | |
| }, | |
| } | |
| (MISSION_DIR / f"{mission['mission_id']}.json").write_text(json.dumps(mission, indent=2), encoding="utf-8") | |
| return mission | |
| def list_missions(limit: int = 25) -> dict[str, Any]: | |
| missions = [] | |
| for path in sorted(MISSION_DIR.glob("mission-*.json"), key=lambda item: item.stat().st_mtime, reverse=True)[:limit]: | |
| try: | |
| missions.append(json.loads(path.read_text(encoding="utf-8"))) | |
| except Exception: | |
| pass | |
| return {"missions": missions, "total": len(missions), "mission_dir": str(MISSION_DIR)} | |
| def register_autonomy_routes(app) -> None: | |
| from tasks import create_task, update_task_plan, add_task_log | |
| from agents.commander import plan_task | |
| async def get_autonomy_status() -> dict[str, Any]: | |
| return autonomy_status() | |
| async def get_autonomy_platforms() -> dict[str, Any]: | |
| return {"platforms": [asdict(item) for item in PLATFORMS]} | |
| async def get_autonomy_missions(limit: int = 25) -> dict[str, Any]: | |
| return list_missions(limit=limit) | |
| async def create_autonomy_mission(request: AutonomyMissionRequest) -> dict[str, Any]: | |
| return build_mission(request) | |
| async def dispatch_autonomy_mission(request: AutonomyMissionRequest) -> dict[str, Any]: | |
| mission = build_mission(request) | |
| created = [] | |
| for item in mission["tasks"]: | |
| task = create_task(item["goal"]) | |
| plan = plan_task(item["goal"]) | |
| update_task_plan(task.id, plan["plan"], plan["agents"]) | |
| add_task_log(task.id, "autonomy", "mission_dispatch", f"Mission {mission['mission_id']} platform={item['platform']} mode={request.mode}") | |
| created.append({ | |
| "task_id": task.id, | |
| "platform": item["platform"], | |
| "lane": item["lane"], | |
| "readiness": item["readiness"], | |
| "can_execute_now": item["can_execute_now"], | |
| "tags": task.tags, | |
| "bounty_id": task.bounty_id, | |
| }) | |
| return {"mission": mission, "created_tasks": created} | |