midah commited on
Commit
121f6ca
·
verified ·
1 Parent(s): 343228c

feat: clickable+paginated hits, all-axis pre-warm, eval label fix

Browse files
Files changed (4) hide show
  1. __pycache__/app.cpython-313.pyc +0 -0
  2. app.py +35 -9
  3. static/app.js +45 -15
  4. static/style.css +2 -1
__pycache__/app.cpython-313.pyc CHANGED
Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ
 
app.py CHANGED
@@ -49,6 +49,7 @@ Design decisions (benefit / price):
49
 
50
  from __future__ import annotations
51
 
 
52
  import math
53
  import re
54
  import threading
@@ -253,6 +254,7 @@ app = FastAPI(title="ProcGrep explorer", docs_url="/api")
253
  class QueryRequest(BaseModel):
254
  dataset: str = SUGGESTED[0]
255
  pattern: str # regex over the space-joined atom spine
 
256
 
257
 
258
  @app.get("/datasets")
@@ -335,15 +337,17 @@ def query(req: QueryRequest) -> JSONResponse:
335
  "mix_all": _action_mix(traces),
336
  "mix_hits": _action_mix(hits) if hits else {},
337
  "atom_color": ATOM_COLOR,
 
338
  "hits": [
339
  {
340
  "trace_id": t.trace_id,
341
  "model": t.agent,
342
  "task": t.task,
343
  "outcome": t.outcome,
 
344
  "atoms": list(t.atoms[:200]),
345
  }
346
- for t in hits[:HIT_SAMPLE]
347
  ],
348
  }
349
  )
@@ -366,7 +370,11 @@ class CompareRequest(BaseModel):
366
  def _side_traces(axis: str, dataset: str, value: str) -> tuple[list[CachedTrace], str]:
367
  """Resolve one side of a comparison to its traces and a display label."""
368
  if axis == "eval":
369
- return _load(value), value.split("/")[-1]
 
 
 
 
370
  if axis == "agent":
371
  return [t for t in _load(dataset) if t.agent == value], value
372
  if axis == "outcome":
@@ -496,20 +504,38 @@ def compare(req: CompareRequest) -> JSONResponse:
496
 
497
 
498
  def _warm_default_compare() -> None:
499
- """Cache the comparator's default landing pair: first store dataset, its two
500
- most common agents. Runs in a background thread so it never blocks startup.
 
501
  """
502
  try:
503
  store = _load_store()
504
  datasets = list(store.keys()) or list(SUGGESTED)
505
- dataset = datasets[0]
506
- agents = [a for a, _ in Counter(t.agent for t in _load(dataset)).most_common()]
 
 
 
 
 
 
 
 
 
 
507
  if len(agents) >= 2:
508
- _COMPARE_CACHE[("agent", dataset, agents[0], agents[1])] = _compute_compare(
509
- "agent", dataset, agents[0], agents[1]
510
- )
511
  except Exception:
512
  pass
 
 
 
 
 
 
 
 
 
513
 
514
 
515
  @app.on_event("startup")
 
49
 
50
  from __future__ import annotations
51
 
52
+ import contextlib
53
  import math
54
  import re
55
  import threading
 
254
  class QueryRequest(BaseModel):
255
  dataset: str = SUGGESTED[0]
256
  pattern: str # regex over the space-joined atom spine
257
+ offset: int = 0 # paginate the matched-trace sample for "show more"
258
 
259
 
260
  @app.get("/datasets")
 
337
  "mix_all": _action_mix(traces),
338
  "mix_hits": _action_mix(hits) if hits else {},
339
  "atom_color": ATOM_COLOR,
340
+ "n_shown_from": req.offset,
341
  "hits": [
342
  {
343
  "trace_id": t.trace_id,
344
  "model": t.agent,
345
  "task": t.task,
346
  "outcome": t.outcome,
347
+ "steps": len(t.atoms),
348
  "atoms": list(t.atoms[:200]),
349
  }
350
+ for t in hits[req.offset : req.offset + HIT_SAMPLE]
351
  ],
352
  }
353
  )
 
370
  def _side_traces(axis: str, dataset: str, value: str) -> tuple[list[CachedTrace], str]:
