Spaces:
Running
Running
Download ctt/app.js from SamJoshua/agent-security-bench: direct link, hf CLI and curl.
- Browser
- Download file 8.21 kB
-
https://huggingface.co/spaces/SamJoshua/agent-security-bench/resolve/main/ctt/app.js
- Command line
-
hf download hf://spaces/SamJoshua/agent-security-bench/ctt/app.js
-
curl -L -o app.js https://huggingface.co/spaces/SamJoshua/agent-security-bench/resolve/main/ctt/app.js
8.21 kB
| import data from "./data.js"; | |
| const STATUS_LABEL = { | |
| pass: ["pass", "pass"], | |
| fail_crash: ["crash", "crash"], | |
| fail_clear: ["clear", "clear"], | |
| fail_double_encoded: ["double", "double"], | |
| fail_dropped: ["dropped", "dropped"], | |
| fail_raw_name: ["raw", "verbatim"], | |
| }; | |
| const CASE_COLS = data.cases.map((c) => ({ | |
| key: c.short, | |
| label: c.id.split("_")[0], // C1, C2, ... | |
| title: `${c.id}: ${c.title}`, | |
| })); | |
| const resultMap = new Map(); | |
| for (const r of data.results) { | |
| resultMap.set(`${r.repo_id}::${r.short}`, r); | |
| } | |
| function escapeHtml(value) { | |
| return String(value ?? "") | |
| .replaceAll("&", "&") | |
| .replaceAll("<", "<") | |
| .replaceAll(">", ">") | |
| .replaceAll('"', """); | |
| } | |
| function fmtNum(n) { | |
| if (n === null || n === undefined) return "—"; | |
| return Number(n).toLocaleString("en-US"); | |
| } | |
| function pill(status) { | |
| if (!status) return `<span class="pill na">n/a</span>`; | |
| const pair = STATUS_LABEL[status]; | |
| if (!pair) return `<span class="pill na">${escapeHtml(status)}</span>`; | |
| return `<span class="pill ${pair[0]}">${pair[1]}</span>`; | |
| } | |
| function uniqueBest(models) { | |
| const seen = new Map(); | |
| for (const m of models) { | |
| const key = m.template_sha1 || `solo:${m.repo_id}`; | |
| const prev = seen.get(key); | |
| if (!prev || (m.downloads || 0) > (prev.downloads || 0)) seen.set(key, m); | |
| } | |
| return [...seen.values()]; | |
| } | |
| const state = { | |
| q: "", | |
| unique: false, | |
| sortKey: "n_pass", | |
| sortDir: "desc", | |
| open: null, | |
| }; | |
| function filtered() { | |
| let rows = data.models.slice(); | |
| if (state.unique) rows = uniqueBest(rows); | |
| const q = state.q.trim().toLowerCase(); | |
| if (q) { | |
| rows = rows.filter((m) => | |
| m.repo_id.toLowerCase().includes(q) || | |
| (m.template_sha1 || "").toLowerCase().includes(q) | |
| ); | |
| } | |
| const dir = state.sortDir === "asc" ? 1 : -1; | |
| const key = state.sortKey; | |
| rows.sort((a, b) => { | |
| let av; | |
| let bv; | |
| if (key === "repo_id" || key === "template_sha1") { | |
| av = (a[key] || "").toLowerCase(); | |
| bv = (b[key] || "").toLowerCase(); | |
| if (av < bv) return -1 * dir; | |
| if (av > bv) return 1 * dir; | |
| } else if (key.startsWith("case:")) { | |
| const short = key.slice(5); | |
| av = a.cases?.[short] || ""; | |
| bv = b.cases?.[short] || ""; | |
| if (av === bv) { | |
| /* fall through to n_pass / downloads */ | |
| } else { | |
| // pass first when descending | |
| const rank = (s) => { | |
| if (s === "pass") return 5; | |
| if (s === "fail_clear") return 3; | |
| if (s === "fail_double_encoded") return 2; | |
| if (s === "fail_raw_name") return 1; | |
| if (s === "fail_crash") return 0; | |
| return -1; | |
| }; | |
| return (rank(av) - rank(bv)) * dir; | |
| } | |
| } else { | |
| av = a[key]; | |
| bv = b[key]; | |
| if (av == null && bv == null) { /* equal */ } | |
| else if (av == null) return 1; | |
| else if (bv == null) return -1; | |
| else if (av !== bv) return (av < bv ? -1 : 1) * dir; | |
| } | |
| // stable-ish tie breakers | |
| if ((b.n_pass || 0) !== (a.n_pass || 0)) return (b.n_pass || 0) - (a.n_pass || 0); | |
| if ((b.downloads || 0) !== (a.downloads || 0)) return (b.downloads || 0) - (a.downloads || 0); | |
| return a.repo_id.localeCompare(b.repo_id); | |
| }); | |
| return rows; | |
| } | |
| function renderStats() { | |
| const s = data.summary; | |
| const items = [ | |
| [String(s.n_repos_measured), "repos measured"], | |
| [`${s.of_dict_pass_string_crash}/${s.n_dict_pass}`, "crash on OpenAI string args"], | |
| [String(s.of_dict_pass_string_ok), "render string args correctly"], | |
| [`${s.C10_name_escape_raw}/${s.n_dict_pass}`, "paste the tool name verbatim"], | |
| ]; | |
| document.getElementById("stats").innerHTML = items.map(([n, l]) => | |
| `<div class="stat"><b>${escapeHtml(n)}</b><span>${escapeHtml(l)}</span></div>` | |
| ).join(""); | |
| } | |
| function renderCases() { | |
| document.getElementById("case-grid").innerHTML = data.cases.map((c) => | |
| `<article class="case-card"> | |
| <h3><span class="case-id">${escapeHtml(c.id.split("_")[0])}</span>${escapeHtml(c.title)}</h3> | |
| <p>${escapeHtml(c.description)}</p> | |
| </article>` | |
| ).join(""); | |
| } | |
| function headerCell(key, label, extraClass, title) { | |
| const active = state.sortKey === key; | |
| const cls = [ | |
| extraClass || "", | |
| active ? `sort-${state.sortDir}` : "", | |
| ].filter(Boolean).join(" "); | |
| return `<th class="${cls}" data-sort="${escapeHtml(key)}" title="${escapeHtml(title || label)}">${escapeHtml(label)}</th>`; | |
| } | |
| function renderHead() { | |
| const cols = [ | |
| headerCell("repo_id", "Repo", "", "Repository"), | |
| headerCell("n_pass", "Pass", "num", "Cases passed"), | |
| ...CASE_COLS.map((c) => headerCell(`case:${c.key}`, c.label, "", c.title)), | |
| headerCell("downloads", "Downloads", "num", "Hub downloads at snapshot (16 Nov 2026)"), | |
| headerCell("template_sha1", "Hash", "", "First 10 hex chars of SHA-1(chat_template)"), | |
| ]; | |
| document.getElementById("head").innerHTML = `<tr>${cols.join("")}</tr>`; | |
| } | |
| function detailHtml(model) { | |
| const blocks = data.cases.map((c) => { | |
| const r = resultMap.get(`${model.repo_id}::${c.short}`) || {}; | |
| const status = r.status || model.cases?.[c.short]; | |
| const bits = []; | |
| if (r.detail) bits.push(`<p>${escapeHtml(r.detail)}</p>`); | |
| if (r.error_type) bits.push(`<p>${escapeHtml(r.error_type)}${r.error_message ? ": " + escapeHtml(r.error_message) : ""}</p>`); | |
| if (r.snippet) bits.push(`<pre>${escapeHtml(r.snippet)}</pre>`); | |
| if (r.value_style) bits.push(`<p>value style: ${escapeHtml(r.value_style)}</p>`); | |
| return `<div class="detail-case"> | |
| <h3>${escapeHtml(c.id.split("_")[0])} ${escapeHtml(c.title)} ${pill(status)}</h3> | |
| ${bits.join("") || "<p>No detail recorded.</p>"} | |
| </div>`; | |
| }); | |
| return `<tr class="detail"><td colspan="14"><div class="detail-grid">${blocks.join("")}</div></td></tr>`; | |
| } | |
| function renderBody() { | |
| const rows = filtered(); | |
| document.getElementById("showing").textContent = | |
| `Showing ${rows.length} of ${data.models.length}`; | |
| const html = []; | |
| for (const m of rows) { | |
| const open = state.open === m.repo_id; | |
| const cells = [ | |
| `<td class="repo"><a href="https://huggingface.co/${encodeURI(m.repo_id)}" target="_blank" rel="noopener">${escapeHtml(m.repo_id)}</a></td>`, | |
| `<td class="num npass">${m.n_pass ?? 0}/10</td>`, | |
| ...CASE_COLS.map((c) => `<td class="cell">${pill(m.cases?.[c.key])}</td>`), | |
| `<td class="num">${fmtNum(m.downloads)}</td>`, | |
| `<td class="hash">${escapeHtml(m.template_sha1 || "—")}</td>`, | |
| ]; | |
| html.push(`<tr class="row${open ? " is-open" : ""}" data-repo="${escapeHtml(m.repo_id)}">${cells.join("")}</tr>`); | |
| if (open) html.push(detailHtml(m)); | |
| } | |
| document.getElementById("body").innerHTML = html.join(""); | |
| } | |
| function render() { | |
| renderHead(); | |
| renderBody(); | |
| } | |
| function setSort(key) { | |
| if (state.sortKey === key) { | |
| state.sortDir = state.sortDir === "desc" ? "asc" : "desc"; | |
| } else { | |
| state.sortKey = key; | |
| state.sortDir = key === "repo_id" || key === "template_sha1" ? "asc" : "desc"; | |
| } | |
| render(); | |
| } | |
| function bind() { | |
| document.getElementById("head").addEventListener("click", (ev) => { | |
| const th = ev.target.closest("th[data-sort]"); | |
| if (th) setSort(th.getAttribute("data-sort")); | |
| }); | |
| document.getElementById("body").addEventListener("click", (ev) => { | |
| if (ev.target.closest("a")) return; | |
| const tr = ev.target.closest("tr.row"); | |
| if (!tr) return; | |
| const id = tr.getAttribute("data-repo"); | |
| state.open = state.open === id ? null : id; | |
| renderBody(); | |
| }); | |
| document.getElementById("q").addEventListener("input", (ev) => { | |
| state.q = ev.target.value; | |
| renderBody(); | |
| }); | |
| document.getElementById("unique").addEventListener("change", (ev) => { | |
| state.unique = ev.target.checked; | |
| render(); | |
| }); | |
| const copyBtn = document.getElementById("copy-c2"); | |
| const snippet = document.getElementById("c2-snippet"); | |
| copyBtn.addEventListener("click", async () => { | |
| try { | |
| await navigator.clipboard.writeText(snippet.textContent); | |
| copyBtn.textContent = "Copied"; | |
| setTimeout(() => { copyBtn.textContent = "Copy"; }, 1500); | |
| } catch { | |
| copyBtn.textContent = "Select and copy"; | |
| } | |
| }); | |
| } | |
| renderStats(); | |
| renderCases(); | |
| bind(); | |
| render(); | |