Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/web/app/[locale]/arena/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { useEffect, useRef, useState } from "react";
import { useTranslations } from "next-intl";
import { useLocale, useTranslations } from "next-intl";
import {
getArena,
getArenaLimits,
Expand All @@ -17,6 +17,7 @@ import { Button, Card } from "../../../components/ui";
import { laneView, arenaVerdict, arenaCost, costLabel, manifestView, previewView, promptArenaView, canFollowUp, promptChainView } from "../../../lib/arenaStatus";
import { SandboxedPreview } from "../../../components/SandboxedPreview";
import { PromptBar } from "../../../components/PromptBar";
import { shareUrl } from "../../../lib/share";

const BENCHMARK_TASKS: Record<"v1" | "v2" | "v3" | "v4" | "v5", { id: string; goal: string }[]> = {
v5: [
Expand Down Expand Up @@ -99,6 +100,7 @@ function StatusPill({ status, passed, n }: { status: string; passed?: number; n?

export default function ArenaPage() {
const t = useTranslations("arena");
const locale = useLocale();
const tp = useTranslations("plan");
const [suiteVersion, setSuiteVersion] = useState<"v1" | "v2" | "v3" | "v4" | "v5">("v5");
const [selectedTaskId, setSelectedTaskId] = useState<string>("SV5-AO-01");
Expand Down Expand Up @@ -473,6 +475,9 @@ export default function ArenaPage() {
<span className="text-xs text-text-tertiary">
Model: <span className="text-text-secondary font-mono">{activeArena.model}</span>
</span>
{(activeArena.status === "succeeded" || activeArena.status === "failed") && (
<a className="arena-share-link" href={shareUrl("", locale, activeArena.arena_id)}>{t("open-result")} →</a>
)}
</div>
</div>
</Card>
Expand Down
8 changes: 8 additions & 0 deletions apps/web/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextIntlClientProvider } from 'next-intl';
import { getMessages, getTranslations } from 'next-intl/server';
import { notFound } from 'next/navigation';
import { headers } from 'next/headers';
import { FeatureRail } from '../../components/FeatureRail';
import { LanguageSwitcher } from '../../components/LanguageSwitcher';
import { StudioBreadcrumb } from '../../components/StudioBreadcrumb';
Expand All @@ -20,9 +21,16 @@ export async function generateMetadata({
const t = await getTranslations({ locale, namespace: 'titles' });
const tLayout = await getTranslations({ locale, namespace: 'layout' });

// Absolute URLs for link previews (og:image) come from the host that served the page, so a shared
// link shows its card on any deployment without a configured site URL.
const h = await headers();
const host = h.get('x-forwarded-host') ?? h.get('host');
const proto = h.get('x-forwarded-proto') ?? (host && /^(localhost|127\.0\.0\.1)(:|$)/.test(host) ? 'http' : 'https');
return {
...(host ? { metadataBase: new URL(`${proto}://${host}`) } : {}),
title: t('home'),
description: tLayout('description'),
openGraph: { siteName: 'EvoForge', title: t('home'), description: tLayout('description') },
};
}

Expand Down
33 changes: 33 additions & 0 deletions apps/web/app/[locale]/share/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { getTranslations } from 'next-intl/server';
import { fetchArenaForPreview, laneScore } from '../../../../lib/serverArena';

// Link-preview text for one shared result: the verdict and both scores, so the message that carries
// the link already says who won.
export async function generateMetadata({
params,
}: {
params: Promise<{ locale: string; id: string }>;
}) {
const { locale, id } = await params;
const t = await getTranslations({ locale, namespace: 'titles' });
const ts = await getTranslations({ locale, namespace: 'share' });
const doc = await fetchArenaForPreview(id);
if (!doc) return { title: t('share') };
const evo = laneScore(doc, 'evoforge');
const single = laneScore(doc, 'single');
const winner = doc.verdict?.winner;
const verdict = winner && ts.has(`winner-${winner}`) ? ts(`winner-${winner}`) : t('share');
const scores = `EvoForge ${evo ? `${evo.passed}/${evo.n}` : '—'} · ${ts('single')} ${single ? `${single.passed}/${single.n}` : '—'}`;
const prompt = (doc.prompt || doc.goal || '').replace(/\s+/g, ' ').trim().slice(0, 140);
const description = [scores, prompt].filter(Boolean).join(' — ');
return {
title: `${verdict} · ${t('share')}`,
description,
openGraph: { title: verdict, description, type: 'article' },
twitter: { card: 'summary_large_image', title: verdict, description },
};
}

export default function ShareResultLayout({ children }: { children: React.ReactNode }) {
return <>{children}</>;
}
63 changes: 63 additions & 0 deletions apps/web/app/[locale]/share/[id]/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ImageResponse } from "next/og";
import { fetchArenaForPreview, laneScore } from "../../../../lib/serverArena";

// The picture a chat app or social post shows for a shared result: the verdict, both hidden-test
// scores as bars and the costs, read from the stored match. Text stays in Latin script because the
// bundled image font has no Korean glyphs; a prompt in another script is left out rather than garbled.
export const alt = "EvoForge match result";
export const size = { width: 1200, height: 630 };
export const contentType = "image/png";

const VERDICT: Record<string, string> = {
evoforge: "EvoForge wins",
single: "Single AI call wins",
tie: "Tie",
inconclusive: "Needs another check",
unscorable: "Not scorable",
};

export default async function Image({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const doc = await fetchArenaForPreview(id);
const evo = laneScore(doc, "evoforge");
const single = laneScore(doc, "single");
const winner = doc?.verdict?.winner ?? "";
const headline = VERDICT[winner] ?? "Same model, two builds, hidden tests decide";
const rawPrompt = (doc?.prompt || doc?.goal || "").replace(/\s+/g, " ").trim();
const prompt = /^[\x20-\x7E]*$/.test(rawPrompt) ? (rawPrompt.length > 110 ? `${rawPrompt.slice(0, 107)}...` : rawPrompt) : "";
const cost = (side: "evoforge" | "single") => {
const c = doc?.lanes?.[side]?.cost_cents;
return Number.isInteger(c) ? `${c} cents` : "";
};
const lane = (label: string, s: { passed: number; n: number } | null, color: string, track: string, costText: string) => (
<div style={{ display: "flex", flexDirection: "column", width: "100%", marginTop: 28 }}>
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end" }}>
<span style={{ fontSize: 30, fontWeight: 700, color: "#333d4b" }}>{label}</span>
<span style={{ display: "flex", alignItems: "flex-end", gap: 16 }}>
<span style={{ fontSize: 22, color: "#8b95a1" }}>{costText}</span>
<span style={{ fontSize: 56, fontWeight: 800, color }}>{s ? `${s.passed}/${s.n}` : "-"}</span>
</span>
</div>
<div style={{ display: "flex", marginTop: 10, height: 18, borderRadius: 9, background: track, width: "100%" }}>
<div style={{ display: "flex", height: 18, borderRadius: 9, background: color, width: `${s ? Math.round((100 * s.passed) / s.n) : 0}%` }} />
</div>
</div>
);
return new ImageResponse(
(
<div style={{ width: "100%", height: "100%", display: "flex", padding: 48, background: "#f2f4f6" }}>
<div style={{ display: "flex", flexDirection: "column", width: "100%", height: "100%", padding: "48px 56px", background: "#ffffff", borderRadius: 40 }}>
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
<span style={{ fontSize: 26, fontWeight: 800, color: "#191f28" }}>EvoForge</span>
<span style={{ fontSize: 20, fontWeight: 700, color: "#1b64da", background: "#e8f3ff", padding: "8px 18px", borderRadius: 999 }}>Hidden tests decide · signed result</span>
</div>
<div style={{ display: "flex", marginTop: 28, height: 76, alignItems: "center", fontSize: 60, fontWeight: 800, letterSpacing: -2, color: winner === "evoforge" ? "#0a8a5a" : winner === "single" ? "#1b64da" : "#191f28" }}>{headline}</div>
{prompt ? <div style={{ display: "flex", marginTop: 12, fontSize: 26, lineHeight: 1.35, color: "#6b7684" }}>{prompt}</div> : null}
{lane("EvoForge", evo, "#12a66e", "#e8f8f1", cost("evoforge"))}
{lane("Single AI call", single, "#3182f6", "#eaf2fe", cost("single"))}
</div>
</div>
),
size,
);
}
176 changes: 102 additions & 74 deletions apps/web/app/[locale]/share/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
"use client";
import { use, useEffect, useState } from "react";
import { useLocale, useTranslations } from "next-intl";
import { getArena, getArenaProof, type ArenaDoc } from "../../../../lib/api";
import { getArena, getArenaProof, type ArenaDoc, type ArenaLane } from "../../../../lib/api";
import { manifestView, previewView } from "../../../../lib/arenaStatus";
import { shareText } from "../../../../lib/share";
import { SandboxedPreview } from "../../../../components/SandboxedPreview";

type Side = "evoforge" | "single";

// One lane of the result: its hidden-test score as a number and a bar, its cost, and why it lost
// points when the patch never ran.
function LaneScore({ side, lane, leading }: { side: Side; lane: ArenaLane | undefined; leading: boolean }) {
const t = useTranslations("share");
const tc = useTranslations("canvas");
const held = lane?.heldout;
const scored = held && Number.isInteger(held.passed) && Number.isInteger(held.n) && held.n > 0;
const pct = scored ? Math.round((100 * held.passed) / held.n) : 0;
const note = lane?.outcome === "apply_failed" ? tc("patch-not-applied")
: lane?.outcome === "empty_diff" ? tc("no-patch")
: null;
return (
<div className={`share-lane is-${side}${leading ? " is-leading" : ""}`}>
<span className="share-lane-name">{side === "evoforge" ? "EvoForge" : t("single")}</span>
<strong className="share-lane-score">{scored ? `${held.passed}/${held.n}` : "—"}</strong>
<span className="share-lane-bar" aria-hidden="true"><span style={{ width: `${pct}%` }} /></span>
<span className="share-lane-meta">
{t("hidden-tests")} {scored ? `${pct}%` : "—"} · {t("cost")} {Number.isInteger(lane?.cost_cents) ? `${lane?.cost_cents}¢` : "—"}
</span>
{note && <span className="share-lane-note">{note}</span>}
</div>
);
}

// An arena certificate is verified by the arena id itself (GET /v1/proof/<arena_id>).
function ShareDetails({ doc, certificateId }: { doc: ArenaDoc; certificateId: string | null }) {
const t = useTranslations("share");
const locale = useLocale();
Expand All @@ -17,68 +45,74 @@ function ShareDetails({ doc, certificateId }: { doc: ArenaDoc; certificateId: st
const singleHtml = singlePreview.html ?? singleLane?.preview_html ?? null;
const prompt = doc.prompt || doc.goal || doc.task_id || doc.arena_id;
const verdict = doc.verdict;
const homeHref = locale === "ko" ? "/ko" : "/";
const winner = verdict?.winner ?? null;
const prefix = locale === "ko" ? "/ko" : "";
const homeHref = prefix || "/";
const proofId = certificateId ? doc.arena_id : null;
const [copied, setCopied] = useState(false);
const share = async () => {
const url = window.location.href;
const nav = navigator as Navigator & { share?: (data: { url?: string; text?: string }) => Promise<void> };
if (typeof nav.share === "function") {
try { await nav.share({ url, text: shareText(doc, locale) }); } catch {}
return;
}
try {
await navigator.clipboard.writeText(url);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch {}
};
const when = typeof doc.created_at === "number"
? new Intl.DateTimeFormat(locale === "ko" ? "ko-KR" : "en-US", { dateStyle: "medium", timeZone: locale === "ko" ? "Asia/Seoul" : "UTC" }).format(new Date(doc.created_at * 1000))
: null;

return (
<main className="studio-home canvas-workspace" style={{ maxWidth: "100%", overflowWrap: "anywhere", padding: "24px 16px 48px" }}>
<h1>{t("title")}</h1>
<p style={{ maxWidth: "100%", whiteSpace: "pre-wrap" }}>{prompt}</p>
<div className="canvas-stage is-compare" style={{ maxWidth: "100%", padding: "0 0 24px" }}>
<article className="canvas-output" aria-label="EvoForge">
<header className="canvas-output-header">
<strong>EvoForge</strong>
<div className="canvas-output-numbers">
<span>{evoLane?.heldout ? `${evoLane.heldout.passed}/${evoLane.heldout.n}` : "—"}</span>
<span className="canvas-number-divider" aria-hidden="true">·</span>
<span>{Number.isInteger(evoLane?.cost_cents) ? `${evoLane?.cost_cents}¢` : "—"}</span>
</div>
</header>
<div className="canvas-output-body">
{evoHtml ? (
<SandboxedPreview html={evoHtml} title={`share-${doc.arena_id}-evoforge`} />
) : (
<div className="canvas-empty">—</div>
)}
</div>
<div style={{ display: "flex", flexWrap: "wrap", gap: 12, padding: "12px 20px", fontSize: 12, maxWidth: "100%" }}>
<span>{t("hidden-tests")} {evoLane?.heldout ? `${evoLane.heldout.passed}/${evoLane.heldout.n}` : "—"}</span>
<span>{t("cost")} {Number.isInteger(evoLane?.cost_cents) ? `${evoLane?.cost_cents}¢` : "—"}</span>
</div>
</article>
<article className="canvas-output" aria-label={t("single")}>
<header className="canvas-output-header">
<strong>{t("single")}</strong>
<div className="canvas-output-numbers">
<span>{singleLane?.heldout ? `${singleLane.heldout.passed}/${singleLane.heldout.n}` : "—"}</span>
<span className="canvas-number-divider" aria-hidden="true">·</span>
<span>{Number.isInteger(singleLane?.cost_cents) ? `${singleLane?.cost_cents}¢` : "—"}</span>
</div>
</header>
<div className="canvas-output-body">
{singleHtml ? (
<SandboxedPreview html={singleHtml} title={`share-${doc.arena_id}-single`} />
) : (
<div className="canvas-empty">—</div>
)}
</div>
<div style={{ display: "flex", flexWrap: "wrap", gap: 12, padding: "12px 20px", fontSize: 12, maxWidth: "100%" }}>
<span>{t("hidden-tests")} {singleLane?.heldout ? `${singleLane.heldout.passed}/${singleLane.heldout.n}` : "—"}</span>
<span>{t("cost")} {Number.isInteger(singleLane?.cost_cents) ? `${singleLane?.cost_cents}¢` : "—"}</span>
</div>
</article>
</div>
<section className="canvas-conditions" style={{ maxWidth: "100%" }}>
<p>
<strong>{t("result")}: </strong>
{verdict?.winner && t.has(`winner-${verdict.winner}`) ? t(`winner-${verdict.winner}`) : "—"}
{evoLane?.heldout && singleLane?.heldout ? ` (EvoForge ${evoLane.heldout.passed} : ${singleLane.heldout.passed} ${t("single")})` : ""}
</p>
{manifest?.disclosure && <p>{manifest.disclosure}</p>}
{certificateId && <p>{t("certificate")}: {certificateId}</p>}
<p>
<a href={homeHref}>{t("try-own")}</a>
</p>
<main className="share-page">
<section className={`share-hero is-${winner ?? "none"}`} aria-labelledby="share-verdict">
<p className="share-kicker">EvoForge · {t("title")}{when ? ` · ${when}` : ""}</p>
<h1 id="share-verdict">{winner && t.has(`winner-${winner}`) ? t(`winner-${winner}`) : t("result-pending")}</h1>
<blockquote className="share-prompt"><span>{prompt}</span></blockquote>
<div className="share-versus">
<LaneScore side="evoforge" lane={evoLane} leading={winner === "evoforge"} />
<span className="share-vs" aria-hidden="true">vs</span>
<LaneScore side="single" lane={singleLane} leading={winner === "single"} />
</div>
<ul className="share-trust">
<li>{t("same-model", { model: doc.model || "—" })}</li>
<li>{t("same-tests")}</li>
{certificateId && <li>{t("signed")}</li>}
</ul>
<div className="share-actions">
<button type="button" className="share-primary" onClick={() => void share()}>{copied ? t("copied") : t("share-this")}</button>
{proofId && <a className="share-secondary" href={`${prefix}/verify/${encodeURIComponent(proofId)}`}>{t("open-proof")}</a>}
<a className="share-link" href={homeHref}>{t("try-own")} →</a>
</div>
</section>

<section className="share-built" aria-labelledby="share-built-title">
<h2 id="share-built-title">{t("what-built")}</h2>
<div className="share-previews">
<article className="share-preview" aria-label="EvoForge">
<header>EvoForge</header>
{evoHtml ? <SandboxedPreview html={evoHtml} title={`share-${doc.arena_id}-evoforge`} /> : <div className="share-preview-empty">{t("no-preview")}</div>}
</article>
<article className="share-preview" aria-label={t("single")}>
<header>{t("single")}</header>
{singleHtml ? <SandboxedPreview html={singleHtml} title={`share-${doc.arena_id}-single`} /> : <div className="share-preview-empty">{t("no-preview")}</div>}
</article>
</div>
</section>

<details className="perf-section share-fine">
<summary>{t("fine-print")}</summary>
<div>
{verdict?.reason && <p>{t("result")}: {verdict.reason}</p>}
{manifest?.disclosure && <p>{manifest.disclosure}</p>}
{certificateId && <p>{t("certificate")}: <code>{certificateId}</code></p>}
<p><code>{doc.arena_id}</code></p>
</div>
</details>
</main>
);
}
Expand All @@ -93,25 +127,19 @@ export default function SharePage({ params }: { params: Promise<{ id: string }>
useEffect(() => {
let cancelled = false;
(async () => {
try {
const arena = await getArena(id);
if (!cancelled) setDoc(arena);
} catch {
if (!cancelled) setMissing(true);
}
try {
const cert = await getArenaProof(id);
if (!cancelled) setProofId(cert?.certificate_id ?? null);
} catch {
if (!cancelled) setProofId(null);
}
const [arena, cert] = await Promise.allSettled([getArena(id), getArenaProof(id)]);
if (cancelled) return;
if (arena.status === "fulfilled") setDoc(arena.value);
else setMissing(true);
const c = cert.status === "fulfilled" ? cert.value : null;
setProofId(c?.certificate_id ?? null);
})();
return () => {
cancelled = true;
};
}, [id]);

if (missing) return <p className="studio-home">{t("not-found")}</p>;
if (doc === null) return <p className="studio-home">{t("title")}</p>;
if (missing) return <p className="share-page share-status">{t("not-found")}</p>;
if (doc === null) return <p className="share-page share-status">{t("loading")}</p>;
return <ShareDetails doc={doc} certificateId={proofId} />;
}
Loading
Loading