@ancha-labs/cli 0.4.16 → 0.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.md +3 -1
- package/lib/ancha.mjs +1064 -681
- package/lib/assets/SKILL.md +1 -1
- package/lib/assets/agents-section.md +1 -1
- package/lib/assets/docs/cloud.md +1 -1
- package/lib/assets/docs/datasets.md +2 -2
- package/lib/assets/docs/scenes.md +1 -1
- package/lib/assets/docs/setup.md +2 -2
- package/lib/assets/docs/traces.md +1 -1
- package/lib/assets/harbor/companion.mjs +43 -25
- package/lib/assets/harbor/driver.py +17 -3
- package/lib/assets/ui/app.js +432 -395
- package/lib/assets/ui/style.css +372 -50
- package/lib/mcp-entry.mjs +9 -5
- package/lib/worker.mjs +53 -25
- package/lib/world-server.mjs +43 -25
- package/package.json +1 -1
package/lib/assets/ui/app.js
CHANGED
|
@@ -9,7 +9,7 @@ var code = (value) => `<pre>${json(value)}</pre>`;
|
|
|
9
9
|
var mono = (value) => `<span class="mono">${h(value)}</span>`;
|
|
10
10
|
var clock = (ms = 0) => `+${String(Math.floor(ms / 6e4)).padStart(2, "0")}:${String(Math.floor(ms / 1e3) % 60).padStart(2, "0")}`;
|
|
11
11
|
var title = (s) => ({ "bad-deploy": "Bad deployment", "false-alarm": "False alarm", "flapping-monitor": "Flapping monitor", "db-disk-full": "Disk full", "status-request": "Status request" })[s.id] ?? s.title ?? s.id;
|
|
12
|
-
var badge = (text2,
|
|
12
|
+
var badge = (text2, tone2 = "") => `<span class="badge ${h(tone2)}">${h(text2)}</span>`;
|
|
13
13
|
var button = (label2, action2, value = "", cls = "") => `<button type="button" class="${cls}" data-action="${h(action2)}" data-value="${h(value)}">${h(label2)}</button>`;
|
|
14
14
|
var empty = (text2) => `<div class="empty compact">${h(text2)}</div>`;
|
|
15
15
|
var details = (name, value) => `<details><summary>${h(name)}</summary>${code(value)}</details>`;
|
|
@@ -162,7 +162,7 @@ function seedData(scene, selected) {
|
|
|
162
162
|
if (selected === "pagerduty") body2 = `<div class="seed-cards">${(s.services ?? []).map((v) => `<article class="record"><span class="small muted">Service</span><h3>${h(v.name)}</h3><p>${h(label2(v.escalation_policy))}</p>${(s.escalation_policies ?? []).filter((p) => label2(v.escalation_policy) === label2("$" + p.ref)).map((p) => `<ol>${(p.levels ?? []).map((l) => `<li>${h((l.targets ?? []).map(label2).join(", "))}${l.after ? ` \xB7 escalate after ${h(l.after)}` : ""}</li>`).join("")}</ol>`).join("")}${v.slack_channel ? `<p class="small muted">Slack \xB7 #${h(label2(v.slack_channel))}</p>` : ""}</article>`).join("")}${(s.incidents ?? []).map((i) => `<article class="record">${badge(i.status)}<h3>${h(i.title)}</h3><p>${h(label2(i.service))}</p></article>`).join("")}</div>`;
|
|
163
163
|
return `<h2>${h(toolName(selected))}</h2>${body2 || empty("No data seeded")}${details("Full starting data", s)}${selected === "datadog" ? details("Generated telemetry definitions", { metrics: scene.world_rules?.metrics, logs: scene.world_rules?.logs, monitors: scene.world_rules?.monitors }) : ""}`;
|
|
164
164
|
}
|
|
165
|
-
var countLabel = (
|
|
165
|
+
var countLabel = (count2, noun, plural = noun + "s") => `${count2} ${count2 === 1 ? noun : plural}`;
|
|
166
166
|
function agentLabel(agent, all) {
|
|
167
167
|
const twins = all.filter((other) => other.name === agent.name);
|
|
168
168
|
if (twins.length < 2) return String(agent.name);
|
|
@@ -361,9 +361,10 @@ function checkFocus(o) {
|
|
|
361
361
|
}
|
|
362
362
|
return focus;
|
|
363
363
|
}
|
|
364
|
-
function peopleSection(world) {
|
|
364
|
+
function peopleSection(world, kit = false) {
|
|
365
365
|
const persons = list(world.people ?? world.configuration?.people);
|
|
366
366
|
if (!persons.length) return "";
|
|
367
|
+
if (kit) return `<section class="k-card"><div class="k-card-head"><h2>People \xB7 ${persons.length}</h2></div><div class="k-scroll" role="region" aria-label="People" tabindex="0"><table class="k-table mid"><thead><tr><th scope="col">Person</th><th scope="col">Role</th><th scope="col" class="num">Facts</th><th scope="col">Decides</th></tr></thead><tbody>${persons.map((person2) => `<tr><td>${h(String(person2.name ?? person2.ref ?? "Person"))}</td><td>${h(String(person2.role ?? "\u2014"))}</td><td class="num">${list(person2.knows).length}</td><td>${h(list(person2.decides).map((decision) => String(decision.id)).join(", ") || "\u2014")}</td></tr>`).join("")}</tbody></table></div></section>`;
|
|
367
368
|
return `<section class="world-people"><div class="ww-section-heading"><h2>People</h2><span>${persons.length}</span></div><div class="world-people-list">${persons.map((person2) => {
|
|
368
369
|
const facts2 = list(person2.knows).length, decides = list(person2.decides).map((decision) => String(decision.id));
|
|
369
370
|
return `<article class="world-person"><strong>${h(String(person2.name ?? person2.ref ?? "Person"))}</strong><span class="muted">${h(String(person2.role ?? ""))}</span><span>${facts2} ${facts2 === 1 ? "fact" : "facts"}${decides.length ? ` \xB7 decides ${h(decides.join(", "))}` : ""}</span></article>`;
|
|
@@ -525,8 +526,6 @@ function glyph(kind, size = 16, label2) {
|
|
|
525
526
|
return `<svg class="c-glyph c-${kind}" width="${size}" height="${size}" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" ${label2 ? `role="img" aria-label="${h(label2)}"` : 'aria-hidden="true"'}><circle cx="8" cy="8" r="6.4"${s.dash ? ` stroke-dasharray="${s.dash}"` : ""}/><path d="${s.path}"/></svg>`;
|
|
526
527
|
}
|
|
527
528
|
var statusMark = (kind, label2 = statusLabel(kind)) => `<span class="c-status c-${kind}">${glyph(kind)}<span>${h(label2)}</span></span>`;
|
|
528
|
-
var statusPill = (kind, label2 = statusLabel(kind)) => `<span class="c-pill c-${kind}">${glyph(kind, 15)}${h(label2)}</span>`;
|
|
529
|
-
var tag = (text2, tone = "neutral") => `<span class="c-tag c-tone-${tone}">${h(text2)}</span>`;
|
|
530
529
|
var COPY = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V5.5A1.5 1.5 0 0 1 6.5 4H15"/></svg>';
|
|
531
530
|
var copyButton = (value, label2) => `<button type="button" class="c-copy" data-action="copy-text" data-value="${h(value)}" aria-label="${h(label2)}" title="${h(label2)}">${COPY}</button>`;
|
|
532
531
|
var copyCommand = (command) => `<div class="c-command"><code>${h(command)}</code>${copyButton(command, "Copy command")}</div>`;
|
|
@@ -535,9 +534,8 @@ function shortId(id, keep = 8) {
|
|
|
535
534
|
return id.length > prefix.length + keep + 2 ? `${prefix}\u2026${id.slice(-keep)}` : id;
|
|
536
535
|
}
|
|
537
536
|
var facts = (items, label2 = "Facts") => `<dl class="c-facts" aria-label="${h(label2)}">${items.map((f) => `<div><dt>${h(f.label)}</dt><dd class="c-fact-value${f.mono ? " mono" : ""}"${f.title ? ` title="${h(f.title)}"` : ""}>${f.html ?? h(f.value)}</dd>${f.sub ? `<dd class="c-fact-sub">${h(f.sub)}</dd>` : ""}</div>`).join("")}</dl>`;
|
|
538
|
-
var strip = (states, label2) => `<span class="c-strip${states.length > 12 ? " dense" : ""}" role="img" aria-label="${h(label2)}">${states.map((s) => `<i class="c-seg ${h(s)}"></i>`).join("")}</span>`;
|
|
539
537
|
var stateCard = (title2, bodyHtml = "", actionHtml = "", kind = "empty") => `<section class="c-state c-state-${h(kind)}"><strong>${h(title2)}</strong>${bodyHtml ? `<p>${bodyHtml}</p>` : ""}${actionHtml}</section>`;
|
|
540
|
-
var skeletonRows = (
|
|
538
|
+
var skeletonRows = (count2) => `<div class="c-skeleton" aria-busy="true" aria-label="Loading">${Array.from({ length: count2 }, () => "<div><i></i><i></i><i></i></div>").join("")}</div>`;
|
|
541
539
|
var MINUTE = 6e4;
|
|
542
540
|
var HOUR2 = 36e5;
|
|
543
541
|
var DAY2 = 864e5;
|
|
@@ -582,13 +580,10 @@ function duration(ms) {
|
|
|
582
580
|
if (s < 3600) return `${Math.floor(s / 60)} m ${String(s % 60).padStart(2, "0")} s`;
|
|
583
581
|
return `${Math.floor(s / 3600)} h ${String(Math.floor(s / 60) % 60).padStart(2, "0")} m`;
|
|
584
582
|
}
|
|
585
|
-
function median(values, at2 = 0.5) {
|
|
586
|
-
const sorted = values.filter(Number.isFinite).sort((a, b) => a - b);
|
|
587
|
-
return sorted.length ? sorted[Math.min(sorted.length - 1, Math.floor((sorted.length - 1) * at2 + 0.5))] : void 0;
|
|
588
|
-
}
|
|
589
583
|
|
|
590
584
|
// frontend/src/runs-page.ts
|
|
591
585
|
var SOURCES = { console: "Console", cli: "CLI", ci: "CI", cloud: "Cloud" };
|
|
586
|
+
var TARGETS = { local: "Local", docker: "Docker", hosted: "Hosted", cloud: "Cloud" };
|
|
592
587
|
var RANGES = { "24h": ["24 h", 864e5], "7d": ["7 d", 7 * 864e5], "30d": ["30 d", 30 * 864e5] };
|
|
593
588
|
var PAGE = 25;
|
|
594
589
|
function originLabel(origin) {
|
|
@@ -602,10 +597,6 @@ function whereKey(origin) {
|
|
|
602
597
|
return source === "cloud" || target === "cloud" ? "cloud" : source === "ci" ? "ci" : target === "docker" ? "docker" : target === "hosted" ? "hosted" : source === "console" || !source ? "console" : "local";
|
|
603
598
|
}
|
|
604
599
|
var WHERE = { cloud: "Cloud", ci: "CI", local: "Local", docker: "Docker", hosted: "Hosted", console: "Console" };
|
|
605
|
-
function whereLabel(origin) {
|
|
606
|
-
const commit = origin?.commit ? `${String(origin.commit).slice(0, 7)}${origin.dirty ? " + changes" : ""}` : "";
|
|
607
|
-
return [WHERE[whereKey(origin)], commit].filter(Boolean).join(" \xB7 ");
|
|
608
|
-
}
|
|
609
600
|
function runCounts(run) {
|
|
610
601
|
const summary = run.summary, tasks = run.tasks ?? [], attempts = run.attempts ?? [];
|
|
611
602
|
const verified = summary?.verdictVersion === 2 ? summary.counts : void 0;
|
|
@@ -635,25 +626,20 @@ function runTitle(run) {
|
|
|
635
626
|
if (tasks.length === 1) return shortPrompt(tasks[0].prompt) || String(tasks[0].title || batchTitle(run));
|
|
636
627
|
return tasks.length ? `${tasks.length} tests` : batchTitle(run);
|
|
637
628
|
}
|
|
638
|
-
var
|
|
639
|
-
function runRef(run) {
|
|
640
|
-
const tasks = run.tasks ?? [];
|
|
641
|
-
const test = tasks.length === 1 ? cliRun(run) ? String(tasks[0].id) : String(run.test?.name ?? "") : tasks.length > 1 ? `${tasks.length} tests` : "";
|
|
642
|
-
return [shortId(String(run.id)), test].filter(Boolean).join(" \xB7 ");
|
|
643
|
-
}
|
|
629
|
+
var productionBadge = (text2, tone2 = "neutral") => `<span class="k-badge ${tone2 === "pass" ? "pass" : tone2 === "fail" ? "fail" : tone2 === "warn" ? "none" : ""}">${h(text2)}</span>`;
|
|
644
630
|
function productionTag(reproduction) {
|
|
645
631
|
const rows3 = Array.isArray(reproduction) ? reproduction.filter((r) => r && typeof r === "object") : [];
|
|
646
632
|
if (!rows3.length) return "";
|
|
647
|
-
const
|
|
648
|
-
const again =
|
|
633
|
+
const count2 = (verdict) => rows3.filter((r) => r.verdict === verdict).length;
|
|
634
|
+
const again = count2("reproduced") + count2("partly") + count2("crashed"), fixed = count2("not-reproduced"), differs = count2("differs");
|
|
649
635
|
if (rows3.length === 1) {
|
|
650
|
-
const [text2,
|
|
651
|
-
return
|
|
636
|
+
const [text2, tone2] = { reproduced: ["Same failure", "fail"], partly: ["Partly the same", "fail"], crashed: ["Agent crashed", "fail"], "not-reproduced": ["Fixed", "pass"], matches: ["Matches production", "pass"], differs: ["New failure", "warn"], unknown: ["Production ungraded", "neutral"], ungraded: ["Not compared", "neutral"] }[String(rows3[0].verdict)] ?? ["Not compared", "neutral"];
|
|
637
|
+
return productionBadge(text2, tone2);
|
|
652
638
|
}
|
|
653
|
-
if (again) return
|
|
654
|
-
if (differs) return
|
|
655
|
-
if (fixed) return
|
|
656
|
-
return
|
|
639
|
+
if (again) return productionBadge(`${again} of ${rows3.length} fail again`, "fail");
|
|
640
|
+
if (differs) return productionBadge(`${differs} new ${differs === 1 ? "failure" : "failures"}`, "warn");
|
|
641
|
+
if (fixed) return productionBadge(`${fixed} of ${rows3.length} fixed`, "pass");
|
|
642
|
+
return count2("matches") === rows3.length ? productionBadge("Matches production", "pass") : productionBadge("Not compared", "neutral");
|
|
657
643
|
}
|
|
658
644
|
function baselineNote(run) {
|
|
659
645
|
const comparison = run.comparison;
|
|
@@ -680,82 +666,27 @@ function runMs(run, now) {
|
|
|
680
666
|
function view(run, now) {
|
|
681
667
|
return { run, status: runStatus(run), title: runTitle(run), agent: String(run.agentName ?? run.entries?.[0]?.agentName ?? ""), command: String(run.agentCommand ?? ""), where: whereKey(run.origin), ms: runMs(run, now) };
|
|
682
668
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
function
|
|
695
|
-
const run =
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
const run = item.run, c = runCounts(run), states = attemptStates(run);
|
|
701
|
-
const counted = `${c.finished} / ${c.total}`, label2 = `${counted} attempts finished${c.graded ? `, ${c.passed} passed` : ""}${c.invalid ? `, ${c.invalid} invalid` : ""}`;
|
|
702
|
-
return `<a class="rt-row" href="/playgrounds/${encodeURIComponent(String(run.id))}" data-nav><span class="rt-result">${statusMark(item.status)}</span><span class="rt-test"><span class="rt-title" title="${h(item.title)}">${h(item.title)}</span><span class="rt-ref mono">${h(runRef(run))}</span></span><span class="rt-agent"><span class="rt-agent-name">${h(item.agent || "\u2014")}</span>${item.command ? `<span class="c-note mono rt-command" title="${h(item.command)}">${h(item.command)}</span>` : ""}<span class="c-note">${h(whereLabel(run.origin))}</span></span><span class="rt-attempts">${strip(states, label2)}<span class="c-note">${h(counted)}</span></span><span class="rt-passed">${rateCell(item)}</span><span class="rt-prod">${productionTag(run.reproduction) || '<span class="c-note">\u2014</span>'}</span><span class="rt-started">${startedCell(item, now)}</span></a>`;
|
|
669
|
+
var resultClass = (state) => state === "passed" ? "pass" : state === "failed" ? "fail" : state === "running" ? "run" : state === "queued" ? "queue" : "none";
|
|
670
|
+
var resultLabel = (state) => state === "done" || state === "ungraded" ? "No result \xB7 Ungraded" : statusLabel(state);
|
|
671
|
+
var resultBadge = (state) => `<span class="k-badge ${["passed", "failed"].includes(state) ? resultClass(state) : ["running", "queued", "stopped"].includes(state) ? "" : "none"}">${h(resultLabel(state))}</span>`;
|
|
672
|
+
var resultIcon = (state) => ["running", "queued"].includes(state) ? `<span class="k-sq ${resultClass(state)}" role="img" aria-label="${h(resultLabel(state))}"></span>` : `<span class="k-icon ${resultClass(state)}" role="img" aria-label="${h(resultLabel(state))}"></span>`;
|
|
673
|
+
function attemptSquares(states, links = [], labels = []) {
|
|
674
|
+
return `<span class="k-squares">${states.map((state, i) => {
|
|
675
|
+
const label2 = labels[i] ?? `Attempt ${i + 1}: ${resultLabel(state)}`;
|
|
676
|
+
const attrs = `class="k-sq ${resultClass(state)}" role="img" aria-label="${h(label2)}" title="${h(label2)}"`;
|
|
677
|
+
return links[i] ? `<a ${attrs} href="${h(links[i])}" data-nav></a>` : `<span ${attrs}></span>`;
|
|
678
|
+
}).join("")}</span>`;
|
|
679
|
+
}
|
|
680
|
+
function row(item, now, compared) {
|
|
681
|
+
const run = item.run, c = runCounts(run), baseline = baselineNote(run);
|
|
682
|
+
const attemptLinks = whereKey(run.origin) === "cloud" && !terminal(run.status) ? [] : (run.attempts ?? []).map((a) => a.id && a.taskId ? `/playgrounds/${encodeURIComponent(String(run.id))}?task=${encodeURIComponent(String(a.taskId))}&attempt=${encodeURIComponent(String(a.id))}` : void 0);
|
|
683
|
+
const pending = item.status === "queued" ? queueLabel(run.queue) || "Queued" : item.status === "running" ? "Graded as attempts finish" : "";
|
|
684
|
+
const note = [pending, c.graded && !c.requested ? "Rerun to record requested attempts" : "", c.invalid ? `${c.invalid} invalid` : "", c.skipped ? `${c.skipped} skipped` : "", !c.graded && !pending && !c.invalid && !c.skipped ? "No checks evaluated" : ""].filter(Boolean).join(" \xB7 ");
|
|
685
|
+
return `<tr><td class="wrap"><a class="rt-row" href="/playgrounds/${encodeURIComponent(String(run.id))}" data-nav><span class="rt-result"><span class="c-${item.status}">${resultBadge(item.status)}</span></span><span class="k-name">${h(run.origin?.branch || item.title)}</span><span class="k-id">#${h(shortId(String(run.id)))}</span></a></td><td class="wrap"><span class="k-name">${h(item.agent || "\u2014")}</span>${item.command ? `<div class="k-id" title="${h(item.command)}">${h(item.command)}</div>` : ""}</td><td>${attemptSquares(attemptStates(run), attemptLinks)}<div class="k-meta">${h(`${c.finished} / ${c.total} done`)}</div></td><td class="num">${c.graded && c.requested ? `${c.passed}/${c.requested}` : "\u2014"}${note ? `<div class="k-meta">${h(note)}</div>` : ""}</td>` + (compared ? `<td>${baseline ? `<span class="k-${baseline.tone === "fail" ? "fail-text" : baseline.tone === "pass" ? "pass-text" : "muted"}">${h(baseline.text)}</span>` : "\u2014"}</td>` : "") + `<td class="wrap k-meta">${h(originLabel(run.origin) || "Console")}</td><td class="wrap num k-meta">${when(run.createdAt, now)}<div>${h(item.status === "queued" ? "Queued" : duration(item.ms))}</div></td></tr>`;
|
|
703
686
|
}
|
|
704
687
|
function runsTable(runs, options = {}) {
|
|
705
|
-
const now = options.now ?? Date.now();
|
|
706
|
-
return `<
|
|
707
|
-
}
|
|
708
|
-
function failingTests(rows3) {
|
|
709
|
-
const seen = /* @__PURE__ */ new Set(), failing = [];
|
|
710
|
-
for (const item of rows3) {
|
|
711
|
-
if (!terminal(item.run.status)) continue;
|
|
712
|
-
const attempts = item.run.attempts ?? [];
|
|
713
|
-
for (const task of item.run.tasks ?? []) {
|
|
714
|
-
const key = `${item.run.test?.id ?? ""}:${task.id}`;
|
|
715
|
-
if (seen.has(key)) continue;
|
|
716
|
-
seen.add(key);
|
|
717
|
-
if (attempts.some((a) => a.taskId === task.id && a.outcome === "failed")) failing.push([shortPrompt(task.prompt) || String(task.title || task.id), item.agent]);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
return failing;
|
|
721
|
-
}
|
|
722
|
-
function stats(rows3, range, now) {
|
|
723
|
-
const done = rows3.filter((r) => terminal(r.run.status));
|
|
724
|
-
const passedRuns = rows3.filter((r) => r.status === "passed").length, failedRuns = rows3.filter((r) => r.status === "failed").length;
|
|
725
|
-
const counts = done.map((r) => runCounts(r.run)).filter((c) => c.graded && c.requested);
|
|
726
|
-
const requested = counts.reduce((n, c) => n + c.requested, 0), passed = counts.reduce((n, c) => n + c.passed, 0);
|
|
727
|
-
const failing = failingTests(rows3);
|
|
728
|
-
const times = done.map((r) => r.ms).filter((ms) => ms !== void 0);
|
|
729
|
-
const cell2 = (label2, value, sub, tone = "") => `<div class="rs-cell"><span>${h(label2)}</span><strong${tone ? ` class="c-tone-${tone}"` : ""}>${h(value)}</strong><small>${h(sub)}</small></div>`;
|
|
730
|
-
return `<section class="rs-strip" aria-label="Summary of the runs shown">` + cell2("Runs", String(rows3.length), `${passedRuns} passed \xB7 ${failedRuns} failed \xB7 ${rows3.length - passedRuns - failedRuns} other`) + cell2("Attempts passed", requested ? `${Math.round(passed / requested * 100)}%` : "\u2014", requested ? `${passed} of ${requested} attempts` : "no graded attempts") + cell2("Tests failing now", String(failing.length), failing.length ? failing[0].filter(Boolean).join(" \xB7 ") : "none", failing.length ? "fail" : "") + cell2("Median run time", duration(median(times)), times.length > 1 ? `p90 ${duration(median(times, 0.9))}` : times.length ? "one run" : "no finished runs") + perDay(rows3, range, now) + "</section>";
|
|
731
|
-
}
|
|
732
|
-
function perDay(rows3, range, now) {
|
|
733
|
-
const hourly = range === "24h", size = hourly ? 36e5 : 864e5;
|
|
734
|
-
const startOfBucket = (ms) => {
|
|
735
|
-
const d = new Date(ms);
|
|
736
|
-
return hourly ? Math.floor(ms / size) * size : Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
737
|
-
};
|
|
738
|
-
const count = hourly ? 24 : range === "7d" ? 7 : 30, last = startOfBucket(now);
|
|
739
|
-
const buckets = Array.from({ length: count }, (_, i) => ({ at: last - (count - 1 - i) * size, passed: 0, failed: 0, other: 0 }));
|
|
740
|
-
for (const item of rows3) {
|
|
741
|
-
const at2 = timeOf(item.run.createdAt), bucket = Number.isFinite(at2) ? buckets.find((b) => b.at === startOfBucket(at2)) : void 0;
|
|
742
|
-
if (bucket) bucket[item.status === "passed" ? "passed" : item.status === "failed" ? "failed" : "other"] += 1;
|
|
743
|
-
}
|
|
744
|
-
const W = 10, H = 52, most = Math.max(1, ...buckets.map((b) => b.passed + b.failed + b.other));
|
|
745
|
-
const name = (b) => hourly ? `${new Date(b.at).toISOString().slice(11, 16)} UTC` : utcDay(b.at);
|
|
746
|
-
const bars = buckets.map((b, i) => {
|
|
747
|
-
let y = H;
|
|
748
|
-
const parts = ["passed", "failed", "other"].map((kind) => {
|
|
749
|
-
if (!b[kind]) return "";
|
|
750
|
-
const height = Math.max(2, Math.round(b[kind] / most * H));
|
|
751
|
-
y -= height;
|
|
752
|
-
return `<rect class="${kind}" x="${i * W + 1}" y="${y}" width="${W - 2}" height="${height}"/>`;
|
|
753
|
-
}).join("");
|
|
754
|
-
return parts ? `<g><title>${h(`${name(b)}: ${b.passed} passed, ${b.failed} failed, ${b.other} other`)}</title>${parts}</g>` : "";
|
|
755
|
-
}).join("");
|
|
756
|
-
const total = buckets.reduce((n, b) => n + b.passed + b.failed + b.other, 0), span = hourly ? "the last 24 hours" : `the last ${count} days`;
|
|
757
|
-
const labels = count === 7 ? buckets.map(name) : [name(buckets[0]), name(buckets[Math.floor(count / 2)]), name(buckets[count - 1])];
|
|
758
|
-
return `<div class="rs-cell rs-days"><div class="rs-days-head"><span>${hourly ? "Runs per hour" : "Runs per day"}</span><span class="rs-legend"><i class="passed"></i>Passed<i class="failed"></i>Failed<i class="other"></i>Other</span></div><svg class="rs-chart" viewBox="0 0 ${count * W} ${H}" preserveAspectRatio="none" role="img" aria-label="${h(`${total} ${total === 1 ? "run" : "runs"} over ${span}`)}"><line class="axis" x1="0" y1="${H - 0.5}" x2="${count * W}" y2="${H - 0.5}"/>${bars}</svg><div class="rs-labels${count === 7 ? " even" : ""}">${labels.map((label2) => `<span>${h(label2)}</span>`).join("")}</div></div>`;
|
|
688
|
+
const now = options.now ?? Date.now(), compared = runs.some((run) => baselineNote(run));
|
|
689
|
+
return `<section class="k-card runs-v2" aria-label="Runs"><div class="k-scroll"><table class="k-table wider"><thead><tr><th>Run</th><th>Agent</th><th>Results</th><th class="num">Passed</th>${compared ? "<th>vs main</th>" : ""}<th>From</th><th class="num">When</th></tr></thead><tbody>${runs.map((run) => row(view(run, now), now, compared)).join("")}</tbody></table></div></section>`;
|
|
759
690
|
}
|
|
760
691
|
function filterUrl(filters, change) {
|
|
761
692
|
const next = { ...filters, ...change }, params = new URLSearchParams();
|
|
@@ -765,7 +696,7 @@ function filterUrl(filters, change) {
|
|
|
765
696
|
var RESULT_ORDER = ["passed", "failed", "invalid", "skipped", "running", "queued", "stopped", "error", "ungraded"];
|
|
766
697
|
function runsPage(runs, filters, options = {}) {
|
|
767
698
|
const now = options.now ?? Date.now(), range = RANGES[filters.range ?? ""] ? filters.range : "";
|
|
768
|
-
const head2 = (meta2) => `<header class="
|
|
699
|
+
const head2 = (meta2) => `<header class="k-head"><div class="k-title"><h1>Runs</h1>${meta2 ? `<p class="k-sub">${h(meta2)}</p>` : ""}</div><div class="k-actions"><nav class="k-seg" aria-label="Time range">${[["", "All"], ...Object.entries(RANGES).map(([key, [label2]]) => [key, label2])].map(([key, label2]) => `<a href="${h(filterUrl(filters, { range: key, limit: void 0 }))}" data-nav${key === range ? ' aria-current="page"' : ""}>${h(label2)}</a>`).join("")}</nav>${copyCommand("ancha run")}</div></header>`;
|
|
769
700
|
if (!runs.length) return head2("") + stateCard("No runs yet", options.emptyHtml ?? "", copyCommand("ancha run"));
|
|
770
701
|
const all = runs.map((run) => view(run, now)).sort((a, b) => timeOf(b.run.createdAt) - timeOf(a.run.createdAt) || String(b.run.id).localeCompare(String(a.run.id)));
|
|
771
702
|
const inRange = range ? all.filter((item) => now - timeOf(item.run.createdAt) <= RANGES[range][1]) : all;
|
|
@@ -773,18 +704,18 @@ function runsPage(runs, filters, options = {}) {
|
|
|
773
704
|
const query = String(filters.q ?? "").trim().toLowerCase();
|
|
774
705
|
const matches = (item) => !query || [item.title, item.run.id, item.agent, item.command, item.run.test?.name, ...(item.run.tasks ?? []).flatMap((t) => [t.id, t.title, t.prompt])].some((v) => String(v ?? "").toLowerCase().includes(query));
|
|
775
706
|
const shown = inRange.filter((item) => matches(item) && (!filters.agent || item.agent === filters.agent || item.run.agentId === filters.agent || item.run.entries?.some((entry) => entry.agentId === filters.agent)) && (!filters.result || item.status === filters.result) && (!filters.where || item.where === filters.where) && (!filters.commit || item.run.origin?.commit === filters.commit) && (!filters.source || item.run.origin?.source === filters.source) && (!filters.target || item.run.origin?.target === filters.target));
|
|
776
|
-
const select = (name, label2, choices, all2 = "All") => `<label class="
|
|
707
|
+
const select = (name, label2, choices, all2 = "All") => `<label class="s059-filter"><span>${h(label2)}</span><select class="k-field" name="${name}" data-run-filter><option value="">${h(all2)}</option>${choices.map(([value, text2]) => `<option value="${h(value)}" ${filters[name] === value ? "selected" : ""}>${h(text2)}</option>`).join("")}</select></label>`;
|
|
777
708
|
const commits = values((item) => item.run.origin?.commit, filters.commit);
|
|
778
709
|
const named2 = filters.agent ? all.find((item) => item.run.agentId === filters.agent)?.agent : void 0;
|
|
779
710
|
const agentChoices = values((item) => item.agent, named2 ? void 0 : filters.agent).map((v) => [v === named2 ? filters.agent : v, v]);
|
|
780
|
-
const legacy = ["
|
|
781
|
-
const bar = `<form class="runs-filters" aria-label="Filter runs" role="search">${legacy}<
|
|
711
|
+
const legacy = ["range"].filter((key) => filters[key]).map((key) => `<input type="hidden" name="${key}" value="${h(filters[key])}">`).join("");
|
|
712
|
+
const bar = `<form class="runs-filters k-filters" aria-label="Filter runs" role="search">${legacy}<input class="k-field grow" aria-label="Search runs" type="search" name="q" value="${h(filters.q ?? "")}" placeholder="Search by request, test or run id" data-run-search>` + select("agent", "Agent", agentChoices) + select("result", "Result", RESULT_ORDER.filter((kind) => all.some((item) => item.status === kind) || filters.result === kind).map((kind) => [kind, statusLabel(kind)])) + select("where", "Where", values((item) => item.where, filters.where).map((v) => [v, WHERE[v] ?? v])) + select("source", "Source", values((item) => item.run.origin?.source, filters.source).map((v) => [v, SOURCES[v] ?? v])) + select("target", "Target", values((item) => item.run.origin?.target, filters.target).map((v) => [v, TARGETS[v] ?? v])) + (commits.length ? select("commit", "Commit", commits.map((v) => [v, v.slice(0, 7)]), "Any") : "") + "</form>";
|
|
782
713
|
const meta = range ? `${inRange.length} in the last ${RANGES[range][0].replace(" h", " hours").replace(" d", " days")}` : `${all.length} ${all.length === 1 ? "run" : "runs"}`;
|
|
783
714
|
const filtered = Boolean(query || filters.agent || filters.result || filters.where || filters.commit || filters.source || filters.target);
|
|
784
|
-
if (!shown.length) return
|
|
715
|
+
if (!shown.length) return `<div class="k-page">` + head2(meta) + bar + stateCard(filtered ? "No runs match these filters" : "No runs in this range", filtered ? h([query && `\u201C${filters.q}\u201D`, filters.agent && `Agent: ${named2 ?? filters.agent}`, filters.result && `Result: ${RESULT_ORDER.includes(filters.result) ? statusLabel(filters.result) : filters.result}`, filters.where && `Where: ${WHERE[filters.where] ?? filters.where}`, filters.commit && `Commit: ${filters.commit.slice(0, 7)}`].filter(Boolean).join(" \xB7 ")) : "", `<a class="button-link" href="${h(filtered ? filterUrl({ range: filters.range }, {}) : filterUrl(filters, { range: "" }))}" data-nav>${filtered ? "Clear filters" : "Show all runs"}</a>`, "filtered") + "</div>";
|
|
785
716
|
const limit = Math.max(PAGE, Number(filters.limit) || PAGE), page = shown.slice(0, limit);
|
|
786
717
|
const more = shown.length > page.length ? `<a class="button-link" href="${h(filterUrl(filters, { limit: limit + PAGE }))}" data-nav>Load ${Math.min(PAGE, shown.length - page.length)} more</a>` : "";
|
|
787
|
-
return
|
|
718
|
+
return `<div class="k-page">` + head2(meta) + bar + runsTable(page.map((item) => item.run), { now }) + `<div class="rt-foot"><span class="c-note">${page.length} of ${shown.length} ${shown.length === 1 ? "run" : "runs"}, newest first</span>${more}</div></div>`;
|
|
788
719
|
}
|
|
789
720
|
|
|
790
721
|
// frontend/src/experience.ts
|
|
@@ -807,7 +738,7 @@ var usableMs = (value) => {
|
|
|
807
738
|
return Number.isFinite(ms) && simIso(ms) ? ms : NaN;
|
|
808
739
|
};
|
|
809
740
|
var ordered = (values, key) => values.slice().sort((a, b) => (milliseconds(a[key]) || 0) - (milliseconds(b[key]) || 0));
|
|
810
|
-
var pill = (value,
|
|
741
|
+
var pill = (value, tone2 = "") => `<span class="pill ${h(tone2)}">${h(value)}</span>`;
|
|
811
742
|
var empty2 = (value) => `<p class="muted experience-empty">${h(value)}</p>`;
|
|
812
743
|
var heading = (name, context = "", status = "") => `<header class="tool-title"><div><h2>${h(name)}</h2>${context ? `<span class="muted">${h(context)}</span>` : ""}</div>${status}</header>`;
|
|
813
744
|
function href(base, query) {
|
|
@@ -1024,7 +955,7 @@ function projectedTool(o, tool, options) {
|
|
|
1024
955
|
const columns = active?.columns ?? [], records2 = list2(active?.rows);
|
|
1025
956
|
const identifier = (key) => /(?:^|[_-])(id|key|uuid|ref|sha)(?:$|[_-])/i.test(key) || /(?:Id|Key|Uuid|Sha)$/.test(key);
|
|
1026
957
|
const numeric = (key) => records2.some((row2) => typeof row2[key] === "number") && records2.every((row2) => row2[key] == null || typeof row2[key] === "number");
|
|
1027
|
-
return `<section class="tool-surface records-surface">${options.embedded ? "" : heading(toolName(tool))}${tables.length ? `<nav class="tool-nav records-collections" aria-label="Record collections">${tables.map((t) => `<a data-nav class="${t === active ? "active" : ""}" ${t === active ? 'aria-current="page"' : ""} href="${h(href(options.baseHref || "", { view: "tools", tool, resource: t.title, conversation: null }))}"><span>${h(t.title)}</span><span class="records-count">${h(t.total)}</span></a>`).join("")}</nav>` : ""}${active ? `<div class="tool-section-title"><h3>${h(active.title)}</h3><span class="muted">${Number(active.total)} records</span></div><div class="table-wrap records-grid" role="region" aria-label="${h(active.title)} records" tabindex="0"><table><thead class="records-frozen-head"><tr>${columns.map((key) => `<th scope="col" class="${numeric(key) ? "num" : ""}"><code>${h(key)}</code></th>`).join("")}</tr></thead><tbody>${records2.map((row2) => `<tr>${columns.map((key) => {
|
|
958
|
+
return `<section class="tool-surface records-surface">${options.embedded ? "" : heading(toolName(tool))}${tables.length ? `<nav class="tool-nav records-collections" aria-label="Record collections">${tables.map((t) => `<a data-nav class="${t === active ? "active" : ""}" ${t === active ? 'aria-current="page"' : ""} href="${h(href(options.baseHref || "", { view: "tools", tool, resource: t.title, conversation: null }))}"><span>${h(t.title)}</span><span class="records-count">${h(t.total)}</span></a>`).join("")}</nav>` : ""}${active ? `<div class="tool-section-title"><h3>${h(active.title)}</h3><span class="muted">${Number(active.total)} records</span></div><div class="table-wrap records-grid" role="region" aria-label="${h(active.title)} records" tabindex="0"><table${options.kit ? ' class="k-table"' : ""}><thead class="records-frozen-head"><tr>${columns.map((key) => `<th scope="col" class="${numeric(key) ? "num" : ""}"><code>${h(key)}</code></th>`).join("")}</tr></thead><tbody>${records2.map((row2) => `<tr>${columns.map((key) => {
|
|
1028
959
|
const value = cell(row2[key]) || "\u2014", mono2 = identifier(key), raw = text(row2[key]);
|
|
1029
960
|
return `<td class="${mono2 ? "mono " : ""}${typeof row2[key] === "number" ? "num" : ""}"><div class="records-cell"><span class="records-value" title="${h(raw || value)}">${h(value)}</span>${mono2 && raw ? copyButton(raw, "Copy " + key) : ""}</div></td>`;
|
|
1030
961
|
}).join("")}</tr>`).join("")}</tbody></table>${!records2.length ? stateCard("No records in this collection", "Select another collection to browse its records.") : ""}</div>${active.rows.length < active.total ? `<p class="muted small">Showing ${active.rows.length} of ${active.total} records.</p>` : ""}` : stateCard("No records in this capture")}${conversations.length ? `<div class="transcript-list">${conversations.map((c, index) => nav(c.title, options.baseHref || "", { view: "tools", tool, conversation: index }, "transcript-link")).join("")}</div>` : ""}</section>`;
|
|
@@ -1093,7 +1024,7 @@ function traceDescription(t) {
|
|
|
1093
1024
|
if (filename) result.push(filename);
|
|
1094
1025
|
}
|
|
1095
1026
|
if (t.service === "tools") {
|
|
1096
|
-
const fields2 = (value,
|
|
1027
|
+
const fields2 = (value, count2) => value && typeof value === "object" && !Array.isArray(value) ? Object.entries(value).filter(([, v]) => v === null || ["string", "number", "boolean"].includes(typeof v)).slice(0, count2).map(([k, v]) => `${k}: ${String(v).slice(0, 60)}`).join(", ") : "";
|
|
1097
1028
|
const args = fields2(t.request?.args, 3), answer = fields2(t.response?.result, 4);
|
|
1098
1029
|
if (args) result.push(args);
|
|
1099
1030
|
if (answer) result.push(`returned ${answer}`);
|
|
@@ -1204,6 +1135,7 @@ function attemptResult(observation2, scene, selectedCheck, baseHref = "") {
|
|
|
1204
1135
|
}
|
|
1205
1136
|
|
|
1206
1137
|
// frontend/src/attempt-workspace.ts
|
|
1138
|
+
var count = (n, noun) => `${n} ${noun}${n === 1 ? "" : "s"}`;
|
|
1207
1139
|
var readOnlyRun = (batch) => batch.origin?.stored === true || batch.origin?.mirrored === true || ["cli", "ci", "pytest"].includes(batch.origin?.source);
|
|
1208
1140
|
var records = (value) => Array.isArray(value) ? value.filter((item) => item && typeof item === "object") : [];
|
|
1209
1141
|
var basePath = (batch) => "/playgrounds/" + encodeURIComponent(String(batch.id));
|
|
@@ -1269,25 +1201,6 @@ function executionSummary(attempts, requested = attempts.length) {
|
|
|
1269
1201
|
var percent = (part, whole) => whole ? `${Math.round(part / whole * 100)}%` : "\u2014";
|
|
1270
1202
|
var medianTime = (attempts) => duration(executionSummary(attempts).medianMs);
|
|
1271
1203
|
var hasChecks = (tasks) => Array.isArray(tasks) && tasks.some((task) => Array.isArray(task?.checks) && task.checks.length > 0);
|
|
1272
|
-
function summaryWidgets(attempts, checked = false, requested = attempts.length) {
|
|
1273
|
-
const s = executionSummary(attempts, requested);
|
|
1274
|
-
const cell2 = (label2, value, note, tone2 = "") => `<div class="rs-stat${tone2 ? " " + tone2 : ""}"><span>${h(label2)}</span><strong>${h(value)}</strong><small>${h(note)}</small></div>`;
|
|
1275
|
-
const progress = s.active || s.queued ? [s.active - s.starting && `${s.active - s.starting} running`, s.starting && `${s.starting} starting`, s.queued && `${s.queued} queued`].filter(Boolean).join(" \xB7 ") : s.error ? `${s.error} ended with an error` : s.total ? "All finished" : "No attempts yet";
|
|
1276
|
-
const invalid = s.invalid ? `${s.invalid} invalid (harness), not passed` : "", skipped = s.skipped ? `${s.skipped} skipped` : "";
|
|
1277
|
-
const rate = s.graded ? [`${s.passed} of ${s.total} requested passed`, invalid, skipped].filter(Boolean).join(" \xB7 ") : !s.total ? "No attempts yet" : !checked ? "Add checks to a task to grade it" : s.active || s.queued ? "Graded as attempts finish" : [invalid, skipped].filter(Boolean).join(" \xB7 ") || "No attempt could be graded";
|
|
1278
|
-
const tone = !s.graded ? "" : s.passed === s.total ? "pass" : s.passed ? "mixed" : "fail";
|
|
1279
|
-
return `<section class="run-summary" aria-label="Summary"><div class="rs-stats">${cell2("Success rate", s.graded ? percent(s.passed, s.total) : "\u2014", rate, tone)}${s.invalid ? cell2("Invalid", String(s.invalid), "Harness failures; not passed", "invalid") : ""}${cell2("Finished", `${s.finished}/${s.total}`, progress)}${cell2("Tool calls", String(s.toolCalls), s.finished ? `${(s.toolCalls / s.finished).toFixed(1)} per attempt` : "\u2014")}${cell2("Median time", duration(s.medianMs), "per attempt")}</div>${progressBar(attempts)}</section>`;
|
|
1280
|
-
}
|
|
1281
|
-
function attemptState(attempt) {
|
|
1282
|
-
const outcome = attemptOutcome(attempt);
|
|
1283
|
-
if (outcome.key !== "ungraded") return outcome.key;
|
|
1284
|
-
return ["queued", "starting", "running", "completed", "stopped", "error"].includes(attempt.status) ? attempt.status === "starting" ? "running" : attempt.status : "queued";
|
|
1285
|
-
}
|
|
1286
|
-
function progressBar(attempts) {
|
|
1287
|
-
if (!attempts.length) return "";
|
|
1288
|
-
const s = executionSummary(attempts), label2 = `${s.finished} of ${s.total} attempts finished${s.graded ? `, ${s.passed} passed, ${s.failed} failed` : ""}${s.invalid ? `, ${s.invalid} invalid` : ""}`;
|
|
1289
|
-
return `<div class="run-progress" role="img" aria-label="${h(label2)}" title="${h(label2)}">${attempts.map((a) => `<span class="seg ${attemptState(a)}"></span>`).join("")}</div>`;
|
|
1290
|
-
}
|
|
1291
1204
|
function taskOutcome(attempts, checked = false, requested = attempts.length) {
|
|
1292
1205
|
const s = executionSummary(attempts, requested);
|
|
1293
1206
|
if (s.graded) return { value: percent(s.passed, s.total), note: `${s.passed} of ${s.total} requested passed${s.invalid ? ` \xB7 ${s.invalid} invalid` : ""}`, tone: s.passed === s.total ? "pass" : s.passed ? "mixed" : "fail" };
|
|
@@ -1301,8 +1214,8 @@ function executionBadge(attempt, compact = false) {
|
|
|
1301
1214
|
const since = startingSince(attempt);
|
|
1302
1215
|
return `<span class="aw-execution active">${compact ? "Starting" : h(attemptLabel(status))} <span data-since="${since}">${elapsedLabel(since)}</span></span>`;
|
|
1303
1216
|
}
|
|
1304
|
-
const
|
|
1305
|
-
return `<span class="aw-execution ${
|
|
1217
|
+
const tone2 = status === "error" ? "error" : ["running", "starting"].includes(status) ? "active" : "neutral";
|
|
1218
|
+
return `<span class="aw-execution ${tone2}">${h(attemptLabel(status))}</span>`;
|
|
1306
1219
|
}
|
|
1307
1220
|
function outcomeBadge(attempt) {
|
|
1308
1221
|
const outcome = attemptOutcome(attempt);
|
|
@@ -1318,9 +1231,6 @@ function sentence(text2) {
|
|
|
1318
1231
|
return value;
|
|
1319
1232
|
}
|
|
1320
1233
|
}
|
|
1321
|
-
function widgets(attempts, tasks) {
|
|
1322
|
-
return summaryWidgets(attempts, hasChecks(tasks), tasks.reduce((sum2, task) => sum2 + (Number(task.attempts) || attempts.filter((attempt) => attempt.taskId === task.id).length), 0));
|
|
1323
|
-
}
|
|
1324
1234
|
function errorMessage(value) {
|
|
1325
1235
|
if (!value) return "";
|
|
1326
1236
|
const message = typeof value === "string" ? value : typeof value === "object" && value !== null && "message" in value ? String(value.message) : "";
|
|
@@ -1330,23 +1240,10 @@ function entrySections(batch) {
|
|
|
1330
1240
|
const entries = records(batch.entries);
|
|
1331
1241
|
return entries.length ? entries.map((entry) => ({ entry, tasks: tasksForEntry(batch, entry), attempts: attemptsForEntry(batch, entry) })) : [{ entry: void 0, tasks: records(batch.tasks), attempts: records(batch.attempts) }];
|
|
1332
1242
|
}
|
|
1333
|
-
function attemptMark(attempt) {
|
|
1334
|
-
const outcome = attemptOutcome(attempt);
|
|
1335
|
-
if (outcome.key !== "ungraded") return outcome.mark;
|
|
1336
|
-
return attempt.status === "error" ? "!" : ["running", "starting"].includes(attempt.status) ? "" : attempt.status === "queued" ? "" : attempt.status === "stopped" ? "\u2013" : "\u2022";
|
|
1337
|
-
}
|
|
1338
1243
|
function attemptMs(attempt) {
|
|
1339
1244
|
const ms = Number.isFinite(attempt.durationMs) ? Number(attempt.durationMs) : Date.parse(attempt.finishedAt) - Date.parse(attempt.startedAt);
|
|
1340
1245
|
return Number.isFinite(ms) && ms >= 0 ? ms : void 0;
|
|
1341
1246
|
}
|
|
1342
|
-
function markers(batch, task, attempts) {
|
|
1343
|
-
return `<div class="aw-attempt-strip" aria-label="${h(task.title || "Task")} attempts">${attempts.map((attempt) => {
|
|
1344
|
-
const state = ["queued", "starting", "running", "completed", "stopped", "error"].includes(attempt.status) ? attempt.status : "unavailable";
|
|
1345
|
-
const outcome = attemptOutcome(attempt), ms = attemptMs(attempt);
|
|
1346
|
-
const label2 = `Attempt ${attempt.number} \xB7 ${outcome.key === "ungraded" ? attemptLabel(state) : outcome.label}${ms === void 0 ? "" : ` \xB7 ${duration(ms)}`}`;
|
|
1347
|
-
return `<a data-nav class="aw-attempt-marker execution-${h(state)} outcome-${outcome.key}" href="${h(taskHref(batch, task, { attempt: attempt.id }))}" title="${h(label2)}" aria-label="${h(label2)}">${attemptMark(attempt)}</a>`;
|
|
1348
|
-
}).join("")}</div>`;
|
|
1349
|
-
}
|
|
1350
1247
|
function comparisonForm(batch, task, attempts, selected) {
|
|
1351
1248
|
if (attempts.length < 2 || readOnlyRun(batch)) return "";
|
|
1352
1249
|
const option = (a, chosen) => `<option value="${h(a.id)}" ${a.id === chosen ? "selected" : ""}>Attempt ${h(a.number)}</option>`;
|
|
@@ -1358,30 +1255,109 @@ function comparisonForm(batch, task, attempts, selected) {
|
|
|
1358
1255
|
const left = attempts[0].id, right = attempts[1].id;
|
|
1359
1256
|
return `${open}<label>Compare<select name="left">${attempts.map((a) => option(a, left)).join("")}</select></label><label>With<select name="right">${attempts.map((a) => option(a, right)).join("")}</select></label><button type="submit">Compare</button></form>`;
|
|
1360
1257
|
}
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1258
|
+
var kitActions = (html) => html.replace(/(<button[^>]*class=")([^"]*)"/g, '$1k-btn $2"');
|
|
1259
|
+
var detailRow = (label2, value) => `<div class="k-kv"><span class="k-label">${h(label2)}</span><span>${value}</span></div>`;
|
|
1260
|
+
var agentName = (batch) => String(batch.agentName ?? batch.test?.agentName ?? batch.entries?.[0]?.agentName ?? "");
|
|
1261
|
+
function agentCrumb(batch) {
|
|
1262
|
+
const name = agentName(batch);
|
|
1263
|
+
return name ? `${batch.agentId ? navLink(name, "/agents/" + encodeURIComponent(String(batch.agentId))) : `<span>${h(name)}</span>`}<span>/</span>` : "";
|
|
1264
|
+
}
|
|
1265
|
+
function runDetails(batch, tasks, attempts) {
|
|
1266
|
+
const baseline = batch.comparison?.baselineRunId, total = timeOf(batch.finishedAt) - timeOf(batch.startedAt ?? batch.createdAt);
|
|
1267
|
+
return `<section class="k-card" aria-label="Details"><h2>Details</h2>` + (agentName(batch) ? detailRow("Agent", batch.agentId ? navLink(agentName(batch), "/agents/" + encodeURIComponent(String(batch.agentId))) : h(agentName(batch))) : "") + (batch.origin?.commit ? detailRow("Commit", `<span class="k-mono">${h(String(batch.origin.commit).slice(0, 7))}${batch.origin.dirty ? " + changes" : ""}</span>`) : "") + (baseline ? detailRow("Compared with", navLink(shortId(String(baseline)), "/playgrounds/" + encodeURIComponent(String(baseline)))) : "") + detailRow("From", h(originLabel(batch.origin) || "Console")) + (batch.createdAt ? detailRow("Started", `<time datetime="${h(batch.createdAt)}" title="${h(utc(batch.createdAt))}">${h(utcClock(batch.createdAt))}<span class="k-meta"> \xB7 ${h(utcDay(batch.createdAt))}</span></time>`) : "") + (Number.isFinite(total) && total >= 0 ? detailRow("Duration", h(duration(total))) : "") + detailRow("Tests \xD7 attempts", h(`${count(tasks.length, "test")} \xB7 ${count(runCounts({ ...batch, tasks, attempts }).total, "attempt")}`)) + (Number(batch.concurrency) > 0 ? detailRow("At once", h(`${batch.concurrency} attempts`)) : "") + (batch.exitCode !== void 0 ? detailRow("Exit", h(batch.exitCode)) : "") + "</section>";
|
|
1268
|
+
}
|
|
1269
|
+
function testSquares(batch, task, attempts) {
|
|
1270
|
+
const states = attemptStates({ tasks: [task], attempts });
|
|
1271
|
+
return attemptSquares(states, attempts.map((a) => taskHref(batch, task, { attempt: a.id })), attempts.map((a) => `Attempt ${a.number}: ${resultLabel(attemptKind(a))}`));
|
|
1365
1272
|
}
|
|
1366
|
-
function
|
|
1367
|
-
const reproduction =
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1273
|
+
function testPeek(batch, task, attempts, index) {
|
|
1274
|
+
const failure = attempts.find((a) => a.outcome === "failed"), reproduction = reproductionOf(batch, task);
|
|
1275
|
+
return `<div class="k-peek-backdrop" data-peek-close></div><aside class="k-peek" role="dialog" aria-modal="true" aria-labelledby="run-peek-title" tabindex="-1"><header class="k-peek-head"><div><h2 id="run-peek-title">${h(taskDisplayName(task, index))}</h2><div class="k-badges">${resultBadge(taskKind(attempts))}${productionTag(reproduction ? [reproduction] : [])}</div></div><button id="run-peek-close" class="k-close" type="button" aria-label="Close test" data-peek-close></button></header><div class="k-peek-label">Attempts</div><nav class="k-peek-list" aria-label="Test attempts">${attempts.map((a) => `<a id="peek-attempt-${h(a.id)}" data-nav href="${h(taskHref(batch, task, { attempt: a.id }))}">${resultIcon(attemptKind(a))}<span>Attempt ${h(a.number)}</span><span>${h(firstFailure(a)?.explanation || sentence(firstFailure(a)?.actual) || firstFailure(a)?.id || (a.outcome === "passed" ? "All checks passed" : resultLabel(attemptKind(a))))}</span></a>`).join("")}</nav><footer class="k-peek-foot">${navLink("Open test", taskHref(batch, task), "k-btn").replace("<a ", '<a id="run-peek-test" ')}${failure ? navLink("Open first failure", taskHref(batch, task, { attempt: failure.id }), "k-btn primary").replace("<a ", '<a id="run-peek-failure" ') : ""}</footer></aside>`;
|
|
1276
|
+
}
|
|
1277
|
+
function runProgress(batch) {
|
|
1278
|
+
const states = attemptStates(batch), c = runCounts(batch), s = executionSummary(records(batch.attempts), c.total);
|
|
1279
|
+
const noResult = Math.max(0, c.finished - c.passed - c.failed), queued = states.filter((state) => state === "queued").length;
|
|
1280
|
+
const label2 = `${c.passed} passed \xB7 ${c.failed} failed \xB7 ${noResult} no result \xB7 ${s.active - s.starting} running \xB7 ${s.starting} starting \xB7 ${queued} queued`;
|
|
1281
|
+
return `<section class="k-card k-progress" aria-label="Progress"><div class="k-progress-line"><strong class="k-big mid">${c.finished} of ${c.total} attempts done</strong></div><div class="k-meter s059-meter" role="img" aria-label="${h(label2)}">${states.map((state) => `<span class="${resultClass(state)}"></span>`).join("")}</div><span class="k-meta">${h(label2)}. Results are graded as each attempt finishes.</span></section>`;
|
|
1371
1282
|
}
|
|
1372
1283
|
function renderRunOverview(batch, actionsHtml = "", options = {}) {
|
|
1373
|
-
const groups = entrySections(batch),
|
|
1374
|
-
const
|
|
1375
|
-
const
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1284
|
+
const groups = entrySections(batch), tasks = groups.flatMap((group) => group.tasks), allAttempts = records(batch.attempts), c = runCounts(batch);
|
|
1285
|
+
const rows3 = groups.flatMap(({ entry, tasks: tasks2, attempts }) => tasks2.map((task) => ({ entry, task, attempts: attempts.filter((a) => a.taskId === task.id) }))).filter((row2) => !options.task || row2.task.id === options.task);
|
|
1286
|
+
const hasProduction = rows3.some((row2) => reproductionOf(batch, row2.task));
|
|
1287
|
+
const failed = rows3.filter((row2) => row2.attempts.some((a) => a.outcome === "failed")).length;
|
|
1288
|
+
const noResult = rows3.filter((row2) => row2.attempts.some((a) => ["completed", "error", "stopped"].includes(a.status) && !["passed", "failed"].includes(a.outcome))).length;
|
|
1289
|
+
return `<div class="k-page s059-run"><div class="s059-run-content k-stack"><nav class="k-crumbs" aria-label="Breadcrumb">${agentCrumb(batch)}${navLink("Runs", "/playgrounds")}<span>/</span><span aria-current="page">#${h(shortId(String(batch.id)))}</span></nav><header class="k-head"><div class="k-title"><h1>${h(batch.origin?.branch || batch.groupName || runTitle(batch))} <span class="k-num">#${h(shortId(String(batch.id)))}</span></h1>${resultBadge(runStatus(batch))}</div><div class="k-actions">${kitActions(actionsHtml)}</div></header>${queueLine(batch)}${errorMessage(batch.error)}<div class="k-cols"><div class="k-main">${options.task && rows3[0] ? `<section class="k-card k-task"><span class="k-label">Task</span><div>${h(rows3[0].task.prompt ?? "")}</div></section>${comparisonForm(batch, rows3[0].task, rows3[0].attempts)}` : ""}${["running", "starting", "queued"].includes(batch.status) ? runProgress(batch) : ""}<section class="k-card" aria-label="Tests"><div class="k-card-head"><h2>${c.passed} of ${c.total} passed</h2><nav class="k-seg" aria-label="Filter tests"><button type="button" id="run-filter-all" data-test-filter="all" aria-pressed="true">All (${rows3.length})</button><button type="button" id="run-filter-failed" data-test-filter="failed" aria-pressed="false">Failed (${failed})</button><button type="button" id="run-filter-none" data-test-filter="none" aria-pressed="false">No result (${noResult})</button></nav></div><div class="k-scroll"><table class="k-table mid"><thead><tr><th class="icon-cell"><span class="sr-only">Result</span></th><th>Test</th><th>Attempts</th><th class="num">Passed</th>${hasProduction ? "<th>vs production</th>" : ""}</tr></thead><tbody>${rows3.map(({ entry, task, attempts }) => {
|
|
1290
|
+
const outcome = taskOutcome(attempts, hasChecks([task]), Number(task.attempts) || attempts.length), reproduction = reproductionOf(batch, task);
|
|
1291
|
+
return `<tr data-test-row data-failed="${attempts.some((a) => a.outcome === "failed")}" data-none="${attempts.some((a) => ["completed", "error", "stopped"].includes(a.status) && !["passed", "failed"].includes(a.outcome))}"><td class="icon-cell">${resultIcon(taskKind(attempts))}</td><td class="wrap"><button class="k-name" type="button" id="run-test-${h(task.id)}" data-peek-task="${h(task.id)}" aria-haspopup="dialog">${h(taskDisplayName(task, tasks.indexOf(task)))}</button>${groups.length > 1 ? `<div class="k-meta">${h(entry?.agentName ?? entry?.name ?? "")}</div>` : ""}<div class="k-meta">${h(shortPrompt(task.prompt))}</div><template data-test-peek="${h(task.id)}">${testPeek(batch, task, attempts, tasks.indexOf(task))}</template></td><td>${testSquares(batch, task, attempts)}</td><td class="num">${attempts.some((a) => ["passed", "failed"].includes(a.outcome)) ? `${attempts.filter((a) => a.outcome === "passed").length}/${Number(task.attempts) || attempts.length}` : "\u2014"}<div class="k-meta">${h(outcome.note)}</div></td>${hasProduction ? `<td>${productionTag(reproduction ? [reproduction] : []) || "\u2014"}</td>` : ""}</tr>`;
|
|
1292
|
+
}).join("")}</tbody></table></div>${!rows3.length ? '<p class="k-empty">No tasks recorded.</p>' : ""}<p class="k-empty" data-test-empty hidden>No tests match this filter.</p></section></div><aside class="k-side">${runDetails(batch, tasks, allAttempts)}${baselineNote(batch) ? `<p class="k-meta">${h(baselineNote(batch).text)}</p>` : ""}</aside></div></div><div data-peek-host></div></div>`;
|
|
1293
|
+
}
|
|
1294
|
+
function mountRunOverview(container, state = {}) {
|
|
1295
|
+
const page = container.querySelector(".s059-run");
|
|
1296
|
+
if (!page) return;
|
|
1297
|
+
const content = page.querySelector(".s059-run-content"), host = page.querySelector("[data-peek-host]");
|
|
1298
|
+
const buttons = [...page.querySelectorAll("[data-peek-task]")];
|
|
1299
|
+
const applyFilter = () => {
|
|
1300
|
+
let count2 = 0;
|
|
1301
|
+
const rows3 = [...page.querySelectorAll("[data-test-row]")];
|
|
1302
|
+
for (const row2 of rows3) {
|
|
1303
|
+
row2.hidden = state.filter === "failed" ? row2.dataset.failed !== "true" : state.filter === "none" ? row2.dataset.none !== "true" : false;
|
|
1304
|
+
if (!row2.hidden) count2++;
|
|
1305
|
+
}
|
|
1306
|
+
for (const button2 of page.querySelectorAll("[data-test-filter]")) button2.setAttribute("aria-pressed", String(button2.dataset.testFilter === (state.filter ?? "all")));
|
|
1307
|
+
page.querySelector("[data-test-empty]").hidden = count2 > 0 || rows3.length === 0;
|
|
1308
|
+
};
|
|
1309
|
+
const close = () => {
|
|
1310
|
+
const id = state.peek;
|
|
1311
|
+
state.peek = void 0;
|
|
1312
|
+
host.replaceChildren();
|
|
1313
|
+
content.inert = false;
|
|
1314
|
+
buttons.find((button2) => button2.dataset.peekTask === id)?.focus();
|
|
1315
|
+
};
|
|
1316
|
+
const open = (id) => {
|
|
1317
|
+
const template = [...page.querySelectorAll("template[data-test-peek]")].find((node) => node.dataset.testPeek === id);
|
|
1318
|
+
if (!template) {
|
|
1319
|
+
state.peek = void 0;
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
state.peek = id;
|
|
1323
|
+
host.replaceChildren(template.content.cloneNode(true));
|
|
1324
|
+
content.inert = true;
|
|
1325
|
+
host.querySelector(".k-close")?.focus();
|
|
1326
|
+
};
|
|
1327
|
+
page.addEventListener("click", (event) => {
|
|
1328
|
+
const link = event.target.closest("a[data-nav]");
|
|
1329
|
+
if (link && host.contains(link) && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
1330
|
+
close();
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1333
|
+
const target = event.target.closest("[data-peek-task], [data-peek-close], [data-test-filter]");
|
|
1334
|
+
if (!target) return;
|
|
1335
|
+
if (target.hasAttribute("data-peek-close")) close();
|
|
1336
|
+
else if (target.dataset.peekTask) open(target.dataset.peekTask);
|
|
1337
|
+
else {
|
|
1338
|
+
state.filter = target.dataset.testFilter;
|
|
1339
|
+
applyFilter();
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
page.addEventListener("keydown", (event) => {
|
|
1343
|
+
if (!state.peek) return;
|
|
1344
|
+
if (event.key === "Escape") {
|
|
1345
|
+
event.preventDefault();
|
|
1346
|
+
close();
|
|
1347
|
+
}
|
|
1348
|
+
if (event.key === "Tab") {
|
|
1349
|
+
const focusable = [...host.querySelectorAll("a[href], button")], first = focusable[0], last = focusable.at(-1);
|
|
1350
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
1351
|
+
event.preventDefault();
|
|
1352
|
+
last?.focus();
|
|
1353
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
1354
|
+
event.preventDefault();
|
|
1355
|
+
first?.focus();
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
applyFilter();
|
|
1360
|
+
if (state.peek) open(state.peek);
|
|
1385
1361
|
}
|
|
1386
1362
|
function safeLink(value) {
|
|
1387
1363
|
if (/[\u0000-\u0020\u007f\\]/.test(value)) return;
|
|
@@ -1493,68 +1469,11 @@ function attemptKind(attempt) {
|
|
|
1493
1469
|
}
|
|
1494
1470
|
function taskKind(attempts) {
|
|
1495
1471
|
const kinds = attempts.map(attemptKind);
|
|
1496
|
-
return ["running", "queued", "failed", "invalid", "error", "
|
|
1472
|
+
return ["running", "queued", "failed", "invalid", "error", "ungraded", "stopped", "skipped", "passed"].find((kind) => kinds.includes(kind)) ?? "ungraded";
|
|
1497
1473
|
}
|
|
1498
|
-
|
|
1499
|
-
const attempts = records(batch.attempts).filter((a) => !taskId || a.taskId === taskId);
|
|
1500
|
-
return attempts.find((a) => a.outcome === "failed") ?? attempts.find((a) => a.outcome === "invalid") ?? attempts.find((a) => ["completed", "error", "stopped"].includes(a.status)) ?? attempts[0];
|
|
1501
|
-
}
|
|
1502
|
-
var cliRun2 = (batch) => ["cli", "ci", "cloud", "pytest"].includes(batch.origin?.source);
|
|
1474
|
+
var cliRun = (batch) => ["cli", "ci", "cloud", "pytest"].includes(batch.origin?.source);
|
|
1503
1475
|
var reproductionOf = (batch, task) => records(batch.reproduction).find((r) => r.sceneId === task.id);
|
|
1504
1476
|
var firstFailure = (attempt) => records(attempt.checks).find((c) => c.required !== false && !c.passed && !c.error && c.status !== "skipped");
|
|
1505
|
-
function runHeader(batch, task, attempts, attempt, actionsHtml) {
|
|
1506
|
-
const id = String(batch.id), trace = reproductionOf(batch, task)?.trace;
|
|
1507
|
-
const crumbs = `<nav class="rd-crumbs" aria-label="Breadcrumb">${navLink("Runs", "/playgrounds")}<span aria-hidden="true">/</span><code title="${h(id)}">${h(shortId(id, 12))}</code>${copyButton(id, "Copy run id")}</nav>`;
|
|
1508
|
-
const kicker = cliRun2(batch) ? `Test <code>${h(task.id)}</code>${trace ? `, made from production trace <code title="${h(trace)}">${h(String(trace).slice(0, 8))}</code>` : ""}` : h(batch.world?.name ?? batch.configuration?.name ?? batch.test?.world?.name ?? batch.groupName ?? "World");
|
|
1509
|
-
const prompt = String(task.prompt ?? "").trim(), long = prompt.length > 160;
|
|
1510
|
-
const title2 = prompt ? `\u201C${long ? `${prompt.slice(0, 157).trimEnd()}\u2026` : prompt}\u201D` : taskDisplayName(task, 0);
|
|
1511
|
-
const c = runCounts(batch), note = baselineNote(batch), failure = firstFailure(attempt);
|
|
1512
|
-
const verdict = `<div class="rd-verdict">${statusPill(runStatus(batch))}${c.graded ? `<span class="rd-rate">${c.passed} of ${c.total} attempts passed</span>` : ""}${productionTag(batch.reproduction)}${note ? `<span class="c-note c-tone-${note.tone}">${h(note.text)}</span>` : ""}</div>`;
|
|
1513
|
-
const reason = failure ? `<p class="rd-reason"><code>${h(failure.id)}</code> ${h(failure.explanation || sentence(failure.actual) || failure.actual)}</p>` : "";
|
|
1514
|
-
return `<div class="rd-top">${crumbs}<div class="rd-top-actions">${cliRun2(batch) ? copyCommand(`ancha explain ${id}`) : ""}${actionsHtml ? `<div class="aw-actions">${actionsHtml}</div>` : ""}</div></div>
|
|
1515
|
-
<header class="rd-head"><span class="rd-kicker">${kicker}</span><h1 title="${h(prompt)}">${h(title2)}</h1>${long ? `<details class="rd-request"><summary>The whole request</summary><p>${h(prompt)}</p></details>` : ""}${verdict}${reason}</header>`;
|
|
1516
|
-
}
|
|
1517
|
-
function runFacts(batch, attempts) {
|
|
1518
|
-
const durations = attempts.map(attemptMs).filter((ms) => ms !== void 0).sort((a, b) => a - b);
|
|
1519
|
-
const total = timeOf(batch.finishedAt) - timeOf(batch.startedAt ?? batch.createdAt), calls = attempts.reduce((sum2, a) => sum2 + (Number(a.toolCalls) || 0), 0);
|
|
1520
|
-
const commit = batch.origin?.commit ? `${String(batch.origin.commit).slice(0, 7)}${batch.origin.dirty ? " + changes" : ""}` : "";
|
|
1521
|
-
const atOnce = Number(batch.concurrency) || 0, cloud = whereKey(batch.origin) === "cloud";
|
|
1522
|
-
const items = [
|
|
1523
|
-
{ label: "Agent", value: String(batch.agentName ?? batch.test?.agentName ?? "\u2014") },
|
|
1524
|
-
{ label: "Where", value: whereLabel(batch.origin).split(" \xB7 ")[0] || "Console", ...cloud && atOnce ? { sub: `${atOnce} at once, a machine each` } : {} },
|
|
1525
|
-
...commit ? [{ label: "Commit", value: commit, mono: true }] : [],
|
|
1526
|
-
{ label: "Started", value: utcClock(batch.createdAt) || "\u2014", sub: [utcDay(batch.createdAt), ago(batch.createdAt)].filter(Boolean).join(" \xB7 "), title: utc(batch.createdAt) },
|
|
1527
|
-
{ label: "Duration", value: Number.isFinite(total) && total >= 0 ? duration(total) : "\u2014", ...durations.length > 1 ? { sub: duration(durations[0]) === duration(durations.at(-1)) ? `attempts ${duration(durations[0])} each` : `attempts ${duration(durations[0])} to ${duration(durations.at(-1))}` } : durations.length ? { sub: `attempt ${duration(durations[0])}` } : {} },
|
|
1528
|
-
{ label: "Tool calls", value: String(calls), ...attempts.length ? { sub: `${Number((calls / attempts.length).toFixed(1))} per attempt` } : {} },
|
|
1529
|
-
...batch.origin?.source ? [{ label: "Started by", value: originLabel({ source: batch.origin.source }) }] : []
|
|
1530
|
-
];
|
|
1531
|
-
return facts(items, "Run facts");
|
|
1532
|
-
}
|
|
1533
|
-
function rail(batch, tasks, allAttempts, task, attempt, view2) {
|
|
1534
|
-
const testLink = (t, i) => {
|
|
1535
|
-
const own = allAttempts.filter((a) => a.taskId === t.id), passed = own.filter((a) => a.outcome === "passed").length;
|
|
1536
|
-
const label2 = `${own.length} attempts: ${own.map((a) => statusLabel(attemptKind(a))).join(", ")}`;
|
|
1537
|
-
return `<a data-nav class="rd-test${t.id === task.id ? " selected" : ""}"${t.id === task.id ? ' aria-current="true"' : ""} href="${h(taskHref(batch, t))}"><span class="rd-test-title">${glyph(taskKind(own))}<span>${h(shortPrompt(t.prompt) || taskDisplayName(t, i))}</span></span><span class="rd-test-meta">${cliRun2(batch) ? `<code>${h(t.id)}</code>` : ""}${strip(own.map(attemptKind), label2)}<span class="num">${passed} / ${own.length}</span></span></a>`;
|
|
1538
|
-
};
|
|
1539
|
-
const attemptsOfTask = allAttempts.filter((a) => a.taskId === task.id);
|
|
1540
|
-
return `<aside class="rd-rail" aria-label="Tests and attempts"><section><h2 class="rd-rail-title">Tests \xB7 ${tasks.length}</h2>${tasks.map(testLink).join("")}</section><section><h2 class="rd-rail-title">Attempts</h2><nav aria-label="Attempts">${attemptsOfTask.map((a) => `<a data-nav class="rd-attempt${a.id === attempt.id ? " selected" : ""}"${a.id === attempt.id ? ' aria-current="page"' : ""} href="${h(taskHref(batch, task, { attempt: a.id, ...view2 === "evidence" ? {} : { view: view2 } }))}">${glyph(attemptKind(a), 16, statusLabel(attemptKind(a)))}<span>Attempt ${h(a.number)}</span><span class="rd-attempt-time">${a.status === "starting" ? `<span data-since="${startingSince(a)}">${elapsedLabel(startingSince(a))}</span>` : h(attemptMs(a) === void 0 ? "" : duration(attemptMs(a)))}</span></a>`).join("")}</nav></section></aside>`;
|
|
1541
|
-
}
|
|
1542
|
-
function checksSection(attempt, callHref, jump) {
|
|
1543
|
-
const checks2 = records(attempt.checks);
|
|
1544
|
-
if (!checks2.length) return "";
|
|
1545
|
-
const skipped = (c) => c.status === "skipped" && !c.error;
|
|
1546
|
-
const evaluated = checks2.filter((c) => !skipped(c)), passed = evaluated.filter((c) => c.passed).length, deciding = checks2.filter((c) => c.required !== false).length;
|
|
1547
|
-
const counts = [`${deciding} ${deciding === 1 ? "decides" : "decide"} the result`, checks2.length - deciding && `${checks2.length - deciding} optional`, `${passed} of ${evaluated.length} passed`, checks2.length - evaluated.length && `${checks2.length - evaluated.length} not evaluated`].filter(Boolean).join(" \xB7 ");
|
|
1548
|
-
return `<section class="rd-section rd-checks" aria-label="Checks"><div class="rd-section-head"><h3>Checks</h3><span>${h(counts)}</span></div>${checks2.map((c) => {
|
|
1549
|
-
const kind = c.error ? "error" : skipped(c) ? "skipped" : c.passed ? "passed" : "failed";
|
|
1550
|
-
const role = c.required === false ? tag("Optional") : kind === "failed" ? tag("Decides the result", "fail") : "";
|
|
1551
|
-
const detail = c.error ? `Error: ${c.error}` : kind === "skipped" ? `Not evaluated \xB7 ${c.explanation || c.warning || c.actual}` : [sentence(c.expected) && `Expected ${sentence(c.expected)}`, c.explanation || c.actual].filter(Boolean).join(". ");
|
|
1552
|
-
const evidence = Array.isArray(c.evidence) ? c.evidence.filter(Number.isSafeInteger) : [];
|
|
1553
|
-
const links = evidence.length ? evidence.slice(0, 3).map((seq) => navLink(`Call ${seq}`, callHref(seq))).join(" ") : c.kind === "judge" && kind !== "skipped" ? '<span class="rd-whole">Whole run</span>' : "";
|
|
1554
|
-
const person2 = kind === "failed" ? jump(String(c.id)) : void 0;
|
|
1555
|
-
return `<div class="rd-check ${kind}">${glyph(kind, 16, statusLabel(kind))}<div class="rd-check-body"><div class="rd-check-name"><code>${h(c.id)}</code>${tag(c.kind === "judge" ? "Judge" : "Rule")}${role}</div>${detail ? `<p>${h(detail)}</p>` : ""}${person2 ? navLink("See in the conversation", person2, "aw-check-jump") : ""}</div><div class="rd-check-links">${links}</div></div>`;
|
|
1556
|
-
}).join("")}</section>`;
|
|
1557
|
-
}
|
|
1558
1477
|
function callName(t) {
|
|
1559
1478
|
const path2 = String(t.path ?? "").split("?")[0] ?? "";
|
|
1560
1479
|
if (t.service === "tools" && path2.startsWith("/tools/")) return path2.slice("/tools/".length);
|
|
@@ -1574,11 +1493,11 @@ function fieldsOf(value, limit = 60) {
|
|
|
1574
1493
|
walk(value, "");
|
|
1575
1494
|
return out;
|
|
1576
1495
|
}
|
|
1577
|
-
function gist(value,
|
|
1496
|
+
function gist(value, count2 = 3) {
|
|
1578
1497
|
if (value === void 0 || value === null || value === "") return "";
|
|
1579
1498
|
if (!(typeof value === "object")) return String(value).replace(/\s+/g, " ").slice(0, 120);
|
|
1580
|
-
const fields2 = fieldsOf(value,
|
|
1581
|
-
return fields2.slice(0,
|
|
1499
|
+
const fields2 = fieldsOf(value, count2 + 1).filter(([, v]) => v !== "");
|
|
1500
|
+
return fields2.slice(0, count2).map(([k, v]) => `${k}: ${v.length > 40 ? `${v.slice(0, 39)}\u2026` : v}`).join(", ") + (fields2.length > count2 ? ", \u2026" : "");
|
|
1582
1501
|
}
|
|
1583
1502
|
var fieldList = (value) => {
|
|
1584
1503
|
const fields2 = fieldsOf(value);
|
|
@@ -1618,6 +1537,54 @@ function productionSection(batch, task, attempt) {
|
|
|
1618
1537
|
return `<div class="rd-table-row"><code>${h(c.check)}</code><span>${statusMark(word[c.production] ?? "ungraded")}</span><span>${total ? statusMark(failed ? "failed" : "passed", failed ? `Failed ${failed} of ${total}` : `Passed ${total} of ${total}`) : '<span class="muted">\u2014</span>'}</span><span>${ownKind ? statusMark(ownKind) : '<span class="muted">\u2014</span>'}</span></div>`;
|
|
1619
1538
|
}).join("")}</div></section>`;
|
|
1620
1539
|
}
|
|
1540
|
+
function checkKind(check) {
|
|
1541
|
+
return check.error ? "error" : check.status === "skipped" ? "skipped" : check.passed ? "passed" : "failed";
|
|
1542
|
+
}
|
|
1543
|
+
var failedCheck = (check) => checkKind(check) === "failed";
|
|
1544
|
+
function checkFields(value) {
|
|
1545
|
+
if (typeof value === "string" && /^\s*[[{]/.test(value)) {
|
|
1546
|
+
try {
|
|
1547
|
+
return fieldsOf(JSON.parse(value));
|
|
1548
|
+
} catch {
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
return fieldsOf(value);
|
|
1552
|
+
}
|
|
1553
|
+
function failedCheckCard(check, jump) {
|
|
1554
|
+
const expected = new Map(checkFields(check.expected)), actual = new Map(checkFields(check.actual)), keys = [.../* @__PURE__ */ new Set([...expected.keys(), ...actual.keys()])], person2 = jump(String(check.id));
|
|
1555
|
+
return `<section class="k-check" aria-label="${h(check.id)}"><header class="k-check-head"><span>${resultIcon("failed")}${h(check.id)}</span>${check.kind ? `<span class="k-badge">${check.kind === "judge" ? "AI judge" : "Rule"}</span>` : ""}${check.required === false ? '<span class="k-badge">Optional</span>' : ""}</header><table class="k-fields"><thead><tr><th>Field</th><th>Expected</th><th>Got</th></tr></thead><tbody>${keys.map((key) => `<tr><td>${h(key || "Result")}</td><td>${h(expected.get(key) ?? "\u2014")}</td><td${expected.get(key) !== actual.get(key) ? ' class="off"' : ""}>${h(actual.get(key) ?? "\u2014")}</td></tr>`).join("")}</tbody></table>${check.explanation ? `<p>${h(check.explanation)}</p>` : ""}${person2 ? `<p>${navLink("See in the conversation", person2, "aw-check-jump")}</p>` : ""}</section>`;
|
|
1556
|
+
}
|
|
1557
|
+
function stepsSection(observation2, checks2, callHref, jump) {
|
|
1558
|
+
const trace = records(observation2.trace).filter((t) => t.path !== "console.manual_action").sort((a, b) => (Number(a.seq) || 0) - (Number(b.seq) || 0));
|
|
1559
|
+
const seqs = new Set(trace.map((t) => Number(t.seq))), failures = checks2.filter(failedCheck);
|
|
1560
|
+
const stepOf = (check) => (Array.isArray(check.evidence) ? check.evidence : []).find((seq) => Number.isSafeInteger(seq) && seqs.has(Number(seq)));
|
|
1561
|
+
const unlinked = failures.filter((check) => stepOf(check) === void 0);
|
|
1562
|
+
const times = trace.map((t) => timeOf(t.tSim)).filter(Number.isFinite), start = times.length ? Math.min(...times) : NaN;
|
|
1563
|
+
return `<section class="k-card" aria-label="Steps"><div class="k-card-head"><h2>Steps</h2><span class="k-meta">${count(trace.length, "call")}</span></div>${unlinked.length ? `<div class="k-stack s059-unlinked">${unlinked.map((check) => failedCheckCard(check, jump)).join("")}</div>` : ""}<ol class="k-steps">${trace.map((call, i) => {
|
|
1564
|
+
const seq = Number(call.seq), own = failures.filter((check) => stepOf(check) === seq), at2 = timeOf(call.tSim);
|
|
1565
|
+
return `<li><div class="k-step${own.length ? " fail" : ""}" id="step-${h(seq)}"><span class="n">${i + 1}</span><span class="tool" title="${h(call.service ?? "")}">${h(call.service === "tools" ? "Tool" : toolName(String(call.service ?? "")) || "Call")}</span><span class="what">${navLink(callName(call), callHref(seq), "k-name")}${gist(call.service === "tools" ? call.request?.args : call.request) ? `<span class="s059-step-gist">${h(gist(call.service === "tools" ? call.request?.args : call.request))}</span>` : ""}</span><span class="t">${Number.isFinite(at2) && Number.isFinite(start) ? h(duration(at2 - start)) : "\u2014"}</span></div>${own.map((check) => `<div class="k-step-check">${failedCheckCard(check, jump)}</div>`).join("")}</li>`;
|
|
1566
|
+
}).join("")}</ol>${trace.length ? "" : '<p class="k-empty">No calls in this attempt.</p>'}</section>`;
|
|
1567
|
+
}
|
|
1568
|
+
function attemptChecks(checks2, trace, callHref, jump) {
|
|
1569
|
+
if (!checks2.length) return "";
|
|
1570
|
+
const evaluated = checks2.filter((c) => c.status !== "skipped" || c.error), deciding = checks2.filter((c) => c.required !== false).length;
|
|
1571
|
+
const counts = [`${deciding} ${deciding === 1 ? "decides" : "decide"} the result`, checks2.length - deciding && `${checks2.length - deciding} optional`, `${evaluated.filter((c) => c.passed).length} of ${evaluated.length} passed`, checks2.length - evaluated.length && `${checks2.length - evaluated.length} not evaluated`].filter(Boolean).join(" \xB7 ");
|
|
1572
|
+
return `<section class="k-card" aria-label="Checks"><div class="k-card-head"><h2>Checks</h2><span class="k-meta">${h(counts)}</span></div>${checks2.map((check) => {
|
|
1573
|
+
const kind = checkKind(check), seqs = Array.isArray(check.evidence) ? check.evidence.filter(Number.isSafeInteger) : [], person2 = jump(String(check.id));
|
|
1574
|
+
return `<div class="s059-check-row">${resultIcon(kind)}<div><strong>${h(check.id)}</strong>${!failedCheck(check) && sentence(check.expected) ? `<p class="k-meta">Expected ${h(sentence(check.expected))}</p>` : ""}<div class="k-meta">${h(resultLabel(kind))}${check.kind ? ` \xB7 ${check.kind === "judge" ? "AI judge" : "Rule"}` : ""}${check.required === false ? " \xB7 Optional" : kind === "failed" ? " \xB7 Decides the result" : ""}</div>${check.error || check.explanation || sentence(check.actual) ? `<p class="k-meta">${h(check.error || check.explanation || sentence(check.actual))}</p>` : ""}<div class="k-actions">${seqs.map((seq) => navLink(trace.some((call) => call.seq === seq) ? `Step ${trace.findIndex((call) => call.seq === seq) + 1}` : `Call ${seq}`, callHref(seq), "k-more")).join("")}${person2 && !failedCheck(check) ? navLink("See in the conversation", person2, "aw-check-jump") : ""}${check.kind === "judge" && kind !== "skipped" && !seqs.length ? '<span class="k-meta">Whole run</span>' : ""}</div></div></div>`;
|
|
1575
|
+
}).join("")}</section>`;
|
|
1576
|
+
}
|
|
1577
|
+
function codingAgentText(batch, task, attempt, checks2) {
|
|
1578
|
+
const value = (input) => checkFields(input).map(([key, text2]) => key ? `${key}: ${text2}` : text2).join("; ");
|
|
1579
|
+
return [
|
|
1580
|
+
`Run: ${batch.id}`,
|
|
1581
|
+
`Test: ${task.title || task.id}`,
|
|
1582
|
+
`Task: ${task.prompt ?? ""}`,
|
|
1583
|
+
`Attempt ${attempt.number}: ${resultLabel(attemptKind(attempt))}`,
|
|
1584
|
+
`Evidence: ${taskHref(batch, task, { attempt: attempt.id })}`,
|
|
1585
|
+
...checks2.flatMap((check) => [`Check ${check.id}: ${resultLabel(checkKind(check))}`, ...check.expected !== void 0 ? [`Expected: ${value(check.expected)}`] : [], ...check.actual !== void 0 ? [`Got: ${value(check.actual)}`] : [], ...check.explanation ? [String(check.explanation)] : []])
|
|
1586
|
+
].join("\n");
|
|
1587
|
+
}
|
|
1621
1588
|
function renderAttemptWorkspace(batch, attempt, evidence, options = {}) {
|
|
1622
1589
|
const entry = groupEntryForAttempt(records(batch.entries), attempt), tasks = entry ? tasksForEntry(batch, entry) : records(batch.tasks), index = tasks.findIndex((t) => t.id === attempt.taskId), task = tasks[index] ?? { id: attempt.taskId, prompt: "" };
|
|
1623
1590
|
const allAttempts = entry ? attemptsForEntry(batch, entry) : records(batch.attempts), attempts = allAttempts.filter((a) => a.taskId === attempt.taskId);
|
|
@@ -1636,16 +1603,16 @@ function renderAttemptWorkspace(batch, attempt, evidence, options = {}) {
|
|
|
1636
1603
|
const callHref = (seq) => taskHref(batch, task, { attempt: attempt.id, view: "evidence", call: seq });
|
|
1637
1604
|
const focus = people2 ? checkFocus(observation2) : /* @__PURE__ */ new Map();
|
|
1638
1605
|
const jump = (checkId) => {
|
|
1639
|
-
const
|
|
1640
|
-
return
|
|
1606
|
+
const id2 = focus.get(checkId);
|
|
1607
|
+
return id2 ? taskHref(batch, task, { attempt: attempt.id, view: "conversation", focus: id2 }) : void 0;
|
|
1641
1608
|
};
|
|
1642
1609
|
const toolsNav = `<nav class="tool-nav" aria-label="Attempt tools">${tools.map((t) => navLink(toolName(t), taskHref(batch, task, { attempt: attempt.id, view: "tools", tool: t }), t === tool ? "active" : "")).join("")}</nav>`;
|
|
1643
1610
|
const logs = typeof observation2.logs === "string" ? observation2.logs : "";
|
|
1644
1611
|
const content = view2 === "tools" ? toolsNav + (tool ? capturedToolView(observation2, tool, { ...query, baseHref: attemptBase }) : '<p class="quiet-empty">No captured tool data.</p>') : view2 === "conversation" ? response + conversationView(observation2, { focus: query.focus }) : view2 === "logs" ? logs.trim() ? `<pre class="rd-log">${h(logs)}</pre>` : stateCard("No log", "The agent wrote nothing to its output in this attempt.") : response + callsSection(observation2, failing, Number(query.call) || void 0) + productionSection(batch, task, fullEvidence);
|
|
1645
|
-
const tab2 = (label2, name, href2) => navLink(label2, href2, view2 === name ? "
|
|
1646
|
-
const ms = attemptMs(attempt), calls = Number(fullEvidence.toolCalls ?? attempt.toolCalls) || 0;
|
|
1647
|
-
const
|
|
1648
|
-
return `<div class="
|
|
1612
|
+
const tab2 = (label2, name, href2) => navLink(label2, href2, view2 === name ? "on" : "").replace("<a ", `<a ${view2 === name ? 'aria-current="page" ' : ""}`);
|
|
1613
|
+
const ms = attemptMs(attempt), calls = Number(fullEvidence.toolCalls ?? attempt.toolCalls) || 0, id = String(batch.id), trace = reproductionOf(batch, task)?.trace;
|
|
1614
|
+
const details2 = `<section class="k-card" aria-label="Details"><h2>Details</h2>${detailRow("Agent", h(entry?.agentName ?? (agentName(batch) || "\u2014")))}${detailRow("Attempt", h(attempt.number))}${detailRow("Duration", h(ms === void 0 ? "\u2014" : duration(ms)))}${detailRow("Tool calls", String(calls))}${detailRow("From", h(originLabel(batch.origin) || "Console"))}${batch.createdAt ? detailRow("Started", `<time datetime="${h(batch.createdAt)}" title="${h(utc(batch.createdAt))}">${h(utcClock(batch.createdAt))} \xB7 ${h(utcDay(batch.createdAt))}</time>`) : ""}${trace ? detailRow("Production trace", `<code title="${h(trace)}">${h(String(trace).slice(0, 8))}</code>`) : ""}${detailRow("Run", navLink(shortId(id), basePath(batch)))}${detailRow("Test", h(task.id))}</section>`;
|
|
1615
|
+
return `<div class="k-page s059-attempt"><nav class="k-crumbs" aria-label="Breadcrumb">${agentCrumb({ ...batch, ...entry?.agentName ? { agentName: entry.agentName, agentId: entry.agentId } : {} })}${navLink("#" + shortId(id), basePath(batch))}<span>/</span>${navLink(taskDisplayName(task, index), taskHref(batch, task))}<span>/</span><span aria-current="page">Attempt ${h(attempt.number)}</span>${copyButton(id, "Copy run id")}</nav><header class="k-head"><div class="k-title"><h1>${h(taskDisplayName(task, index))}</h1>${resultBadge(attemptKind(attempt))}${["starting", "running", "queued"].includes(attempt.status) ? executionBadge(attempt) : ""}</div><div class="k-actions">${cliRun(batch) ? copyCommand(`ancha explain ${id}`) : ""}${kitActions(options.actionsHtml ?? "")}<button type="button" class="k-btn${options.actionsHtml?.includes("primary") ? "" : " primary"}" data-action="copy-text" data-value="${h(codingAgentText(batch, task, fullEvidence, checks2))}">Copy for coding agent</button></div></header><nav class="k-attempts" aria-label="Attempts">${attempts.map((a) => navLink(String(a.number), taskHref(batch, task, { attempt: a.id, ...view2 === "evidence" ? {} : { view: view2 } }), `k-att ${resultClass(attemptKind(a))}`).replace("<a ", `<a aria-label="Attempt ${h(a.number)}: ${h(resultLabel(attemptKind(a)))}" ${a.id === attempt.id ? 'aria-current="page" ' : ""}`)).join("")}</nav>${queueLine(batch)}${errorMessage(batch.error)}<div class="k-cols"><div class="k-main"><section class="k-card k-task"><span class="k-label">Task</span><div>${h(String(task.prompt ?? "").trim())}</div></section>${invalidNote(attempt)}${stepsSection(observation2, checks2, callHref, jump)}${comparisonForm(batch, task, attempts, attempt)}<nav class="k-seg" aria-label="Attempt evidence">${people2 ? tab2("Conversation", "conversation", taskHref(batch, task, { attempt: attempt.id, view: "conversation" })) : ""}${tab2("Evidence", "evidence", people2 ? taskHref(batch, task, { attempt: attempt.id, view: "evidence" }) : attemptBase)}${tab2("World data", "tools", taskHref(batch, task, { attempt: attempt.id, view: "tools" }))}${tab2("Logs", "logs", taskHref(batch, task, { attempt: attempt.id, view: "logs" }))}</nav><div id="attempt-evidence" class="aw-evidence-body">${errorMessage(fullEvidence.error)}${content}</div></div><aside class="k-side">${attemptChecks(checks2, records(observation2.trace).filter((t) => t.path !== "console.manual_action").sort((a, b) => (Number(a.seq) || 0) - (Number(b.seq) || 0)), callHref, jump)}${details2}</aside></div></div>`;
|
|
1649
1616
|
}
|
|
1650
1617
|
function renderManagedComparison(data) {
|
|
1651
1618
|
const sides = records(data.attempts ?? [data.left, data.right]);
|
|
@@ -1660,6 +1627,15 @@ function renderManagedComparison(data) {
|
|
|
1660
1627
|
// frontend/src/world-workspace.ts
|
|
1661
1628
|
var enc = encodeURIComponent;
|
|
1662
1629
|
var label = (task, index) => task.title && task.title !== String(task.prompt).split("\n")[0]?.slice(0, 120) ? task.title : "Task " + (index + 1);
|
|
1630
|
+
var tone = (kind) => kind === "passed" ? "pass" : kind === "failed" ? "fail" : ["invalid", "error", "skipped", "ungraded", "stopped"].includes(kind) ? "none" : "";
|
|
1631
|
+
var resultBadge2 = (kind) => `<span class="k-badge ${tone(kind)}">${h(statusLabel(kind))}</span>`;
|
|
1632
|
+
function attemptSquares2(attempts, runId, taskId) {
|
|
1633
|
+
return `<div class="k-squares">${attempts.map((attempt) => {
|
|
1634
|
+
const kind = attemptKind(attempt), state = kind === "running" ? "run" : kind === "queued" ? "queue" : tone(kind);
|
|
1635
|
+
const name = `Attempt ${attempt.number}: ${attemptLabel(attempt.status)} \xB7 ${attemptOutcome(attempt).label}`;
|
|
1636
|
+
return `<a data-nav class="k-sq ${state}" role="img" href="/playgrounds/${enc(runId)}?task=${enc(taskId)}&attempt=${enc(attempt.id)}" title="${h(name)}" aria-label="${h(name)}"></a>`;
|
|
1637
|
+
}).join("")}</div>`;
|
|
1638
|
+
}
|
|
1663
1639
|
function worldSetups(tests, worldId, agentId) {
|
|
1664
1640
|
return tests.filter((test) => !test.archived && test.worldId === worldId && (!agentId || test.agentId === agentId));
|
|
1665
1641
|
}
|
|
@@ -1770,25 +1746,30 @@ function mountWorldWorkspace(node, options) {
|
|
|
1770
1746
|
}
|
|
1771
1747
|
function configuration2() {
|
|
1772
1748
|
const d = getDraft(), pinned = Number(d.worldRevision) !== world.revision, startingWorld = revisions.get(Number(d.worldRevision));
|
|
1773
|
-
return `<section class="ww-configure"><div class="
|
|
1749
|
+
return `<section class="ww-configure k-card pad"><div class="k-card-head"><h2>Configure</h2><button class="k-btn" type="button" data-ww="close">Close</button></div><form class="ww-form"><div class="form-grid"><label>Agent<select class="k-field" name="agentId" required><option value="">Choose agent</option>${agents.map((a) => `<option value="${h(a.id)}" ${d.agentId === a.id ? "selected" : ""}>${h(agentLabel(a, agents))}</option>`).join("")}</select></label><label>Configuration name<input class="k-field" name="name" required maxlength="120" value="${h(d.name)}"></label></div><section class="ww-tools k-card pad"><div class="k-card-head"><h3>Tools</h3><a data-nav href="${base}?edit=1">Edit world</a></div><div class="ww-tool-list">${(startingWorld?.configuration.preset.datasets ?? []).map((item) => `<a data-nav href="/tools/${enc(item.tool)}">${toolLogo(item.tool)}${h(toolName(item.tool))}</a>`).join("")}</div>${pinned ? `<label>Starting data<select class="k-field" name="worldRevision"><option value="${h(d.worldRevision)}">Saved revision ${h(d.worldRevision)}</option><option value="${world.revision}">Current revision ${world.revision}</option></select></label>` : `<input type="hidden" name="worldRevision" value="${h(d.worldRevision)}">`}</section><div class="k-card-head"><h3>Tasks</h3><button class="k-btn" type="button" data-ww="add-task" ${d.tasks.length >= 20 ? "disabled" : ""}>Add task</button></div><div class="ww-task-fields">${d.tasks.map((task, index) => `<article class="ww-task-editor" data-task-id="${h(task.id)}"><div class="k-card-head"><h3>Task ${index + 1}</h3>${d.tasks.length > 1 ? `<button class="k-btn" type="button" data-ww="remove-task" data-value="${h(task.id)}">Remove</button>` : ""}</div><label>Task name <span class="muted">optional</span><input class="k-field" name="title" maxlength="120" value="${h(task.title ?? "")}" placeholder="Task ${index + 1}"></label><label>Instructions<textarea class="k-field" name="prompt" required maxlength="20000" rows="4">${h(task.prompt)}</textarea></label><div class="ww-task-options"><label>Repeat<input class="k-field" type="number" name="attempts" min="1" max="100" value="${h(task.attempts)}" required><span>times</span></label><label>Time limit <span class="muted">minutes</span><input class="k-field" type="number" name="minutes" min="0.016666666666666666" max="60" step="any" value="${h(task.timeoutMs / 6e4)}" required></label></div><label class="ww-checks-field">Checks <span class="muted">optional \xB7 JSON list, see <a href="/docs#checks" target="_blank" rel="noopener">Docs</a></span><textarea class="k-field" name="checks" rows="${Math.min(12, Math.max(3, checksText(task).split("\n").length))}" spellcheck="false" maxlength="20000" placeholder='[{"id": "posted", "trace": {"called": "* /api/chat.postMessage"}}]'>${h(checksText(task))}</textarea></label></article>`).join("")}</div><div class="ww-footer"><label>Run at once<input class="k-field" name="concurrency" type="number" min="1" max="10" value="${h(d.concurrency)}" required></label><button type="submit" class="k-btn primary" ${saving ? "disabled" : ""}>${saving ? "Saving\u2026" : "Save configuration"}</button></div></form></section>`;
|
|
1774
1750
|
}
|
|
1775
1751
|
function render() {
|
|
1776
1752
|
if (disposed) return;
|
|
1777
1753
|
const currentRuns = selected ? setupRuns(runs, selected) : [], run = currentRuns[0], attempts = run?.attempts ?? [], tasks = selected?.tasks ?? [], choices = worldSetups(tests, world.id, agentId);
|
|
1778
|
-
|
|
1754
|
+
const usedBy = worldSetups(tests, world.id), datasets = world.configuration?.preset?.datasets ?? [];
|
|
1755
|
+
node.innerHTML = `<div class="k-page world-v2"><nav class="k-crumbs" aria-label="Breadcrumb"><a data-nav href="/worlds">Worlds</a><span>/</span><span aria-current="page">${h(world.name)}</span></nav><header class="k-head"><div><div class="k-title"><h1>${h(world.name)}</h1><span class="k-badge">Revision ${h(world.revision)}</span></div><div class="worlds-id"><code title="${h(world.id)}">${h(shortId(world.id))}</code>${copyButton(world.id, "Copy world id")}</div></div><div class="k-actions"><label class="world-agent-select">Agent<select class="k-field" data-ww-select="agent"><option value="" disabled>Choose agent</option>${agents.map((a) => `<option value="${h(a.id)}" ${a.id === agentId ? "selected" : ""}>${h(agentLabel(a, agents))}</option>`).join("")}</select></label><a data-nav class="k-btn" href="${base}?data=1">View data</a><button class="k-btn" type="button" data-ww="configure">Configure</button>${selected ? options.runActions?.(selected.id) ?? button("Run tasks", "run-saved-test", selected.id, "k-btn primary") : ""}</div></header><p class="ww-error" role="alert" ${error ? "" : "hidden"}>${h(error)}</p>${errors.map((e) => `<p class="ww-error" role="alert">${h(e.message)}</p>`).join("")}${error || errors.length ? '<button class="k-btn" type="button" data-ww="retry">Retry loading tasks and runs</button>' : ""}${!loaded ? skeletonRows(4) : ""}<div class="k-cols"><div class="k-main">${choices.length > 1 ? `<label class="world-setup-select">Configuration<select class="k-field" data-ww-select="test">${!selected ? '<option value="" selected disabled>New configuration</option>' : ""}${choices.map((t) => `<option value="${h(t.id)}" ${t.id === selected?.id ? "selected" : ""}>${h(t.name)}</option>`).join("")}</select></label>` : ""}${loaded && configure ? configuration2() : loaded ? `${run ? latestRun(run, attempts, tasks) : ""}<section class="k-card"><div class="k-card-head"><h2>Tasks${tasks.length ? ` \xB7 ${tasks.length}` : ""}</h2><div class="k-actions">${worldHistory(runs, world.id, agentId || void 0).length || selected ? `<button class="k-btn small" type="button" data-ww="history" aria-expanded="${showHistory}">History</button>` : ""}<button class="k-btn small" type="button" data-ww="configure">${tasks.length ? "Edit tasks" : "Add tasks"}</button></div></div>${tasks.length ? taskTable(tasks, attempts, run) : stateCard("Add tasks to this world", agents.length ? "Configure tasks for your agent to run." : "Connect an agent to run tasks.", agents.length ? '<button class="k-btn" type="button" data-ww="configure">Add tasks</button>' : '<a class="k-btn" data-nav href="/agents">Connect an agent</a>')}</section>${selected && !currentRuns.length && setupHistory(runs, selected).some((item) => item.earlier) ? '<p class="k-meta">This configuration has changed. Earlier attempts are in History.</p>' : ""}${showHistory ? history2() : ""}` : ""}${peopleSection(world, true)}</div><aside class="k-side"><section class="k-card"><div class="k-card-head"><h2>Tools \xB7 ${datasets.length}</h2><a data-nav href="${base}?edit=1">Edit world</a></div><div class="k-scroll" role="region" aria-label="World tools" tabindex="0"><table class="k-table"><thead><tr><th scope="col">Tool</th><th scope="col">Records</th></tr></thead><tbody>${datasets.map((dataset) => `<tr><td><a data-nav class="k-name world-tool-label" href="/tools/${enc(dataset.tool)}">${toolLogo(dataset.tool)}${h(toolName(dataset.tool))}</a></td><td><a data-nav class="k-name" href="${base}?data=1&tool=${enc(dataset.tool)}">View data</a></td></tr>`).join("")}</tbody></table></div>${!datasets.length ? '<p class="k-empty">No tools</p>' : ""}</section>${loaded ? `<section class="k-card"><div class="k-card-head"><h2>Used by ${usedBy.length} ${usedBy.length === 1 ? "test" : "tests"}</h2></div>${usedBy.length ? usedBy.map((test) => `<a data-nav class="k-kv k-name" href="${h(href2(test, test.agentId))}">${h(test.name)}</a>`).join("") : '<p class="k-empty">No tests</p>'}</section>` : ""}</aside></div></div>`;
|
|
1756
|
+
}
|
|
1757
|
+
function latestRun(run, attempts, tasks) {
|
|
1758
|
+
const requested = run.summary?.counts?.requested ?? attempts.length, summary = executionSummary(attempts, requested), outcome = taskOutcome(attempts, hasChecks(run.tasks ?? tasks), requested);
|
|
1759
|
+
const stats = [["Success rate", summary.graded ? outcome.value : "\u2014", outcome.note], ["Finished", `${summary.finished}/${summary.total}`, `${summary.active} running \xB7 ${summary.queued} queued`], ["Tool calls", String(summary.toolCalls), summary.finished ? `${(summary.toolCalls / summary.finished).toFixed(1)} per attempt` : ""], ["Median time", medianTime(attempts), "per attempt"]];
|
|
1760
|
+
if (summary.invalid) stats.splice(1, 0, ["Invalid", String(summary.invalid), "Harness failures"]);
|
|
1761
|
+
return `<section class="k-stack"><div class="k-head"><h2 class="k-h2">Latest run</h2><a data-nav class="k-name" href="/playgrounds/${enc(run.id)}">${resultBadge2(runStatus(run))} ${when(run.createdAt)}</a></div><a data-nav class="world-run-summary k-grid" href="/playgrounds/${enc(run.id)}" aria-label="Open the latest run">${stats.map(([name, value, note]) => `<div class="k-card k-stat"><span class="k-label">${h(name)}</span><strong class="k-big">${h(value)}</strong><span class="k-meta">${h(note)}</span></div>`).join("")}</a></section>`;
|
|
1762
|
+
}
|
|
1763
|
+
function taskTable(tasks, attempts, run) {
|
|
1764
|
+
return `<div class="k-scroll" role="region" aria-label="Tasks" tabindex="0"><table class="k-table wide"><thead><tr><th scope="col">Task</th><th scope="col">Result</th><th scope="col">Attempts</th><th scope="col" class="num">Median</th><th scope="col"><span class="sr-only">Evidence</span></th></tr></thead><tbody>${tasks.map((task, index) => {
|
|
1779
1765
|
const list4 = attempts.filter((a) => a.taskId === task.id), taskURL = run ? `/playgrounds/${enc(run.id)}?task=${enc(task.id)}${list4[0] ? "&attempt=" + enc(list4[0].id) : ""}` : "";
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
})()}<div class="ww-attempt-marks" role="group" aria-label="Attempts for ${h(label(task, index))}">${list4.map((a) => {
|
|
1784
|
-
const o = attemptOutcome(a);
|
|
1785
|
-
return `<a data-nav class="ww-attempt-mark ${h(a.status)} outcome-${o.key}" href="/playgrounds/${enc(run.id)}?task=${enc(task.id)}&attempt=${enc(a.id)}" title="Attempt ${a.number}: ${h(attemptLabel(a.status))} \xB7 ${o.label}" aria-label="Attempt ${a.number}: ${h(attemptLabel(a.status))} \xB7 ${o.label}">${glyph(attemptKind(a))}</a>`;
|
|
1786
|
-
}).join("") || `<span class="muted">Repeat ${h(task.attempts)} times</span>`}</div><span class="ww-task-time">${list4.length ? h(medianTime(list4)) : ""}</span>${taskURL ? `<a data-nav class="ww-row-inspect" href="${taskURL}" aria-label="Inspect ${h(label(task, index))}">\u2192</a>` : "<span></span>"}</article>`;
|
|
1787
|
-
}).join("")}</section></div>` : stateCard("Add tasks to this world", agents.length ? "Configure tasks for your agent to run." : "Connect an agent to run tasks.", agents.length ? '<button type="button" data-ww="configure">Add tasks</button>' : '<a data-nav href="/agents">Connect an agent</a>')}${selected && !currentRuns.length && setupHistory(runs, selected).some((item) => item.earlier) ? '<p class="ww-snapshot-notice">This configuration has changed. Earlier attempts are in History.</p>' : ""}${showHistory ? history2() : ""}` : ""}${peopleSection(world)}</div>`;
|
|
1766
|
+
const outcome = taskOutcome(list4, hasChecks([task]), Number(task.attempts) || list4.length);
|
|
1767
|
+
return `<tr><td class="wrap world-task-cell">${taskURL ? `<a data-nav class="k-name" href="${taskURL}">${h(label(task, index))}</a>` : `<strong>${h(label(task, index))}</strong>`}<p class="world-task-prompt" title="${h(task.prompt)}">${h(task.prompt)}</p></td><td>${taskURL ? `<a data-nav class="k-name" href="${taskURL}">${list4.length ? resultBadge2(taskKind(list4)) : ""} ${h(outcome.value)}</a>` : h(outcome.value)}<div class="k-meta">${h(outcome.note)}</div></td><td>${list4.length ? attemptSquares2(list4, run.id, task.id) : `<span class="k-meta">Repeat ${h(task.attempts)} times</span>`}</td><td class="num">${list4.length ? h(medianTime(list4)) : ""}</td><td>${taskURL ? `<a data-nav class="k-name" href="${taskURL}" aria-label="Inspect ${h(label(task, index))}">\u2192</a>` : ""}</td></tr>`;
|
|
1768
|
+
}).join("")}</tbody></table></div>`;
|
|
1788
1769
|
}
|
|
1789
1770
|
function history2() {
|
|
1790
1771
|
const all = worldHistory(runs, world.id, agentId || void 0);
|
|
1791
|
-
return `<section class="
|
|
1772
|
+
return `<section class="k-card"><div class="k-card-head"><h2>History</h2><button class="k-btn small" type="button" data-ww="new">New configuration</button></div>${all.length ? `<div class="k-scroll" role="region" aria-label="Run history" tabindex="0"><table class="k-table wide"><thead><tr><th scope="col">Result</th><th scope="col">Run</th><th scope="col" class="num">Attempts</th><th scope="col" class="num">Started</th></tr></thead><tbody>${all.map(({ run, attemptCount, grouped }) => `<tr><td><a data-nav href="/playgrounds/${enc(run.id)}">${resultBadge2(runStatus(run))}</a></td><td><a data-nav class="k-name" href="/playgrounds/${enc(run.id)}" title="${h(run.groupName ?? run.test?.name ?? run.id)}">${h(run.groupName ?? run.test?.name ?? shortId(run.id))}</a><div class="worlds-id"><code title="${h(run.id)}">${h(shortId(run.id))}</code>${copyButton(run.id, "Copy run id")}${grouped ? "<span>Group</span>" : ""}</div></td><td class="num"><a data-nav class="k-name" href="/playgrounds/${enc(run.id)}">${attemptCount}</a></td><td class="num">${when(run.createdAt)}</td></tr>`).join("")}</tbody></table></div>` : stateCard("No runs recorded", "Run tasks to see their results here.")}</section>`;
|
|
1792
1773
|
}
|
|
1793
1774
|
async function refresh(initial = false) {
|
|
1794
1775
|
try {
|
|
@@ -1947,49 +1928,116 @@ function worldDataPage(title2, context, back, data, base, query) {
|
|
|
1947
1928
|
next.set("tool", name);
|
|
1948
1929
|
return `${base.split("?")[0]}?${next}`;
|
|
1949
1930
|
};
|
|
1950
|
-
const tabs = tools.map((name) => `<a data-nav class="${name === tool ? "
|
|
1931
|
+
const tabs = tools.map((name) => `<a data-nav class="${name === tool ? "on" : ""}" href="${h(link(name))}" ${name === tool ? 'aria-current="page"' : ""}><span class="world-data-logo" aria-hidden="true">${toolLogo(name)}</span>${h(toolName(name))}</a>`).join("");
|
|
1951
1932
|
const options = Object.fromEntries([...query].filter(([key]) => key === "resource" || key === "conversation"));
|
|
1952
1933
|
const pending = data.status === 202, failed = data.status === 422 || data.timedOut;
|
|
1953
|
-
const retry = `<button type="button" data-action="reload"${data.retryAfter > 0 ? " disabled" : ""}>Try again</button>`;
|
|
1954
|
-
return `<div class="world-data-page"><a data-nav
|
|
1934
|
+
const retry = `<button type="button" class="k-btn" data-action="reload"${data.retryAfter > 0 ? " disabled" : ""}>Try again</button>`;
|
|
1935
|
+
return `<div class="world-data-page k-page"><nav class="k-crumbs" aria-label="Breadcrumb"><a data-nav href="/worlds">Worlds</a><span>/</span>${back.href !== "/worlds" ? `<a data-nav href="${h(back.href)}">${h(back.label)}</a><span>/</span><span aria-current="page">Data</span>` : `<span aria-current="page">${h(title2)}</span>`}</nav><header class="k-head"><div><div class="k-title"><h1>${h(title2)}</h1>${context ? `<span class="k-badge">${h(context)}</span>` : ""}</div></div></header>` + (pending ? stateCard("Preparing this world's starting data", "It opens here when it is ready.") + skeletonRows(5) : failed ? stateCard(data.timedOut ? "The starting data is taking longer to prepare" : "The starting data could not be prepared", h(data.timedOut ? "Try again to check its progress." : data.error?.message ?? data.error ?? "Try again to prepare the starting data."), retry, "error") : tools.length ? `<nav class="k-seg world-data-tabs" aria-label="Tools">${tabs}</nav><section class="k-card world-records">${recordsView(data, tool, { ...options, embedded: true, kit: true, baseHref: link(tool) })}</section>` : stateCard("No tools in this world", "Choose tools in the world editor.")) + "</div>";
|
|
1955
1936
|
}
|
|
1956
1937
|
function worldToolsCell(world) {
|
|
1957
1938
|
const tools = [...new Set(world.tools ?? (world.configuration?.preset?.datasets ?? []).map((dataset) => dataset.tool))];
|
|
1958
1939
|
const names = tools.map(toolName);
|
|
1959
1940
|
return `<div class="world-tool-icons" role="group" aria-label="Tools: ${h(names.join(", "))}">${tools.slice(0, 2).map((tool) => `<span class="world-tool-name" title="${h(toolName(tool))}">${toolLogo(tool)}<span>${h(toolName(tool))}</span></span>`).join("")}${tools.length > 2 ? `<span class="world-tool-more" title="${h(names.join(", "))}">+${tools.length - 2}</span>` : ""}</div>`;
|
|
1960
1941
|
}
|
|
1961
|
-
function worldsTable(worlds2,
|
|
1962
|
-
|
|
1963
|
-
|
|
1942
|
+
function worldsTable(worlds2, testCounts, writable = true, options = {}) {
|
|
1943
|
+
const people2 = worlds2.some((world) => Array.isArray(world.people ?? world.configuration?.people));
|
|
1944
|
+
const empty3 = `<p class="k-empty">No worlds</p>${writable ? '<div class="k-card-head"><a href="/worlds/new" data-nav class="k-btn primary">Create world</a></div>' : ""}`;
|
|
1945
|
+
return `<section class="k-card"><div class="k-card-head"><h2>${worlds2.length} ${worlds2.length === 1 ? "world" : "worlds"}</h2></div>${worlds2.length ? `<div class="k-scroll" role="region" aria-label="Worlds" tabindex="0"><table class="k-table wide"><thead><tr><th scope="col">World</th><th scope="col">Tools</th>${people2 ? '<th scope="col" class="num">People</th>' : ""}${testCounts ? '<th scope="col" class="num">Tests</th>' : ""}<th scope="col" class="num">Revision</th><th scope="col" class="num">Updated</th></tr></thead><tbody>${worlds2.map((world) => {
|
|
1964
1946
|
const base = "/worlds/" + encodeURIComponent(world.id) + (options.startingData ? "?data=1" : "");
|
|
1965
|
-
|
|
1966
|
-
|
|
1947
|
+
const persons = world.people ?? world.configuration?.people;
|
|
1948
|
+
return `<tr><td><a data-nav class="k-name" href="${base}" title="${h(world.name)}">${h(world.name)}</a><div class="worlds-id"><code title="${h(world.id)}">${h(shortId(world.id))}</code>${copyButton(world.id, "Copy world id")}</div></td><td>${worldToolsCell(world)}</td>${people2 ? `<td class="num">${Array.isArray(persons) ? persons.length : "\u2014"}</td>` : ""}${testCounts ? `<td class="num"><a data-nav class="k-name" href="${base}" data-world-count="${h(world.id)}">${h(testCounts.get(world.id) ?? 0)}</a></td>` : ""}<td class="num">${h(world.revision ?? "\u2014")}</td><td class="num">${when(world.updatedAt)}</td></tr>`;
|
|
1949
|
+
}).join("")}</tbody></table></div>` : empty3}</section>`;
|
|
1967
1950
|
}
|
|
1968
1951
|
|
|
1969
1952
|
// frontend/src/agent-page.ts
|
|
1970
1953
|
function agentConnection(agent, operation) {
|
|
1954
|
+
const recorded = agent.verification;
|
|
1955
|
+
operation ??= recorded ? { state: recorded.status, stale: recorded.status === "stale" } : null;
|
|
1971
1956
|
const ready = agent.execution?.mode === "container" && !!agent.taskInput;
|
|
1972
|
-
const [kind, label2] = operation?.state === "connecting" ? ["running", "Connecting\u2026"] : operation?.state === "queued" ? ["queued", "Connect queued"] : operation?.stale ? ["invalid", "Needs recheck"] : operation?.state === "connected" ? ["passed", "
|
|
1957
|
+
const [kind, label2] = operation?.state === "connecting" ? ["running", "Connecting\u2026"] : operation?.state === "queued" ? ["queued", "Connect queued"] : operation?.stale ? ["invalid", "Needs recheck"] : operation?.state === "connected" ? ["passed", "Ready"] : operation?.state === "failed" ? ["failed", "Connection failed"] : operation?.state === "cancelled" ? ["stopped", "Connection cancelled"] : operation?.state === "configured" || ready ? ["ungraded", "Configured"] : ["ungraded", "Not connected"];
|
|
1973
1958
|
return { kind, label: label2 };
|
|
1974
1959
|
}
|
|
1960
|
+
function agentConnectionBadge(agent, operation = null) {
|
|
1961
|
+
const { kind, label: label2 } = agentConnection(agent, operation);
|
|
1962
|
+
return `<span class="k-badge ${kind === "passed" ? "pass" : kind === "failed" ? "fail" : kind === "invalid" ? "none" : ""}">${h(label2)}</span>`;
|
|
1963
|
+
}
|
|
1964
|
+
function agentCrumbs(home, agent, page) {
|
|
1965
|
+
return `<nav class="k-crumbs" aria-label="Breadcrumb"><a href="${h(home)}" data-nav>Agents</a>${agent ? `<span>/</span>${page ? `<a href="/agents/${encodeURIComponent(agent.id)}" data-nav>${h(agent.name)}</a><span>/</span><span aria-current="page">${h(page)}</span>` : `<span aria-current="page">${h(agent.name)}</span>`}` : page ? `<span>/</span><span aria-current="page">${h(page)}</span>` : ""}</nav>`;
|
|
1966
|
+
}
|
|
1967
|
+
function agentPageHead(name, actions = "", badge2 = "") {
|
|
1968
|
+
return `<header class="k-head"><div class="k-title"><h1>${h(name)}</h1>${badge2}</div><div class="k-actions">${actions}</div></header>`;
|
|
1969
|
+
}
|
|
1975
1970
|
function agentFacts(agent, operation) {
|
|
1976
|
-
const
|
|
1977
|
-
const command = String(agent.command ?? agent.configPath ?? "");
|
|
1971
|
+
const folder = String(agent.cwd ?? ""), command = String(agent.command ?? agent.configPath ?? "");
|
|
1978
1972
|
const execution = agent.execution?.mode === "container" ? String(agent.execution.image ?? "Container") : "Host process";
|
|
1979
1973
|
const items = [
|
|
1980
|
-
{ label: "Folder", value: folder, mono: true, title: folder, html: `<span class="
|
|
1981
|
-
{ label: agent.command ? "Start command" : "Config", value: command, mono: true, title: command
|
|
1974
|
+
{ label: "Folder", value: folder, mono: true, title: folder, html: `<span class="ag-copy"><span>${h(folder)}</span>${copyButton(folder, "Copy folder")}</span>` },
|
|
1975
|
+
{ label: agent.command ? "Start command" : "Config", value: command, mono: true, title: command },
|
|
1982
1976
|
{ label: "Execution", value: execution, mono: agent.execution?.mode === "container", title: execution },
|
|
1983
|
-
{ label: "Connection", value:
|
|
1977
|
+
{ label: "Connection", value: "", html: agentConnectionBadge(agent, operation) }
|
|
1984
1978
|
];
|
|
1985
1979
|
if (agent.provider?.model) items.push({ label: "Model", value: String(agent.provider.model) });
|
|
1986
|
-
return
|
|
1980
|
+
return `<section class="k-card" aria-label="Agent facts"><div class="k-card-head"><h2>Details</h2></div><dl class="ag-facts">${items.map((f) => `<div class="k-kv"><dt class="k-label">${h(f.label)}</dt><dd${f.mono ? ' class="k-mono"' : ""}${f.title ? ` title="${h(f.title)}"` : ""}>${f.html ?? h(f.value)}</dd></div>`).join("")}</dl></section>`;
|
|
1981
|
+
}
|
|
1982
|
+
var newestFirst = (a, b) => (timeOf(b.createdAt) || 0) - (timeOf(a.createdAt) || 0) || String(b.id).localeCompare(String(a.id));
|
|
1983
|
+
var hasTest = (run, id) => run.test?.id === id || run.entries?.some((entry) => entry.test?.id === id);
|
|
1984
|
+
function historyBars(runs, history2) {
|
|
1985
|
+
const bars = runs.map((run) => {
|
|
1986
|
+
const counts = runCounts(run), states = attemptStates(run);
|
|
1987
|
+
const passed = counts.passed, failed = states.filter((state) => state === "failed").length;
|
|
1988
|
+
return { id: run.id, createdAt: run.createdAt, href: "/playgrounds/" + encodeURIComponent(run.id), passed, failed, none: Math.max(0, counts.total - passed - failed), total: counts.total };
|
|
1989
|
+
});
|
|
1990
|
+
for (const run of history2) {
|
|
1991
|
+
if (!run.summary || bars.some((bar) => bar.id === run.runId)) continue;
|
|
1992
|
+
const c = run.view?.counts, summary = run.summary;
|
|
1993
|
+
const scenes = summary?.scenes ?? [];
|
|
1994
|
+
const total = c?.total ?? scenes.reduce((n, s) => n + Number(s.trials ?? 0), 0);
|
|
1995
|
+
const ungraded = summary?.verdict === "ungraded" || run.view?.state === "ungraded";
|
|
1996
|
+
const passed = ungraded ? 0 : c?.passed ?? scenes.reduce((n, s) => n + Number(s.passed ?? 0), 0);
|
|
1997
|
+
const failed = ungraded ? 0 : c?.failed ?? 0;
|
|
1998
|
+
bars.push({ id: run.runId, createdAt: summary.startedAt ?? run.status?.startedAt, href: "/playgrounds/" + encodeURIComponent(run.runId), passed, failed, none: Math.max(0, total - passed - failed), total });
|
|
1999
|
+
}
|
|
2000
|
+
return bars.sort(newestFirst).slice(0, 10).reverse();
|
|
1987
2001
|
}
|
|
1988
2002
|
function agentRecentRuns(runs, agent, emptyAction, options = {}) {
|
|
1989
|
-
const selected = options.testId ? runs.filter((run) => run.test?.id === options.testId || run.entries?.some((entry) => entry.test?.id === options.testId)) : runs;
|
|
1990
|
-
const recent = [...selected].sort((a, b) => timeOf(b.createdAt) - timeOf(a.createdAt) || String(b.id).localeCompare(String(a.id))).slice(0, options.testId ? selected.length : 10);
|
|
1991
2003
|
const all = "/playgrounds?" + new URLSearchParams({ agent: agent.id });
|
|
1992
|
-
|
|
2004
|
+
if (options.testId) {
|
|
2005
|
+
const recent2 = runs.filter((run) => hasTest(run, options.testId)).sort(newestFirst);
|
|
2006
|
+
return `<section class="k-stack"><div class="k-head"><h2 class="k-h2">Runs</h2>${recent2.length ? `<a class="k-more" data-nav href="${h(all)}">All runs</a>` : ""}</div>${recent2.length ? runsTable(recent2, { now: options.now }) : stateCard("No runs yet", "Run a saved task to see its results here.", emptyAction)}</section>`;
|
|
2007
|
+
}
|
|
2008
|
+
const recent = historyBars(runs, options.history ?? []), max = Math.max(1, ...recent.map((run) => run.total));
|
|
2009
|
+
const legend = `<div class="ag-legend">${[["pass", "Passed"], ["fail", "Failed"], ["none", "No result"]].map(([kind, label2]) => `<span><span class="k-icon ${kind}" role="img" aria-label="${label2}"></span>${label2}</span>`).join("")}</div>`;
|
|
2010
|
+
return `<section class="k-card" aria-label="Results over time"><div class="k-card-head"><h2>${recent.length ? `Last ${recent.length} ${recent.length === 1 ? "run" : "runs"}` : "Runs"}</h2>${legend}</div>${recent.length ? `<div class="k-scroll"><div class="ag-chart"><div class="ag-axis k-meta"><span>${max}</span><span>0</span></div><div class="ag-bars">${recent.map((run) => {
|
|
2011
|
+
const label2 = `Run ${shortId(String(run.id))}: ${run.passed} passed, ${run.failed} failed, ${run.none} no result`;
|
|
2012
|
+
const pass = Math.round(10 * run.passed / max), fail = Math.round(10 * (run.passed + run.failed) / max) - pass;
|
|
2013
|
+
const none = Math.round(10 * run.total / max) - pass - fail;
|
|
2014
|
+
return `<a class="ag-run" href="${h(run.href)}" data-nav aria-label="${h(label2)}" title="${h(label2)}"><span class="ag-run-stack" aria-hidden="true"><span class="ag-segment pass ag-h-${pass}"></span><span class="ag-segment fail ag-h-${fail}"></span><span class="ag-segment none ag-h-${none}"></span></span><span class="ag-run-id">${h(String(run.id).slice(-7))}</span></a>`;
|
|
2015
|
+
}).join("")}</div></div></div><p class="k-note"><a class="k-more" data-nav href="${h(all)}">All runs</a></p>` : stateCard("No runs yet", "Run a saved task to see its results here.", emptyAction)}</section>`;
|
|
2016
|
+
}
|
|
2017
|
+
function testLastRun(run, testId) {
|
|
2018
|
+
const entries = (run.entries ?? []).filter((entry) => entry.test?.id === testId);
|
|
2019
|
+
let selected = run;
|
|
2020
|
+
if (entries.length) {
|
|
2021
|
+
const attempts = (run.attempts ?? []).filter((a) => entries.some((entry) => entry.id === a.entryId));
|
|
2022
|
+
const taskIds = new Set(attempts.map((a) => a.taskId));
|
|
2023
|
+
selected = { ...run, summary: void 0, attempts, tasks: (run.tasks ?? []).filter((t) => taskIds.has(t.id)) };
|
|
2024
|
+
}
|
|
2025
|
+
const c = runCounts(selected);
|
|
2026
|
+
if (!terminal(run.status)) return resultBadge(run.status === "queued" ? "queued" : "running");
|
|
2027
|
+
if (!c.graded || !c.total) return resultBadge(c.invalid ? "invalid" : "ungraded");
|
|
2028
|
+
const state = c.failed ? "fail" : c.passed === c.total ? "pass" : "none";
|
|
2029
|
+
const label2 = state === "pass" ? `Passed ${c.passed} of ${c.total}` : state === "fail" ? `Failed \xB7 ${c.passed} of ${c.total} passed` : `No result \xB7 ${c.passed} of ${c.total} passed`;
|
|
2030
|
+
return `<span class="k-badge ${state}">${h(label2)}</span>`;
|
|
2031
|
+
}
|
|
2032
|
+
function agentTests(tests, worlds2, runs, base, actions) {
|
|
2033
|
+
const latest = [...runs].sort(newestFirst);
|
|
2034
|
+
const rows3 = tests.map((test) => {
|
|
2035
|
+
const world = worlds2.find((world2) => world2.id === test.worldId);
|
|
2036
|
+
const href2 = "/worlds/" + encodeURIComponent(test.worldId) + "?" + new URLSearchParams({ agent: test.agentId, test: test.id });
|
|
2037
|
+
const run = latest.find((run2) => hasTest(run2, test.id));
|
|
2038
|
+
return `<tr><td class="wrap"><a class="k-name" data-nav href="${h(base)}?tab=test&test=${encodeURIComponent(test.id)}">${h(test.name)}</a><div class="k-meta"><a data-nav class="k-quiet" href="/worlds/${encodeURIComponent(test.worldId)}">${h(world?.name ?? "Saved world")}</a></div>${(test.tasks ?? []).map((task) => `<div class="ag-task"><a class="k-quiet" data-nav href="${h(href2)}" title="${h(task.prompt)}">${h(task.prompt)}</a><span class="k-meta">Repeat ${h(task.attempts)}</span></div>`).join("")}</td><td>${run ? `<a class="ag-result" href="/playgrounds/${encodeURIComponent(run.id)}" data-nav>${testLastRun(run, test.id)}</a>` : '<span class="k-muted">Not run yet</span>'}</td><td><div class="k-actions"><a class="k-more" data-nav href="${h(href2)}">Open world</a>${actions(test.id)}</div></td></tr>`;
|
|
2039
|
+
}).join("");
|
|
2040
|
+
return `<section class="k-card" aria-label="Tests"><div class="k-card-head"><h2>Tests \xB7 ${tests.length}</h2><a data-nav href="${h(base)}?tab=new-test">Add tests</a></div>${tests.length ? `<div class="k-scroll"><table class="k-table mid"><thead><tr><th scope="col">Test</th><th scope="col">Last run</th><th scope="col">Actions</th></tr></thead><tbody>${rows3}</tbody></table></div>` : '<p class="k-empty">Add tests to run this agent in a world.</p>'}</section>`;
|
|
1993
2041
|
}
|
|
1994
2042
|
|
|
1995
2043
|
// frontend/src/workspace-view.ts
|
|
@@ -2152,7 +2200,7 @@ function starterCount(tool, key, state) {
|
|
|
2152
2200
|
}
|
|
2153
2201
|
|
|
2154
2202
|
// frontend/src/generated/coding-agent-skill.ts
|
|
2155
|
-
var codingAgentSkill = "---\nname: ancha\ndescription: Test, debug and fix an AI agent (a Slack bot, a support or on-call agent) against stateful replicas of the tools it uses, built from its production traces, and prove a fix with graded runs in the cloud. Use when asked to test an agent with Ancha, or in a repository that has ancha.yaml.\n---\n\n# Ancha\n\nAncha gives an AI agent the other side of its job: stateful replicas of the tools it uses (Slack, GitHub, Datadog, PagerDuty and more), seeded with one fictional company or rebuilt from a production trace, and checks that grade every attempt from the agent's calls and the world's end state. The verdict comes from the world, not from mocks you wrote yourself. `ancha run --on cloud` runs each attempt on a fresh machine of its own in Ancha's cloud.\n\n## Run the CLI\n\nBefore the CLI is installed, run every command as `npx -y @ancha-labs/cli <command>`. After `npm install -g @ancha-labs/cli` (Node 24 or newer), run `ancha <command>`. Never run `npx` with the bare name `ancha`: that npm name is not this package.\n\nAdd `--json` to every command. Runs print NDJSON events that end with `run_finished`; `ancha traces upload` prints the tests it made. `env list` and `sandbox list` return arrays; trace commands use the fields described in `ancha docs traces`. `ancha schema <kind> --json` prints the JSON Schema of `ancha.yaml`, test files (`scene.yaml`) and these outputs. If your command can time out, give `ancha run` an `--idempotency-key <key>`: running it again with the same key returns the same run instead of starting another.\n\n## First steps\n\n<!-- ancha:first-steps -->\n1. **Install the CLI and sign in.** It needs Node 24 or newer. Approve this computer in the browser, once.\n ```sh\n ancha --version || npm install -g @ancha-labs/cli\n ancha login\n ```\n2. **Set up the project.** Run it in the agent's project: it finds the command that starts the agent and how the agent takes its task, and writes both to `ancha.yaml`. It installs and runs nothing.\n ```sh\n ancha init\n ```\n - To name the command yourself: `ancha init --agent \"<the command that starts your agent>\"`.\n - To name its tools yourself (NetSuite, Slack, ...): `ancha init --tools netsuite,slack`.\n3. **Store the key it needs.** The agent's own model key, read from your shell, never from an argument: it is stored in your workspace and named under `agent.pass_env` in `ancha.yaml`, so the agent gets it in every cloud attempt.\n ```sh\n ancha secrets set ANTHROPIC_API_KEY\n ```\n4. **Upload your agent.** A fresh machine in the cloud installs the project's dependencies and starts the agent once with a task. It says the agent is ready, or shows the end of its log.\n ```sh\n ancha agent upload\n ```\n - The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.\n5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests from the questions an operator asks.\n - Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.\n - Your evals: `ancha test import <file> --world <id>` (JSONL, JSON, CSV or YAML with a question and an expected answer).\n - One test from a sentence: `ancha test new \"<sentence>\" --world <id>`.\n6. **Upload traces.** A file or a folder of traces, runs that went fine and runs that failed: each trace becomes a test, in `scenes/from-traces/` and in your workspace.\n ```sh\n ancha traces upload ./traces\n ```\n - From Langfuse or LangSmith, with your keys on this computer: `ancha traces upload --from langfuse --limit 50`, or `--from langsmith`.\n - A trace of a run that went wrong can say what went wrong: `ancha traces upload <trace file> --expect \"<what went wrong>\"`, or for a test already made, `ancha pull <test id> --expect \"<what went wrong>\"`.\n - Traces your agent already sent to your workspace: `ancha traces`, then `ancha pull <trace id>`.\n - A test lists what one trace cannot settle: answer with `ancha pull <test id> --answer <question>=<answer>`.\n7. **Point the agent at the test's tools.** In a test, the agent calls Ancha instead of production:\n - Its clients for Slack, GitHub and the other tools Ancha replicates take the URLs and credentials Ancha supplies: `ancha connect <tool>` prints the settings.\n - Its own functions: wrap them with `wrapTools` from `@ancha-labs/tools` (`ancha.wrap_tools` in Python), or serve them over MCP.\n8. **Run your tests.** Every test, each attempt on a fresh machine. The run grades each attempt check by check and ends with the link to its result.\n ```sh\n ancha run\n ```\n - Your agent and its worlds run in the cloud, each attempt on a fresh machine of its own; a run keeps going when your laptop closes, and its results land in Runs.\n - `--attempts <n>` sets how many attempts each test gets, `--concurrency <n>` how many run at once.\n - `ancha wait <run id>` follows a run again from any terminal; `ancha explain <run id>` shows why a check failed.\n - `ancha status` shows which of these steps your workspace has done.\n9. **Fix the agent and keep the test.** Keep the failing run as the reference, fix the agent, and run again: exit 0 means every check passes and nothing regressed.\n ```sh\n ancha baseline save before --from <run id>\n ancha run --compare before\n ```\n - Commit `scenes/from-traces/` so every run, in CI too, keeps it fixed.\n10. **Run it on this computer.** While you develop, `ancha run --on local` runs the agent and its worlds on this computer, with the same checks.\n ```sh\n ancha run --on local --attempts 1\n ```\n - Here the agent gets the keys in `agent.pass_env` from your shell, and model-graded checks need `OPENROUTER_API_KEY`.\n<!-- /ancha:first-steps -->\n\n## Cloud runs\n\n- `ancha run --on cloud` sends the project as one bundle: the agent's files, without hidden directories, dependencies or credential-like files, and its tests with their worlds and checks, which stay with the grader and never reach the agent. Each attempt's machine installs the dependencies, runs the agent and grades it with the same engine as a run on this computer. `--attempts <n>` sets the attempts per test, `--concurrency <n>` how many run at once.\n- The agent gets the workspace's secrets for the names in `agent.pass_env`, and its network reaches its tools and its model providers. Model-graded checks and the people in a world run on the workspace's model credit.\n- The `run_finished` event carries `url` (the result in the workspace) and `summary`, with `counts` of the attempts: requested, completed, invalid, skipped and cancelled. Interrupting the command stops the following, never the run: `ancha wait <run id>` follows it again, and `--detach` returns once the run is accepted.\n- `ancha explain <run id> --json` shows each failed check: what was expected, what happened, and the calls and world events behind it. Read it before guessing from the code; many bugs only show up with the world's data and timing.\n- When every attempt ended before the agent did anything (it exited within seconds without a call, or its command could not start), the run, `ancha wait` and `ancha explain` say that first: \"Your agent didn't run\", the end of its log once, and the likely fix read from it, such as the `agent.env` line that gives the agent its task under the name it reads. `agentNeverRan` in the JSON carries the same. Make that fix first: the failed checks follow from it, and `ancha explain <run id> --all` lists them.\n- `ancha status --json` shows the workspace's three steps (agent uploaded, tests added, tests run in the cloud) and the next command. In CI, `ANCHA_SERVER_URL` and `ANCHA_API_KEY` replace the login. More: `ancha docs cloud`.\n\n## An app, not a command\n\nIf the AI feature lives inside an app (a web app or API server with its database, workers and scheduled jobs), don't wrap it in `agent.command`. Ancha starts the app once per attempt with `agent.start`, waits for `agent.ready_url`, delivers the tools' events to `agent.url`, and a scene's `world_rules.app_calls` call the app's own routes, such as its cron jobs, at a time. Read `ancha docs apps` before writing `ancha.yaml`. The start script gives the app a clean database, cache and seed every attempt: a new world has new URLs and tokens, and stale rows or sync cursors make an app silently do nothing.\n\n## More from production traces\n\n`ancha traces upload <file or folder> --json` sends the traces to the workspace, which rebuilds each one's world and checks, and writes each test to `scenes/from-traces/<name>/scene.yaml`: runs that went fine and runs that failed. `--from langfuse` or `--from langsmith` takes the newest traces there instead (`--limit`, `--since`), with the keys in this shell. For one trace of a failure, `--expect \"<what went wrong>\"` adds a check for it. A test lists the questions one trace cannot settle, each with the default it uses. Ask the user for the answers; don't guess them. Pass them with `ancha pull <test id> --answer <question>=<value>`. `ancha import --offline <trace file> --json` makes the tests on this computer instead, one per conversation, and uploads nothing; there, `--answer` and `--force` go on the import.\n\nA test from a run that failed should fail the same way production did. If it doesn't, run it on this computer: `ancha traces diff <trace file> latest` shows the calls production made and the attempt didn't, and the import also lists the app's own setup calls, which the start script or an `app_call` has to make.\n\nIf the user's workspace takes traces (their agents send them to it), each trace becomes a test there: `ancha pull --all --json` writes every test that is turned on (`--agent <name>` for one agent's), `ancha traces --failed --json` lists the ones where production failed a check, `ancha traces show <id> --json` previews the test, and `ancha pull <id> --json` writes one, with `--answer` for its questions. Checks you add to a pulled `scene.yaml` stay when you pull a newer version; any other edit stops the pull. More: `ancha docs traces`.\n\n## Other tests\n\nThe starter test `ancha init` writes when `scenes/` holds no tests only proves that the agent reaches each tool. For the agent's real job beyond its traces, `ancha test new \"<the test in one sentence>\" --json` drafts a test with people for the project's world (`ancha init --intent \"<company and scenario>\"` makes the world and a first test). Review its checks before you run it. To write a seed yourself, `ancha twins seed <tool> --json` prints the tool's fields, an example that validates as written, and the checks a test can make on it. More: `ancha docs scenes`.\n\n## The rule\n\nFix the agent, not the tests or their checks. `ancha.yaml` says how to start the agent and give it its task and keys: change it for that, never to make a check pass. The exception is a check that is wrong for the real API, such as a method the official SDK never sends. Then don't quietly edit it: tell the user, show the evidence (the call from `ancha explain`, the vendor's documentation), and change it only with their agreement.\n\nNever give the agent under test the tests, checks, seeds or reference companions (`oracle.mjs`, `null.mjs`), and never point it at a real SaaS API.\n\n## What the agent gets\n\nEach attempt gives the agent its tools as environment variables, with fake credentials that only work against the replicas:\n\n- Slack: `SLACK_API_URL` (ends in `/api/`), `SLACK_BOT_TOKEN`\n- GitHub: `GITHUB_API_URL`, `GITHUB_TOKEN`\n- Datadog: `DATADOG_API_URL`, `DD_API_KEY`, `DD_APP_KEY`\n- PagerDuty: `PAGERDUTY_API_URL`, `PAGERDUTY_API_TOKEN`, `PAGERDUTY_FROM_EMAIL`, `PAGERDUTY_ROUTING_KEY`\n- the same pattern for the other tools in the world; `ANCHA_TASK` carries a command-line task, and `ANCHA_TASK_FILE` names a file holding it. An agent that reads its task under another name gets it with `agent.env: { MY_TASK: \"{{task}}\" }` (`{{task_file}}` for the file); `ancha init` writes that line when it finds the name.\n\n`ancha connect <tool> --lang ts|py` prints the SDK settings. `ancha twins coverage <tool>` lists the endpoints each replica implements.\n\nGoogle clients (`googleapis`, `@googleapis/*`) take the replica's URL in each call's options: `drive.files.list(params, { rootUrl: process.env.GOOGLE_DRIVE_API_URL + '/' })`. A `rootUrl` set on the client keeps only the host; Ancha still routes those calls by their token, but the client sends file uploads to www.googleapis.com.\n\nThe agent's own keys are the names in `agent.pass_env` in `ancha.yaml`, such as `agent.pass_env: [OPENAI_API_KEY]`, and `agent.env` sets fixed values, such as the path of a key file. In the cloud each name comes from the workspace's secrets (`ancha secrets set NAME`). `ancha run --on local` starts the agent on this computer instead, with this computer's network and those names from this shell (or `--pass-env NAME`); `--on docker` seals it in a container (`agent.execution: { mode: container, image: node:24-slim }`, which needs Docker). An agent without its model key stops at its first model call.\n\n## When something fails\n\n- Exit 1: a check failed or the comparison regressed (a single check's drop counts, see `comparison.droppedChecks`). Run `ancha explain <run id> --json`.\n- Exit 2: usage, config, test file or authentication error, or a cancelled cloud run. `AUTH_INVALID` means `ancha login` again or a valid `ANCHA_API_KEY`; `CONFIG_INVALID` naming a workspace secret means `ancha secrets set NAME`. Read the `hint`.\n- Exit 3: infrastructure, or an attempt the harness couldn't run or grade. It counts as invalid, never as a failed check, so it's not the agent's fault; run again, and `ancha agent upload --json` if it repeats.\n- Exit 4, only with `--strict`: an endpoint coverage error or a verdict using simulated tool answers. The summary names the tests, trials and evaluated checks using those answers. `ancha explain` lists endpoint errors; `ancha twins coverage <tool>` shows the endpoint inventory.\n\nRead the error's stable `code` and `message`, then follow its `hint` when provided. More: `ancha docs`, `ancha docs <topic>` for setup, run, traces, explain, compare, scenes, integrations, cloud and playgrounds, and https://docs.ancha.io/coding-agents.\n\nTell the user what you ran, where it ran, the pass rate, the evidence and the result link. Never claim a fix until `ancha run --compare` exits 0.\n";
|
|
2203
|
+
var codingAgentSkill = "---\nname: ancha\ndescription: Test, debug and fix an AI agent (a Slack bot, a support or on-call agent) against stateful replicas of the tools it uses, built from its production traces, and prove a fix with graded runs in the cloud. Use when asked to test an agent with Ancha, or in a repository that has ancha.yaml.\n---\n\n# Ancha\n\nAncha gives an AI agent the other side of its job: stateful replicas of the tools it uses (Slack, GitHub, Datadog, PagerDuty and more), seeded with one fictional company or rebuilt from a production trace, and checks that grade every attempt from the agent's calls and the world's end state. The verdict comes from the world, not from mocks you wrote yourself. `ancha run --on cloud` runs each attempt on a fresh machine of its own in Ancha's cloud.\n\n## Run the CLI\n\nBefore the CLI is installed, run every command as `npx -y @ancha-labs/cli <command>`. After `npm install -g @ancha-labs/cli` (Node 24 or newer), run `ancha <command>`. Never run `npx` with the bare name `ancha`: that npm name is not this package.\n\nAdd `--json` to every command. Runs print NDJSON events that end with `run_finished`; `ancha traces upload` prints the tests it made. `env list` and `sandbox list` return arrays; trace commands use the fields described in `ancha docs traces`. `ancha schema <kind> --json` prints the JSON Schema of `ancha.yaml`, test files (`scene.yaml`) and these outputs. If your command can time out, give `ancha run` an `--idempotency-key <key>`: running it again with the same key returns the same run instead of starting another.\n\n## First steps\n\n<!-- ancha:first-steps -->\n1. **Install the CLI and sign in.** It needs Node 24 or newer. Approve this computer in the browser, once.\n ```sh\n ancha --version || npm install -g @ancha-labs/cli\n ancha login\n ```\n2. **Set up the project.** Run it in the agent's project: it finds the command that starts the agent and how the agent takes its task, and writes both to `ancha.yaml`. It installs and runs nothing.\n ```sh\n ancha init\n ```\n - To name the command yourself: `ancha init --agent \"<the command that starts your agent>\"`.\n - To name its tools yourself (NetSuite, Slack, ...): `ancha init --tools netsuite,slack`.\n3. **Store the key it needs.** The agent's own model key, read from your shell, never from an argument: it is stored in your workspace and named under `agent.pass_env` in `ancha.yaml`, so the agent gets it in every cloud attempt.\n ```sh\n ancha secrets set ANTHROPIC_API_KEY\n ```\n4. **Upload your agent.** A fresh machine in the cloud installs the project's dependencies and starts the agent once with a task. It says the agent is ready, or shows the end of its log.\n ```sh\n ancha agent upload\n ```\n - The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.\n5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests: 10 read tasks and 15 write workflows.\n - Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.\n - Your evals: `ancha test import <file> --world <id>` (JSONL, JSON, CSV or YAML with a question and an expected answer).\n - One test from a sentence: `ancha test new \"<sentence>\" --world <id>`.\n6. **Upload traces.** A file or a folder of traces, runs that went fine and runs that failed: each trace becomes a test, in `scenes/from-traces/` and in your workspace.\n ```sh\n ancha traces upload ./traces\n ```\n - From Langfuse or LangSmith, with your keys on this computer: `ancha traces upload --from langfuse --limit 50`, or `--from langsmith`.\n - A trace of a run that went wrong can say what went wrong: `ancha traces upload <trace file> --expect \"<what went wrong>\"`, or for a test already made, `ancha pull <test id> --expect \"<what went wrong>\"`.\n - Traces your agent already sent to your workspace: `ancha traces`, then `ancha pull <trace id>`.\n - A test lists what one trace cannot settle: answer with `ancha pull <test id> --answer <question>=<answer>`.\n7. **Point the agent at the test's tools.** In a test, the agent calls Ancha instead of production:\n - Its clients for Slack, GitHub and the other tools Ancha replicates take the URLs and credentials Ancha supplies: `ancha connect <tool>` prints the settings.\n - Its own functions: wrap them with `wrapTools` from `@ancha-labs/tools` (`ancha.wrap_tools` in Python), or serve them over MCP.\n8. **Run your tests.** Every test, each attempt on a fresh machine. The run grades each attempt check by check and ends with the link to its result.\n ```sh\n ancha run\n ```\n - Your agent and its worlds run in the cloud, each attempt on a fresh machine of its own; a run keeps going when your laptop closes, and its results land in Runs.\n - `--attempts <n>` sets how many attempts each test gets, `--concurrency <n>` how many run at once.\n - `ancha wait <run id>` follows a run again from any terminal; `ancha explain <run id>` shows why a check failed.\n - `ancha status` shows which of these steps your workspace has done.\n9. **Fix the agent and keep the test.** Keep the failing run as the reference, fix the agent, and run again: exit 0 means every check passes and nothing regressed.\n ```sh\n ancha baseline save before --from <run id>\n ancha run --compare before\n ```\n - Commit `scenes/from-traces/` so every run, in CI too, keeps it fixed.\n10. **Run it on this computer.** While you develop, `ancha run --on local` runs the agent and its worlds on this computer, with the same checks.\n ```sh\n ancha run --on local --attempts 1\n ```\n - Here the agent gets the keys in `agent.pass_env` from your shell, and model-graded checks need `OPENROUTER_API_KEY`.\n<!-- /ancha:first-steps -->\n\n## Cloud runs\n\n- `ancha run --on cloud` sends the project as one bundle: the agent's files, without hidden directories, dependencies or credential-like files, and its tests with their worlds and checks, which stay with the grader and never reach the agent. Each attempt's machine installs the dependencies, runs the agent and grades it with the same engine as a run on this computer. `--attempts <n>` sets the attempts per test, `--concurrency <n>` how many run at once.\n- The agent gets the workspace's secrets for the names in `agent.pass_env`, and its network reaches its tools and its model providers. Model-graded checks and the people in a world run on the workspace's model credit.\n- The `run_finished` event carries `url` (the result in the workspace) and `summary`, with `counts` of the attempts: requested, completed, invalid, skipped and cancelled. Interrupting the command stops the following, never the run: `ancha wait <run id>` follows it again, and `--detach` returns once the run is accepted.\n- `ancha explain <run id> --json` shows each failed check: what was expected, what happened, and the calls and world events behind it. Read it before guessing from the code; many bugs only show up with the world's data and timing.\n- When every attempt ended before the agent did anything (it exited within seconds without a call, or its command could not start), the run, `ancha wait` and `ancha explain` say that first: \"Your agent didn't run\", the end of its log once, and the likely fix read from it, such as the `agent.env` line that gives the agent its task under the name it reads. `agentNeverRan` in the JSON carries the same. Make that fix first: the failed checks follow from it, and `ancha explain <run id> --all` lists them.\n- `ancha status --json` shows the workspace's three steps (agent uploaded, tests added, tests run in the cloud) and the next command. In CI, `ANCHA_SERVER_URL` and `ANCHA_API_KEY` replace the login. More: `ancha docs cloud`.\n\n## An app, not a command\n\nIf the AI feature lives inside an app (a web app or API server with its database, workers and scheduled jobs), don't wrap it in `agent.command`. Ancha starts the app once per attempt with `agent.start`, waits for `agent.ready_url`, delivers the tools' events to `agent.url`, and a scene's `world_rules.app_calls` call the app's own routes, such as its cron jobs, at a time. Read `ancha docs apps` before writing `ancha.yaml`. The start script gives the app a clean database, cache and seed every attempt: a new world has new URLs and tokens, and stale rows or sync cursors make an app silently do nothing.\n\n## More from production traces\n\n`ancha traces upload <file or folder> --json` sends the traces to the workspace, which rebuilds each one's world and checks, and writes each test to `scenes/from-traces/<name>/scene.yaml`: runs that went fine and runs that failed. `--from langfuse` or `--from langsmith` takes the newest traces there instead (`--limit`, `--since`), with the keys in this shell. For one trace of a failure, `--expect \"<what went wrong>\"` adds a check for it. A test lists the questions one trace cannot settle, each with the default it uses. Ask the user for the answers; don't guess them. Pass them with `ancha pull <test id> --answer <question>=<value>`. `ancha import --offline <trace file> --json` makes the tests on this computer instead, one per conversation, and uploads nothing; there, `--answer` and `--force` go on the import.\n\nA test from a run that failed should fail the same way production did. If it doesn't, run it on this computer: `ancha traces diff <trace file> latest` shows the calls production made and the attempt didn't, and the import also lists the app's own setup calls, which the start script or an `app_call` has to make.\n\nIf the user's workspace takes traces (their agents send them to it), each trace becomes a test there: `ancha pull --all --json` writes every test that is turned on (`--agent <name>` for one agent's), `ancha traces --failed --json` lists the ones where production failed a check, `ancha traces show <id> --json` previews the test, and `ancha pull <id> --json` writes one, with `--answer` for its questions. Checks you add to a pulled `scene.yaml` stay when you pull a newer version; any other edit stops the pull. More: `ancha docs traces`.\n\n## Other tests\n\nThe starter test `ancha init` writes when `scenes/` holds no tests only proves that the agent reaches each tool. For the agent's real job beyond its traces, `ancha test new \"<the test in one sentence>\" --json` drafts a test with people for the project's world (`ancha init --intent \"<company and scenario>\"` makes the world and a first test). Review its checks before you run it. To write a seed yourself, `ancha twins seed <tool> --json` prints the tool's fields, an example that validates as written, and the checks a test can make on it. More: `ancha docs scenes`.\n\n## The rule\n\nFix the agent, not the tests or their checks. `ancha.yaml` says how to start the agent and give it its task and keys: change it for that, never to make a check pass. The exception is a check that is wrong for the real API, such as a method the official SDK never sends. Then don't quietly edit it: tell the user, show the evidence (the call from `ancha explain`, the vendor's documentation), and change it only with their agreement.\n\nNever give the agent under test the tests, checks, seeds or reference companions (`oracle.mjs`, `null.mjs`), and never point it at a real SaaS API.\n\n## What the agent gets\n\nEach attempt gives the agent its tools as environment variables, with fake credentials that only work against the replicas:\n\n- Slack: `SLACK_API_URL` (ends in `/api/`), `SLACK_BOT_TOKEN`\n- GitHub: `GITHUB_API_URL`, `GITHUB_TOKEN`\n- Datadog: `DATADOG_API_URL`, `DD_API_KEY`, `DD_APP_KEY`\n- PagerDuty: `PAGERDUTY_API_URL`, `PAGERDUTY_API_TOKEN`, `PAGERDUTY_FROM_EMAIL`, `PAGERDUTY_ROUTING_KEY`\n- the same pattern for the other tools in the world; `ANCHA_TASK` carries a command-line task, and `ANCHA_TASK_FILE` names a file holding it. An agent that reads its task under another name gets it with `agent.env: { MY_TASK: \"{{task}}\" }` (`{{task_file}}` for the file); `ancha init` writes that line when it finds the name.\n\n`ancha connect <tool> --lang ts|py` prints the SDK settings. `ancha twins coverage <tool>` lists the endpoints each replica implements.\n\nGoogle clients (`googleapis`, `@googleapis/*`) take the replica's URL in each call's options: `drive.files.list(params, { rootUrl: process.env.GOOGLE_DRIVE_API_URL + '/' })`. A `rootUrl` set on the client keeps only the host; Ancha still routes those calls by their token, but the client sends file uploads to www.googleapis.com.\n\nThe agent's own keys are the names in `agent.pass_env` in `ancha.yaml`, such as `agent.pass_env: [OPENAI_API_KEY]`, and `agent.env` sets fixed values, such as the path of a key file. In the cloud each name comes from the workspace's secrets (`ancha secrets set NAME`). `ancha run --on local` starts the agent on this computer instead, with this computer's network and those names from this shell (or `--pass-env NAME`); `--on docker` seals it in a container (`agent.execution: { mode: container, image: node:24-slim }`, which needs Docker). An agent without its model key stops at its first model call.\n\n## When something fails\n\n- Exit 1: a check failed or the comparison regressed (a single check's drop counts, see `comparison.droppedChecks`). Run `ancha explain <run id> --json`.\n- Exit 2: usage, config, test file or authentication error, or a cancelled cloud run. `AUTH_INVALID` means `ancha login` again or a valid `ANCHA_API_KEY`; `CONFIG_INVALID` naming a workspace secret means `ancha secrets set NAME`. Read the `hint`.\n- Exit 3: infrastructure, or an attempt the harness couldn't run or grade. It counts as invalid, never as a failed check, so it's not the agent's fault; run again, and `ancha agent upload --json` if it repeats.\n- Exit 4, only with `--strict`: an endpoint coverage error or a verdict using simulated tool answers. The summary names the tests, trials and evaluated checks using those answers. `ancha explain` lists endpoint errors; `ancha twins coverage <tool>` shows the endpoint inventory.\n\nRead the error's stable `code` and `message`, then follow its `hint` when provided. More: `ancha docs`, `ancha docs <topic>` for setup, run, traces, explain, compare, scenes, integrations, cloud and playgrounds, and https://docs.ancha.io/coding-agents.\n\nTell the user what you ran, where it ran, the pass rate, the evidence and the result link. Never claim a fix until `ancha run --compare` exits 0.\n";
|
|
2156
2204
|
|
|
2157
2205
|
// frontend/src/workspace-pages.ts
|
|
2158
2206
|
var startSentence = "Set up Ancha for this agent: read https://app.ancha.io/llms.txt and follow its first steps.";
|
|
@@ -2195,28 +2243,10 @@ function helpPage() {
|
|
|
2195
2243
|
return `<section class="help-focus"><h2>Use with your coding agent.</h2><p>Give it Ancha\u2019s instructions to connect your project, create a world, and run tests.</p><div class="actions"><button class="primary" data-action="copy-ancha-skill">Copy instructions</button><button data-action="download-ancha-skill">Download SKILL.md</button><a class="button-link" href="https://app.ancha.io/llms.txt" target="_blank" rel="noopener">Open llms.txt</a></div></section><section class="help-reference"><h2>Command reference</h2><div class="catalog-scroll" tabindex="0" aria-label="Command reference"><table class="catalog-table help-table"><thead><tr><th scope="col">Command</th><th scope="col">What it does</th></tr></thead>${groups.map(([job, commands]) => `<tbody><tr class="help-job"><th scope="rowgroup" colspan="2">${h(job)}</th></tr>${commands.map(([command, description]) => `<tr><td><div class="catalog-copy"><code>${h(command)}</code>${copyButton(command, "Copy command")}</div></td><td>${h(description)}</td></tr>`).join("")}</tbody>`).join("")}</table></div><p class="muted">CLI guide: <code>ancha docs cli-quickstart</code></p></section>`;
|
|
2196
2244
|
}
|
|
2197
2245
|
function testCard(test, world, base, actions, detail = false) {
|
|
2198
|
-
return `<section class="agent-saved-test"><header><div>${detail ? "" : `<a class="test-title" data-nav href="${h(base)}?tab=test&test=${encodeURIComponent(test.id)}">${h(test.name)}</a>`}<div class="test-context">${world ? `<a data-nav href="/worlds/${encodeURIComponent(world.id)}">${h(world.name)}</a>` : "Saved world"}<span>\xB7</span><span>${test.tasks.length} ${test.tasks.length === 1 ? "task" : "tasks"}</span></div></div><div class="actions">${actions}</div></header><div class="
|
|
2199
|
-
}
|
|
2200
|
-
function agentWorldTasks(tests, worlds2, actions) {
|
|
2201
|
-
const groups = /* @__PURE__ */ new Map();
|
|
2202
|
-
for (const test of tests) {
|
|
2203
|
-
const group = groups.get(test.worldId) ?? [];
|
|
2204
|
-
group.push(test);
|
|
2205
|
-
groups.set(test.worldId, group);
|
|
2206
|
-
}
|
|
2207
|
-
return `<div class="catalog-scroll agent-tasks-scroll" tabindex="0" aria-label="Tasks by world"><table class="catalog-table agent-tasks-table"><thead><tr><th scope="col">Prompt</th><th scope="col" class="num">Repeat</th><th scope="col">Actions</th></tr></thead>${[...groups].map(([worldId, configurations]) => {
|
|
2208
|
-
const world = worlds2.find((item) => item.id === worldId);
|
|
2209
|
-
return `<tbody><tr class="agent-world-group"><th scope="rowgroup" colspan="3"><a data-nav href="/worlds/${encodeURIComponent(worldId)}">${h(world?.name ?? "Saved world")}</a></th></tr>${configurations.map((test, place) => {
|
|
2210
|
-
const href2 = "/worlds/" + encodeURIComponent(worldId) + "?" + new URLSearchParams({ agent: test.agentId, test: test.id });
|
|
2211
|
-
const tasks = test.tasks ?? [];
|
|
2212
|
-
const cell2 = `<td rowspan="${Math.max(1, tasks.length)}" class="agent-task-actions${place === configurations.length - 1 ? " agent-task-last" : ""}"><div class="agent-task-config">${configurations.length > 1 ? `<span class="catalog-cut" title="${h(test.name)}">${h(test.name)}</span>` : ""}<div class="actions"><a data-nav href="${h(href2)}">Open world</a>${actions(test.id)}</div></div></td>`;
|
|
2213
|
-
if (!tasks.length) return `<tr><td class="muted">No tasks</td><td class="num">0</td>${cell2}</tr>`;
|
|
2214
|
-
return tasks.map((task, index) => `<tr><td><a data-nav class="catalog-cut" href="${h(href2)}" title="${h(task.prompt)}">${h(task.prompt)}</a></td><td class="num">${h(task.attempts)}</td>${index === 0 ? cell2 : ""}</tr>`).join("");
|
|
2215
|
-
}).join("")}</tbody>`;
|
|
2216
|
-
}).join("")}</table></div>`;
|
|
2246
|
+
return `<section class="agent-saved-test k-card"><header class="k-card-head"><div>${detail ? "" : `<a class="test-title" data-nav href="${h(base)}?tab=test&test=${encodeURIComponent(test.id)}">${h(test.name)}</a>`}<div class="test-context">${world ? `<a data-nav href="/worlds/${encodeURIComponent(world.id)}">${h(world.name)}</a>` : "Saved world"}<span>\xB7</span><span>${test.tasks.length} ${test.tasks.length === 1 ? "task" : "tasks"}</span></div></div><div class="k-actions">${actions}</div></header><div class="k-scroll" tabindex="0" aria-label="Test tasks"><table class="k-table"><thead><tr><th scope="col">Prompt</th><th scope="col" class="num">Repeat</th></tr></thead><tbody>${test.tasks.map((task) => `<tr><td class="wrap"><span class="ag-prompt" title="${h(task.prompt)}">${h(task.prompt)}</span></td><td class="num">${h(task.attempts)}</td></tr>`).join("")}</tbody></table></div></section>`;
|
|
2217
2247
|
}
|
|
2218
2248
|
var SECTIONS = { worlds: "Worlds", agents: "Agents", playgrounds: "Runs", tools: "Tools", help: "Help", settings: "Settings" };
|
|
2219
|
-
var notFoundPage = (hosted) => `<p>Nothing lives at this address.</p><p>${hosted ? '<a href="/start">
|
|
2249
|
+
var notFoundPage = (hosted) => `<p>Nothing lives at this address.</p><p>${hosted ? '<a href="/start">Go to Overview</a>' : '<a href="/playgrounds" data-nav>Go to Runs</a>'}</p>`;
|
|
2220
2250
|
var missingRun = (message) => /^(?:invalid playground run id|playground run was not found|run not found)\.?$/i.test(message);
|
|
2221
2251
|
var agentsHome = (hosted) => hosted ? "/agents?tab=connected" : "/agents";
|
|
2222
2252
|
var taskTool = (name) => name !== "google-ads";
|
|
@@ -2229,7 +2259,7 @@ function mountWorlds(node, worlds2, tools, selected, api2, go2) {
|
|
|
2229
2259
|
}
|
|
2230
2260
|
if (editing) {
|
|
2231
2261
|
const chosen = world?.configuration.preset.datasets.map((d) => d.tool) ?? [new URLSearchParams(location.search).get("tool")].filter((name) => !!name && taskTool(name) && tools.some((t) => t.name === name));
|
|
2232
|
-
node.innerHTML = `<form id="catalog-world-editor" class="world-editor-page"><label>World name<input name="name" maxlength="100" value="${h(world?.name ?? "")}" required autofocus></label><h2>Tools</h2><div class="world-tool-grid">${worldTools(tools, chosen).map((t) => `<label class="world-tool ${chosen.includes(t.name) ? "selected" : ""}"><input type="checkbox" name="tools" value="${h(t.name)}" ${chosen.includes(t.name) ? "checked" : ""}>${toolLogo(t.name)}<span title="${h(toolName(t.name))}">${h(toolName(t.name))}</span></label>`).join("")}</div><p class="error" role="alert" id="world-error"></p><div class="actions"><button type="submit" class="primary">Save world</button><a data-nav href="${world ? "/worlds/" + encodeURIComponent(world.id) : "/worlds"}">Cancel</a></div></form>`;
|
|
2262
|
+
node.innerHTML = `<form id="catalog-world-editor" class="world-editor-page k-card pad"><label>World name<input class="k-field" name="name" maxlength="100" value="${h(world?.name ?? "")}" required autofocus></label><h2 class="k-h2">Tools</h2><div class="world-tool-grid">${worldTools(tools, chosen).map((t) => `<label class="world-tool ${chosen.includes(t.name) ? "selected" : ""}"><input type="checkbox" name="tools" value="${h(t.name)}" ${chosen.includes(t.name) ? "checked" : ""}>${toolLogo(t.name)}<span title="${h(toolName(t.name))}">${h(toolName(t.name))}</span></label>`).join("")}</div><p class="error" role="alert" id="world-error"></p><div class="k-actions"><button type="submit" class="k-btn primary">Save world</button><a data-nav href="${world ? "/worlds/" + encodeURIComponent(world.id) : "/worlds"}">Cancel</a></div></form>`;
|
|
2233
2263
|
const form = node.querySelector("form");
|
|
2234
2264
|
form.addEventListener("change", (e) => {
|
|
2235
2265
|
const input = e.target;
|
|
@@ -2324,8 +2354,8 @@ function mountTestFlow(node, options) {
|
|
|
2324
2354
|
} else if (step === "tasks") {
|
|
2325
2355
|
node.innerHTML += `<form id="test-tasks"><label>Test name<input name="name" value="${h(draft.name)}" required maxlength="120" placeholder="e.g. Customer follow-ups"></label><div id="task-editors">${taskFields(draft.tasks)}</div><button type="button" data-flow="add-task">Add task</button><div class="task-start-bar"><label>Run at once<input name="concurrency" type="number" min="1" max="10" value="${h(draft.concurrency)}" required></label><button type="submit" class="primary">Review</button></div></form>`;
|
|
2326
2356
|
} else {
|
|
2327
|
-
const
|
|
2328
|
-
node.innerHTML += `<section class="test-review"><h2>${h(draft.name)}</h2><div class="review-world"><span>${h(agent.name)}</span><span aria-hidden="true">\u2192</span><strong>${h(world?.name ?? "Loading saved world\u2026")}</strong>${world ? `<span class="muted">Revision ${h(world.revision)}</span>` : ""}<span class="world-marks">${(world?.configuration.preset.datasets ?? []).map((d) => toolLogo(d.tool)).join("")}</span></div>${draft.tasks.map((t, i) => `<div class="review-task"><span class="muted">${i + 1}</span><p>${h(t.prompt)}</p><span>${t.attempts} trials \xB7 ${Number((t.timeoutMs / 6e4).toFixed(2))} min</span></div>`).join("")}<div class="flow-footer"><span>${
|
|
2357
|
+
const count2 = draft.tasks.reduce((n, t) => n + t.attempts, 0);
|
|
2358
|
+
node.innerHTML += `<section class="test-review"><h2>${h(draft.name)}</h2><div class="review-world"><span>${h(agent.name)}</span><span aria-hidden="true">\u2192</span><strong>${h(world?.name ?? "Loading saved world\u2026")}</strong>${world ? `<span class="muted">Revision ${h(world.revision)}</span>` : ""}<span class="world-marks">${(world?.configuration.preset.datasets ?? []).map((d) => toolLogo(d.tool)).join("")}</span></div>${draft.tasks.map((t, i) => `<div class="review-task"><span class="muted">${i + 1}</span><p>${h(t.prompt)}</p><span>${t.attempts} trials \xB7 ${Number((t.timeoutMs / 6e4).toFixed(2))} min</span></div>`).join("")}<div class="flow-footer"><span>${count2} trials \xB7 up to ${Math.min(count2, draft.concurrency)} at once</span>${pending ? "" : `<button type="button" data-flow="save-test" ${!world ? "disabled" : ""}>Save test</button>`}<button type="button" data-flow="run-test" class="primary" ${!world ? "disabled" : ""}>${pending ? "Retry same run" : draft.savedTest ? "Run test" : "Save and run"}</button></div></section>`;
|
|
2329
2359
|
}
|
|
2330
2360
|
}
|
|
2331
2361
|
async function execute(action2) {
|
|
@@ -2545,7 +2575,7 @@ function mountGroupFlow(node, options) {
|
|
|
2545
2575
|
}
|
|
2546
2576
|
let saving = false, error = "";
|
|
2547
2577
|
const selectedWorld = () => options.worlds.find((world) => world.id === draft.worldId && world.revision === draft.worldRevision);
|
|
2548
|
-
const
|
|
2578
|
+
const count2 = () => draft.tasks.reduce((sum2, task) => sum2 + Number(task.attempts || 0), 0) * draft.agentIds.length;
|
|
2549
2579
|
const remember = () => {
|
|
2550
2580
|
try {
|
|
2551
2581
|
sessionStorage.setItem(key, JSON.stringify(draft));
|
|
@@ -2576,7 +2606,7 @@ function mountGroupFlow(node, options) {
|
|
|
2576
2606
|
}
|
|
2577
2607
|
function render() {
|
|
2578
2608
|
remember();
|
|
2579
|
-
const world = selectedWorld(), selected = new Set(draft.agentIds), total =
|
|
2609
|
+
const world = selectedWorld(), selected = new Set(draft.agentIds), total = count2();
|
|
2580
2610
|
const pending = !!draft.pendingSubmission, uncertain = !!draft.submissionUncertain;
|
|
2581
2611
|
node.innerHTML = `<div class="flow-error group-flow-error" role="alert" ${error ? "" : "hidden"}>${h(error)}</div>${pending || uncertain ? '<p class="hint" role="status">We could not confirm whether this run started. Retry the same request to avoid creating a duplicate.</p>' : ""}${draft.step === "review" ? `<form id="group-run-form"><section class="group-review"><h2>${h(draft.name || "Agent comparison")}</h2><div class="group-review-summary"><strong>${draft.agentIds.length} agents</strong><span>${h(world?.name ?? "Shared world")} \xB7 revision ${h(world?.revision ?? "unselected")}</span></div><div class="group-review-agents">${options.agents.filter((a) => selected.has(a.id)).map((a) => `<span>${h(a.name)}</span>`).join("")}</div>${draft.tasks.map((task, index) => `<div class="review-task"><span class="muted">Task ${index + 1}</span><p>${h(task.prompt)}</p><span>${task.attempts} trials \xB7 ${timeLimit(task.timeoutMs)}</span></div>`).join("")}<div class="flow-footer"><span>${total} trials \xB7 up to ${Math.min(Number(draft.concurrency), total)} requested at once</span>${pending || uncertain ? "" : `<button type="button" data-group="back">Edit</button>`}<button type="submit" class="primary" ${saving || uncertain ? "disabled" : ""}>${pending ? "Retry same request" : "Start group run"}</button></div></section></form>` : `<form id="group-run-form"><section class="group-section"><label>Run name<input name="name" value="${h(draft.name)}" maxlength="120" required></label><fieldset class="group-agent-select"><legend>Agents</legend>${options.agents.map((agent) => `<label class="group-agent-choice"><input type="checkbox" name="agentIds" value="${h(agent.id)}" ${selected.has(agent.id) ? "checked" : ""}><span><strong>${h(agentLabel(agent, options.agents))}</strong></span></label>`).join("")}</fieldset><label>Shared world<select name="worldId" required><option value="">Choose a world</option>${options.worlds.map((w) => `<option value="${h(w.id)}" ${w.id === draft.worldId ? "selected" : ""}>${h(w.name)} \xB7 revision ${h(w.revision)}</option>`).join("")}</select></label>${options.worlds.length ? "" : '<p class="quiet-empty">Create a world from an agent\u2019s New test flow before starting a group run.</p>'}</section><section class="group-section"><div class="section-title"><h2>Tasks</h2><button type="button" data-group="add-task">Add task</button></div><div id="group-task-editors">${taskFields(draft.tasks)}</div><div class="task-start-bar"><label>Run at once<input name="concurrency" type="number" min="1" max="10" value="${h(draft.concurrency)}" required></label><span id="group-attempt-count">${total} trials across ${draft.agentIds.length} agents</span><button type="submit" class="primary" ${options.agents.length < 2 || options.worlds.length === 0 ? "disabled" : ""}>Review</button></div></section></form>`}`;
|
|
2582
2612
|
}
|
|
@@ -2750,23 +2780,24 @@ function filteredTools(tools, filters = {}) {
|
|
|
2750
2780
|
const query = (filters.q ?? "").trim().toLowerCase();
|
|
2751
2781
|
return [...tools].sort((a, b) => (toolOrder.indexOf(a.name) + 99) % 99 - (toolOrder.indexOf(b.name) + 99) % 99).filter((t) => (!filters.category || (toolCategory[t.name] ?? "Tool") === filters.category) && [t.name, toolName(t.name), toolCategory[t.name] ?? "Tool", t.descriptor?.description ?? toolDescription(t.name)].join(" ").toLowerCase().includes(query));
|
|
2752
2782
|
}
|
|
2753
|
-
function toolTiles(tools, filters = {}) {
|
|
2783
|
+
function toolTiles(tools, filters = {}, worlds2 = []) {
|
|
2754
2784
|
const matches = filteredTools(tools, filters);
|
|
2755
|
-
|
|
2756
|
-
return
|
|
2785
|
+
const used = new Set(worlds2.flatMap((world) => world.tools ?? (world.configuration?.preset?.datasets ?? []).map((dataset) => dataset.tool)));
|
|
2786
|
+
if (!matches.length) return stateCard("No tools match", "Try another name, category or description.", '<a class="k-btn" data-tool-clear href="/tools">Clear</a>');
|
|
2787
|
+
return `<div class="k-grid mock-tool-grid">${matches.map((t) => {
|
|
2757
2788
|
const d = t.descriptor ?? {}, endpoints = (t.coverage ?? []).length;
|
|
2758
2789
|
const version = String(d.version ?? "").replace(/\bsubset\b/gi, "").trim();
|
|
2759
2790
|
const api2 = version && !/[A-Za-z]{3,}/.test(version) ? `API ${version}` : version;
|
|
2760
2791
|
const description = d.description ?? toolDescription(t.name);
|
|
2761
|
-
return `<a class="tool-card" data-nav href="/tools/${encodeURIComponent(t.name)}"><div class="tool-
|
|
2792
|
+
return `<a class="k-card pad mock-tool-card" data-nav href="/tools/${encodeURIComponent(t.name)}"><div class="mock-tool-head"><span class="mock-tool-name">${toolLogo(t.name)}<strong>${h(toolName(t.name))}</strong></span>${used.has(t.name) ? '<span class="k-badge pass">In use</span>' : ""}</div><div class="k-meta mock-tool-meta"><span>${h(toolCategory[t.name] ?? "Tool")}</span> \xB7 <span>${endpoints} endpoint${endpoints === 1 ? "" : "s"}</span>${api2 ? ` \xB7 <span>${h(api2)}</span>` : ""}</div><p>${h(description)}</p></a>`;
|
|
2762
2793
|
}).join("")}</div>`;
|
|
2763
2794
|
}
|
|
2764
|
-
function toolsCatalog(tools, filters = {}) {
|
|
2765
|
-
const categories = [...new Set(tools.map((t) => toolCategory[t.name] ?? "Tool"))];
|
|
2766
|
-
return `<section class="tools-catalog" aria-label="Tool catalog"><label class="
|
|
2767
|
-
const
|
|
2768
|
-
return `<button type="button" data-tool-category="${h(category)}" aria-pressed="${(filters.category ?? "") === category}">${h(category || "All")} <span>${
|
|
2769
|
-
}).join("")}</div><p class="tools-result-count" role="status">${filteredTools(tools, filters).length} of ${tools.length} tools</p><div id="tool-tiles">${toolTiles(tools, filters)}</div></section>`;
|
|
2795
|
+
function toolsCatalog(tools, filters = {}, worlds2 = []) {
|
|
2796
|
+
const categories = [...new Set(filteredTools(tools).map((t) => toolCategory[t.name] ?? "Tool"))];
|
|
2797
|
+
return `<section class="tools-catalog k-stack" aria-label="Tool catalog"><div class="k-head"><h2 class="k-h2">Mock tools \xB7 ${tools.length}</h2><label class="mock-tool-search"><span class="sr-only">Search tools</span><input class="k-field" id="tools-search" type="search" placeholder="Search name, category or description" value="${h(filters.q ?? "")}"></label></div><div class="k-seg" role="group" aria-label="Tool category">${["", ...categories].map((category) => {
|
|
2798
|
+
const count2 = category ? tools.filter((t) => (toolCategory[t.name] ?? "Tool") === category).length : tools.length;
|
|
2799
|
+
return `<button type="button" data-tool-category="${h(category)}" aria-pressed="${(filters.category ?? "") === category}">${h(category || "All")} <span class="k-count">${count2}</span></button>`;
|
|
2800
|
+
}).join("")}</div><p class="tools-result-count k-meta" role="status">${filteredTools(tools, filters).length} of ${tools.length} tools</p><div id="tool-tiles">${toolTiles(tools, filters, worlds2)}</div></section>`;
|
|
2770
2801
|
}
|
|
2771
2802
|
function toolEndpoints(coverage) {
|
|
2772
2803
|
if (!coverage.length) return "";
|
|
@@ -2779,9 +2810,8 @@ function toolConnect(name) {
|
|
|
2779
2810
|
return env.length ? `<section class="tool-aside-section"><h2>Connect your agent</h2><div class="catalog-scroll" tabindex="0" aria-label="Connection variables"><table class="catalog-table connect-table"><thead><tr><th scope="col">Variable</th><th scope="col">Holds</th></tr></thead><tbody>${env.map((key) => `<tr><td><div class="catalog-copy"><code>${h(key)}</code>${copyButton(key, "Copy variable name")}</div></td><td>${h(connectionLabel(key))}</td></tr>`).join("")}</tbody></table></div>${connectionNote[name] ? `<p class="hint">${h(connectionNote[name])}</p>` : ""}</section>` : "";
|
|
2780
2811
|
}
|
|
2781
2812
|
function agentList(agents, instead) {
|
|
2782
|
-
if (!agents.length) return stateCard("No agents", instead ? "" : "Choose your local project to get started.", instead ?? copyCommand("ancha init") + button("Connect agent", "add-agent", "", "primary"));
|
|
2783
|
-
|
|
2784
|
-
return `<div class="catalog-scroll agents-scroll" tabindex="0" aria-label="Agents"><table class="catalog-table agents-table"><thead><tr><th scope="col">Agent</th><th scope="col">Folder</th><th scope="col">Start command / config</th>${model ? '<th scope="col">Model</th>' : ""}</tr></thead><tbody>${agents.map((a) => `<tr><td><a data-nav class="catalog-agent-name" href="/agents/${encodeURIComponent(a.id)}" title="${h(a.name)}">${h(a.name)}</a><div class="catalog-copy agent-ref"><code title="${h(a.id)}">${h(shortId(a.id))}</code>${copyButton(a.id, "Copy agent id")}</div></td><td><div class="catalog-copy"><code class="catalog-cut" title="${h(a.cwd ?? "")}">${h(a.cwd ?? "")}</code>${a.cwd ? copyButton(a.cwd, "Copy folder") : ""}</div></td><td><code class="catalog-cut" title="${h(a.command ?? a.configPath ?? "")}">${h(a.command ?? a.configPath ?? "")}</code></td>${model ? `<td><span class="catalog-cut" title="${h(a.provider?.model ?? "")}">${h(a.provider?.model ?? "")}</span></td>` : ""}</tr>`).join("")}</tbody></table></div>`;
|
|
2813
|
+
if (!agents.length) return stateCard("No agents", instead ? "" : "Choose your local project to get started.", instead ?? copyCommand("ancha init") + button("Connect agent", "add-agent", "", "k-btn primary"));
|
|
2814
|
+
return `<section class="k-card" aria-label="Agents"><div class="k-scroll" tabindex="0" aria-label="Agents table"><table class="k-table"><thead><tr><th scope="col">Agent</th><th scope="col">Status</th></tr></thead><tbody>${agents.map((a) => `<tr><td class="wrap"><a data-nav class="k-name" href="/agents/${encodeURIComponent(a.id)}" title="${h(a.name)}">${h(a.name)}</a><div class="ag-copy k-id"><span title="${h(a.id)}">${h(shortId(a.id))}</span>${copyButton(a.id, "Copy agent id")}</div></td><td>${agentConnectionBadge(a)}</td></tr>`).join("")}</tbody></table></div></section>`;
|
|
2785
2815
|
}
|
|
2786
2816
|
function settingsPage(boot2) {
|
|
2787
2817
|
if (!boot2.hosted) {
|
|
@@ -2831,7 +2861,7 @@ function comparisonSetup(runId, runs) {
|
|
|
2831
2861
|
function comparisonResults(result, labels) {
|
|
2832
2862
|
const percent2 = (rate) => `${(rate * 100).toLocaleString("en-US", { maximumFractionDigits: 1 })}%`;
|
|
2833
2863
|
const change = (delta) => delta === 0 ? "No change" : Math.abs(delta * 100) < 0.1 ? `${delta > 0 ? "Increase" : "Decrease"} under 0.1 percentage points` : `${delta > 0 ? "+" : "\u2212"}${Math.abs(delta * 100).toLocaleString("en-US", { maximumFractionDigits: 1 })} percentage points`;
|
|
2834
|
-
const attempts = (
|
|
2864
|
+
const attempts = (count2) => `${count2} ${count2 === 1 ? "attempt" : "attempts"}`;
|
|
2835
2865
|
return `<p>${result.regressed ? "Pass rate decreased in one or more scenarios." : "No decrease in pass rate."}</p><div class="table-wrap comparison-table"><table><thead><tr><th scope="col">Scenario</th><th scope="col">Before</th><th scope="col">After</th><th scope="col">Change</th></tr></thead><tbody>${result.scenes.map((s, index) => `<tr><th scope="row">${h(labels[s.sceneId] ?? `Scenario ${index + 1}`)}</th><td><strong>${percent2(s.before)}</strong><span class="comparison-attempts">${attempts(s.beforeTrials)}</span></td><td><strong>${percent2(s.after)}</strong><span class="comparison-attempts">${attempts(s.afterTrials)}</span></td><td>${badge(change(s.delta), s.delta > 0 ? "good" : s.delta < 0 ? "bad" : "")}</td></tr>`).join("")}</tbody></table></div><p class="hint">Observed pass rates; no claim of statistical significance.</p>${details("Comparison details", result)}`;
|
|
2836
2866
|
}
|
|
2837
2867
|
function dataSelection(item) {
|
|
@@ -2885,7 +2915,7 @@ var blockedConnect = null;
|
|
|
2885
2915
|
var runnerBusyHtml = (message, run) => `${h(message)} ${navLink("Open run", "/playgrounds/" + enc2(run.id), "button-link")} ${button("Stop it", "stop-blocking-run", run.id, "secondary")}`;
|
|
2886
2916
|
var isRunnerBusy = (e) => e?.code === "RUNNER_BUSY" && !!e.run;
|
|
2887
2917
|
var workspaceCleanup;
|
|
2888
|
-
var
|
|
2918
|
+
var worldTestCounts = /* @__PURE__ */ new Map();
|
|
2889
2919
|
function savedTestRunStorageKey(testId) {
|
|
2890
2920
|
return `ancha-saved-test-run:${testId}`;
|
|
2891
2921
|
}
|
|
@@ -2900,15 +2930,15 @@ function pendingSavedTestRun(testId) {
|
|
|
2900
2930
|
throw new Error("A previous run may still be starting, but its retry details are unavailable. Reloading or starting again could create a duplicate.");
|
|
2901
2931
|
}
|
|
2902
2932
|
}
|
|
2903
|
-
function savedTestActions(testId, label2 = "Run", primary = false) {
|
|
2933
|
+
function savedTestActions(testId, label2 = "Run", primary = false, kit = false) {
|
|
2904
2934
|
let pending = false, unavailable = false;
|
|
2905
2935
|
try {
|
|
2906
2936
|
pending = !!pendingSavedTestRun(testId);
|
|
2907
2937
|
} catch {
|
|
2908
2938
|
unavailable = true;
|
|
2909
2939
|
}
|
|
2910
|
-
if (unavailable) return
|
|
2911
|
-
return `${button(pending ? "Retry same run" : label2, "run-saved-test", testId, pending || primary ? "primary" : "")}${pending ? '<span class="muted" role="status">Retry uses the same request.</span>' : ""}`;
|
|
2940
|
+
if (unavailable) return `<button type="button" class="${kit ? "k-btn " : ""}primary" disabled>Retry unavailable</button><span class="muted" role="status">Retry details could not be read safely.</span>`;
|
|
2941
|
+
return `${button(pending ? "Retry same run" : label2, "run-saved-test", testId, (kit ? "k-btn " : "") + (pending || primary ? "primary" : ""))}${pending ? '<span class="muted" role="status">Retry uses the same request.</span>' : ""}`;
|
|
2912
2942
|
}
|
|
2913
2943
|
function rerunStorageKey(runId) {
|
|
2914
2944
|
return `ancha-playground-rerun:${runId}`;
|
|
@@ -2987,13 +3017,13 @@ async function api(path2, data, signal, background = false) {
|
|
|
2987
3017
|
connected = true;
|
|
2988
3018
|
noteConnection(true);
|
|
2989
3019
|
const result = await res.json();
|
|
2990
|
-
const retryAfter = Number(res.headers.get("retry-after") ?? result
|
|
3020
|
+
const retryAfter = Number(res.headers.get("retry-after") ?? result?.retryAfter);
|
|
2991
3021
|
if (!res.ok) {
|
|
2992
3022
|
const refusal = result.error && typeof result.error === "object" ? result.error : void 0;
|
|
2993
3023
|
const message = refusal ? [refusal.message, refusal.hint].map(sentence2).filter(Boolean).join(" ") : result.error ?? `Request failed (${res.status})`;
|
|
2994
3024
|
throw Object.assign(new Error(message), { status: res.status, code: refusal?.code ?? result.code, run: result.run, retryAfter: Number.isFinite(retryAfter) ? retryAfter : void 0 });
|
|
2995
3025
|
}
|
|
2996
|
-
if (res.status === 202 && result
|
|
3026
|
+
if (res.status === 202 && result?.state === "computing") return { ...result, status: 202, retryAfter: Number.isFinite(retryAfter) ? retryAfter : 3 };
|
|
2997
3027
|
return result;
|
|
2998
3028
|
}
|
|
2999
3029
|
var sentence2 = (text2) => {
|
|
@@ -3001,7 +3031,7 @@ var sentence2 = (text2) => {
|
|
|
3001
3031
|
return t && t[0].toUpperCase() + t.slice(1) + (/[.!?]$/.test(t) ? "" : ".");
|
|
3002
3032
|
};
|
|
3003
3033
|
var ownRunsOff = () => boot.hosted?.execution === false;
|
|
3004
|
-
var agentsBack = () =>
|
|
3034
|
+
var agentsBack = (agent, page) => agentCrumbs(agentsHome(Boolean(boot.hosted)), agent, page);
|
|
3005
3035
|
var notFound = () => head("Page not found") + notFoundPage(Boolean(boot.hosted));
|
|
3006
3036
|
var viewMode2 = () => viewMode(boot);
|
|
3007
3037
|
var staticTools = catalogTools();
|
|
@@ -3100,11 +3130,11 @@ function starterPanel(tool, q, base) {
|
|
|
3100
3130
|
}
|
|
3101
3131
|
function shell(section, content) {
|
|
3102
3132
|
const nav2 = (items) => items.map(([id, name]) => `<a href="/${id}" data-nav class="nav-item ${section === id ? "active" : ""}" ${section === id ? 'aria-current="page"' : ""}>${name}</a>`).join("");
|
|
3103
|
-
root.innerHTML = `<aside class="sidebar"><a href="/worlds" class="brand" data-nav>ancha</a><nav class="app-nav" aria-label="Main navigation">${nav2([["
|
|
3133
|
+
root.innerHTML = `<aside class="sidebar"><a href="/worlds" class="brand" data-nav>ancha</a><nav class="app-nav" aria-label="Main navigation">${nav2([["agents", "Agents"], ["playgrounds", "Runs"], ["worlds", "Worlds"], ["tools", "Tools"]])}</nav><div class="workspace"><span id="connection" class="connection warn" role="status"${failedProbes < 2 ? " hidden" : ""}>${failedProbes < 2 ? "" : "Can\u2019t reach the server. Retrying\u2026"}</span><a href="/help" data-nav>Help</a><a href="/settings" data-nav>Settings</a></div></aside><main id="main" tabindex="-1">${content}</main>`;
|
|
3104
3134
|
}
|
|
3105
3135
|
function folderScenes(scenes) {
|
|
3106
3136
|
if (!scenes.length) return "";
|
|
3107
|
-
return `<section class="
|
|
3137
|
+
return `<section class="k-card" aria-labelledby="folder-scenes-title"><div class="k-card-head"><h2 id="folder-scenes-title">Scenes in this folder</h2></div><div class="k-scroll" role="region" aria-label="Scenes in this folder" tabindex="0"><table class="k-table wide"><thead><tr><th scope="col">Scene</th><th scope="col">Tools</th><th scope="col">Path</th></tr></thead><tbody>${scenes.map((scene) => `<tr><td><a class="k-name" href="/worlds?scene=${enc2(String(scene.key))}" data-nav title="${h(String(scene.title || scene.id))}">${h(String(scene.title || scene.id))}</a></td><td>${worldToolIcons(scene)}</td><td><code class="worlds-path" title="${h(String(scene.path))}">${h(String(scene.path))}</code></td></tr>`).join("")}</tbody></table></div></section>`;
|
|
3108
3138
|
}
|
|
3109
3139
|
function worldToolIcons(world) {
|
|
3110
3140
|
return worldToolsCell(world);
|
|
@@ -3200,32 +3230,27 @@ async function load() {
|
|
|
3200
3230
|
worlds = result.worlds ?? [];
|
|
3201
3231
|
agentCatalog = registry.agents ?? [];
|
|
3202
3232
|
savedPlaygroundTests = definitions.tests ?? [];
|
|
3203
|
-
for (const world of worlds)
|
|
3204
|
-
const setups = savedPlaygroundTests.filter((test) => test.worldId === world.id);
|
|
3205
|
-
const selectedSetup = setups.find((test) => test.id === new URLSearchParams(location.search).get("test")) ?? setups[0];
|
|
3206
|
-
worldTaskCounts.set(world.id, selectedSetup?.tasks?.length ?? 0);
|
|
3207
|
-
}
|
|
3233
|
+
for (const world of worlds) worldTestCounts.set(world.id, worldSetups(savedPlaygroundTests, world.id).length);
|
|
3208
3234
|
const selected = worlds.find((w) => w.id === p[1]), editing = !viewMode2() && (p[1] === "new" || new URLSearchParams(location.search).has("edit"));
|
|
3209
3235
|
if (viewMode2()) {
|
|
3210
3236
|
current = {};
|
|
3211
|
-
shell("worlds",
|
|
3212
|
-
document.querySelector("#worlds-page").innerHTML = worldsAnswer.snapshotAt ? snapshotNote(worldsAnswer) + worldsTable(worlds,
|
|
3237
|
+
shell("worlds", '<div class="k-page"><header class="k-head"><div class="k-title"><h1>Worlds</h1></div></header><div id="worlds-page" class="k-stack"></div></div>');
|
|
3238
|
+
document.querySelector("#worlds-page").innerHTML = (worldsAnswer.snapshotAt ? snapshotNote(worldsAnswer) + worldsTable(worlds, worldTestCounts, false, { startingData: true }) : viewWorldsEmpty(boot)) + (p[1] ? "" : toolsCatalog(staticTools, Object.fromEntries(q), worlds));
|
|
3239
|
+
if (!p[1]) bindToolsCatalog();
|
|
3213
3240
|
} else if (selected && !editing) {
|
|
3214
3241
|
current = { world: selected };
|
|
3215
3242
|
shell("worlds", '<div id="world-workspace"></div>');
|
|
3216
|
-
workspaceCleanup = mountWorldWorkspace(document.querySelector("#world-workspace"), { world: selected, worlds, agents: agentCatalog, tools: toolCatalog, api, poll, go, runActions: (id) => savedTestActions(id, "Run tasks", true
|
|
3217
|
-
worldTaskCounts.set(selected.id, test?.tasks?.length ?? 0);
|
|
3218
|
-
const count = document.querySelector(`[data-world-count="${selected.id}"]`);
|
|
3219
|
-
if (count) count.textContent = `${test?.tasks?.length ?? 0} ${test?.tasks?.length === 1 ? "task" : "tasks"}`;
|
|
3220
|
-
} });
|
|
3243
|
+
workspaceCleanup = mountWorldWorkspace(document.querySelector("#world-workspace"), { world: selected, worlds, agents: agentCatalog, tools: toolCatalog, api, poll, go, runActions: (id) => savedTestActions(id, "Run tasks", true, true) });
|
|
3221
3244
|
} else {
|
|
3222
3245
|
current = {};
|
|
3223
|
-
shell("worlds",
|
|
3246
|
+
shell("worlds", `<div class="k-page">${p[1] ? '<nav class="k-crumbs" aria-label="Breadcrumb"><a data-nav href="/worlds">Worlds</a><span>/</span><span aria-current="page">' + (selected ? "Edit world" : "New world") + "</span></nav>" : ""}<header class="k-head"><div class="k-title"><h1>${editing ? selected ? "Edit world" : "New world" : "Worlds"}</h1></div>${editing ? "" : navLink("New world", "/worlds/new", "k-btn primary")}</header><div id="worlds-page" class="k-stack"></div></div>`);
|
|
3224
3247
|
const ownAgents = agentCatalog.filter((a) => !/(^|\/)sample-agent\/?$/.test(String(a.cwd ?? "")));
|
|
3225
3248
|
const sampleRun = !p[1] && !ownAgents.length ? ((await api("/playgrounds")).runs ?? []).slice().sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt)))[0] : void 0;
|
|
3226
3249
|
if (thisGeneration !== generation) return;
|
|
3227
|
-
if (!p[1])
|
|
3228
|
-
|
|
3250
|
+
if (!p[1]) {
|
|
3251
|
+
document.querySelector("#worlds-page").innerHTML = (ownAgents.length ? "" : startCard(sampleRun?.id, Boolean(boot.hosted))) + worldsTable(worlds, worldTestCounts) + folderScenes(folder.scenes ?? []) + toolsCatalog(staticTools, Object.fromEntries(q), worlds);
|
|
3252
|
+
bindToolsCatalog();
|
|
3253
|
+
} else mountWorlds(document.querySelector("#worlds-page"), worlds, toolCatalog, p[1], api, go);
|
|
3229
3254
|
}
|
|
3230
3255
|
} else if (section === "tools") {
|
|
3231
3256
|
current = {};
|
|
@@ -3247,11 +3272,9 @@ async function load() {
|
|
|
3247
3272
|
} else if (section === "playgrounds" && p[1]) {
|
|
3248
3273
|
const q = new URLSearchParams(location.search), asked = q.get("attempt");
|
|
3249
3274
|
const [batch, worldList, askedEvidence] = await Promise.all([api(`/playgrounds/${enc2(p[1])}`), api("/worlds"), asked ? api(`/playgrounds/${enc2(p[1])}/attempts/${enc2(asked)}`) : Promise.resolve({})]);
|
|
3250
|
-
shownAttempt = asked || q.get("compare") ? void 0 : defaultAttempt(batch, q.get("task") ?? void 0)?.id;
|
|
3251
|
-
const evidence = shownAttempt ? await api(`/playgrounds/${enc2(p[1])}/attempts/${enc2(shownAttempt)}`) : askedEvidence;
|
|
3252
3275
|
current = batch;
|
|
3253
3276
|
worlds = worldList.worlds ?? [];
|
|
3254
|
-
batchEvidence =
|
|
3277
|
+
batchEvidence = askedEvidence;
|
|
3255
3278
|
if (thisGeneration !== generation) return;
|
|
3256
3279
|
renderPlayground();
|
|
3257
3280
|
pollPlayground(p[1], thisGeneration);
|
|
@@ -3400,13 +3423,13 @@ function updateTaskCount() {
|
|
|
3400
3423
|
const form = document.querySelector("#playground-form");
|
|
3401
3424
|
if (!form) return;
|
|
3402
3425
|
rememberDraft();
|
|
3403
|
-
const draft = agentDraft(form.dataset.agent),
|
|
3426
|
+
const draft = agentDraft(form.dataset.agent), count2 = draft.tasks.reduce((n, t) => n + (Number.isFinite(t.attempts) ? t.attempts : 0), 0);
|
|
3404
3427
|
const summary = document.querySelector("#task-count");
|
|
3405
|
-
if (summary) summary.textContent = `${
|
|
3428
|
+
if (summary) summary.textContent = `${count2} ${count2 === 1 ? "trial" : "trials"} \xB7 ${Math.min(draft.concurrency, count2)} at a time`;
|
|
3406
3429
|
const submit = form.querySelector("button[type=submit]");
|
|
3407
|
-
if (submit) submit.disabled = !playgroundReadiness.ready || !configuredTools().length ||
|
|
3430
|
+
if (submit) submit.disabled = !playgroundReadiness.ready || !configuredTools().length || count2 < 1 || count2 > 100;
|
|
3408
3431
|
const limit = document.querySelector("#task-limit");
|
|
3409
|
-
if (limit) limit.textContent =
|
|
3432
|
+
if (limit) limit.textContent = count2 > 100 ? "Use at most 100 trials per run." : "";
|
|
3410
3433
|
}
|
|
3411
3434
|
function taskInputFields(input) {
|
|
3412
3435
|
const kind = input?.kind ?? "";
|
|
@@ -3433,19 +3456,19 @@ function providerValue(data) {
|
|
|
3433
3456
|
function renderAgents(id) {
|
|
3434
3457
|
renderedLocation = new URL(location.href);
|
|
3435
3458
|
if (!id) {
|
|
3436
|
-
const listHead = (actions2 = "") => boot.hosted ?
|
|
3459
|
+
const listHead = (actions2 = "") => (boot.hosted ? '<nav class="k-crumbs" aria-label="Breadcrumb"><a href="/agents">Agents</a><span>/</span><span aria-current="page">Connected agents</span></nav>' : "") + agentPageHead("Agents", actions2);
|
|
3437
3460
|
if (viewMode2()) {
|
|
3438
|
-
shell("agents", listHead() + (agentsAnswer.snapshotAt && agentCatalog.length ? snapshotNote(agentsAnswer) + agentList(agentCatalog, void 0) : stateCard("No connected agents", "", '<a class="
|
|
3461
|
+
shell("agents", '<div class="k-page ag-page">' + listHead() + agentErrors.map((e) => `<div class="k-alert fail" role="alert">${h(e.message)}</div>`).join("") + (agentsAnswer.snapshotAt && agentCatalog.length ? snapshotNote(agentsAnswer) + agentList(agentCatalog, void 0) : stateCard("No connected agents", "", '<a class="k-btn" href="/agents">All agents</a>')) + "</div>");
|
|
3439
3462
|
return;
|
|
3440
3463
|
}
|
|
3441
3464
|
if (new URLSearchParams(location.search).get("tab") === "group-run") {
|
|
3442
|
-
shell("agents", agentsBack() +
|
|
3465
|
+
shell("agents", '<div class="k-page ag-page">' + agentsBack(void 0, "Run agents together") + agentPageHead("Run agents together") + '<div id="group-run-flow"></div></div>');
|
|
3443
3466
|
mountGroupFlow(document.querySelector("#group-run-flow"), { agents: agentCatalog, worlds, api, go });
|
|
3444
3467
|
return;
|
|
3445
3468
|
}
|
|
3446
3469
|
const note = ownRunsOff() ? betaNote() : void 0, list4 = agentList(agentCatalog, note);
|
|
3447
|
-
const actions = agentCatalog.length ? `${agentCatalog.length > 1 ? navLink("Run agents together", "/agents?tab=group-run", "
|
|
3448
|
-
shell("agents", listHead(actions) + (note && agentCatalog.length ? note : "") + agentErrors.map((e) => `<div class="alert">${h(e.message)}</div>`).join("") + list4);
|
|
3470
|
+
const actions = agentCatalog.length ? `${agentCatalog.length > 1 ? navLink("Run agents together", "/agents?tab=group-run", "k-btn") : ""}${note ? "" : button("Connect agent", "add-agent", "", "k-btn primary")}` : "";
|
|
3471
|
+
shell("agents", '<div class="k-page ag-page">' + listHead(actions) + (note && agentCatalog.length ? note : "") + agentErrors.map((e) => `<div class="k-alert fail" role="alert">${h(e.message)}</div>`).join("") + list4 + "</div>");
|
|
3449
3472
|
const handoff = new URLSearchParams(location.search);
|
|
3450
3473
|
if (handoff.has("connect") && !note) {
|
|
3451
3474
|
history.replaceState(history.state, "", location.pathname);
|
|
@@ -3469,14 +3492,14 @@ function renderAgents(id) {
|
|
|
3469
3492
|
const primary = page === "setup" ? "" : agentPrimary(a, operation);
|
|
3470
3493
|
const blocked = blockedConnect?.agentId === a.id ? blockedConnect : null;
|
|
3471
3494
|
if (blocked) blockedConnect = null;
|
|
3472
|
-
const connectionNotice = blocked ? `<div role="alert">${stateCard("Connection waiting", runnerBusyHtml(blocked.message, blocked.run), "", "queued")}</div>` : connecting || queuedConnect ? `<div class="connect-progress c-state c-state-${connecting ? "running" : "queued"}" role="status"><div>${statusMark(connecting ? "running" : "queued", status)}<p>${h(operation?.message ?? (queuedConnect ? "Waiting for another connection to finish." : ""))}</p></div>${button("Cancel", "cancel-connect", operation.id)}</div>` : operation?.state === "failed" ? `<div role="alert">${stateCard("Couldn\u2019t connect", h(operation.message ?? operation.error ?? "Check your settings and try again."), navLink("Edit connection", url(base, { tab: "setup" }), "
|
|
3495
|
+
const connectionNotice = blocked ? `<div role="alert">${stateCard("Connection waiting", runnerBusyHtml(blocked.message, blocked.run), "", "queued")}</div>` : connecting || queuedConnect ? `<div class="connect-progress c-state c-state-${connecting ? "running" : "queued"}" role="status"><div>${statusMark(connecting ? "running" : "queued", status)}<p>${h(operation?.message ?? (queuedConnect ? "Waiting for another connection to finish." : ""))}</p></div>${button("Cancel", "cancel-connect", operation.id, "k-btn")}</div>` : operation?.state === "failed" ? `<div role="alert">${stateCard("Couldn\u2019t connect", h(operation.message ?? operation.error ?? "Check your settings and try again."), navLink("Edit connection", url(base, { tab: "setup" }), "k-btn"), "error")}</div>` : "";
|
|
3473
3496
|
let content = "";
|
|
3474
3497
|
if (page === "new-test") {
|
|
3475
3498
|
if (q.get("test") && !savedPlaygroundTests.some((t) => t.id === q.get("test"))) {
|
|
3476
|
-
shell("agents", `<div class="
|
|
3499
|
+
shell("agents", `<div class="k-page ag-page">${agentsBack(a, "Test unavailable") + agentPageHead("Test unavailable") + stateCard("This test is unavailable.", "", navLink("Back to agent", base), "error")}</div>`);
|
|
3477
3500
|
return;
|
|
3478
3501
|
}
|
|
3479
|
-
shell("agents", `<div class="
|
|
3502
|
+
shell("agents", `<div class="k-page ag-page">${agentsBack(a, q.get("test") ? "Edit test" : "New test") + agentPageHead(q.get("test") ? "Edit test" : "New test")}<div id="test-flow"></div></div>`);
|
|
3480
3503
|
mountTestFlow(document.querySelector("#test-flow"), { agent: a, tools: toolCatalog, worlds, test: savedPlaygroundTests.find((t) => t.id === q.get("test")), api, go, preview: async (tool) => {
|
|
3481
3504
|
const data = await starterPreview(tool);
|
|
3482
3505
|
return `<div class="section-title"><h3>${h(toolName(tool))}</h3></div>` + toolView(data, tool, { baseHref: "/tools/" + enc2(tool) });
|
|
@@ -3486,24 +3509,26 @@ function renderAgents(id) {
|
|
|
3486
3509
|
if (page === "setup" && ownRunsOff()) {
|
|
3487
3510
|
content = `${connectionNotice}${betaNote()}<div class="agent-footer">${button("Remove agent", "delete-agent", a.id, "link")}</div>`;
|
|
3488
3511
|
} else if (page === "setup") {
|
|
3489
|
-
content = `${connectionNotice}<form id="agent-settings-form" class="agent-settings" data-agent="${h(a.id)}"><div class="folder-field"><label for="agent-folder">Project folder</label><div class="folder-input"><input id="agent-folder" name="cwd" value="${h(a.cwd)}" required>${boot.folderPickerAvailable ? button("Choose folder\u2026", "choose-agent-folder") : ""}</div></div><label>${a.configPath ? "Configuration file" : "Start command"}<input name="${a.configPath ? "configPath" : "command"}" value="${h(a.configPath ?? a.command)}" required></label>${taskInputFields(a.taskInput)}${providerFields(a.provider)}<label>Memory between trials<select name="state"><option value="stateless" ${a.state === "stateless" ? "selected" : ""}>No persistent memory</option><option value="namespaced" ${a.state === "namespaced" ? "selected" : ""}>Separate folder for each trial</option><option value="external" ${a.state === "external" ? "selected" : ""}>Shared files or external memory</option></select></label><p class="hint" id="state-detail">${a.state === "namespaced" ? "Your agent uses ANCHA_STATE_DIR for its persistent state." : ""}</p><div class="actions"><button type="submit" class="primary" ${connecting ? "disabled" : ""}>Save and connect</button>${button("Advanced settings", "agent-execution", a.id, "
|
|
3512
|
+
content = `${connectionNotice}<form id="agent-settings-form" class="agent-settings k-card pad" data-agent="${h(a.id)}"><div class="folder-field"><label for="agent-folder">Project folder</label><div class="folder-input"><input class="k-field" id="agent-folder" name="cwd" value="${h(a.cwd)}" required>${boot.folderPickerAvailable ? button("Choose folder\u2026", "choose-agent-folder", "", "k-btn") : ""}</div></div><label>${a.configPath ? "Configuration file" : "Start command"}<input class="k-field" name="${a.configPath ? "configPath" : "command"}" value="${h(a.configPath ?? a.command)}" required></label>${taskInputFields(a.taskInput).replace(/<(input|select) /g, '<$1 class="k-field" ')}${providerFields(a.provider).replace(/<(input|select) /g, '<$1 class="k-field" ')}<label>Memory between trials<select class="k-field" name="state"><option value="stateless" ${a.state === "stateless" ? "selected" : ""}>No persistent memory</option><option value="namespaced" ${a.state === "namespaced" ? "selected" : ""}>Separate folder for each trial</option><option value="external" ${a.state === "external" ? "selected" : ""}>Shared files or external memory</option></select></label><p class="hint" id="state-detail">${a.state === "namespaced" ? "Your agent uses ANCHA_STATE_DIR for its persistent state." : ""}</p><div class="k-actions"><button type="submit" class="k-btn primary" ${connecting ? "disabled" : ""}>Save and connect</button>${button("Advanced settings", "agent-execution", a.id, "k-btn")}</div><p id="page-form-error" class="error" role="alert"></p></form><div class="agent-footer">${button("Remove agent", "delete-agent", a.id, "link")}</div>`;
|
|
3490
3513
|
} else {
|
|
3491
3514
|
const tests = savedPlaygroundTests;
|
|
3492
3515
|
const selectedTest = tests.find((t) => t.id === q.get("test"));
|
|
3493
3516
|
if (page === "test") {
|
|
3494
3517
|
if (!selectedTest) {
|
|
3495
|
-
shell("agents", `<div class="
|
|
3518
|
+
shell("agents", `<div class="k-page ag-page">${agentsBack(a, "Test unavailable") + agentPageHead("Test unavailable") + stateCard("This test is unavailable.", "", navLink("Back to agent", base), "error")}</div>`);
|
|
3496
3519
|
return;
|
|
3497
3520
|
}
|
|
3498
|
-
content = testCard(selectedTest, worlds.find((w) => w.id === selectedTest.worldId), base, savedTestActions(selectedTest.id) + navLink("Edit", url(base, { tab: "new-test", test: selectedTest.id })) + button("Archive", "archive-test", selectedTest.id, "
|
|
3499
|
-
} else content = connectionNotice + `<
|
|
3521
|
+
content = testCard(selectedTest, worlds.find((w) => w.id === selectedTest.worldId), base, savedTestActions(selectedTest.id, "Run", false, true) + navLink("Edit", url(base, { tab: "new-test", test: selectedTest.id }), "k-btn") + button("Archive", "archive-test", selectedTest.id, "k-btn"), true) + `<div id="agent-recent-runs">${agentRecentRuns(playgroundRuns, a, savedTestActions(selectedTest.id, "Run", false, true), { testId: selectedTest.id })}</div>`;
|
|
3522
|
+
} else content = connectionNotice + `<div class="k-cols"><div class="k-main"><div id="agent-recent-runs">${agentRecentRuns(playgroundRuns, a, "", { history: agentRuns })}</div><div id="agent-tests">${agentTests(tests, worlds, playgroundRuns, base, (id2) => savedTestActions(id2, "Run tasks", false, true))}</div>${playgroundErrors.map((e) => `<div role="alert">${stateCard("Run could not be read", h(e.message), `<a class="k-btn" href="${h(url(base, { tab: page }))}">Retry</a>`, "error")}</div>`).join("")}<p id="page-form-error" class="error" role="alert"></p></div><aside class="k-side">${agentFacts(a, operation)}</aside></div>`;
|
|
3500
3523
|
}
|
|
3501
|
-
const
|
|
3502
|
-
const
|
|
3503
|
-
|
|
3524
|
+
const settingsControl = page === "setup" ? navLink("Overview", base, "k-btn") : navLink("Connection settings", url(base, { tab: "setup" }), "k-btn");
|
|
3525
|
+
const testName = savedPlaygroundTests.find((t) => t.id === q.get("test"))?.name ?? a.name;
|
|
3526
|
+
const crumbs = agentsBack(a, page === "test" ? testName : page === "setup" ? "Connection settings" : void 0);
|
|
3527
|
+
const heading2 = agentPageHead(page === "test" ? testName : a.name, page === "test" ? "" : primary + settingsControl, page === "test" ? "" : agentConnectionBadge(a, operation));
|
|
3528
|
+
shell("agents", `<div class="k-page ag-page">${crumbs + heading2}${page === "setup" ? `<div class="k-cols"><div class="k-main">${content}</div><aside class="k-side">${agentFacts(a, operation)}</aside></div>` : content}</div>`);
|
|
3504
3529
|
}
|
|
3505
3530
|
function retainReadingPosition(render) {
|
|
3506
|
-
const scrolls = [...document.querySelectorAll(".aw-attempt-list,.world-nav")].map((el) => ({ selector: el.classList.contains("aw-attempt-list") ? ".aw-attempt-list" : ".world-nav", top: el.scrollTop, left: el.scrollLeft }));
|
|
3531
|
+
const scrolls = [...document.querySelectorAll(".aw-attempt-list,.world-nav,.s059-run .k-scroll,.s059-run .k-peek")].map((el) => ({ selector: el.classList.contains("aw-attempt-list") ? ".aw-attempt-list" : el.classList.contains("k-peek") ? ".s059-run .k-peek" : el.classList.contains("k-scroll") ? ".s059-run .k-scroll" : ".world-nav", top: el.scrollTop, left: el.scrollLeft }));
|
|
3507
3532
|
const y = window.scrollY, active = document.activeElement, id = active?.id, href2 = active instanceof HTMLAnchorElement ? active.getAttribute("href") : null;
|
|
3508
3533
|
render();
|
|
3509
3534
|
const next = id ? document.getElementById(id) : href2 ? [...document.querySelectorAll("a[href]")].find((a) => a.getAttribute("href") === href2) : null;
|
|
@@ -3519,15 +3544,17 @@ function retainReadingPosition(render) {
|
|
|
3519
3544
|
}
|
|
3520
3545
|
function agentPrimary(a, operation) {
|
|
3521
3546
|
if (operation?.state === "connecting" || operation?.state === "queued") return "";
|
|
3522
|
-
if (a.execution?.mode === "container" && a.taskInput) return button("Add tasks", "add-tasks", a.id, "primary");
|
|
3523
|
-
return ownRunsOff() ? "" : navLink("Connect agent", url("/agents/" + enc2(a.id), { tab: "setup" }), "
|
|
3547
|
+
if (a.execution?.mode === "container" && a.taskInput) return button("Add tasks", "add-tasks", a.id, "k-btn primary");
|
|
3548
|
+
return ownRunsOff() ? "" : navLink("Connect agent", url("/agents/" + enc2(a.id), { tab: "setup" }), "k-btn primary");
|
|
3524
3549
|
}
|
|
3525
3550
|
function refreshAgentRuns() {
|
|
3526
3551
|
const area = document.querySelector("#agent-recent-runs");
|
|
3527
3552
|
if (!area) return;
|
|
3528
3553
|
const a = current.agent ?? current, q = new URLSearchParams(location.search);
|
|
3529
3554
|
const testId = q.get("tab") === "test" ? q.get("test") ?? void 0 : void 0;
|
|
3530
|
-
area.innerHTML = agentRecentRuns(playgroundRuns, a, testId ? savedTestActions(testId) : "", { testId });
|
|
3555
|
+
area.innerHTML = agentRecentRuns(playgroundRuns, a, testId ? savedTestActions(testId, "Run", false, true) : "", { testId, history: agentRuns });
|
|
3556
|
+
const tests = document.querySelector("#agent-tests");
|
|
3557
|
+
if (tests) tests.innerHTML = agentTests(savedPlaygroundTests, worlds, playgroundRuns, "/agents/" + enc2(a.id), (id) => savedTestActions(id, "Run tasks", false, true));
|
|
3531
3558
|
}
|
|
3532
3559
|
function pollAgent(id, version) {
|
|
3533
3560
|
const waiting = (state) => state === "connecting" || state === "queued";
|
|
@@ -3560,7 +3587,6 @@ function pollAgent(id, version) {
|
|
|
3560
3587
|
}
|
|
3561
3588
|
var runsList;
|
|
3562
3589
|
var searchTimer;
|
|
3563
|
-
var shownAttempt;
|
|
3564
3590
|
function renderRunsList() {
|
|
3565
3591
|
const q = new URLSearchParams(location.search), get = (key) => q.get(key) ?? void 0;
|
|
3566
3592
|
shell("playgrounds", runsPage(runsList?.runs ?? [], { q: get("q"), range: get("range"), agent: get("agent"), result: get("result"), where: get("where"), commit: get("commit"), source: get("source"), target: get("target"), limit: Number(q.get("limit")) || void 0 }));
|
|
@@ -3570,9 +3596,11 @@ function runFilterUrl(form) {
|
|
|
3570
3596
|
for (const [key, value] of new FormData(form)) if (value) params.set(key, String(value));
|
|
3571
3597
|
return "/playgrounds" + (params.size ? "?" + params : "");
|
|
3572
3598
|
}
|
|
3599
|
+
var runOverviewId = "";
|
|
3600
|
+
var runOverviewState = {};
|
|
3573
3601
|
function renderPlayground() {
|
|
3574
3602
|
renderedLocation = new URL(location.href);
|
|
3575
|
-
const batch = current, q = new URLSearchParams(location.search), selected = q.get("attempt")
|
|
3603
|
+
const batch = current, q = new URLSearchParams(location.search), selected = q.get("attempt"), attempt = (batch.attempts ?? []).find((a) => a.id === selected), base = "/playgrounds/" + enc2(batch.id);
|
|
3576
3604
|
const actions = readOnlyRun(batch) ? batch.origin?.stored ? button("Delete run", "delete-stored-run", batch.id, "link") : "" : !terminal(batch.status) ? button("Stop", "stop-playground", batch.id) : rerunAction(batch.id);
|
|
3577
3605
|
if (selected && !attempt) throw new Error("This attempt is not available.");
|
|
3578
3606
|
if (q.get("compare")) {
|
|
@@ -3585,6 +3613,13 @@ function renderPlayground() {
|
|
|
3585
3613
|
return;
|
|
3586
3614
|
}
|
|
3587
3615
|
shell("playgrounds", attempt ? renderAttemptWorkspace(batch, attempt, batchEvidence, { view: q.get("view") ?? void 0, tool: q.get("tool") ?? void 0, actionsHtml: actions, query: Object.fromEntries(q) }) : renderRunOverview(batch, actions, { task: q.get("task") ?? void 0 }));
|
|
3616
|
+
const overviewId = batch.id + ":" + (q.get("task") ?? "");
|
|
3617
|
+
if (runOverviewId !== overviewId) {
|
|
3618
|
+
runOverviewId = overviewId;
|
|
3619
|
+
runOverviewState = {};
|
|
3620
|
+
}
|
|
3621
|
+
if (attempt) runOverviewState.peek = void 0;
|
|
3622
|
+
else mountRunOverview(root, runOverviewState);
|
|
3588
3623
|
const focus = q.get("focus");
|
|
3589
3624
|
if (attempt && focus) document.getElementById(entryAnchor(focus))?.scrollIntoView({ block: "center" });
|
|
3590
3625
|
const call = q.get("call");
|
|
@@ -3597,8 +3632,7 @@ function pollPlayground(id, version) {
|
|
|
3597
3632
|
const batch = await poll(`/playgrounds/${enc2(id)}`);
|
|
3598
3633
|
if (version !== generation) return;
|
|
3599
3634
|
const q = new URLSearchParams(location.search);
|
|
3600
|
-
|
|
3601
|
-
const selected = q.get("attempt") ?? shownAttempt, evidence = selected ? await poll(`/playgrounds/${enc2(id)}/attempts/${enc2(selected)}`) : {};
|
|
3635
|
+
const selected = q.get("attempt"), evidence = selected ? await poll(`/playgrounds/${enc2(id)}/attempts/${enc2(selected)}`) : {};
|
|
3602
3636
|
if (version !== generation) return;
|
|
3603
3637
|
const changed = JSON.stringify(current) !== JSON.stringify(batch) || JSON.stringify(batchEvidence) !== JSON.stringify(evidence);
|
|
3604
3638
|
current = batch;
|
|
@@ -3615,6 +3649,37 @@ function starterStats(tool) {
|
|
|
3615
3649
|
const cells = (starterCounts[tool] ?? []).map(([key, label2]) => [label2, starterCount(tool, key, state)]).filter(([, n]) => n !== void 0);
|
|
3616
3650
|
return cells.length ? `<section class="run-summary tool-stats" aria-label="Starter data"><div class="rs-stats cols-${Math.min(cells.length, 4)}">${cells.map(([label2, n]) => `<div class="rs-stat"><span>${h(label2)}</span><strong>${h(String(n))}</strong></div>`).join("")}</div></section>` : "";
|
|
3617
3651
|
}
|
|
3652
|
+
function bindToolsCatalog() {
|
|
3653
|
+
const filters = Object.fromEntries(new URLSearchParams(location.search));
|
|
3654
|
+
const catalogNode = document.querySelector(".tools-catalog");
|
|
3655
|
+
const update = () => {
|
|
3656
|
+
const next = new URL(location.href);
|
|
3657
|
+
for (const key of ["q", "category"]) {
|
|
3658
|
+
if (filters[key]) next.searchParams.set(key, filters[key]);
|
|
3659
|
+
else next.searchParams.delete(key);
|
|
3660
|
+
}
|
|
3661
|
+
history.replaceState(history.state, "", next);
|
|
3662
|
+
renderedLocation = next;
|
|
3663
|
+
catalogNode.querySelector("#tool-tiles").innerHTML = toolTiles(staticTools, filters, worlds);
|
|
3664
|
+
catalogNode.querySelector(".tools-result-count").textContent = `${filteredTools(staticTools, filters).length} of ${staticTools.length} tools`;
|
|
3665
|
+
catalogNode.querySelectorAll("[data-tool-category]").forEach((chip) => chip.setAttribute("aria-pressed", String(chip.dataset.toolCategory === (filters.category ?? ""))));
|
|
3666
|
+
};
|
|
3667
|
+
catalogNode.querySelector("#tools-search").addEventListener("input", (event) => {
|
|
3668
|
+
filters.q = event.target.value;
|
|
3669
|
+
update();
|
|
3670
|
+
});
|
|
3671
|
+
catalogNode.addEventListener("click", (event) => {
|
|
3672
|
+
const target = event.target.closest("[data-tool-category], [data-tool-clear]");
|
|
3673
|
+
if (!target) return;
|
|
3674
|
+
event.preventDefault();
|
|
3675
|
+
if (target.hasAttribute("data-tool-clear")) {
|
|
3676
|
+
filters.q = "";
|
|
3677
|
+
filters.category = "";
|
|
3678
|
+
catalogNode.querySelector("#tools-search").value = "";
|
|
3679
|
+
} else filters.category = target.dataset.toolCategory ?? "";
|
|
3680
|
+
update();
|
|
3681
|
+
});
|
|
3682
|
+
}
|
|
3618
3683
|
function renderTools(selected) {
|
|
3619
3684
|
renderedLocation = new URL(location.href);
|
|
3620
3685
|
const tool = staticTools.find((t) => t.name === selected);
|
|
@@ -3623,36 +3688,8 @@ function renderTools(selected) {
|
|
|
3623
3688
|
return;
|
|
3624
3689
|
}
|
|
3625
3690
|
if (!tool) {
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
const catalogNode = document.querySelector(".tools-catalog");
|
|
3629
|
-
const update = () => {
|
|
3630
|
-
const next = new URL(location.href);
|
|
3631
|
-
for (const key of ["q", "category"]) {
|
|
3632
|
-
if (filters[key]) next.searchParams.set(key, filters[key]);
|
|
3633
|
-
else next.searchParams.delete(key);
|
|
3634
|
-
}
|
|
3635
|
-
history.replaceState(history.state, "", next);
|
|
3636
|
-
renderedLocation = next;
|
|
3637
|
-
catalogNode.querySelector("#tool-tiles").innerHTML = toolTiles(staticTools, filters);
|
|
3638
|
-
catalogNode.querySelector(".tools-result-count").textContent = `${filteredTools(staticTools, filters).length} of ${staticTools.length} tools`;
|
|
3639
|
-
catalogNode.querySelectorAll("[data-tool-category]").forEach((chip) => chip.setAttribute("aria-pressed", String(chip.dataset.toolCategory === (filters.category ?? ""))));
|
|
3640
|
-
};
|
|
3641
|
-
catalogNode.querySelector("#tools-search").addEventListener("input", (event) => {
|
|
3642
|
-
filters.q = event.target.value;
|
|
3643
|
-
update();
|
|
3644
|
-
});
|
|
3645
|
-
catalogNode.addEventListener("click", (event) => {
|
|
3646
|
-
const target = event.target.closest("[data-tool-category], [data-tool-clear]");
|
|
3647
|
-
if (!target) return;
|
|
3648
|
-
event.preventDefault();
|
|
3649
|
-
if (target.hasAttribute("data-tool-clear")) {
|
|
3650
|
-
filters.q = "";
|
|
3651
|
-
filters.category = "";
|
|
3652
|
-
catalogNode.querySelector("#tools-search").value = "";
|
|
3653
|
-
} else filters.category = target.dataset.toolCategory ?? "";
|
|
3654
|
-
update();
|
|
3655
|
-
});
|
|
3691
|
+
shell("tools", `<div class="k-page"><header class="k-head"><div class="k-title"><h1>Tools</h1></div><a class="k-btn" href="mailto:patrick@ancha.io?subject=Tool%20request">Request a tool</a></header>${toolsCatalog(staticTools, Object.fromEntries(new URLSearchParams(location.search)), worlds)}</div>`);
|
|
3692
|
+
bindToolsCatalog();
|
|
3656
3693
|
return;
|
|
3657
3694
|
}
|
|
3658
3695
|
const d = tool.descriptor ?? {}, endpoints = toolEndpoints(tool.coverage ?? []), connect = toolConnect(tool.name);
|
|
@@ -3714,11 +3751,11 @@ function renderRuns() {
|
|
|
3714
3751
|
const item = catalog.scenes.find((i) => i.key === c.key);
|
|
3715
3752
|
return item ? title(item.scene) : c.title;
|
|
3716
3753
|
});
|
|
3717
|
-
return `<a href="/runs/${enc2(r.runId)}" data-nav class="run-row"><div><strong>${h(r.metadata?.label ?? "Historical CLI test")}</strong>${runsTab === "connections" ? "" : `<p>${h(names.join(" \xB7 ") || r.metadata?.titles?.join(" \xB7 ") || r.summary?.scenes?.map((c) => title({ id: c.scenarioId ?? c.sceneId })).join(" \xB7 ") || "Scenario run")}</p>`}<p class="run-time">${runDate(r)}</p></div>${
|
|
3754
|
+
return `<a href="/runs/${enc2(r.runId)}" data-nav class="run-row"><div><strong>${h(r.metadata?.label ?? "Historical CLI test")}</strong>${runsTab === "connections" ? "" : `<p>${h(names.join(" \xB7 ") || r.metadata?.titles?.join(" \xB7 ") || r.summary?.scenes?.map((c) => title({ id: c.scenarioId ?? c.sceneId })).join(" \xB7 ") || "Scenario run")}</p>`}<p class="run-time">${runDate(r)}</p></div>${resultBadge3(r)}<span aria-hidden="true">\u2192</span></a>`;
|
|
3718
3755
|
}).join("")}</div>` : empty(runsTab === "connections" ? "No connection checks yet." : "No test runs yet.");
|
|
3719
3756
|
shell("runs", head("Runs", button("Run scenario", "test", "", "primary")) + tabs + content + (current.truncated ? '<p class="hint">Showing the most recent 80 runs.</p>' : ""));
|
|
3720
3757
|
}
|
|
3721
|
-
function
|
|
3758
|
+
function resultBadge3(r) {
|
|
3722
3759
|
if (r.metadata?.diagnostic && r.verification) return connectionStatus(r.verification);
|
|
3723
3760
|
const invalid = r.summary?.scenes?.some((s) => s.invalidTrials > 0);
|
|
3724
3761
|
if (invalid) return badge("Evaluation error", "bad");
|
|
@@ -3818,8 +3855,8 @@ function setupData() {
|
|
|
3818
3855
|
function updateRunCount() {
|
|
3819
3856
|
const form = document.querySelector("#test-form");
|
|
3820
3857
|
if (!form) return;
|
|
3821
|
-
const values = new FormData(form),
|
|
3822
|
-
document.querySelector("#run-count").textContent = `${
|
|
3858
|
+
const values = new FormData(form), count2 = 1 + values.getAll("extraScenes").length, repeats = Number(values.get("trials") || 1), parallel = Number(values.get("parallel") || 1);
|
|
3859
|
+
document.querySelector("#run-count").textContent = `${count2 * repeats} ${count2 * repeats === 1 ? "attempt" : "attempts"}${count2 > 1 ? ` across ${count2} scenarios` : ""}${count2 * repeats > 1 ? ` \xB7 up to ${parallel} at a time` : ""}`;
|
|
3823
3860
|
}
|
|
3824
3861
|
async function testForm(selected = "", preferred = selectedAgent) {
|
|
3825
3862
|
boot = await api("/bootstrap");
|