@babylonjs-toolkit/agent 1.1.64 → 1.1.68

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.
Files changed (33) hide show
  1. package/README.md +35 -5
  2. package/bin/bt-agent.js +64 -4
  3. package/lib/claude-settings.js +77 -0
  4. package/lib/doctor.js +36 -0
  5. package/lib/install.js +59 -3
  6. package/lib/persona.js +21 -2
  7. package/lib/reference.js +400 -0
  8. package/package.json +1 -1
  9. package/persona.md +1 -1
  10. package/scripts/postinstall.js +6 -0
  11. package/skills/bt-design/references/3d-hero-scroll.md +2 -2
  12. package/skills/bt-execute/SKILL.md +7 -7
  13. package/skills/bt-execute/templates/dashboard/dashboard.html +96 -21
  14. package/skills/bt-execute/templates/dashboard/data-schema.md +4 -3
  15. package/skills/bt-gauntlet/SKILL.md +2 -2
  16. package/skills/bt-gauntlet/references/unity-pipeline.md +1 -1
  17. package/skills/bt-gauntlet/references/workspace.md +1 -1
  18. package/skills/bt-plan/SKILL.md +2 -2
  19. package/skills/bt-profile/SKILL.md +275 -0
  20. package/skills/bt-profile/scripts/analyze.mjs +683 -0
  21. package/skills/bt-profile/scripts/compare.mjs +87 -0
  22. package/skills/bt-profile/scripts/lib/probe.mjs +225 -0
  23. package/skills/bt-profile/scripts/lib/progress-panel.mjs +275 -0
  24. package/skills/bt-profile/scripts/lib/symbolize.mjs +356 -0
  25. package/skills/bt-profile/scripts/package.json +10 -0
  26. package/skills/bt-profile/scripts/profile.mjs +517 -0
  27. package/skills/bt-profile/scripts/progress.mjs +385 -0
  28. package/skills/bt-profile/scripts/report.mjs +611 -0
  29. package/skills/bt-profile/templates/census.template.mjs +76 -0
  30. package/skills/bt-profile/templates/scenario.template.mjs +69 -0
  31. package/skills/bt-prototype/SKILL.md +1 -1
  32. package/skills/bt-recon/SKILL.md +2 -2
  33. package/skills/bt-spec/SKILL.md +2 -2