371
  """Resolve one side of a comparison to its traces and a display label."""
372
  if axis == "eval":
373
+ # org/short label so same-basename datasets stay distinct, e.g.
374
+ # nebius/SWE-agent vs ElenaFu/SWE-agent.
375
+ org, _, name = value.partition("/")
376
+ short = name.replace("-trajectories", "") or name
377
+ return _load(value), f"{org}/{short}" if org else name
378
  if axis == "agent":
379
  return [t for t in _load(dataset) if t.agent == value], value
380
  if axis == "outcome":
 
504
 
505
 
506
  def _warm_default_compare() -> None:
507
+ """Cache the comparator's default landing pair for every axis (agent, eval,
508
+ outcome), mirroring the frontend defaults so each axis lands instantly.
509
+ Runs in a background thread so it never blocks startup.
510
  """
511
  try:
512
  store = _load_store()
513
  datasets = list(store.keys()) or list(SUGGESTED)
514
+ except Exception:
515
+ return
516
+
517
+ def warm(axis: str, dataset: str, left: str, right: str) -> None:
518
+ key = (axis, dataset, left, right)
519
+ if key not in _COMPARE_CACHE:
520
+ with contextlib.suppress(Exception):
521
+ _COMPARE_CACHE[key] = _compute_compare(axis, dataset, left, right)
522
+
523
+ # agent: first dataset, its two most common agents (frontend default).
524
+ try:
525
+ agents = [a for a, _ in Counter(t.agent for t in _load(datasets[0])).most_common()]
526
  if len(agents) >= 2:
527
+ warm("agent", datasets[0], agents[0], agents[1])
 
 
528
  except Exception:
529
  pass
530
+ # eval: first two store datasets.
531
+ if len(datasets) >= 2:
532
+ warm("eval", datasets[0], datasets[0], datasets[1])
533
+ # outcome: first dataset that carries a resolved label, resolved vs unresolved.
534
+ outcome_ds = [
535
+ d for d, ts in store.items() if any(t.outcome in ("resolved", "unresolved") for t in ts)
536
+ ]
537
+ if outcome_ds:
538
+ warm("outcome", outcome_ds[0], "resolved", "unresolved")
539
 
540
 
541
  @app.on_event("startup")
static/app.js CHANGED
@@ -21,6 +21,7 @@ let HIDE_NOISE = false;
21
  let DSETS = []; // store-backed dataset ids (shared by query + compare)
22
  let OUTCOME_DS = []; // datasets that carry a genuine resolution label
23
  let QTIMER; // debounce handle for live-as-you-type
 
24
  const CMP = { axis: "agent", ds: null, left: null, right: null, data: null };
25
 
26
  // Brief provenance: link the selected dataset to its Hugging Face source page.
@@ -96,6 +97,7 @@ async function run(pattern) {
96
  }
97
  if (r.error) { $("res").innerHTML = `<span class="err">${r.error}</span>`; return; }
98
  $("dsmeta").textContent = `· ${r.n_traces} traces${r.truncated ? " (capped)" : ""}`;
 
99
  const col = r.atom_color;
100
  const top = r.by_model[0];
101
  const s = r.stats || {};
