"""Free-tier Hugging Face interface for Project RxV. The Space is intentionally a control plane: it receives public repository URLs and renders reports, while the private Runner executes every package in a fresh sandbox. Never enable an embedded runner in this public process. """ from __future__ import annotations import html import json import os import re import time from typing import Any from urllib.parse import urlparse import gradio as gr import httpx API_URL = os.getenv("RXV_API_URL", "").rstrip("/") GITHUB_RE = re.compile(r"^https://github\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+/?$") CSS = """ :root{--rxv:#9b7bff;--aqua:#4de0cd;--ink:#070a12;--panel:#101725;--line:#263450} body,.gradio-container{background:radial-gradient(950px 480px at 83% -5%,#382473 0%,transparent 58%),var(--ink)!important;color:#f4f7ff!important;font-family:Inter,ui-sans-serif,system-ui} .gradio-container{max-width:1240px!important}.hero{padding:55px 0 23px}.eyebrow{color:var(--aqua);font-size:11px;font-weight:800;letter-spacing:.18em}.hero h1{font-size:clamp(42px,6vw,76px);line-height:.95;letter-spacing:-.065em;margin:13px 0}.hero h1 span{display:block;color:#ad93ff}.hero p{color:#afbbd1;max-width:760px;font-size:17px;line-height:1.6}.metric{border-left:1px solid #33425e;padding-left:15px;margin-right:26px;display:inline-flex;flex-direction:column}.metric b{font-size:22px}.metric small{color:#95a2bb;text-transform:uppercase;font-size:10px;letter-spacing:.08em}.card{background:linear-gradient(145deg,rgba(21,30,48,.97),rgba(11,16,28,.97));border:1px solid var(--line);border-radius:16px;padding:20px!important}.section-title{font-weight:800;font-size:16px}.hint{color:#9ba9c1;font-size:13px}.primary button{background:linear-gradient(90deg,#8561f6,#aa80ff)!important;border:0!important;font-weight:800!important;height:48px!important}.status{border:1px solid #30415e;border-radius:10px;padding:14px 16px;background:#0b101b}.suite{display:grid;grid-template-columns:13px 1fr auto;gap:10px;padding:12px 0;border-bottom:1px solid #253149}.suite:last-child{border:0}.dot-pass{color:#4de0cd}.dot-warning{color:#ffc668}.dot-fail{color:#ff7286}.tag{font-size:10px;letter-spacing:.1em;color:#aab7d0}.empty{color:#98a6c0;padding:22px 0}.notice{margin:16px 0;padding:12px 14px;border:1px solid #4a397d;border-radius:10px;color:#d4c8ff;background:rgba(141,105,255,.09)} """ def validate_repo_url(value: str) -> str: value = value.strip().rstrip("/") parsed = urlparse(value) if parsed.hostname != "github.com" or parsed.username or parsed.password or parsed.query or parsed.fragment or not GITHUB_RE.fullmatch(value): raise gr.Error("Enter a public GitHub repository URL, for example https://github.com/org/package.") return value def suite_html(report: dict[str, Any] | None) -> str: if not report: return '
Submit a repository to see integrity, AST, security, test, documentation, visual, and release-gate results here.
' rows = [] for suite in report.get("suites", []): status = suite.get("status", "skipped") tone = "pass" if status == "passed" else "fail" if status in {"failed", "error"} else "warning" rows.append(f'
●
{html.escape(suite.get("name", "Validation suite"))}
{html.escape(suite.get("summary", ""))}
{html.escape(status.upper())}
') return "".join(rows) def score_html(report: dict[str, Any] | None) -> str: if not report: return '
FINAL RELEASE DECISION

Your quality score and release verdict will appear after the isolated runner finishes.
' score = html.escape(str(report.get("score", "—"))) verdict = html.escape(str(report.get("verdict", "complete")).replace("_", " ").upper()) return f'
RXV QUALITY SCORE
{score}/100
{verdict}

Weighted across correctness, security, test confidence, reproducibility, and release risk.

