@babylonjs-toolkit/agent 1.2.11 → 1.2.14
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 +5 -3
- package/lib/claude-settings.js +8 -1
- package/lib/doctor.js +2 -1
- package/lib/install.js +9 -7
- package/package.json +1 -1
- package/skills/bt-optimize/SKILL.md +94 -48
- package/skills/bt-optimize/planning.md +104 -0
- package/skills/bt-optimize/scripts/BtCombine.cs +18 -2
- package/skills/bt-optimize/scripts/BtOptimize.cs +817 -17
- package/skills/bt-optimize/scripts/qa/gltf-stats.mjs +74 -13
- package/skills/bt-optimize/scripts/qa/profile-browser.mjs +161 -2
- package/skills/bt-plan/SKILL.md +4 -1
- package/skills/bt-spec/SKILL.md +1 -1
|
@@ -1,24 +1,82 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* bt-optimize export stats: compares exported .gltf scenes — drawn mesh nodes, meshes, primitives (draw calls before
|
|
3
|
-
* LOD selection), materials, textures, drawn vertices and the size on disk of the .gltf plus its buffers.
|
|
3
|
+
* LOD selection), materials, textures, drawn vertices and the size on disk of the .gltf plus its buffers. Gzipped
|
|
4
|
+
* exports (`.gz.gltf` / `.gz.bin`, detected by their magic bytes, not their names) are read too; each buffer reports
|
|
5
|
+
* its size on disk and uncompressed.
|
|
4
6
|
*
|
|
5
7
|
* Usage:
|
|
6
|
-
* node gltf-stats.mjs export/scenes/original.gltf export/scenes/combined.gltf
|
|
8
|
+
* node gltf-stats.mjs export/scenes/original.gltf export/scenes/combined.gz.gltf
|
|
7
9
|
*/
|
|
8
10
|
import fs from "node:fs";
|
|
9
11
|
import path from "node:path";
|
|
12
|
+
import zlib from "node:zlib";
|
|
10
13
|
|
|
11
14
|
/** Bytes per megabyte, for readable sizes. */
|
|
12
15
|
const BYTES_PER_MEGABYTE = 1024 * 1024;
|
|
13
16
|
|
|
17
|
+
/** The two bytes every gzip stream starts with. */
|
|
18
|
+
const GZIP_MAGIC = [0x1f, 0x8b];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Tells whether a file starts with the gzip magic bytes.
|
|
22
|
+
* @param {string} filePath - path of the file to test
|
|
23
|
+
* @returns {boolean} true when the file is a gzip stream
|
|
24
|
+
*/
|
|
25
|
+
function isGzipFile(filePath) {
|
|
26
|
+
const header = Buffer.alloc(GZIP_MAGIC.length);
|
|
27
|
+
const descriptor = fs.openSync(filePath, "r");
|
|
28
|
+
try {
|
|
29
|
+
fs.readSync(descriptor, header, 0, header.length, 0);
|
|
30
|
+
} finally {
|
|
31
|
+
fs.closeSync(descriptor);
|
|
32
|
+
}
|
|
33
|
+
return header[0] === GZIP_MAGIC[0] && header[1] === GZIP_MAGIC[1];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Reads a .gltf file as JSON, gunzipping it first when it is gzipped.
|
|
38
|
+
* @param {string} gltfPath - path of the .gltf (or .gz.gltf) file
|
|
39
|
+
* @returns {object} the parsed glTF document
|
|
40
|
+
*/
|
|
41
|
+
function readGltf(gltfPath) {
|
|
42
|
+
const raw = fs.readFileSync(gltfPath);
|
|
43
|
+
const text = isGzipFile(gltfPath) ? zlib.gunzipSync(raw) : raw;
|
|
44
|
+
return JSON.parse(text.toString("utf8"));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Measures one external buffer: its size on disk and uncompressed. A gzipped buffer's uncompressed size is the
|
|
49
|
+
* glTF's declared `byteLength` (what the loader gets after inflating it), so the file is never inflated here.
|
|
50
|
+
* @param {string} folder - folder of the .gltf the buffer belongs to
|
|
51
|
+
* @param {{uri: string, byteLength: number}} buffer - the glTF buffer entry
|
|
52
|
+
* @returns {{uri: string, gzipped: boolean, diskBytes: number, uncompressedBytes: number}} the buffer's sizes (0 when missing)
|
|
53
|
+
*/
|
|
54
|
+
function measureBuffer(folder, buffer) {
|
|
55
|
+
const bufferPath = path.join(folder, decodeURIComponent(buffer.uri));
|
|
56
|
+
if (!fs.existsSync(bufferPath)) return { uri: buffer.uri, gzipped: false, diskBytes: 0, uncompressedBytes: 0 };
|
|
57
|
+
const diskBytes = fs.statSync(bufferPath).size;
|
|
58
|
+
const gzipped = isGzipFile(bufferPath);
|
|
59
|
+
return { uri: buffer.uri, gzipped, diskBytes, uncompressedBytes: gzipped ? buffer.byteLength : diskBytes };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Converts bytes to megabytes with two decimals.
|
|
64
|
+
* @param {number} bytes - a size in bytes
|
|
65
|
+
* @returns {number} the size in megabytes
|
|
66
|
+
*/
|
|
67
|
+
function toMegabytes(bytes) {
|
|
68
|
+
return Number((bytes / BYTES_PER_MEGABYTE).toFixed(2));
|
|
69
|
+
}
|
|
70
|
+
|
|
14
71
|
/**
|
|
15
72
|
* Reads one exported scene and measures it.
|
|
16
|
-
* @param {string} gltfPath - path of the .gltf file
|
|
17
|
-
* @returns {{file: string, nodes: number, drawnMeshNodes: number, meshes: number, primitives: number,
|
|
18
|
-
* textures: number, drawnVertices: number, sizeMegabytes: number
|
|
73
|
+
* @param {string} gltfPath - path of the .gltf (or gzipped .gz.gltf) file
|
|
74
|
+
* @returns {{file: string, gzipped: boolean, nodes: number, drawnMeshNodes: number, meshes: number, primitives: number,
|
|
75
|
+
* materials: number, textures: number, drawnVertices: number, sizeMegabytes: number, binMegabytesOnDisk: number,
|
|
76
|
+
* binMegabytesUncompressed: number, buffers: object[]}} the measurements (`sizeMegabytes` is the .gltf plus its buffers on disk)
|
|
19
77
|
*/
|
|
20
78
|
function measure(gltfPath) {
|
|
21
|
-
const gltf =
|
|
79
|
+
const gltf = readGltf(gltfPath);
|
|
22
80
|
const meshes = gltf.meshes || [];
|
|
23
81
|
const accessors = gltf.accessors || [];
|
|
24
82
|
const nodes = gltf.nodes || [];
|
|
@@ -29,15 +87,15 @@ function measure(gltfPath) {
|
|
|
29
87
|
const drawnVertices = drawnNodes.reduce((total, node) => total + verticesPerMesh[node.mesh], 0);
|
|
30
88
|
|
|
31
89
|
const folder = path.dirname(gltfPath);
|
|
32
|
-
const
|
|
90
|
+
const buffers = (gltf.buffers || [])
|
|
33
91
|
.filter((buffer) => buffer.uri && !buffer.uri.startsWith("data:"))
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, 0);
|
|
92
|
+
.map((buffer) => measureBuffer(folder, buffer));
|
|
93
|
+
const bufferDiskBytes = buffers.reduce((total, buffer) => total + buffer.diskBytes, 0);
|
|
94
|
+
const bufferUncompressedBytes = buffers.reduce((total, buffer) => total + buffer.uncompressedBytes, 0);
|
|
38
95
|
|
|
39
96
|
return {
|
|
40
97
|
file: path.basename(gltfPath),
|
|
98
|
+
gzipped: isGzipFile(gltfPath),
|
|
41
99
|
nodes: nodes.length,
|
|
42
100
|
drawnMeshNodes: drawnNodes.length,
|
|
43
101
|
meshes: meshes.length,
|
|
@@ -45,13 +103,16 @@ function measure(gltfPath) {
|
|
|
45
103
|
materials: (gltf.materials || []).length,
|
|
46
104
|
textures: (gltf.textures || []).length,
|
|
47
105
|
drawnVertices,
|
|
48
|
-
sizeMegabytes:
|
|
106
|
+
sizeMegabytes: toMegabytes(fs.statSync(gltfPath).size + bufferDiskBytes),
|
|
107
|
+
binMegabytesOnDisk: toMegabytes(bufferDiskBytes),
|
|
108
|
+
binMegabytesUncompressed: toMegabytes(bufferUncompressedBytes),
|
|
109
|
+
buffers,
|
|
49
110
|
};
|
|
50
111
|
}
|
|
51
112
|
|
|
52
113
|
const files = process.argv.slice(2);
|
|
53
114
|
if (files.length === 0) {
|
|
54
|
-
process.stderr.write("Usage: node gltf-stats.mjs <scene.gltf> [more
|
|
115
|
+
process.stderr.write("Usage: node gltf-stats.mjs <scene.gltf | scene.gz.gltf> [more ...]\n");
|
|
55
116
|
process.exit(1);
|
|
56
117
|
}
|
|
57
118
|
process.stdout.write(JSON.stringify(files.map(measure), null, 2) + "\n");
|
|
@@ -9,6 +9,11 @@
|
|
|
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`)
|
|
13
|
+
* [--hold 40:24,60:44 | --hold true] (with --pin / --poses: holds the scene's Timeline still at each pin — pin seconds :
|
|
14
|
+
* director seconds, or `true` for wherever the director is when the pin lands; a pose file's `heldTimeline` is used
|
|
15
|
+
* for any pin the list does not name. Each pin records `heldTimeline` (null when the scene has no director) and
|
|
16
|
+
* fails when the director strays more than HOLD_TOLERANCE_SECONDS during the measure window.)
|
|
12
17
|
*/
|
|
13
18
|
import fs from "node:fs";
|
|
14
19
|
import os from "node:os";
|
|
@@ -24,6 +29,9 @@ const DEFAULT_WINDOW_SECONDS = 3;
|
|
|
24
29
|
/** How long to wait for the scene to finish loading, in milliseconds. */
|
|
25
30
|
const READY_TIMEOUT_MS = 600000;
|
|
26
31
|
|
|
32
|
+
/** How far a held Timeline may stray during a pin's measure window before that pin fails, in seconds. */
|
|
33
|
+
const HOLD_TOLERANCE_SECONDS = 0.05;
|
|
34
|
+
|
|
27
35
|
/**
|
|
28
36
|
* Reads `--name value` pairs from the command line.
|
|
29
37
|
* @param {string[]} argv - process.argv.slice(2)
|
|
@@ -255,6 +263,40 @@ function installProbe() {
|
|
|
255
263
|
return pose;
|
|
256
264
|
};
|
|
257
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Holds the scene's Timeline still: pauses its PlayableDirector, moves it to the given time and poses every track
|
|
268
|
+
* there, so the sun's angle, the active light and the shot on screen stop changing while a pin is measured.
|
|
269
|
+
* @param {number|null} timelineSeconds - director time to hold, in seconds; null holds the director's current time
|
|
270
|
+
* @returns {number|null} the held director time in seconds, or null (and nothing done) when the scene has no director
|
|
271
|
+
*/
|
|
272
|
+
state.holdTimeline = (timelineSeconds) => {
|
|
273
|
+
const director = state.director();
|
|
274
|
+
if (!director) return null;
|
|
275
|
+
director.pause();
|
|
276
|
+
if (timelineSeconds != null) director.time = timelineSeconds;
|
|
277
|
+
director.evaluate();
|
|
278
|
+
return director.time;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The scene's Timeline director, when it has one.
|
|
283
|
+
* @returns {object|null} the toolkit PlayableDirector, or null when the scene has none (or the runtime has no Timeline)
|
|
284
|
+
*/
|
|
285
|
+
state.director = () => {
|
|
286
|
+
const directorClass = window.TOOLKIT && TOOLKIT.PlayableDirector;
|
|
287
|
+
if (!directorClass || typeof directorClass.Find !== "function") return null;
|
|
288
|
+
return directorClass.Find(state.scene()) || null;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* The director's current time, to prove a held Timeline did not move.
|
|
293
|
+
* @returns {number|null} seconds, or null when the scene has no director
|
|
294
|
+
*/
|
|
295
|
+
state.directorTime = () => {
|
|
296
|
+
const director = state.director();
|
|
297
|
+
return director ? director.time : null;
|
|
298
|
+
};
|
|
299
|
+
|
|
258
300
|
/**
|
|
259
301
|
* Splits each frame's draw calls by pass, read from the engine's running draw counter: shadow maps, other render
|
|
260
302
|
* targets before the main pass (geometry / velocity buffers for motion blur, TAA, SSAO; realtime probes), the main
|
|
@@ -725,6 +767,53 @@ function installProbe() {
|
|
|
725
767
|
};
|
|
726
768
|
};
|
|
727
769
|
|
|
770
|
+
/**
|
|
771
|
+
* Records, over the next rendered frame, which meshes every shadow generator draws and in which cascade, by wrapping
|
|
772
|
+
* each generator's per-sub-mesh shadow render. Shadow maps are often the largest pass once repeats instance, and a
|
|
773
|
+
* caster whose shadow lands on nothing the camera sees (roads, flat ground, water, far backdrops) is pure cost — this
|
|
774
|
+
* names them, with their draws per cascade, so they can be pruned and proven by capture.
|
|
775
|
+
* @returns {Promise<{lights: {light: string, cascades: number, draws: number, casters: {mesh: string, owner: string, perCascade: number[], draws: number}[]}[]}>}
|
|
776
|
+
*/
|
|
777
|
+
state.shadowCasters = () => new Promise((resolve, reject) => {
|
|
778
|
+
const scene = state.scene();
|
|
779
|
+
const generators = scene.lights
|
|
780
|
+
.map((light) => ({ light, generator: light.getShadowGenerator && light.getShadowGenerator() }))
|
|
781
|
+
.filter((entry) => entry.generator && typeof entry.generator._renderSubMeshForShadowMap === "function");
|
|
782
|
+
const records = generators.map(({ light, generator }) => ({ light: light.name, generator, cascades: generator.numCascades || 1, casters: new Map() }));
|
|
783
|
+
let recording = false;
|
|
784
|
+
const originals = records.map((record) => {
|
|
785
|
+
const original = record.generator._renderSubMeshForShadowMap;
|
|
786
|
+
record.generator._renderSubMeshForShadowMap = function (subMesh, ...rest) {
|
|
787
|
+
if (recording) {
|
|
788
|
+
const mesh = subMesh.getMesh();
|
|
789
|
+
if (!record.casters.has(mesh)) record.casters.set(mesh, new Array(record.cascades).fill(0));
|
|
790
|
+
const cascade = Math.min(record.cascades - 1, Math.max(0, record.generator._currentLayer || 0));
|
|
791
|
+
record.casters.get(mesh)[cascade]++;
|
|
792
|
+
}
|
|
793
|
+
return original.call(this, subMesh, ...rest);
|
|
794
|
+
};
|
|
795
|
+
return original;
|
|
796
|
+
});
|
|
797
|
+
const restore = () => records.forEach((record, index) => { record.generator._renderSubMeshForShadowMap = originals[index]; });
|
|
798
|
+
const timeout = setTimeout(() => { restore(); reject(new Error(`shadowCasters: no frame rendered within ${DRAW_OWNER_FRAME_TIMEOUT_MS} ms`)); }, DRAW_OWNER_FRAME_TIMEOUT_MS);
|
|
799
|
+
scene.onBeforeRenderObservable.addOnce(() => {
|
|
800
|
+
recording = true;
|
|
801
|
+
scene.onAfterRenderObservable.addOnce(() => {
|
|
802
|
+
recording = false;
|
|
803
|
+
clearTimeout(timeout);
|
|
804
|
+
restore();
|
|
805
|
+
resolve({
|
|
806
|
+
lights: records.map((record) => {
|
|
807
|
+
const casters = [...record.casters.entries()].map(([mesh, perCascade]) => ({
|
|
808
|
+
mesh: mesh.name, owner: state.ownerOf(mesh), perCascade, draws: perCascade.reduce((sum, count) => sum + count, 0),
|
|
809
|
+
})).sort((first, second) => second.draws - first.draws);
|
|
810
|
+
return { light: record.light, cascades: record.cascades, draws: casters.reduce((sum, caster) => sum + caster.draws, 0), casters };
|
|
811
|
+
}),
|
|
812
|
+
});
|
|
813
|
+
});
|
|
814
|
+
});
|
|
815
|
+
});
|
|
816
|
+
|
|
728
817
|
/**
|
|
729
818
|
* Switches one runtime cost off (on = false) or back on (on = true).
|
|
730
819
|
* Keys: dpr, taa, motionblur, bloom, post (every camera post-process), shadows, lights (every point / spot light).
|
|
@@ -828,6 +917,63 @@ async function cpuProfile(page, seconds) {
|
|
|
828
917
|
return { totalMs: Math.round(totalMs), top };
|
|
829
918
|
}
|
|
830
919
|
|
|
920
|
+
/**
|
|
921
|
+
* Reads `--hold` into a per-pin plan. `--hold true` holds every pin where the director is when the pin lands;
|
|
922
|
+
* `--hold 40:24,60:44` holds the named pins at those director seconds; a pose file's `heldTimeline` fills any pin the
|
|
923
|
+
* flag does not name (so replaying a held run's output holds the same moments). `--hold false` turns holding off.
|
|
924
|
+
* @param {string|undefined} holdFlag - the raw `--hold` value
|
|
925
|
+
* @param {{atSeconds: number, heldTimeline?: number|null}[]|null} poses - the `--poses` entries, when given
|
|
926
|
+
* @returns {{timeFor: (pinSeconds: number) => {hold: boolean, timelineSeconds: number|null}}} the plan
|
|
927
|
+
* @throws {Error} when a `--hold` entry is not `pin:seconds`
|
|
928
|
+
*/
|
|
929
|
+
function parseHoldPlan(holdFlag, poses) {
|
|
930
|
+
const holdAll = holdFlag === "true";
|
|
931
|
+
const holdOff = holdFlag === "false";
|
|
932
|
+
const explicitTimes = new Map();
|
|
933
|
+
if (holdFlag && !holdAll && !holdOff) {
|
|
934
|
+
for (const entry of holdFlag.split(",").filter(Boolean)) {
|
|
935
|
+
const [pinSeconds, timelineSeconds] = entry.split(":").map(Number);
|
|
936
|
+
if (!Number.isFinite(pinSeconds) || !Number.isFinite(timelineSeconds)) throw new Error(`--hold entry "${entry}" is not pin:seconds (e.g. --hold 40:24,60:44)`);
|
|
937
|
+
explicitTimes.set(pinSeconds, timelineSeconds);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
const poseFileTimes = new Map((poses || []).filter((entry) => entry.heldTimeline != null).map((entry) => [entry.atSeconds, entry.heldTimeline]));
|
|
941
|
+
return {
|
|
942
|
+
timeFor(pinSeconds) {
|
|
943
|
+
if (holdOff) return { hold: false, timelineSeconds: null };
|
|
944
|
+
if (explicitTimes.has(pinSeconds)) return { hold: true, timelineSeconds: explicitTimes.get(pinSeconds) };
|
|
945
|
+
if (poseFileTimes.has(pinSeconds)) return { hold: true, timelineSeconds: poseFileTimes.get(pinSeconds) };
|
|
946
|
+
return { hold: holdAll, timelineSeconds: null };
|
|
947
|
+
},
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Holds the page's Timeline at a time (or where it is, for null).
|
|
953
|
+
* @param {object} page - the puppeteer page
|
|
954
|
+
* @param {number|null} timelineSeconds - director seconds to hold, or null for the current time
|
|
955
|
+
* @returns {Promise<number|null>} the held time, or null when the scene has no director
|
|
956
|
+
*/
|
|
957
|
+
async function holdTimeline(page, timelineSeconds) {
|
|
958
|
+
const held = await page.evaluate((seconds) => window.__btProfile.holdTimeline(seconds), timelineSeconds);
|
|
959
|
+
return held == null ? null : +held.toFixed(4);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* Re-reads the director after a measure window and refuses the window when the held Timeline moved, mirroring the
|
|
964
|
+
* look tests' held shots: a moved Timeline means the sun, the light or the shot changed while the frame was measured.
|
|
965
|
+
* @param {object} page - the puppeteer page
|
|
966
|
+
* @param {number|null} heldTimeline - the held time, or null when the scene has no director
|
|
967
|
+
* @returns {Promise<{timeAfterWindow: number|null, driftSeconds: number, error?: string}>} the check
|
|
968
|
+
*/
|
|
969
|
+
async function checkHold(page, heldTimeline) {
|
|
970
|
+
const timeAfterWindow = await page.evaluate(() => window.__btProfile.directorTime());
|
|
971
|
+
if (heldTimeline == null || timeAfterWindow == null) return { timeAfterWindow, driftSeconds: 0 };
|
|
972
|
+
const driftSeconds = +Math.abs(timeAfterWindow - heldTimeline).toFixed(4);
|
|
973
|
+
if (driftSeconds <= HOLD_TOLERANCE_SECONDS) return { timeAfterWindow, driftSeconds };
|
|
974
|
+
return { timeAfterWindow, driftSeconds, error: `Timeline drifted: held ${heldTimeline} s, ${timeAfterWindow} s after the window` };
|
|
975
|
+
}
|
|
976
|
+
|
|
831
977
|
/** Records one measurement window on the page. */
|
|
832
978
|
async function measure(page, windowSeconds) {
|
|
833
979
|
await page.evaluate(() => window.__btProfile.start());
|
|
@@ -847,8 +993,10 @@ async function main() {
|
|
|
847
993
|
const scene = flags.scene;
|
|
848
994
|
if (!scene) throw new Error("Pass --scene <exported scene file>, e.g. --scene level.gltf");
|
|
849
995
|
const times = (flags.times || DEFAULT_TIMES).split(",").map(Number).sort((first, second) => first - second);
|
|
850
|
-
const poses = flags.poses ? JSON.parse(fs.readFileSync(path.resolve(flags.poses), "utf8")).pins.map((pin) => ({ atSeconds: pin.atSeconds, pose: pin.pinned })) : null;
|
|
996
|
+
const poses = flags.poses ? JSON.parse(fs.readFileSync(path.resolve(flags.poses), "utf8")).pins.map((pin) => ({ atSeconds: pin.atSeconds, pose: pin.pinned, heldTimeline: pin.heldTimeline })) : null;
|
|
851
997
|
const pins = poses ? poses.map((entry) => entry.atSeconds) : (flags.pin || "").split(",").filter(Boolean).map(Number);
|
|
998
|
+
const holdPlan = parseHoldPlan(flags.hold, poses);
|
|
999
|
+
let failedPins = 0;
|
|
852
1000
|
const toggles = (flags.toggles || "dpr,taa,motionblur,bloom,post,shadows,lights").split(",").filter((key) => key && key !== "none");
|
|
853
1001
|
const windowSeconds = Number(flags.window || DEFAULT_WINDOW_SECONDS);
|
|
854
1002
|
const settleSeconds = Number(flags.settle || 4);
|
|
@@ -890,11 +1038,20 @@ async function main() {
|
|
|
890
1038
|
await sleep(seconds);
|
|
891
1039
|
// With --poses, the camera goes to the exact pose an earlier run pinned, so two exports are measured from one view.
|
|
892
1040
|
const pinned = poses ? await page.evaluate((pose) => window.__btProfile.pose(pose), poses[index].pose) : await page.evaluate(() => window.__btProfile.pin());
|
|
1041
|
+
const holdRequest = holdPlan.timeFor(seconds);
|
|
1042
|
+
let heldTimeline = holdRequest.hold ? await holdTimeline(page, holdRequest.timelineSeconds) : undefined;
|
|
893
1043
|
await settle(page, settleSeconds);
|
|
1044
|
+
// Settling waits on whenReadyAsync, which can let a director resume, so the hold is applied again.
|
|
1045
|
+
if (holdRequest.hold) heldTimeline = await holdTimeline(page, heldTimeline);
|
|
894
1046
|
if (shots) await page.screenshot({ path: path.join(shots, `${tag}_pin${seconds}s.png`) });
|
|
895
1047
|
const poseBefore = await page.evaluate(() => window.__btProfile.actualPose());
|
|
896
1048
|
const baseline = await measure(page, windowSeconds);
|
|
897
1049
|
const poseAfter = await page.evaluate(() => window.__btProfile.actualPose());
|
|
1050
|
+
const holdCheck = holdRequest.hold ? await checkHold(page, heldTimeline) : null;
|
|
1051
|
+
if (holdCheck && holdCheck.error) {
|
|
1052
|
+
failedPins++;
|
|
1053
|
+
process.stderr.write(`FAILED pin ${seconds}s: ${holdCheck.error}\n`);
|
|
1054
|
+
}
|
|
898
1055
|
const target = pinned.position || pinned;
|
|
899
1056
|
const drift = Math.max(...[poseBefore, poseAfter].map((actual) => Math.hypot(actual.position[0] - target[0], actual.position[1] - target[1], actual.position[2] - target[2])));
|
|
900
1057
|
if (drift > 0.05 || (pinned.fov != null && Math.abs(poseAfter.fov - pinned.fov) > 1e-3) || poseBefore.camera !== poseAfter.camera)
|
|
@@ -903,6 +1060,7 @@ async function main() {
|
|
|
903
1060
|
const lightAudit = await page.evaluate(() => window.__btProfile.lightAudit());
|
|
904
1061
|
// drawOwners is async: it measures the next rendered frame, and page.evaluate waits for that promise.
|
|
905
1062
|
const drawOwners = await page.evaluate(() => window.__btProfile.drawOwners());
|
|
1063
|
+
const shadowCasters = flags.casters === "true" ? await page.evaluate(() => window.__btProfile.shadowCasters()) : null;
|
|
906
1064
|
const steps = [];
|
|
907
1065
|
for (const key of toggles) {
|
|
908
1066
|
const change = await page.evaluate((k) => window.__btProfile.toggle(k, false), key);
|
|
@@ -913,7 +1071,7 @@ async function main() {
|
|
|
913
1071
|
steps.push({ off: key, change, fps: off.fps, p50Ms: off.p50Ms, drawCalls: off.drawCalls, passes: off.passes, cpuRenderMs: off.cpuRenderMs, cpuFrameMs: off.cpuFrameMs });
|
|
914
1072
|
}
|
|
915
1073
|
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 } });
|
|
1074
|
+
report.pins.push({ atSeconds: seconds, readyMs, pinned, heldTimeline, holdCheck, actual: { before: poseBefore, after: poseAfter }, baseline, lightAudit, drawOwners, shadowCasters, cpu, steps, baselineAgain: { fps: after.fps, p50Ms: after.p50Ms } });
|
|
917
1075
|
await page.close();
|
|
918
1076
|
}
|
|
919
1077
|
}
|
|
@@ -921,6 +1079,7 @@ async function main() {
|
|
|
921
1079
|
const text = JSON.stringify(report, null, 2);
|
|
922
1080
|
if (flags.out) fs.writeFileSync(path.resolve(flags.out), text);
|
|
923
1081
|
process.stdout.write(text + "\n");
|
|
1082
|
+
if (failedPins > 0) throw new Error(`${failedPins} pin(s) failed: the held Timeline moved during the measure window`);
|
|
924
1083
|
} finally {
|
|
925
1084
|
await browser.close();
|
|
926
1085
|
}
|
package/skills/bt-plan/SKILL.md
CHANGED
|
@@ -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.
|
package/skills/bt-spec/SKILL.md
CHANGED
|
@@ -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".
|