/* 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)}
${esc(q.problem)}
`, "question"); qEl.querySelector(".issue-toggle").onclick = (e) => { const o = qEl.querySelector(".issue").classList.toggle("open"); e.target.textContent = `[full issue text sent to the agent, ${issueLines} lines ${o ? "▾" : "▸"}]`; }; const steps = document.createElement("div"); steps.className = "steps"; screen.appendChild(steps); const goldFiles = q.gold_files; for (let i = 0; i < q.steps.length; i++) { const s = q.steps[i]; await wait(i === 0 ? 500 : 250); if (id !== state.runId) return; const pending = document.createElement("div"); pending.className = "step pending"; pending.innerHTML = `${i + 1}⠋thinking…`; steps.appendChild(pending); scrollDown(); const frames = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"; let f = 0; const spin = setInterval(() => { const sp = pending.querySelector(".spinner"); if (sp) sp.textContent = frames[++f % frames.length]; }, 80); await wait(s.tool === "colgrep" ? 900 : s.tool === "finish" ? 700 : 550); clearInterval(spin); if (id !== state.runId) { pending.remove(); return; } if (s.note) { const n = document.createElement("div"); n.className = "note"; n.textContent = `harness: ${s.note}`; steps.insertBefore(n, pending); } pending.className = `step ${s.tool}`; pending.tabIndex = 0; const hasOut = s.output && s.tool !== "finish"; pending.innerHTML = `${i + 1}${icon[s.tool]} ${s.tool}${esc(s.text)}${hasOut ? `▸ output` : ""}`; if (hasOut) { const out = document.createElement("div"); out.className = "output"; out.innerHTML = markGold(s.output, goldFiles); steps.appendChild(out); const toggle = () => { const o = out.classList.toggle("open"); pending.querySelector(".caret").textContent = o ? "▾ output" : "▸ output"; }; pending.onclick = toggle; pending.onkeydown = (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); toggle(); } }; } scrollDown(); } await wait(300); if (id !== state.runId) return; const n = q.locations.length; line(`✓ ${n} location${n === 1 ? "" : "s"} · ${q.n_turns} turns · ${q.n_searches} search${q.n_searches === 1 ? "" : "es"} · ${q.n_terminal} terminal command${q.n_terminal === 1 ? "" : "s"}${q.forced_finish ? " · finish forced by the turn budget" : ""}`, "summary"); for (const l of q.locations) { await wait(200); if (id !== state.runId) return; const range = l.start === l.end ? `${l.start}` : `${l.start}-${l.end}`; const code = l.code ? `
${l.code.map((c) => c.gap ? `      …` : `${c.n}${esc(c.t)}`).join("")}
` : `(code not available)`; line(`
${esc(l.file)}:${range}${l.symbol ? `${esc(l.symbol)}` : ""}
${code}`, "loc"); } await wait(300); if (id !== state.runId) return; line(referenceHtml(q), "ref"); scrollDown(); } function markGold(text, gold) { let h = esc(text); for (const g of gold) h = h.split(esc(g)).join(`${esc(g)}`); return h; } const overlaps = (a, b) => a.file === b.file && a.start <= b.end && b.start <= a.end; function referenceHtml(q) { const rows = q.locations.map((l) => { const inFile = q.gold_files.includes(l.file); const inLines = inFile && q.gold.some((g) => overlaps(l, g)); const mark = inLines ? `✓` : inFile ? `◐` : `✗`; const why = inLines ? "overlaps a reference range" : inFile ? "right file, lines outside the reference ranges" : "not a file the fix touched"; const range = l.start === l.end ? `${l.start}` : `${l.start}-${l.end}`; return `${mark} ${esc(l.file)}:${range}${why}`; }).join(""); const missed = q.gold_files.filter((g) => !q.locations.some((l) => l.file === g)).map((g) => `✗ ${esc(g)}reference file not submitted`).join(""); const gold = q.gold.map((g) => `${esc(g.file)}:${g.start === g.end ? g.start : `${g.start}-${g.end}`}`).join(", "); const s = q.scores; const f = (x) => (x == null ? "n/a" : x.toFixed(2)); return `
Checked against the pull request that fixed ${esc(q.id)}
${rows}${missed}` + `reference ranges: ${gold}` + `file F1 ${f(s.file_f1)} · line F1 ${f(s.line_f1)}(line F1 counts exact line overlap)` + (q.note ? `
${esc(q.note)}
` : ""); } // ------------------------------------------------------------- wiring $("#prompt").onsubmit = (e) => { e.preventDefault(); const v = input.value.trim(); if (v) run(v); }; $("#skip").onclick = () => { state.instant = true; }; $("#clear").onclick = () => { state.runId++; screen.innerHTML = ""; input.disabled = false; $("#skip").hidden = true; renderSuggest(); input.focus(); }; body.addEventListener("click", (e) => { if (!e.target.closest("button, .step, .output, .issue, a, input, select") && !getSelection().toString()) input.focus({ preventScroll: true }); }); input.addEventListener("keydown", (e) => { if (e.key === "Tab" && !e.shiftKey) { const v = input.value.trim(); if (!v) return; e.preventDefault(); const opts = state.repo ? state.repo.queries.map((q) => `colgrep --agent "${q.title}"`) : state.data.repos.map((r) => `cd ${r.repo}`); const hit = opts.find((o) => o.toLowerCase().startsWith(v.toLowerCase())) || opts.find((o) => o.toLowerCase().includes(v.toLowerCase())); if (hit) input.value = hit; } }); async function boot() { const r = await fetch("data/demo.json"); state.data = await r.json(); renderSuggest(); line(intro(), "intro"); const repo = params.get("repo"), query = params.get("query"); if (query) { const q = state.data.repos.flatMap((r) => r.queries).find((x) => x.id === query); if (q) { await run(`cd ${state.data.repos.find((r) => r.queries.includes(q)).repo}`); await run(`colgrep --agent "${q.title}"`); return; } } if (repo) await run(`cd ${repo}`); } boot().catch((err) => line(`failed to load data: ${esc(err.message)}`)); })();