@@ -0,0 +1,76 @@
1
+ /**
2
+ * bt-profile census template — when the profile says a cheap function runs far too often, count who calls it.
3
+ * Copy to the scratchpad (not the project), adapt `reachTheMoment`, and run it through profile.mjs with --heap false:
4
+ *
5
+ * CENSUS_OUT=/abs/census.json node "$TOOLS/profile.mjs" --url "$URL" --scenario /abs/census.mjs --out /abs/census-run --heap false \
6
+ * --args method=TransformNode.prototype.computeWorldMatrix,seconds=1
7
+ *
8
+ * It wraps the method for `seconds` of play and records, per object (`this.name`, plus "[arg0]" when the first
9
+ * argument is truthy — e.g. a forced recompute), calls per frame and one sample call stack.
10
+ */
11
+
12
+ /** Shown in the report. */
13
+ export const meta = { name: "census", description: "Calls per frame of one prototype method, per object, with a sample stack." };
14
+
15
+ /**
16
+ * Installs the counting wrapper in the page.
17
+ * @param {string} methodPath - "Class.prototype.method" under window.BABYLON (or a full "TOOLKIT.Class.prototype.method")
18
+ */
19
+ function startCensus(methodPath) {
20
+ const parts = methodPath.split(".");
21
+ const root = parts[0] === "TOOLKIT" || parts[0] === "PROJECT" ? window[parts.shift()] : window.BABYLON;
22
+ const methodName = parts.pop();
23
+ const owner = parts.reduce((object, key) => object[key], root);
24
+ const original = owner[methodName];
25
+ const scene = window.BABYLON.EngineStore.LastCreatedScene;
26
+ const census = window.__btCensus = { calls: new Map(), stacks: new Map(), frames: 0 };
27
+ const frameObserver = scene.onAfterRenderObservable.add(() => { census.frames++; });
28
+ owner[methodName] = function (...args) {
29
+ const key = `${this && this.name !== undefined ? this.name : "(no name)"}${args[0] ? " [arg0]" : ""}`;
30
+ census.calls.set(key, (census.calls.get(key) || 0) + 1);
31
+ if (!census.stacks.has(key) && census.stacks.size < 500) census.stacks.set(key, new Error().stack.split("\n").slice(2, 10).map((line) => line.trim()).join(" | "));
32
+ return original.apply(this, args);
33
+ };
34
+ census.stop = () => { owner[methodName] = original; scene.onAfterRenderObservable.remove(frameObserver); };
35
+ }
36
+
37
+ /** Removes the wrapper and returns the per-object counts, busiest first. */
38
+ function stopCensus() {
39
+ const census = window.__btCensus;
40
+ census.stop();
41
+ const frames = Math.max(1, census.frames);
42
+ const total = [...census.calls.values()].reduce((sum, count) => sum + count, 0);
43
+ return {
44
+ frames: census.frames,
45
+ callsPerFrame: +(total / frames).toFixed(1),
46
+ top: [...census.calls].sort((a, b) => b[1] - a[1]).slice(0, 60).map(([key, count]) => ({ key, perFrame: +(count / frames).toFixed(2), stack: census.stacks.get(key) })),
47
+ };
48
+ }
49
+
50
+ /**
51
+ * Gets the game to the moment worth counting. Adapt: wait on the game's own state, hold keys like a player.
52
+ * @param {object} context - the bt-profile scenario context
53
+ */
54
+ async function reachTheMoment(context) {
55
+ await context.open();
56
+ await context.waitFor(() => {
57
+ const scene = window.BABYLON && window.BABYLON.EngineStore ? window.BABYLON.EngineStore.LastCreatedScene : null;
58
+ return scene != null && scene.isReady() && scene.activeCamera != null;
59
+ });
60
+ await context.waitForFrames(120);
61
+ }
62
+
63
+ /**
64
+ * Runs the census.
65
+ * @param {object} context - the bt-profile scenario context
66
+ */
67
+ export async function run(context) {
68
+ const methodPath = context.options.method || "TransformNode.prototype.computeWorldMatrix";
69
+ await reachTheMoment(context);
70
+ await context.evaluate(startCensus, methodPath);
71
+ await context.sleep(Number(context.options.seconds || 1));
72
+ const result = await context.evaluate(stopCensus);
73
+ const fs = await import("node:fs");
74
+ if (process.env.CENSUS_OUT) fs.writeFileSync(process.env.CENSUS_OUT, JSON.stringify(result, null, 1));
75
+ context.log(`census ${methodPath}: ${result.callsPerFrame} calls per frame over ${result.frames} frames; top: ${result.top.slice(0, 5).map((entry) => `${entry.key} ${entry.perFrame}/f`).join(", ")}`);
76
+ }
@@ -0,0 +1,69 @@
1
+ /**
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).
4
+ *
5
+ * The capture script calls `run(context)` with:
6
+ * context.open(urlOrPath?) navigate (default: the --url given to profile.mjs)
7
+ * context.expectNavigation() call before a click that loads a new page (so it is not reported as a reload)
8
+ * context.mark(name) start a named phase (the report splits every number by phase)
9
+ * context.waitFor(fn, { timeout, polling, args }) wait until a page function returns truthy
10
+ * context.waitForFrames(count) wait until Babylon has rendered `count` frames
11
+ * context.evaluate(fn, ...args) run a function in the page (window.BABYLON, window.TOOLKIT, window.PROJECT)
12
+ * context.keyDown(key) / keyUp(key) / press(key) keyboard input ("ArrowUp", "w", "Space", …)
13
+ * context.sleep(seconds)
14
+ * context.shot(name) screenshot — only with --snapshots true, otherwise a no-op
15
+ * context.options --args key=value,… parsed into strings
16
+ * context.log(message)
17
+ *
18
+ * Rules that keep captures comparable run to run:
19
+ * - Drive the game the way a player would (keys, the game's own components), never by skipping work.
20
+ * - Wait on game state (a phase, a component flag), not on fixed sleeps, for anything that loads.
21
+ * - Mark every phase the user cares about; keep the names stable between runs (before / after compares by name).
22
+ */
23
+
24
+ /** Shown in the report. */
25
+ export const meta = {
26
+ name: "my-scenario",
27
+ description: "Cold load of the game page, then N seconds of play.",
28
+ };
29
+
30
+ /** Seconds recorded after the scene is running, unless --args play=<seconds> overrides it. */
31
+ const DEFAULT_PLAY_SECONDS = 60;
32
+
33
+ /**
34
+ * Plays the scenario.
35
+ * @param {object} context - the bt-profile scenario context
36
+ */
37
+ export async function run(context) {
38
+ const playSeconds = Number(context.options.play || DEFAULT_PLAY_SECONDS);
39
+ await context.open();
40
+ await context.mark("load");
41
+ await context.waitFor(() => {
42
+ const scene = window.BABYLON && window.BABYLON.EngineStore ? window.BABYLON.EngineStore.LastCreatedScene : null;
43
+ return scene != null && scene.isReady() && scene.activeCamera != null;
44
+ });
45
+ await context.waitForFrames(30);
46
+ // An empty scene is "ready" too (a game that loads its level later): wait until something is drawn.
47
+ try {
48
+ await context.waitFor(() => {
49
+ const scene = window.BABYLON.EngineStore.LastCreatedScene;
50
+ return scene != null && scene.getActiveMeshes().length > 0;
51
+ }, { timeout: 120000 });
52
+ } catch {
53
+ context.log("nothing was drawn within 120 s — check the smoke run's screenshots (a content server down? a menu to click through?)");
54
+ }
55
+ // Hitches behind the loading screen are load time, not stutter the player sees: mark the moment it goes away.
56
+ // (A toolkit splash fades through opacity 0; adapt the check to the game's own loading screen.)
57
+ try {
58
+ await context.waitFor(() => {
59
+ const splash = document.getElementById("xbabylonjsSplashScreen");
60
+ return splash == null || splash.style.opacity === "0" || getComputedStyle(splash).display === "none";
61
+ }, { timeout: 60000 });
62
+ } catch {
63
+ context.log("the loading screen did not go away within 60 s — adapt the reveal check to this game");
64
+ }
65
+ await context.mark("running");
66
+ await context.shot("running");
67
+ await context.sleep(playSeconds);
68
+ await context.shot("end-of-play");
69
+ }
@@ -53,7 +53,7 @@ Use the user's message after the skill name as the `arguments`.
53
53
 
