File size: 8,214 Bytes
385fef5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
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("<", "&lt;")
    .replaceAll(">", "&gt;")
    .replaceAll('"', "&quot;");
}

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();