@babylonjs-toolkit/agent 1.1.68 → 1.1.69
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/README.md +2 -2
- package/package.json +1 -1
- package/skills/bt-design/SKILL.md +7 -0
- package/skills/bt-design/templates/3d-hero-scroll/hero-scroll.js +27 -9
- package/skills/bt-execute/SKILL.md +2 -2
- package/skills/bt-gauntlet/references/critic-rubrics.md +1 -0
- package/skills/bt-plan/SKILL.md +1 -1
- package/skills/bt-profile/SKILL.md +77 -34
- package/skills/bt-profile/scripts/analyze.mjs +67 -15
- package/skills/bt-profile/scripts/lib/chrome.mjs +22 -0
- package/skills/bt-profile/scripts/lib/probe.mjs +117 -2
- package/skills/bt-profile/scripts/lib/progress-panel.mjs +103 -7
- package/skills/bt-profile/scripts/profile.mjs +89 -40
- package/skills/bt-profile/scripts/progress.mjs +141 -10
- package/skills/bt-profile/scripts/report.mjs +203 -11
- package/skills/bt-profile/templates/scenario.template.mjs +28 -19
- package/skills/bt-prototype/SKILL.md +1 -1
|
@@ -5,14 +5,17 @@
|
|
|
5
5
|
* Usage (from `.agents/profile/<slug>/data`):
|
|
6
6
|
* node ../../.tools/report.mjs --analysis runs/<run>/cold/analysis.json [--out ../dashboard.html]
|
|
7
7
|
* [--baseline runs/<baseline>/cold/analysis.json] [--warm runs/<run>/warm/analysis.json]
|
|
8
|
-
* [--findings ./findings.json] [--title "Race start"]
|
|
8
|
+
* [--findings ./findings.json] [--title "Race start"] [--pdf false]
|
|
9
9
|
* [--snapshots runs/<snapshots run>/cold] [--snapshots-before <dir of earlier shots>]
|
|
10
10
|
* `--snapshots` shows the screenshots of a separate `--snapshots true` capture (so the measured run stays free of
|
|
11
11
|
* screenshot overhead); `--snapshots-before` sets them beside earlier shots of the same names (e.g. the smoke run).
|
|
12
12
|
*
|
|
13
13
|
* findings.json (written by the agent — the diagnosis in plain language):
|
|
14
14
|
* { "title", "summary", "findings": [{ "id", "title", "severity": "critical|major|minor", "status": "fixed|proposed|reverted|not-fixed",
|
|
15
|
-
* "phases": [..], "cost", "cause", "evidence": [..], "code": [{ "file", "line", "label" }], "fix", "before", "after", "diff"
|
|
15
|
+
* "phases": [..], "cost", "cause", "evidence": [..], "code": [{ "file", "line", "label" }], "fix", "before", "after", "diff",
|
|
16
|
+
* "gain", "risk", "verify" }] } (gain / risk / verify: optional — the expected win, what could break, how to prove it)
|
|
17
|
+
* Every build also writes findings.md beside the dashboard: the same diagnosis as a spec-ready document (one section per
|
|
18
|
+
* finding — cause, evidence, code, proposed fix, gain, risk, how to verify) to fix later with a full spec (bt-spec).
|
|
16
19
|
*/
|
|
17
20
|
import fs from "node:fs";
|
|
18
21
|
import path from "node:path";
|
|
@@ -151,7 +154,9 @@ h3 { font-size: 15px; margin: 0 0 6px; }
|
|
|
151
154
|
.meta { color: var(--text-muted); font: 12px/1.6 var(--mono); }
|
|
152
155
|
.verdict.disturbed { border-left-color: var(--serious); }
|
|
153
156
|
.verdict { background: var(--surface-1); border: 1px solid var(--surface-3); border-left: 3px solid var(--accent); border-radius: 8px; padding: 14px 16px; margin: 16px 0; color: var(--text-primary); font-size: 15px; }
|
|
154
|
-
|
|
157
|
+
/* Balanced rows of equal tiles: renderTiles sets --tile-columns (8 tiles → 2 × 4, 6 → 2 × 3); two per row on a phone */
|
|
158
|
+
.tiles { display: grid; grid-template-columns: repeat(var(--tile-columns, 4), minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 10px; }
|
|
159
|
+
@media (max-width: 720px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
155
160
|
.tile { background: var(--surface-1); border: 1px solid var(--surface-3); border-radius: 8px; padding: 12px 14px; }
|
|
156
161
|
.tile .label { color: var(--text-secondary); font-size: 12px; }
|
|
157
162
|
.tile .value { font-size: 26px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
|
|
@@ -211,6 +216,30 @@ details { margin-top: 8px; } summary { cursor: pointer; color: var(--text-second
|
|
|
211
216
|
.signals li { margin: 4px 0; color: var(--text-secondary); }
|
|
212
217
|
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 12px; }
|
|
213
218
|
@media (max-width: 520px) { .two { grid-template-columns: 1fr; } .tile .value { font-size: 22px; } }
|
|
219
|
+
footer.generated-by { margin-top: 64px; padding-top: 20px; border-top: 1px solid var(--surface-3); color: var(--text-muted); font-size: 12.5px; }
|
|
220
|
+
footer.generated-by a { color: inherit; }
|
|
221
|
+
table.fixes td.pick, table.fixes th.pick { width: 28px; } table.fixes td.id { font: 600 12px var(--mono); white-space: nowrap; }
|
|
222
|
+
table.fixes td.act { text-align: right; white-space: nowrap; }
|
|
223
|
+
table.fixes .badge { white-space: nowrap; }
|
|
224
|
+
td.nw { white-space: nowrap; }
|
|
225
|
+
.hint { color: var(--text-secondary); font-size: 13px; margin: 0 0 10px; }
|
|
226
|
+
.copy-spec { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--surface-3); border-radius: 6px; font-size: 12px; padding: 4px 10px; cursor: pointer; }
|
|
227
|
+
.copy-spec:disabled { opacity: 0.5; cursor: default; }
|
|
228
|
+
.spec-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
|
|
229
|
+
.spec-bar code { flex: 1 1 320px; font: 12px var(--mono); background: var(--surface-0); border: 1px solid var(--surface-3); border-radius: 6px; padding: 6px 10px; overflow-wrap: anywhere; }
|
|
230
|
+
@media print { .pick, .act, .spec-bar, #fixes .hint { display: none !important; } }
|
|
231
|
+
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
232
|
+
a.toggle { text-decoration: none; display: inline-block; }
|
|
233
|
+
@media print {
|
|
234
|
+
:root, :root[data-theme] { color-scheme: light; --surface-0: #ffffff; --surface-1: #ffffff; --surface-2: #f4f4f2; --surface-3: #d9d8d3; --text-primary: #0b0b0b; --text-secondary: #3d3c39; --text-muted: #5f5e59; }
|
|
235
|
+
body { background: #ffffff !important; }
|
|
236
|
+
main { max-width: none !important; padding: 0 !important; }
|
|
237
|
+
.actions, .btp-toolbar, .btp-next, .btp-copy { display: none !important; }
|
|
238
|
+
.panel, .finding, .tile, .verdict, figure, tr, .btp-card { break-inside: avoid; page-break-inside: avoid; }
|
|
239
|
+
h2 { break-after: avoid; page-break-after: avoid; }
|
|
240
|
+
.panel { overflow: visible !important; }
|
|
241
|
+
a { color: inherit; text-decoration: none; }
|
|
242
|
+
}
|
|
214
243
|
.toggle { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--surface-3); border-radius: 6px; font-size: 12px; padding: 4px 10px; cursor: pointer; }
|
|
215
244
|
`;
|
|
216
245
|
|
|
@@ -249,7 +278,7 @@ function settledPhase(analysis) {
|
|
|
249
278
|
|
|
250
279
|
function renderTiles() {
|
|
251
280
|
const settled = settledPhase(run), settledBase = base ? settledPhase(base) : null;
|
|
252
|
-
const worstPhase = [...run.phases].filter((p) => p.frames.fps != null && p.durationSeconds >= 1).sort((a, b) => a.frames.fps - b.frames.fps)[0];
|
|
281
|
+
const worstPhase = [...run.phases].filter((p) => !p.beforeFirstFrame && p.frames.fps != null && p.durationSeconds >= 1).sort((a, b) => a.frames.fps - b.frames.fps)[0];
|
|
253
282
|
const worstBase = base && worstPhase ? base.phases.find((p) => p.name === worstPhase.name) : null;
|
|
254
283
|
const gc = (a) => (a.overall.lists.owners.find((o) => o.owner === "gc") || { pctBusy: 0 }).pctBusy;
|
|
255
284
|
const shaders = (a) => a.timeline.reduce((sum, b) => sum + (b.shaders || 0), 0);
|
|
@@ -263,6 +292,8 @@ function renderTiles() {
|
|
|
263
292
|
{ label: "Allocated", value: run.heap ? fmt(run.heap.mbPerSecond, 0) + " MB/s" : "–", delta: base && base.heap && run.heap ? delta(run.heap.mbPerSecond, base.heap.mbPerSecond, true, " MB/s", 0) : "" },
|
|
264
293
|
{ label: "Shaders compiled in run", value: fmt(shaders(run), 0), delta: base ? delta(shaders(run), shaders(base), true, "", 0) : "" },
|
|
265
294
|
];
|
|
295
|
+
const rows = Math.ceil(tiles.length / 4);
|
|
296
|
+
$("#tiles").style.setProperty("--tile-columns", String(Math.max(1, Math.ceil(tiles.length / rows))));
|
|
266
297
|
$("#tiles").innerHTML = tiles.map((t) => '<div class="tile"><div class="label">' + esc(t.label) + '</div><div class="value">' + t.value + '</div>' + (t.delta || "") + '</div>').join("");
|
|
267
298
|
}
|
|
268
299
|
|
|
@@ -389,6 +420,45 @@ function renderTimeline() {
|
|
|
389
420
|
} else $("#film-wrap").style.display = "none";
|
|
390
421
|
}
|
|
391
422
|
|
|
423
|
+
/**
|
|
424
|
+
* The fixes, listed whether or not they were applied: spec one (its row's button) or a group (tick them) with bt-spec.
|
|
425
|
+
* The spec command points bt-spec at findings.md, which carries each fix's cause, evidence, code, gain, risk and check.
|
|
426
|
+
*/
|
|
427
|
+
function renderFixes() {
|
|
428
|
+
const wrap = $("#fixes-wrap");
|
|
429
|
+
const list = (findings && findings.findings ? findings.findings : []).filter((f) => f.fix);
|
|
430
|
+
if (!list.length) { wrap.style.display = "none"; return; }
|
|
431
|
+
const source = "@.agents/profile/" + DATA.slug + "/findings.md";
|
|
432
|
+
const join = (ids) => ids.length <= 1 ? ids.join("") : ids.slice(0, -1).join(", ") + " and " + ids[ids.length - 1];
|
|
433
|
+
const command = (ids) => "/bt-spec Fix " + join(ids) + " from " + source;
|
|
434
|
+
// A fix is done once it is in the code: "kept" (applied and proven by the fix loop) or "fixed".
|
|
435
|
+
const isDone = (f) => f.status === "kept" || f.status === "fixed";
|
|
436
|
+
const open = list.filter((f) => !isDone(f)).map((f) => f.id);
|
|
437
|
+
const rows = list.map((f) => '<tr><td class="pick"><input type="checkbox" value="' + esc(f.id) + '"' + (!isDone(f) ? " checked" : "") + ' aria-label="Select ' + esc(f.id) + '"></td>' +
|
|
438
|
+
'<td class="id"><a href="#' + esc(f.id) + '">' + esc(f.id) + '</a></td><td>' + esc(f.title) + '</td>' +
|
|
439
|
+
'<td><span class="badge ' + esc(f.status) + '">' + esc(f.status) + '</span></td>' +
|
|
440
|
+
'<td>' + esc(f.gain || f.cost || "–") + '</td><td>' + esc(f.risk || "–") + '</td>' +
|
|
441
|
+
'<td class="act"><button type="button" class="copy-spec" data-ids="' + esc(f.id) + '">Copy spec command</button></td></tr>').join("");
|
|
442
|
+
$("#fixes").innerHTML = '<div class="panel"><p class="hint">Each fix can be specced on its own, or several together: tick them and copy one command for <code>/bt-spec</code>. ' +
|
|
443
|
+
(open.length ? open.length + " not fixed yet." : "All of them are fixed.") + '</p>' +
|
|
444
|
+
'<div class="scroll"><table class="fixes"><thead><tr><th class="pick"></th><th>ID</th><th>Fix</th><th>Status</th><th>Expected gain</th><th>Risk</th><th class="act"></th></tr></thead><tbody>' + rows + '</tbody></table></div>' +
|
|
445
|
+
'<div class="spec-bar"><code id="spec-selected"></code><button type="button" class="copy-spec" id="copy-selected">Copy for the selected</button>' +
|
|
446
|
+
(open.length ? '<button type="button" class="copy-spec" data-ids="' + esc(open.join(" ")) + '">Copy for all open fixes</button>' : "") + '</div></div>';
|
|
447
|
+
const selected = () => [...document.querySelectorAll("#fixes input[type=checkbox]:checked")].map((box) => box.value);
|
|
448
|
+
const refresh = () => { const ids = selected(); $("#spec-selected").textContent = ids.length ? command(ids) : "Tick the fixes to spec together"; $("#copy-selected").disabled = !ids.length; };
|
|
449
|
+
$("#fixes").addEventListener("change", refresh);
|
|
450
|
+
$("#fixes").addEventListener("click", (event) => {
|
|
451
|
+
const button = event.target.closest(".copy-spec");
|
|
452
|
+
if (!button) return;
|
|
453
|
+
const ids = button.id === "copy-selected" ? selected() : button.dataset.ids.split(" ");
|
|
454
|
+
if (!ids.length) return;
|
|
455
|
+
const text = command(ids);
|
|
456
|
+
const done = () => { const label = button.textContent; button.textContent = "Copied"; setTimeout(() => { button.textContent = label; }, 1500); };
|
|
457
|
+
if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(text).then(done, done); else done();
|
|
458
|
+
});
|
|
459
|
+
refresh();
|
|
460
|
+
}
|
|
461
|
+
|
|
392
462
|
function renderFindings() {
|
|
393
463
|
const box = $("#findings");
|
|
394
464
|
if (!findings || !findings.findings || !findings.findings.length) {
|
|
@@ -455,7 +525,8 @@ function renderHeap() {
|
|
|
455
525
|
}
|
|
456
526
|
|
|
457
527
|
function renderWorst() {
|
|
458
|
-
|
|
528
|
+
const kindLabel = { cpu: "CPU work", wait: "waited", gap: "gap" };
|
|
529
|
+
$("#worst").innerHTML = "<div class='scroll'><table><thead><tr><th class='num'>at</th><th>Phase</th><th>Kind</th><th class='num'>CPU ms</th><th class='num'>gap ms</th><th class='num'>script ms</th><th class='num'>new pipelines</th><th>Filled by</th><th>Your code in it</th></tr></thead><tbody>" + run.worstFrames.map((f) => "<tr><td class='num'>" + fmt(f.t) + "s</td><td class='nw'>" + esc(f.phase || "") + "</td><td class='nw'>" + esc(kindLabel[f.kind] || "–") + "</td><td class='num'>" + fmt(f.cpuMs) + "</td><td class='num'>" + fmt(f.intervalMs) + "</td><td class='num'>" + fmt(f.scriptMs) + "</td><td class='num'>" + fmt(f.pipelinesNear) + "</td><td class='where'>" + esc(f.top.map((e) => e.name + " " + e.ms).join(" · ")) + "</td><td class='where'>" + (f.yours.map((e) => link(e.file, e.line, e.name + " " + e.ms + " ms")).join(" · ") || "–") + "</td></tr>").join("") + "</tbody></table></div>";
|
|
459
530
|
}
|
|
460
531
|
|
|
461
532
|
function renderShots() {
|
|
@@ -486,17 +557,25 @@ function renderMeta() {
|
|
|
486
557
|
].map(([k, v]) => "<tr><th>" + esc(k) + "</th><td>" + (k === "CPU profile" ? v : esc(v)) + "</td></tr>").join("") + "</tbody></table>";
|
|
487
558
|
}
|
|
488
559
|
|
|
560
|
+
// Print (and Save as PDF from the print dialog): every collapsed section opens for the print and closes again after.
|
|
561
|
+
let openedForPrint = [];
|
|
562
|
+
addEventListener("beforeprint", () => {
|
|
563
|
+
openedForPrint = [...document.querySelectorAll("details:not([open])")];
|
|
564
|
+
openedForPrint.forEach((details) => { details.open = true; });
|
|
565
|
+
});
|
|
566
|
+
addEventListener("afterprint", () => { openedForPrint.forEach((details) => { details.open = false; }); openedForPrint = []; });
|
|
567
|
+
$("#print").addEventListener("click", () => window.print());
|
|
489
568
|
$("#theme").addEventListener("click", () => {
|
|
490
569
|
const root = document.documentElement;
|
|
491
570
|
const dark = root.dataset.theme ? root.dataset.theme === "dark" : !matchMedia("(prefers-color-scheme: light)").matches;
|
|
492
571
|
root.dataset.theme = dark ? "light" : "dark";
|
|
493
572
|
});
|
|
494
|
-
renderTiles(); renderFindings(); renderTimeline(); renderPhases(); renderOwners(); renderFunctions(); renderHeap(); renderWorst(); renderShots(); renderWarm(); renderMeta();
|
|
573
|
+
renderTiles(); renderFindings(); renderFixes(); renderTimeline(); renderPhases(); renderOwners(); renderFunctions(); renderHeap(); renderWorst(); renderShots(); renderWarm(); renderMeta();
|
|
495
574
|
let resizeTimer; addEventListener("resize", () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(renderTimeline, 150); });
|
|
496
575
|
`;
|
|
497
576
|
|
|
498
577
|
/** Builds the HTML page. */
|
|
499
|
-
function buildPage({ title, verdict, data }) {
|
|
578
|
+
function buildPage({ title, verdict, data, pdfName }) {
|
|
500
579
|
const json = JSON.stringify(data).replace(/</g, "\\u003c");
|
|
501
580
|
return `<!doctype html>
|
|
502
581
|
<html lang="en">
|
|
@@ -510,7 +589,11 @@ function buildPage({ title, verdict, data }) {
|
|
|
510
589
|
<main>
|
|
511
590
|
<header class="top">
|
|
512
591
|
<h1>${escapeHtml(title)}</h1>
|
|
513
|
-
<
|
|
592
|
+
<div class="actions">
|
|
593
|
+
<button class="toggle" id="print" type="button" title="Print the report, or choose Save as PDF in the print dialog">Print</button>
|
|
594
|
+
${pdfName ? `<a class="toggle" id="pdf" href="${escapeHtml(pdfName)}" download title="The report as a PDF, written with it">Download PDF</a>` : ""}
|
|
595
|
+
<button class="toggle" id="theme" type="button">Light / dark</button>
|
|
596
|
+
</div>
|
|
514
597
|
</header>
|
|
515
598
|
${progressMarkup()}
|
|
516
599
|
<div class="meta">${escapeHtml(data.run.capture.capturedAt)} · ${escapeHtml(data.run.capture.engine || "")} · scenario ${escapeHtml(data.run.capture.scenario || "")} · ${escapeHtml(data.run.capture.wallSeconds)} s${data.baseline ? " · compared with baseline " + escapeHtml(data.baseline.capture.capturedAt) : ""}</div>
|
|
@@ -521,6 +604,8 @@ function buildPage({ title, verdict, data }) {
|
|
|
521
604
|
<h2>The bottlenecks</h2>
|
|
522
605
|
<section id="findings"></section>
|
|
523
606
|
|
|
607
|
+
<div id="fixes-wrap"><h2>The fixes</h2><section id="fixes"></section></div>
|
|
608
|
+
|
|
524
609
|
<h2>Frame rate over the run</h2>
|
|
525
610
|
<section class="panel"><div class="legend" id="fps-legend"></div><div id="chart-fps"></div></section>
|
|
526
611
|
|
|
@@ -548,6 +633,7 @@ function buildPage({ title, verdict, data }) {
|
|
|
548
633
|
<section class="panel" id="heap"></section>
|
|
549
634
|
|
|
550
635
|
<h2>Worst frames</h2>
|
|
636
|
+
<p class="meta">“CPU work”: the frame's own script was the cost. “Waited”: a long gap the main thread mostly sat through — the GPU process compiling pipelines (new pipelines just before it), a GPU-bound frame, or browser work.</p>
|
|
551
637
|
<section class="panel" id="worst"></section>
|
|
552
638
|
|
|
553
639
|
<div id="warm-wrap"><h2>Cold load vs warm load</h2><section class="panel" id="warm"></section></div>
|
|
@@ -555,6 +641,7 @@ function buildPage({ title, verdict, data }) {
|
|
|
555
641
|
|
|
556
642
|
<h2>Capture</h2>
|
|
557
643
|
<section class="panel" id="capture"></section>
|
|
644
|
+
<footer class="generated-by">Generated by the <a href="https://www.npmjs.com/package/@babylonjs-toolkit/agent" target="_blank" rel="noopener noreferrer">Babylon Toolkit Desktop Agent</a></footer>
|
|
558
645
|
</main>
|
|
559
646
|
<div class="tooltip" id="tooltip" role="status"></div>
|
|
560
647
|
<script type="application/json" id="bt-data">${json}</script>
|
|
@@ -576,8 +663,105 @@ function shotsFrom(dir, reportDir) {
|
|
|
576
663
|
}));
|
|
577
664
|
}
|
|
578
665
|
|
|
666
|
+
/**
|
|
667
|
+
* The diagnosis as a spec-ready Markdown document (findings.md beside the dashboard): what was measured and how, what is
|
|
668
|
+
* still to fix, then one section per finding with its cause, evidence, code, proposed fix, expected gain, risk and how
|
|
669
|
+
* to verify it — the input for a later fix with a full spec (`bt-spec @.agents/profile/<slug>/findings.md`).
|
|
670
|
+
* @returns {string} the Markdown
|
|
671
|
+
*/
|
|
672
|
+
function findingsMarkdown(findings, analysis, slugName) {
|
|
673
|
+
const capture = analysis.capture || {};
|
|
674
|
+
const list = (findings && Array.isArray(findings.findings)) ? findings.findings : [];
|
|
675
|
+
// A fix is done once it is in the code: "kept" (applied and proven by the fix loop) or "fixed".
|
|
676
|
+
const isDone = (finding) => finding.status === "kept" || finding.status === "fixed";
|
|
677
|
+
const open = list.filter((finding) => !isDone(finding));
|
|
678
|
+
const lines = [];
|
|
679
|
+
const push = (text = "") => lines.push(text);
|
|
680
|
+
push(`# ${findings && findings.title ? findings.title : "Performance findings"}`);
|
|
681
|
+
push();
|
|
682
|
+
if (findings && findings.summary) { push(findings.summary); push(); }
|
|
683
|
+
push(`- **Measured:** ${capture.url || "–"} · scenario \`${capture.scenario || "–"}\` · ${capture.engine || "no Babylon engine (browser frames)"} · captured ${capture.capturedAt || "–"}`);
|
|
684
|
+
push(`- **Dashboard:** \`dashboard.html\` beside this file · **Data:** \`data/\` (runs, findings.json)`);
|
|
685
|
+
push(`- **Re-measure after a fix:** \`/bt-profile --slug:${slugName}\` (same scenario) and compare the phases named below`);
|
|
686
|
+
push();
|
|
687
|
+
const fixable = list.filter((finding) => finding.fix);
|
|
688
|
+
const source = `@.agents/profile/${slugName}/findings.md`;
|
|
689
|
+
const join = (ids) => ids.length <= 1 ? ids.join("") : `${ids.slice(0, -1).join(", ")} and ${ids[ids.length - 1]}`;
|
|
690
|
+
const cell = (text) => String(text || "–").replace(/\|/g, "\\|").replace(/\n/g, " ");
|
|
691
|
+
push(`## The fixes (${open.length} not fixed yet)`);
|
|
692
|
+
push();
|
|
693
|
+
push("Spec them one at a time, or several together — each command points bt-spec at this file, which carries every fix's cause, evidence, code, gain, risk and how to verify it.");
|
|
694
|
+
push();
|
|
695
|
+
if (fixable.length) {
|
|
696
|
+
push("| ID | Fix | Status | Expected gain | Risk | Spec it |");
|
|
697
|
+
push("|---|---|---|---|---|---|");
|
|
698
|
+
for (const finding of fixable) push(`| ${finding.id} | ${cell(finding.title)} | ${finding.status || "proposed"} | ${cell(finding.gain || finding.cost)} | ${cell(finding.risk)} | \`/bt-spec Fix ${finding.id} from ${source}\` |`);
|
|
699
|
+
push();
|
|
700
|
+
const openIds = open.filter((finding) => finding.fix).map((finding) => finding.id);
|
|
701
|
+
if (openIds.length > 1) { push(`**All open fixes together:** \`/bt-spec Fix ${join(openIds)} from ${source}\``); push(); }
|
|
702
|
+
// The example group names real fixes: the first and last open ones, or the first two in the table.
|
|
703
|
+
const exampleIds = openIds.length > 2 ? [openIds[0], openIds[openIds.length - 1]] : fixable.slice(0, 2).map((finding) => finding.id);
|
|
704
|
+
if (exampleIds.length > 1) push(`**A group of your choice:** \`/bt-spec Fix ${join(exampleIds)} from ${source}\` (any IDs from the table)`);
|
|
705
|
+
} else {
|
|
706
|
+
push("No fixes proposed.");
|
|
707
|
+
}
|
|
708
|
+
push();
|
|
709
|
+
for (const finding of list) {
|
|
710
|
+
push(`## ${finding.id} · ${finding.title}`);
|
|
711
|
+
push();
|
|
712
|
+
push(`**Severity:** ${finding.severity || "–"} · **Status:** ${finding.status || "–"} · **Phases:** ${(finding.phases || []).join(", ") || "–"}${finding.cost ? ` · **Cost:** ${finding.cost}` : ""}`);
|
|
713
|
+
push();
|
|
714
|
+
if (finding.cause) { push("### Why it is slow"); push(); push(finding.cause); push(); }
|
|
715
|
+
if (finding.evidence && finding.evidence.length) { push("### Evidence"); push(); for (const item of finding.evidence) push(`- ${item}`); push(); }
|
|
716
|
+
if (finding.code && finding.code.length) { push("### Code"); push(); for (const location of finding.code) push(`- \`${location.file}${location.line ? `:${location.line}` : ""}\`${location.label ? ` — ${location.label}` : ""}`); push(); }
|
|
717
|
+
if (finding.fix) { push(isDone(finding) ? "### The fix" : "### Proposed fix"); push(); push(finding.fix); push(); }
|
|
718
|
+
if (finding.gain) { push(`**Expected gain:** ${finding.gain}`); push(); }
|
|
719
|
+
if (finding.risk) { push(`**Risk:** ${finding.risk}`); push(); }
|
|
720
|
+
if (finding.verify) { push(`**How to verify:** ${finding.verify}`); push(); }
|
|
721
|
+
if (finding.before || finding.after) { push(`**Before:** ${finding.before || "–"} · **After:** ${finding.after || "not fixed yet"}`); push(); }
|
|
722
|
+
if (finding.diff) { push("<details><summary>The change</summary>"); push(); push("```diff"); push(finding.diff); push("```"); push(); push("</details>"); push(); }
|
|
723
|
+
}
|
|
724
|
+
return lines.join("\n");
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Prints the report to a PDF beside it (the page's Download PDF button), with the Chrome the capture drives: the print
|
|
729
|
+
* stylesheet, every collapsed section open, backgrounds kept. A machine without puppeteer or Chrome only skips the PDF.
|
|
730
|
+
*/
|
|
731
|
+
async function writePdf(htmlFile, pdfFile) {
|
|
732
|
+
let puppeteer = null;
|
|
733
|
+
try {
|
|
734
|
+
puppeteer = (await import("puppeteer-core")).default;
|
|
735
|
+
} catch {
|
|
736
|
+
process.stdout.write("skipped the PDF (puppeteer-core is not installed next to report.mjs)\n");
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
let browser = null;
|
|
740
|
+
try {
|
|
741
|
+
const { findChrome } = await import("./lib/chrome.mjs");
|
|
742
|
+
browser = await puppeteer.launch({ executablePath: findChrome(), headless: "new", args: ["--allow-file-access-from-files"] });
|
|
743
|
+
const page = await browser.newPage();
|
|
744
|
+
await page.setViewport({ width: 1280, height: 900, deviceScaleFactor: 1 });
|
|
745
|
+
await page.goto("file://" + path.resolve(htmlFile), { waitUntil: "load" });
|
|
746
|
+
await new Promise((resolve) => setTimeout(resolve, 1200)); // charts and the progress panel render after load
|
|
747
|
+
await page.evaluate(() => {
|
|
748
|
+
// The PDF is the report: a run still marked running (the report is written just before the run ends) keeps
|
|
749
|
+
// its live panel off the page.
|
|
750
|
+
if (document.documentElement.classList.contains("btp-running")) document.querySelectorAll("#bt-progress, .btp-toolbar").forEach((element) => element.remove());
|
|
751
|
+
document.querySelectorAll("details").forEach((details) => { details.open = true; });
|
|
752
|
+
});
|
|
753
|
+
await page.emulateMediaType("print");
|
|
754
|
+
await page.pdf({ path: pdfFile, format: "A4", printBackground: true, margin: { top: "12mm", right: "10mm", bottom: "12mm", left: "10mm" } });
|
|
755
|
+
process.stdout.write(`wrote ${pdfFile}\n`);
|
|
756
|
+
} catch (error) {
|
|
757
|
+
process.stdout.write(`skipped the PDF: ${error.message}\n`);
|
|
758
|
+
} finally {
|
|
759
|
+
if (browser) await browser.close();
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
579
763
|
/** Entry point. */
|
|
580
|
-
function main() {
|
|
764
|
+
async function main() {
|
|
581
765
|
const flags = parseArguments(process.argv.slice(2));
|
|
582
766
|
if (!flags.analysis) throw new Error("Pass --analysis <analysis.json> [--out <dashboard.html>]");
|
|
583
767
|
const runDir = (file) => (file ? path.dirname(path.resolve(file)) : null);
|
|
@@ -598,14 +782,22 @@ function main() {
|
|
|
598
782
|
warm: warm ? pageData(warm, reportDir, runDir(flags.warm)) : null,
|
|
599
783
|
findings,
|
|
600
784
|
groups: OWNER_GROUPS,
|
|
785
|
+
slug: path.basename(reportDir),
|
|
601
786
|
};
|
|
602
787
|
if (flags.snapshots) data.run.shots = shotsFrom(path.resolve(flags.snapshots), reportDir);
|
|
603
788
|
if (flags["snapshots-before"]) {
|
|
604
789
|
// Shown beside this run's shots of the same names (needs --baseline, whose own shots they replace).
|
|
605
790
|
if (data.baseline) data.baseline.shots = shotsFrom(path.resolve(flags["snapshots-before"]), reportDir);
|
|
606
791
|
}
|
|
607
|
-
|
|
792
|
+
const pdfFile = flags.pdf === "false" ? null : outFile.replace(/\.html?$/i, "") + ".pdf";
|
|
793
|
+
fs.writeFileSync(outFile, buildPage({ title, verdict: findings && findings.summary, data, pdfName: pdfFile ? path.basename(pdfFile) : null }));
|
|
608
794
|
process.stdout.write(`wrote ${outFile}\n`);
|
|
795
|
+
if (findings) {
|
|
796
|
+
const markdownFile = path.join(path.dirname(outFile), "findings.md");
|
|
797
|
+
fs.writeFileSync(markdownFile, findingsMarkdown(findings, analysis, path.basename(path.dirname(outFile))));
|
|
798
|
+
process.stdout.write(`wrote ${markdownFile}\n`);
|
|
799
|
+
}
|
|
800
|
+
if (pdfFile) return writePdf(outFile, pdfFile);
|
|
609
801
|
}
|
|
610
802
|
|
|
611
|
-
main();
|
|
803
|
+
main().catch((error) => { process.stderr.write(String(error && error.stack ? error.stack : error) + "\n"); process.exit(1); });
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* bt-profile scenario template — copy to `<project>/.agents/profile/<slug>/data/scenario.mjs` and make it play the
|
|
3
|
-
* moment the user says is slow (a cold load, a level start, a boss fight, a menu → game transition
|
|
3
|
+
* moment the user says is slow (a cold load, a level start, a boss fight, a menu → game transition, a page that janks
|
|
4
|
+
* on scroll, a slow route change). It works on any web page; on a Babylon page it also waits for the scene.
|
|
4
5
|
*
|
|
5
6
|
* The capture script calls `run(context)` with:
|
|
6
7
|
* context.open(urlOrPath?) navigate (default: the --url given to profile.mjs)
|
|
7
8
|
* context.expectNavigation() call before a click that loads a new page (so it is not reported as a reload)
|
|
8
9
|
* context.mark(name) start a named phase (the report splits every number by phase)
|
|
9
10
|
* context.waitFor(fn, { timeout, polling, args }) wait until a page function returns truthy
|
|
10
|
-
* context.waitForFrames(count) wait until
|
|
11
|
+
* context.waitForFrames(count) wait until the page has rendered `count` frames (Babylon frames, else browser frames)
|
|
11
12
|
* context.evaluate(fn, ...args) run a function in the page (window.BABYLON, window.TOOLKIT, window.PROJECT)
|
|
12
13
|
* context.keyDown(key) / keyUp(key) / press(key) keyboard input ("ArrowUp", "w", "Space", …)
|
|
13
14
|
* context.sleep(seconds)
|
|
14
15
|
* context.shot(name) screenshot — only with --snapshots true, otherwise a no-op
|
|
15
|
-
* context.options --args key=value,… parsed into strings
|
|
16
|
+
* context.options --args key=value,… parsed into strings (settle = seconds to record after the moment)
|
|
16
17
|
* context.log(message)
|
|
17
18
|
*
|
|
18
19
|
* Rules that keep captures comparable run to run:
|
|
20
|
+
* - Enter the app the way a player does: open the page they open (usually the home page) and click through what they
|
|
21
|
+
* click (a menu, a level button — context.expectNavigation() first when the click loads a new page). A deep link you
|
|
22
|
+
* build yourself can take a path players never take (another route, a server quirk), and then you measure the wrong thing.
|
|
19
23
|
* - Drive the game the way a player would (keys, the game's own components), never by skipping work.
|
|
20
24
|
* - Wait on game state (a phase, a component flag), not on fixed sleeps, for anything that loads.
|
|
21
25
|
* - Mark every phase the user cares about; keep the names stable between runs (before / after compares by name).
|
|
@@ -24,33 +28,38 @@
|
|
|
24
28
|
/** Shown in the report. */
|
|
25
29
|
export const meta = {
|
|
26
30
|
name: "my-scenario",
|
|
27
|
-
description: "Cold load of the
|
|
31
|
+
description: "Cold load of the page (and its Babylon scene, if any), then N seconds of use.",
|
|
28
32
|
};
|
|
29
33
|
|
|
30
|
-
/** Seconds recorded after the scene is running, unless --args
|
|
31
|
-
const
|
|
34
|
+
/** Seconds recorded after the scene is running, unless --args settle=<seconds> overrides it (SKILL.md passes it). */
|
|
35
|
+
const DEFAULT_SETTLE_SECONDS = 60;
|
|
32
36
|
|
|
33
37
|
/**
|
|
34
38
|
* Plays the scenario.
|
|
35
39
|
* @param {object} context - the bt-profile scenario context
|
|
36
40
|
*/
|
|
37
41
|
export async function run(context) {
|
|
38
|
-
const
|
|
42
|
+
const settleSeconds = Number(context.options.settle || context.options.play || DEFAULT_SETTLE_SECONDS);
|
|
39
43
|
await context.open();
|
|
40
44
|
await context.mark("load");
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return scene != null && scene.isReady() && scene.activeCamera != null;
|
|
44
|
-
});
|
|
45
|
+
// Any web app: wait for the page to load and paint. A Babylon page also waits for its scene below.
|
|
46
|
+
await context.waitFor(() => document.readyState === "complete");
|
|
45
47
|
await context.waitForFrames(30);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
const babylonPage = await context.evaluate(() => window.BABYLON != null);
|
|
49
|
+
if (babylonPage) {
|
|
48
50
|
await context.waitFor(() => {
|
|
49
|
-
const scene = window.BABYLON.EngineStore.LastCreatedScene;
|
|
50
|
-
return scene != null && scene.
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const scene = window.BABYLON.EngineStore ? window.BABYLON.EngineStore.LastCreatedScene : null;
|
|
52
|
+
return scene != null && scene.isReady() && scene.activeCamera != null;
|
|
53
|
+
});
|
|
54
|
+
// An empty scene is "ready" too (a game that loads its level later): wait until something is drawn.
|
|
55
|
+
try {
|
|
56
|
+
await context.waitFor(() => {
|
|
57
|
+
const scene = window.BABYLON.EngineStore.LastCreatedScene;
|
|
58
|
+
return scene != null && scene.getActiveMeshes().length > 0;
|
|
59
|
+
}, { timeout: 120000 });
|
|
60
|
+
} catch {
|
|
61
|
+
context.log("nothing was drawn within 120 s — check the smoke run's screenshots (a content server down? a menu to click through?)");
|
|
62
|
+
}
|
|
54
63
|
}
|
|
55
64
|
// Hitches behind the loading screen are load time, not stutter the player sees: mark the moment it goes away.
|
|
56
65
|
// (A toolkit splash fades through opacity 0; adapt the check to the game's own loading screen.)
|
|
@@ -64,6 +73,6 @@ export async function run(context) {
|
|
|
64
73
|
}
|
|
65
74
|
await context.mark("running");
|
|
66
75
|
await context.shot("running");
|
|
67
|
-
await context.sleep(
|
|
76
|
+
await context.sleep(settleSeconds);
|
|
68
77
|
await context.shot("end-of-play");
|
|
69
78
|
}
|
|
@@ -133,7 +133,7 @@ Each prototype subagent gets: its **direction**, the **theme**, the **world anch
|
|
|
133
133
|
3. **Produce assets** via any mix of the available workflows: Pinterest pulls for reference, **GPT Image 2** for stills, **KIE MCP servers (default) / the Higgsfield CLI (Kling, Seedance, etc.)** for motion/video, hand-authored WebGL/SVG/CSS. All assets stay faithful to the world anchor and live in the prototype's folder. **On Higgsfield, every generation goes through the reference's `scripts/hf-generate.mjs` wrapper** with `--out .agents/prototypes/<NN-slug>/<file>`: the CLI alone only returns a CDN URL, and a prototype must never hot-link one. Local reference images are passed as file paths (`--image-references`, `--start-image`, `--end-image`) and uploaded automatically.
|
|
134
134
|
4. **3D-hero-scroll directions:** follow *The 3D-hero-scroll batch rule* below.
|
|
135
135
|
5. Run its own **iteration passes** (Step 4) before returning.
|
|
136
|
-
6. **Write clean, readable code.** Every file follows the Coding Practices: clean, professional TypeScript or JavaScript in the project's own language; meaningful full-word names, never one- or two-letter names or obfuscation; well-structured, readable, maintainable code for human developers; meaningful JSDoc on every class, function, method and public member (always written, but never a reason to fail a test or verification). The chosen prototype becomes the user's real front end, so its code must be maintainable.
|
|
136
|
+
6. **Write clean, readable code.** Every file follows the Coding Practices: clean, professional TypeScript or JavaScript in the project's own language; meaningful full-word names, never one- or two-letter names or obfuscation; well-structured, readable, maintainable code for human developers; meaningful JSDoc on every class, function, method and public member (always written, but never a reason to fail a test or verification). The chosen prototype becomes the user's real front end, so its code must be maintainable. Every HUD follows the Agent Reference's **Game UI Performance — ENFORCED**: per-frame values (speed, timers, bars, needles) reach the screen through refs and one frame loop, never React state or a per-frame EventBus message.
|
|
137
137
|
|
|
138
138
|
## The 3D-hero-scroll batch rule
|
|
139
139
|
|