/* Full transcript of a run (build/transcripts.py writes data/tx//.json.gz): a closed section that loads the run's record when opened. Runs of tool calls fold into one line each; "Messages only" hides them. */ (() => { const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c])); const num = n => n.toLocaleString("en-US"), pl = (n, w) => `${num(n)} ${w}${n === 1 ? "" : "s"}`; const PAGE = 150, FOLD = 3; function section(task, rid, judgeOnly) { return `
Full transcript

Everything that happened in this run

${judgeOnly ? "The transcript is the whole record of this run" : "The steps above tell this run's story. The transcript is the whole record"}, on the task's clock: the ask, everything the agent wrote, every tool call it made with its result, and each message from a colleague or a scheduled event. The colleagues' and the judge's own reasoning is not included.

`; } function wire(root) { if (!root) return; const go = root.querySelector(".txs-go"), body = root.querySelector(".txs-body"); let tx = null, loading = false; go.addEventListener("click", async () => { if (tx) { const open = body.hidden; body.hidden = !open; go.textContent = open ? "Hide the transcript" : "Show the full transcript"; return; } if (loading) return; loading = true; go.textContent = "Loading…"; try { tx = await load(root.dataset.task, root.dataset.run); } catch (e) { go.textContent = "Show the full transcript"; loading = false; body.hidden = false; body.innerHTML = e.message === "404" ? `

This run has no transcript yet.

` : `

The transcript did not load. Check the connection and try again.

`; return; } body.hidden = false; go.textContent = "Hide the transcript"; draw(body, tx); }); } async function load(task, rid) { const r = await fetch(`data/tx/${encodeURIComponent(task)}/${encodeURIComponent(rid)}.json.gz`, { credentials: "same-origin" }); if (!r.ok) throw new Error(String(r.status)); const buf = new Uint8Array(await r.arrayBuffer()); if (buf[0] !== 0x1f || buf[1] !== 0x8b) return JSON.parse(new TextDecoder().decode(buf)); /* the server already unzipped it */ const s = new Blob([buf]).stream().pipeThrough(new DecompressionStream("gzip")); return JSON.parse(await new Response(s).text()); } function draw(body, tx) { const ev = tx.events, n = k => ev.filter(e => k.includes(e.k)).length; const pre = ev.filter(e => e.k === "beat" && e.before), rest = ev.filter(e => !(e.k === "beat" && e.before)); const items = fold(rest); let mode = "all", shown = 0; body.innerHTML = `

${num(ev.length - pre.length)} events · ${num(n(["send"]))} sent or written by the agent · ${num(n(["msg", "beat"]) - pre.length)} from colleagues and scheduled events · ${pl(n(["say"]), "note")} by the agent · ${pl(n(["call", "local"]), "other tool call")}

${pre.length ? `
Before the run starts · ${pre.length} scheduled event${pre.length > 1 ? "s" : ""} set up the world
    ${pre.map(row).join("")}
` : ""}
    `; const list = body.querySelector("#txL"), more = body.querySelector(".txs-more"); const pool = () => mode === "all" ? items : items.filter(x => !x.burst && !["call", "local"].includes(x.e.k)); const page = () => { const p = pool(), next = p.slice(shown, shown + PAGE); list.insertAdjacentHTML("beforeend", next.map(item).join("")); shown += next.length; more.hidden = shown >= p.length; more.textContent = `Show the next ${num(Math.min(PAGE, p.length - shown))} of ${num(p.length - shown)} more`; }; const reset = () => { list.innerHTML = ""; shown = 0; page(); }; more.addEventListener("click", page); body.addEventListener("click", e => { const c = e.target.closest("button.tx-c"); if (!c) return; const p = c.nextElementSibling, open = p.hidden; p.hidden = !open; c.setAttribute("aria-expanded", String(open)); }); body.querySelector(".txs-mode").addEventListener("click", e => { const b = e.target.closest("[data-m]"); if (!b || b.dataset.m === mode) return; mode = b.dataset.m; body.querySelectorAll(".txs-mode [data-m]").forEach(x => x.setAttribute("aria-pressed", String(x === b))); reset(); }); list.addEventListener("toggle", e => { const d = e.target; if (d.classList && d.classList.contains("tx-burst") && d.open && !d.dataset.done) { d.dataset.done = 1; d.querySelector("ol").innerHTML = items[+d.dataset.i].burst.map(row).join(""); } }, true); items.forEach((x, i) => x.i = i); reset(); function item(x) { if (!x.burst) return row(x.e); const b = x.burst, tools = {}; b.forEach(e => tools[e.tool] = (tools[e.tool] || 0) + 1); const top = Object.entries(tools).sort((p, q) => q[1] - p[1]), errs = b.filter(e => e.err).length; return `
  1. ${esc(b[0].t)}
    ${b.length} tool calls${top.slice(0, 3).map(([t, c]) => `${esc(t)}${c > 1 ? " ×" + c : ""}`).join(", ")}${top.length > 3 ? `, ${top.length - 3} more` : ""}${errs ? `${errs} failed` : ""}${esc(b[0].t)}–${esc(b[b.length - 1].t)}
    1. `; } function row(e) { const t = `${esc(e.t)}`; if (e.k === "prompt") return `
    2. ${t}
      ${e.first ? `The ask · from ${esc(tx.as)}` : `${esc(tx.as)} writes again`}${e.from_task ? `as the task gives it; this harness's record leaves the prompt out` : ""}

      ${esc(e.x)}

    3. `; if (e.k === "send") { const more = e.r ? `Result · ${num(e.r.length)} characters` : "Show the call"; return `
    4. ${t}
      ${logo(tx)}The agent ${verb(e.tool)}${e.to ? ` → ${esc(e.to)}` : ""}${esc(e.tool)}${e.err ? `failed` : ""}
      ${e.x ? `

      ${esc(e.x)}

      ` : e.a ? `

      ${esc(e.a.length > 320 ? e.a.slice(0, 319) + "…" : e.a)}

      ` : ""}
    5. `; } if (e.k === "say") return `
    6. ${t}
      ${logo(tx)}The agent's notenot sent to anyone

      ${esc(e.x)}

    7. `; if (e.k === "msg" || e.k === "beat") return `
    8. ${t}
      ${esc(e.who)}${e.k === "beat" ? `scheduled` : ""}${esc(e.tool)}${e.to ? " → " + esc(e.to) : ""}
      ${e.x ? `

      ${esc(e.x)}

      ` : ""}
    9. `; if (e.k === "brief") return `
    10. ${t}
      ${logo(tx)}The agent briefs a helper agenta sub-agent it started

      ${esc(e.x)}

    11. `; if (e.k === "note") return `
    12. ${t}
      Harness note

      ${esc(e.x)}

    13. `; if (e.k === "grade") return `
    14. ${t}
      The judge scores the end state${(+e.score).toFixed(2)}${e.pass ? "Pass" : "Fail"}
    15. `; /* one line: the tool, its arguments cut to fit, and a toggle that opens the arguments in full and the result */ const call = e.k === "call", a = e.a && e.a !== "{}" ? e.a : "", more = call && e.r ? `Result · ${num(e.r.length)} characters` : a ? (call ? "Show the arguments" : "Show the command") : ""; return `
    16. ${t}
      ${more ? `` : "
      "}${more ? `` : ""}
    17. `; } } /* consecutive tool calls (FOLD or more) become one folded item; everything else stays one item per event */ function fold(ev) { const out = []; let run = []; const flush = () => { if (run.length >= FOLD) out.push({ burst: run }); else run.forEach(e => out.push({ e })); run = []; }; ev.forEach(e => { if (e.k === "call" || e.k === "local") run.push(e); else { flush(); out.push({ e }); } }); flush(); return out; } /* what a write does, from its tool name: slack_send_message sends, update_records_for_table updates */ function verb(tool) { const m = /(?:^|_)(send|reply|forward|post|schedule|create|update|modify|add|delete|upsert|archive|move|close|resolve)(?:_|$)/.exec(tool); const v = m ? m[1] : ""; return { send: "sends", reply: "replies", forward: "forwards", post: "posts", schedule: "schedules", create: "creates", update: "updates", modify: "updates", add: "adds", delete: "deletes", upsert: "updates", archive: "archives", move: "moves", close: "closes", resolve: "resolves" }[v] || "writes"; } function logo(tx) { const M = typeof MODELS !== "undefined" ? MODELS : {}, L = typeof MODEL_LOGO !== "undefined" ? MODEL_LOGO : {}; /* data6.js globals */ const m = Object.keys(M).find(k => M[k].id === tx.model) || ""; return m && L[m] ? `` : ""; } window.CBTX = { section, wire }; })();