@@ -111,13 +113,10 @@ async function run(pattern) {
111
  <div class="eyebrow">action mix · matched vs. all</div>
112
  <div class="rrow"><span class="rlab">matched</span>${r.n_hits ? mixbar(r.mix_hits, col) : '<span class="dim">no matches</span>'}</div>
113
  <div class="rrow"><span class="rlab">all traces</span>${mixbar(r.mix_all, col)}</div>
114
- <div class="eyebrow">matching traces · matched span outlined</div>
115
- ${r.hits.map((h) => {
116
- const prob = h.task || h.trace_id || "";
117
- const oc = h.outcome ? `<span class="oc ${h.outcome}">${h.outcome}</span>` : "";
118
- return `<div class="qhit"><span class="hit-model">${prettyModel(h.model)}</span><span class="hit-task dim" title="${prob}">${prettyTask(prob)}</span>${oc}<span class="dim">${h.atoms.length} steps</span>${spine(h.atoms, col, matchSpan(h.atoms, r.pattern))}</div>`;
119
- }).join("")}
120
- ${r.n_hits > r.hits.length ? `<div class="note">showing ${r.hits.length} of ${r.n_hits} matches</div>` : ""}`;
121
  }
122
 
123
  document.addEventListener("click", (e) => {
@@ -174,24 +173,55 @@ function barcode(atoms, color) {
174
  }).join("") + "</span>";
175
  }
176
 
177
- function openTrace(side, i) {
178
- const r = CMP.data; if (!r) return;
179
- const t = r[side].trails[i];
180
- const ds = CMP.axis === "eval" ? (side === "left" ? CMP.left : CMP.right) : CMP.ds;
181
  const src = `https://huggingface.co/datasets/${ds}`;
 
 
182
  const sheet = document.createElement("div");
183
  sheet.className = "sheet";
184
  sheet.onclick = (e) => { if (e.target === sheet) sheet.remove(); };
185
  sheet.innerHTML =
186
  `<div class="card"><span class="x" onclick="this.closest('.sheet').remove()">close ✕</span>
187
- <div style="font-size:15px"><b>${prettyModel(t.model)}</b>${t.task ? ` · ${prettyTask(t.task)}` : ""}</div>
188
- <div class="dim" style="margin:2px 0 4px">${t.steps} steps · structural trail, no raw text stored</div>
189
- <div style="margin:6px 0 12px">${barcode(t.atoms, r.atom_color)}</div>
190
- <div class="thread">${threadHTML(t.atoms, r.atom_color)}</div>
191
  <div class="note" style="margin-top:12px"><a href="${src}" target="_blank" rel="noopener">view full trace at source ↗</a> · ${ds}</div>
192
  </div>`;
193
  document.body.appendChild(sheet);
194
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
  function trailStack(side) {
197
  const r = CMP.data, col = r[side], c = r.atom_color;
 
21
  let DSETS = []; // store-backed dataset ids (shared by query + compare)
22
  let OUTCOME_DS = []; // datasets that carry a genuine resolution label
23
  let QTIMER; // debounce handle for live-as-you-type
24
+ let QHITS = [], QCOLOR = {}, QNH = 0, QPAT = ""; // current query hits, for click + paginate
25
  const CMP = { axis: "agent", ds: null, left: null, right: null, data: null };
26
 
27
  // Brief provenance: link the selected dataset to its Hugging Face source page.
 
97
  }
98
  if (r.error) { $("res").innerHTML = `<span class="err">${r.error}</span>`; return; }
99
  $("dsmeta").textContent = `· ${r.n_traces} traces${r.truncated ? " (capped)" : ""}`;
100
+ QHITS = r.hits; QCOLOR = r.atom_color; QNH = r.n_hits; QPAT = r.pattern;
101
  const col = r.atom_color;
102
  const top = r.by_model[0];
103
  const s = r.stats || {};
 
113
  <div class="eyebrow">action mix · matched vs. all</div>
114
  <div class="rrow"><span class="rlab">matched</span>${r.n_hits ? mixbar(r.mix_hits, col) : '<span class="dim">no matches</span>'}</div>
115
  <div class="rrow"><span class="rlab">all traces</span>${mixbar(r.mix_all, col)}</div>
116
+ <div class="eyebrow">matching traces · click to open · matched span outlined</div>
117
+ <div id="qhits"></div>
118
+ <div id="qmore"></div>`;
119
+ renderHits();
 
 
 
120
  }
121
 
122
  document.addEventListener("click", (e) => {
 
173
  }).join("") + "</span>";
174
  }
175
 
176
+ // Open any trace as a thread sheet. Shared by the comparator trails and the
177
+ // query hits, so "select a trace to inspect" works the same everywhere.
178
+ function openTraceData(t, ds, color) {
 
179
  const src = `https://huggingface.co/datasets/${ds}`;
180
+ const prob = t.task || t.trace_id || "";
181
+ const oc = t.outcome ? ` <span class="oc ${t.outcome}">${t.outcome}</span>` : "";
182
  const sheet = document.createElement("div");
183
  sheet.className = "sheet";
184
  sheet.onclick = (e) => { if (e.target === sheet) sheet.remove(); };
185
  sheet.innerHTML =
186
  `<div class="card"><span class="x" onclick="this.closest('.sheet').remove()">close ✕</span>
187
+ <div style="font-size:15px"><b>${prettyModel(t.model)}</b>${prob ? ` · ${prettyTask(prob)}` : ""}${oc}</div>
188
+ <div class="dim" style="margin:2px 0 4px">${t.steps ?? t.atoms.length} steps · structural trail, no raw text stored</div>
189
+ <div style="margin:6px 0 12px">${barcode(t.atoms, color)}</div>
190
+ <div class="thread">${threadHTML(t.atoms, color)}</div>
191
  <div class="note" style="margin-top:12px"><a href="${src}" target="_blank" rel="noopener">view full trace at source ↗</a> · ${ds}</div>
192
  </div>`;
193
  document.body.appendChild(sheet);
194
  }
