/* colgrep --agent terminal replay. Static: loads data/demo.json, replays recorded runs. */ (() => { const $ = (s) => document.querySelector(s); const esc = (s) => String(s ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c])); const params = new URLSearchParams(location.search); const state = { data: null, repo: null, runId: 0, instant: false }; const screen = $("#screen"), body = $("#term-body"), input = $("#cmd"), suggest = $("#suggest"); const speed = () => 1; const wait = (ms) => new Promise((r) => setTimeout(r, state.instant || speed() === 0 ? 0 : ms / speed())); const scrollDown = () => { body.scrollTop = body.scrollHeight; }; const line = (html, cls = "") => { const d = document.createElement("div"); d.className = `line ${cls}`; d.innerHTML = html; screen.appendChild(d); scrollDown(); return d; }; async function typeCommand(text) { const el = line(`${esc(cwd())} $ `, "cmdline"); const span = el.querySelector(".cmd"); const html = text.replace(/^(colgrep --agent )("[^"]*")$/, (_, a, b) => `${esc(a)}${esc(b)}`); if (state.instant || speed() === 0) { span.innerHTML = html; return; } for (let i = 1; i <= text.length; i++) { span.textContent = text.slice(0, i); await wait(28); } span.innerHTML = html; } const cwd = () => (state.repo ? `~/${state.repo.repo.split("/")[1]}` : "~"); const setCwd = () => { $("#cwd").textContent = cwd(); }; // ------------------------------------------------------------- suggestions function renderSuggest() { const d = state.data; if (!state.repo) { suggest.innerHTML = `repositories (click to cd):` + d.repos.map((r, i) => ``).join(""); } else { suggest.innerHTML = `recorded questions in ${esc(state.repo.repo)}, ${esc(state.repo.language)} (click to run):` + state.repo.queries.map((q, i) => ``).join("") + ``; } } suggest.addEventListener("click", (e) => { const b = e.target.closest("button"); if (!b) return; if (b.dataset.repo != null) run(`cd ${state.data.repos[+b.dataset.repo].repo}`); else if (b.dataset.query != null) run(`colgrep --agent "${state.repo.queries[+b.dataset.query].title}"`); else if (b.dataset.back) run("cd .."); }); // ------------------------------------------------------------- commands async function run(cmd) { const id = ++state.runId; state.instant = false; $("#skip").hidden = true; input.value = ""; input.disabled = true; try { await typeCommand(cmd); if (id !== state.runId) return; const m = /^colgrep\s+--agent\s+"?(.+?)"?\s*$/.exec(cmd); if (/^clear$/.test(cmd)) { screen.innerHTML = ""; } else if (/^help$/.test(cmd)) help(); else if (/^cd\s+\.\.$/.test(cmd) || /^cd$/.test(cmd)) { state.repo = null; setCwd(); } else if (/^cd\s+/.test(cmd)) cd(cmd.replace(/^cd\s+/, "").trim()); else if (/^ls$/.test(cmd)) ls(); else if (m) await agent(m[1], id); else { const hit = matchAny(cmd); if (hit) { if (!state.repo || !state.repo.queries.includes(hit)) cd(state.data.repos.find((r) => r.queries.includes(hit)).repo); await agent(hit.title, id); } else line(`no recorded session matches "${esc(cmd)}". Nothing runs live here: this terminal replays ${state.data.repos.reduce((n, r) => n + r.queries.length, 0)} recorded runs. Pick one below, or type a few words of its title.`); } } finally { if (id === state.runId) { input.disabled = false; $("#skip").hidden = true; renderSuggest(); scrollDown(); input.focus({ preventScroll: true }); } } const u = new URL(location); if (state.repo) u.searchParams.set("repo", state.repo.repo); else u.searchParams.delete("repo"); history.replaceState(null, "", u); } function intro() { const n = state.data.repos.reduce((k, r) => k + r.queries.length, 0); return `This terminal replays ${n} recorded runs of ${esc(state.data.model)} on ${state.data.repos.length} evaluation repositories, so only two commands do anything: cd <repo> pick a repository colgrep --agent "<question>" replay the recorded run for one of its questions`; } function help() { line(`cd <repo> enter one of the evaluation repositories cd .. leave it ls list what is available here colgrep --agent "…" replay the recorded run for one of the listed questions clear clear the screen`); } function ls() { if (!state.repo) line(`${state.data.repos.map((r) => esc(r.repo.split("/")[1]) + "/").join(" ")}`); else line(`${state.repo.queries.map((q) => `${esc(q.id)} ${esc(q.title)}`).join("\n")}`); } function cd(name) { const r = state.data.repos.find((x) => x.repo === name || x.repo.split("/")[1] === name || x.repo.endsWith("/" + name)); if (!r) { line(`cd: no such repository: ${esc(name)}`); return; } state.repo = r; setCwd(); } function matchAny(text) { const t = text.toLowerCase().replace(/^colgrep\s+--agent\s+/, "").replace(/^"|"$/g, ""); const pool = (state.repo ? state.repo.queries : []).concat(state.data.repos.flatMap((r) => r.queries)); return pool.find((q) => q.title.toLowerCase().includes(t) || q.id.toLowerCase().includes(t)) || null; } function filterChips(text) { const t = text.toLowerCase().replace(/^colgrep\s+--agent\s+/, "").replace(/^"|"$/g, ""); suggest.querySelectorAll(".chip").forEach((c) => { c.classList.toggle("hidden", !!t && !c.textContent.toLowerCase().includes(t) && !(c.title || "").toLowerCase().includes(t)); }); } input.addEventListener("input", () => filterChips(input.value.trim())); // ------------------------------------------------------------- the agent replay const benchShort = (b) => (b.includes("Lite") ? "SWE-bench Lite" : "Multi-SWE-bench Flash"); const icon = { colgrep: "●", terminal: "■", finish: "◆" }; function findQuery(text) { const t = text.toLowerCase(); const pool = state.repo ? state.repo.queries : state.data.repos.flatMap((r) => r.queries); return pool.find((q) => q.title.toLowerCase() === t || q.id.toLowerCase() === t) || pool.find((q) => q.title.toLowerCase().startsWith(t) || q.id.toLowerCase().includes(t)) || null; } async function agent(text, id) { const q = findQuery(text); if (!q) { line(`no recorded run for this question. Nothing runs live here: pick one of the questions below${state.repo ? "" : ", after choosing a repository"}.`); return; } if (!state.repo || !state.repo.queries.includes(q)) { state.repo = state.data.repos.find((r) => r.queries.includes(q)); setCwd(); } $("#skip").hidden = false; const d = state.data; line(`◆ colgrep agent · ${esc(d.model)} · recorded run on ${esc(benchShort(q.benchmark))}, seed ${d.seed}, ${d.evaluation.max_turns}-turn budget\n◆ ${esc(state.repo.repo)} @ ${esc(q.base_commit.slice(0, 7))}${q.n_files ? ` · ${q.n_files.toLocaleString()} files` : ""}`, "hdr"); const issueLines = q.problem.split("\n").length; const qEl = line(`❯ ${esc(q.title)}
${l.code.map((c) => c.gap ? ` …` : `${c.n}${esc(c.t)}`).join("")}` : `(code not available)`;
line(`