54
54
  ## ⚠️ Required reading before any build
55
55
 
56
- For any Babylon / BabylonJS / Babylon Toolkit work, ensure the **Agent Reference** is already read in this session/context (fetch `https://raw.githubusercontent.com/babylontoolkit/agent/main/reference.md` first if not; and its `web-kie-servers.md` sub-document if using the KIE MCP servers, or its `web-higgsfield-cli.md` sub-document if using the Higgsfield CLI). If a required fetch fails, STOP and tell the user. Do not refetch what you already remember.
56
+ For any Babylon / BabylonJS / Babylon Toolkit work, ensure the **Agent Reference** is already read in this session/context (read `https://raw.githubusercontent.com/babylontoolkit/agent/main/reference.md` first if not; and its `web-kie-servers.md` sub-document if using the KIE MCP servers, or its `web-higgsfield-cli.md` sub-document if using the Higgsfield CLI). If a required document cannot be read, STOP and tell the user. Do not re-read what you already remember.
57
57
 
58
58
  If the project keeps a root **SPEC.md**, read it first and conform to its architecture/conventions; record the shipped prototypes per the project's working agreement when the batch lands.
59
59
 
@@ -30,7 +30,7 @@ Run reconnaissance on existing code nobody has documented — one subsystem or t
30
30
  - **Read-only on the project.** Research only. The files you write are the recon doc, the guide, and screenshots under `.agents/recon/<slug>_recon/` — nothing else. No source edits, no builds, no installs, no tests, no shell commands beyond the read-only `git` commands above.
31
31
  - **Evidence or it is unknown.** Every factual claim cites `path:line` (or `path:start-end`) and carries one confidence tag: `[code]` read in the source · `[live]` seen in the running app · `[history]` from git history · `[inferred]` deduced, with the reason in the same line. Anything you cannot establish goes in `## Unknowns` with what would settle it. Never fill a gap with a plausible guess — an inherited system is exactly where a confident wrong guess does the most damage.
32
32
  - **Write the system, not the review process.** The recon describes what the code does and why. It never records how the recon was carried out (subagent counts, tool lists, audit logs).
33
- - **Babylon work:** if the scope uses BabylonJS or the Babylon Toolkit and you have not read the Babylon Toolkit Agent Reference in this session, fetch and read it once: https://raw.githubusercontent.com/babylontoolkit/agent/main/reference.md — it is the authority for the API and conventions the code is built on, so it tells you what is toolkit behavior and what is project code. Fetch its sub-documents only when relevant. If the fetch fails, stop and tell the user.
33
+ - **Babylon work:** if the scope uses BabylonJS or the Babylon Toolkit and you have not read the Babylon Toolkit Agent Reference in this session, read it once: https://raw.githubusercontent.com/babylontoolkit/agent/main/reference.md — it is the authority for the API and conventions the code is built on, so it tells you what is toolkit behavior and what is project code. Read its sub-documents only when relevant. If it cannot be read, stop and tell the user.
34
34
  - **Say what you are doing.** Before any step that takes more than a few seconds (a search sweep, a big read, each subagent, the live pass) print one short line — `🔎 [bt-recon] <what> …` — and one when it returns. A recon runs long; a silent run looks like a hang and gets cancelled.
