create-threenative 0.2.5 → 0.2.7

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 (631) hide show
  1. package/README.md +25 -3
  2. package/agent-docs/references/assertion-reference.md +40 -1
  3. package/agent-docs/references/build-profiles.md +126 -0
  4. package/agent-docs/references/capability-reference.md +1382 -65
  5. package/agent-docs/references/finding-assets.md +8 -1
  6. package/agent-docs/references/performance-basics.md +117 -0
  7. package/agent-docs/references/rigging-characters.md +51 -0
  8. package/agent-docs/references/sculpt-from-a-reference.md +1 -1
  9. package/agent-docs/references/trace-a-slow-frame.md +1 -1
  10. package/agent-docs/references/visual-baseline.md +8 -4
  11. package/agent-docs/references/webview-ui.md +3 -2
  12. package/agent-files/.agents/skills/file-engine-bug/SKILL.md +15 -4
  13. package/agent-files/.agents/skills/ponytail/SKILL.md +68 -0
  14. package/agent-files/.agents/skills/threenative-assets/SKILL.md +12 -4
  15. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +1 -1
  16. package/agent-files/.agents/skills/threenative-context/SKILL.md +9 -1
  17. package/agent-files/.agents/skills/threenative-performance/SKILL.md +26 -10
  18. package/agent-files/.agents/skills/threenative-playtest/SKILL.md +1 -1
  19. package/agent-files/.agents/skills/threenative-ui/SKILL.md +1 -1
  20. package/agent-files/.agents/skills/threenative-visuals/SKILL.md +4 -4
  21. package/agent-files/.claude/hooks/ponytail-context.mjs +51 -0
  22. package/agent-files/.claude/settings.json +38 -0
  23. package/agent-files/.codex/hooks.json +40 -0
  24. package/capabilities.json +1891 -101
  25. package/dist/index.d.ts +39 -1
  26. package/dist/index.js +480 -56
  27. package/dist/threenative.js +1247 -177
  28. package/package.json +6 -6
  29. package/template-assets/assets/mannequin-combat.glb +0 -0
  30. package/template-assets/assets/mannequin.glb +0 -0
  31. package/template-assets/assets/player-viewmodel.glb +0 -0
  32. package/template-assets/assets/sky.jpg +0 -0
  33. package/template-assets/clearwater/README.md +141 -0
  34. package/template-assets/clearwater/install.mjs +50 -0
  35. package/template-assets/clearwater/src/clearwater.ts +180 -0
  36. package/template-assets/clearwater/src/clearwaterDemo.ts +28 -0
  37. package/template-assets/clearwater/src/clearwaterLifetime.ts +28 -0
  38. package/{LICENSE → template-assets/clearwater/src/render/CLEARWATER-LICENSE.txt} +4 -1
  39. package/template-assets/clearwater/src/render/clearwater.ts +278 -0
  40. package/template-assets/clearwater/src/render/clearwaterCaustics.ts +138 -0
  41. package/template-assets/clearwater/src/render/clearwaterDemo.ts +65 -0
  42. package/template-assets/clearwater/src/render/clearwaterOptics.ts +33 -0
  43. package/template-assets/clearwater/src/render/clearwaterOptions.ts +177 -0
  44. package/template-assets/clearwater/src/render/clearwaterPass.ts +51 -0
  45. package/template-assets/patches/three@0.185.1.patch +2228 -105
  46. package/template-assets/worldEnvironment.ts +52 -1
  47. package/templates/action-rpg/AGENTS.md +43 -43
  48. package/templates/action-rpg/CLAUDE.md +43 -43
  49. package/templates/action-rpg/kit.json +1 -1
  50. package/templates/action-rpg/package.json +14 -8
  51. package/templates/action-rpg/playtests/combat.playtest.json +162 -23
  52. package/templates/action-rpg/playtests/performance.playtest.json +4 -3
  53. package/templates/action-rpg/playtests/survives.playtest.json +25 -8
  54. package/templates/action-rpg/src/conventions.ts +24 -18
  55. package/templates/action-rpg/src/entities/Enemy.ts +74 -24
  56. package/templates/action-rpg/src/entities/Fighter.ts +127 -0
  57. package/templates/action-rpg/src/entities/Player.ts +102 -32
  58. package/templates/action-rpg/src/game.ts +3 -3
  59. package/templates/action-rpg/src/render/camera.ts +18 -16
  60. package/templates/action-rpg/src/render/dungeon.ts +192 -0
  61. package/templates/action-rpg/src/render/lighting.ts +45 -28
  62. package/templates/action-rpg/src/render/loading.ts +4 -4
  63. package/templates/action-rpg/src/render/materials.ts +191 -47
  64. package/templates/action-rpg/src/render/palette.ts +14 -13
  65. package/templates/action-rpg/src/render/postprocessing.ts +12 -2
  66. package/templates/action-rpg/src/render/props.ts +117 -0
  67. package/templates/action-rpg/src/render/quality.ts +40 -82
  68. package/templates/action-rpg/src/render/sky.ts +36 -13
  69. package/templates/action-rpg/src/render/touch-controls.ts +1 -1
  70. package/templates/action-rpg/src/render/worldEnvironment.ts +52 -1
  71. package/templates/action-rpg/src/scenes/Play.ts +61 -39
  72. package/templates/action-rpg/src/style.css +9 -7
  73. package/templates/action-rpg/src/ui/AbilityBar.tsx +3 -1
  74. package/templates/action-rpg/src/ui/Hud.tsx +3 -3
  75. package/templates/action-rpg/threenative.config.ts +14 -1
  76. package/templates/action-rpg/vite.config.ts +4 -1
  77. package/templates/minimal/AGENTS.md +12 -12
  78. package/templates/minimal/CLAUDE.md +12 -12
  79. package/templates/minimal/package.json +13 -7
  80. package/templates/minimal/playtests/play.playtest.json +6 -5
  81. package/templates/minimal/playtests/sky.playtest.json +27 -0
  82. package/templates/minimal/src/conventions.ts +6 -3
  83. package/templates/minimal/src/entities/Player.ts +73 -27
  84. package/templates/minimal/src/main.ts +2 -3
  85. package/templates/minimal/src/render/camera.ts +22 -4
  86. package/templates/minimal/src/render/lighting.ts +24 -48
  87. package/templates/minimal/src/render/materials.ts +158 -13
  88. package/templates/minimal/src/render/palette.ts +10 -7
  89. package/templates/minimal/src/render/postprocessing.ts +12 -25
  90. package/templates/minimal/src/render/quality.ts +35 -69
  91. package/templates/minimal/src/render/sky.ts +35 -54
  92. package/templates/minimal/src/render/touch-controls.ts +1 -1
  93. package/templates/minimal/src/render/worldEnvironment.ts +52 -1
  94. package/templates/minimal/src/scenes/Play.ts +121 -111
  95. package/templates/minimal/src/state.ts +0 -4
  96. package/templates/minimal/src/style.css +0 -10
  97. package/templates/minimal/threenative.config.ts +15 -1
  98. package/templates/minimal/vite.config.ts +4 -1
  99. package/templates/platformer/AGENTS.md +18 -56
  100. package/templates/platformer/CLAUDE.md +18 -56
  101. package/templates/platformer/kit.json +2 -2
  102. package/templates/platformer/package.json +14 -10
  103. package/templates/platformer/playtests/buffer.playtest.json +15 -5
  104. package/templates/platformer/playtests/collect.playtest.json +8 -34
  105. package/templates/platformer/playtests/coyote.playtest.json +12 -34
  106. package/templates/platformer/playtests/damage.playtest.json +40 -15
  107. package/templates/platformer/playtests/hud.playtest.json +34 -0
  108. package/templates/platformer/playtests/move.playtest.json +24 -0
  109. package/templates/platformer/playtests/performance.playtest.json +24 -7
  110. package/templates/platformer/playtests/respawn.playtest.json +46 -11
  111. package/templates/platformer/playtests/stomp.playtest.json +49 -12
  112. package/templates/platformer/playtests/survives.playtest.json +3 -19
  113. package/templates/platformer/playtests/world.playtest.json +26 -0
  114. package/templates/platformer/src/entities/Fox.ts +273 -0
  115. package/templates/platformer/src/entities/Pickup.ts +43 -60
  116. package/templates/platformer/src/entities/Walker.ts +88 -0
  117. package/templates/platformer/src/game.ts +11 -8
  118. package/templates/platformer/src/level/Checkpoints.ts +29 -16
  119. package/templates/platformer/src/level/Stage.ts +469 -0
  120. package/templates/platformer/src/render/blocks.ts +94 -0
  121. package/templates/platformer/src/render/camera.ts +28 -3
  122. package/templates/platformer/src/render/fox.ts +196 -0
  123. package/templates/platformer/src/render/lighting.ts +42 -33
  124. package/templates/platformer/src/render/materials.ts +115 -5
  125. package/templates/platformer/src/render/palette.ts +68 -53
  126. package/templates/platformer/src/render/pickups.ts +142 -0
  127. package/templates/platformer/src/render/postprocessing.ts +12 -2
  128. package/templates/platformer/src/render/props.ts +147 -0
  129. package/templates/platformer/src/render/quality.ts +47 -99
  130. package/templates/platformer/src/render/scenery.ts +172 -0
  131. package/templates/platformer/src/render/sky.ts +120 -31
  132. package/templates/platformer/src/render/touch-controls.ts +5 -2
  133. package/templates/platformer/src/render/walkers.ts +96 -0
  134. package/templates/platformer/src/render/waterfall.ts +85 -0
  135. package/templates/platformer/src/render/worldEnvironment.ts +52 -1
  136. package/templates/platformer/src/scenes/Boot.ts +3 -4
  137. package/templates/platformer/src/scenes/Play.ts +362 -0
  138. package/templates/platformer/src/state.ts +16 -14
  139. package/templates/platformer/src/style.css +9 -8
  140. package/templates/platformer/src/ui/Hud.tsx +62 -29
  141. package/templates/platformer/src/ui/Menu.tsx +2 -2
  142. package/templates/platformer/threenative.config.ts +14 -1
  143. package/templates/platformer/vite.config.ts +4 -1
  144. package/templates/puzzle/AGENTS.md +21 -22
  145. package/templates/puzzle/CLAUDE.md +21 -22
  146. package/templates/puzzle/assets/native-proof.glb +0 -0
  147. package/templates/puzzle/assets/native-proof.png +0 -0
  148. package/templates/puzzle/kit.json +1 -1
  149. package/templates/puzzle/package.json +14 -8
  150. package/templates/puzzle/playtests/axis.playtest.json +20 -0
  151. package/templates/puzzle/playtests/blocked.playtest.json +73 -0
  152. package/templates/puzzle/playtests/caused.playtest.json +65 -0
  153. package/templates/puzzle/playtests/lit.playtest.json +74 -0
  154. package/templates/puzzle/playtests/performance.playtest.json +24 -7
  155. package/templates/{starter/playtests/respawn.playtest.json → puzzle/playtests/push.playtest.json} +24 -19
  156. package/templates/puzzle/playtests/replay.playtest.json +81 -0
  157. package/templates/puzzle/playtests/restart.playtest.json +108 -0
  158. package/templates/puzzle/playtests/seal.playtest.json +98 -0
  159. package/templates/puzzle/playtests/settle.playtest.json +100 -0
  160. package/templates/puzzle/playtests/survives.playtest.json +6 -29
  161. package/templates/{starter/playtests/hot-reload.playtest.json → puzzle/playtests/travel.playtest.json} +6 -5
  162. package/templates/puzzle/src/entities/Crate.ts +99 -42
  163. package/templates/puzzle/src/entities/Seal.ts +69 -0
  164. package/templates/puzzle/src/entities/Warden.ts +135 -0
  165. package/templates/puzzle/src/game.ts +15 -11
  166. package/templates/puzzle/src/render/camera.ts +66 -31
  167. package/templates/puzzle/src/render/crateShape.ts +70 -0
  168. package/templates/puzzle/src/render/lighting.ts +41 -41
  169. package/templates/puzzle/src/render/loading.ts +4 -4
  170. package/templates/puzzle/src/render/materials.ts +131 -27
  171. package/templates/puzzle/src/render/palette.ts +19 -29
  172. package/templates/puzzle/src/render/postprocessing.ts +15 -3
  173. package/templates/puzzle/src/render/quality.ts +71 -80
  174. package/templates/puzzle/src/render/shapes.ts +109 -108
  175. package/templates/puzzle/src/render/sky.ts +18 -10
  176. package/templates/puzzle/src/render/touch-controls.ts +8 -51
  177. package/templates/puzzle/src/render/vault.ts +315 -0
  178. package/templates/puzzle/src/render/warden.ts +46 -0
  179. package/templates/puzzle/src/render/worldEnvironment.ts +52 -1
  180. package/templates/puzzle/src/scenes/Play.ts +793 -0
  181. package/templates/puzzle/src/state.ts +55 -24
  182. package/templates/puzzle/src/style.css +7 -8
  183. package/templates/puzzle/src/ui/App.tsx +2 -2
  184. package/templates/puzzle/src/ui/Hud.tsx +92 -40
  185. package/templates/puzzle/src/ui/Menu.tsx +40 -2
  186. package/templates/puzzle/threenative.config.ts +14 -1
  187. package/templates/puzzle/vite.config.ts +4 -1
  188. package/templates/racing/AGENTS.md +20 -21
  189. package/templates/racing/CLAUDE.md +20 -21
  190. package/templates/racing/package.json +14 -8
  191. package/templates/racing/playtests/boost.playtest.json +33 -12
  192. package/templates/racing/playtests/outcome.playtest.json +32 -50
  193. package/templates/racing/playtests/performance.playtest.json +2 -1
  194. package/templates/racing/playtests/ranking.playtest.json +5 -14
  195. package/templates/racing/playtests/rescue.playtest.json +2 -2
  196. package/templates/racing/playtests/reverse.playtest.json +30 -8
  197. package/templates/racing/playtests/shortcut.playtest.json +54 -9
  198. package/templates/racing/playtests/touch-controls.playtest.json +32 -5
  199. package/templates/racing/src/entities/CarBody.ts +327 -0
  200. package/templates/racing/src/entities/LineDriver.ts +220 -0
  201. package/templates/racing/src/entities/RacingCar.ts +150 -89
  202. package/templates/racing/src/entities/Rival.ts +61 -24
  203. package/templates/racing/src/game.ts +5 -0
  204. package/templates/racing/src/render/camera.ts +49 -7
  205. package/templates/racing/src/render/lighting.ts +36 -37
  206. package/templates/racing/src/render/materials.ts +239 -19
  207. package/templates/racing/src/render/palette.ts +19 -21
  208. package/templates/racing/src/render/postprocessing.ts +12 -2
  209. package/templates/racing/src/render/quality.ts +43 -82
  210. package/templates/racing/src/render/shapes.ts +20 -6
  211. package/templates/racing/src/render/sky.ts +47 -39
  212. package/templates/racing/src/render/touch-controls.ts +1 -1
  213. package/templates/racing/src/render/worldEnvironment.ts +52 -1
  214. package/templates/racing/src/scenes/Race.ts +107 -54
  215. package/templates/racing/src/state.ts +2 -0
  216. package/templates/racing/src/track/Checkline.ts +22 -7
  217. package/templates/racing/src/track/Lap.ts +64 -36
  218. package/templates/racing/src/track/Ranking.ts +20 -11
  219. package/templates/racing/src/track/Track.ts +809 -361
  220. package/templates/racing/src/track/TrackSector.ts +40 -11
  221. package/templates/racing/src/track/circuit.ts +477 -0
  222. package/templates/racing/src/track/rescue.ts +16 -4
  223. package/templates/racing/threenative.config.ts +14 -1
  224. package/templates/racing/vite.config.ts +4 -1
  225. package/templates/rts/AGENTS.md +96 -0
  226. package/templates/rts/CLAUDE.md +98 -0
  227. package/templates/rts/kit.json +7 -0
  228. package/templates/{defense → rts}/package.json +14 -8
  229. package/templates/{defense → rts}/playtests/performance.playtest.json +28 -26
  230. package/templates/rts/playtests/rts-ai-attack.playtest.json +24 -0
  231. package/templates/rts/playtests/rts-attack.playtest.json +75 -0
  232. package/templates/rts/playtests/rts-build.playtest.json +68 -0
  233. package/templates/rts/playtests/rts-orders.playtest.json +150 -0
  234. package/templates/rts/playtests/rts-train.playtest.json +62 -0
  235. package/templates/rts/playtests/survives.playtest.json +58 -0
  236. package/templates/rts/public/favicon.svg +4 -0
  237. package/templates/rts/src/game.ts +64 -0
  238. package/templates/rts/src/orders.ts +22 -0
  239. package/templates/rts/src/render/army.ts +346 -0
  240. package/templates/rts/src/render/camera.ts +123 -0
  241. package/templates/rts/src/render/lighting.ts +61 -0
  242. package/templates/rts/src/render/loading.ts +33 -0
  243. package/templates/rts/src/render/materials.ts +152 -0
  244. package/templates/rts/src/render/models.ts +705 -0
  245. package/templates/rts/src/render/palette.ts +17 -0
  246. package/templates/rts/src/render/picking.ts +93 -0
  247. package/templates/{defense → rts}/src/render/postprocessing.ts +15 -3
  248. package/templates/rts/src/render/quality.ts +128 -0
  249. package/templates/rts/src/render/resources.ts +141 -0
  250. package/templates/rts/src/render/sky.ts +44 -0
  251. package/templates/rts/src/render/terrain.ts +116 -0
  252. package/templates/{defense → rts}/src/render/worldEnvironment.ts +52 -1
  253. package/templates/rts/src/scenes/Play.ts +650 -0
  254. package/templates/rts/src/sim/ai.ts +1140 -0
  255. package/templates/rts/src/sim/combat.ts +416 -0
  256. package/templates/rts/src/sim/construction.ts +374 -0
  257. package/templates/rts/src/sim/economy.ts +167 -0
  258. package/templates/rts/src/sim/game.ts +1082 -0
  259. package/templates/rts/src/sim/movement.ts +371 -0
  260. package/templates/rts/src/sim/nav.ts +276 -0
  261. package/templates/rts/src/sim/production.ts +180 -0
  262. package/templates/rts/src/sim/terrain.ts +170 -0
  263. package/templates/rts/src/sim/types.ts +647 -0
  264. package/templates/rts/src/sim/vision.ts +46 -0
  265. package/templates/rts/src/state.ts +100 -0
  266. package/templates/{defense → rts}/src/style.css +21 -8
  267. package/templates/rts/src/ui/App.tsx +21 -0
  268. package/templates/rts/src/ui/Commands.tsx +129 -0
  269. package/templates/rts/src/ui/GameUi.tsx +22 -0
  270. package/templates/rts/src/ui/Hud.tsx +165 -0
  271. package/templates/rts/src/ui/Minimap.tsx +84 -0
  272. package/templates/rts/tailwind.config.ts +2 -0
  273. package/templates/rts/threenative.config.ts +56 -0
  274. package/templates/rts/tsconfig.json +17 -0
  275. package/templates/{defense → rts}/vite.config.ts +4 -1
  276. package/templates/runner/AGENTS.md +8 -12
  277. package/templates/runner/CLAUDE.md +8 -12
  278. package/templates/runner/README.md +3 -3
  279. package/templates/runner/package.json +14 -8
  280. package/templates/runner/playtests/performance.playtest.json +2 -2
  281. package/templates/runner/src/conventions.ts +4 -3
  282. package/templates/runner/src/entities/Runner.ts +54 -7
  283. package/templates/runner/src/game.ts +2 -0
  284. package/templates/runner/src/render/camera.ts +4 -2
  285. package/templates/runner/src/render/dust.ts +5 -2
  286. package/templates/runner/src/render/lighting.ts +41 -45
  287. package/templates/runner/src/render/loading.ts +2 -2
  288. package/templates/runner/src/render/materials.ts +165 -25
  289. package/templates/runner/src/render/palette.ts +17 -28
  290. package/templates/runner/src/render/postprocessing.ts +12 -2
  291. package/templates/runner/src/render/quality.ts +42 -96
  292. package/templates/runner/src/render/shapes.ts +59 -37
  293. package/templates/runner/src/render/sky.ts +32 -41
  294. package/templates/runner/src/render/touch-controls.ts +1 -1
  295. package/templates/runner/src/render/worldEnvironment.ts +52 -1
  296. package/templates/runner/src/scenes/Run.ts +26 -6
  297. package/templates/runner/src/track.ts +6 -1
  298. package/templates/runner/threenative.config.ts +14 -1
  299. package/templates/runner/vite.config.ts +4 -1
  300. package/templates/sailing/AGENTS.md +14 -14
  301. package/templates/sailing/CLAUDE.md +14 -14
  302. package/templates/sailing/assets/ship.glb +0 -0
  303. package/templates/sailing/package.json +14 -8
  304. package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +10 -6
  305. package/templates/sailing/playtests/sails.playtest.json +33 -0
  306. package/templates/sailing/playtests/win.playtest.json +156 -8
  307. package/templates/sailing/src/conventions.ts +29 -2
  308. package/templates/sailing/src/entities/Ship.ts +381 -57
  309. package/templates/sailing/src/game.ts +14 -0
  310. package/templates/sailing/src/render/camera.ts +63 -9
  311. package/templates/sailing/src/render/lighting.ts +49 -27
  312. package/templates/sailing/src/render/materials.ts +50 -15
  313. package/templates/sailing/src/render/ocean.ts +647 -60
  314. package/templates/sailing/src/render/palette.ts +16 -12
  315. package/templates/sailing/src/render/postprocessing.ts +12 -2
  316. package/templates/sailing/src/render/props.ts +316 -442
  317. package/templates/sailing/src/render/quality.ts +14 -4
  318. package/templates/sailing/src/render/sky.ts +116 -23
  319. package/templates/sailing/src/render/worldEnvironment.ts +52 -1
  320. package/templates/sailing/src/scenes/Boot.ts +21 -0
  321. package/templates/sailing/src/scenes/Sailing.ts +173 -39
  322. package/templates/sailing/src/state.ts +6 -0
  323. package/templates/sailing/src/ui/Hud.tsx +41 -9
  324. package/templates/sailing/threenative.config.ts +14 -1
  325. package/templates/sailing/vite.config.ts +4 -1
  326. package/templates/shooter/AGENTS.md +29 -44
  327. package/templates/shooter/CLAUDE.md +29 -44
  328. package/templates/shooter/index.html +1 -0
  329. package/templates/shooter/package.json +14 -8
  330. package/templates/shooter/playtests/aim-alignment.playtest.json +58 -0
  331. package/templates/shooter/playtests/breakable-shatters.playtest.json +62 -0
  332. package/templates/shooter/playtests/bullet-holes.playtest.json +56 -0
  333. package/templates/shooter/playtests/camera-tracks-body-vertically.playtest.json +61 -0
  334. package/templates/shooter/playtests/crouch-lowers-the-eye.playtest.json +41 -0
  335. package/templates/shooter/playtests/death-no-snap.playtest.json +77 -0
  336. package/templates/shooter/playtests/debug-ads.playtest.json +58 -0
  337. package/templates/shooter/playtests/debug-clear.playtest.json +383 -0
  338. package/templates/shooter/playtests/debug-endurance.playtest.json +61 -0
  339. package/templates/shooter/playtests/debug-fire.playtest.json +119 -0
  340. package/templates/shooter/playtests/debug-restart.playtest.json +24 -0
  341. package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +79 -0
  342. package/templates/shooter/playtests/enemy-death-settles.playtest.json +64 -0
  343. package/templates/shooter/playtests/enemy-flinches-when-hit.playtest.json +75 -0
  344. package/templates/shooter/playtests/enemy-foot-contact.playtest.json +41 -0
  345. package/templates/shooter/playtests/enemy-material-is-not-shared.playtest.json +59 -0
  346. package/templates/shooter/playtests/enemy-reaches-walkway.playtest.json +80 -0
  347. package/templates/shooter/playtests/enemy-rifle-grip.playtest.json +101 -0
  348. package/templates/shooter/playtests/enemy-scale.playtest.json +56 -0
  349. package/templates/shooter/playtests/enemy-stops-without-snapping.playtest.json +486 -0
  350. package/templates/shooter/playtests/enemy-stride-matches-speed.playtest.json +198 -0
  351. package/templates/shooter/playtests/enemy-stride-under-crouch.playtest.json +87 -0
  352. package/templates/shooter/playtests/enemy-uses-crouch-clips.playtest.json +74 -0
  353. package/templates/shooter/playtests/five-soldiers.playtest.json +83 -0
  354. package/templates/shooter/playtests/flash-retires.playtest.json +62 -0
  355. package/templates/shooter/playtests/headshot-hits-head.playtest.json +132 -0
  356. package/templates/shooter/playtests/hold-to-fire.playtest.json +45 -0
  357. package/templates/shooter/playtests/input-control.playtest.json +43 -98
  358. package/templates/shooter/playtests/minimap-state.playtest.json +75 -0
  359. package/templates/shooter/playtests/performance.playtest.json +62 -26
  360. package/templates/{starter/playtests/forward.playtest.json → shooter/playtests/round-clock.playtest.json} +11 -16
  361. package/templates/shooter/playtests/shot-tracks-crosshair.playtest.json +79 -0
  362. package/templates/shooter/playtests/survives.playtest.json +36 -30
  363. package/templates/shooter/playtests/walkway-reachable.playtest.json +67 -0
  364. package/templates/shooter/src/entities/Breakables.ts +412 -0
  365. package/templates/shooter/src/entities/Enemy.ts +2095 -0
  366. package/templates/shooter/src/entities/FpsPlayer.ts +283 -0
  367. package/templates/shooter/src/entities/Rifle.ts +442 -0
  368. package/templates/shooter/src/entities/Target.ts +199 -83
  369. package/templates/shooter/src/entities/TouchControls.ts +276 -0
  370. package/templates/shooter/src/game.ts +75 -41
  371. package/templates/shooter/src/main.ts +0 -1
  372. package/templates/shooter/src/postPhysics.ts +36 -0
  373. package/templates/shooter/src/render/camera.ts +78 -74
  374. package/templates/shooter/src/render/decals.ts +142 -82
  375. package/templates/shooter/src/render/facade.ts +1373 -0
  376. package/templates/shooter/src/render/gunfx.ts +704 -0
  377. package/templates/shooter/src/render/lighting.ts +52 -38
  378. package/templates/shooter/src/render/loading.ts +2 -2
  379. package/templates/shooter/src/render/materials.ts +100 -88
  380. package/templates/shooter/src/render/occlusion.ts +108 -0
  381. package/templates/shooter/src/render/palette.ts +10 -10
  382. package/templates/shooter/src/render/palm.ts +455 -0
  383. package/templates/shooter/src/render/pooled-billboards.ts +144 -0
  384. package/templates/shooter/src/render/postprocessing.ts +15 -3
  385. package/templates/shooter/src/render/quality.ts +40 -82
  386. package/templates/shooter/src/render/scale.ts +148 -15
  387. package/templates/shooter/src/render/shapes.ts +138 -613
  388. package/templates/shooter/src/render/sky.ts +35 -35
  389. package/templates/shooter/src/render/town-schematic.ts +120 -0
  390. package/templates/shooter/src/render/town.ts +986 -0
  391. package/templates/shooter/src/render/townMaterials.ts +160 -0
  392. package/templates/shooter/src/render/vehicles.ts +741 -0
  393. package/templates/shooter/src/render/worldEnvironment.ts +52 -1
  394. package/templates/shooter/src/scenes/Play.ts +727 -650
  395. package/templates/shooter/src/state.ts +26 -41
  396. package/templates/shooter/src/style.css +207 -11
  397. package/templates/shooter/src/surfaces.ts +131 -0
  398. package/templates/shooter/src/ui/App.tsx +9 -10
  399. package/templates/shooter/src/ui/Crosshair.tsx +25 -18
  400. package/templates/shooter/src/ui/GameUi.tsx +6 -9
  401. package/templates/shooter/src/ui/Hud.tsx +428 -39
  402. package/templates/shooter/src/ui/Minimap.tsx +164 -0
  403. package/templates/shooter/src/ui/TouchOverlay.tsx +54 -0
  404. package/templates/shooter/src/ui/main.tsx +2 -3
  405. package/templates/shooter/threenative.config.ts +14 -1
  406. package/templates/shooter/vite.config.ts +4 -1
  407. package/templates/starter/AGENTS.md +20 -20
  408. package/templates/starter/CLAUDE.md +20 -20
  409. package/templates/starter/native-playtests/render-chain.playtest.json +13 -45
  410. package/templates/starter/package.json +15 -9
  411. package/templates/starter/playtests/play.playtest.json +2 -1
  412. package/templates/starter/playtests/{restart.playtest.json → production-readiness.playtest.json} +17 -12
  413. package/templates/starter/playtests/survives.playtest.json +1 -1
  414. package/templates/starter/src/conventions.ts +6 -3
  415. package/templates/starter/src/entities/Goal.ts +35 -42
  416. package/templates/starter/src/entities/Player.ts +99 -16
  417. package/templates/starter/src/render/arena.ts +131 -0
  418. package/templates/starter/src/render/lighting.ts +27 -44
  419. package/templates/starter/src/render/materials.ts +164 -35
  420. package/templates/starter/src/render/palette.ts +16 -16
  421. package/templates/starter/src/render/postprocessing.ts +6 -7
  422. package/templates/starter/src/render/quality.ts +43 -101
  423. package/templates/starter/src/render/shapes.ts +1 -1
  424. package/templates/starter/src/render/sky.ts +39 -45
  425. package/templates/starter/src/render/touch-controls.ts +3 -1
  426. package/templates/starter/src/render/worldEnvironment.ts +52 -1
  427. package/templates/starter/src/scenes/Play.ts +82 -81
  428. package/templates/starter/src/ui/Hud.tsx +2 -2
  429. package/templates/starter/src/ui/Menu.tsx +5 -1
  430. package/templates/starter/threenative.config.ts +14 -1
  431. package/templates/starter/vite.config.ts +4 -1
  432. package/templates/tower-defense/.codex/config.toml +19 -0
  433. package/templates/tower-defense/.cursor/mcp.json +32 -0
  434. package/templates/tower-defense/.gemini/settings.json +32 -0
  435. package/templates/tower-defense/.mcp.json +32 -0
  436. package/templates/tower-defense/.vscode/mcp.json +36 -0
  437. package/templates/tower-defense/.zed/settings.json +36 -0
  438. package/templates/{defense → tower-defense}/AGENTS.md +16 -14
  439. package/templates/{defense → tower-defense}/CLAUDE.md +16 -14
  440. package/templates/tower-defense/README.md +16 -0
  441. package/templates/tower-defense/index.html +12 -0
  442. package/templates/tower-defense/kit.json +7 -0
  443. package/templates/tower-defense/opencode.json +41 -0
  444. package/templates/tower-defense/package.json +56 -0
  445. package/templates/tower-defense/playtests/arsenal.playtest.json +214 -0
  446. package/templates/tower-defense/playtests/defeat.playtest.json +85 -0
  447. package/templates/tower-defense/playtests/look.playtest.json +130 -0
  448. package/templates/tower-defense/playtests/performance.playtest.json +77 -0
  449. package/templates/tower-defense/playtests/placement.playtest.json +115 -0
  450. package/templates/{defense → tower-defense}/playtests/pointer-placement.playtest.json +21 -49
  451. package/templates/tower-defense/playtests/strike.playtest.json +98 -0
  452. package/templates/tower-defense/playtests/survives.playtest.json +85 -0
  453. package/templates/tower-defense/playtests/target-priority.playtest.json +177 -0
  454. package/templates/tower-defense/playtests/upgrade-recycle.playtest.json +124 -0
  455. package/templates/tower-defense/playtests/victory.playtest.json +810 -0
  456. package/templates/tower-defense/src/balance.ts +187 -0
  457. package/templates/tower-defense/src/board/Board.ts +100 -0
  458. package/templates/tower-defense/src/board/Route.ts +84 -0
  459. package/templates/tower-defense/src/camera-rig.ts +62 -0
  460. package/templates/tower-defense/src/economy.ts +64 -0
  461. package/templates/tower-defense/src/effects/Effects.ts +284 -0
  462. package/templates/tower-defense/src/enemies/Enemy.ts +198 -0
  463. package/templates/tower-defense/src/game.ts +72 -0
  464. package/templates/tower-defense/src/intents.ts +21 -0
  465. package/templates/tower-defense/src/main.ts +15 -0
  466. package/templates/tower-defense/src/physics.ts +6 -0
  467. package/templates/tower-defense/src/render/camera.ts +38 -0
  468. package/templates/tower-defense/src/render/lighting.ts +42 -0
  469. package/templates/{defense → tower-defense}/src/render/loading.ts +3 -3
  470. package/templates/tower-defense/src/render/materials.ts +103 -0
  471. package/templates/tower-defense/src/render/palette.ts +58 -0
  472. package/templates/tower-defense/src/render/postprocessing.ts +46 -0
  473. package/templates/tower-defense/src/render/quality.ts +128 -0
  474. package/templates/tower-defense/src/render/shapes.ts +550 -0
  475. package/templates/tower-defense/src/render/sky.ts +27 -0
  476. package/templates/tower-defense/src/render/worldEnvironment.ts +809 -0
  477. package/templates/tower-defense/src/scenes/Battle.ts +539 -0
  478. package/templates/{shooter → tower-defense}/src/scenes/Boot.ts +3 -3
  479. package/templates/tower-defense/src/state.ts +88 -0
  480. package/templates/tower-defense/src/style.css +137 -0
  481. package/templates/tower-defense/src/towers/Tower.ts +230 -0
  482. package/templates/tower-defense/src/towers/targeting.ts +97 -0
  483. package/templates/tower-defense/src/ui/Hud.tsx +270 -0
  484. package/templates/tower-defense/src/ui/Menu.tsx +134 -0
  485. package/templates/tower-defense/src/ui/icons.tsx +54 -0
  486. package/templates/tower-defense/src/ui/main.tsx +14 -0
  487. package/templates/tower-defense/src/waves.ts +90 -0
  488. package/templates/{defense → tower-defense}/threenative.config.ts +14 -1
  489. package/templates/tower-defense/vite.config.ts +41 -0
  490. package/agent-files/.claude/skills/file-engine-bug/SKILL.md +0 -59
  491. package/agent-files/.claude/skills/prd-creator/SKILL.md +0 -40
  492. package/agent-files/.claude/skills/threenative-assets/SKILL.md +0 -45
  493. package/agent-files/.claude/skills/threenative-capabilities/SKILL.md +0 -27
  494. package/agent-files/.claude/skills/threenative-context/SKILL.md +0 -57
  495. package/agent-files/.claude/skills/threenative-performance/SKILL.md +0 -42
  496. package/agent-files/.claude/skills/threenative-playtest/SKILL.md +0 -44
  497. package/agent-files/.claude/skills/threenative-ui/SKILL.md +0 -20
  498. package/agent-files/.claude/skills/threenative-visuals/SKILL.md +0 -41
  499. package/agent-files/AGENT-ROLES.md +0 -26
  500. package/templates/action-rpg/src/render/shapes.ts +0 -269
  501. package/templates/action-rpg/src/render/types.ts +0 -3
  502. package/templates/action-rpg/src/scenes/Boot.ts +0 -12
  503. package/templates/defense/README.md +0 -10
  504. package/templates/defense/kit.json +0 -7
  505. package/templates/defense/playtests/leak.playtest.json +0 -23
  506. package/templates/defense/playtests/placement.playtest.json +0 -40
  507. package/templates/defense/playtests/scan.playtest.json +0 -20
  508. package/templates/defense/playtests/survive.playtest.json +0 -45
  509. package/templates/defense/playtests/survives.playtest.json +0 -36
  510. package/templates/defense/src/attackers/Attacker.ts +0 -120
  511. package/templates/defense/src/board/Route.ts +0 -94
  512. package/templates/defense/src/conventions.ts +0 -18
  513. package/templates/defense/src/economy.ts +0 -36
  514. package/templates/defense/src/entities/Player.ts +0 -52
  515. package/templates/defense/src/game.ts +0 -51
  516. package/templates/defense/src/physics.ts +0 -13
  517. package/templates/defense/src/placement/Buildable.ts +0 -49
  518. package/templates/defense/src/render/camera.ts +0 -16
  519. package/templates/defense/src/render/lighting.ts +0 -37
  520. package/templates/defense/src/render/materials.ts +0 -22
  521. package/templates/defense/src/render/palette.ts +0 -28
  522. package/templates/defense/src/render/quality.ts +0 -170
  523. package/templates/defense/src/render/shapes.ts +0 -246
  524. package/templates/defense/src/render/sky.ts +0 -45
  525. package/templates/defense/src/scenes/Boot.ts +0 -12
  526. package/templates/defense/src/scenes/Defense.ts +0 -231
  527. package/templates/defense/src/state.ts +0 -56
  528. package/templates/defense/src/towers/Tower.ts +0 -95
  529. package/templates/defense/src/towers/targeting.ts +0 -53
  530. package/templates/defense/src/ui/Hud.tsx +0 -62
  531. package/templates/defense/src/ui/Menu.tsx +0 -7
  532. package/templates/defense/src/waves.ts +0 -40
  533. package/templates/minimal/playtests/atmosphere.playtest.json +0 -32
  534. package/templates/minimal/src/render/hud.ts +0 -69
  535. package/templates/platformer/playtests/avoidance.playtest.json +0 -28
  536. package/templates/platformer/playtests/chase.playtest.json +0 -21
  537. package/templates/platformer/playtests/collision-layers.playtest.json +0 -36
  538. package/templates/platformer/playtests/oneway.playtest.json +0 -44
  539. package/templates/platformer/playtests/patrol.playtest.json +0 -13
  540. package/templates/platformer/playtests/physics.playtest.json +0 -14
  541. package/templates/platformer/playtests/stomp-rise.playtest.json +0 -55
  542. package/templates/platformer/playtests/terminal-loop-fail.playtest.json +0 -41
  543. package/templates/platformer/playtests/terminal-loop-win.playtest.json +0 -52
  544. package/templates/platformer/src/conventions.ts +0 -18
  545. package/templates/platformer/src/entities/Character.ts +0 -286
  546. package/templates/platformer/src/entities/Chaser.ts +0 -118
  547. package/templates/platformer/src/entities/Patrol.ts +0 -93
  548. package/templates/platformer/src/level/Platform.ts +0 -46
  549. package/templates/platformer/src/render/rig.ts +0 -60
  550. package/templates/platformer/src/render/terrain.ts +0 -31
  551. package/templates/platformer/src/scenes/Level.ts +0 -241
  552. package/templates/puzzle/README.md +0 -43
  553. package/templates/puzzle/playtests/carry.playtest.json +0 -71
  554. package/templates/puzzle/playtests/swing.playtest.json +0 -38
  555. package/templates/puzzle/src/conventions.ts +0 -25
  556. package/templates/puzzle/src/entities/Ball.ts +0 -70
  557. package/templates/puzzle/src/entities/Gripper.ts +0 -69
  558. package/templates/puzzle/src/entities/Pendulum.ts +0 -89
  559. package/templates/puzzle/src/physics.ts +0 -19
  560. package/templates/puzzle/src/room.ts +0 -83
  561. package/templates/puzzle/src/scenes/Boot.ts +0 -12
  562. package/templates/puzzle/src/scenes/Puzzle.ts +0 -158
  563. package/templates/shooter/playtests/combat.playtest.json +0 -48
  564. package/templates/shooter/playtests/fail.playtest.json +0 -31
  565. package/templates/shooter/playtests/per-item.playtest.json +0 -59
  566. package/templates/shooter/playtests/shooter.playtest.json +0 -99
  567. package/templates/shooter/playtests/touch-controls.playtest.json +0 -42
  568. package/templates/shooter/playtests/weapon-cycle.playtest.json +0 -164
  569. package/templates/shooter/src/combat/damage.ts +0 -40
  570. package/templates/shooter/src/conventions.ts +0 -51
  571. package/templates/shooter/src/entities/Pickup.ts +0 -70
  572. package/templates/shooter/src/entities/Player.ts +0 -310
  573. package/templates/shooter/src/level/SpawnPoints.ts +0 -28
  574. package/templates/shooter/src/playtest-events.ts +0 -15
  575. package/templates/shooter/src/render/touch-controls.ts +0 -305
  576. package/templates/shooter/src/render/types.ts +0 -3
  577. package/templates/shooter/src/render/ui.css +0 -330
  578. package/templates/shooter/src/render/ui.ts +0 -75
  579. package/templates/shooter/src/render/vfx.ts +0 -215
  580. package/templates/shooter/src/ui/Menu.tsx +0 -41
  581. package/templates/shooter/src/waves.ts +0 -50
  582. package/templates/shooter/src/weapons/Hitscan.ts +0 -42
  583. package/templates/shooter/src/weapons/Projectile.ts +0 -92
  584. package/templates/shooter/src/weapons/Viewmodel.ts +0 -275
  585. package/templates/starter/playtests/assets.playtest.json +0 -65
  586. package/templates/starter/playtests/buffer.playtest.json +0 -79
  587. package/templates/starter/playtests/cloth.playtest.json +0 -113
  588. package/templates/starter/playtests/coyote.playtest.json +0 -87
  589. package/templates/starter/playtests/gameover.playtest.json +0 -66
  590. package/templates/starter/playtests/goal.playtest.json +0 -67
  591. package/templates/starter/playtests/look.playtest.json +0 -175
  592. package/templates/starter/playtests/models-baseline.png +0 -0
  593. package/templates/starter/playtests/models.playtest.json +0 -74
  594. package/templates/starter/playtests/monitoring.playtest.json +0 -72
  595. package/templates/starter/playtests/odometer.playtest.json +0 -54
  596. package/templates/starter/playtests/seed.playtest.json +0 -54
  597. package/templates/starter/playtests/textures-baseline.png +0 -0
  598. package/templates/starter/playtests/textures.playtest.json +0 -74
  599. package/templates/starter/playtests/touch-controls.playtest.json +0 -42
  600. package/templates/starter/playtests/zoom-pinch.playtest.json +0 -86
  601. package/templates/starter/playtests/zoom-wheel.playtest.json +0 -59
  602. package/templates/starter/src/render/coast.ts +0 -199
  603. package/templates/starter/src/render/hero.ts +0 -88
  604. package/templates/starter/src/render/implicitSurface.ts +0 -199
  605. package/templates/starter/src/render/kuwahara.ts +0 -174
  606. package/templates/starter/src/render/outline.ts +0 -141
  607. package/templates/starter/src/render/painterly.ts +0 -86
  608. package/templates/starter/src/render/rockRidge.ts +0 -198
  609. package/templates/starter/src/render/rockRidge.worker.ts +0 -77
  610. package/templates/starter/src/render/scenery.ts +0 -40
  611. package/templates/starter/src/render/textureLifetime.ts +0 -53
  612. package/templates/starter/src/render/water.ts +0 -38
  613. package/templates/starter/src/render/watercolor.ts +0 -85
  614. /package/templates/{starter → puzzle}/playtests/boot-failure.playtest.json +0 -0
  615. /package/templates/{starter → puzzle}/playtests/pause.playtest.json +0 -0
  616. /package/templates/{defense → rts}/.codex/config.toml +0 -0
  617. /package/templates/{defense → rts}/.cursor/mcp.json +0 -0
  618. /package/templates/{defense → rts}/.gemini/settings.json +0 -0
  619. /package/templates/{defense → rts}/.mcp.json +0 -0
  620. /package/templates/{defense → rts}/.vscode/mcp.json +0 -0
  621. /package/templates/{defense → rts}/.zed/settings.json +0 -0
  622. /package/templates/{defense → rts}/index.html +0 -0
  623. /package/templates/{defense → rts}/opencode.json +0 -0
  624. /package/templates/{defense → rts}/src/main.ts +0 -0
  625. /package/templates/{defense → rts}/src/ui/main.tsx +0 -0
  626. /package/templates/{defense → tower-defense}/public/favicon.svg +0 -0
  627. /package/templates/{defense → tower-defense}/src/playtest-events.ts +0 -0
  628. /package/templates/{defense → tower-defense}/src/ui/App.tsx +0 -0
  629. /package/templates/{defense → tower-defense}/src/ui/GameUi.tsx +0 -0
  630. /package/templates/{defense → tower-defense}/tailwind.config.ts +0 -0
  631. /package/templates/{defense → tower-defense}/tsconfig.json +0 -0
