Spaces:
Running
Running
feat: trajectory replay in sheet, unified barcodes, author/repo filter
Browse files- static/app.js +105 -13
- static/style.css +16 -0
static/app.js
CHANGED
|
@@ -114,6 +114,7 @@ async function run(pattern) {
|
|
| 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();
|
|
@@ -166,31 +167,117 @@ function threadHTML(atoms, color) {
|
|
| 166 |
// A contiguous trajectory barcode: one cell per atom, reasoning pale and
|
| 167 |
// actions vivid, so trail length is proportional and behavior reads as color
|
| 168 |
// density. Used by the comparator (vs the collapsing spine() the query uses).
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
| 171 |
const noise = a === "think" || a === "other";
|
| 172 |
-
|
|
|
|
| 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)
|
| 185 |
sheet.innerHTML =
|
| 186 |
-
`<div class="card"><span class="x" onclick="
|
| 187 |
<div style="font-size:15px"><b>${prettyModel(t.model)}</b>${prob ? ` · ${prettyTask(prob)}` : ""}${oc}</div>
|
| 188 |
-
<div class="dim" style="margin:2px 0
|
| 189 |
-
<div style="margin:
|
| 190 |
-
<div class="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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;
|
|
@@ -202,15 +289,20 @@ function openQHit(i) { openTraceData(QHITS[i], $("ds").value, QCOLOR); }
|
|
| 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 |
-
$("
|
|
|
|
|
|
|
|
|
|
| 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>${
|
| 209 |
}).join("");
|
| 210 |
const left = QNH - QHITS.length;
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
| 214 |
}
|
| 215 |
async function moreHits() {
|
| 216 |
let r;
|
|
|
|
| 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 |
+
<input id="qfilter" class="qfilter" placeholder="filter these by author or repo, e.g. Azure" oninput="renderHits()">
|
| 118 |
<div id="qhits"></div>
|
| 119 |
<div id="qmore"></div>`;
|
| 120 |
renderHits();
|
|
|
|
| 167 |
// A contiguous trajectory barcode: one cell per atom, reasoning pale and
|
| 168 |
// actions vivid, so trail length is proportional and behavior reads as color
|
| 169 |
// density. Used by the comparator (vs the collapsing spine() the query uses).
|
| 170 |
+
// hi (optional) is an [start,end] atom range; cells outside it dim so the
|
| 171 |
+
// matched span pops. Noise cells get class nz so "hide think/other" can drop them.
|
| 172 |
+
function barcode(atoms, color, hi) {
|
| 173 |
+
return '<span class="bc">' + atoms.map((a, idx) => {
|
| 174 |
const noise = a === "think" || a === "other";
|
| 175 |
+
const dim = hi && (idx < hi[0] || idx > hi[1]) ? ";opacity:.3" : "";
|
| 176 |
+
return `<i class="${noise ? "nz" : ""}" title="${a}" style="background:${noise ? "#e6e1d8" : (color[a] || "#ccc")}${dim}"></i>`;
|
| 177 |
}).join("") + "</span>";
|
| 178 |
}
|
| 179 |
|
| 180 |
// Open any trace as a thread sheet. Shared by the comparator trails and the
|
| 181 |
// query hits, so "select a trace to inspect" works the same everywhere.
|
| 182 |
+
// Present-tense phrase per atom, for the terminal-style replay lines.
|
| 183 |
+
const ATOM_PHRASE = {
|
| 184 |
+
search_repo: "grepped the repo", read_file: "opened a file", edit: "edited code",
|
| 185 |
+
create_file: "created a file", delete_file: "deleted a file", run_test: "ran the tests",
|
| 186 |
+
submit: "submitted the patch", localize: "localized the fault", error: "hit an error",
|
| 187 |
+
think: "reasoning", other: "other",
|
| 188 |
+
};
|
| 189 |
+
// Active replay state for the open sheet. One sheet at a time.
|
| 190 |
+
let RP = null;
|
| 191 |
+
|
| 192 |
+
function rpMini(atoms, n, color) {
|
| 193 |
+
return '<span class="bc">' + atoms.map((a, idx) => {
|
| 194 |
+
const noise = a === "think" || a === "other";
|
| 195 |
+
return `<i style="background:${noise ? "#e6e1d8" : (color[a] || "#ccc")};opacity:${idx <= n ? 1 : 0.16}"></i>`;
|
| 196 |
+
}).join("") + "</span>";
|
| 197 |
+
}
|
| 198 |
+
function rpTerminal(atoms, n, color) {
|
| 199 |
+
const out = [];
|
| 200 |
+
let i = 0;
|
| 201 |
+
while (i <= n && i < atoms.length) {
|
| 202 |
+
const a = atoms[i];
|
| 203 |
+
if (a === "think" || a === "other") {
|
| 204 |
+
let k = 0;
|
| 205 |
+
while (i <= n && i < atoms.length && (atoms[i] === "think" || atoms[i] === "other")) { k++; i++; }
|
| 206 |
+
out.push(`<div class="tstep fold">┄ ${k} reasoning ${k > 1 ? "steps" : "step"}</div>`);
|
| 207 |
+
} else {
|
| 208 |
+
const now = i === n ? " rpnow" : "";
|
| 209 |
+
out.push(`<div class="tstep${now}"><span class="ti">${i + 1}</span><span class="dot" style="background:${color[a] || "#ccc"}"></span>${ATOM_PHRASE[a] || a}${now ? ' <span class="cur">▍</span>' : ""}</div>`);
|
| 210 |
+
i++;
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
return out.join("");
|
| 214 |
+
}
|
| 215 |
+
function rpFire() {
|
| 216 |
+
if (!RP) return;
|
| 217 |
+
const pat = $("rp-q").value.trim(), el = $("rp-fire");
|
| 218 |
+
if (!pat) { el.textContent = ""; return; }
|
| 219 |
+
let rx; try { rx = new RegExp(pat); } catch { el.innerHTML = '<span class="dim">…</span>'; return; }
|
| 220 |
+
const sp = RP.atoms.slice(0, RP.n + 1).join(" ") + " ";
|
| 221 |
+
const m = rx.exec(sp);
|
| 222 |
+
el.innerHTML = m
|
| 223 |
+
? `<span class="fire">● fired at step ${sp.slice(0, m.index).split(" ").length}</span>`
|
| 224 |
+
: '<span class="dim">no match yet</span>';
|
| 225 |
+
}
|
| 226 |
+
function rpDraw() {
|
| 227 |
+
$("rp-mini").innerHTML = rpMini(RP.atoms, RP.n, RP.color);
|
| 228 |
+
$("rp-term").innerHTML = rpTerminal(RP.atoms, RP.n, RP.color);
|
| 229 |
+
$("rp-seek").value = RP.n;
|
| 230 |
+
$("rp-step").textContent = `${RP.n + 1} / ${RP.max + 1}`;
|
| 231 |
+
rpFire();
|
| 232 |
+
const tm = $("rp-term"); if (tm) tm.scrollTop = tm.scrollHeight;
|
| 233 |
+
}
|
| 234 |
+
function rpPause() {
|
| 235 |
+
if (!RP) return;
|
| 236 |
+
RP.playing = false;
|
| 237 |
+
if (RP.timer) { clearInterval(RP.timer); RP.timer = null; }
|
| 238 |
+
const b = $("rp-play"); if (b) b.textContent = "▶ play";
|
| 239 |
+
}
|
| 240 |
+
function rpToggle() {
|
| 241 |
+
if (!RP) return;
|
| 242 |
+
if (RP.playing) { rpPause(); return; }
|
| 243 |
+
if (RP.n >= RP.max) RP.n = 0;
|
| 244 |
+
RP.playing = true; $("rp-play").textContent = "❚❚ pause";
|
| 245 |
+
RP.timer = setInterval(() => { if (RP.n < RP.max) { RP.n++; rpDraw(); } else { rpPause(); } }, RP.speed);
|
| 246 |
+
}
|
| 247 |
+
function rpSeek(v) { rpPause(); RP.n = +v; rpDraw(); }
|
| 248 |
+
function rpSpeed(ms) {
|
| 249 |
+
if (ms === 0) { rpPause(); RP.n = RP.max; rpDraw(); return; } // instant: jump to end
|
| 250 |
+
const was = RP.playing; RP.speed = ms; rpPause(); if (was) rpToggle();
|
| 251 |
+
}
|
| 252 |
+
function rpClose() { rpPause(); RP = null; const s = document.querySelector(".sheet"); if (s) s.remove(); }
|
| 253 |
+
|
| 254 |
function openTraceData(t, ds, color) {
|
| 255 |
+
rpPause();
|
| 256 |
const src = `https://huggingface.co/datasets/${ds}`;
|
| 257 |
const prob = t.task || t.trace_id || "";
|
| 258 |
const oc = t.outcome ? ` <span class="oc ${t.outcome}">${t.outcome}</span>` : "";
|
| 259 |
+
const max = t.atoms.length - 1;
|
| 260 |
+
RP = { atoms: t.atoms, color, n: max, max, playing: false, timer: null, speed: 380 };
|
| 261 |
const sheet = document.createElement("div");
|
| 262 |
sheet.className = "sheet";
|
| 263 |
+
sheet.onclick = (e) => { if (e.target === sheet) rpClose(); };
|
| 264 |
sheet.innerHTML =
|
| 265 |
+
`<div class="card"><span class="x" onclick="rpClose()">close ✕</span>
|
| 266 |
<div style="font-size:15px"><b>${prettyModel(t.model)}</b>${prob ? ` · ${prettyTask(prob)}` : ""}${oc}</div>
|
| 267 |
+
<div class="dim" style="margin:2px 0 6px">${t.steps ?? t.atoms.length} steps · structural trail, no raw text stored · press play to replay</div>
|
| 268 |
+
<div id="rp-mini" style="margin:2px 0 8px"></div>
|
| 269 |
+
<div class="rpbar">
|
| 270 |
+
<span class="rpbtn" id="rp-play" onclick="rpToggle()">▶ play</span>
|
| 271 |
+
<input id="rp-seek" type="range" min="0" max="${max}" value="${max}" oninput="rpSeek(this.value)">
|
| 272 |
+
<span class="rpspd"><span onclick="rpSpeed(380)">1x</span> <span onclick="rpSpeed(100)">4x</span> <span onclick="rpSpeed(0)">end</span></span>
|
| 273 |
+
<span class="dim" id="rp-step"></span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="thread" id="rp-term"></div>
|
| 276 |
+
<div class="rpq"><span class="dim">live query</span> <input id="rp-q" placeholder="(edit ){3,}" oninput="rpFire()"> <span id="rp-fire" class="dim"></span></div>
|
| 277 |
<div class="note" style="margin-top:12px"><a href="${src}" target="_blank" rel="noopener">view full trace at source ↗</a> · ${ds}</div>
|
| 278 |
</div>`;
|
| 279 |
document.body.appendChild(sheet);
|
| 280 |
+
rpDraw();
|
| 281 |
}
|
| 282 |
function openTrace(side, i) {
|
| 283 |
const r = CMP.data; if (!r) return;
|
|
|
|
| 289 |
// Render the matched-trace list with a "show more" control so the full match
|
| 290 |
// set is browsable, not just the first server page.
|
| 291 |
function renderHits() {
|
| 292 |
+
const f = ($("qfilter") && $("qfilter").value || "").trim().toLowerCase();
|
| 293 |
+
const rows = QHITS.map((h, i) => [h, i]).filter(([h]) =>
|
| 294 |
+
!f || (h.task || h.trace_id || "").toLowerCase().includes(f));
|
| 295 |
+
$("qhits").innerHTML = rows.map(([h, i]) => {
|
| 296 |
const prob = h.task || h.trace_id || "";
|
| 297 |
const oc = h.outcome ? `<span class="oc ${h.outcome}">${h.outcome}</span>` : "";
|
| 298 |
+
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>${barcode(h.atoms, QCOLOR, matchSpan(h.atoms, QPAT))}</div>`;
|
| 299 |
}).join("");
|
| 300 |
const left = QNH - QHITS.length;
|
| 301 |
+
let more = "";
|
| 302 |
+
if (f) more += `<div class="note">${rows.length} of ${QHITS.length} loaded match "${f}"</div>`;
|
| 303 |
+
if (left > 0) more += `<span class="chip" onclick="moreHits()">show more · ${QHITS.length} of ${QNH}</span>`;
|
| 304 |
+
else if (QNH && !f) more += `<div class="note">showing all ${QNH}</div>`;
|
| 305 |
+
$("qmore").innerHTML = more;
|
| 306 |
}
|
| 307 |
async function moreHits() {
|
| 308 |
let r;
|
static/style.css
CHANGED
|
@@ -28,6 +28,9 @@ select,input{font-family:var(--mono);font-size:12px;padding:6px 8px;border:1px s
|
|
| 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}
|
|
@@ -83,6 +86,19 @@ a{color:var(--copper)}
|
|
| 83 |
.tstep .ti{width:14px;color:var(--gray);text-align:right;flex:none}
|
| 84 |
.tstep .dot{width:8px;height:8px;border-radius:2px;flex:none;align-self:center}
|
| 85 |
.tstep.fold{color:var(--olive);font-style:italic}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
/* provenance */
|
| 88 |
.src{font-size:11px;text-decoration:none}
|
|
|
|
| 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 |
+
.qhit .bc{flex:1;min-width:0}
|
| 32 |
+
.qfilter{font-family:var(--mono);font-size:12px;padding:5px 8px;border:1px solid var(--rule);background:#fff;color:var(--ink);width:300px;margin:2px 0 10px}
|
| 33 |
+
body.hide-noise .bc i.nz{display:none}
|
| 34 |
.hit-model{min-width:96px}
|
| 35 |
.hit-task{min-width:130px;max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px}
|
| 36 |
.oc{font-size:10px;padding:1px 6px;border-radius:2px;flex:none}
|
|
|
|
| 86 |
.tstep .ti{width:14px;color:var(--gray);text-align:right;flex:none}
|
| 87 |
.tstep .dot{width:8px;height:8px;border-radius:2px;flex:none;align-self:center}
|
| 88 |
.tstep.fold{color:var(--olive);font-style:italic}
|
| 89 |
+
.tstep.rpnow{background:#fff4ee}
|
| 90 |
+
.cur{color:var(--copper);animation:blink 1s step-end infinite}
|
| 91 |
+
@keyframes blink{50%{opacity:0}}
|
| 92 |
+
.rpbar{display:flex;align-items:center;gap:10px;margin:4px 0 10px}
|
| 93 |
+
.rpbtn{cursor:pointer;border:1px solid var(--ink);padding:2px 10px;font-size:11px;flex:none}
|
| 94 |
+
.rpbar input[type=range]{flex:1;accent-color:var(--copper)}
|
| 95 |
+
.rpspd{font-size:11px;color:var(--olive);flex:none}
|
| 96 |
+
.rpspd span{cursor:pointer;padding:0 2px}
|
| 97 |
+
.rpspd span:hover{color:var(--ink)}
|
| 98 |
+
.thread#rp-term{max-height:300px;overflow:auto}
|
| 99 |
+
.rpq{display:flex;align-items:center;gap:8px;margin-top:10px;font-size:12px}
|
| 100 |
+
.rpq input{flex:none;width:200px}
|
| 101 |
+
.fire{color:var(--copper)}
|
| 102 |
|
| 103 |
/* provenance */
|
| 104 |
.src{font-size:11px;text-decoration:none}
|