@babylonjs-toolkit/agent 1.2.11 → 1.2.12

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.
@@ -9,6 +9,7 @@
9
9
  * node profile-browser.mjs --scene level.gltf --pin 20,35 --toggles dpr,taa,motionblur,bloom,post,shadows,lights
10
10
  * node profile-browser.mjs --scene optimized.gltf --poses ./before-pinned.json --toggles none (same views as an earlier run)
11
11
  * [--headed true] [--dpr 2] [--window 3] [--settle 4] [--shots ./shots] [--cpuprofile true] [--toggles none]
12
+ * [--casters true] (with --pin / --poses: each pin also records every shadow map's casters per cascade, `shadowCasters`)
12
13
  */
13
14
  import fs from "node:fs";
14
15
  import os from "node:os";
@@ -725,6 +726,53 @@ function installProbe() {
725
726
  };
726
727
  };
727
728
 
729
+ /**
730
+ * Records, over the next rendered frame, which meshes every shadow generator draws and in which cascade, by wrapping
731
+ * each generator's per-sub-mesh shadow render. Shadow maps are often the largest pass once repeats instance, and a
732
+ * caster whose shadow lands on nothing the camera sees (roads, flat ground, water, far backdrops) is pure cost — this
733
+ * names them, with their draws per cascade, so they can be pruned and proven by capture.
734
+ * @returns {Promise<{lights: {light: string, cascades: number, draws: number, casters: {mesh: string, owner: string, perCascade: number[], draws: number}[]}[]}>}
735
+ */
736
+ state.shadowCasters = () => new Promise((resolve, reject) => {
737
+ const scene = state.scene();
738
+ const generators = scene.lights
739
+ .map((light) => ({ light, generator: light.getShadowGenerator && light.getShadowGenerator() }))
740
+ .filter((entry) => entry.generator && typeof entry.generator._renderSubMeshForShadowMap === "function");
741
+ const records = generators.map(({ light, generator }) => ({ light: light.name, generator, cascades: generator.numCascades || 1, casters: new Map() }));
742
+ let recording = false;
743
+ const originals = records.map((record) => {
744
+ const original = record.generator._renderSubMeshForShadowMap;
745
+ record.generator._renderSubMeshForShadowMap = function (subMesh, ...rest) {
746
+ if (recording) {
747
+ const mesh = subMesh.getMesh();
748
+ if (!record.casters.has(mesh)) record.casters.set(mesh, new Array(record.cascades).fill(0));
749
+ const cascade = Math.min(record.cascades - 1, Math.max(0, record.generator._currentLayer || 0));
750
+ record.casters.get(mesh)[cascade]++;
751
+ }
752
+ return original.call(this, subMesh, ...rest);
753
+ };
754
+ return original;
755
+ });
756
+ const restore = () => records.forEach((record, index) => { record.generator._renderSubMeshForShadowMap = originals[index]; });
757
+ const timeout = setTimeout(() => { restore(); reject(new Error(`shadowCasters: no frame rendered within ${DRAW_OWNER_FRAME_TIMEOUT_MS} ms`)); }, DRAW_OWNER_FRAME_TIMEOUT_MS);
758
+ scene.onBeforeRenderObservable.addOnce(() => {
759
+ recording = true;
760
+ scene.onAfterRenderObservable.addOnce(() => {
761
+ recording = false;
762
+ clearTimeout(timeout);
763
+ restore();
764
+ resolve({
765
+ lights: records.map((record) => {
766
+ const casters = [...record.casters.entries()].map(([mesh, perCascade]) => ({
767
+ mesh: mesh.name, owner: state.ownerOf(mesh), perCascade, draws: perCascade.reduce((sum, count) => sum + count, 0),
768
+ })).sort((first, second) => second.draws - first.draws);
769
+ return { light: record.light, cascades: record.cascades, draws: casters.reduce((sum, caster) => sum + caster.draws, 0), casters };
770
+ }),
771
+ });
772
+ });
773
+ });
774
+ });
775
+
728
776
  /**
729
777
  * Switches one runtime cost off (on = false) or back on (on = true).
730
778
  * Keys: dpr, taa, motionblur, bloom, post (every camera post-process), shadows, lights (every point / spot light).
@@ -903,6 +951,7 @@ async function main() {
903
951
  const lightAudit = await page.evaluate(() => window.__btProfile.lightAudit());
904
952
  // drawOwners is async: it measures the next rendered frame, and page.evaluate waits for that promise.
905
953
  const drawOwners = await page.evaluate(() => window.__btProfile.drawOwners());
954
+ const shadowCasters = flags.casters === "true" ? await page.evaluate(() => window.__btProfile.shadowCasters()) : null;
906
955
  const steps = [];
907
956
  for (const key of toggles) {
908
957
  const change = await page.evaluate((k) => window.__btProfile.toggle(k, false), key);
@@ -913,7 +962,7 @@ async function main() {
913
962
  steps.push({ off: key, change, fps: off.fps, p50Ms: off.p50Ms, drawCalls: off.drawCalls, passes: off.passes, cpuRenderMs: off.cpuRenderMs, cpuFrameMs: off.cpuFrameMs });
914
963
  }
915
964
  const after = await measure(page, windowSeconds);
916
- report.pins.push({ atSeconds: seconds, readyMs, pinned, actual: { before: poseBefore, after: poseAfter }, baseline, lightAudit, drawOwners, cpu, steps, baselineAgain: { fps: after.fps, p50Ms: after.p50Ms } });
965
+ report.pins.push({ atSeconds: seconds, readyMs, pinned, actual: { before: poseBefore, after: poseAfter }, baseline, lightAudit, drawOwners, shadowCasters, cpu, steps, baselineAgain: { fps: after.fps, p50Ms: after.p50Ms } });
917
966
  await page.close();
918
967
  }
919
968
  }
@@ -12,6 +12,7 @@ Turn a feature spec into `.agents/specs/<slug>/documents/<slug>_plan.md`: an ord
12
12
  /bt-plan @.agents/specs/mute-game-audio/documents/mute-game-audio_spec.md
13
13
  /bt-plan "add a settings toggle to mute all game audio" # no spec file → Quick Plan: short interview, creates the feature folder, then plans
14
14
  /bt-plan Fix F3 from @.agents/specs/<slug>/documents/<slug>_followups.md # Quick Plan for a finished feature's follow-ups (its dashboard's copy buttons)
15
+ /bt-plan "optimize Assets/Scenes/Level01.unity" # Quick Plan of a scene optimization: bt-optimize's playbook, no interview
15
16
  /bt-plan --heavy @.agents/specs/<slug>/documents/<slug>_spec.md # decision-complete plan for a long or cheaper-model run
16
17
  /bt-plan --heavy --parity @.agents/specs/<slug>/documents/<slug>_spec.md # numeric parity gates against the reference (slow)
17
18
  /bt-plan --no-time-limit @.agents/specs/<slug>/documents/<slug>_spec.md # turn off the default TIME MATTERS mode
@@ -33,13 +34,15 @@ Turn a feature spec into `.agents/specs/<slug>/documents/<slug>_plan.md`: an ord
33
34
  1. Read the feature spec in full, and `SPEC.md`'s headings, Architecture, Conventions and the systems the feature touches. The plan must conform to SPEC.md — **if it would conflict, stop and tell the user.** Verification procedures described in SPEC.md are tooling you may reuse, not a bar the plan must meet. Note the spec's `spec_impact`, `size` and `proof`.
34
35
  2. **Start from the spec's `## Research Notes`, and any bt-recon doc it cites (the feature's own `recon/` copies, or `.agents/recon/*_recon.md`) or whose scope covers the systems the feature touches** — its Extension Points and End-to-End Flows usually name the integration points directly. Spot-check that the paths exist, then research only what a plan needs beyond them: how the app is built and tested, the real conventions and the closest feature to mirror, the concrete files and integration points, available dependencies, constraints from the agent instructions.
35
36
  3. Size the research: `small` → inline; `medium` / `large` (or no Research Notes) → up to 3 **read-only** subagents returning findings and paths, not file dumps. Tell each one 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 — not even into a build folder. If a fact needs a build or a test run to establish, report it as unknown and say which command would settle it."*
36
- 4. Sibling-skill pattern (e.g. bt-design's 3D-Hero-Scroll): read that skill's reference **and templates** *(where skills load through a tool: `load_skill` + `read_skill_resource`, never a guessed path; where they are files: the skills directory this skill was loaded from, e.g. `~/.claude/skills/`, `~/.agents/skills/` or the project's equivalent)*. The plan **copies and configures the template engine — never re-implements it**; each behavioral option the spec records (e.g. `sweep: page`) becomes an Acceptance item stated in observable terms. Prefer copying and wiring the template as the first task, so later tasks only configure it.
37
+ 4. Sibling-skill pattern (e.g. bt-design's 3D-Hero-Scroll, bt-optimize's scene optimization): read that skill's reference **and templates** *(where skills load through a tool: `load_skill` + `read_skill_resource`, never a guessed path; where they are files: the skills directory this skill was loaded from, e.g. `~/.claude/skills/`, `~/.agents/skills/` or the project's equivalent)*. The plan **copies and configures the template engine — never re-implements it**; each behavioral option the spec records (e.g. `sweep: page`) becomes an Acceptance item stated in observable terms. Prefer copying and wiring the template as the first task, so later tasks only configure it.
37
38
  5. Too ambiguous to plan responsibly → ask the user. **Already built?** If the research shows some or all of the feature already exists, say so first and plan only what is missing (often just tests and the live check).
38
39
 
39
40
  **Quick Plan (no spec file):** after the analysis, ask a small round of high-leverage questions (scope, behavior, edge cases, which systems it touches); skip anything the brief or code already answers. Unanswered items fall back to: feature name from the brief — the `<slug>`: lowercase kebab-case, `a-z 0-9 -` only, max 40 chars, with `-02`, `-03` … appended if a folder of that name already exists in `.agents/specs/`, `.agents/complete/`, `.agents/followup/` or anywhere under `.agents/archived/`; `spec_impact` and `size` inferred from the analysis; `proof: functional` unless `--parity`. List the assumptions in Codebase Analysis. **A Quick Plan is a creation point:** it first makes sure the default `.agents` folders exist — `.agents/specs/`, `.agents/complete/`, `.agents/archived/`, `.agents/followup/`, `.agents/profile/` and `.agents/recon/`, each with an empty `.gitkeep` (write only the ones missing; never touch what a folder holds), then creates the feature folder `.agents/specs/<slug>/` (with `documents/`), exactly as bt-spec would, and the plan, report and tests live there.
40
41
 
41
42
  **A Quick Plan of follow-ups** (`Fix F3 from @<source-folder>/documents/<slug>_followups.md`, the dashboard's Quick Plan copy command): the cited follow-ups are the brief, read in full with what they point at in the source feature (its plan's Decisions, the run-log lines and files named, its `recon/` copies when they touch that code). Plan only them, as one new feature named for what they fix, never `fix-f3` or the source's slug. The plan's opening paragraph names them with the file: `Quick Plan for follow-up **F3** of <source title> (\`<source-folder>/documents/<slug>_followups.md\`).` — the helper's `check` links an unlinked feature from that line, so it must be there. A cited id the file lacks: list the ids it has, and stop. A cited follow-up whose **Status** line says a later feature already addresses it (anything but *partly done*): name that feature and ask before planning it again. Step 4 links the new feature to them.
42
43
 
44
+ **A plan that optimizes a Unity scene** — a Quick Plan brief or a spec asking to make a scene run faster or lighter in the browser ("optimize `Level01.unity`", "cut the level's draw calls", "this track runs at 30 FPS"): read bt-optimize's `SKILL.md` and **`planning.md`** *(same lookup as step 4)* before anything else. The plan adopts its standard decisions **O1–O11** (in Codebase Analysis, or the Decisions log under `--heavy`; a spec's own choices win), follows its standard task list — baseline, then the working-copy pass, then shadow casters and the final proof in the game — and its tasks run bt-optimize's phases and scripts, never re-implement them. Find the scene, its export, the game code that loads it and any earlier `.agents/optimize/` run in the project; never ask about them. A Quick Plan asks **no** interview round: at most the one question `planning.md` allows (keep the current lighting exactly, or allow the re-bake merging needs), only when the brief and project leave it open — otherwise apply its default and list it as an assumption. The plan never edits the source scene, never deletes an earlier copy, and names the scene to export in its last task's Acceptance.
45
+
43
46
  **A Quick Plan of profile fixes** (`Fix F1 and F3 from @.agents/profile/<slug>/findings.md using @<recon>`, bt-profile's Quick Plan copy command): the cited fixes in `findings.md` are the brief — each one's cause, evidence, code, proposed fix, gain, risk and how to verify it, and the Verify becomes the task's proof. Read every cited recon in full, whatever its scope says, and **copy each into the new feature's `recon/` folder** (as bt-spec does), so the feature holds what it rests on after the profile is archived; turn what a recon says must not break into Acceptance or named tests. A cited recon that does not exist yet: say so, give its `/bt-recon` command (the report's **Copy recon command**), and carry on with your own analysis. Plan only the cited fixes, as one new feature named for what they fix, never `fix-f1` or the profile's slug; the plan's opening paragraph names them with the file (`Quick Plan for fixes **F1** and **F3** of profile <slug> (\`.agents/profile/<slug>/findings.md\`).`). Add a last task that re-profiles the same scenario (`/bt-profile --slug:<slug>`) and compares the phases the findings name — that re-measure is how the profile learns the fixes worked.
44
47
 
45
48
  **The feature folder.** Every feature has one: `.agents/specs/<slug>/` holding `dashboard.html` (the feature dashboard), `documents/` (`<slug>_spec.md`, `<slug>_plan.md`, bt-execute's `<slug>_autopilot.md`, the dashboard data `<slug>_dashboard.js` and live status `<slug>_live.js`), `snapshots/` and `tests/`. From a spec, `<slug>` is its folder name. A **legacy flat spec** (`.agents/specs/<slug>_spec.md`) is read where it is and left there; the plan and report still go into the new `.agents/specs/<slug>/` folder, and the report's Spec link points back to the flat file.
@@ -48,7 +48,7 @@ From the flag-stripped brief derive `feature_title` (Title Case), `feature_slug`
48
48
 
49
49
  ## Step 3. Sibling-skill patterns
50
50
 
51
- If the feature is built on a pattern owned by another skill (bt-design's 3D-Hero-Scroll, bt-atlas, bt-convert …), or the brief names a builder skill ("using bt-hero …", "using bt-prototype …"), **read that skill's SKILL.md and relevant reference before writing requirements.** *(Where skills load through a tool: `load_skill('<name>')`, then `read_skill_resource` with the paths it returns — never a guessed path. Where skills are files on disk: read them from the skills directory this skill was loaded from — e.g. `~/.claude/skills/`, `~/.agents/skills/`, or the project's `.claude/skills/` / `.agents/skills/`.)* For 3D-scroll / scroll-scrubbed / cinematic-hero features that is bt-design's `references/3d-hero-scroll.md`.
51
+ If the feature is built on a pattern owned by another skill (bt-design's 3D-Hero-Scroll, bt-atlas, bt-convert …), or the brief names a builder skill ("using bt-hero …", "using bt-prototype …"), **read that skill's SKILL.md and relevant reference before writing requirements.** *(Where skills load through a tool: `load_skill('<name>')`, then `read_skill_resource` with the paths it returns — never a guessed path. Where skills are files on disk: read them from the skills directory this skill was loaded from — e.g. `~/.claude/skills/`, `~/.agents/skills/`, or the project's `.claude/skills/` / `.agents/skills/`.)* For 3D-scroll / scroll-scrubbed / cinematic-hero features that is bt-design's `references/3d-hero-scroll.md`. **To make a Unity scene run faster or lighter in the browser** ("spec out optimizing `Level01.unity`", "cut the level's draw calls") that is bt-optimize's `SKILL.md` and `planning.md`: the spec records its standard decisions O1–O11 as Functional Requirements / Decisions (with any the user changed), its measured outcomes as Acceptance Criteria (draws and FPS before → after at the same pinned poses, every draw owner of 5%+ accounted for, `Verify` problems=0, the same look in Unity, the browser and the game, the scene to export named), and the scene, its export and the game code that loads it in Research Notes — found in the project, never asked. Cite an earlier run's `.agents/optimize/<Scene>/survey.md` when one exists.
52
52
 
53
53
  - Record the pattern's behavioral config as explicit Functional Requirements, using the sub-skill's **own names and defaults, unchanged** (e.g. 3D-Hero-Scroll `sweep: page` — PLAY glides to the document bottom and END jumps there). State any override and why.
54
54
  - Keep a behavioral option separate from the feature's route/DOM scope — `sweep` is not "which page it lives on".