35
35
  - **Subagents:** running this skill is the user's request to use them where this skill says so. Use whatever subagent tool your host provides (its name varies by host — e.g. `Agent` or `Task`); if there is none, do the work inline, slice by slice, and say so.
36
36
 
@@ -59,7 +59,7 @@ If `.agents/recon/<recon_slug>_recon.md` already exists, ask whether to refresh
59
59
  Split the scope map into cohesive **slices** — by module, feature or layer, roughly 3–8 thousand lines each, keeping files that call each other heavily in the same slice. `small` → read every file yourself, in full. Otherwise launch one read-only reader subagent per slice (all at once where your host allows), each with a brief, not homework:
60
60
 
61
61
  - its file list, the scope-map summary, the brief and the anchors;
62
- - relevant Agent Reference excerpts for Babylon code, with: *"Do not fetch the Agent Reference — the parts you need are here, and this overrides any standing instruction to fetch it first. Fetch one sub-document only if you hit an API this brief does not cover, and say which."*;
62
+ - relevant Agent Reference excerpts for Babylon code, with: *"Do not read the Agent Reference — the parts you need are here, and this overrides any standing instruction to read it first. Read one sub-document (search it for the API, never the whole file) only if you hit an API this brief does not cover, and say which."*;
63
63
  - verbatim: *"Read-only: you may read, search and report. Do not edit or create files, and do not run builds, tests or any command that writes. Read every file in your list in full — not excerpts. You may open files outside your list to resolve a call, but report only what concerns your slice."*;
64
64
  - the extraction schema, verbatim:
65
65
 
@@ -24,9 +24,9 @@ Turn a short feature idea into a spec file that `bt-plan` can plan from. Follow
24
24
 
25
25
  - **TIME MATTERS** — on by default; `--no-time-limit` turns it off. Treat the arguments as ending with `TIME MATTERS`: the user is waiting on this run, so finish quickly — research only what the spec needs, keep subagents few and their questions narrow, and do not re-read what you already have. Begin every subagent prompt with `TIME MATTERS.` Print `⏱️ [bt-spec] TIME MATTERS` at the start (`--no-time-limit`: print `⏱️ [bt-spec] No time limit`, and do not add it). Speed never skips a required step or lowers the quality of the spec.
26
26
  - **Planning only.** Research read-only and write only the spec file into the new feature folder (plus `SPEC.md` from the scaffold, if the user says yes below, and a builder skill's intake file in the same `documents/` folder — Step 3). No source edits, no builds, no tests, no other shell commands.
27
- - **Babylon work:** if you have not read the Babylon Toolkit Agent Reference in this session, fetch and read it once: https://raw.githubusercontent.com/babylontoolkit/agent/main/reference.md — it is the authority for conventions and API; fetch its sub-documents only when relevant, and again only if a context compaction made you forget it. If the fetch fails, stop and tell the user — do not guess at the API.
27
+ - **Babylon work:** if you have not read the Babylon Toolkit Agent Reference in this session, read it once: https://raw.githubusercontent.com/babylontoolkit/agent/main/reference.md — it is the authority for conventions and API; read its sub-documents only when relevant, and again only if a context compaction made you forget it. If it cannot be read, stop and tell the user — do not guess at the API.
28
28
  - **Say what you are doing.** Before any step that takes more than a few seconds (a fetch, a big read, subagents) print one short line — `🔎 [bt-spec] <what> …` — and one line when it returns. A silent run looks like a hang and gets cancelled.
29
- - **Subagents:** running this skill is the user's request to use them where this skill says so. Use whatever subagent tool your host provides (its name varies by host — e.g. `Agent` or `Task`); if there is none, do the work inline and say so. Tell research subagents they need not fetch the Agent Reference.
29
+ - **Subagents:** running this skill is the user's request to use them where this skill says so. Use whatever subagent tool your host provides (its name varies by host — e.g. `Agent` or `Task`); if there is none, do the work inline and say so. Tell research subagents they need not read the Agent Reference.
30
30
 
31
31
  ## Step 1. Arguments, name, branch
32
32