const $ = (selector) => document.querySelector(selector); const $$ = (selector) => [...document.querySelectorAll(selector)]; const state = { runId: null, poller: null, lastRecord: null, startedAt: 0 }; const stageOrder = ["planning", "branching", "testing", "judging", "complete"]; function escapeHtml(value = "") { return value.replace(/[&<>'"]/g, (char) => ({ "&": "&", "<": "<", ">": ">", "'": "'", '"': """ })[char]); } function toast(message) { const node = $("#toast"); node.textContent = message; node.classList.add("show"); window.setTimeout(() => node.classList.remove("show"), 2200); } async function api(path, options) { const response = await fetch(path, options); if (!response.ok) throw new Error(`${response.status} ${response.statusText}`); return response.json(); } async function boot() { try { const [sample, health] = await Promise.all([api("/api/sample"), api("/api/health")]); $("#issue").value = sample.issue; $("#repository").value = sample.repository; $("#provider-badge").textContent = health.provider; const planner = health.model.split("/").pop().replaceAll("_", ".").replace("Nemotron-", "N"); const judge = health.judge_model.split("/").pop().replaceAll("_", ".").replace("Nemotron-", "N"); $("#model-badge").textContent = planner === judge ? `${planner} · 2 STAGES` : `${planner} → ${judge}`; } catch (error) { $("#issue").value = "Refunds at half-cent boundaries round against the customer. Preserve validation and prove a safe fix."; } } function resetRunUi() { $("#evidence").hidden = true; $("#run-status").classList.add("running"); $("#run-status").innerHTML = " Preparing experiment"; $("#branch-grid").innerHTML = ["amber", "violet", "green"].map((color, i) => `
${String.fromCharCode(65 + i)}PLANNING

Generating hypothesis

Nemotron is searching for a distinct, executable repair strategy.

`).join(""); updateStages("planning"); } function updateStages(activeStage) { const activeIndex = stageOrder.indexOf(activeStage); $$(".stage").forEach((node) => { const index = stageOrder.indexOf(node.dataset.stage); node.classList.toggle("active", index === activeIndex || activeStage === "complete" && index === 3); node.classList.toggle("done", index < activeIndex || activeStage === "complete"); }); $$("#stage-track > i").forEach((node, index) => node.classList.toggle("done", index < activeIndex)); } function runningCards(stage) { const labels = { planning: ["FORMING THESIS", "Generating hypothesis", "Nemotron is creating independent repair strategies."], branching: ["FORKING STATE", "Creating checkpoint", "ConTree is forking the same filesystem state."], testing: ["EXECUTING", "Running regression suite", "Each branch is producing comparable test evidence."], judging: ["SCORING", "Weighing the evidence", "Nemotron is reviewing safety, clarity, and observed results."] }; const [tag, title, body] = labels[stage] || labels.planning; $$(".branch-card").forEach((card, i) => { const top = card.querySelector("small"); const h3 = card.querySelector("h3"); const p = card.querySelector("p"); if (top) top.textContent = tag; if (h3) h3.textContent = `${title} ${String.fromCharCode(65 + i)}`; if (p) p.textContent = body; }); } function renderBranch(branch, index) { const { candidate, tests, score, verdict } = branch; const statusClass = tests.exit_code === 0 ? "pass" : "fail"; const statusText = tests.exit_code === 0 ? "PASS" : "FAIL"; const winner = verdict === "winner"; return `
${winner ? 'SELECTED' : ""}
${String.fromCharCode(65 + index)}${escapeHtml(tests.checkpoint.slice(0, 13).toUpperCase())}

${escapeHtml(candidate.name)}

${escapeHtml(candidate.thesis)}

EVIDENCE SCORE${score}
TESTS ${tests.passed}/${tests.total}${tests.duration_ms}ms${statusText}
RISK${escapeHtml(candidate.risk)}
`; } function paintDiff(diff) { return escapeHtml(diff || "No diff returned.").split("\n").map((line) => { const cls = line.startsWith("+") && !line.startsWith("+++") ? "diff-add" : line.startsWith("-") && !line.startsWith("---") ? "diff-remove" : line.startsWith("@@") || line.startsWith("+++") || line.startsWith("---") ? "diff-head" : ""; return `${line}`; }).join("\n"); } function renderComplete(record) { $("#branch-grid").innerHTML = record.branches.map(renderBranch).join(""); record.branches.forEach((branch, index) => { const tree = document.querySelector(`[data-tree="${index}"]`); if (tree) tree.lastChild.textContent = branch.candidate.name.toLowerCase(); }); updateStages("complete"); $("#run-status").classList.remove("running"); $("#run-status").innerHTML = ` ${escapeHtml(record.events.at(-1)?.message || "Evidence sealed")}`; const winner = record.branches.find((branch) => branch.candidate.id === record.winner_id) || record.branches[0]; $("#winner-name").textContent = winner.candidate.name; $("#winner-synthesis").textContent = record.synthesis; $("#winner-score").textContent = winner.score; $("#receipt-tests").textContent = `${winner.tests.passed} / ${winner.tests.total} passed`; $("#receipt-checkpoint").textContent = winner.tests.checkpoint; $("#model-path-value").textContent = `${record.planner_mode} / ${record.judge_mode}`.toUpperCase(); $("#runtime-pill").textContent = record.sandbox_mode.replaceAll("-", " ").toUpperCase(); $("#isolation-value").textContent = record.sandbox_mode === "nebius-sandbox" ? "VM boundary" : "Local process"; $("#patch-diff").innerHTML = `${paintDiff(winner.diff)}`; $("#evidence").hidden = false; $("#run-button").disabled = false; $("#run-button .button-copy b").textContent = "Forge again"; window.setTimeout(() => $("#evidence").scrollIntoView({ behavior: "smooth", block: "start" }), 220); } async function pollRun() { try { const record = await api(`/api/runs/${state.runId}`); state.lastRecord = record; if (record.status === "failed") { throw new Error(record.error || "The experiment stopped safely."); } updateStages(record.status); runningCards(record.status); const message = record.events.at(-1)?.message || "Working"; $("#run-status").innerHTML = ` ${escapeHtml(message)}`; if (record.branches.length) $("#branch-grid").innerHTML = record.branches.map(renderBranch).join(""); if (record.status === "complete") { const elapsed = Date.now() - state.startedAt; const minimumShowcaseMs = 2400; window.clearInterval(state.poller); window.setTimeout(() => renderComplete(record), Math.max(0, minimumShowcaseMs - elapsed)); } } catch (error) { window.clearInterval(state.poller); $("#run-button").disabled = false; $("#run-status").classList.remove("running"); $("#run-status").innerHTML = ` Run stopped safely`; toast(error.message); } } async function startRun() { const issue = $("#issue").value.trim(); if (issue.length < 12) return toast("Add a more specific issue brief."); $("#run-button").disabled = true; $("#run-button .button-copy b").textContent = "Forging evidence…"; resetRunUi(); $("#run-section").scrollIntoView({ behavior: "smooth", block: "start" }); state.startedAt = Date.now(); try { const record = await api("/api/runs", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ repository: $("#repository").value.trim(), issue, mode: "sample" }) }); state.runId = record.id; state.poller = window.setInterval(pollRun, 420); await pollRun(); } catch (error) { $("#run-button").disabled = false; toast(error.message); } } $("#run-button").addEventListener("click", startRun); $("#copy-patch").addEventListener("click", async () => { const winner = state.lastRecord?.branches.find((branch) => branch.candidate.id === state.lastRecord.winner_id); if (!winner) return; await navigator.clipboard.writeText(winner.diff); toast("Verified diff copied."); }); boot();