@@ -2,15 +2,135 @@
2
2
  import { createRequire } from 'node:module';
3
3
  import { spawnSync, execFileSync, spawn } from 'child_process';
4
4
  import { randomUUID, createHash } from 'crypto';
5
- import { readFile, readdir, stat, mkdir, writeFile, rm, rename, access, unlink } from 'fs/promises';
5
+ import { existsSync, realpathSync, readFileSync, statSync, openSync, readSync, closeSync, accessSync, constants } from 'fs';
6
+ import { mkdir, rm, open, readFile, writeFile, readdir, stat, rename, access, unlink } from 'fs/promises';
6
7
  import { createRequire as createRequire$1 } from 'module';
7
- import path2 from 'path';
8
- import { compileAssets, parsePng, parseAudioConfig } from '@threenative/assets';
8
+ import path4 from 'path';
9
9
  import { pathToFileURL, fileURLToPath } from 'url';
10
- import { existsSync, realpathSync, readFileSync, statSync, openSync, readSync, closeSync, accessSync, constants } from 'fs';
10
+ import { compileAssets, parsePng, parseAudioConfig } from '@threenative/assets';
11
+ import { brotliCompressSync, constants as constants$1, gzipSync } from 'zlib';
11
12
  import { platform, homedir } from 'os';