' def findings_html(report: dict[str, Any] | None) -> str: if not report or not report.get("findings"): return '
No findings are available yet.
' rows = [] for finding in report["findings"]: rows.append(f"
●
{html.escape(str(finding.get('rule', 'RXV')))} · {html.escape(str(finding.get('file', '')))}:{html.escape(str(finding.get('line', 0)))}
{html.escape(str(finding.get('message', '')))}
{html.escape(str(finding.get('severity', ''))).upper()}
") return "".join(rows) def validate_repository(repo_url: str, profile: str, progress=gr.Progress()): repo_url = validate_repo_url(repo_url) if not API_URL: raise gr.Error("The public UI is deployed, but the private RxV Runner has not been configured. Set the RXV_API_URL Space variable to enable real validation.") progress(0.05, desc="Submitting isolated validation job") try: with httpx.Client(timeout=30) as client: submit = client.post(f"{API_URL}/api/submissions", data={"github_url": repo_url, "profile": profile}) submit.raise_for_status() run_id = submit.json()["id"] for attempt in range(90): progress(min(0.1 + attempt / 100, 0.97), desc="Running package validation in isolated sandbox") response = client.get(f"{API_URL}/api/runs/{run_id}") response.raise_for_status() run = response.json() if run["status"] in {"passed", "failed", "error"}: report = run.get("report") status = f"### Run `{run_id[:12]}` · **{run['status'].upper()}**\nRepository: `{repo_url}` · Profile: **{profile.title()}**" return status, score_html(report), suite_html(report), findings_html(report), report or {"error": run.get("error")} time.sleep(2) except httpx.HTTPError as exc: raise gr.Error("RxV could not contact its private validation service. Try again shortly.") from exc raise gr.Error("This validation exceeded the public UI wait limit. Check the run history service for its final report.") with gr.Blocks(title="Project RxV · R Package Validation", css=CSS, theme=gr.themes.Base()) as demo: gr.HTML("""
PUBLIC R PACKAGE QUALITY INTELLIGENCE

Prove your package is ready.Before CRAN does.

Paste a public GitHub repository. Project RxV runs a deep, isolated validation across package integrity, AST risk, security, tests, coverage, documentation, visual snapshots, reproducibility, and release readiness.

14+validation domains0network access in test sandbox1final release verdict
""") if not API_URL: gr.HTML("
RUNNER CONFIGURATION REQUIRED · This free public Space is ready for its private validation endpoint. Set RXV_API_URL in Space Variables to enable real test runs.
") with gr.Row(): with gr.Column(scale=7, elem_classes=["card"]): gr.HTML("
01 · Package source

Only public GitHub owner/repository URLs are accepted.

") repo = gr.Textbox(label="Public GitHub repository", placeholder="https://github.com/organisation/package") profile = gr.Radio([("Rapid · static, structure, install", "rapid"), ("Standard · full package confidence", "standard"), ("Release · visual, portability, release gate", "release")], value="standard", label="Validation depth") submit = gr.Button("Start isolated validation →", variant="primary", elem_classes=["primary"]) with gr.Column(scale=5, elem_classes=["card"]): gr.HTML("
What RxV validates

Package layout · metadata · license · AST · secrets · dependencies · build · CRAN check · tests · coverage · lint · docs · vignettes · visual/UI · reproducibility · release gate

Every submission is executed outside this public UI in a disposable sandbox. Public visitors never need an account.
") gr.HTML("
LIVE VALIDATION REPORT
") run_status = gr.Markdown("### No validation run selected\nSubmit a repository above to generate an evidence-backed release report.") with gr.Row(): with gr.Column(scale=4, elem_classes=["card"]): score = gr.HTML(score_html(None)) with gr.Column(scale=8, elem_classes=["card"]): suites = gr.HTML(suite_html(None)) with gr.Column(elem_classes=["card"]): gr.HTML("
Findings
") findings = gr.HTML(findings_html(None)) raw = gr.JSON(label="Structured RxV report", visible=False) submit.click(validate_repository, inputs=[repo, profile], outputs=[run_status, score, suites, findings, raw]) demo.queue(default_concurrency_limit=8).launch(share=True)