195
+ function openTrace(side, i) {
196
+ const r = CMP.data; if (!r) return;
197
+ const ds = CMP.axis === "eval" ? (side === "left" ? CMP.left : CMP.right) : CMP.ds;
198
+ openTraceData(r[side].trails[i], ds, r.atom_color);
199
+ }
200
+ function openQHit(i) { openTraceData(QHITS[i], $("ds").value, QCOLOR); }
201
+
202
+ // Render the matched-trace list with a "show more" control so the full match
203
+ // set is browsable, not just the first server page.
204
+ function renderHits() {
205
+ $("qhits").innerHTML = QHITS.map((h, i) => {
206
+ const prob = h.task || h.trace_id || "";
207
+ const oc = h.outcome ? `<span class="oc ${h.outcome}">${h.outcome}</span>` : "";
208
+ return `<div class="qhit" onclick="openQHit(${i})"><span class="hit-model">${prettyModel(h.model)}</span><span class="hit-task dim" title="${prob}">${prettyTask(prob)}</span>${oc}<span class="dim">${h.steps ?? h.atoms.length} steps</span>${spine(h.atoms, QCOLOR, matchSpan(h.atoms, QPAT))}</div>`;
209
+ }).join("");
210
+ const left = QNH - QHITS.length;
211
+ $("qmore").innerHTML = left > 0
212
+ ? `<span class="chip" onclick="moreHits()">show more · ${QHITS.length} of ${QNH}</span>`
213
+ : (QNH ? `<div class="note">showing all ${QNH}</div>` : "");
214
+ }
215
+ async function moreHits() {
216
+ let r;
217
+ try {
218
+ r = await (await fetch("query", {
219
+ method: "POST", headers: { "Content-Type": "application/json" },
220
+ body: JSON.stringify({ dataset: $("ds").value, pattern: QPAT, offset: QHITS.length }),
221
+ })).json();
222
+ } catch { return; }
223
+ if (r.hits && r.hits.length) { QHITS = QHITS.concat(r.hits); renderHits(); }
224
+ }
225
 
226
  function trailStack(side) {
227
  const r = CMP.data, col = r[side], c = r.atom_color;
static/style.css CHANGED
@@ -26,7 +26,8 @@ select,input{font-family:var(--mono);font-size:12px;padding:6px 8px;border:1px s
26
  .mix{display:inline-flex;height:11px;width:200px;border:1px solid var(--rule)}
27
  .mix>span{height:100%}
28
  .speed{color:var(--copper)}
29
- .qhit{padding:5px 2px;border-bottom:1px solid var(--rule);display:flex;align-items:center;gap:8px}
 
30
  .hit-model{min-width:96px}
31
  .hit-task{min-width:130px;max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px}
32
  .oc{font-size:10px;padding:1px 6px;border-radius:2px;flex:none}
 
26
  .mix{display:inline-flex;height:11px;width:200px;border:1px solid var(--rule)}
27
  .mix>span{height:100%}
28
  .speed{color:var(--copper)}
29
+ .qhit{padding:5px 2px;border-bottom:1px solid var(--rule);display:flex;align-items:center;gap:8px;cursor:pointer}
30
+ .qhit:hover{background:#fff}
31
  .hit-model{min-width:96px}
32
  .hit-task{min-width:130px;max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px}
33
  .oc{font-size:10px;padding:1px 6px;border-radius:2px;flex:none}