12
13
 
13
14
  createRequire(import.meta.url);
15
+ var BUILD_REPORT_SUFFIX = ".build-report.json";
16
+ function sha256(bytes) {
17
+ return createHash("sha256").update(bytes).digest("hex");
18
+ }
19
+ async function listFiles(target, prefix = "") {
20
+ const entries = await readdir(target, { withFileTypes: true });
21
+ const files = [];
22
+ for (const entry of entries.sort((left, right) => left.name < right.name ? -1 : 1)) {
23
+ const relative = prefix === "" ? entry.name : `${prefix}/${entry.name}`;
24
+ if (entry.isDirectory())
25
+ files.push(...await listFiles(path4.join(target, entry.name), relative));
26
+ else if (entry.isFile()) files.push(relative);
27
+ }
28
+ return files;
29
+ }
30
+ async function hashArtifact(target) {
31
+ const name = path4.basename(target);
32
+ if (!(await stat(target)).isDirectory()) {
33
+ return { kind: "file", name, sha256: sha256(await readFile(target)) };
34
+ }
35
+ const lines = [];
36
+ for (const file of await listFiles(target)) {
37
+ lines.push(`${file} ${sha256(await readFile(path4.join(target, file)))}`);
38
+ }
39
+ return { kind: "directory", name, sha256: sha256(Buffer.from(lines.join("\n"), "utf8")) };
40
+ }
41
+ async function measureTreeBytes(target) {
42
+ const info = await stat(target);
43
+ if (!info.isDirectory()) return info.size;
44
+ let total = 0;
45
+ for (const entry of await readdir(target))
46
+ total += await measureTreeBytes(path4.join(target, entry));
47
+ return total;
48
+ }
49
+ async function writeBuildReport(options) {
50
+ const { artifact, assets, config, target } = options;
51
+ const report = {
52
+ artifact: await hashArtifact(artifact),
53
+ measured: {
54
+ artifactBytes: await measureTreeBytes(artifact),
55
+ packagedAssetBytes: options.packagedAssetBytes
56
+ },
57
+ manifestSha256: await fileSha(path4.join(assets, "assets.manifest.json")),
58
+ performanceBudget: config.buildProfile?.performanceBudget ?? null,
59
+ profile: config.buildProfile?.name ?? null,
60
+ schemaVersion: 1,
61
+ target
62
+ };
63
+ const destination = path4.join(
64
+ path4.dirname(artifact),
65
+ `${path4.basename(artifact)}${BUILD_REPORT_SUFFIX}`
66
+ );
67
+ await writeFile(destination, `${JSON.stringify(report, null, 2)}
68
+ `);
69
+ return destination;
70
+ }
71
+ async function fileSha(target) {
72
+ try {
73
+ return sha256(await readFile(target));
74
+ } catch {
75
+ return null;
76
+ }
77
+ }
78
+ var COMPRESSIBLE_EXTENSIONS = /* @__PURE__ */ new Set([".css", ".html", ".js", ".json", ".mjs", ".wasm"]);
79
+ var MIN_BYTES = 1024;
80
+ async function walk(directory, files) {
81
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
82
+ const file = path4.join(directory, entry.name);
83
+ if (entry.isDirectory()) await walk(file, files);
84
+ else if (entry.isFile()) files.push(file);
85
+ }
86
+ }
87
+ function brotli(data) {
88
+ return brotliCompressSync(data, {
89
+ params: { [constants$1.BROTLI_PARAM_QUALITY]: constants$1.BROTLI_MAX_QUALITY }
90
+ });
91
+ }
92
+ function gzip(data) {
93
+ return gzipSync(data, { level: constants$1.Z_BEST_COMPRESSION });
94
+ }
95
+ async function writeCompressionSidecars(outputDirectory) {
96
+ const files = [];
97
+ if (!existsSync(outputDirectory)) {
98
+ process.stdout.write(`web compression skipped: no build output at ${outputDirectory}
99
+ `);
100
+ return void 0;
101
+ }
102
+ await walk(outputDirectory, files);
103
+ for (const file of files) {
104
+ if (!COMPRESSIBLE_EXTENSIONS.has(path4.extname(file).toLowerCase())) continue;
105
+ try {
106
+ const data = await readFile(file);
107
+ if (data.byteLength <= MIN_BYTES) continue;
108
+ await writeFile(`${file}.br`, brotli(data));
109
+ await writeFile(`${file}.gz`, gzip(data));
110
+ } catch (error) {
111
+ throw new Error(
112
+ `TN_WEB_COMPRESSION_FAILED: ${path4.relative(outputDirectory, file)}: ${error.message}`
113
+ );
114
+ }
115
+ }
116
+ return mainEntryReport(outputDirectory, files);
117
+ }
118
+ async function mainEntryReport(outputDirectory, files) {
119
+ const html = files.find((file) => path4.basename(file) === "index.html");
120
+ if (html === void 0) return void 0;
121
+ const match = /<script[^>]+src="([^"]+\.m?js)"/u.exec(await readFile(html, "utf8"));
122
+ const source = match?.[1];
123
+ if (source === void 0) return void 0;
124
+ const entry = path4.join(outputDirectory, source.replace(/^\//u, ""));
125
+ const raw = (await stat(entry)).size;
126
+ if (raw <= MIN_BYTES) return void 0;
127
+ return {
128
+ brotli: (await stat(`${entry}.br`)).size,
129
+ entry: path4.relative(outputDirectory, entry),
130
+ gzip: (await stat(`${entry}.gz`)).size,
131
+ raw
132
+ };
133
+ }
14
134
  var ORIENTATIONS = ["landscape", "portrait", "sensor"];
15
135
  var CONFIG_FILE = "threenative.config.ts";
16
136
  var ConfigFailure = class extends Error {
@@ -85,13 +205,13 @@ function defaultAppId(name) {
85
205
  return `com.threenative.${segment}`;
86
206
  }
87
207
  function projectRequire(cwd) {
88
- return createRequire$1(path2.join(cwd, "package.json"));
208
+ return createRequire$1(path4.join(cwd, "package.json"));
89
209
  }
90
210
  function configLoaderSearch(cwd) {
91
211
  return [
92
- path2.join(cwd, "node_modules", "vite"),
93
- path2.join(cwd, "node_modules", "esbuild"),
94
- path2.resolve(path2.dirname(fileURLToPath(import.meta.url)), "..", "node_modules", "esbuild")
212
+ path4.join(cwd, "node_modules", "vite"),
213
+ path4.join(cwd, "node_modules", "esbuild"),
214
+ path4.resolve(path4.dirname(fileURLToPath(import.meta.url)), "..", "node_modules", "esbuild")
95
215
  ];
96
216
  }
97
217
  var CONFIG_BUILD_COMMAND = "pnpm exec threenative build --target web";
@@ -99,7 +219,7 @@ function configContext(cwd, layer, sources, searched, fix) {
99
219
  return { cwd, fix, layer, searched, sources };
100
220
  }
101
221
  function packageContext(cwd) {
102
- const packagePath = path2.join(cwd, "package.json");
222
+ const packagePath = path4.join(cwd, "package.json");
103
223
  return configContext(
104
224
  cwd,
105
225
  "package manifest",
@@ -122,8 +242,8 @@ function validationContext(cwd, sources) {
122
242
  cwd,
123
243
  "config validation",
124
244
  sources,
125
- [path2.join(cwd, "package.json"), path2.join(cwd, CONFIG_FILE)],
126
- `fix '${path2.join(cwd, CONFIG_FILE)}' and rerun ${CONFIG_BUILD_COMMAND}`
245
+ [path4.join(cwd, "package.json"), path4.join(cwd, CONFIG_FILE)],
246
+ `fix '${path4.join(cwd, CONFIG_FILE)}' and rerun ${CONFIG_BUILD_COMMAND}`
127
247
  );
128
248
  }
129
249
  function configFailure(code, context, detail) {
@@ -163,7 +283,7 @@ function resolveEsbuild(cwd) {
163
283
  }
164
284
  }
165
285
  async function importConfig(cwd) {
166
- const sourcePath = path2.join(cwd, CONFIG_FILE);
286
+ const sourcePath = path4.join(cwd, CONFIG_FILE);
167
287
  try {
168
288
  await access(sourcePath);
169
289
  } catch {
@@ -224,7 +344,7 @@ async function importConfig(cwd) {
224
344
  error instanceof Error ? error.message : String(error)
225
345
  );
226
346
  }
227
- const compiledPath = path2.join(cwd, `.threenative.config.${process.pid}.${Date.now()}.mjs`);
347
+ const compiledPath = path4.join(cwd, `.threenative.config.${process.pid}.${Date.now()}.mjs`);
228
348
  try {
229
349
  await writeFile(compiledPath, code, "utf8");
230
350
  } catch (error) {
@@ -260,7 +380,7 @@ async function importConfig(cwd) {
260
380
  async function readManifest(cwd) {
261
381
  let parsed;
262
382
  try {
263
- parsed = JSON.parse(await readFile(path2.join(cwd, "package.json"), "utf8"));
383
+ parsed = JSON.parse(await readFile(path4.join(cwd, "package.json"), "utf8"));
264
384
  } catch (error) {
265
385
  fail("TN_CONFIG_PACKAGE_INVALID", error instanceof Error ? error.message : String(error));
266
386
  }
@@ -279,12 +399,12 @@ function packageNativeEntry(manifest) {
279
399
  }
280
400
  function validateNativeEntry(value, cwd) {
281
401
  const entry = nonEmptyString(value, "TN_NATIVE_ENTRY_MISSING", "nativeEntry");
282
- if (path2.isAbsolute(entry)) {
402
+ if (path4.isAbsolute(entry)) {
283
403
  fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must be project-relative.");
284
404
  }
285
- const resolved = path2.resolve(cwd, entry);
286
- const relative = path2.relative(cwd, resolved);
287
- if (relative === ".." || relative.startsWith(`..${path2.sep}`) || path2.isAbsolute(relative)) {
405
+ const resolved = path4.resolve(cwd, entry);
406
+ const relative = path4.relative(cwd, resolved);
407
+ if (relative === ".." || relative.startsWith(`..${path4.sep}`) || path4.isAbsolute(relative)) {
288
408
  fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must stay inside the project.");
289
409
  }
290
410
  return entry;
@@ -328,18 +448,18 @@ async function validateApp(raw, name, cwd) {
328
448
  }
329
449
  async function validateProjectAsset(raw, cwd, label, options) {
330
450
  const relative = nonEmptyString(raw, `${options.codePrefix}_INVALID`, label);
331
- if (path2.isAbsolute(relative)) {
451
+ if (path4.isAbsolute(relative)) {
332
452
  fail(`${options.codePrefix}_PATH_INVALID`, `${label} must be project-relative: ${relative}`);
333
453
  }
334
- const resolved = path2.resolve(cwd, relative);
335
- const withinProject = path2.relative(cwd, resolved);
336
- if (withinProject === ".." || withinProject.startsWith(`..${path2.sep}`) || path2.isAbsolute(withinProject)) {
454
+ const resolved = path4.resolve(cwd, relative);
455
+ const withinProject = path4.relative(cwd, resolved);
456
+ if (withinProject === ".." || withinProject.startsWith(`..${path4.sep}`) || path4.isAbsolute(withinProject)) {
337
457
  fail(
338
458
  `${options.codePrefix}_PATH_INVALID`,
339
459
  `${label} must stay inside the project: ${relative}`
340
460
  );
341
461
  }
342
- const extension = path2.extname(relative).slice(1).toLowerCase();
462
+ const extension = path4.extname(relative).slice(1).toLowerCase();
343
463
  if (!options.formats.includes(extension)) {
344
464
  fail(
345
465
  options.codePrefix === "TN_CONFIG_ICON" ? `${options.codePrefix}_INVALID` : `${options.codePrefix}_FORMAT_INVALID`,
@@ -563,7 +683,7 @@ var UI_RENDERERS = ["native", "web"];
563
683
  function validateUi(raw) {
564
684
  const ui = assertRecord(raw, "ui");
565
685
  assertKeys(ui, "ui", ["renderer"]);
566
- const renderer = ui.renderer === void 0 ? "native" : ui.renderer;
686
+ const renderer = ui.renderer === void 0 ? "web" : ui.renderer;
567
687
  if (typeof renderer !== "string" || !UI_RENDERERS.includes(renderer)) {
568
688
  fail("TN_CONFIG_UI_RENDERER_INVALID", "ui.renderer must be web or native.");
569
689
  }
@@ -576,6 +696,9 @@ function validateRenderer(raw) {
576
696
  "resolutionScale",
577
697
  "antialias",
578
698
  "alphaAntialiasing",
699
+ "projection",
700
+ "minimumProjectedPixels",
701
+ "matrixWorld",
579
702
  "android"
580
703
  ]);
581
704
  const android = assertRecord(renderer.android, "renderer.android");
@@ -604,6 +727,15 @@ function validateRenderer(raw) {
604
727
  android.alphaAntialiasing,
605
728
  "renderer.android.alphaAntialiasing"
606
729
  );
730
+ const projection = booleanOrUndefined(renderer.projection, "renderer.projection");
731
+ const minimumProjectedPixels = numberOrFalse(
732
+ renderer.minimumProjectedPixels,
733
+ "renderer.minimumProjectedPixels"
734
+ );
735
+ const matrixWorld = renderer.matrixWorld;
736
+ if (matrixWorld !== void 0 && matrixWorld !== "visible" && matrixWorld !== "all") {
737
+ fail("TN_CONFIG_RENDERER_INVALID", 'renderer.matrixWorld must be "visible" or "all".');
738
+ }
607
739
  const androidOverrides = {
608
740
  ...androidResolutionScale === void 0 ? {} : { resolutionScale: androidResolutionScale },
609
741
  ...androidAntialias === void 0 ? {} : { antialias: androidAntialias },
@@ -618,6 +750,9 @@ function validateRenderer(raw) {
618
750
  ),
619
751
  ...antialias === void 0 ? {} : { antialias },
620
752
  ...alphaAntialiasing === void 0 ? {} : { alphaAntialiasing },
753
+ ...projection === void 0 ? {} : { projection },
754
+ ...minimumProjectedPixels === void 0 ? {} : { minimumProjectedPixels },
755
+ ...matrixWorld === void 0 ? {} : { matrixWorld },
621
756
  ...resolutionScale === void 0 ? {} : { resolutionScale },
622
757
  ...Object.keys(androidOverrides).length === 0 ? {} : { android: androidOverrides }
623
758
  };
@@ -627,6 +762,13 @@ function booleanOrUndefined(value, name) {
627
762
  if (typeof value !== "boolean") fail("TN_CONFIG_RENDERER_INVALID", `${name} must be a boolean.`);
628
763
  return value;
629
764
  }
765
+ function numberOrFalse(value, name) {
766
+ if (value === void 0 || value === false) return value;
767
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
768
+ fail("TN_CONFIG_RENDERER_INVALID", `${name} must be false or a positive finite number.`);
769
+ }
770
+ return value;
771
+ }
630
772
  var ASSET_TARGET_KEYS = [
631
773
  "maxMaterials",
632
774
  "maxTriangles",
@@ -744,6 +886,7 @@ function validateModels(raw) {
744
886
  if (raw === "none") return "none";
745
887
  const models = assertRecord(raw, "assets.models");
746
888
  assertKeys(models, "assets.models", [
889
+ "compact",
747
890
  "lightmap",
748
891
  "passes",
749
892
  "quantize",
@@ -807,6 +950,7 @@ function validateModels(raw) {
807
950
  }
808
951
  const simplify = models.simplify;
809
952
  const textures = models.textures;
953
+ const compact = models.compact;
810
954
  let virtual;
811
955
  if (models.virtual === "none") {
812
956
  virtual = "none";
@@ -836,6 +980,7 @@ function validateModels(raw) {
836
980
  virtual = bake;
837
981
  }
838
982
  return {
983
+ ...compact === void 0 ? {} : { compact },
839
984
  ...lightmap === void 0 ? {} : { lightmap },
840
985
  ...passes === void 0 || Object.keys(passes).length === 0 ? {} : { passes },
841
986
  ...quantize === void 0 || Object.keys(quantize).length === 0 ? {} : { quantize },
@@ -845,6 +990,156 @@ function validateModels(raw) {
845
990
  ...virtual === void 0 ? {} : { virtual }
846
991
  };
847
992
  }
993
+ var LOD_PRESETS = ["aggressive", "balanced", "quality"];
994
+ var LOD_MIN_TRIANGLES_SCOPES = ["primitive", "asset"];
995
+ var LOD_KEYS = ["enabled", "generation", "overrides", "preset", "runtime"];
996
+ var LOD_GENERATION_KEYS = [
997
+ "errorTargets",
998
+ "join",
999
+ "maxLevels",
1000
+ "minSaving",
1001
+ "minTriangles",
1002
+ "minTrianglesScope"
1003
+ ];
1004
+ var LOD_RUNTIME_KEYS = ["hysteresis", "maxPixelError"];
1005
+ var LOD_OVERRIDE_KEYS = ["enabled", "generation", "preset", "runtime"];
1006
+ function lodGeneration(raw, label) {
1007
+ const value = assertRecord(raw, label);
1008
+ assertKeys(value, label, LOD_GENERATION_KEYS);
1009
+ const generation = {};
1010
+ if (value.join !== void 0) {
1011
+ if (typeof value.join !== "boolean") {
1012
+ fail("TN_CONFIG_ASSETS_INVALID", `${label}.join must be a boolean.`);
1013
+ }
1014
+ generation.join = value.join;
1015
+ }
1016
+ if (value.maxLevels !== void 0) {
1017
+ if (!Number.isSafeInteger(value.maxLevels) || value.maxLevels < 1 || value.maxLevels > 8) {
1018
+ fail("TN_CONFIG_ASSETS_INVALID", `${label}.maxLevels must be an integer between 1 and 8.`);
1019
+ }
1020
+ generation.maxLevels = value.maxLevels;
1021
+ }
1022
+ if (value.minTriangles !== void 0) {
1023
+ generation.minTriangles = positiveInteger(
1024
+ value.minTriangles,
1025
+ 1,
1026
+ "TN_CONFIG_ASSETS_INVALID",
1027
+ `${label}.minTriangles`
1028
+ );
1029
+ }
1030
+ if (value.minTrianglesScope !== void 0) {
1031
+ if (typeof value.minTrianglesScope !== "string" || !LOD_MIN_TRIANGLES_SCOPES.includes(value.minTrianglesScope)) {
1032
+ fail(
1033
+ "TN_CONFIG_ASSETS_INVALID",
1034
+ `${label}.minTrianglesScope must be one of ${LOD_MIN_TRIANGLES_SCOPES.join(", ")}.`
1035
+ );
1036
+ }
1037
+ generation.minTrianglesScope = value.minTrianglesScope;
1038
+ }
1039
+ if (value.minSaving !== void 0) {
1040
+ if (typeof value.minSaving !== "number" || !Number.isFinite(value.minSaving) || value.minSaving < 0 || value.minSaving >= 1) {
1041
+ fail("TN_CONFIG_ASSETS_INVALID", `${label}.minSaving must be a finite number in [0, 1).`);
1042
+ }
1043
+ generation.minSaving = value.minSaving;
1044
+ }
1045
+ if (value.errorTargets !== void 0) {
1046
+ const targets = value.errorTargets;
1047
+ if (!Array.isArray(targets) || targets.length === 0 || targets.length > 16) {
1048
+ fail(
1049
+ "TN_CONFIG_ASSETS_INVALID",
1050
+ `${label}.errorTargets must be 1 to 16 geometric-error targets.`
1051
+ );
1052
+ }
1053
+ let previous = -1;
1054
+ for (const target of targets) {
1055
+ if (typeof target !== "number" || !Number.isFinite(target) || target <= 0) {
1056
+ fail("TN_CONFIG_ASSETS_INVALID", `${label}.errorTargets must be positive finite numbers.`);
1057
+ }
1058
+ if (target <= previous) {
1059
+ fail("TN_CONFIG_ASSETS_INVALID", `${label}.errorTargets must increase strictly.`);
1060
+ }
1061
+ previous = target;
1062
+ }
1063
+ generation.errorTargets = [...targets];
1064
+ }
1065
+ return generation;
1066
+ }
1067
+ function lodRuntime(raw, label) {
1068
+ const value = assertRecord(raw, label);
1069
+ assertKeys(value, label, LOD_RUNTIME_KEYS);
1070
+ const runtime = {};
1071
+ if (value.maxPixelError !== void 0) {
1072
+ if (typeof value.maxPixelError !== "number" || !Number.isFinite(value.maxPixelError) || value.maxPixelError <= 0) {
1073
+ fail("TN_CONFIG_ASSETS_INVALID", `${label}.maxPixelError must be a positive finite number.`);
1074
+ }
1075
+ runtime.maxPixelError = value.maxPixelError;
1076
+ }
1077
+ if (value.hysteresis !== void 0) {
1078
+ if (typeof value.hysteresis !== "number" || !Number.isFinite(value.hysteresis) || value.hysteresis < 0 || value.hysteresis >= 0.5) {
1079
+ fail("TN_CONFIG_ASSETS_INVALID", `${label}.hysteresis must be a finite number in [0, 0.5).`);
1080
+ }
1081
+ runtime.hysteresis = value.hysteresis;
1082
+ }
1083
+ return runtime;
1084
+ }
1085
+ function lodPreset(raw, label) {
1086
+ if (typeof raw !== "string" || !LOD_PRESETS.includes(raw)) {
1087
+ fail("TN_CONFIG_ASSETS_INVALID", `${label} must be one of ${LOD_PRESETS.join(", ")}.`);
1088
+ }
1089
+ return raw;
1090
+ }
1091
+ function lodOverride(raw, label) {
1092
+ if (typeof raw === "boolean") return raw;
1093
+ const value = assertRecord(raw, label);
1094
+ assertKeys(value, label, LOD_OVERRIDE_KEYS);
1095
+ return {
1096
+ ...value.enabled === void 0 ? {} : {
1097
+ enabled: booleanValue(
1098
+ value.enabled,
1099
+ true,
1100
+ "TN_CONFIG_ASSETS_INVALID",
1101
+ `${label}.enabled`
1102
+ )
1103
+ },
1104
+ ...value.generation === void 0 ? {} : { generation: lodGeneration(value.generation, `${label}.generation`) },
1105
+ ...value.preset === void 0 ? {} : { preset: lodPreset(value.preset, `${label}.preset`) },
1106
+ ...value.runtime === void 0 ? {} : { runtime: lodRuntime(value.runtime, `${label}.runtime`) }
1107
+ };
1108
+ }
1109
+ function validateLod(raw) {
1110
+ if (typeof raw === "boolean") return raw;
1111
+ const value = assertRecord(raw, "assets.lod");
1112
+ assertKeys(value, "assets.lod", LOD_KEYS);
1113
+ const overrides = {};
1114
+ if (value.overrides !== void 0) {
1115
+ if (!isRecord(value.overrides)) {
1116
+ fail("TN_CONFIG_ASSETS_INVALID", "assets.lod.overrides must be an object.");
1117
+ }
1118
+ for (const [key, entry] of Object.entries(value.overrides)) {
1119
+ if (key.trim() === "") {
1120
+ fail(
1121
+ "TN_CONFIG_ASSETS_INVALID",
1122
+ "assets.lod.overrides keys must be non-empty source asset paths."
1123
+ );
1124
+ }
1125
+ overrides[key] = lodOverride(entry, `assets.lod.overrides['${key}']`);
1126
+ }
1127
+ }
1128
+ return {
1129
+ ...value.enabled === void 0 ? {} : {
1130
+ enabled: booleanValue(
1131
+ value.enabled,
1132
+ true,
1133
+ "TN_CONFIG_ASSETS_INVALID",
1134
+ "assets.lod.enabled"
1135
+ )
1136
+ },
1137
+ ...value.generation === void 0 ? {} : { generation: lodGeneration(value.generation, "assets.lod.generation") },
1138
+ ...Object.keys(overrides).length === 0 ? {} : { overrides },
1139
+ ...value.preset === void 0 ? {} : { preset: lodPreset(value.preset, "assets.lod.preset") },
1140
+ ...value.runtime === void 0 ? {} : { runtime: lodRuntime(value.runtime, "assets.lod.runtime") }
1141
+ };
1142
+ }
848
1143
  function validateBudget(raw) {
849
1144
  const limit = (value) => value === "none" || typeof value === "number" && Number.isSafeInteger(value) && value > 0;
850
1145
  if (limit(raw)) return raw;
@@ -873,6 +1168,7 @@ function validateAssets(raw) {
873
1168
  "budget",
874
1169
  "exclude",
875
1170
  "concurrency",
1171
+ "lod",
876
1172
  "models",
877
1173
  "source",
878
1174
  "output",
@@ -880,6 +1176,7 @@ function validateAssets(raw) {
880
1176
  "textures"
881
1177
  ]);
882
1178
  const targets = assets.targets === void 0 ? void 0 : validateAssetTargets(assets.targets);
1179
+ const lod = assets.lod === void 0 ? void 0 : validateLod(assets.lod);
883
1180
  const models = assets.models === void 0 ? void 0 : validateModels(assets.models);
884
1181
  const textures = assets.textures === void 0 ? void 0 : validateTextures(assets.textures);
885
1182
  if (assets.exclude !== void 0 && (!Array.isArray(assets.exclude) || assets.exclude.some((glob) => typeof glob !== "string" || glob.trim() === ""))) {
@@ -903,13 +1200,244 @@ function validateAssets(raw) {
903
1200
  ...assets.source === void 0 ? {} : { source: nonEmptyString(assets.source, "TN_CONFIG_ASSETS_INVALID", "assets.source") },
904
1201
  ...assets.output === void 0 ? {} : { output: nonEmptyString(assets.output, "TN_CONFIG_ASSETS_INVALID", "assets.output") },
905
1202
  ...targets === void 0 ? {} : { targets },
1203
+ ...lod === void 0 ? {} : { lod },
906
1204
  ...models === void 0 ? {} : { models },
907
1205
  ...textures === void 0 ? {} : { textures }
908
1206
  };
909
1207
  }
910
- async function loadConfigInternal(root) {
911
- const packagePath = path2.join(root, "package.json");
912
- const sourcePath = path2.join(root, CONFIG_FILE);
1208
+ var PROFILE_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/u;
1209
+ var PROFILE_ASSET_KEYS = [
1210
+ "audio",
1211
+ "budget",
1212
+ "lod",
1213
+ "models",
1214
+ "targets",
1215
+ "textures"
1216
+ ];
1217
+ var PROFILE_TARGETS = ["android", "desktop", "ios", "web"];
1218
+ var ARTIFACT_BUDGET_KEYS = ["artifactBytes", "packagedAssetBytes"];
1219
+ var ARTIFACT_BUDGET_SEVERITIES = ["error", "warn"];
1220
+ var PERFORMANCE_BUDGET_KEYS = [
1221
+ "maxDrawCalls",
1222
+ "maxFrameMsP95",
1223
+ "maxPassDrawCalls",
1224
+ "maxPassTriangles",
1225
+ "maxPhaseMsP95",
1226
+ "maxTriangles",
1227
+ "minFps"
1228
+ ];
1229
+ var PERFORMANCE_BUDGET_PHASES = [
1230
+ "hostGap",
1231
+ "overlay",
1232
+ "render",
1233
+ "residual",
1234
+ "update"
1235
+ ];
1236
+ var PERFORMANCE_BUDGET_PASSES = ["main", "shadow", "reflection", "nested"];
1237
+ function validatePerformanceBudgetMap(raw, label, names, unit) {
1238
+ const map = assertRecord(raw, label);
1239
+ const entries = Object.entries(map);
1240
+ if (entries.length === 0)
1241
+ fail("TN_CONFIG_PROFILE_INVALID", `${label} must name at least one entry.`);
1242
+ const budget = {};
1243
+ for (const [name, ceiling] of entries) {
1244
+ if (!names.includes(name)) {
1245
+ fail(
1246
+ "TN_CONFIG_PROFILE_INVALID",
1247
+ `${label}.${name} is not recognised. Expected one of: ${names.join(", ")}.`
1248
+ );
1249
+ }
1250
+ if (typeof ceiling !== "number" || !Number.isFinite(ceiling) || ceiling < 0) {
1251
+ fail(
1252
+ "TN_CONFIG_PROFILE_INVALID",
1253
+ `${label}.${name} must be a non-negative number of ${unit}.`
1254
+ );
1255
+ }
1256
+ budget[name] = ceiling;
1257
+ }
1258
+ return budget;
1259
+ }
1260
+ function validatePerformanceBudget(raw, label) {
1261
+ const budget = assertRecord(raw, `${label}.performanceBudget`);
1262
+ assertKeys(budget, `${label}.performanceBudget`, PERFORMANCE_BUDGET_KEYS);
1263
+ if (Object.keys(budget).length === 0) {
1264
+ fail(
1265
+ "TN_CONFIG_PROFILE_INVALID",
1266
+ `${label}.performanceBudget must declare at least one ceiling; an empty budget bounds nothing.`
1267
+ );
1268
+ }
1269
+ const out = {};
1270
+ for (const key of ["maxDrawCalls", "maxFrameMsP95", "maxTriangles", "minFps"]) {
1271
+ const value = budget[key];
1272
+ if (value === void 0) continue;
1273
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
1274
+ fail(
1275
+ "TN_CONFIG_PROFILE_INVALID",
1276
+ `${label}.performanceBudget.${key} must be a non-negative number.`
1277
+ );
1278
+ }
1279
+ out[key] = value;
1280
+ }
1281
+ for (const [key, names, unit] of [
1282
+ ["maxPassDrawCalls", PERFORMANCE_BUDGET_PASSES, "draw calls"],
1283
+ ["maxPassTriangles", PERFORMANCE_BUDGET_PASSES, "triangles"],
1284
+ ["maxPhaseMsP95", PERFORMANCE_BUDGET_PHASES, "milliseconds"]
1285
+ ]) {
1286
+ if (budget[key] === void 0) continue;
1287
+ out[key] = validatePerformanceBudgetMap(
1288
+ budget[key],
1289
+ `${label}.performanceBudget.${key}`,
1290
+ names,
1291
+ unit
1292
+ );
1293
+ }
1294
+ return out;
1295
+ }
1296
+ function artifactBudgetLimit(raw, label) {
1297
+ const limit = assertRecord(raw, label);
1298
+ assertKeys(limit, label, ["limit", "severity"]);
1299
+ const bytes = positiveInteger(limit.limit, 1, "TN_CONFIG_PROFILE_INVALID", `${label}.limit`);
1300
+ if (typeof limit.severity !== "string" || !ARTIFACT_BUDGET_SEVERITIES.includes(limit.severity)) {
1301
+ fail(
1302
+ "TN_CONFIG_PROFILE_INVALID",
1303
+ `${label}.severity must be one of ${ARTIFACT_BUDGET_SEVERITIES.join(", ")}.`
1304
+ );
1305
+ }
1306
+ return { limit: bytes, severity: limit.severity };
1307
+ }
1308
+ function validateArtifactBudget(raw, label) {
1309
+ const budget = assertRecord(raw, `${label}.artifactBudget`);
1310
+ assertKeys(budget, `${label}.artifactBudget`, ARTIFACT_BUDGET_KEYS);
1311
+ const artifactBytes = budget.artifactBytes === void 0 ? void 0 : artifactBudgetLimit(budget.artifactBytes, `${label}.artifactBudget.artifactBytes`);
1312
+ const packagedAssetBytes = budget.packagedAssetBytes === void 0 ? void 0 : artifactBudgetLimit(
1313
+ budget.packagedAssetBytes,
1314
+ `${label}.artifactBudget.packagedAssetBytes`
1315
+ );
1316
+ return {
1317
+ ...artifactBytes === void 0 ? {} : { artifactBytes },
1318
+ ...packagedAssetBytes === void 0 ? {} : { packagedAssetBytes }
1319
+ };
1320
+ }
1321
+ function resolveBuildProfile(raw, selection) {
1322
+ if (raw === void 0) {
1323
+ if (selection?.profile !== void 0) {
1324
+ fail(
1325
+ "TN_CONFIG_PROFILE_UNKNOWN",
1326
+ `--profile ${selection.profile} was requested but ${CONFIG_FILE} declares no buildProfiles.`
1327
+ );
1328
+ }
1329
+ return void 0;
1330
+ }
1331
+ const group = assertRecord(raw, "buildProfiles");
1332
+ assertKeys(group, "buildProfiles", ["defaults", "profiles"]);
1333
+ const defaults = assertRecord(group.defaults, "buildProfiles.defaults");
1334
+ assertKeys(defaults, "buildProfiles.defaults", PROFILE_TARGETS);
1335
+ for (const [target, name2] of Object.entries(defaults)) {
1336
+ if (typeof name2 !== "string" || name2.length === 0) {
1337
+ fail("TN_CONFIG_PROFILE_INVALID", `buildProfiles.defaults.${target} must name a profile.`);
1338
+ }
1339
+ }
1340
+ const profiles = assertRecord(group.profiles, "buildProfiles.profiles");
1341
+ const declared = Object.keys(profiles);
1342
+ if (declared.length === 0) {
1343
+ fail("TN_CONFIG_GROUP_INVALID", "buildProfiles.profiles must declare at least one profile.");
1344
+ }
1345
+ const budgets = {};
1346
+ const performanceBudgets = {};
1347
+ for (const name2 of declared) {
1348
+ const label = `buildProfiles.profiles['${name2}']`;
1349
+ if (!PROFILE_NAME.test(name2)) {
1350
+ fail(
1351
+ "TN_CONFIG_PROFILE_NAME_INVALID",
1352
+ `${label} is not a usable profile name ('${name2}'): names are one lower-case path segment matching /^[a-z0-9][a-z0-9_-]{0,63}$/, so no name can traverse out of the build directory or collide by case.`
1353
+ );
1354
+ }
1355
+ const profile2 = assertRecord(profiles[name2], label);
1356
+ assertKeys(profile2, label, ["artifactBudget", "assets", "performanceBudget"]);
1357
+ assertKeys(
1358
+ assertRecord(profile2.assets, `${label}.assets`),
1359
+ `${label}.assets`,
1360
+ PROFILE_ASSET_KEYS
1361
+ );
1362
+ if (profile2.artifactBudget !== void 0) {
1363
+ budgets[name2] = validateArtifactBudget(profile2.artifactBudget, label);
1364
+ }
1365
+ if (profile2.performanceBudget !== void 0) {
1366
+ performanceBudgets[name2] = validatePerformanceBudget(profile2.performanceBudget, label);
1367
+ }
1368
+ }
1369
+ for (const [target, name2] of Object.entries(defaults)) {
1370
+ if (typeof name2 === "string" && !Object.hasOwn(profiles, name2)) {
1371
+ fail(
1372
+ "TN_CONFIG_PROFILE_UNKNOWN",
1373
+ `buildProfiles.defaults.${target} names '${name2}', which is not declared. Declared profiles: ${declared.join(", ")}.`
1374
+ );
1375
+ }
1376
+ }
1377
+ if (selection === void 0) return void 0;
1378
+ const requested = selection.profile;
1379
+ const name = requested ?? defaults[selection.target];
1380
+ if (name === void 0) return void 0;
1381
+ const profile = profiles[name];
1382
+ if (profile === void 0) {
1383
+ const asked = requested === void 0 ? `buildProfiles.defaults.${selection.target}` : `--profile ${name}`;
1384
+ fail(
1385
+ "TN_CONFIG_PROFILE_UNKNOWN",
1386
+ `${asked} names a profile this project does not declare. Declared profiles: ${declared.join(", ")}.`
1387
+ );
1388
+ }
1389
+ return {
1390
+ assets: isRecord(profile.assets) ? profile.assets : {},
1391
+ ...budgets[name] === void 0 ? {} : { artifactBudget: budgets[name] },
1392
+ ...performanceBudgets[name] === void 0 ? {} : { performanceBudget: performanceBudgets[name] },
1393
+ name,
1394
+ source: requested === void 0 ? "default" : "flag",
1395
+ target: selection.target
1396
+ };
1397
+ }
1398
+ function mergeProfileOverlay(base, overlay) {
1399
+ if (!isRecord(base)) return overlay;
1400
+ const merged = { ...base };
1401
+ for (const [key, value] of Object.entries(overlay)) {
1402
+ const current = merged[key];
1403
+ merged[key] = isRecord(current) && isRecord(value) ? mergeProfileOverlay(current, value) : value;
1404
+ }
1405
+ return merged;
1406
+ }
1407
+ function assertProfileCapReachable(assets, overlay, name) {
1408
+ const overlayTextures = overlay.textures;
1409
+ const overlayModels = overlay.models;
1410
+ const caps = isRecord(overlayTextures) && overlayTextures.maxSize !== void 0 || isRecord(overlayModels) && isRecord(overlayModels.textures) && overlayModels.textures.maxSize !== void 0;
1411
+ if (!caps) return;
1412
+ const conflicts = [];
1413
+ if (assets.textures !== void 0 && assets.textures !== "none") {
1414
+ for (const override of assets.textures.overrides ?? []) {
1415
+ if (override.codec === "none") {
1416
+ conflicts.push(`assets.textures.overrides glob '${override.glob}' declares codec "none"`);
1417
+ }
1418
+ }
1419
+ }
1420
+ const models = assets.models;
1421
+ const modelTextures = models === void 0 || models === "none" ? void 0 : models.textures;
1422
+ if (modelTextures !== void 0 && modelTextures !== "none") {
1423
+ for (const override of modelTextures.overrides ?? []) {
1424
+ if (override.codec === "none") {
1425
+ conflicts.push(
1426
+ `assets.models.textures.overrides slot '${override.slot}' declares codec "none"`
1427
+ );
1428
+ }
1429
+ }
1430
+ }
1431
+ if (conflicts.length > 0) {
1432
+ fail(
1433
+ "TN_CONFIG_PROFILE_CONFLICT",
1434
+ `profile '${name}' caps texture size, and ${conflicts.join("; ")}, which returns the authored bytes before resizing. Drop the override, or take the cap out of the profile.`
1435
+ );
1436
+ }
1437
+ }
1438
+ async function loadConfigInternal(root, selection) {
1439
+ const packagePath = path4.join(root, "package.json");
1440
+ const sourcePath = path4.join(root, CONFIG_FILE);
913
1441
  const manifest = await withConfigContext(
914
1442
  packageContext(root),
915
1443
  "TN_CONFIG_PACKAGE_INVALID",
@@ -940,7 +1468,8 @@ async function loadConfigInternal(root) {
940
1468
  "nativeEntry",
941
1469
  "renderer",
942
1470
  "ui",
943
- "assets"
1471
+ "assets",
1472
+ "buildProfiles"
944
1473
  ]);
945
1474
  }
946
1475
  const configuredEntry = raw?.nativeEntry;
@@ -952,7 +1481,12 @@ async function loadConfigInternal(root) {
952
1481
  }
953
1482
  const app = await validateApp(raw?.app, name, root);
954
1483
  const bootSplash = await validateBootSplash(raw?.bootSplash, root);
955
- const assets = raw?.assets === void 0 ? void 0 : validateAssets(raw.assets);
1484
+ const profile = resolveBuildProfile(raw?.buildProfiles, selection);
1485
+ const rawAssets = profile === void 0 ? raw?.assets : mergeProfileOverlay(raw?.assets, profile.assets);
1486
+ const assets = rawAssets === void 0 ? void 0 : validateAssets(rawAssets);
1487
+ if (assets !== void 0 && profile !== void 0) {
1488
+ assertProfileCapReachable(assets, profile.assets, profile.name);
1489
+ }
956
1490
  return {
957
1491
  app,
958
1492
  display: validateDisplay(raw?.display),
@@ -961,50 +1495,53 @@ async function loadConfigInternal(root) {
961
1495
  renderer: validateRenderer(raw?.renderer),
962
1496
  ui: validateUi(raw?.ui),
963
1497
  ...bootSplash === void 0 ? {} : { bootSplash },
964
- ...assets === void 0 ? {} : { assets }
1498
+ ...assets === void 0 ? {} : { assets },
1499
+ ...profile === void 0 ? {} : {
1500
+ buildProfile: {
1501
+ name: profile.name,
1502
+ source: profile.source,
1503
+ target: profile.target,
1504
+ ...profile.artifactBudget === void 0 ? {} : { artifactBudget: profile.artifactBudget },
1505
+ ...profile.performanceBudget === void 0 ? {} : { performanceBudget: profile.performanceBudget }
1506
+ }
1507
+ }
965
1508
  };
966
1509
  }
967
1510
  );
968
1511
  }
969
- async function loadConfig(cwd) {
970
- const root = path2.resolve(cwd);
1512
+ async function loadConfig(cwd, selection) {
1513
+ const root = path4.resolve(cwd);
971
1514
  return withConfigContext(
972
- validationContext(root, [path2.join(root, CONFIG_FILE), path2.join(root, "package.json")]),
1515
+ validationContext(root, [path4.join(root, CONFIG_FILE), path4.join(root, "package.json")]),
973
1516
  "TN_CONFIG_VALIDATION_FAILED",
974
- () => loadConfigInternal(root)
1517
+ () => loadConfigInternal(root, selection)
975
1518
  );
976
1519
  }
977
1520
 
978
1521
  // src/build.ts
979
1522
  var TARGETS = ["web", "desktop", "android", "ios"];
980
1523
  function projectRequire2(cwd) {
981
- return createRequire$1(path2.join(cwd, "package.json"));
1524
+ return createRequire$1(path4.join(cwd, "package.json"));
982
1525
  }
983
1526
  function packageRoot(cwd, packageName) {
984
1527
  try {
985
- return path2.dirname(projectRequire2(cwd).resolve(`${packageName}/package.json`));
1528
+ return path4.dirname(projectRequire2(cwd).resolve(`${packageName}/package.json`));
986
1529
  } catch {
987
- throw new Error(
988
- `Cannot build a native target because '${packageName}' is not installed in ${cwd}.`
989
- );
1530
+ throw new Error(`Cannot build because '${packageName}' is not installed in ${cwd}.`);
990
1531
  }
991
1532
  }
992
- function executable(cwd, name) {
993
- const suffix = process.platform === "win32" ? ".cmd" : "";
994
- return path2.join(cwd, "node_modules", ".bin", `${name}${suffix}`);
995
- }
996
1533
  async function run(command, args, cwd) {
997
1534
  await new Promise((resolve, reject) => {
998
1535
  const child = spawn(command, [...args], { cwd, stdio: "inherit" });
999
1536
  child.once("error", reject);
1000
1537
  child.once("exit", (code) => {
1001
1538
  if (code === 0) resolve();
1002
- else reject(new Error(`${path2.basename(command)} exited with code ${code ?? "unknown"}.`));
1539
+ else reject(new Error(`${path4.basename(command)} exited with code ${code ?? "unknown"}.`));
1003
1540
  });
1004
1541
  });
1005
1542
  }
1006
1543
  async function projectName(cwd) {
1007
- const manifest = JSON.parse(await readFile(path2.join(cwd, "package.json"), "utf8"));
1544
+ const manifest = JSON.parse(await readFile(path4.join(cwd, "package.json"), "utf8"));
1008
1545
  const name = manifest.name?.replace(/^@[^/]+\//u, "").replace(/[^a-zA-Z0-9._-]/gu, "-");
1009
1546
  if (name === void 0 || name.length === 0) throw new Error("package.json must name the game.");
1010
1547
  return name;
@@ -1033,7 +1570,9 @@ async function assertNativeBundleCompatible(bundle, target) {
1033
1570
  }
1034
1571
  function assertNativeUiRendererCompatible(target, renderer, platform2 = process.platform) {
1035
1572
  if (renderer === "native" || target === "android" || target === "ios") return;
1036
- if (target === "desktop" && platform2 === "linux") return;
1573
+ if (target === "desktop" && (platform2 === "linux" || platform2 === "darwin" || platform2 === "win32")) {
1574
+ return;
1575
+ }
1037
1576
  const platformName = platform2 === "darwin" ? "macOS" : platform2 === "win32" ? "Windows" : platform2;
1038
1577
  throw new Error(
1039
1578
  `TN_UI_RENDERER_UNSUPPORTED: ui.renderer is "web", but ${target} has no WebView host on ${platformName}. Set ui.renderer to "native" for ${target}.`
@@ -1049,10 +1588,13 @@ function namedAssets(logicalPaths) {
1049
1588
  const rest = logicalPaths.length - 3;
1050
1589
  return rest > 0 ? `${shown} and ${rest} more` : shown;
1051
1590
  }
1591
+ function assetRoot(cwd, config) {
1592
+ return path4.resolve(cwd, config.assets?.output ?? "public");
1593
+ }
1052
1594
  async function assertNativeAssetsCompatible(cwd, target, config) {
1053
1595
  if (target === "desktop" || target === "web") return;
1054
- const outputRoot = path2.resolve(cwd, config.assets?.output ?? "public");
1055
- const manifestPath = path2.join(outputRoot, "assets.manifest.json");
1596
+ const outputRoot = assetRoot(cwd, config);
1597
+ const manifestPath = path4.join(outputRoot, "assets.manifest.json");
1056
1598
  let raw;
1057
1599
  try {
1058
1600
  raw = await readFile(manifestPath, "utf8");
@@ -1091,11 +1633,19 @@ async function assertNativeAssetsCompatible(cwd, target, config) {
1091
1633
  );
1092
1634
  }
1093
1635
  }
1094
- var UI_ENTRY = path2.join("src", "ui", "main.tsx");
1636
+ function announceProfile(config) {
1637
+ const selected = config.buildProfile;
1638
+ if (selected === void 0) return;
1639
+ process.stdout.write(
1640
+ `threenative build: profile ${selected.name} (${selected.source}) for ${selected.target}
1641
+ `
1642
+ );
1643
+ }
1644
+ var UI_ENTRY = path4.join("src", "ui", "main.tsx");
1095
1645
  var UI_PAGE_PREFIX = ".threenative-ui-";
1096
1646
  async function buildUi(cwd, config) {
1097
- const output = path2.join(cwd, ".threenative", "build", "ui");
1098
- const entry = path2.join(cwd, UI_ENTRY);
1647
+ const output = path4.join(cwd, ".threenative", "build", "ui");
1648
+ const entry = path4.join(cwd, UI_ENTRY);
1099
1649
  try {
1100
1650
  if (!(await stat(entry)).isFile()) throw new Error("not a file");
1101
1651
  } catch {
@@ -1103,9 +1653,9 @@ async function buildUi(cwd, config) {
1103
1653
  `TN_UI_ENTRY_MISSING: ui.renderer is "${config.ui.renderer}" but ${UI_ENTRY} does not exist. It is the entry every platform's web view loads; create it, or set ui.renderer to "native".`
1104
1654
  );
1105
1655
  }
1106
- const buildRoot = path2.join(cwd, ".threenative", "build");
1656
+ const buildRoot = path4.join(cwd, ".threenative", "build");
1107
1657
  await mkdir(buildRoot, { recursive: true });
1108
- const page = path2.join(cwd, `${UI_PAGE_PREFIX}${randomUUID()}.html`);
1658
+ const page = path4.join(cwd, `${UI_PAGE_PREFIX}${randomUUID()}.html`);
1109
1659
  await writeFile(
1110
1660
  page,
1111
1661
  [
@@ -1118,20 +1668,20 @@ async function buildUi(cwd, config) {
1118
1668
  " </head>",
1119
1669
  " <body>",
1120
1670
  ' <div id="tn-ui"></div>',
1121
- ` <script type="module" src="/${UI_ENTRY.split(path2.sep).join("/")}"></script>`,
1671
+ ` <script type="module" src="/${UI_ENTRY.split(path4.sep).join("/")}"></script>`,
1122
1672
  " </body>",
1123
1673
  "</html>"
1124
1674
  ].join("\n")
1125
1675
  );
1126
- const driver = path2.join(buildRoot, "build-ui.mjs");
1676
+ const driver = path4.join(buildRoot, "build-ui.mjs");
1127
1677
  await writeFile(driver, uiBuildDriver(cwd, page, output));
1128
1678
  try {
1129
1679
  await run(process.execPath, [driver], cwd);
1130
1680
  } finally {
1131
1681
  await rm(page, { force: true });
1132
1682
  }
1133
- const generatedPage = path2.join(output, path2.basename(page));
1134
- const index = path2.join(output, "index.html");
1683
+ const generatedPage = path4.join(output, path4.basename(page));
1684
+ const index = path4.join(output, "index.html");
1135
1685
  await rename(generatedPage, index);
1136
1686
  return output;
1137
1687
  }
@@ -1171,14 +1721,94 @@ function uiBuildDriver(cwd, page, output) {
1171
1721
  ].join("\n")}
1172
1722
  `;
1173
1723
  }
1174
- async function buildWeb(cwd, viteArgs = []) {
1175
- const config = await loadConfig(cwd);
1724
+ async function buildWeb(cwd, viteArgs = [], profile) {
1725
+ const config = await loadConfig(cwd, { target: "web", profile });
1726
+ announceProfile(config);
1176
1727
  await compileAssets({ config: config.assets, cwd, platform: "web" });
1177
- await run(executable(cwd, "vite"), ["build", ...viteArgs], cwd);
1728
+ const assets = assetRoot(cwd, config);
1729
+ const outDir = path4.resolve(cwd, viteOutDir(viteArgs));
1730
+ const staging = stagingPath(outDir);
1731
+ const driver = path4.join(cwd, ".threenative", "build", "vite.web.mjs");
1732
+ try {
1733
+ await mkdir(path4.dirname(staging), { recursive: true });
1734
+ await mkdir(path4.dirname(driver), { recursive: true });
1735
+ await writeFile(driver, webBuildDriver(cwd, assets));
1736
+ await run(
1737
+ process.execPath,
1738
+ [
1739
+ path4.join(packageRoot(cwd, "vite"), "bin/vite.js"),
1740
+ "build",
1741
+ ...stagedViteArgs(viteArgs, staging),
1742
+ ...ownConfigArgs(viteArgs, driver, assets === path4.resolve(cwd, "public"))
1743
+ ],
1744
+ cwd
1745
+ );
1746
+ await pruneUnpackagedAssets(cwd, config, staging);
1747
+ const report = await writeCompressionSidecars(staging);
1748
+ if (report !== void 0) {
1749
+ process.stdout.write(
1750
+ `web main chunk ${report.entry}: raw ${report.raw} B, gzip ${report.gzip} B, brotli ${report.brotli} B
1751
+ `
1752
+ );
1753
+ }
1754
+ await assertArtifactBudget(cwd, config, outDir, staging, assets);
1755
+ await writeBuildReport({
1756
+ artifact: staging,
1757
+ assets,
1758
+ config,
1759
+ packagedAssetBytes: await measurePackagedAssetBytes(cwd, assets),
1760
+ target: "web"
1761
+ });
1762
+ await publishStagedArtifact(outDir, staging);
1763
+ } catch (error) {
1764
+ await rm(path4.dirname(staging), { force: true, recursive: true });
1765
+ throw error;
1766
+ }
1767
+ }
1768
+ function webBuildDriver(cwd, assets) {
1769
+ const literal = (value) => JSON.stringify(value);
1770
+ return `${[
1771
+ 'import { defineConfig, loadConfigFromFile, mergeConfig } from "vite";',
1772
+ "",
1773
+ `const root = ${literal(cwd)};`,
1774
+ `const assets = ${literal(assets)};`,
1775
+ "export default defineConfig(async ({ command, mode }) => {",
1776
+ " const own = (await loadConfigFromFile({ command, mode }, undefined, root))?.config ?? {};",
1777
+ " return mergeConfig(own, own.publicDir === undefined ? { publicDir: assets } : {});",
1778
+ "});",
1779
+ ""
1780
+ ].join("\n")}
1781
+ `;
1782
+ }
1783
+ function ownConfigArgs(viteArgs, driver, defaultRoot) {
1784
+ const named = viteArgs.some((arg) => arg === "--config" || arg.startsWith("--config="));
1785
+ return named || defaultRoot ? [] : ["--config", driver];
1786
+ }
1787
+ async function pruneUnpackagedAssets(cwd, config, outDir) {
1788
+ const assets = assetRoot(cwd, config);
1789
+ if (!existsSync(assets)) return;
1790
+ const selector = await packagingSelector(cwd);
1791
+ if (selector === void 0) return;
1792
+ for (const file of selector.selectManifestAssets(assets).dropped)
1793
+ await rm(path4.join(outDir, file), { force: true });
1794
+ }
1795
+ function viteOutDir(viteArgs) {
1796
+ const index = viteArgs.findIndex((arg) => arg === "--outDir" || arg.startsWith("--outDir="));
1797
+ if (index === -1) return "dist";
1798
+ const flag = viteArgs[index];
1799
+ return flag.startsWith("--outDir=") ? flag.slice("--outDir=".length) : viteArgs[index + 1] ?? "dist";
1800
+ }
1801
+ function stagedViteArgs(viteArgs, staging) {
1802
+ const index = viteArgs.findIndex((arg) => arg === "--outDir" || arg.startsWith("--outDir="));
1803
+ if (index === -1) return [...viteArgs, "--outDir", staging];
1804
+ const staged = [...viteArgs];
1805
+ if (staged[index].startsWith("--outDir=")) staged[index] = `--outDir=${staging}`;
1806
+ else staged[index + 1] = staging;
1807
+ return staged;
1178
1808
  }
1179
1809
  async function nativeEntry(cwd, config) {
1180
1810
  const relative = (config ?? await loadConfig(cwd)).nativeEntry;
1181
- const entry = path2.resolve(cwd, relative);
1811
+ const entry = path4.resolve(cwd, relative);
1182
1812
  try {
1183
1813
  if (!(await stat(entry)).isFile()) throw new Error("not a file");
1184
1814
  } catch {
@@ -1187,25 +1817,25 @@ async function nativeEntry(cwd, config) {
1187
1817
  return entry;
1188
1818
  }
1189
1819
  function resolvePackagingConfig(cwd, config) {
1190
- const resolve = (value) => value === void 0 ? void 0 : path2.resolve(cwd, value);
1820
+ const resolve = (value) => value === void 0 ? void 0 : path4.resolve(cwd, value);
1191
1821
  const artifact = {
1192
1822
  ...config,
1193
1823
  app: {
1194
1824
  ...config.app,
1195
- ...config.app.icon === void 0 ? {} : { icon: path2.resolve(cwd, config.app.icon) },
1825
+ ...config.app.icon === void 0 ? {} : { icon: path4.resolve(cwd, config.app.icon) },
1196
1826
  ...config.app.icons === void 0 ? {} : {
1197
1827
  icons: {
1198
1828
  ...config.app.icons.android === void 0 ? {} : {
1199
1829
  android: {
1200
- ...config.app.icons.android.foreground === void 0 ? {} : { foreground: path2.resolve(cwd, config.app.icons.android.foreground) },
1830
+ ...config.app.icons.android.foreground === void 0 ? {} : { foreground: path4.resolve(cwd, config.app.icons.android.foreground) },
1201
1831
  ...config.app.icons.android.background === void 0 ? {} : { background: config.app.icons.android.background },
1202
- ...config.app.icons.android.monochrome === void 0 ? {} : { monochrome: path2.resolve(cwd, config.app.icons.android.monochrome) }
1832
+ ...config.app.icons.android.monochrome === void 0 ? {} : { monochrome: path4.resolve(cwd, config.app.icons.android.monochrome) }
1203
1833
  }
1204
1834
  },
1205
1835
  ...config.app.icons.ios === void 0 ? {} : {
1206
1836
  ios: {
1207
- ...config.app.icons.ios.dark === void 0 ? {} : { dark: path2.resolve(cwd, config.app.icons.ios.dark) },
1208
- ...config.app.icons.ios.tinted === void 0 ? {} : { tinted: path2.resolve(cwd, config.app.icons.ios.tinted) }
1837
+ ...config.app.icons.ios.dark === void 0 ? {} : { dark: path4.resolve(cwd, config.app.icons.ios.dark) },
1838
+ ...config.app.icons.ios.tinted === void 0 ? {} : { tinted: path4.resolve(cwd, config.app.icons.ios.tinted) }
1209
1839
  }
1210
1840
  },
1211
1841
  ...config.app.icons.web === void 0 ? {} : {
@@ -1222,27 +1852,39 @@ function resolvePackagingConfig(cwd, config) {
1222
1852
  ...config.bootSplash === void 0 ? {} : {
1223
1853
  bootSplash: {
1224
1854
  ...config.bootSplash,
1225
- ...config.bootSplash.image === void 0 ? {} : { image: path2.resolve(cwd, config.bootSplash.image) }
1855
+ ...config.bootSplash.image === void 0 ? {} : { image: path4.resolve(cwd, config.bootSplash.image) }
1226
1856
  }
1227
1857
  }
1228
1858
  };
1229
1859
  return artifact;
1230
1860
  }
1231
1861
  async function writePackagingConfig(cwd, config) {
1232
- const directory = path2.join(cwd, ".threenative", "build");
1862
+ const directory = path4.join(cwd, ".threenative", "build");
1233
1863
  await mkdir(directory, { recursive: true });
1234
1864
  const artifact = resolvePackagingConfig(cwd, config);
1235
- const output = path2.join(directory, "config.json");
1865
+ const output = path4.join(directory, "config.json");
1236
1866
  await writeFile(output, `${JSON.stringify(artifact, null, 2)}
1237
1867
  `);
1238
1868
  return output;
1239
1869
  }
1240
- async function bundleNative(cwd, runtimeRoot, entry, target) {
1241
- const output = path2.join(cwd, ".threenative", "build", "game.js");
1870
+ function runtimeHasWebAssembly(binary = process.env.THREENATIVE_RUNTIME_BINARY, probe = spawnSync) {
1871
+ if (binary === void 0 || !existsSync(binary)) return true;
1872
+ let result;
1873
+ try {
1874
+ result = probe(binary, ["--version"], { encoding: "utf8" });
1875
+ } catch {
1876
+ return true;
1877
+ }
1878
+ if (result.status !== 0) return true;
1879
+ const engine = /\+ (\S+) build/u.exec(String(result.stdout ?? ""))?.[1] ?? "";
1880
+ return !/^(?:quickjs|jsc)$/iu.test(engine);
1881
+ }
1882
+ async function bundleNative(cwd, runtimeRoot, entry, target, nativeBackend) {
1883
+ const output = path4.join(cwd, ".threenative", "build", "game.js");
1242
1884
  await run(
1243
1885
  process.execPath,
1244
1886
  [
1245
- path2.join(runtimeRoot, "scripts", "bundle.mjs"),
1887
+ path4.join(runtimeRoot, "scripts", "bundle.mjs"),
1246
1888
  "--project",
1247
1889
  cwd,
1248
1890
  "--entry",
@@ -1250,31 +1892,92 @@ async function bundleNative(cwd, runtimeRoot, entry, target) {
1250
1892
  "--target",
1251
1893
  target,
1252
1894
  "--output",
1253
- output
1895
+ output,
1896
+ ...nativeBackend ? ["--native-backend"] : []
1254
1897
  ],
1255
1898
  cwd
1256
1899
  );
1257
1900
  return output;
1258
1901
  }
1259
- async function buildNative(target, cwd, allowSourceBuild = false) {
1260
- const config = await loadConfig(cwd);
1902
+ async function packagingSelector(cwd) {
1903
+ try {
1904
+ const module = path4.join(
1905
+ packageRoot(cwd, "@threenative/runtime-native"),
1906
+ "scripts",
1907
+ "asset-manifest.mjs"
1908
+ );
1909
+ return await import(pathToFileURL(module).href);
1910
+ } catch {
1911
+ return void 0;
1912
+ }
1913
+ }
1914
+ async function measurePackagedAssetBytes(cwd, assets) {
1915
+ if (!existsSync(assets)) return 0;
1916
+ const selector = await packagingSelector(cwd);
1917
+ if (selector === void 0) return measureTreeBytes(assets);
1918
+ let total = 0;
1919
+ for (const file of selector.selectManifestAssets(assets, { log: () => {
1920
+ } }).selected)
1921
+ total += (await stat(path4.join(assets, file))).size;
1922
+ return total;
1923
+ }
1924
+ function budgetSentence(metric, measured, limit) {
1925
+ return `threenative build: ${metric} measured ${measured} bytes over its ${limit}-byte limit.`;
1926
+ }
1927
+ async function assertArtifactBudget(cwd, config, final, staged, assets) {
1928
+ const budget = config.buildProfile?.artifactBudget;
1929
+ if (budget === void 0) return;
1930
+ const metrics = [
1931
+ {
1932
+ declared: budget.artifactBytes,
1933
+ measured: await measureTreeBytes(staged),
1934
+ name: "artifactBytes"
1935
+ },
1936
+ {
1937
+ declared: budget.packagedAssetBytes,
1938
+ measured: await measurePackagedAssetBytes(cwd, assets),
1939
+ name: "packagedAssetBytes"
1940
+ }
1941
+ ];
1942
+ for (const { declared, measured, name } of metrics) {
1943
+ if (declared === void 0 || measured <= declared.limit) continue;
1944
+ const sentence = budgetSentence(name, measured, declared.limit);
1945
+ if (declared.severity === "error") {
1946
+ throw new Error(
1947
+ `TN_BUILD_ARTIFACT_BUDGET_EXCEEDED: ${sentence} The build did not publish, so ${final} is still the previous artifact.`
1948
+ );
1949
+ }
1950
+ process.stdout.write(`${sentence}
1951
+ `);
1952
+ }
1953
+ }
1954
+ async function buildNative(target, cwd, allowSourceBuild = false, mode = "debug", format = "apk", profile) {
1955
+ const config = await loadConfig(cwd, { target, profile });
1956
+ announceProfile(config);
1261
1957
  assertNativeUiRendererCompatible(target, config.ui.renderer);
1262
- await compileAssets({ config: config.assets, cwd, platform: target });
1958
+ const webAssembly = runtimeHasWebAssembly();
1959
+ await compileAssets({
1960
+ config: config.assets,
1961
+ cwd,
1962
+ platform: target,
1963
+ ...webAssembly ? {} : { runtimeDecoders: { ktx2: false, meshopt: false } }
1964
+ });
1263
1965
  await assertNativeAssetsCompatible(cwd, target, config);
1264
1966
  const entry = await nativeEntry(cwd, config);
1265
1967
  const orientation = config.display.orientation;
1266
1968
  const configPath = await writePackagingConfig(cwd, config);
1267
1969
  const runtimeRoot = packageRoot(cwd, "@threenative/runtime-native");
1268
- const bundle = await bundleNative(cwd, runtimeRoot, entry, target);
1970
+ const bundle = await bundleNative(cwd, runtimeRoot, entry, target, !webAssembly);
1269
1971
  await assertNativeBundleCompatible(bundle, target);
1270
- const assets = path2.join(cwd, "public");
1972
+ const assets = assetRoot(cwd, config);
1271
1973
  const ui = config.ui.renderer === "web" ? await buildUi(cwd, config) : void 0;
1272
1974
  if (target === "ios") {
1273
- const output2 = path2.join(cwd, "dist-native", `${await projectName(cwd)}.app`);
1274
- await run(
1275
- process.execPath,
1975
+ const output2 = path4.join(cwd, "dist-native", `${await projectName(cwd)}.app`);
1976
+ await packageStaged(
1977
+ output2,
1978
+ runtimeRoot,
1276
1979
  [
1277
- path2.join(runtimeRoot, "scripts", "package-ios.mjs"),
1980
+ path4.join(runtimeRoot, "scripts", "package-ios.mjs"),
1278
1981
  "--bundle",
1279
1982
  bundle,
1280
1983
  "--assets",
@@ -1287,17 +1990,30 @@ async function buildNative(target, cwd, allowSourceBuild = false) {
1287
1990
  "--output",
1288
1991
  output2
1289
1992
  ],
1290
- runtimeRoot
1993
+ { assets, config, target: "ios" }
1291
1994
  );
1292
1995
  return;
1293
1996
  }
1294
1997
  if (target === "android") {
1295
- const output2 = path2.join(cwd, "dist-native", `${await projectName(cwd)}.apk`);
1296
- await run(
1297
- process.execPath,
1998
+ const output2 = path4.join(
1999
+ cwd,
2000
+ "dist-native",
2001
+ `${await projectName(cwd)}.${format === "aab" ? "aab" : "apk"}`
2002
+ );
2003
+ await packageStaged(
2004
+ output2,
2005
+ runtimeRoot,
1298
2006
  [
1299
- path2.join(runtimeRoot, "scripts", "package-android.mjs"),
2007
+ path4.join(runtimeRoot, "scripts", "package-android.mjs"),
1300
2008
  ...allowSourceBuild ? ["--allow-source-build"] : [],
2009
+ "--mode",
2010
+ mode,
2011
+ "--format",
2012
+ format,
2013
+ // The consumer project, so a relative keystore path in the signing environment resolves
2014
+ // against the game rather than the engine's Android project.
2015
+ "--project-root",
2016
+ cwd,
1301
2017
  "--bundle",
1302
2018
  bundle,
1303
2019
  "--assets",
@@ -1310,15 +2026,18 @@ async function buildNative(target, cwd, allowSourceBuild = false) {
1310
2026
  "--output",
1311
2027
  output2
1312
2028
  ],
1313
- runtimeRoot
2029
+ { assets, config, target: "android" }
1314
2030
  );
1315
2031
  return;
1316
2032
  }
1317
- const output = path2.join(cwd, "dist-native", await projectName(cwd));
1318
- await run(
1319
- process.execPath,
2033
+ const output = path4.join(cwd, "dist-native", await projectName(cwd));
2034
+ await packageStaged(
2035
+ output,
2036
+ cwd,
1320
2037
  [
1321
- path2.join(runtimeRoot, "scripts", "package-desktop.mjs"),
2038
+ path4.join(runtimeRoot, "scripts", "package-desktop.mjs"),
2039
+ "--mode",
2040
+ mode,
1322
2041
  "--bundle",
1323
2042
  bundle,
1324
2043
  "--assets",
@@ -1326,34 +2045,163 @@ async function buildNative(target, cwd, allowSourceBuild = false) {
1326
2045
  ...ui === void 0 ? [] : ["--ui", ui],
1327
2046
  "--config",
1328
2047
  configPath,
1329
- ...process.env.THREENATIVE_RUNTIME_BINARY ? ["--runtime", path2.resolve(process.env.THREENATIVE_RUNTIME_BINARY)] : [],
2048
+ ...process.env.THREENATIVE_RUNTIME_BINARY ? ["--runtime", path4.resolve(process.env.THREENATIVE_RUNTIME_BINARY)] : [],
1330
2049
  "--output",
1331
2050
  output
1332
2051
  ],
1333
- cwd
2052
+ { assets, config, target: "desktop" }
1334
2053
  );
1335
2054
  }
2055
+ async function packageStaged(output, cwd, args, report) {
2056
+ const staged = stagingPath(output);
2057
+ const index = args.indexOf("--output");
2058
+ if (index < 0 || index + 1 >= args.length) {
2059
+ throw new Error("packageStaged needs the packager's --output <path> argument to stage it.");
2060
+ }
2061
+ const packager = [...args];
2062
+ packager[index + 1] = staged;
2063
+ try {
2064
+ await mkdir(path4.dirname(staged), { recursive: true });
2065
+ await run(process.execPath, packager, cwd);
2066
+ if (report !== void 0) {
2067
+ const produced = await producedArtifact(staged);
2068
+ if (report.config.buildProfile?.artifactBudget !== void 0)
2069
+ await assertArtifactBudget(cwd, report.config, output, produced, report.assets);
2070
+ await writeBuildReport({
2071
+ artifact: produced,
2072
+ assets: report.assets,
2073
+ config: report.config,
2074
+ packagedAssetBytes: await measurePackagedAssetBytes(cwd, report.assets),
2075
+ target: report.target
2076
+ });
2077
+ }
2078
+ } catch (error) {
2079
+ await rm(path4.dirname(staged), { force: true, recursive: true });
2080
+ throw error;
2081
+ }
2082
+ await publishStagedArtifact(output, staged);
2083
+ }
2084
+ function stagingPath(final) {
2085
+ return path4.join(path4.dirname(final), `.staging-${process.pid}`, path4.basename(final));
2086
+ }
2087
+ async function producedArtifact(staged) {
2088
+ const directory = path4.dirname(staged);
2089
+ const name = path4.basename(staged);
2090
+ const entries = existsSync(directory) ? await readdir(directory) : [];
2091
+ for (const candidate of [name, `${name}.exe`, `${name}.app`, `${name}.tar.gz`, `${name}.zip`]) {
2092
+ if (entries.includes(candidate)) return path4.join(directory, candidate);
2093
+ }
2094
+ const other = entries.filter((entry) => !entry.endsWith(BUILD_REPORT_SUFFIX)).sort()[0];
2095
+ if (other === void 0) {
2096
+ throw new Error(
2097
+ `TN_BUILD_ARTIFACT_MISSING: the packager exited successfully but wrote no artifact to ${staged}.`
2098
+ );
2099
+ }
2100
+ return path4.join(directory, other);
2101
+ }
2102
+ async function publishStagedArtifact(final, staging) {
2103
+ const from = path4.dirname(staging);
2104
+ const produced = existsSync(from) ? await readdir(from) : [];
2105
+ if (!produced.some((name) => !name.endsWith(BUILD_REPORT_SUFFIX))) {
2106
+ throw new Error(
2107
+ `TN_BUILD_ARTIFACT_MISSING: the packager exited successfully but wrote no artifact to ${staging}; ${final} is unchanged.`
2108
+ );
2109
+ }
2110
+ const directory = path4.dirname(final);
2111
+ for (const name of produced) {
2112
+ const source = path4.join(from, name);
2113
+ const to = path4.join(directory, name);
2114
+ if (!existsSync(to)) {
2115
+ await rename(source, to);
2116
+ continue;
2117
+ }
2118
+ const previous = path4.join(from, `${name}.previous`);
2119
+ await rename(to, previous);
2120
+ try {
2121
+ await rename(source, to);
2122
+ } catch (error) {
2123
+ await rename(previous, to);
2124
+ throw error;
2125
+ }
2126
+ }
2127
+ await rm(from, { force: true, recursive: true });
2128
+ }
2129
+ var BUILD_LOCK = path4.join(".threenative", "build.lock");
2130
+ function pidAlive(pid) {
2131
+ try {
2132
+ process.kill(pid, 0);
2133
+ return true;
2134
+ } catch (error) {
2135
+ return error.code === "EPERM";
2136
+ }
2137
+ }
2138
+ async function acquireBuildLock(lock) {
2139
+ for (; ; ) {
2140
+ try {
2141
+ const handle = await open(lock, "wx");
2142
+ await handle.writeFile(String(process.pid));
2143
+ await handle.close();
2144
+ return;
2145
+ } catch (error) {
2146
+ if (error.code !== "EEXIST") throw error;
2147
+ const pid = Number.parseInt((await readFile(lock, "utf8").catch(() => "")).trim(), 10);
2148
+ if (Number.isSafeInteger(pid) && pid > 0 && pidAlive(pid)) {
2149
+ throw new Error(
2150
+ `TN_BUILD_BUSY: another threenative build (pid ${pid}) holds ${lock}. Wait for it to finish; if that process is gone, delete the lock.`
2151
+ );
2152
+ }
2153
+ await rm(lock, { force: true });
2154
+ }
2155
+ }
2156
+ }
1336
2157
  async function build(options) {
1337
2158
  if (options.allowSourceBuild && options.target !== "android") {
1338
2159
  throw new Error("--allow-source-build is supported only for --target android.");
1339
2160
  }
1340
- const cwd = path2.resolve(options.cwd ?? process.cwd());
1341
- if (options.target === "web") await buildWeb(cwd, options.viteArgs);
1342
- else {
1343
- if ((options.viteArgs?.length ?? 0) > 0) {
1344
- throw new Error(
1345
- `${options.target} build does not accept ${options.viteArgs?.join(" ")}. iOS output is simulator-only; device signing remains OPEN.`
2161
+ if (options.mode !== void 0 && options.target !== "android" && options.target !== "desktop" || options.format !== void 0 && options.target !== "android") {
2162
+ throw new Error(
2163
+ "--mode is supported only for --target android or desktop; --format only for --target android."
2164
+ );
2165
+ }
2166
+ const mode = options.mode ?? "debug";
2167
+ const format = options.format ?? "apk";
2168
+ if (format === "aab" && mode !== "release") {
2169
+ throw new Error("--format aab requires --mode release.");
2170
+ }
2171
+ if (options.target !== "web" && (options.viteArgs?.length ?? 0) > 0) {
2172
+ throw new Error(
2173
+ `${options.target} build does not accept ${options.viteArgs?.join(" ")}. iOS output is simulator-only; device signing remains OPEN.`
2174
+ );
2175
+ }
2176
+ const cwd = path4.resolve(options.cwd ?? process.cwd());
2177
+ const lock = path4.join(cwd, BUILD_LOCK);
2178
+ await mkdir(path4.dirname(lock), { recursive: true });
2179
+ await acquireBuildLock(lock);
2180
+ try {
2181
+ if (options.target === "web") await buildWeb(cwd, options.viteArgs, options.profile);
2182
+ else {
2183
+ await buildNative(
2184
+ options.target,
2185
+ cwd,
2186
+ options.allowSourceBuild === true,
2187
+ mode,
2188
+ format,
2189
+ options.profile
1346
2190
  );
1347
2191
  }
1348
- await buildNative(options.target, cwd, options.allowSourceBuild === true);
2192
+ } finally {
2193
+ await rm(lock, { force: true });
1349
2194
  }
1350
2195
  }
1351
2196
  function buildHelp() {
1352
2197
  return `${[
1353
- "Usage: threenative build [--target web|desktop|android|ios]",
2198
+ "Usage: threenative build [--target web|desktop|android|ios] [--mode debug|release] [--format apk|aab]",
1354
2199
  "",
1355
2200
  "Options:",
1356
2201
  " --target <target> Choose web, desktop, android, or ios (default: web).",
2202
+ " --mode <mode> debug (default) or release. Desktop release wraps the executable in one complete OS container.",
2203
+ " --format <format> Android only: apk (default) or aab. aab requires --mode release.",
2204
+ " --profile <name> A buildProfiles name; wins over buildProfiles.defaults for the target.",
1357
2205
  " --allow-source-build Explicitly allow Android maintainer source compilation.",
1358
2206
  " --help Show this help."
1359
2207
  ].join("\n")}
@@ -1372,12 +2220,37 @@ function parseBuildArgs(argv) {
1372
2220
  if (allowSourceBuild && value !== "android") {
1373
2221
  throw new Error("--allow-source-build is supported only for --target android.");
1374
2222
  }
2223
+ const mode = flagValue(argv, "--mode");
2224
+ if (mode !== void 0 && mode !== "debug" && mode !== "release") {
2225
+ throw new Error(`Unknown build mode '${mode}'. Choose debug or release.`);
2226
+ }
2227
+ const format = flagValue(argv, "--format");
2228
+ if (format !== void 0 && format !== "apk" && format !== "aab") {
2229
+ throw new Error(`Unknown build format '${format}'. Choose apk or aab.`);
2230
+ }
2231
+ const profile = flagValue(argv, "--profile");
2232
+ if (mode !== void 0 && value !== "android" && value !== "desktop" || format !== void 0 && value !== "android") {
2233
+ throw new Error(
2234
+ "--mode is supported only for --target android or desktop; --format only for --target android."
2235
+ );
2236
+ }
2237
+ if (format === "aab" && (mode ?? "debug") !== "release") {
2238
+ throw new Error("--format aab requires --mode release.");
2239
+ }
1375
2240
  const consumed = /* @__PURE__ */ new Set([0]);
1376
2241
  if (allowSourceBuild) {
1377
2242
  for (let index = 1; index < argv.length; index += 1) {
1378
2243
  if (argv[index] === "--allow-source-build") consumed.add(index);
1379
2244
  }
1380
2245
  }
2246
+ for (const flag of ["--mode", "--format", "--profile"]) {
2247
+ for (let index = 1; index < argv.length; index += 1) {
2248
+ if (argv[index] === flag) {
2249
+ consumed.add(index);
2250
+ consumed.add(index + 1);
2251
+ }
2252
+ }
2253
+ }
1381
2254
  if (targetIndex !== -1) {
1382
2255
  consumed.add(targetIndex);
1383
2256
  consumed.add(targetIndex + 1);
@@ -1385,9 +2258,19 @@ function parseBuildArgs(argv) {
1385
2258
  return {
1386
2259
  target: value,
1387
2260
  ...allowSourceBuild ? { allowSourceBuild: true } : {},
2261
+ ...mode === void 0 ? {} : { mode },
2262
+ ...format === void 0 ? {} : { format },
2263
+ ...profile === void 0 ? {} : { profile },
1388
2264
  viteArgs: argv.filter((_, index) => !consumed.has(index))
1389
2265
  };
1390
2266
  }
2267
+ function flagValue(argv, flag) {
2268
+ const index = argv.indexOf(flag);
2269
+ if (index === -1) return void 0;
2270
+ const value = argv[index + 1];
2271
+ if (value === void 0 || value.startsWith("--")) throw new Error(`${flag} requires a value.`);
2272
+ return value;
2273
+ }
1391
2274
 
1392
2275
  // src/commands.ts
1393
2276
  var threenativeCommands = ["build", "doctor"];
@@ -1424,13 +2307,13 @@ function binaryNames(platformName) {
1424
2307
  function pathCandidates(environment, platformName) {
1425
2308
  const raw = environment.PATH ?? environment.Path ?? "";
1426
2309
  if (raw.trim().length === 0) return [];
1427
- return raw.split(path2.delimiter).filter((directory) => directory.trim().length > 0).flatMap((directory) => binaryNames(platformName).map((name) => path2.join(directory, name)));
2310
+ return raw.split(path4.delimiter).filter((directory) => directory.trim().length > 0).flatMap((directory) => binaryNames(platformName).map((name) => path4.join(directory, name)));
1428
2311
  }
1429
2312
  function conventionalCandidates(platformName, home) {
1430
2313
  if (platformName === "darwin") {
1431
2314
  return [
1432
2315
  "/Applications/Blender.app/Contents/MacOS/Blender",
1433
- path2.join(home, "Applications/Blender.app/Contents/MacOS/Blender")
2316
+ path4.join(home, "Applications/Blender.app/Contents/MacOS/Blender")
1434
2317
  ];
1435
2318
  }
1436
2319
  if (platformName === "win32") {
@@ -1440,7 +2323,7 @@ function conventionalCandidates(platformName, home) {
1440
2323
  ];
1441
2324
  return roots.flatMap(
1442
2325
  (root) => ["5.2", "5.1", "5.0", "4.5", "4.2"].map(
1443
- (release) => path2.join(root, "Blender Foundation", `Blender ${release}`, "blender.exe")
2326
+ (release) => path4.join(root, "Blender Foundation", `Blender ${release}`, "blender.exe")
1444
2327
  )
1445
2328
  );
1446
2329
  }
@@ -1449,7 +2332,7 @@ function conventionalCandidates(platformName, home) {
1449
2332
  "/usr/local/bin/blender",
1450
2333
  "/snap/bin/blender",
1451
2334
  "/var/lib/flatpak/exports/bin/org.blender.Blender",
1452
- path2.join(home, ".local/bin/blender")
2335
+ path4.join(home, ".local/bin/blender")
1453
2336
  ];
1454
2337
  }
1455
2338
  function parseBlenderVersion(output) {
@@ -1482,7 +2365,7 @@ function resolveBlender(environment = process.env, options = {}) {
1482
2365
  const install = BLENDER_INSTALL_GUIDANCE;
1483
2366
  const override = environment.THREENATIVE_BLENDER_PATH;
1484
2367
  if (override !== void 0 && override.trim().length > 0) {
1485
- const candidate = path2.resolve(override.trim());
2368
+ const candidate = path4.resolve(override.trim());
1486
2369
  if (!executableFile(candidate)) {
1487
2370
  return {
1488
2371
  available: false,
@@ -1576,10 +2459,10 @@ var MCP_SERVERS = Object.freeze({
1576
2459
  })
1577
2460
  });
1578
2461
  var MCP_PACKAGES = Object.freeze({
1579
- assets: Object.freeze({ name: "threenative-asset-mcp", version: "0.8.0" }),
2462
+ assets: Object.freeze({ name: "threenative-asset-mcp", version: "0.9.5" }),
1580
2463
  sculpt: Object.freeze({ name: "threenative-sculpt-mcp", version: "0.1.1" }),
1581
- engine: Object.freeze({ name: "threenative-engine-mcp", version: "0.2.2" }),
1582
- blender: Object.freeze({ name: "threenative-blender-mcp", version: "0.1.2" })
2464
+ engine: Object.freeze({ name: "threenative-engine-mcp", version: "0.2.4" }),
2465
+ blender: Object.freeze({ name: "threenative-blender-mcp", version: "0.1.4" })
1583
2466
  });
1584
2467
  var SERVER_FORMATS = Object.freeze({
1585
2468
  // Claude Code (`.mcp.json`), Cursor and the Gemini CLI all read this one.
@@ -1699,9 +2582,29 @@ var DEFAULT_NATIVE_ENTRY = "src/game.ts";
1699
2582
  var RUNTIME_PACKAGE = "@threenative/runtime-native";
1700
2583
  var PLAYTEST_BINARY = "threenative-playtest";
1701
2584
  var ANDROID_JDK_MAJOR = 17;
1702
- var ANDROID_COMPILE_SDK = 35;
2585
+ var DEFAULT_ANDROID_COMPILE_SDK = 36;
2586
+ function androidGradleSdk(source) {
2587
+ if (source === void 0) return void 0;
2588
+ const target = /targetSdk\s*=\s*(\d+)/u.exec(source);
2589
+ const compile = /compileSdk\s*=\s*(\d+)/u.exec(source);
2590
+ const value = target?.[1] ?? compile?.[1];
2591
+ return value === void 0 ? void 0 : Number(value);
2592
+ }
2593
+ function requiredAndroidSdk(snapshot) {
2594
+ return androidGradleSdk(snapshot.readRuntimeText?.("android/app/build.gradle.kts")) ?? DEFAULT_ANDROID_COMPILE_SDK;
2595
+ }
2596
+ function requiredAndroidSdkFromRoot(root) {
2597
+ if (root === void 0) return DEFAULT_ANDROID_COMPILE_SDK;
2598
+ try {
2599
+ return androidGradleSdk(
2600
+ readFileSync(path4.join(root, "android", "app", "build.gradle.kts"), "utf8")
2601
+ ) ?? DEFAULT_ANDROID_COMPILE_SDK;
2602
+ } catch {
2603
+ return DEFAULT_ANDROID_COMPILE_SDK;
2604
+ }
2605
+ }
1703
2606
  var CORE_PACKAGE_NAME = "@threenative/core";
1704
- var CORE_PACKAGE_VERSION = "0.3.2";
2607
+ var CORE_PACKAGE_VERSION = "0.3.4";
1705
2608
  var CORE_RESOLVED_SERVERS = /* @__PURE__ */ new Set([
1706
2609
  "threenative-engine",
1707
2610
  "threenative-blender"
@@ -1762,26 +2665,60 @@ for (const host of MCP_HOSTS) {
1762
2665
  var SHAPE_VERIFIABLE_HOSTS = MCP_HOSTS.filter(
1763
2666
  ({ format }) => format === "mcpServers"
1764
2667
  );
2668
+ var X11_COMPOSITOR_PROBE = [
2669
+ "import ctypes, ctypes.util, sys",
2670
+ 'path = ctypes.util.find_library("X11")',
2671
+ "if not path:",
2672
+ " print('unknown'); sys.exit(0)",
2673
+ "x = ctypes.CDLL(path)",
2674
+ "x.XOpenDisplay.restype = ctypes.c_void_p",
2675
+ "x.XOpenDisplay.argtypes = [ctypes.c_char_p]",
2676
+ "display = x.XOpenDisplay(None)",
2677
+ "if not display:",
2678
+ " print('unknown'); sys.exit(0)",
2679
+ "x.XDefaultScreen.restype = ctypes.c_int",
2680
+ "x.XDefaultScreen.argtypes = [ctypes.c_void_p]",
2681
+ "screen = x.XDefaultScreen(display)",
2682
+ "x.XInternAtom.restype = ctypes.c_ulong",
2683
+ "x.XInternAtom.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]",
2684
+ 'atom = x.XInternAtom(display, ("_NET_WM_CM_S%d" % screen).encode(), 0)',
2685
+ "x.XGetSelectionOwner.restype = ctypes.c_ulong",
2686
+ "x.XGetSelectionOwner.argtypes = [ctypes.c_void_p, ctypes.c_ulong]",
2687
+ "owner = x.XGetSelectionOwner(display, atom)",
2688
+ "x.XCloseDisplay.argtypes = [ctypes.c_void_p]",
2689
+ "x.XCloseDisplay(display)",
2690
+ "print('1' if owner else '0')"
2691
+ ].join("\n");
1765
2692
  function detectX11Compositor(environment = process.env) {
1766
2693
  if (environment.DISPLAY === void 0) return void 0;
1767
2694
  try {
1768
- const output = execFileSync("xprop", ["-root", "_NET_WM_CM_S0"], {
2695
+ const output = execFileSync("python3", ["-c", X11_COMPOSITOR_PROBE], {
1769
2696
  encoding: "utf8",
1770
2697
  env: { ...environment },
1771
2698
  stdio: ["ignore", "pipe", "pipe"]
1772
2699
  });
1773
- return /window id\s*#/u.test(output);
1774
- } catch (error) {
1775
- return error.code === "ENOENT" ? void 0 : false;
2700
+ const answer = output.trim();
2701
+ if (answer === "1") return true;
2702
+ if (answer === "0") return false;
2703
+ return void 0;
2704
+ } catch {
2705
+ return void 0;
1776
2706
  }
1777
2707
  }
1778
2708
  function probeDesktopOverlay(environment = process.env, compositor = detectX11Compositor) {
1779
2709
  const wayland = environment.WAYLAND_DISPLAY !== void 0 || environment.XDG_SESSION_TYPE === "wayland";
1780
2710
  if (wayland) {
2711
+ if (environment.DISPLAY === void 0) {
2712
+ return {
2713
+ detail: "a Wayland session without an X11 display (Xwayland) cannot host the desktop overlay",
2714
+ fix: "Enable Xwayland for this session or use the web UI target.",
2715
+ status: "fail"
2716
+ };
2717
+ }
1781
2718
  return {
1782
- detail: "the transparent container could not be created on this Wayland/Xwayland session",
1783
- fix: "Run the desktop target under an X11 session (for example SDL_VIDEODRIVER=x11) or use the web UI target.",
1784
- status: "fail"
2719
+ detail: "the runtime selects Xwayland (SDL x11, GDK_BACKEND=x11) and the Wayland compositor blends the overlay's alpha",
2720
+ fix: "",
2721
+ status: "ok"
1785
2722
  };
1786
2723
  }
1787
2724
  if (environment.DISPLAY === void 0) {
@@ -1802,13 +2739,13 @@ function probeDesktopOverlay(environment = process.env, compositor = detectX11Co
1802
2739
  if (present === false) {
1803
2740
  return {
1804
2741
  detail: "no compositing manager is running, so nothing would blend the overlay",
1805
- fix: "Start a compositing manager or run the desktop target under a composited X11 session.",
2742
+ fix: "Start a compositing manager (xcompmgr -n, picom or compton -- the three the repository's own private displays borrow) or run the desktop target under a composited X11 session.",
1806
2743
  status: "fail"
1807
2744
  };
1808
2745
  }
1809
2746
  return {
1810
2747
  detail: "the X11 compositor probe could not run, so overlay transparency is unknown",
1811
- fix: "Install xprop and rerun doctor in the desktop display session.",
2748
+ fix: "Install python3 and rerun doctor in the desktop display session.",
1812
2749
  status: "warn"
1813
2750
  };
1814
2751
  }
@@ -1838,11 +2775,11 @@ function nativeEntryCompat(value) {
1838
2775
  return typeof entry === "string" && entry.length > 0 ? { nativeEntry: entry } : void 0;
1839
2776
  }
1840
2777
  function resolvePackageDirectoryFrom(start, name) {
1841
- let directory = path2.resolve(start);
2778
+ let directory = path4.resolve(start);
1842
2779
  while (true) {
1843
- const candidate = path2.join(directory, "node_modules", name);
1844
- if (existsSync(path2.join(candidate, "package.json"))) return candidate;
1845
- const parent = path2.dirname(directory);
2780
+ const candidate = path4.join(directory, "node_modules", name);
2781
+ if (existsSync(path4.join(candidate, "package.json"))) return candidate;
2782
+ const parent = path4.dirname(directory);
1846
2783
  if (parent === directory) return void 0;
1847
2784
  directory = parent;
1848
2785
  }
@@ -1863,13 +2800,13 @@ function resolvePackageDirectory(snapshot, name) {
1863
2800
  }
1864
2801
  }
1865
2802
  function resolveBinaryFrom(start, name) {
1866
- let directory = path2.resolve(start);
2803
+ let directory = path4.resolve(start);
1867
2804
  while (true) {
1868
- const binDirectory = path2.join(directory, "node_modules", ".bin");
1869
- const candidates = process.platform === "win32" ? [path2.join(binDirectory, `${name}.cmd`), path2.join(binDirectory, name)] : [path2.join(binDirectory, name)];
2805
+ const binDirectory = path4.join(directory, "node_modules", ".bin");
2806
+ const candidates = process.platform === "win32" ? [path4.join(binDirectory, `${name}.cmd`), path4.join(binDirectory, name)] : [path4.join(binDirectory, name)];
1870
2807
  const found = candidates.find((candidate) => existsSync(candidate));
1871
2808
  if (found !== void 0) return found;
1872
- const parent = path2.dirname(directory);
2809
+ const parent = path4.dirname(directory);
1873
2810
  if (parent === directory) return void 0;
1874
2811
  directory = parent;
1875
2812
  }
@@ -1942,7 +2879,7 @@ function mcpServerCheck(snapshot, spec, value, file) {
1942
2879
  status: "fail"
1943
2880
  };
1944
2881
  }
1945
- if (snapshot.projectRoot !== void 0 && !existsSync(path2.resolve(snapshot.projectRoot, spec.expectedArgs))) {
2882
+ if (snapshot.projectRoot !== void 0 && !existsSync(path4.resolve(snapshot.projectRoot, spec.expectedArgs))) {
1946
2883
  return {
1947
2884
  detail: `${spec.configName} points at missing ${spec.expectedArgs}; @threenative/core is not providing the configured server shim`,
1948
2885
  fix: "Install @threenative/core again so the generated MCP server entry exists.",
@@ -1968,7 +2905,7 @@ function mcpServerCheck(snapshot, spec, value, file) {
1968
2905
  status: "warn"
1969
2906
  };
1970
2907
  }
1971
- const manifest = readJsonSync(path2.join(packageDirectory, "package.json"));
2908
+ const manifest = readJsonSync(path4.join(packageDirectory, "package.json"));
1972
2909
  const installedVersion = record(manifest)?.version;
1973
2910
  if (typeof installedVersion !== "string") {
1974
2911
  return {
@@ -1999,7 +2936,7 @@ function probeMcpServer(projectRoot, spec) {
1999
2936
  method: "initialize",
2000
2937
  params: {
2001
2938
  capabilities: {},
2002
- clientInfo: { name: "threenative-doctor", version: "0.3.2" },
2939
+ clientInfo: { name: "threenative-doctor", version: "0.3.4" },
2003
2940
  protocolVersion: "2025-06-18"
2004
2941
  }
2005
2942
  });
@@ -2129,10 +3066,10 @@ function configuredTargets(snapshot) {
2129
3066
  function directoryCanBeWritten(snapshot, relative) {
2130
3067
  if (snapshot.directoryWritable !== void 0) return snapshot.directoryWritable(relative);
2131
3068
  if (snapshot.projectRoot === void 0) return void 0;
2132
- const root = path2.resolve(snapshot.projectRoot);
2133
- let candidate = path2.resolve(root, relative);
2134
- if (candidate !== root && !candidate.startsWith(`${root}${path2.sep}`)) return false;
2135
- while (candidate !== root && !existsSync(candidate)) candidate = path2.dirname(candidate);
3069
+ const root = path4.resolve(snapshot.projectRoot);
3070
+ let candidate = path4.resolve(root, relative);
3071
+ if (candidate !== root && !candidate.startsWith(`${root}${path4.sep}`)) return false;
3072
+ while (candidate !== root && !existsSync(candidate)) candidate = path4.dirname(candidate);
2136
3073
  if (!existsSync(candidate)) return false;
2137
3074
  try {
2138
3075
  if (!statSync(candidate).isDirectory()) return false;
@@ -2185,7 +3122,7 @@ function assetPipelineCheck(snapshot) {
2185
3122
  status
2186
3123
  };
2187
3124
  }
2188
- function androidToolchainFacts(probe) {
3125
+ function androidToolchainFacts(probe, requiredSdk = DEFAULT_ANDROID_COMPILE_SDK) {
2189
3126
  const details = [];
2190
3127
  const blockers = [];
2191
3128
  let status = probe.status ?? "ok";
@@ -2203,20 +3140,20 @@ function androidToolchainFacts(probe) {
2203
3140
  details.push(`JDK ${probe.jdkVersion} found (supported JDK ${ANDROID_JDK_MAJOR})`);
2204
3141
  }
2205
3142
  if (probe.sdkVersion === void 0) {
2206
- const blocker = `Android SDK platform android-${ANDROID_COMPILE_SDK} not found`;
3143
+ const blocker = `Android SDK platform android-${requiredSdk} not found`;
2207
3144
  details.push(blocker);
2208
3145
  blockers.push(blocker);
2209
3146
  status = "warn";
2210
3147
  } else {
2211
- details.push(`Android SDK platform android-${ANDROID_COMPILE_SDK} ${probe.sdkVersion} found`);
3148
+ details.push(`Android SDK platform android-${requiredSdk} ${probe.sdkVersion} found`);
2212
3149
  }
2213
3150
  return { blockers, details, status };
2214
3151
  }
2215
- function androidToolchainStatus(probe) {
2216
- const { details, status } = androidToolchainFacts(probe);
3152
+ function androidToolchainStatus(probe, requiredSdk = DEFAULT_ANDROID_COMPILE_SDK) {
3153
+ const { details, status } = androidToolchainFacts(probe, requiredSdk);
2217
3154
  return {
2218
3155
  detail: details.join("; "),
2219
- fix: status === "ok" ? void 0 : `Install Android SDK platform android-${ANDROID_COMPILE_SDK} and JDK ${ANDROID_JDK_MAJOR}, or set ANDROID_HOME or ANDROID_SDK_ROOT and JAVA_HOME (or put JDK ${ANDROID_JDK_MAJOR} on PATH).`,
3156
+ fix: status === "ok" ? void 0 : `Install Android SDK platform android-${requiredSdk} and JDK ${ANDROID_JDK_MAJOR}, or set ANDROID_HOME or ANDROID_SDK_ROOT and JAVA_HOME (or put JDK ${ANDROID_JDK_MAJOR} on PATH).`,
2220
3157
  name: "android toolchain",
2221
3158
  status
2222
3159
  };
@@ -2266,6 +3203,53 @@ function executePlaytestDoctor(runner, projectRoot, capturePath) {
2266
3203
  timeout: 3e4
2267
3204
  });
2268
3205
  }
3206
+ var SCENE_WARNING_MARKER = "TN_SCENE_WARNING";
3207
+ function sceneShapeCheck(snapshot) {
3208
+ let latest;
3209
+ for (const file of snapshot.files) {
3210
+ if (!file.endsWith(".log") && !file.endsWith(".txt") && !file.endsWith(".json")) continue;
3211
+ const text = snapshot.readText(file);
3212
+ if (text === void 0 || !text.includes(SCENE_WARNING_MARKER)) continue;
3213
+ for (const line of text.split("\n")) {
3214
+ const at = line.indexOf(`${SCENE_WARNING_MARKER}:`);
3215
+ if (at >= 0) latest = line.slice(at + SCENE_WARNING_MARKER.length + 1).trim();
3216
+ }
3217
+ }
3218
+ if (latest === void 0) {
3219
+ return {
3220
+ detail: "no recorded run carries a scene verdict yet",
3221
+ name: "scene shape",
3222
+ status: "ok"
3223
+ };
3224
+ }
3225
+ let verdict;
3226
+ try {
3227
+ verdict = JSON.parse(latest);
3228
+ } catch {
3229
+ return {
3230
+ detail: `a ${SCENE_WARNING_MARKER} line was recorded but could not be read: ${latest.slice(0, 120)}`,
3231
+ fix: "Re-run the game and keep its stdout; the marker is one JSON object on one line.",
3232
+ name: "scene shape",
3233
+ status: "warn"
3234
+ };
3235
+ }
3236
+ if (typeof verdict !== "object" || verdict === null || !("dominantTerm" in verdict)) {
3237
+ return {
3238
+ detail: `a ${SCENE_WARNING_MARKER} line was recorded without a verdict in it`,
3239
+ name: "scene shape",
3240
+ status: "warn"
3241
+ };
3242
+ }
3243
+ const term = String(verdict.dominantTerm);
3244
+ const renderMs = "renderMs" in verdict ? String(verdict.renderMs) : "?";
3245
+ const gpuShare = "gpuShare" in verdict ? String(verdict.gpuShare) : "?";
3246
+ return {
3247
+ detail: `the last window was CPU-bound on scene shape: render ${renderMs} ms with the GPU at ${gpuShare} of the frame, dominated by ${term}`,
3248
+ fix: "Reduce the dominant term before tuning the renderer: fewer objects and fewer draws, not different render settings.",
3249
+ name: "scene shape",
3250
+ status: "warn"
3251
+ };
3252
+ }
2269
3253
  function playtestCheck(snapshot, capturePath) {
2270
3254
  const runner = playtestRunner(snapshot);
2271
3255
  if (runner === void 0) return missingPlaytestCheck(snapshot);
@@ -2298,13 +3282,13 @@ function parseApkSizeRecord(source) {
2298
3282
  const bytesText = bytesMatch[1];
2299
3283
  const artifact = artifactMatch[1];
2300
3284
  const buildDirectory = buildDirectoryMatch[1];
2301
- const sha256 = sha256Match[1];
2302
- if (bytesText === void 0 || artifact === void 0 || buildDirectory === void 0 || sha256 === void 0)
3285
+ const sha2562 = sha256Match[1];
3286
+ if (bytesText === void 0 || artifact === void 0 || buildDirectory === void 0 || sha2562 === void 0)
2303
3287
  return void 0;
2304
3288
  const bytes = Number(bytesText.replaceAll(",", ""));
2305
3289
  if (!Number.isSafeInteger(bytes) || bytes <= 0) return void 0;
2306
3290
  if (artifact.length === 0 || buildDirectory.length === 0) return void 0;
2307
- return { artifact, buildDirectory, bytes, sha256: sha256.toLowerCase() };
3291
+ return { artifact, buildDirectory, bytes, sha256: sha2562.toLowerCase() };
2308
3292
  }
2309
3293
  function sha256File(file) {
2310
3294
  const hash = createHash("sha256");
@@ -2322,10 +3306,10 @@ function sha256File(file) {
2322
3306
  }
2323
3307
  }
2324
3308
  function evidencePath(snapshot, relative) {
2325
- if (snapshot.projectRoot === void 0 || path2.isAbsolute(relative)) return void 0;
2326
- const root = path2.resolve(snapshot.projectRoot);
2327
- const resolved = path2.resolve(root, relative);
2328
- return resolved === root || resolved.startsWith(`${root}${path2.sep}`) ? resolved : void 0;
3309
+ if (snapshot.projectRoot === void 0 || path4.isAbsolute(relative)) return void 0;
3310
+ const root = path4.resolve(snapshot.projectRoot);
3311
+ const resolved = path4.resolve(root, relative);
3312
+ return resolved === root || resolved.startsWith(`${root}${path4.sep}`) ? resolved : void 0;
2329
3313
  }
2330
3314
  function evidenceExists(snapshot, relative, directory) {
2331
3315
  const absolute = evidencePath(snapshot, relative);
@@ -2459,6 +3443,20 @@ function nativeRuntimeKey() {
2459
3443
  function nativeRuntimeFilename() {
2460
3444
  return process.platform === "win32" ? "threenative-runtime.exe" : "threenative-runtime";
2461
3445
  }
3446
+ var NATIVE_HOST_PROBE_TIMEOUT_MS = 2e4;
3447
+ function probeNativeHost(binary) {
3448
+ try {
3449
+ const output = execFileSync(binary, ["--version"], {
3450
+ encoding: "utf8",
3451
+ stdio: ["ignore", "pipe", "pipe"],
3452
+ timeout: NATIVE_HOST_PROBE_TIMEOUT_MS
3453
+ });
3454
+ const runtimeVersion = output.match(/Native Runtime v(\d+\.\d+(?:\.\d+)?)/u)?.[1];
3455
+ return runtimeVersion === void 0 ? { reason: "the host did not name its runtime version" } : { runtimeVersion };
3456
+ } catch (error) {
3457
+ return { reason: error instanceof Error ? error.message : String(error) };
3458
+ }
3459
+ }
2462
3460
  function nativeRuntimeCheck(snapshot) {
2463
3461
  const key = nativeRuntimeKey();
2464
3462
  if (snapshot.runtimeRoot === void 0 || snapshot.readRuntimeText === void 0) {
@@ -2540,7 +3538,7 @@ function nativeRuntimeCheck(snapshot) {
2540
3538
  };
2541
3539
  }
2542
3540
  const binary = `prebuilt/${key}/${nativeRuntimeFilename()}`;
2543
- const exists = snapshot.runtimeFileExists?.(binary) ?? existsSync(path2.join(snapshot.runtimeRoot, binary));
3541
+ const exists = snapshot.runtimeFileExists?.(binary) ?? existsSync(path4.join(snapshot.runtimeRoot, binary));
2544
3542
  if (!exists) {
2545
3543
  return {
2546
3544
  detail: `unavailable \u2014 ${key} prebuilt binary is missing`,
@@ -2549,7 +3547,72 @@ function nativeRuntimeCheck(snapshot) {
2549
3547
  status: "fail"
2550
3548
  };
2551
3549
  }
2552
- return { detail: `available (${key})`, name: "native runtime", status: "ok" };
3550
+ const host = snapshot.nativeHost ?? probeNativeHost(path4.join(snapshot.runtimeRoot, binary));
3551
+ const reported = host.runtimeVersion;
3552
+ if (reported === void 0) {
3553
+ return {
3554
+ detail: `unavailable \u2014 the ${key} host did not report a runtime version (${host.reason ?? "no reason given"})`,
3555
+ fix: "Reinstall the native runtime, or build it from source with `pnpm --filter @threenative/runtime-native native:build`: doctor cannot vouch for a host it cannot identify.",
3556
+ name: "native runtime",
3557
+ status: "fail"
3558
+ };
3559
+ }
3560
+ const required = newestVersion([
3561
+ snapshot.installedVersions.get(RUNTIME_PACKAGE),
3562
+ snapshot.installedVersions.get(CORE_PACKAGE_NAME)
3563
+ ]);
3564
+ const lags = required === void 0 ? void 0 : hostIsOlder(reported, required);
3565
+ if (lags !== false) {
3566
+ return {
3567
+ detail: lags === true ? `unavailable \u2014 the ${key} host reports runtime v${reported}, older than the installed engine ${String(required)}` : `unavailable \u2014 the ${key} host reports runtime v${reported}, which cannot be compared with the installed engine ${String(required)}`,
3568
+ fix: "Install a native runtime at least as new as the engine, or build one from source with `pnpm --filter @threenative/runtime-native native:build`. A host older than the engine builds a desktop binary whose UI never appears.",
3569
+ name: "native runtime",
3570
+ status: "fail"
3571
+ };
3572
+ }
3573
+ return {
3574
+ detail: `available (${key}, host runtime v${reported})`,
3575
+ name: "native runtime",
3576
+ status: "ok"
3577
+ };
3578
+ }
3579
+ function versionParts(value) {
3580
+ const match = /^(\d+)\.(\d+)\.(\d+)/u.exec(value.trim());
3581
+ if (match === null) return void 0;
3582
+ const parts = [Number(match[1]), Number(match[2]), Number(match[3])];
3583
+ return parts.every(Number.isSafeInteger) ? parts : void 0;
3584
+ }
3585
+ function newestVersion(versions) {
3586
+ let best;
3587
+ let bestParts;
3588
+ for (const candidate of versions) {
3589
+ if (candidate === void 0) continue;
3590
+ const parts = versionParts(candidate);
3591
+ if (parts === void 0) continue;
3592
+ if (bestParts === void 0 || isNewer(parts, bestParts)) {
3593
+ best = candidate;
3594
+ bestParts = parts;
3595
+ }
3596
+ }
3597
+ return best;
3598
+ }
3599
+ function isNewer(left, right) {
3600
+ const [leftMajor, leftMinor, leftPatch] = left;
3601
+ const [rightMajor, rightMinor, rightPatch] = right;
3602
+ if (leftMajor !== rightMajor) return leftMajor > rightMajor;
3603
+ if (leftMinor !== rightMinor) return leftMinor > rightMinor;
3604
+ return leftPatch > rightPatch;
3605
+ }
3606
+ function hostIsOlder(host, required) {
3607
+ const hostParts = versionParts(host);
3608
+ const requiredParts = versionParts(required);
3609
+ if (hostParts === void 0 || requiredParts === void 0) return void 0;
3610
+ const [hostMajor, hostMinor, hostPatch] = hostParts;
3611
+ const [requiredMajor, requiredMinor, requiredPatch] = requiredParts;
3612
+ if (hostMajor !== requiredMajor) return hostMajor < requiredMajor;
3613
+ if (hostMinor !== requiredMinor) return hostMinor < requiredMinor;
3614
+ if (hostPatch !== requiredPatch) return hostPatch < requiredPatch;
3615
+ return /[-+]/u.test(host.trim()) && !/[-+]/u.test(required.trim());
2553
3616
  }
2554
3617
  function javaVersion(output) {
2555
3618
  const match = output.match(/version\s+["']([^"']+)["']/iu);
@@ -2560,11 +3623,11 @@ function javaVersion(output) {
2560
3623
  const major = majorText === void 0 ? Number.NaN : Number(majorText);
2561
3624
  return Number.isSafeInteger(major) ? { major, version } : void 0;
2562
3625
  }
2563
- function androidSdkVersion(root) {
2564
- const sourceProperties = path2.join(
3626
+ function androidSdkVersion(root, requiredSdk) {
3627
+ const sourceProperties = path4.join(
2565
3628
  root,
2566
3629
  "platforms",
2567
- `android-${ANDROID_COMPILE_SDK}`,
3630
+ `android-${requiredSdk}`,
2568
3631
  "source.properties"
2569
3632
  );
2570
3633
  try {
@@ -2575,9 +3638,9 @@ function androidSdkVersion(root) {
2575
3638
  return void 0;
2576
3639
  }
2577
3640
  }
2578
- function probeAndroidToolchain(environment = process.env) {
3641
+ function probeAndroidToolchain(environment = process.env, requiredSdk = DEFAULT_ANDROID_COMPILE_SDK) {
2579
3642
  const javaHome = environment.JAVA_HOME?.trim() || void 0;
2580
- const java = javaHome === void 0 ? "java" : path2.join(javaHome, "bin", process.platform === "win32" ? "java.exe" : "java");
3643
+ const java = javaHome === void 0 ? "java" : path4.join(javaHome, "bin", process.platform === "win32" ? "java.exe" : "java");
2581
3644
  let jdkMajor;
2582
3645
  let jdkVersion;
2583
3646
  try {
@@ -2595,18 +3658,18 @@ function probeAndroidToolchain(environment = process.env) {
2595
3658
  const sdkCandidates = [
2596
3659
  environment.ANDROID_HOME,
2597
3660
  environment.ANDROID_SDK_ROOT,
2598
- path2.join(homedir(), "Android", "Sdk")
3661
+ path4.join(homedir(), "Android", "Sdk")
2599
3662
  ].map((candidate) => candidate?.trim()).filter((candidate) => candidate !== void 0 && candidate.length > 0);
2600
3663
  const sdkRoot = sdkCandidates.find((candidate) => existsSync(candidate));
2601
3664
  return {
2602
3665
  ...jdkMajor === void 0 ? {} : { jdkMajor },
2603
3666
  ...jdkVersion === void 0 ? {} : { jdkVersion },
2604
- ...sdkRoot === void 0 ? {} : { sdkVersion: androidSdkVersion(sdkRoot) }
3667
+ ...sdkRoot === void 0 ? {} : { sdkVersion: androidSdkVersion(sdkRoot, requiredSdk) }
2605
3668
  };
2606
3669
  }
2607
3670
  function runtimeFileAvailable(snapshot, relative) {
2608
3671
  if (snapshot.runtimeRoot === void 0) return false;
2609
- return snapshot.runtimeFileExists?.(relative) ?? existsSync(path2.join(snapshot.runtimeRoot, relative));
3672
+ return snapshot.runtimeFileExists?.(relative) ?? existsSync(path4.join(snapshot.runtimeRoot, relative));
2610
3673
  }
2611
3674
  function androidTargetCheck(snapshot) {
2612
3675
  if (!runtimeFileAvailable(snapshot, "scripts/package-android.mjs")) {
@@ -2616,8 +3679,9 @@ function androidTargetCheck(snapshot) {
2616
3679
  status: snapshot.runtimeRoot === void 0 ? "warn" : "fail"
2617
3680
  };
2618
3681
  }
2619
- const androidToolchain = snapshot.androidToolchain ?? (snapshot.projectRoot === void 0 ? void 0 : probeAndroidToolchain());
2620
- const toolchain = androidToolchain === void 0 ? void 0 : androidToolchainStatus(androidToolchain);
3682
+ const requiredSdk = requiredAndroidSdk(snapshot);
3683
+ const androidToolchain = snapshot.androidToolchain ?? (snapshot.projectRoot === void 0 ? void 0 : probeAndroidToolchain(process.env, requiredSdk));
3684
+ const toolchain = androidToolchain === void 0 ? void 0 : androidToolchainStatus(androidToolchain, requiredSdk);
2621
3685
  return {
2622
3686
  detail: toolchain === void 0 ? "available \u2014 runtime packager installed; Android toolchain was not probed in this in-memory snapshot" : `available \u2014 runtime packager installed; ${toolchain.detail}`,
2623
3687
  ...toolchain?.fix === void 0 ? {} : { fix: toolchain.fix },
@@ -2667,9 +3731,10 @@ function requestedBuildBlockers(snapshot, request, nativeRuntime) {
2667
3731
  }
2668
3732
  if (!runtimeFileAvailable(snapshot, "scripts/package-android.mjs"))
2669
3733
  blockers.push(`${RUNTIME_PACKAGE} has no Android packager`);
2670
- const androidToolchain = snapshot.androidToolchain ?? (snapshot.projectRoot === void 0 ? void 0 : probeAndroidToolchain());
3734
+ const requiredSdk = requiredAndroidSdk(snapshot);
3735
+ const androidToolchain = snapshot.androidToolchain ?? (snapshot.projectRoot === void 0 ? void 0 : probeAndroidToolchain(process.env, requiredSdk));
2671
3736
  if (androidToolchain === void 0) blockers.push("the Android toolchain was not probed");
2672
- else blockers.push(...androidToolchainFacts(androidToolchain).blockers);
3737
+ else blockers.push(...androidToolchainFacts(androidToolchain, requiredSdk).blockers);
2673
3738
  if (request.mode === "release") {
2674
3739
  const environment = snapshot.environment ?? {};
2675
3740
  const missing = ANDROID_RELEASE_SIGNING_ENV.filter(
@@ -2687,9 +3752,10 @@ function requestedBuildCheck(snapshot, request, nativeRuntime) {
2687
3752
  const blockers = requestedBuildBlockers(snapshot, { ...request, target }, nativeRuntime);
2688
3753
  if (blockers.length === 0)
2689
3754
  return { detail: `buildable \u2014 ${scope}`, name: "requested build", status: "ok" };
3755
+ const requiredSdk = requiredAndroidSdk(snapshot);
2690
3756
  return {
2691
3757
  detail: `not buildable \u2014 ${scope}: ${blockers.join("; ")}`,
2692
- fix: target === "android" ? `Install JDK ${ANDROID_JDK_MAJOR} and Android SDK platform android-${ANDROID_COMPILE_SDK}, reinstall ${RUNTIME_PACKAGE} so its prebuilt downloads${request.mode === "release" ? `, and export ${ANDROID_RELEASE_SIGNING_ENV.join(", ")} from the game's build environment` : ""}.` : `Resolve the cause above, then run 'threenative doctor --target ${target}' again.`,
3758
+ fix: target === "android" ? `Install JDK ${ANDROID_JDK_MAJOR} and Android SDK platform android-${requiredSdk}, reinstall ${RUNTIME_PACKAGE} so its prebuilt downloads${request.mode === "release" ? `, and export ${ANDROID_RELEASE_SIGNING_ENV.join(", ")} from the game's build environment` : ""}.` : `Resolve the cause above, then run 'threenative doctor --target ${target}' again.`,
2693
3759
  name: "requested build",
2694
3760
  status: "fail"
2695
3761
  };
@@ -2887,6 +3953,7 @@ function diagnoseProject(snapshot, options = {}) {
2887
3953
  name: "playtests",
2888
3954
  status: "warn"
2889
3955
  },
3956
+ sceneShapeCheck(snapshot),
2890
3957
  ...capabilitySearchChecks(snapshot),
2891
3958
  editorActivationCheck(snapshot),
2892
3959
  ...blender === void 0 ? [] : [blender]
@@ -2899,7 +3966,7 @@ function diagnoseProject(snapshot, options = {}) {
2899
3966
  }
2900
3967
  async function collectFiles(root, relative = "", depth = 0) {
2901
3968
  if (depth > 3) return [];
2902
- const absolute = path2.join(root, relative);
3969
+ const absolute = path4.join(root, relative);
2903
3970
  if (!existsSync(absolute)) return [];
2904
3971
  const entries = await readdir(absolute, { withFileTypes: true });
2905
3972
  const files = [];
@@ -2920,7 +3987,7 @@ async function readJson(file) {
2920
3987
  }
2921
3988
  async function runtimeReleaseManifestUrl(runtimeRoot, version) {
2922
3989
  try {
2923
- const module = await import(pathToFileURL(path2.join(runtimeRoot, "scripts", "install-prebuilt.mjs")).href);
3990
+ const module = await import(pathToFileURL(path4.join(runtimeRoot, "scripts", "install-prebuilt.mjs")).href);
2924
3991
  const releaseUrl = record(module)?.releaseManifestUrl;
2925
3992
  if (typeof releaseUrl !== "function") return void 0;
2926
3993
  const result = releaseUrl(version);
@@ -2930,19 +3997,19 @@ async function runtimeReleaseManifestUrl(runtimeRoot, version) {
2930
3997
  }
2931
3998
  }
2932
3999
  async function readProject(root) {
2933
- const projectRoot = path2.resolve(root);
2934
- const packageJson = await readJson(path2.join(projectRoot, "package.json"));
2935
- const typeScriptConfig = path2.join(projectRoot, "threenative.config.ts");
4000
+ const projectRoot = path4.resolve(root);
4001
+ const packageJson = await readJson(path4.join(projectRoot, "package.json"));
4002
+ const typeScriptConfig = path4.join(projectRoot, "threenative.config.ts");
2936
4003
  const config = existsSync(typeScriptConfig) ? await readTypeScriptConfig(projectRoot) : nativeEntryCompat(record(packageJson)?.threenative);
2937
4004
  const files = new Set(await collectFiles(projectRoot));
2938
4005
  const installedVersions = /* @__PURE__ */ new Map();
2939
4006
  for (const name of declaredDependencies(packageJson)) {
2940
- const manifest = await readJson(path2.join(projectRoot, "node_modules", name, "package.json"));
4007
+ const manifest = await readJson(path4.join(projectRoot, "node_modules", name, "package.json"));
2941
4008
  const version = record(manifest)?.version;
2942
4009
  if (typeof version === "string") installedVersions.set(name, version);
2943
4010
  }
2944
4011
  const runtimeRoot = installedVersions.has(RUNTIME_PACKAGE) ? (() => {
2945
- const candidate = path2.join(projectRoot, "node_modules", RUNTIME_PACKAGE);
4012
+ const candidate = path4.join(projectRoot, "node_modules", RUNTIME_PACKAGE);
2946
4013
  try {
2947
4014
  return realpathSync(candidate);
2948
4015
  } catch {
@@ -2955,7 +4022,7 @@ async function readProject(root) {
2955
4022
  const mcpServerHealth = /* @__PURE__ */ new Map();
2956
4023
  if (SHAPE_VERIFIABLE_HOSTS.some(({ file }) => files.has(file))) {
2957
4024
  for (const spec of MCP_SERVER_SPECS) {
2958
- if (existsSync(path2.resolve(projectRoot, spec.expectedArgs))) {
4025
+ if (existsSync(path4.resolve(projectRoot, spec.expectedArgs))) {
2959
4026
  mcpServerHealth.set(spec.configName, probeMcpServer(projectRoot, spec));
2960
4027
  }
2961
4028
  }
@@ -2968,14 +4035,14 @@ async function readProject(root) {
2968
4035
  packageJson,
2969
4036
  projectRoot,
2970
4037
  readText: (relative) => {
2971
- const file = path2.join(projectRoot, relative);
4038
+ const file = path4.join(projectRoot, relative);
2972
4039
  try {
2973
4040
  return existsSync(file) ? readFileSync(file, "utf8") : void 0;
2974
4041
  } catch {
2975
4042
  return void 0;
2976
4043
  }
2977
4044
  },
2978
- androidToolchain: probeAndroidToolchain(),
4045
+ androidToolchain: probeAndroidToolchain(process.env, requiredAndroidSdkFromRoot(runtimeRoot)),
2979
4046
  blender: (() => {
2980
4047
  const status = resolveBlender();
2981
4048
  return {
@@ -2994,12 +4061,15 @@ async function readProject(root) {
2994
4061
  ...runtimeRoot === void 0 ? {} : {
2995
4062
  readRuntimeText: (relative) => {
2996
4063
  try {
2997
- return readFileSync(path2.join(runtimeRoot, relative), "utf8");
4064
+ return readFileSync(path4.join(runtimeRoot, relative), "utf8");
2998
4065
  } catch {
2999
4066
  return void 0;
3000
4067
  }
3001
4068
  },
3002
- runtimeFileExists: (relative) => existsSync(path2.join(runtimeRoot, relative)),
4069
+ runtimeFileExists: (relative) => existsSync(path4.join(runtimeRoot, relative)),
4070
+ nativeHost: probeNativeHost(
4071
+ path4.join(runtimeRoot, "prebuilt", nativeRuntimeKey(), nativeRuntimeFilename())
4072
+ ),
3003
4073
  ...runtimeManifestUrl === void 0 ? {} : { runtimeManifestUrl },
3004
4074
  runtimeRoot
3005
4075
  }