create-threenative 0.2.17 → 0.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-docs/kit-mcp.md +1 -1
- package/agent-docs/kit-router.md +1 -1
- package/agent-docs/references/assertion-reference.md +54 -110
- package/agent-docs/references/capability-reference.md +790 -24
- package/agent-docs/references/conventions.md +28 -0
- package/agent-docs/references/kit-racing.md +4 -2
- package/agent-docs/references/performance-basics.md +10 -5
- package/agent-docs/references/terrain-authoring.md +21 -7
- package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
- package/agent-files/.agents/skills/prd-creator/SKILL.md +24 -0
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +7 -4
- package/agent-files/.claude/hooks/discovery-gate.mjs +2 -2
- package/dist/index.d.ts +97 -6
- package/dist/index.js +1040 -529
- package/dist/quality.d.ts +5 -1
- package/dist/quality.js +75 -6
- package/dist/terrain-kit.js +1 -1
- package/dist/threenative.js +98 -17
- package/dist/web-engine-ccd-ik-solver.js +127 -0
- package/dist/web-engine-gltf-loader.js +52 -14
- package/dist/web-engine-post-effects.js +11 -10
- package/dist/web-engine-runtime.js +3638 -361
- package/package.json +8 -7
- package/template-assets/assets/floor-fern-0.glb +0 -0
- package/template-assets/assets/floor-litter-0.glb +0 -0
- package/template-assets/assets/floor-log-0.glb +0 -0
- package/template-assets/assets/floor-log-1.glb +0 -0
- package/template-assets/assets/floor-stump-0.glb +0 -0
- package/template-assets/assets/floor-twig-0.glb +0 -0
- package/template-assets/clearwater/README.md +1 -1
- package/template-assets/patches/manifest.json +18 -0
- package/template-assets/quality/eslint.config.js +1 -1
- package/templates/action-rpg/AGENTS.md +8 -4
- package/templates/action-rpg/CLAUDE.md +8 -4
- package/templates/action-rpg/package.json +7 -7
- package/templates/action-rpg/src/game.ts +1 -1
- package/templates/action-rpg/src/loot/drops.ts +3 -7
- package/templates/action-rpg/src/render/atmosphere.ts +6 -0
- package/templates/action-rpg/src/render/backlightControls.ts +10 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +4 -4
- package/templates/action-rpg/src/render/camera.ts +2 -2
- package/templates/action-rpg/src/render/clouds.ts +16 -1
- package/templates/action-rpg/src/render/materialLighting.ts +5 -5
- package/templates/action-rpg/src/render/materials.ts +3 -2
- package/templates/action-rpg/src/render/quality.ts +7 -32
- package/templates/action-rpg/src/render/touch-controls.ts +7 -6
- package/templates/action-rpg/src/scenes/Play.ts +5 -16
- package/templates/action-rpg/src/style.css +4 -0
- package/templates/action-rpg/vite.config.ts +2 -0
- package/templates/adventure/AGENTS.md +10 -5
- package/templates/adventure/CLAUDE.md +10 -5
- package/templates/adventure/kit.json +5 -1
- package/templates/adventure/native-playtests/survives.playtest.json +12 -0
- package/templates/adventure/native-playtests/woodland-floor.playtest.json +61 -0
- package/templates/adventure/package.json +7 -7
- package/templates/adventure/playtests/grass.playtest.json +61 -0
- package/templates/adventure/playtests/performance.playtest.json +1 -1
- package/templates/adventure/playtests/survives.playtest.json +2 -2
- package/templates/adventure/playtests/woodland-floor.playtest.json +61 -0
- package/templates/adventure/src/entities/LockOn.ts +42 -4
- package/templates/adventure/src/entities/Warden.ts +4 -1
- package/templates/adventure/src/game.ts +1 -1
- package/templates/adventure/src/level/Vale.ts +241 -16
- package/templates/adventure/src/render/camera.ts +2 -2
- package/templates/adventure/src/render/foliage.ts +64 -20
- package/templates/adventure/src/render/grass.ts +325 -0
- package/templates/adventure/src/render/materials.ts +3 -2
- package/templates/adventure/src/render/palette.ts +3 -0
- package/templates/adventure/src/render/touch-controls.ts +4 -1
- package/templates/adventure/src/scenes/Play.ts +96 -1
- package/templates/adventure/src/style.css +4 -0
- package/templates/adventure/tsconfig.json +1 -1
- package/templates/adventure/vite.config.ts +2 -0
- package/templates/collectathon/AGENTS.md +7 -2
- package/templates/collectathon/CLAUDE.md +7 -2
- package/templates/collectathon/package.json +7 -7
- package/templates/collectathon/src/game.ts +1 -1
- package/templates/collectathon/src/level/Course.ts +55 -14
- package/templates/collectathon/src/level/terrain.ts +29 -7
- package/templates/collectathon/src/main.ts +1 -0
- package/templates/collectathon/src/render/camera.ts +2 -2
- package/templates/collectathon/src/render/foliage.ts +359 -98
- package/templates/collectathon/src/render/ground.ts +4 -4
- package/templates/collectathon/src/render/hero.ts +1 -1
- package/templates/collectathon/src/render/materials.ts +0 -1
- package/templates/collectathon/src/render/sky.ts +80 -15
- package/templates/collectathon/src/render/water.ts +32 -10
- package/templates/collectathon/src/scenes/Play.ts +18 -5
- package/templates/collectathon/src/style.css +4 -0
- package/templates/collectathon/tsconfig.json +1 -1
- package/templates/collectathon/vite.config.ts +2 -0
- package/templates/kart/AGENTS.md +7 -2
- package/templates/kart/CLAUDE.md +7 -2
- package/templates/kart/package.json +6 -6
- package/templates/kart/src/entities/Kart.ts +2 -1
- package/templates/kart/src/game.ts +1 -1
- package/templates/kart/src/main.ts +1 -0
- package/templates/kart/src/render/course.ts +2 -1
- package/templates/kart/src/style.css +4 -0
- package/templates/kart/src/track/Course.ts +3 -1
- package/templates/kart/tsconfig.json +1 -1
- package/templates/kart/vite.config.ts +2 -0
- package/templates/minimal/AGENTS.md +8 -3
- package/templates/minimal/CLAUDE.md +8 -3
- package/templates/minimal/package.json +6 -6
- package/templates/minimal/playtests/stands-still.playtest.json +30 -0
- package/templates/minimal/src/game.ts +1 -1
- package/templates/minimal/src/render/atmosphere.ts +6 -0
- package/templates/minimal/src/render/backlightControls.ts +10 -0
- package/templates/minimal/src/render/backlightMaterial.ts +4 -4
- package/templates/minimal/src/render/camera.ts +14 -3
- package/templates/minimal/src/render/clouds.ts +16 -1
- package/templates/minimal/src/render/lighting.ts +4 -2
- package/templates/minimal/src/render/materialLighting.ts +5 -5
- package/templates/minimal/src/render/materials.ts +13 -2
- package/templates/minimal/src/render/quality.ts +7 -32
- package/templates/minimal/src/render/touch-controls.ts +7 -6
- package/templates/minimal/src/scenes/Play.ts +4 -1
- package/templates/minimal/vite.config.ts +7 -1
- package/templates/platformer/AGENTS.md +9 -4
- package/templates/platformer/CLAUDE.md +9 -4
- package/templates/platformer/index.html +1 -1
- package/templates/platformer/main.html +12 -0
- package/templates/platformer/package.json +7 -7
- package/templates/platformer/playtests/collect.playtest.json +4 -1
- package/templates/platformer/playtests/gamepad-idle.playtest.json +21 -0
- package/templates/platformer/playtests/gamepad.playtest.json +30 -0
- package/templates/platformer/src/entities/Fox.ts +21 -6
- package/templates/platformer/src/game.ts +1 -1
- package/templates/platformer/src/level/Stage.ts +2 -6
- package/templates/platformer/src/main.ts +1 -0
- package/templates/platformer/src/render/backlightControls.ts +10 -0
- package/templates/platformer/src/render/backlightMaterial.ts +4 -4
- package/templates/platformer/src/render/materialLighting.ts +5 -5
- package/templates/platformer/src/render/quality.ts +7 -32
- package/templates/platformer/src/scenes/Play.ts +4 -2
- package/templates/platformer/src/style.css +4 -0
- package/templates/platformer/src/worker-page.ts +29 -0
- package/templates/platformer/src/worker.ts +5 -0
- package/templates/platformer/tsconfig.json +1 -1
- package/templates/platformer/vite.config.ts +4 -0
- package/templates/puzzle/AGENTS.md +7 -2
- package/templates/puzzle/CLAUDE.md +7 -2
- package/templates/puzzle/package.json +7 -7
- package/templates/puzzle/src/entities/Warden.ts +3 -3
- package/templates/puzzle/src/game.ts +1 -1
- package/templates/puzzle/src/render/backlightControls.ts +10 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +4 -4
- package/templates/puzzle/src/render/camera.ts +2 -2
- package/templates/puzzle/src/render/materialLighting.ts +5 -5
- package/templates/puzzle/src/render/quality.ts +7 -32
- package/templates/puzzle/src/render/touch-controls.ts +7 -6
- package/templates/puzzle/src/scenes/Play.ts +1 -1
- package/templates/puzzle/src/style.css +4 -0
- package/templates/puzzle/tsconfig.json +1 -1
- package/templates/puzzle/vite.config.ts +2 -0
- package/templates/racing/AGENTS.md +9 -4
- package/templates/racing/CLAUDE.md +9 -4
- package/templates/racing/CREDITS.md +29 -0
- package/templates/racing/assets/engine-loop.wav +0 -0
- package/templates/racing/assets/grass/Grass004_color.jpg +0 -0
- package/templates/racing/assets/grass/Grass004_normal.jpg +0 -0
- package/templates/racing/assets/grass/Grass004_roughness.jpg +0 -0
- package/templates/racing/assets/nitro-burst.wav +0 -0
- package/templates/racing/assets/tyre-squeal.wav +0 -0
- package/templates/racing/package.json +7 -7
- package/templates/racing/playtests/drift-natural.playtest.json +68 -0
- package/templates/racing/playtests/drift.playtest.json +100 -0
- package/templates/racing/playtests/hud.playtest.json +117 -0
- package/templates/racing/playtests/launch-pose.playtest.json +34 -0
- package/templates/racing/playtests/nitro.playtest.json +158 -0
- package/templates/racing/playtests/outcome.playtest.json +4 -4
- package/templates/racing/playtests/performance.playtest.json +1 -1
- package/templates/racing/playtests/steady-camera.playtest.json +88 -0
- package/templates/racing/src/audio/engine.ts +138 -0
- package/templates/racing/src/entities/CarBody.ts +83 -10
- package/templates/racing/src/entities/Drift.ts +243 -0
- package/templates/racing/src/entities/LineDriver.ts +2 -2
- package/templates/racing/src/entities/Nitro.ts +72 -0
- package/templates/racing/src/entities/RacingCar.ts +86 -21
- package/templates/racing/src/entities/Rival.ts +35 -21
- package/templates/racing/src/game.ts +7 -1
- package/templates/racing/src/gauges.ts +74 -0
- package/templates/racing/src/render/atmosphere.ts +6 -0
- package/templates/racing/src/render/backlightControls.ts +10 -0
- package/templates/racing/src/render/backlightMaterial.ts +4 -4
- package/templates/racing/src/render/camera.ts +29 -4
- package/templates/racing/src/render/clouds.ts +16 -1
- package/templates/racing/src/render/effects.ts +244 -0
- package/templates/racing/src/render/materialLighting.ts +5 -5
- package/templates/racing/src/render/materials.ts +43 -8
- package/templates/racing/src/render/quality.ts +7 -32
- package/templates/racing/src/render/shapes.ts +37 -0
- package/templates/racing/src/render/skids.ts +84 -0
- package/templates/racing/src/render/touch-controls.ts +10 -10
- package/templates/racing/src/scenes/Race.ts +281 -26
- package/templates/racing/src/state.ts +35 -0
- package/templates/racing/src/style.css +7 -0
- package/templates/racing/src/track/Track.ts +132 -58
- package/templates/racing/src/track/TrackSector.ts +19 -1
- package/templates/racing/src/track/circuit.ts +21 -15
- package/templates/racing/src/ui/GameUi.tsx +0 -2
- package/templates/racing/src/ui/Hud.tsx +417 -50
- package/templates/racing/threenative.config.ts +15 -0
- package/templates/racing/tools/make-racing-audio.mjs +388 -0
- package/templates/racing/tsconfig.json +1 -1
- package/templates/racing/vite.config.ts +2 -0
- package/templates/rain/AGENTS.md +6 -2
- package/templates/rain/CLAUDE.md +6 -2
- package/templates/rain/package.json +6 -6
- package/templates/rain/src/game.ts +1 -1
- package/templates/rain/src/render/noise-volume.ts +2 -1
- package/templates/rain/src/state.ts +3 -1
- package/templates/rain/src/ui/GameUi.tsx +1 -1
- package/templates/rain/src/ui/automation.ts +10 -8
- package/templates/rain/src/ui/tempest.ts +3 -4
- package/templates/rain/vite.config.ts +6 -0
- package/templates/rts/AGENTS.md +6 -2
- package/templates/rts/CLAUDE.md +6 -2
- package/templates/rts/package.json +6 -6
- package/templates/rts/src/game.ts +1 -1
- package/templates/rts/src/render/backlightControls.ts +10 -0
- package/templates/rts/src/render/backlightMaterial.ts +4 -4
- package/templates/rts/src/render/materialLighting.ts +5 -5
- package/templates/rts/src/render/quality.ts +7 -31
- package/templates/rts/src/scenes/Play.ts +1 -1
- package/templates/rts/src/sim/terrain.ts +1 -0
- package/templates/rts/src/sim/types.ts +1 -0
- package/templates/rts/src/style.css +4 -0
- package/templates/rts/vite.config.ts +2 -0
- package/templates/runner/AGENTS.md +7 -2
- package/templates/runner/CLAUDE.md +7 -2
- package/templates/runner/package.json +7 -7
- package/templates/runner/src/game.ts +1 -1
- package/templates/runner/src/render/atmosphere.ts +6 -0
- package/templates/runner/src/render/backlightControls.ts +10 -0
- package/templates/runner/src/render/backlightMaterial.ts +4 -4
- package/templates/runner/src/render/clouds.ts +16 -1
- package/templates/runner/src/render/materialLighting.ts +5 -5
- package/templates/runner/src/render/materials.ts +3 -2
- package/templates/runner/src/render/quality.ts +7 -32
- package/templates/runner/src/render/touch-controls.ts +7 -6
- package/templates/runner/src/scenes/Run.ts +8 -10
- package/templates/runner/src/style.css +4 -0
- package/templates/runner/tsconfig.json +1 -1
- package/templates/runner/vite.config.ts +2 -0
- package/templates/sailing/AGENTS.md +7 -2
- package/templates/sailing/CLAUDE.md +7 -2
- package/templates/sailing/package.json +7 -7
- package/templates/sailing/src/game.ts +1 -1
- package/templates/sailing/src/render/backlightControls.ts +10 -0
- package/templates/sailing/src/render/backlightMaterial.ts +4 -4
- package/templates/sailing/src/render/environmentSetup.ts +1 -1
- package/templates/sailing/src/render/materialLighting.ts +5 -5
- package/templates/sailing/src/render/quality.ts +7 -32
- package/templates/sailing/src/render/touch-controls.ts +7 -6
- package/templates/sailing/src/style.css +5 -0
- package/templates/sailing/vite.config.ts +6 -0
- package/templates/shooter/AGENTS.md +6 -2
- package/templates/shooter/CLAUDE.md +6 -2
- package/templates/shooter/package.json +7 -7
- package/templates/shooter/src/game.ts +3 -2
- package/templates/shooter/src/render/atmosphere.ts +6 -0
- package/templates/shooter/src/render/backlightControls.ts +10 -0
- package/templates/shooter/src/render/backlightMaterial.ts +4 -4
- package/templates/shooter/src/render/clouds.ts +16 -1
- package/templates/shooter/src/render/materialLighting.ts +5 -5
- package/templates/shooter/src/render/quality.ts +7 -32
- package/templates/shooter/src/scenes/Play.ts +4 -1
- package/templates/shooter/src/style.css +4 -0
- package/templates/shooter/vite.config.ts +2 -0
- package/templates/snow/AGENTS.md +7 -2
- package/templates/snow/CLAUDE.md +7 -2
- package/templates/snow/package.json +7 -7
- package/templates/snow/src/entities/Explorer.ts +6 -12
- package/templates/snow/src/game.ts +1 -1
- package/templates/snow/src/render/backlightControls.ts +10 -0
- package/templates/snow/src/render/backlightMaterial.ts +4 -4
- package/templates/snow/src/render/bootPrint.ts +3 -1
- package/templates/snow/src/render/camera.ts +3 -2
- package/templates/snow/src/render/materialLighting.ts +5 -5
- package/templates/snow/src/render/quality.ts +7 -32
- package/templates/snow/src/render/scenery.ts +3 -3
- package/templates/snow/src/render/touch-controls.ts +7 -6
- package/templates/snow/src/render/weather.ts +3 -5
- package/templates/snow/src/style.css +5 -0
- package/templates/snow/src/terrain.ts +2 -1
- package/templates/snow/vite.config.ts +6 -0
- package/templates/starter/AGENTS.md +8 -3
- package/templates/starter/CLAUDE.md +8 -3
- package/templates/starter/native-playtests/render-chain.playtest.json +9 -9
- package/templates/starter/package.json +7 -7
- package/templates/starter/src/entities/Crate.ts +5 -2
- package/templates/starter/src/entities/Player.ts +10 -2
- package/templates/starter/src/game.ts +4 -3
- package/templates/starter/src/render/adaptiveQuality.ts +17 -0
- package/templates/starter/src/render/atmosphere.ts +6 -0
- package/templates/starter/src/render/backlightControls.ts +10 -0
- package/templates/starter/src/render/backlightMaterial.ts +4 -4
- package/templates/starter/src/render/camera.ts +2 -2
- package/templates/starter/src/render/clouds.ts +16 -1
- package/templates/starter/src/render/contactShadow.ts +1 -1
- package/templates/starter/src/render/materialLighting.ts +5 -5
- package/templates/starter/src/render/materials.ts +3 -2
- package/templates/starter/src/render/postprocessing.ts +11 -10
- package/templates/starter/src/render/quality.ts +14 -1
- package/templates/starter/src/render/touch-controls.ts +7 -6
- package/templates/starter/src/scenes/Play.ts +13 -17
- package/templates/starter/src/state.ts +2 -0
- package/templates/starter/src/style.css +4 -0
- package/templates/starter/src/ui/Menu.tsx +5 -1
- package/templates/starter/vite.config.ts +2 -0
- package/templates/tower-defense/AGENTS.md +7 -2
- package/templates/tower-defense/CLAUDE.md +7 -2
- package/templates/tower-defense/package.json +7 -7
- package/templates/tower-defense/src/game.ts +1 -1
- package/templates/tower-defense/src/render/backlightControls.ts +10 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +4 -4
- package/templates/tower-defense/src/render/materialLighting.ts +5 -5
- package/templates/tower-defense/src/render/quality.ts +7 -32
- package/templates/tower-defense/src/render/shapes.ts +1 -2
- package/templates/tower-defense/src/scenes/Battle.ts +4 -9
- package/templates/tower-defense/src/style.css +4 -0
- package/templates/tower-defense/tsconfig.json +1 -1
- package/templates/tower-defense/vite.config.ts +2 -0
- package/templates/action-rpg/src/render/environmentContribution.ts +0 -188
- package/templates/action-rpg/src/render/environmentRadiance.ts +0 -36
- package/templates/action-rpg/src/render/environmentSampleCache.ts +0 -43
- package/templates/action-rpg/src/render/environmentSampling.ts +0 -193
- package/templates/action-rpg/src/render/environmentSnapshot.ts +0 -53
- package/templates/minimal/src/render/environmentContribution.ts +0 -188
- package/templates/minimal/src/render/environmentRadiance.ts +0 -36
- package/templates/minimal/src/render/environmentSampleCache.ts +0 -43
- package/templates/minimal/src/render/environmentSampling.ts +0 -193
- package/templates/minimal/src/render/environmentSnapshot.ts +0 -53
- package/templates/platformer/src/render/environmentContribution.ts +0 -188
- package/templates/platformer/src/render/environmentRadiance.ts +0 -36
- package/templates/platformer/src/render/environmentSampleCache.ts +0 -43
- package/templates/platformer/src/render/environmentSampling.ts +0 -193
- package/templates/platformer/src/render/environmentSnapshot.ts +0 -53
- package/templates/puzzle/src/render/environmentContribution.ts +0 -188
- package/templates/puzzle/src/render/environmentRadiance.ts +0 -36
- package/templates/puzzle/src/render/environmentSampleCache.ts +0 -43
- package/templates/puzzle/src/render/environmentSampling.ts +0 -193
- package/templates/puzzle/src/render/environmentSnapshot.ts +0 -53
- package/templates/racing/src/render/environmentContribution.ts +0 -188
- package/templates/racing/src/render/environmentRadiance.ts +0 -36
- package/templates/racing/src/render/environmentSampleCache.ts +0 -43
- package/templates/racing/src/render/environmentSampling.ts +0 -193
- package/templates/racing/src/render/environmentSnapshot.ts +0 -53
- package/templates/racing/src/ui/Menu.tsx +0 -7
- package/templates/rts/src/render/environmentContribution.ts +0 -188
- package/templates/rts/src/render/environmentRadiance.ts +0 -36
- package/templates/rts/src/render/environmentSampleCache.ts +0 -43
- package/templates/rts/src/render/environmentSampling.ts +0 -193
- package/templates/rts/src/render/environmentSnapshot.ts +0 -53
- package/templates/runner/src/render/environmentContribution.ts +0 -188
- package/templates/runner/src/render/environmentRadiance.ts +0 -36
- package/templates/runner/src/render/environmentSampleCache.ts +0 -43
- package/templates/runner/src/render/environmentSampling.ts +0 -193
- package/templates/runner/src/render/environmentSnapshot.ts +0 -53
- package/templates/sailing/src/render/environmentContribution.ts +0 -188
- package/templates/sailing/src/render/environmentRadiance.ts +0 -36
- package/templates/sailing/src/render/environmentSampleCache.ts +0 -43
- package/templates/sailing/src/render/environmentSampling.ts +0 -193
- package/templates/sailing/src/render/environmentSnapshot.ts +0 -53
- package/templates/shooter/src/render/environmentContribution.ts +0 -188
- package/templates/shooter/src/render/environmentRadiance.ts +0 -36
- package/templates/shooter/src/render/environmentSampleCache.ts +0 -43
- package/templates/shooter/src/render/environmentSampling.ts +0 -193
- package/templates/shooter/src/render/environmentSnapshot.ts +0 -53
- package/templates/snow/src/render/environmentContribution.ts +0 -188
- package/templates/snow/src/render/environmentRadiance.ts +0 -36
- package/templates/snow/src/render/environmentSampleCache.ts +0 -43
- package/templates/snow/src/render/environmentSampling.ts +0 -193
- package/templates/snow/src/render/environmentSnapshot.ts +0 -53
- package/templates/starter/src/render/environmentContribution.ts +0 -188
- package/templates/starter/src/render/environmentRadiance.ts +0 -36
- package/templates/starter/src/render/environmentSampleCache.ts +0 -43
- package/templates/starter/src/render/environmentSampling.ts +0 -193
- package/templates/starter/src/render/environmentSnapshot.ts +0 -53
- package/templates/starter/src/render/rendererGate.ts +0 -36
- package/templates/tower-defense/src/render/environmentContribution.ts +0 -188
- package/templates/tower-defense/src/render/environmentRadiance.ts +0 -36
- package/templates/tower-defense/src/render/environmentSampleCache.ts +0 -43
- package/templates/tower-defense/src/render/environmentSampling.ts +0 -193
- package/templates/tower-defense/src/render/environmentSnapshot.ts +0 -53
package/dist/index.js
CHANGED
|
@@ -1,16 +1,270 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { execFileSync, spawn } from 'child_process';
|
|
4
|
+
import { createHash } from 'crypto';
|
|
4
5
|
import { existsSync, realpathSync, readdirSync, readFileSync, mkdirSync, writeFileSync, rmSync } from 'fs';
|
|
5
|
-
import { mkdir, cp, rm, rename, readFile, readdir, writeFile, symlink, access, unlink, stat } from 'fs/promises';
|
|
6
|
-
import
|
|
6
|
+
import { mkdir, cp, rm, rename, readFile, readdir, writeFile, mkdtemp, lstat, symlink, access, unlink, stat } from 'fs/promises';
|
|
7
|
+
import { tmpdir } from 'os';
|
|
8
|
+
import path8 from 'path';
|
|
7
9
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
8
10
|
import { LoadingManager, Box3, Vector3 } from 'three';
|
|
9
|
-
import { createHash } from 'crypto';
|
|
10
11
|
import { createRequire as createRequire$1 } from 'module';
|
|
11
12
|
import { parsePng, parseAudioConfig } from '@threenative/assets';
|
|
12
13
|
|
|
13
14
|
createRequire(import.meta.url);
|
|
15
|
+
|
|
16
|
+
// ../core/mcp/servers.mjs
|
|
17
|
+
var MCP_SERVERS = Object.freeze({
|
|
18
|
+
"threenative-assets": Object.freeze({
|
|
19
|
+
command: "node",
|
|
20
|
+
args: Object.freeze(["./node_modules/@threenative/core/mcp/assets.mjs"]),
|
|
21
|
+
// Entries rather than an object literal: these are environment variable names, not identifiers,
|
|
22
|
+
// and written as property names they read as names the naming rule must judge.
|
|
23
|
+
env: Object.freeze(
|
|
24
|
+
Object.fromEntries([
|
|
25
|
+
["ASSET_DOWNLOAD_DIR", "./public/assets"],
|
|
26
|
+
["AUDIO_DOWNLOAD_DIR", "./public/audio"]
|
|
27
|
+
])
|
|
28
|
+
)
|
|
29
|
+
}),
|
|
30
|
+
"threenative-sculpt": Object.freeze({
|
|
31
|
+
command: "node",
|
|
32
|
+
args: Object.freeze(["./node_modules/@threenative/core/mcp/sculpt.mjs"])
|
|
33
|
+
}),
|
|
34
|
+
"threenative-engine": Object.freeze({
|
|
35
|
+
command: "node",
|
|
36
|
+
args: Object.freeze(["./node_modules/@threenative/core/mcp/engine.mjs"])
|
|
37
|
+
}),
|
|
38
|
+
// Cooks a starter terrain kit into a world.glb. The server lives in the optional
|
|
39
|
+
// `@threenative/terrain` package, which the shim resolves from the project at launch.
|
|
40
|
+
"threenative-terrain": Object.freeze({
|
|
41
|
+
command: "node",
|
|
42
|
+
args: Object.freeze(["./node_modules/@threenative/core/mcp/terrain.mjs"])
|
|
43
|
+
}),
|
|
44
|
+
// Inspects, attaches, edits and verifies character animation. Every operation is a build-time
|
|
45
|
+
// edit of one GLB, so a game that animates nothing pays for nothing.
|
|
46
|
+
"threenative-animation": Object.freeze({
|
|
47
|
+
command: "node",
|
|
48
|
+
args: Object.freeze(["./node_modules/@threenative/core/mcp/animation.mjs"])
|
|
49
|
+
}),
|
|
50
|
+
// Google's Chrome DevTools server: performance traces, GPU timing, network, heap and console of
|
|
51
|
+
// the running game. It starts Chrome only on its first tool call, so a project that never
|
|
52
|
+
// inspects a page pays nothing. Its async stack capture inflates CPU time several times, so
|
|
53
|
+
// `trace-a-slow-frame.md` sends absolute CPU questions to `playtest trace` first.
|
|
54
|
+
"threenative-devtools": Object.freeze({
|
|
55
|
+
command: "node",
|
|
56
|
+
args: Object.freeze(["./node_modules/@threenative/core/mcp/devtools.mjs"])
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
var SERVER_FORMATS = Object.freeze({
|
|
60
|
+
// Claude Code (`.mcp.json`), Cursor and the Gemini CLI all read this one.
|
|
61
|
+
mcpServers: Object.freeze({
|
|
62
|
+
key: "mcpServers",
|
|
63
|
+
entry: (server) => ({
|
|
64
|
+
command: server.command,
|
|
65
|
+
args: [...server.args],
|
|
66
|
+
...server.env === void 0 ? {} : { env: { ...server.env } }
|
|
67
|
+
})
|
|
68
|
+
}),
|
|
69
|
+
// VS Code names the table `servers` and requires an explicit transport per server.
|
|
70
|
+
vscode: Object.freeze({
|
|
71
|
+
key: "servers",
|
|
72
|
+
entry: (server) => ({
|
|
73
|
+
type: "stdio",
|
|
74
|
+
command: server.command,
|
|
75
|
+
args: [...server.args],
|
|
76
|
+
...server.env === void 0 ? {} : { env: { ...server.env } }
|
|
77
|
+
})
|
|
78
|
+
}),
|
|
79
|
+
// opencode folds the command and its arguments into one array and spells the environment
|
|
80
|
+
// `environment`. A server it does not mark enabled is written down and never started.
|
|
81
|
+
opencode: Object.freeze({
|
|
82
|
+
key: "mcp",
|
|
83
|
+
entry: (server) => ({
|
|
84
|
+
type: "local",
|
|
85
|
+
command: [server.command, ...server.args],
|
|
86
|
+
enabled: true,
|
|
87
|
+
...server.env === void 0 ? {} : { environment: { ...server.env } }
|
|
88
|
+
})
|
|
89
|
+
}),
|
|
90
|
+
// Zed calls them context servers and needs `source: "custom"` to accept a command of our own.
|
|
91
|
+
zed: Object.freeze({
|
|
92
|
+
key: "context_servers",
|
|
93
|
+
entry: (server) => ({
|
|
94
|
+
source: "custom",
|
|
95
|
+
command: server.command,
|
|
96
|
+
args: [...server.args],
|
|
97
|
+
...server.env === void 0 ? {} : { env: { ...server.env } }
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
Object.freeze(Object.keys(SERVER_FORMATS));
|
|
102
|
+
function mergeMcpServers(existing, format = "mcpServers") {
|
|
103
|
+
const shape = SERVER_FORMATS[format];
|
|
104
|
+
if (shape === void 0) throw new Error(`Unknown MCP config format '${format}'.`);
|
|
105
|
+
const malformed = existing !== void 0 && (typeof existing !== "object" || existing === null || Array.isArray(existing));
|
|
106
|
+
if (malformed) {
|
|
107
|
+
throw new Error("MCP config root must be an object.");
|
|
108
|
+
}
|
|
109
|
+
const previous = existing ?? {};
|
|
110
|
+
const existingServers = previous[shape.key];
|
|
111
|
+
if (existingServers !== void 0 && (typeof existingServers !== "object" || existingServers === null || Array.isArray(existingServers))) {
|
|
112
|
+
throw new Error(`MCP config '${shape.key}' must be an object.`);
|
|
113
|
+
}
|
|
114
|
+
const servers = { ...existingServers ?? {} };
|
|
115
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
116
|
+
if (typeof server !== "object" || server === null || Array.isArray(server)) {
|
|
117
|
+
throw new Error(`MCP server '${name}' in '${shape.key}' must be an object.`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let changed = false;
|
|
121
|
+
const conflicts = [];
|
|
122
|
+
for (const [name, server] of Object.entries(MCP_SERVERS)) {
|
|
123
|
+
const wanted = shape.entry(server);
|
|
124
|
+
if (Object.hasOwn(servers, name)) {
|
|
125
|
+
if (JSON.stringify(servers[name]) !== JSON.stringify(wanted)) conflicts.push(name);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
servers[name] = wanted;
|
|
129
|
+
changed = true;
|
|
130
|
+
}
|
|
131
|
+
return { changed, conflicts, config: { ...previous, [shape.key]: servers } };
|
|
132
|
+
}
|
|
133
|
+
function codexServerBlock(name, server) {
|
|
134
|
+
const args = server.args.map((argument) => JSON.stringify(argument)).join(", ");
|
|
135
|
+
const lines = [
|
|
136
|
+
`[mcp_servers.${name}]`,
|
|
137
|
+
`command = ${JSON.stringify(server.command)}`,
|
|
138
|
+
`args = [${args}]`
|
|
139
|
+
];
|
|
140
|
+
if (server.env !== void 0) {
|
|
141
|
+
lines.push("", `[mcp_servers.${name}.env]`);
|
|
142
|
+
for (const [key, value] of Object.entries(server.env)) {
|
|
143
|
+
lines.push(`${key} = ${JSON.stringify(value)}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return lines.join("\n");
|
|
147
|
+
}
|
|
148
|
+
var CODEX_MCP_SERVERS = Object.freeze(
|
|
149
|
+
Object.entries(MCP_SERVERS).map(
|
|
150
|
+
([name, server]) => Object.freeze({ body: codexServerBlock(name, server), name })
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// ../core/src/version.ts
|
|
155
|
+
var CORE_VERSION = "0.3.15";
|
|
156
|
+
var MCP_HOSTS = Object.freeze([
|
|
157
|
+
Object.freeze({
|
|
158
|
+
id: "claude-code",
|
|
159
|
+
label: "Claude Code",
|
|
160
|
+
file: ".mcp.json",
|
|
161
|
+
format: "mcpServers"
|
|
162
|
+
}),
|
|
163
|
+
Object.freeze({ id: "codex", label: "Codex", file: ".codex/config.toml", format: "codex" }),
|
|
164
|
+
Object.freeze({ id: "cursor", label: "Cursor", file: ".cursor/mcp.json", format: "mcpServers" }),
|
|
165
|
+
Object.freeze({ id: "vscode", label: "VS Code", file: ".vscode/mcp.json", format: "vscode" }),
|
|
166
|
+
Object.freeze({
|
|
167
|
+
id: "gemini-cli",
|
|
168
|
+
label: "Gemini CLI",
|
|
169
|
+
file: ".gemini/settings.json",
|
|
170
|
+
format: "mcpServers"
|
|
171
|
+
}),
|
|
172
|
+
Object.freeze({
|
|
173
|
+
id: "opencode",
|
|
174
|
+
label: "opencode",
|
|
175
|
+
file: "opencode.json",
|
|
176
|
+
format: "opencode",
|
|
177
|
+
// Written only when this installer creates the file, so a second install still reports
|
|
178
|
+
// "unchanged" rather than rewriting a config the user has since edited.
|
|
179
|
+
seed: Object.freeze({ $schema: "https://opencode.ai/config.json" })
|
|
180
|
+
}),
|
|
181
|
+
Object.freeze({ id: "zed", label: "Zed", file: ".zed/settings.json", format: "zed" })
|
|
182
|
+
]);
|
|
183
|
+
function ensureJsonMcpConfig(target, file, format, seed = void 0) {
|
|
184
|
+
const configPath = path8.join(target, file);
|
|
185
|
+
let existing;
|
|
186
|
+
if (existsSync(configPath)) {
|
|
187
|
+
try {
|
|
188
|
+
existing = JSON.parse(readFileSync(configPath, "utf8"));
|
|
189
|
+
} catch {
|
|
190
|
+
return "unreadable";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
let merged;
|
|
194
|
+
try {
|
|
195
|
+
merged = mergeMcpServers(existing, format);
|
|
196
|
+
} catch {
|
|
197
|
+
return "unreadable";
|
|
198
|
+
}
|
|
199
|
+
const { changed, config, conflicts } = merged;
|
|
200
|
+
if (!changed) return conflicts.length > 0 ? "conflict" : "unchanged";
|
|
201
|
+
const written = existing === void 0 ? { ...seed, ...config } : config;
|
|
202
|
+
mkdirSync(path8.dirname(configPath), { recursive: true });
|
|
203
|
+
writeFileSync(configPath, `${JSON.stringify(written, null, 2)}
|
|
204
|
+
`);
|
|
205
|
+
return conflicts.length > 0 ? "conflict" : existing === void 0 ? "created" : "updated";
|
|
206
|
+
}
|
|
207
|
+
function ensureCodexMcpConfig(target) {
|
|
208
|
+
const directory = path8.join(target, ".codex");
|
|
209
|
+
const configPath = path8.join(directory, "config.toml");
|
|
210
|
+
const existing = existsSync(configPath) ? readFileSync(configPath, "utf8") : "";
|
|
211
|
+
const missing = CODEX_MCP_SERVERS.filter(
|
|
212
|
+
({ name }) => !existing.includes(`[mcp_servers.${name}]`)
|
|
213
|
+
);
|
|
214
|
+
if (missing.length === 0) return "unchanged";
|
|
215
|
+
mkdirSync(directory, { recursive: true });
|
|
216
|
+
const separator = existing.length === 0 || existing.endsWith("\n\n") ? "" : existing.endsWith("\n") ? "\n" : "\n\n";
|
|
217
|
+
writeFileSync(
|
|
218
|
+
configPath,
|
|
219
|
+
`${existing}${separator}${missing.map(({ body }) => body).join("\n\n")}
|
|
220
|
+
`
|
|
221
|
+
);
|
|
222
|
+
return existing.length === 0 ? "created" : "updated";
|
|
223
|
+
}
|
|
224
|
+
function ensureHostMcpConfigs(target) {
|
|
225
|
+
const outcomes = /* @__PURE__ */ new Map();
|
|
226
|
+
for (const host of MCP_HOSTS) {
|
|
227
|
+
try {
|
|
228
|
+
outcomes.set(
|
|
229
|
+
host.id,
|
|
230
|
+
host.format === "codex" ? ensureCodexMcpConfig(target) : ensureJsonMcpConfig(target, host.file, host.format, host.seed)
|
|
231
|
+
);
|
|
232
|
+
} catch {
|
|
233
|
+
outcomes.set(host.id, "unreadable");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return outcomes;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/mcp-servers.ts
|
|
240
|
+
var CORE_PACKAGE_NAME = "@threenative/core";
|
|
241
|
+
var CORE_PACKAGE_VERSION = CORE_VERSION;
|
|
242
|
+
function serverEntryPath(server) {
|
|
243
|
+
const entry = server.args[0];
|
|
244
|
+
if (entry === void 0) {
|
|
245
|
+
throw new Error("TN_MCP_TABLE: an MCP server entry declares no shim to launch.");
|
|
246
|
+
}
|
|
247
|
+
return entry;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/core-pair.ts
|
|
251
|
+
function parts(value) {
|
|
252
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/u.exec(value.trim());
|
|
253
|
+
if (match === null) return void 0;
|
|
254
|
+
const parsed = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
255
|
+
return parsed.every(Number.isSafeInteger) ? parsed : void 0;
|
|
256
|
+
}
|
|
257
|
+
function pairsWithCore(installed) {
|
|
258
|
+
if (installed === void 0) return false;
|
|
259
|
+
const have = parts(installed);
|
|
260
|
+
const paired = parts(CORE_PACKAGE_VERSION);
|
|
261
|
+
if (have === void 0 || paired === void 0) return false;
|
|
262
|
+
const [haveMajor, haveMinor, havePatch] = have;
|
|
263
|
+
const [pairedMajor, pairedMinor, pairedPatch] = paired;
|
|
264
|
+
if (haveMajor !== pairedMajor) return haveMajor > pairedMajor;
|
|
265
|
+
if (haveMinor !== pairedMinor) return haveMinor > pairedMinor;
|
|
266
|
+
return havePatch >= pairedPatch;
|
|
267
|
+
}
|
|
14
268
|
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([".glb", ".gltf"]);
|
|
15
269
|
var METRE_UPPER_BOUND = 10;
|
|
16
270
|
var CENTIMETRE_LOWER_BOUND = 100;
|
|
@@ -86,10 +340,10 @@ function localResourcePath(baseDirectory, uri) {
|
|
|
86
340
|
} catch (error) {
|
|
87
341
|
throw new Error(`Invalid glTF resource URI "${uri}": ${String(error)}`);
|
|
88
342
|
}
|
|
89
|
-
return
|
|
343
|
+
return path8.resolve(baseDirectory, decoded);
|
|
90
344
|
}
|
|
91
345
|
function resourceMimeType(resourcePath, declared) {
|
|
92
|
-
return declared ?? RESOURCE_MIME_TYPES[
|
|
346
|
+
return declared ?? RESOURCE_MIME_TYPES[path8.extname(resourcePath).toLowerCase()] ?? "application/octet-stream";
|
|
93
347
|
}
|
|
94
348
|
function gltfResourceReferences(document) {
|
|
95
349
|
const references = [];
|
|
@@ -118,10 +372,10 @@ async function readLocalResources(baseDirectory, references) {
|
|
|
118
372
|
return resources;
|
|
119
373
|
}
|
|
120
374
|
async function localResourceResolver(file, data) {
|
|
121
|
-
if (
|
|
375
|
+
if (path8.extname(file).toLowerCase() !== ".gltf") return (url) => url;
|
|
122
376
|
const document = JSON.parse(data.toString("utf8"));
|
|
123
377
|
const references = gltfResourceReferences(document);
|
|
124
|
-
const baseDirectory =
|
|
378
|
+
const baseDirectory = path8.dirname(path8.resolve(file));
|
|
125
379
|
const resources = await readLocalResources(baseDirectory, references);
|
|
126
380
|
return (url) => {
|
|
127
381
|
const resourcePath = localResourcePath(baseDirectory, url);
|
|
@@ -135,11 +389,11 @@ async function parseGltfAsset(file, data) {
|
|
|
135
389
|
const manager = new LoadingManager();
|
|
136
390
|
manager.setURLModifier(await localResourceResolver(file, data));
|
|
137
391
|
const loader = new GLTFLoader(manager);
|
|
138
|
-
const extension =
|
|
392
|
+
const extension = path8.extname(file).toLowerCase();
|
|
139
393
|
const payload = extension === ".gltf" ? data.toString("utf8") : data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
140
394
|
const parsed = await loader.parseAsync(
|
|
141
395
|
payload,
|
|
142
|
-
`${
|
|
396
|
+
`${path8.dirname(path8.resolve(file))}${path8.sep}`
|
|
143
397
|
);
|
|
144
398
|
const json = parsed.parser.json;
|
|
145
399
|
return {
|
|
@@ -199,11 +453,11 @@ function inspectScene(file, scene, animations, resourceCounts) {
|
|
|
199
453
|
bounds,
|
|
200
454
|
bones: resources.bones,
|
|
201
455
|
clips: animations.map((clip) => clip.name || "(unnamed)"),
|
|
202
|
-
file:
|
|
456
|
+
file: path8.basename(file),
|
|
203
457
|
forwardAxis: largest === void 0 ? { axis: "unknown", basis: "none", direction: "unknown" } : { axis: largest.axis, basis: "longest geometry axis", direction: "unknown" },
|
|
204
458
|
materials: resourceCounts.materials ?? resources.materials,
|
|
205
459
|
meshes: resourceCounts.meshes ?? resources.meshes,
|
|
206
|
-
path:
|
|
460
|
+
path: path8.resolve(file),
|
|
207
461
|
textures: resourceCounts.textures ?? resources.textures,
|
|
208
462
|
units: {
|
|
209
463
|
label: unitsLabel(largest?.value ?? 0),
|
|
@@ -232,7 +486,7 @@ function parseInspectArgs(argv) {
|
|
|
232
486
|
return { file, json: argv.includes("--json") };
|
|
233
487
|
}
|
|
234
488
|
async function inspectAsset(file) {
|
|
235
|
-
const extension =
|
|
489
|
+
const extension = path8.extname(file).toLowerCase();
|
|
236
490
|
if (!SUPPORTED_EXTENSIONS.has(extension)) {
|
|
237
491
|
throw new Error(`TN_ASSET_INSPECT_UNSUPPORTED: ${file}: expected a .glb or .gltf file.`);
|
|
238
492
|
}
|
|
@@ -260,388 +514,33 @@ function formatAssetInspection(result) {
|
|
|
260
514
|
const bones = result.bones.length === 0 ? "(none)" : `${result.bones.join(", ")} (${result.bones.length})`;
|
|
261
515
|
return `${[
|
|
262
516
|
result.file,
|
|
263
|
-
` bounds ${formatVector(result.bounds.size, " x ")} (centre ${formatVector(result.bounds.center, ", ")})`,
|
|
264
|
-
` units ${result.units.label} \u2014 longest axis ${result.units.longestAxis.toFixed(1)}`,
|
|
265
|
-
` forward ${forward}`,
|
|
266
|
-
` clips ${listOrNone(result.clips)}`,
|
|
267
|
-
` bones ${bones}`,
|
|
268
|
-
` meshes ${result.meshes} materials ${result.materials} textures ${result.textures}`
|
|
269
|
-
].join("\n")}
|
|
270
|
-
`;
|
|
271
|
-
}
|
|
272
|
-
function inspectHelp() {
|
|
273
|
-
return `${[
|
|
274
|
-
"Usage: npx create-threenative inspect <file.glb> [--json]",
|
|
275
|
-
"",
|
|
276
|
-
"Read a glTF asset and report its bounds, units heuristic, axis observation, clips, bones,",
|
|
277
|
-
"meshes, materials and textures. The command never modifies the asset.",
|
|
278
|
-
"",
|
|
279
|
-
"Options:",
|
|
280
|
-
" --json Print the same inspection as machine-readable JSON."
|
|
281
|
-
].join("\n")}
|
|
282
|
-
`;
|
|
283
|
-
}
|
|
284
|
-
async function inspectCommand(argv, write = (text) => process.stdout.write(text)) {
|
|
285
|
-
const options = parseInspectArgs(argv);
|
|
286
|
-
const result = await inspectAsset(options.file);
|
|
287
|
-
write(options.json ? `${JSON.stringify(result, null, 2)}
|
|
288
|
-
` : formatAssetInspection(result));
|
|
289
|
-
return result;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// ../core/mcp/servers.mjs
|
|
293
|
-
var MCP_SERVERS = Object.freeze({
|
|
294
|
-
"threenative-assets": Object.freeze({
|
|
295
|
-
command: "node",
|
|
296
|
-
args: Object.freeze(["./node_modules/@threenative/core/mcp/assets.mjs"]),
|
|
297
|
-
// Entries rather than an object literal: these are environment variable names, not identifiers,
|
|
298
|
-
// and written as property names they read as names the naming rule must judge.
|
|
299
|
-
env: Object.freeze(
|
|
300
|
-
Object.fromEntries([
|
|
301
|
-
["ASSET_DOWNLOAD_DIR", "./public/assets"],
|
|
302
|
-
["AUDIO_DOWNLOAD_DIR", "./public/audio"]
|
|
303
|
-
])
|
|
304
|
-
)
|
|
305
|
-
}),
|
|
306
|
-
"threenative-sculpt": Object.freeze({
|
|
307
|
-
command: "node",
|
|
308
|
-
args: Object.freeze(["./node_modules/@threenative/core/mcp/sculpt.mjs"])
|
|
309
|
-
}),
|
|
310
|
-
"threenative-engine": Object.freeze({
|
|
311
|
-
command: "node",
|
|
312
|
-
args: Object.freeze(["./node_modules/@threenative/core/mcp/engine.mjs"])
|
|
313
|
-
}),
|
|
314
|
-
// Cooks a starter terrain kit into a world.glb. The server lives in the optional
|
|
315
|
-
// `@threenative/terrain` package, which the shim resolves from the project at launch.
|
|
316
|
-
"threenative-terrain": Object.freeze({
|
|
317
|
-
command: "node",
|
|
318
|
-
args: Object.freeze(["./node_modules/@threenative/core/mcp/terrain.mjs"])
|
|
319
|
-
}),
|
|
320
|
-
// Inspects, attaches, edits and verifies character animation. Every operation is a build-time
|
|
321
|
-
// edit of one GLB, so a game that animates nothing pays for nothing.
|
|
322
|
-
"threenative-animation": Object.freeze({
|
|
323
|
-
command: "node",
|
|
324
|
-
args: Object.freeze(["./node_modules/@threenative/core/mcp/animation.mjs"])
|
|
325
|
-
}),
|
|
326
|
-
// Google's Chrome DevTools server: performance traces, GPU timing, network, heap and console of
|
|
327
|
-
// the running game. It starts Chrome only on its first tool call, so a project that never
|
|
328
|
-
// inspects a page pays nothing. Its async stack capture inflates CPU time several times, so
|
|
329
|
-
// `trace-a-slow-frame.md` sends absolute CPU questions to `playtest trace` first.
|
|
330
|
-
"threenative-devtools": Object.freeze({
|
|
331
|
-
command: "node",
|
|
332
|
-
args: Object.freeze(["./node_modules/@threenative/core/mcp/devtools.mjs"])
|
|
333
|
-
})
|
|
334
|
-
});
|
|
335
|
-
var SERVER_FORMATS = Object.freeze({
|
|
336
|
-
// Claude Code (`.mcp.json`), Cursor and the Gemini CLI all read this one.
|
|
337
|
-
mcpServers: Object.freeze({
|
|
338
|
-
key: "mcpServers",
|
|
339
|
-
entry: (server) => ({
|
|
340
|
-
command: server.command,
|
|
341
|
-
args: [...server.args],
|
|
342
|
-
...server.env === void 0 ? {} : { env: { ...server.env } }
|
|
343
|
-
})
|
|
344
|
-
}),
|
|
345
|
-
// VS Code names the table `servers` and requires an explicit transport per server.
|
|
346
|
-
vscode: Object.freeze({
|
|
347
|
-
key: "servers",
|
|
348
|
-
entry: (server) => ({
|
|
349
|
-
type: "stdio",
|
|
350
|
-
command: server.command,
|
|
351
|
-
args: [...server.args],
|
|
352
|
-
...server.env === void 0 ? {} : { env: { ...server.env } }
|
|
353
|
-
})
|
|
354
|
-
}),
|
|
355
|
-
// opencode folds the command and its arguments into one array and spells the environment
|
|
356
|
-
// `environment`. A server it does not mark enabled is written down and never started.
|
|
357
|
-
opencode: Object.freeze({
|
|
358
|
-
key: "mcp",
|
|
359
|
-
entry: (server) => ({
|
|
360
|
-
type: "local",
|
|
361
|
-
command: [server.command, ...server.args],
|
|
362
|
-
enabled: true,
|
|
363
|
-
...server.env === void 0 ? {} : { environment: { ...server.env } }
|
|
364
|
-
})
|
|
365
|
-
}),
|
|
366
|
-
// Zed calls them context servers and needs `source: "custom"` to accept a command of our own.
|
|
367
|
-
zed: Object.freeze({
|
|
368
|
-
key: "context_servers",
|
|
369
|
-
entry: (server) => ({
|
|
370
|
-
source: "custom",
|
|
371
|
-
command: server.command,
|
|
372
|
-
args: [...server.args],
|
|
373
|
-
...server.env === void 0 ? {} : { env: { ...server.env } }
|
|
374
|
-
})
|
|
375
|
-
})
|
|
376
|
-
});
|
|
377
|
-
Object.freeze(Object.keys(SERVER_FORMATS));
|
|
378
|
-
function mergeMcpServers(existing, format = "mcpServers") {
|
|
379
|
-
const shape = SERVER_FORMATS[format];
|
|
380
|
-
if (shape === void 0) throw new Error(`Unknown MCP config format '${format}'.`);
|
|
381
|
-
const malformed = existing !== void 0 && (typeof existing !== "object" || existing === null || Array.isArray(existing));
|
|
382
|
-
if (malformed) {
|
|
383
|
-
throw new Error("MCP config root must be an object.");
|
|
384
|
-
}
|
|
385
|
-
const previous = existing ?? {};
|
|
386
|
-
const existingServers = previous[shape.key];
|
|
387
|
-
if (existingServers !== void 0 && (typeof existingServers !== "object" || existingServers === null || Array.isArray(existingServers))) {
|
|
388
|
-
throw new Error(`MCP config '${shape.key}' must be an object.`);
|
|
389
|
-
}
|
|
390
|
-
const servers = { ...existingServers ?? {} };
|
|
391
|
-
for (const [name, server] of Object.entries(servers)) {
|
|
392
|
-
if (typeof server !== "object" || server === null || Array.isArray(server)) {
|
|
393
|
-
throw new Error(`MCP server '${name}' in '${shape.key}' must be an object.`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
let changed = false;
|
|
397
|
-
const conflicts = [];
|
|
398
|
-
for (const [name, server] of Object.entries(MCP_SERVERS)) {
|
|
399
|
-
const wanted = shape.entry(server);
|
|
400
|
-
if (Object.hasOwn(servers, name)) {
|
|
401
|
-
if (JSON.stringify(servers[name]) !== JSON.stringify(wanted)) conflicts.push(name);
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
servers[name] = wanted;
|
|
405
|
-
changed = true;
|
|
406
|
-
}
|
|
407
|
-
return { changed, conflicts, config: { ...previous, [shape.key]: servers } };
|
|
408
|
-
}
|
|
409
|
-
function codexServerBlock(name, server) {
|
|
410
|
-
const args = server.args.map((argument) => JSON.stringify(argument)).join(", ");
|
|
411
|
-
const lines = [
|
|
412
|
-
`[mcp_servers.${name}]`,
|
|
413
|
-
`command = ${JSON.stringify(server.command)}`,
|
|
414
|
-
`args = [${args}]`
|
|
415
|
-
];
|
|
416
|
-
if (server.env !== void 0) {
|
|
417
|
-
lines.push("", `[mcp_servers.${name}.env]`);
|
|
418
|
-
for (const [key, value] of Object.entries(server.env)) {
|
|
419
|
-
lines.push(`${key} = ${JSON.stringify(value)}`);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return lines.join("\n");
|
|
423
|
-
}
|
|
424
|
-
var CODEX_MCP_SERVERS = Object.freeze(
|
|
425
|
-
Object.entries(MCP_SERVERS).map(
|
|
426
|
-
([name, server]) => Object.freeze({ body: codexServerBlock(name, server), name })
|
|
427
|
-
)
|
|
428
|
-
);
|
|
429
|
-
var MCP_HOSTS = Object.freeze([
|
|
430
|
-
Object.freeze({
|
|
431
|
-
id: "claude-code",
|
|
432
|
-
label: "Claude Code",
|
|
433
|
-
file: ".mcp.json",
|
|
434
|
-
format: "mcpServers"
|
|
435
|
-
}),
|
|
436
|
-
Object.freeze({ id: "codex", label: "Codex", file: ".codex/config.toml", format: "codex" }),
|
|
437
|
-
Object.freeze({ id: "cursor", label: "Cursor", file: ".cursor/mcp.json", format: "mcpServers" }),
|
|
438
|
-
Object.freeze({ id: "vscode", label: "VS Code", file: ".vscode/mcp.json", format: "vscode" }),
|
|
439
|
-
Object.freeze({
|
|
440
|
-
id: "gemini-cli",
|
|
441
|
-
label: "Gemini CLI",
|
|
442
|
-
file: ".gemini/settings.json",
|
|
443
|
-
format: "mcpServers"
|
|
444
|
-
}),
|
|
445
|
-
Object.freeze({
|
|
446
|
-
id: "opencode",
|
|
447
|
-
label: "opencode",
|
|
448
|
-
file: "opencode.json",
|
|
449
|
-
format: "opencode",
|
|
450
|
-
// Written only when this installer creates the file, so a second install still reports
|
|
451
|
-
// "unchanged" rather than rewriting a config the user has since edited.
|
|
452
|
-
seed: Object.freeze({ $schema: "https://opencode.ai/config.json" })
|
|
453
|
-
}),
|
|
454
|
-
Object.freeze({ id: "zed", label: "Zed", file: ".zed/settings.json", format: "zed" })
|
|
455
|
-
]);
|
|
456
|
-
function ensureJsonMcpConfig(target, file, format, seed = void 0) {
|
|
457
|
-
const configPath = path7.join(target, file);
|
|
458
|
-
let existing;
|
|
459
|
-
if (existsSync(configPath)) {
|
|
460
|
-
try {
|
|
461
|
-
existing = JSON.parse(readFileSync(configPath, "utf8"));
|
|
462
|
-
} catch {
|
|
463
|
-
return "unreadable";
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
let merged;
|
|
467
|
-
try {
|
|
468
|
-
merged = mergeMcpServers(existing, format);
|
|
469
|
-
} catch {
|
|
470
|
-
return "unreadable";
|
|
471
|
-
}
|
|
472
|
-
const { changed, config, conflicts } = merged;
|
|
473
|
-
if (!changed) return conflicts.length > 0 ? "conflict" : "unchanged";
|
|
474
|
-
const written = existing === void 0 ? { ...seed, ...config } : config;
|
|
475
|
-
mkdirSync(path7.dirname(configPath), { recursive: true });
|
|
476
|
-
writeFileSync(configPath, `${JSON.stringify(written, null, 2)}
|
|
477
|
-
`);
|
|
478
|
-
return conflicts.length > 0 ? "conflict" : existing === void 0 ? "created" : "updated";
|
|
479
|
-
}
|
|
480
|
-
function ensureCodexMcpConfig(target) {
|
|
481
|
-
const directory = path7.join(target, ".codex");
|
|
482
|
-
const configPath = path7.join(directory, "config.toml");
|
|
483
|
-
const existing = existsSync(configPath) ? readFileSync(configPath, "utf8") : "";
|
|
484
|
-
const missing = CODEX_MCP_SERVERS.filter(
|
|
485
|
-
({ name }) => !existing.includes(`[mcp_servers.${name}]`)
|
|
486
|
-
);
|
|
487
|
-
if (missing.length === 0) return "unchanged";
|
|
488
|
-
mkdirSync(directory, { recursive: true });
|
|
489
|
-
const separator = existing.length === 0 || existing.endsWith("\n\n") ? "" : existing.endsWith("\n") ? "\n" : "\n\n";
|
|
490
|
-
writeFileSync(
|
|
491
|
-
configPath,
|
|
492
|
-
`${existing}${separator}${missing.map(({ body }) => body).join("\n\n")}
|
|
493
|
-
`
|
|
494
|
-
);
|
|
495
|
-
return existing.length === 0 ? "created" : "updated";
|
|
496
|
-
}
|
|
497
|
-
function ensureHostMcpConfigs(target) {
|
|
498
|
-
const outcomes = /* @__PURE__ */ new Map();
|
|
499
|
-
for (const host of MCP_HOSTS) {
|
|
500
|
-
try {
|
|
501
|
-
outcomes.set(
|
|
502
|
-
host.id,
|
|
503
|
-
host.format === "codex" ? ensureCodexMcpConfig(target) : ensureJsonMcpConfig(target, host.file, host.format, host.seed)
|
|
504
|
-
);
|
|
505
|
-
} catch {
|
|
506
|
-
outcomes.set(host.id, "unreadable");
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
return outcomes;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// src/mcp-servers.ts
|
|
513
|
-
function serverEntryPath(server) {
|
|
514
|
-
const entry = server.args[0];
|
|
515
|
-
if (entry === void 0) {
|
|
516
|
-
throw new Error("TN_MCP_TABLE: an MCP server entry declares no shim to launch.");
|
|
517
|
-
}
|
|
518
|
-
return entry;
|
|
519
|
-
}
|
|
520
|
-
var DECODER_LOADER_ID = /[/\\]examples[/\\]jsm[/\\]loaders[/\\](?:KTX2Loader|DRACOLoader)\.js$/u;
|
|
521
|
-
var DECODER_LIB_ASSET_URL = /new URL\(\s*(['"])\.\.\/libs\/([^'"]+)\1\s*,\s*import\.meta\.url\s*\)(?:\.toString\s*\(\s*\)|\.href\s*)?/gu;
|
|
522
|
-
function rewriteDecoderAssetUrls(code) {
|
|
523
|
-
return code.replace(DECODER_LIB_ASSET_URL, '"../libs/$2"');
|
|
524
|
-
}
|
|
525
|
-
var MARKER_RELATIVE = path7.join("node_modules", ".vite", "threenative-engine-build.json");
|
|
526
|
-
function hashTree(hash, directory) {
|
|
527
|
-
const entries = readdirSync(directory, { withFileTypes: true }).sort(
|
|
528
|
-
(left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0
|
|
529
|
-
);
|
|
530
|
-
for (const entry of entries) {
|
|
531
|
-
const full = path7.join(directory, entry.name);
|
|
532
|
-
if (entry.isDirectory()) {
|
|
533
|
-
hashTree(hash, full);
|
|
534
|
-
} else if (entry.isFile()) {
|
|
535
|
-
hash.update(path7.relative(directory, full));
|
|
536
|
-
hash.update(readFileSync(full));
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
function hashEngineDist(projectRoot) {
|
|
541
|
-
const scopeDir = path7.join(projectRoot, "node_modules", "@threenative");
|
|
542
|
-
let packages;
|
|
543
|
-
try {
|
|
544
|
-
packages = readdirSync(scopeDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => entry.name).sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
|
|
545
|
-
} catch {
|
|
546
|
-
return void 0;
|
|
547
|
-
}
|
|
548
|
-
const dists = [];
|
|
549
|
-
for (const name of packages) {
|
|
550
|
-
let packageDir = path7.join(scopeDir, name);
|
|
551
|
-
try {
|
|
552
|
-
packageDir = realpathSync(packageDir);
|
|
553
|
-
} catch {
|
|
554
|
-
continue;
|
|
555
|
-
}
|
|
556
|
-
const dist = path7.join(packageDir, "dist");
|
|
557
|
-
if (existsSync(dist)) dists.push([name, dist]);
|
|
558
|
-
}
|
|
559
|
-
if (dists.length === 0) return void 0;
|
|
560
|
-
const hash = createHash("sha256");
|
|
561
|
-
for (const [name, dist] of dists) {
|
|
562
|
-
hash.update(name);
|
|
563
|
-
hashTree(hash, dist);
|
|
564
|
-
}
|
|
565
|
-
return hash.digest("hex");
|
|
566
|
-
}
|
|
567
|
-
function markerPath(projectRoot) {
|
|
568
|
-
return path7.join(projectRoot, MARKER_RELATIVE);
|
|
569
|
-
}
|
|
570
|
-
function readMarker(file) {
|
|
571
|
-
try {
|
|
572
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
573
|
-
} catch {
|
|
574
|
-
return void 0;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
function processIsAlive(pid) {
|
|
578
|
-
if (pid === process.pid) return true;
|
|
579
|
-
try {
|
|
580
|
-
process.kill(pid, 0);
|
|
581
|
-
return true;
|
|
582
|
-
} catch (error) {
|
|
583
|
-
return error.code === "EPERM";
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
function createEngineFreshnessPlugin() {
|
|
587
|
-
let recordedHash;
|
|
588
|
-
const rootOf = (config) => path7.resolve(config.root ?? process.cwd());
|
|
589
|
-
return {
|
|
590
|
-
name: "threenative-engine-freshness",
|
|
591
|
-
config(config, env) {
|
|
592
|
-
const resolve = { dedupe: ["three", "react", "react-dom"] };
|
|
593
|
-
if (env.command !== "serve") return { resolve };
|
|
594
|
-
const root = rootOf(config);
|
|
595
|
-
recordedHash = hashEngineDist(root);
|
|
596
|
-
const marker = recordedHash === void 0 ? void 0 : readMarker(markerPath(root));
|
|
597
|
-
if (recordedHash === void 0 || marker === void 0 || marker.hash === recordedHash) {
|
|
598
|
-
return { resolve };
|
|
599
|
-
}
|
|
600
|
-
if (processIsAlive(marker.pid)) {
|
|
601
|
-
const where = marker.port === void 0 ? `pid ${marker.pid}` : `pid ${marker.pid} on port ${marker.port}`;
|
|
602
|
-
const how = marker.port === void 0 ? "" : ` (lsof -ti tcp:${marker.port} | xargs -r kill)`;
|
|
603
|
-
console.warn(
|
|
604
|
-
`threenative: a dev server is still running at ${where}, serving engine build ${marker.hash.slice(0, 8)}; the installed build is ${recordedHash.slice(0, 8)}. Kill it before playing${how} \u2014 its tab renders yesterday's engine.`
|
|
605
|
-
);
|
|
606
|
-
}
|
|
607
|
-
return { resolve, optimizeDeps: { force: true } };
|
|
608
|
-
},
|
|
609
|
-
transform(code, id) {
|
|
610
|
-
if (!DECODER_LOADER_ID.test(id)) return null;
|
|
611
|
-
const rewritten = rewriteDecoderAssetUrls(code);
|
|
612
|
-
return rewritten === code ? null : { code: rewritten, map: null };
|
|
613
|
-
},
|
|
614
|
-
configureServer(server) {
|
|
615
|
-
const root = rootOf(server.config);
|
|
616
|
-
const file = markerPath(root);
|
|
617
|
-
const writeBootMarker = (port) => {
|
|
618
|
-
const hash = recordedHash ?? hashEngineDist(root);
|
|
619
|
-
if (hash === void 0) return;
|
|
620
|
-
mkdirSync(path7.dirname(file), { recursive: true });
|
|
621
|
-
writeFileSync(
|
|
622
|
-
file,
|
|
623
|
-
JSON.stringify(
|
|
624
|
-
port === void 0 ? { hash, pid: process.pid } : { hash, pid: process.pid, port }
|
|
625
|
-
)
|
|
626
|
-
);
|
|
627
|
-
};
|
|
628
|
-
const httpServer = server.httpServer;
|
|
629
|
-
if (httpServer === void 0 || httpServer === null) {
|
|
630
|
-
writeBootMarker(void 0);
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
httpServer.once("listening", () => {
|
|
634
|
-
const address = httpServer.address();
|
|
635
|
-
writeBootMarker(
|
|
636
|
-
typeof address === "object" && address !== null && address.port !== void 0 ? address.port : void 0
|
|
637
|
-
);
|
|
638
|
-
});
|
|
639
|
-
httpServer.once("close", () => {
|
|
640
|
-
const marker = readMarker(file);
|
|
641
|
-
if (marker?.pid === process.pid) rmSync(file, { force: true });
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
};
|
|
517
|
+
` bounds ${formatVector(result.bounds.size, " x ")} (centre ${formatVector(result.bounds.center, ", ")})`,
|
|
518
|
+
` units ${result.units.label} \u2014 longest axis ${result.units.longestAxis.toFixed(1)}`,
|
|
519
|
+
` forward ${forward}`,
|
|
520
|
+
` clips ${listOrNone(result.clips)}`,
|
|
521
|
+
` bones ${bones}`,
|
|
522
|
+
` meshes ${result.meshes} materials ${result.materials} textures ${result.textures}`
|
|
523
|
+
].join("\n")}
|
|
524
|
+
`;
|
|
525
|
+
}
|
|
526
|
+
function inspectHelp() {
|
|
527
|
+
return `${[
|
|
528
|
+
"Usage: npx create-threenative inspect <file.glb> [--json]",
|
|
529
|
+
"",
|
|
530
|
+
"Read a glTF asset and report its bounds, units heuristic, axis observation, clips, bones,",
|
|
531
|
+
"meshes, materials and textures. The command never modifies the asset.",
|
|
532
|
+
"",
|
|
533
|
+
"Options:",
|
|
534
|
+
" --json Print the same inspection as machine-readable JSON."
|
|
535
|
+
].join("\n")}
|
|
536
|
+
`;
|
|
537
|
+
}
|
|
538
|
+
async function inspectCommand(argv, write = (text) => process.stdout.write(text)) {
|
|
539
|
+
const options = parseInspectArgs(argv);
|
|
540
|
+
const result = await inspectAsset(options.file);
|
|
541
|
+
write(options.json ? `${JSON.stringify(result, null, 2)}
|
|
542
|
+
` : formatAssetInspection(result));
|
|
543
|
+
return result;
|
|
645
544
|
}
|
|
646
545
|
var ORIENTATIONS = ["landscape", "portrait", "sensor"];
|
|
647
546
|
var CONFIG_FILE = "threenative.config.ts";
|
|
@@ -693,6 +592,13 @@ function positiveInteger(value, fallback, code, label) {
|
|
|
693
592
|
}
|
|
694
593
|
return value;
|
|
695
594
|
}
|
|
595
|
+
function priorityValue(value) {
|
|
596
|
+
if (value === void 0) return "game";
|
|
597
|
+
if (value !== "game" && value !== "normal") {
|
|
598
|
+
fail("TN_CONFIG_PRIORITY_INVALID", 'display.priority must be "game" or "normal".');
|
|
599
|
+
}
|
|
600
|
+
return value;
|
|
601
|
+
}
|
|
696
602
|
function maxFpsValue(value) {
|
|
697
603
|
if (value === void 0) return 60;
|
|
698
604
|
if (!Number.isSafeInteger(value) || value < 0 || value > 1e3) {
|
|
@@ -717,13 +623,13 @@ function defaultAppId(name) {
|
|
|
717
623
|
return `com.threenative.${segment}`;
|
|
718
624
|
}
|
|
719
625
|
function projectRequire(cwd) {
|
|
720
|
-
return createRequire$1(
|
|
626
|
+
return createRequire$1(path8.join(cwd, "package.json"));
|
|
721
627
|
}
|
|
722
628
|
function configLoaderSearch(cwd) {
|
|
723
629
|
return [
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
630
|
+
path8.join(cwd, "node_modules", "vite"),
|
|
631
|
+
path8.join(cwd, "node_modules", "esbuild"),
|
|
632
|
+
path8.resolve(path8.dirname(fileURLToPath(import.meta.url)), "..", "node_modules", "esbuild")
|
|
727
633
|
];
|
|
728
634
|
}
|
|
729
635
|
var CONFIG_BUILD_COMMAND = "pnpm exec threenative build --target web";
|
|
@@ -731,7 +637,7 @@ function configContext(cwd, layer, sources, searched, fix) {
|
|
|
731
637
|
return { cwd, fix, layer, searched, sources };
|
|
732
638
|
}
|
|
733
639
|
function packageContext(cwd) {
|
|
734
|
-
const packagePath =
|
|
640
|
+
const packagePath = path8.join(cwd, "package.json");
|
|
735
641
|
return configContext(
|
|
736
642
|
cwd,
|
|
737
643
|
"package manifest",
|
|
@@ -754,8 +660,8 @@ function validationContext(cwd, sources) {
|
|
|
754
660
|
cwd,
|
|
755
661
|
"config validation",
|
|
756
662
|
sources,
|
|
757
|
-
[
|
|
758
|
-
`fix '${
|
|
663
|
+
[path8.join(cwd, "package.json"), path8.join(cwd, CONFIG_FILE)],
|
|
664
|
+
`fix '${path8.join(cwd, CONFIG_FILE)}' and rerun ${CONFIG_BUILD_COMMAND}`
|
|
759
665
|
);
|
|
760
666
|
}
|
|
761
667
|
function configFailure(code, context, detail) {
|
|
@@ -794,8 +700,12 @@ function resolveEsbuild(cwd) {
|
|
|
794
700
|
}
|
|
795
701
|
}
|
|
796
702
|
}
|
|
703
|
+
var configLoadSequence = 0;
|
|
704
|
+
function configTempName(cwd, pid, now, sequence) {
|
|
705
|
+
return path8.join(cwd, `.threenative.config.${pid}.${now}.${sequence}.mjs`);
|
|
706
|
+
}
|
|
797
707
|
async function importConfig(cwd) {
|
|
798
|
-
const sourcePath =
|
|
708
|
+
const sourcePath = path8.join(cwd, CONFIG_FILE);
|
|
799
709
|
try {
|
|
800
710
|
await access(sourcePath);
|
|
801
711
|
} catch {
|
|
@@ -856,7 +766,8 @@ async function importConfig(cwd) {
|
|
|
856
766
|
error instanceof Error ? error.message : String(error)
|
|
857
767
|
);
|
|
858
768
|
}
|
|
859
|
-
|
|
769
|
+
configLoadSequence += 1;
|
|
770
|
+
const compiledPath = configTempName(cwd, process.pid, Date.now(), configLoadSequence);
|
|
860
771
|
try {
|
|
861
772
|
await writeFile(compiledPath, code, "utf8");
|
|
862
773
|
} catch (error) {
|
|
@@ -892,7 +803,7 @@ async function importConfig(cwd) {
|
|
|
892
803
|
async function readManifest(cwd) {
|
|
893
804
|
let parsed;
|
|
894
805
|
try {
|
|
895
|
-
parsed = JSON.parse(await readFile(
|
|
806
|
+
parsed = JSON.parse(await readFile(path8.join(cwd, "package.json"), "utf8"));
|
|
896
807
|
} catch (error) {
|
|
897
808
|
fail("TN_CONFIG_PACKAGE_INVALID", error instanceof Error ? error.message : String(error));
|
|
898
809
|
}
|
|
@@ -911,12 +822,12 @@ function packageNativeEntry(manifest) {
|
|
|
911
822
|
}
|
|
912
823
|
function validateNativeEntry(value, cwd) {
|
|
913
824
|
const entry = nonEmptyString(value, "TN_NATIVE_ENTRY_MISSING", "nativeEntry");
|
|
914
|
-
if (
|
|
825
|
+
if (path8.isAbsolute(entry)) {
|
|
915
826
|
fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must be project-relative.");
|
|
916
827
|
}
|
|
917
|
-
const resolved =
|
|
918
|
-
const relative =
|
|
919
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
828
|
+
const resolved = path8.resolve(cwd, entry);
|
|
829
|
+
const relative = path8.relative(cwd, resolved);
|
|
830
|
+
if (relative === ".." || relative.startsWith(`..${path8.sep}`) || path8.isAbsolute(relative)) {
|
|
920
831
|
fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must stay inside the project.");
|
|
921
832
|
}
|
|
922
833
|
return entry;
|
|
@@ -960,18 +871,18 @@ async function validateApp(raw, name, cwd) {
|
|
|
960
871
|
}
|
|
961
872
|
async function validateProjectAsset(raw, cwd, label, options) {
|
|
962
873
|
const relative = nonEmptyString(raw, `${options.codePrefix}_INVALID`, label);
|
|
963
|
-
if (
|
|
874
|
+
if (path8.isAbsolute(relative)) {
|
|
964
875
|
fail(`${options.codePrefix}_PATH_INVALID`, `${label} must be project-relative: ${relative}`);
|
|
965
876
|
}
|
|
966
|
-
const resolved =
|
|
967
|
-
const withinProject =
|
|
968
|
-
if (withinProject === ".." || withinProject.startsWith(`..${
|
|
877
|
+
const resolved = path8.resolve(cwd, relative);
|
|
878
|
+
const withinProject = path8.relative(cwd, resolved);
|
|
879
|
+
if (withinProject === ".." || withinProject.startsWith(`..${path8.sep}`) || path8.isAbsolute(withinProject)) {
|
|
969
880
|
fail(
|
|
970
881
|
`${options.codePrefix}_PATH_INVALID`,
|
|
971
882
|
`${label} must stay inside the project: ${relative}`
|
|
972
883
|
);
|
|
973
884
|
}
|
|
974
|
-
const extension =
|
|
885
|
+
const extension = path8.extname(relative).slice(1).toLowerCase();
|
|
975
886
|
if (!options.formats.includes(extension)) {
|
|
976
887
|
fail(
|
|
977
888
|
options.codePrefix === "TN_CONFIG_ICON" ? `${options.codePrefix}_INVALID` : `${options.codePrefix}_FORMAT_INVALID`,
|
|
@@ -1131,7 +1042,13 @@ async function validateIconVariants(raw, cwd) {
|
|
|
1131
1042
|
}
|
|
1132
1043
|
function validateDisplay(raw) {
|
|
1133
1044
|
const display = assertRecord(raw, "display");
|
|
1134
|
-
assertKeys(display, "display", [
|
|
1045
|
+
assertKeys(display, "display", [
|
|
1046
|
+
"orientation",
|
|
1047
|
+
"fullscreen",
|
|
1048
|
+
"keepScreenOn",
|
|
1049
|
+
"priority",
|
|
1050
|
+
"maxFps"
|
|
1051
|
+
]);
|
|
1135
1052
|
const orientation = display.orientation === void 0 ? "landscape" : display.orientation;
|
|
1136
1053
|
if (typeof orientation !== "string" || !ORIENTATIONS.includes(orientation)) {
|
|
1137
1054
|
fail(
|
|
@@ -1153,6 +1070,7 @@ function validateDisplay(raw) {
|
|
|
1153
1070
|
"TN_CONFIG_KEEP_SCREEN_ON_INVALID",
|
|
1154
1071
|
"display.keepScreenOn"
|
|
1155
1072
|
),
|
|
1073
|
+
priority: priorityValue(display.priority),
|
|
1156
1074
|
maxFps: maxFpsValue(display.maxFps)
|
|
1157
1075
|
};
|
|
1158
1076
|
}
|
|
@@ -1973,8 +1891,8 @@ function assertProfileCapReachable(assets, overlay, name) {
|
|
|
1973
1891
|
}
|
|
1974
1892
|
}
|
|
1975
1893
|
async function loadConfigInternal(root, selection) {
|
|
1976
|
-
const packagePath =
|
|
1977
|
-
const sourcePath =
|
|
1894
|
+
const packagePath = path8.join(root, "package.json");
|
|
1895
|
+
const sourcePath = path8.join(root, CONFIG_FILE);
|
|
1978
1896
|
const manifest = await withConfigContext(
|
|
1979
1897
|
packageContext(root),
|
|
1980
1898
|
"TN_CONFIG_PACKAGE_INVALID",
|
|
@@ -2049,15 +1967,15 @@ async function loadConfigInternal(root, selection) {
|
|
|
2049
1967
|
);
|
|
2050
1968
|
}
|
|
2051
1969
|
async function loadConfig(cwd, selection) {
|
|
2052
|
-
const root =
|
|
1970
|
+
const root = path8.resolve(cwd);
|
|
2053
1971
|
return withConfigContext(
|
|
2054
|
-
validationContext(root, [
|
|
1972
|
+
validationContext(root, [path8.join(root, CONFIG_FILE), path8.join(root, "package.json")]),
|
|
2055
1973
|
"TN_CONFIG_VALIDATION_FAILED",
|
|
2056
1974
|
() => loadConfigInternal(root, selection)
|
|
2057
1975
|
);
|
|
2058
1976
|
}
|
|
2059
|
-
function webRuntimeDecoders(
|
|
2060
|
-
return
|
|
1977
|
+
function webRuntimeDecoders(_config) {
|
|
1978
|
+
return { ktx2: true, meshopt: true };
|
|
2061
1979
|
}
|
|
2062
1980
|
var WEB_ENGINE_ID = "\0threenative:web-engine";
|
|
2063
1981
|
var UPSTREAM = ["three", "three/webgpu", "three/tsl"];
|
|
@@ -2095,9 +2013,14 @@ var ENGINE_MATH_MODULES = /* @__PURE__ */ new Set([
|
|
|
2095
2013
|
"three/src/math/Sphere.js",
|
|
2096
2014
|
"three/src/math/Vector2.js",
|
|
2097
2015
|
"three/src/math/Vector3.js",
|
|
2098
|
-
"three/src/math/Vector4.js"
|
|
2016
|
+
"three/src/math/Vector4.js",
|
|
2017
|
+
// three's loader base classes (browser-loaders.ts): fetch and request tracking, no drawing.
|
|
2018
|
+
"three/src/loaders/Cache.js",
|
|
2019
|
+
"three/src/loaders/FileLoader.js",
|
|
2020
|
+
"three/src/loaders/Loader.js",
|
|
2021
|
+
"three/src/loaders/LoadingManager.js"
|
|
2099
2022
|
]);
|
|
2100
|
-
var ENGINE_MATH_IMPORTER = /[\\/](?:browser-math\.ts|web-engine-runtime\.js)(?:\?.*)?$/u;
|
|
2023
|
+
var ENGINE_MATH_IMPORTER = /[\\/](?:browser-math\.ts|browser-loaders\.ts|web-engine-runtime\.js)(?:\?.*)?$/u;
|
|
2101
2024
|
function browserModule(built, source) {
|
|
2102
2025
|
const bundled = fileURLToPath(new URL(`./${built}`, import.meta.url));
|
|
2103
2026
|
if (existsSync(bundled)) return bundled;
|
|
@@ -2117,9 +2040,9 @@ function wasmModule(root, explicit) {
|
|
|
2117
2040
|
}
|
|
2118
2041
|
let entry;
|
|
2119
2042
|
try {
|
|
2120
|
-
const require2 = createRequire$1(
|
|
2121
|
-
entry =
|
|
2122
|
-
|
|
2043
|
+
const require2 = createRequire$1(path8.join(root, "package.json"));
|
|
2044
|
+
entry = path8.join(
|
|
2045
|
+
path8.dirname(require2.resolve("@threenative/runtime-native/package.json")),
|
|
2123
2046
|
WASM_ENGINE_ENTRY
|
|
2124
2047
|
);
|
|
2125
2048
|
} catch {
|
|
@@ -2133,15 +2056,69 @@ function wasmModule(root, explicit) {
|
|
|
2133
2056
|
);
|
|
2134
2057
|
return entry;
|
|
2135
2058
|
}
|
|
2059
|
+
function esmEntry(resolved) {
|
|
2060
|
+
if (!resolved.endsWith(".cjs")) return resolved;
|
|
2061
|
+
for (let dir = path8.dirname(resolved); dir !== path8.dirname(dir); dir = path8.dirname(dir)) {
|
|
2062
|
+
const manifest = path8.join(dir, "package.json");
|
|
2063
|
+
if (!existsSync(manifest)) continue;
|
|
2064
|
+
const root = JSON.parse(readFileSync(manifest, "utf8")).exports?.["."];
|
|
2065
|
+
const sameEntry = typeof root?.require === "string" && path8.join(dir, root.require) === resolved;
|
|
2066
|
+
return sameEntry && typeof root?.import === "string" ? path8.join(dir, root.import) : resolved;
|
|
2067
|
+
}
|
|
2068
|
+
return resolved;
|
|
2069
|
+
}
|
|
2136
2070
|
async function upstreamNames(root) {
|
|
2137
|
-
const require2 = createRequire$1(
|
|
2071
|
+
const require2 = createRequire$1(path8.join(root, "package.json"));
|
|
2138
2072
|
const modules = await Promise.all(
|
|
2139
|
-
UPSTREAM.map(
|
|
2073
|
+
UPSTREAM.map(
|
|
2074
|
+
(id) => import(pathToFileURL(esmEntry(require2.resolve(id))).href)
|
|
2075
|
+
)
|
|
2140
2076
|
);
|
|
2141
2077
|
return [...new Set(modules.flatMap((module) => Object.keys(module)))].filter((name) => name !== "default" && name !== "module.exports").sort();
|
|
2142
2078
|
}
|
|
2079
|
+
var REFUSAL = /^(TN_[A-Z0-9_]+): (\S+) is not available on the Wasm engine\.$/u;
|
|
2080
|
+
async function upstreamRefusals(root, wasm) {
|
|
2081
|
+
const entry = wasmModule(root, wasm);
|
|
2082
|
+
const binary = readFileSync(entry.replace(/\.mjs$/u, ".wasm"));
|
|
2083
|
+
const create = (await import(pathToFileURL(entry).href)).default;
|
|
2084
|
+
const { bindWebEngine } = await import(pathToFileURL(runtimeModule()).href);
|
|
2085
|
+
const names = await upstreamNames(root);
|
|
2086
|
+
const bound = await bindWebEngine(
|
|
2087
|
+
(options) => create({
|
|
2088
|
+
...options,
|
|
2089
|
+
print: () => {
|
|
2090
|
+
},
|
|
2091
|
+
printErr: () => {
|
|
2092
|
+
},
|
|
2093
|
+
// The web build fetches its .wasm by URL; Node has no page to fetch from.
|
|
2094
|
+
instantiateWasm(imports, receive) {
|
|
2095
|
+
void WebAssembly.instantiate(binary, imports).then(
|
|
2096
|
+
(result) => receive(result.instance, result.module)
|
|
2097
|
+
);
|
|
2098
|
+
return {};
|
|
2099
|
+
}
|
|
2100
|
+
}),
|
|
2101
|
+
names
|
|
2102
|
+
);
|
|
2103
|
+
return refusalsOf(bound, names);
|
|
2104
|
+
}
|
|
2105
|
+
function refusalsOf(bound, names) {
|
|
2106
|
+
const refusals = /* @__PURE__ */ new Map();
|
|
2107
|
+
for (const name of names) {
|
|
2108
|
+
const value = bound[name];
|
|
2109
|
+
if (typeof value !== "function") continue;
|
|
2110
|
+
try {
|
|
2111
|
+
Reflect.ownKeys(value);
|
|
2112
|
+
} catch (error) {
|
|
2113
|
+
const match = REFUSAL.exec(error instanceof Error ? error.message : "");
|
|
2114
|
+
if (match?.[2] === name && match[1] !== void 0) refusals.set(name, match[1]);
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
return refusals;
|
|
2118
|
+
}
|
|
2143
2119
|
function createWebEnginePlugin(options = {}) {
|
|
2144
2120
|
let root = options.root;
|
|
2121
|
+
let strict = options.strict ?? true;
|
|
2145
2122
|
const native = options.engine === "threenative";
|
|
2146
2123
|
const projectRoot = () => {
|
|
2147
2124
|
if (root === void 0)
|
|
@@ -2153,6 +2130,7 @@ function createWebEnginePlugin(options = {}) {
|
|
|
2153
2130
|
enforce: "pre",
|
|
2154
2131
|
configResolved(config) {
|
|
2155
2132
|
root ??= config.root;
|
|
2133
|
+
strict = options.strict ?? config.command !== "build";
|
|
2156
2134
|
},
|
|
2157
2135
|
resolveId(specifier, importer = "") {
|
|
2158
2136
|
if (!native) return null;
|
|
@@ -2172,6 +2150,8 @@ function createWebEnginePlugin(options = {}) {
|
|
|
2172
2150
|
);
|
|
2173
2151
|
if (source === "three/addons/geometries/DecalGeometry.js")
|
|
2174
2152
|
return browserModule("web-engine-decal-geometry.js", "addons/decal-geometry.ts");
|
|
2153
|
+
if (source === "three/addons/animation/CCDIKSolver.js")
|
|
2154
|
+
return browserModule("web-engine-ccd-ik-solver.js", "addons/ccd-ik-solver.ts");
|
|
2175
2155
|
if (source === "three/addons/loaders/HDRLoader.js")
|
|
2176
2156
|
return browserModule("web-engine-hdr-loader.js", "addons/hdr-loader.ts");
|
|
2177
2157
|
if (source === "three/addons/loaders/GLTFLoader.js")
|
|
@@ -2201,27 +2181,268 @@ function createWebEnginePlugin(options = {}) {
|
|
|
2201
2181
|
"__tnLoadGltf"
|
|
2202
2182
|
];
|
|
2203
2183
|
const single = wasmModule(projectRoot(), options.wasm);
|
|
2204
|
-
const threads =
|
|
2184
|
+
const threads = path8.join(path8.dirname(single), path8.basename(WASM_THREADS_ENTRY));
|
|
2205
2185
|
if (!existsSync(threads))
|
|
2206
2186
|
throw new Error(
|
|
2207
2187
|
`TN_WASM_THREADS_MISSING: engine "threenative" needs the threaded Wasm engine at ${threads}; reinstall @threenative/runtime-native, or in a ThreeNative checkout run \`pnpm wasm:build\` (presets wasm and wasm-threads). ${OPT_OUT}`
|
|
2208
2188
|
);
|
|
2209
|
-
|
|
2189
|
+
const off = (detail) => `${THREADS_OFF}: ${detail} Serve the game over https or localhost (the build's service worker adds Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp), or send both headers; on itch.io enable "SharedArrayBuffer support".`;
|
|
2190
|
+
const head = [
|
|
2210
2191
|
`import { bindWebEngine } from ${JSON.stringify(runtimeModule())};`,
|
|
2192
|
+
"if (globalThis.crossOriginIsolated !== true) await globalThis.__tnIsolation;"
|
|
2193
|
+
];
|
|
2194
|
+
const threadsReport = "${globalThis.__tnWebThreads}";
|
|
2195
|
+
const lines = strict ? [
|
|
2211
2196
|
"if (globalThis.crossOriginIsolated !== true)",
|
|
2212
|
-
` throw new Error(
|
|
2197
|
+
` throw new Error(${JSON.stringify(off("this page is not cross-origin isolated, so the engine cannot start its worker threads."))});`,
|
|
2213
2198
|
`const createModule = (await import(${JSON.stringify(threads)})).default;`,
|
|
2214
2199
|
`const engine = await bindWebEngine(createModule, ${JSON.stringify(names)});`,
|
|
2215
2200
|
'if (!String(globalThis.__tnWebThreads).startsWith("on"))',
|
|
2216
|
-
` throw new Error(\`${THREADS_OFF}: the engine's job pool started no worker thread (
|
|
2217
|
-
|
|
2218
|
-
""
|
|
2219
|
-
|
|
2201
|
+
` throw new Error(\`${THREADS_OFF}: the engine's job pool started no worker thread (${threadsReport}).\`);`
|
|
2202
|
+
] : [
|
|
2203
|
+
"const createModule = (",
|
|
2204
|
+
" globalThis.crossOriginIsolated === true",
|
|
2205
|
+
` ? await import(${JSON.stringify(threads)})`,
|
|
2206
|
+
` : await import(${JSON.stringify(single)})`,
|
|
2207
|
+
").default;",
|
|
2208
|
+
`const engine = await bindWebEngine(createModule, ${JSON.stringify(names)});`,
|
|
2209
|
+
'if (!String(globalThis.__tnWebThreads).startsWith("on"))',
|
|
2210
|
+
` console.warn(\`${off(`the engine runs without worker threads (${threadsReport}), so frames cost more.`).replaceAll("`", "\\`")}\`);`
|
|
2211
|
+
];
|
|
2212
|
+
return [...head, ...lines, `export const { ${names.join(", ")} } = engine;`, ""].join("\n");
|
|
2220
2213
|
}
|
|
2221
2214
|
};
|
|
2222
2215
|
}
|
|
2223
2216
|
|
|
2224
|
-
// src/
|
|
2217
|
+
// src/engine-catalog.ts
|
|
2218
|
+
var CHECKED_SOURCES = /* @__PURE__ */ new Set(["three", "three/webgpu", "three/tsl"]);
|
|
2219
|
+
var IMPORTS_THREE = /from\s*["']three(?:\/webgpu|\/tsl)?["']/u;
|
|
2220
|
+
var SOURCE_FILE = /\.[cm]?[jt]sx?$/u;
|
|
2221
|
+
var OVERRIDE = 'createEngineCatalogPlugin({ mode: "warn" }) in vite.config.ts reports instead of failing; engine: "threejs" in threenative.config.ts binds every name.';
|
|
2222
|
+
function namedList(ts, statement) {
|
|
2223
|
+
const declaration = ts.isImportDeclaration(statement) && statement.importClause?.isTypeOnly !== true ? { bindings: statement.importClause?.namedBindings, specifier: statement.moduleSpecifier } : ts.isExportDeclaration(statement) && !statement.isTypeOnly ? { bindings: statement.exportClause, specifier: statement.moduleSpecifier } : void 0;
|
|
2224
|
+
const bindings = declaration?.bindings;
|
|
2225
|
+
const specifier = declaration?.specifier;
|
|
2226
|
+
if (bindings === void 0 || specifier === void 0 || !ts.isStringLiteral(specifier))
|
|
2227
|
+
return void 0;
|
|
2228
|
+
if (!CHECKED_SOURCES.has(specifier.text)) return void 0;
|
|
2229
|
+
return ts.isNamedImports(bindings) || ts.isNamedExports(bindings) ? { elements: bindings.elements, source: specifier.text } : void 0;
|
|
2230
|
+
}
|
|
2231
|
+
async function refusedImports(code, file, refusals) {
|
|
2232
|
+
const ts = (await import('typescript')).default;
|
|
2233
|
+
const sourceFile = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true);
|
|
2234
|
+
const found = [];
|
|
2235
|
+
for (const statement of sourceFile.statements) {
|
|
2236
|
+
const list = namedList(ts, statement);
|
|
2237
|
+
for (const element of list?.elements ?? []) {
|
|
2238
|
+
const name = (element.propertyName ?? element.name).text;
|
|
2239
|
+
const refusal = refusals.get(name);
|
|
2240
|
+
if (element.isTypeOnly || refusal === void 0 || list === void 0) continue;
|
|
2241
|
+
const position = sourceFile.getLineAndCharacterOfPosition(element.getStart(sourceFile));
|
|
2242
|
+
found.push({
|
|
2243
|
+
code: refusal,
|
|
2244
|
+
column: position.character,
|
|
2245
|
+
line: position.line + 1,
|
|
2246
|
+
name,
|
|
2247
|
+
source: list.source
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
return found;
|
|
2252
|
+
}
|
|
2253
|
+
function createEngineCatalogPlugin(options = {}) {
|
|
2254
|
+
const mode = options.mode ?? "error";
|
|
2255
|
+
let root = process.cwd();
|
|
2256
|
+
let active = false;
|
|
2257
|
+
let bootWarned = false;
|
|
2258
|
+
let refusals;
|
|
2259
|
+
async function transform(code, id) {
|
|
2260
|
+
const file = id.split("?")[0] ?? id;
|
|
2261
|
+
const where = path8.relative(root, file);
|
|
2262
|
+
if (!active || id.startsWith("\0") || where.startsWith("..") || path8.isAbsolute(where))
|
|
2263
|
+
return null;
|
|
2264
|
+
if (where.split(path8.sep).includes("node_modules")) return null;
|
|
2265
|
+
if (!SOURCE_FILE.test(file) || !IMPORTS_THREE.test(code)) return null;
|
|
2266
|
+
refusals ??= upstreamRefusals(root).catch(
|
|
2267
|
+
(error) => new Error(
|
|
2268
|
+
`TN_ENGINE_CATALOG: the installed Wasm engine did not boot under this create-threenative, so the page cannot bind it either (${error instanceof Error ? error.message : String(error)}). Install one release of both: pnpm up --latest create-threenative @threenative/*`
|
|
2269
|
+
)
|
|
2270
|
+
);
|
|
2271
|
+
const known = await refusals;
|
|
2272
|
+
if (known instanceof Error) {
|
|
2273
|
+
if (mode === "error") return this.error({ message: known.message, id: file });
|
|
2274
|
+
if (!bootWarned) this.warn(known.message);
|
|
2275
|
+
bootWarned = true;
|
|
2276
|
+
return null;
|
|
2277
|
+
}
|
|
2278
|
+
const found = await refusedImports(code, file, known);
|
|
2279
|
+
const first = found[0];
|
|
2280
|
+
if (first === void 0) return null;
|
|
2281
|
+
const message = [
|
|
2282
|
+
...found.map(
|
|
2283
|
+
(refused) => `${refused.code}: ${refused.name} from "${refused.source}" is not available on the Wasm engine (${where}:${refused.line}:${refused.column + 1}).`
|
|
2284
|
+
),
|
|
2285
|
+
OVERRIDE
|
|
2286
|
+
].join("\n");
|
|
2287
|
+
if (mode === "warn") {
|
|
2288
|
+
this.warn(message);
|
|
2289
|
+
return null;
|
|
2290
|
+
}
|
|
2291
|
+
return this.error({
|
|
2292
|
+
message,
|
|
2293
|
+
id: file,
|
|
2294
|
+
loc: { file, line: first.line, column: first.column }
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
return {
|
|
2298
|
+
name: "threenative-engine-catalog",
|
|
2299
|
+
enforce: "pre",
|
|
2300
|
+
// A game booted in a worker (the kits' default page) bundles through `worker.plugins` only.
|
|
2301
|
+
config: () => ({
|
|
2302
|
+
worker: {
|
|
2303
|
+
plugins: () => [{ name: "threenative-engine-catalog-worker", enforce: "pre", transform }]
|
|
2304
|
+
}
|
|
2305
|
+
}),
|
|
2306
|
+
async configResolved(config) {
|
|
2307
|
+
root = config.root;
|
|
2308
|
+
const { engine } = await loadConfig(root);
|
|
2309
|
+
const off = engine !== "threenative" ? `engine ${engine}` : process.env.THREENATIVE_NATIVE_BUNDLE !== void 0 ? "native host bundle" : void 0;
|
|
2310
|
+
active = off === void 0;
|
|
2311
|
+
if (off !== void 0) console.info(`TN_ENGINE_CATALOG: off (${off})`);
|
|
2312
|
+
else if (mode === "warn")
|
|
2313
|
+
console.info(
|
|
2314
|
+
'TN_ENGINE_CATALOG: warn (mode "warn": a refused import is reported, and the page throws at its first use)'
|
|
2315
|
+
);
|
|
2316
|
+
},
|
|
2317
|
+
transform
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
var DECODER_LOADER_ID = /[/\\]examples[/\\]jsm[/\\]loaders[/\\](?:KTX2Loader|DRACOLoader)\.js$/u;
|
|
2321
|
+
var DECODER_LIB_ASSET_URL = /new URL\(\s*(['"])\.\.\/libs\/([^'"]+)\1\s*,\s*import\.meta\.url\s*\)(?:\.toString\s*\(\s*\)|\.href\s*)?/gu;
|
|
2322
|
+
function rewriteDecoderAssetUrls(code) {
|
|
2323
|
+
return code.replace(DECODER_LIB_ASSET_URL, '"../libs/$2"');
|
|
2324
|
+
}
|
|
2325
|
+
var MARKER_RELATIVE = path8.join("node_modules", ".vite", "threenative-engine-build.json");
|
|
2326
|
+
function hashTree(hash, directory) {
|
|
2327
|
+
const entries = readdirSync(directory, { withFileTypes: true }).sort(
|
|
2328
|
+
(left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0
|
|
2329
|
+
);
|
|
2330
|
+
for (const entry of entries) {
|
|
2331
|
+
const full = path8.join(directory, entry.name);
|
|
2332
|
+
if (entry.isDirectory()) {
|
|
2333
|
+
hashTree(hash, full);
|
|
2334
|
+
} else if (entry.isFile()) {
|
|
2335
|
+
hash.update(path8.relative(directory, full));
|
|
2336
|
+
hash.update(readFileSync(full));
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
function hashEngineDist(projectRoot) {
|
|
2341
|
+
const scopeDir = path8.join(projectRoot, "node_modules", "@threenative");
|
|
2342
|
+
let packages;
|
|
2343
|
+
try {
|
|
2344
|
+
packages = readdirSync(scopeDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => entry.name).sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
|
|
2345
|
+
} catch {
|
|
2346
|
+
return void 0;
|
|
2347
|
+
}
|
|
2348
|
+
const dists = [];
|
|
2349
|
+
for (const name of packages) {
|
|
2350
|
+
let packageDir = path8.join(scopeDir, name);
|
|
2351
|
+
try {
|
|
2352
|
+
packageDir = realpathSync(packageDir);
|
|
2353
|
+
} catch {
|
|
2354
|
+
continue;
|
|
2355
|
+
}
|
|
2356
|
+
const dist = path8.join(packageDir, "dist");
|
|
2357
|
+
if (existsSync(dist)) dists.push([name, dist]);
|
|
2358
|
+
}
|
|
2359
|
+
if (dists.length === 0) return void 0;
|
|
2360
|
+
const hash = createHash("sha256");
|
|
2361
|
+
for (const [name, dist] of dists) {
|
|
2362
|
+
hash.update(name);
|
|
2363
|
+
hashTree(hash, dist);
|
|
2364
|
+
}
|
|
2365
|
+
return hash.digest("hex");
|
|
2366
|
+
}
|
|
2367
|
+
function markerPath(projectRoot) {
|
|
2368
|
+
return path8.join(projectRoot, MARKER_RELATIVE);
|
|
2369
|
+
}
|
|
2370
|
+
function readMarker(file) {
|
|
2371
|
+
try {
|
|
2372
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
2373
|
+
} catch {
|
|
2374
|
+
return void 0;
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
function processIsAlive(pid) {
|
|
2378
|
+
if (pid === process.pid) return true;
|
|
2379
|
+
try {
|
|
2380
|
+
process.kill(pid, 0);
|
|
2381
|
+
return true;
|
|
2382
|
+
} catch (error) {
|
|
2383
|
+
return error.code === "EPERM";
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
function createEngineFreshnessPlugin() {
|
|
2387
|
+
let recordedHash;
|
|
2388
|
+
const rootOf = (config) => path8.resolve(config.root ?? process.cwd());
|
|
2389
|
+
return {
|
|
2390
|
+
name: "threenative-engine-freshness",
|
|
2391
|
+
config(config, env) {
|
|
2392
|
+
const resolve = { dedupe: ["three", "react", "react-dom"] };
|
|
2393
|
+
if (env.command !== "serve") return { resolve };
|
|
2394
|
+
const root = rootOf(config);
|
|
2395
|
+
recordedHash = hashEngineDist(root);
|
|
2396
|
+
const marker = recordedHash === void 0 ? void 0 : readMarker(markerPath(root));
|
|
2397
|
+
if (recordedHash === void 0 || marker === void 0 || marker.hash === recordedHash) {
|
|
2398
|
+
return { resolve };
|
|
2399
|
+
}
|
|
2400
|
+
if (processIsAlive(marker.pid)) {
|
|
2401
|
+
const where = marker.port === void 0 ? `pid ${marker.pid}` : `pid ${marker.pid} on port ${marker.port}`;
|
|
2402
|
+
const how = marker.port === void 0 ? "" : ` (lsof -ti tcp:${marker.port} | xargs -r kill)`;
|
|
2403
|
+
console.warn(
|
|
2404
|
+
`threenative: a dev server is still running at ${where}, serving engine build ${marker.hash.slice(0, 8)}; the installed build is ${recordedHash.slice(0, 8)}. Kill it before playing${how} \u2014 its tab renders yesterday's engine.`
|
|
2405
|
+
);
|
|
2406
|
+
}
|
|
2407
|
+
return { resolve, optimizeDeps: { force: true } };
|
|
2408
|
+
},
|
|
2409
|
+
transform(code, id) {
|
|
2410
|
+
if (!DECODER_LOADER_ID.test(id)) return null;
|
|
2411
|
+
const rewritten = rewriteDecoderAssetUrls(code);
|
|
2412
|
+
return rewritten === code ? null : { code: rewritten, map: null };
|
|
2413
|
+
},
|
|
2414
|
+
configureServer(server) {
|
|
2415
|
+
const root = rootOf(server.config);
|
|
2416
|
+
const file = markerPath(root);
|
|
2417
|
+
const writeBootMarker = (port) => {
|
|
2418
|
+
const hash = recordedHash ?? hashEngineDist(root);
|
|
2419
|
+
if (hash === void 0) return;
|
|
2420
|
+
mkdirSync(path8.dirname(file), { recursive: true });
|
|
2421
|
+
writeFileSync(
|
|
2422
|
+
file,
|
|
2423
|
+
JSON.stringify(
|
|
2424
|
+
port === void 0 ? { hash, pid: process.pid } : { hash, pid: process.pid, port }
|
|
2425
|
+
)
|
|
2426
|
+
);
|
|
2427
|
+
};
|
|
2428
|
+
const httpServer = server.httpServer;
|
|
2429
|
+
if (httpServer === void 0 || httpServer === null) {
|
|
2430
|
+
writeBootMarker(void 0);
|
|
2431
|
+
return;
|
|
2432
|
+
}
|
|
2433
|
+
httpServer.once("listening", () => {
|
|
2434
|
+
const address = httpServer.address();
|
|
2435
|
+
writeBootMarker(
|
|
2436
|
+
typeof address === "object" && address !== null && address.port !== void 0 ? address.port : void 0
|
|
2437
|
+
);
|
|
2438
|
+
});
|
|
2439
|
+
httpServer.once("close", () => {
|
|
2440
|
+
const marker = readMarker(file);
|
|
2441
|
+
if (marker?.pid === process.pid) rmSync(file, { force: true });
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2225
2446
|
var ISOLATION_HEADERS = {
|
|
2226
2447
|
"Cross-Origin-Embedder-Policy": "require-corp",
|
|
2227
2448
|
"Cross-Origin-Opener-Policy": "same-origin"
|
|
@@ -2234,15 +2455,105 @@ var isolationMiddleware = (req, res, next) => {
|
|
|
2234
2455
|
function renderIsolationHeaders() {
|
|
2235
2456
|
return `/*
|
|
2236
2457
|
${Object.entries(ISOLATION_HEADERS).map(([key, value]) => ` ${key}: ${value}
|
|
2237
|
-
`).join("")}
|
|
2458
|
+
`).join("")}/assets/*
|
|
2459
|
+
Cache-Control: public, max-age=31536000, immutable
|
|
2460
|
+
`;
|
|
2461
|
+
}
|
|
2462
|
+
var ISOLATION_WORKER_FILE = "tn-isolation-sw.js";
|
|
2463
|
+
function renderIsolationWorker() {
|
|
2464
|
+
return `self.addEventListener("install", () => self.skipWaiting());
|
|
2465
|
+
self.addEventListener("activate", (event) => event.waitUntil(self.clients.claim()));
|
|
2466
|
+
self.addEventListener("fetch", (event) => {
|
|
2467
|
+
const request = event.request;
|
|
2468
|
+
if (request.cache === "only-if-cached" && request.mode !== "same-origin") return;
|
|
2469
|
+
event.respondWith(
|
|
2470
|
+
fetch(request).then((response) => {
|
|
2471
|
+
if (response.status === 0) return response;
|
|
2472
|
+
const headers = new Headers(response.headers);
|
|
2473
|
+
${Object.entries({ ...ISOLATION_HEADERS, "Cross-Origin-Resource-Policy": "cross-origin" }).map(
|
|
2474
|
+
([key, value]) => ` headers.set("${key}", "${value}");
|
|
2475
|
+
`
|
|
2476
|
+
).join(
|
|
2477
|
+
""
|
|
2478
|
+
)} return new Response(response.body, { headers, status: response.status, statusText: response.statusText });
|
|
2479
|
+
}),
|
|
2480
|
+
);
|
|
2481
|
+
});
|
|
2482
|
+
`;
|
|
2483
|
+
}
|
|
2484
|
+
var ISOLATION_BOOT = `<script>(() => {
|
|
2485
|
+
const key = "tnIsolationReload";
|
|
2486
|
+
const store = (use) => { try { return use(sessionStorage); } catch { return null; } };
|
|
2487
|
+
if (globalThis.crossOriginIsolated) return void store((s) => s.removeItem(key));
|
|
2488
|
+
if (!isSecureContext || !("serviceWorker" in navigator) || /[?&]tnIsolation=0(?:&|$)/.test(location.search)) return;
|
|
2489
|
+
globalThis.__tnIsolation = navigator.serviceWorker.register("${ISOLATION_WORKER_FILE}")
|
|
2490
|
+
.then(() => navigator.serviceWorker.ready)
|
|
2491
|
+
.then(() => {
|
|
2492
|
+
if (store((s) => s.getItem(key)) !== null) return void store((s) => s.removeItem(key));
|
|
2493
|
+
if (store((s) => (s.setItem(key, "1"), true)) !== true) return;
|
|
2494
|
+
location.reload();
|
|
2495
|
+
return new Promise(() => {});
|
|
2496
|
+
}, () => {});
|
|
2497
|
+
})();</script>`;
|
|
2498
|
+
function withBuildId(html) {
|
|
2499
|
+
const entry = /<script\b[^>]*\btype="module"[^>]*\bsrc="([^"]*\/assets\/[^"]+\.js)"/iu.exec(
|
|
2500
|
+
html
|
|
2501
|
+
)?.[1];
|
|
2502
|
+
if (entry === void 0) return html;
|
|
2503
|
+
return html.replace(
|
|
2504
|
+
/<script/iu,
|
|
2505
|
+
`<script>globalThis.__TN_BUILD_ID__ = ${JSON.stringify(entry).replaceAll("<", "\\u003c")};</script>
|
|
2506
|
+
<script`
|
|
2507
|
+
);
|
|
2508
|
+
}
|
|
2509
|
+
function withEnginePreload(html, bundle, threaded) {
|
|
2510
|
+
if (bundle === void 0) return html;
|
|
2511
|
+
const files = Object.values(bundle);
|
|
2512
|
+
const entry = /<script\b[^>]*\btype="module"[^>]*\bsrc="([^"]*)"/iu.exec(html)?.[1];
|
|
2513
|
+
const entryFile = files.find((file) => entry?.endsWith(file.fileName) === true);
|
|
2514
|
+
if (entry === void 0 || entryFile === void 0) return html;
|
|
2515
|
+
const base = entry.slice(0, entry.length - entryFile.fileName.length);
|
|
2516
|
+
const href = (test) => {
|
|
2517
|
+
const found = files.find(test);
|
|
2518
|
+
return found === void 0 ? void 0 : base + found.fileName;
|
|
2519
|
+
};
|
|
2520
|
+
const threads = href((file) => /tn-native-engine-web-threads-[^/]*\.wasm$/u.test(file.fileName));
|
|
2521
|
+
const plain = href(
|
|
2522
|
+
(file) => /tn-native-engine-web-(?!threads-)[^/]*\.wasm$/u.test(file.fileName)
|
|
2523
|
+
);
|
|
2524
|
+
const wasm = threaded ? threads : plain;
|
|
2525
|
+
if (wasm === void 0) return html;
|
|
2526
|
+
const rapier = href(
|
|
2527
|
+
(file) => file.type === "chunk" && file.moduleIds?.some((id) => id.includes("/@dimforge/rapier3d")) === true
|
|
2528
|
+
);
|
|
2529
|
+
const quote = (value) => JSON.stringify(value ?? null).replaceAll("<", "\\u003c");
|
|
2530
|
+
const script = `<script>(() => {
|
|
2531
|
+
const link = (rel, href, as) => {
|
|
2532
|
+
const tag = Object.assign(document.createElement("link"), { rel, href, crossOrigin: "anonymous" });
|
|
2533
|
+
if (as !== undefined) tag.as = as;
|
|
2534
|
+
return document.head.appendChild(tag);
|
|
2535
|
+
};
|
|
2536
|
+
if (${threaded} && !globalThis.crossOriginIsolated) return;
|
|
2537
|
+
const href = ${quote(wasm)};
|
|
2538
|
+
const store = (use) => { try { return use(localStorage); } catch { return null; } };
|
|
2539
|
+
if (store((s) => s.getItem("tnEngineWasm")) === href) return;
|
|
2540
|
+
const wasm = link("preload", href, "fetch");
|
|
2541
|
+
const rapier = ${quote(rapier)};
|
|
2542
|
+
wasm.onload = wasm.onerror = () => {
|
|
2543
|
+
store((s) => s.setItem("tnEngineWasm", href));
|
|
2544
|
+
if (rapier !== null) link("modulepreload", rapier);
|
|
2545
|
+
};
|
|
2546
|
+
})();</script>`;
|
|
2547
|
+
return html.replace(/<script/iu, `${script}
|
|
2548
|
+
<script`);
|
|
2238
2549
|
}
|
|
2239
2550
|
function htmlAttribute(value) {
|
|
2240
2551
|
return value.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<");
|
|
2241
2552
|
}
|
|
2242
2553
|
function publicUrl(root, value) {
|
|
2243
2554
|
if (value === void 0) return void 0;
|
|
2244
|
-
const relative =
|
|
2245
|
-
const normalized = relative.replaceAll(
|
|
2555
|
+
const relative = path8.isAbsolute(value) ? path8.relative(root, value) : value;
|
|
2556
|
+
const normalized = relative.replaceAll(path8.sep, "/").replace(/^public\//u, "");
|
|
2246
2557
|
return `/${normalized.replace(/^\//u, "")}`;
|
|
2247
2558
|
}
|
|
2248
2559
|
function manifestIcon(root, source, purpose) {
|
|
@@ -2315,11 +2626,17 @@ function createWebBrandPlugin() {
|
|
|
2315
2626
|
let root = process.cwd();
|
|
2316
2627
|
let config;
|
|
2317
2628
|
let engine;
|
|
2629
|
+
let threaded = false;
|
|
2630
|
+
const load = async (id) => {
|
|
2631
|
+
const code = await engine?.load(id) ?? null;
|
|
2632
|
+
if (id === WEB_ENGINE_ID && code !== null) threaded = true;
|
|
2633
|
+
return code;
|
|
2634
|
+
};
|
|
2318
2635
|
return {
|
|
2319
2636
|
name: "threenative-web-brand",
|
|
2320
2637
|
enforce: "pre",
|
|
2321
2638
|
async config(vite) {
|
|
2322
|
-
const loaded = await loadConfig(
|
|
2639
|
+
const loaded = await loadConfig(path8.resolve(vite.root ?? process.cwd()));
|
|
2323
2640
|
if (loaded.engine === "threenative" && process.env.THREENATIVE_NATIVE_BUNDLE === void 0)
|
|
2324
2641
|
return {
|
|
2325
2642
|
optimizeDeps: { exclude: ["three", "three/webgpu", "three/tsl", "three-mesh-bvh"] },
|
|
@@ -2332,7 +2649,7 @@ function createWebBrandPlugin() {
|
|
|
2332
2649
|
name: "threenative-web-engine-worker",
|
|
2333
2650
|
enforce: "pre",
|
|
2334
2651
|
resolveId: (source, importer) => engine?.resolveId(source, importer) ?? null,
|
|
2335
|
-
load
|
|
2652
|
+
load
|
|
2336
2653
|
}
|
|
2337
2654
|
]
|
|
2338
2655
|
}
|
|
@@ -2342,18 +2659,23 @@ function createWebBrandPlugin() {
|
|
|
2342
2659
|
resolveId(source, importer) {
|
|
2343
2660
|
return engine?.resolveId(source, importer) ?? null;
|
|
2344
2661
|
},
|
|
2345
|
-
|
|
2346
|
-
return engine?.load(id) ?? null;
|
|
2347
|
-
},
|
|
2662
|
+
load,
|
|
2348
2663
|
async configResolved(resolved) {
|
|
2349
2664
|
root = resolved.root;
|
|
2350
2665
|
config = await loadConfig(root);
|
|
2351
2666
|
if (config.engine === "threenative" && process.env.THREENATIVE_NATIVE_BUNDLE === void 0)
|
|
2352
|
-
engine = createWebEnginePlugin({
|
|
2667
|
+
engine = createWebEnginePlugin({
|
|
2668
|
+
root,
|
|
2669
|
+
engine: config.engine,
|
|
2670
|
+
strict: resolved.command !== "build"
|
|
2671
|
+
});
|
|
2353
2672
|
},
|
|
2354
|
-
transformIndexHtml(html) {
|
|
2673
|
+
transformIndexHtml(html, context) {
|
|
2355
2674
|
if (config === void 0) throw new Error("TN_WEB_BRAND_CONFIG_MISSING");
|
|
2356
|
-
|
|
2675
|
+
const output = withBuildId(updateLaunchMarkup(root, config, html));
|
|
2676
|
+
const isolated = threaded ? output.replace(/<script/iu, `${ISOLATION_BOOT}
|
|
2677
|
+
<script`) : output;
|
|
2678
|
+
return withEnginePreload(isolated, context?.bundle, threaded);
|
|
2357
2679
|
},
|
|
2358
2680
|
// Every page links the manifest, and only a build emits it: in dev Vite would answer the link
|
|
2359
2681
|
// with index.html, which the browser reports as a manifest syntax error on each load.
|
|
@@ -2378,6 +2700,12 @@ function createWebBrandPlugin() {
|
|
|
2378
2700
|
});
|
|
2379
2701
|
if (config.engine === "threenative")
|
|
2380
2702
|
this.emitFile({ fileName: "_headers", source: renderIsolationHeaders(), type: "asset" });
|
|
2703
|
+
if (threaded)
|
|
2704
|
+
this.emitFile({
|
|
2705
|
+
fileName: ISOLATION_WORKER_FILE,
|
|
2706
|
+
source: renderIsolationWorker(),
|
|
2707
|
+
type: "asset"
|
|
2708
|
+
});
|
|
2381
2709
|
}
|
|
2382
2710
|
};
|
|
2383
2711
|
}
|
|
@@ -2404,22 +2732,22 @@ var SHARED_AGENT_MARKER_LINE = /^<!--\s*(?:shared:\s*[^>]+|\/shared)\s*-->\r?\n?
|
|
|
2404
2732
|
var DEFAULT_TEMPLATE = "starter";
|
|
2405
2733
|
var SUPPORTED_PACKAGE_MANAGER = "pnpm@10.25.0";
|
|
2406
2734
|
function templateRoot() {
|
|
2407
|
-
return
|
|
2735
|
+
return path8.resolve(path8.dirname(fileURLToPath(import.meta.url)), "../templates");
|
|
2408
2736
|
}
|
|
2409
|
-
var LOADING_SOURCE_RELATIVE_PATH =
|
|
2737
|
+
var LOADING_SOURCE_RELATIVE_PATH = path8.join("src", "render", "loading.ts");
|
|
2410
2738
|
var LOADING_APPEARANCE_MARKER = "BEGIN THREENATIVE LOADING APPEARANCE";
|
|
2411
2739
|
var TEMPLATE_ICON_NAME = "icon.png";
|
|
2412
2740
|
var LOADING_APPEARANCE_BLOCK_PATTERN = /\/\* BEGIN THREENATIVE LOADING APPEARANCE \*\/[\s\S]*?\/\* END THREENATIVE LOADING APPEARANCE \*\//gu;
|
|
2413
2741
|
function discoverStampedTemplates(root = templateRoot()) {
|
|
2414
2742
|
return readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name).sort((left, right) => left.localeCompare(right)).filter((template) => {
|
|
2415
|
-
const file =
|
|
2743
|
+
const file = path8.join(root, template, LOADING_SOURCE_RELATIVE_PATH);
|
|
2416
2744
|
return existsSync(file) && readFileSync(file, "utf8").includes(LOADING_APPEARANCE_MARKER);
|
|
2417
2745
|
});
|
|
2418
2746
|
}
|
|
2419
2747
|
function canonicalLoadingPath(root = templateRoot()) {
|
|
2420
|
-
const local =
|
|
2748
|
+
const local = path8.resolve(root, "..", "template-assets", "loading.ts");
|
|
2421
2749
|
if (existsSync(local)) return local;
|
|
2422
|
-
return
|
|
2750
|
+
return path8.resolve(templateRoot(), "..", "template-assets", "loading.ts");
|
|
2423
2751
|
}
|
|
2424
2752
|
function loadingAppearanceBlock(source, file) {
|
|
2425
2753
|
const matches = source.match(LOADING_APPEARANCE_BLOCK_PATTERN) ?? [];
|
|
@@ -2436,25 +2764,36 @@ function stampLoadingSource(canonical, template) {
|
|
|
2436
2764
|
return canonical.replace(canonicalBlock, templateBlock);
|
|
2437
2765
|
}
|
|
2438
2766
|
var SHARED_RENDER_SOURCES = [
|
|
2767
|
+
// The backlight shader: mechanism every kit repeats, but its constants decide how a surface
|
|
2768
|
+
// looks, so it lives in `src/render/` (rule 3) and is stamped from one source rather than moved
|
|
2769
|
+
// into the engine.
|
|
2770
|
+
"src/render/backlightControls.ts",
|
|
2771
|
+
"src/render/backlightMaterial.ts",
|
|
2772
|
+
"src/render/atmosphere.ts",
|
|
2773
|
+
"src/render/gpuSky.ts",
|
|
2774
|
+
"src/render/kitExposure.ts",
|
|
2775
|
+
"src/render/temporalDetailStage.ts"
|
|
2776
|
+
];
|
|
2777
|
+
var ADDED_RENDER_SOURCES = [
|
|
2439
2778
|
"src/render/kitExposure.ts",
|
|
2440
2779
|
"src/render/temporalDetailStage.ts"
|
|
2441
2780
|
];
|
|
2442
2781
|
function canonicalRenderSourcePath(relativePath, root = templateRoot()) {
|
|
2443
|
-
const name =
|
|
2444
|
-
const local =
|
|
2782
|
+
const name = path8.basename(relativePath);
|
|
2783
|
+
const local = path8.resolve(root, "..", "template-assets", name);
|
|
2445
2784
|
if (existsSync(local)) return local;
|
|
2446
|
-
const starter =
|
|
2785
|
+
const starter = path8.resolve(root, "starter", relativePath);
|
|
2447
2786
|
if (existsSync(starter)) return starter;
|
|
2448
|
-
const shared =
|
|
2787
|
+
const shared = path8.resolve(templateRoot(), "..", "template-assets", name);
|
|
2449
2788
|
if (existsSync(shared)) return shared;
|
|
2450
|
-
return
|
|
2789
|
+
return path8.resolve(templateRoot(), "starter", relativePath);
|
|
2451
2790
|
}
|
|
2452
2791
|
async function restampSharedRenderCopies(root = templateRoot()) {
|
|
2453
2792
|
const stamped = [];
|
|
2454
2793
|
for (const relativePath of SHARED_RENDER_SOURCES) {
|
|
2455
2794
|
const canonical = await readFile(canonicalRenderSourcePath(relativePath, root), "utf8");
|
|
2456
2795
|
for (const template of readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name).sort((left, right) => left.localeCompare(right))) {
|
|
2457
|
-
const file =
|
|
2796
|
+
const file = path8.join(root, template, relativePath);
|
|
2458
2797
|
if (!existsSync(file)) continue;
|
|
2459
2798
|
await writeFile(file, canonical);
|
|
2460
2799
|
stamped.push(file);
|
|
@@ -2466,7 +2805,7 @@ async function restampTemplateLoadingCopies(root = templateRoot()) {
|
|
|
2466
2805
|
const canonical = await readFile(canonicalLoadingPath(root), "utf8");
|
|
2467
2806
|
const stamped = [];
|
|
2468
2807
|
for (const template of discoverStampedTemplates(root)) {
|
|
2469
|
-
const file =
|
|
2808
|
+
const file = path8.join(root, template, LOADING_SOURCE_RELATIVE_PATH);
|
|
2470
2809
|
const source = await readFile(file, "utf8");
|
|
2471
2810
|
await writeFile(file, stampLoadingSource(canonical, source));
|
|
2472
2811
|
stamped.push(file);
|
|
@@ -2474,19 +2813,19 @@ async function restampTemplateLoadingCopies(root = templateRoot()) {
|
|
|
2474
2813
|
return stamped;
|
|
2475
2814
|
}
|
|
2476
2815
|
async function stampTemplateLoading(target, template, root) {
|
|
2477
|
-
const sourcePath =
|
|
2816
|
+
const sourcePath = path8.join(template, LOADING_SOURCE_RELATIVE_PATH);
|
|
2478
2817
|
if (!existsSync(sourcePath)) return;
|
|
2479
2818
|
const source = await readFile(sourcePath, "utf8");
|
|
2480
2819
|
if (!source.includes("BEGIN THREENATIVE LOADING APPEARANCE")) return;
|
|
2481
2820
|
const canonical = await readFile(canonicalLoadingPath(root), "utf8");
|
|
2482
2821
|
await writeFile(
|
|
2483
|
-
|
|
2822
|
+
path8.join(target, LOADING_SOURCE_RELATIVE_PATH),
|
|
2484
2823
|
stampLoadingSource(canonical, source)
|
|
2485
2824
|
);
|
|
2486
2825
|
}
|
|
2487
2826
|
async function copyTemplateIcon(target, templateRootDirectory) {
|
|
2488
|
-
const source =
|
|
2489
|
-
|
|
2827
|
+
const source = path8.join(
|
|
2828
|
+
path8.dirname(templateRootDirectory),
|
|
2490
2829
|
"template-assets",
|
|
2491
2830
|
TEMPLATE_ICON_NAME
|
|
2492
2831
|
);
|
|
@@ -2495,18 +2834,18 @@ async function copyTemplateIcon(target, templateRootDirectory) {
|
|
|
2495
2834
|
`TN_TEMPLATE_ICON_MISSING: '${source}' is not in the package; every generated project needs the native icon asset.`
|
|
2496
2835
|
);
|
|
2497
2836
|
}
|
|
2498
|
-
const destination =
|
|
2499
|
-
await mkdir(
|
|
2837
|
+
const destination = path8.join(target, "public", TEMPLATE_ICON_NAME);
|
|
2838
|
+
await mkdir(path8.dirname(destination), { recursive: true });
|
|
2500
2839
|
await cp(source, destination, { errorOnExist: true, force: false });
|
|
2501
2840
|
}
|
|
2502
2841
|
async function copySharedAssets(target, templateRootDirectory) {
|
|
2503
|
-
const shared =
|
|
2842
|
+
const shared = path8.join(path8.dirname(templateRootDirectory), "template-assets", "assets");
|
|
2504
2843
|
if (!existsSync(shared)) return;
|
|
2505
|
-
const source =
|
|
2844
|
+
const source = path8.join(target, "src");
|
|
2506
2845
|
const texts = [];
|
|
2507
2846
|
const walk = async (directory) => {
|
|
2508
2847
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
2509
|
-
const file =
|
|
2848
|
+
const file = path8.join(directory, entry.name);
|
|
2510
2849
|
if (entry.isDirectory()) await walk(file);
|
|
2511
2850
|
else if (/\.(?:ts|tsx)$/u.test(entry.name)) texts.push(await readFile(file, "utf8"));
|
|
2512
2851
|
}
|
|
@@ -2524,13 +2863,13 @@ async function copySharedAssets(target, templateRootDirectory) {
|
|
|
2524
2863
|
};
|
|
2525
2864
|
for (const name of names) {
|
|
2526
2865
|
if (!copied(name)) continue;
|
|
2527
|
-
const destination =
|
|
2528
|
-
await mkdir(
|
|
2529
|
-
await cp(
|
|
2866
|
+
const destination = path8.join(target, "assets", name);
|
|
2867
|
+
await mkdir(path8.dirname(destination), { recursive: true });
|
|
2868
|
+
await cp(path8.join(shared, name), destination, { errorOnExist: true, force: false });
|
|
2530
2869
|
}
|
|
2531
2870
|
}
|
|
2532
2871
|
async function copyQualityConfig(target, templateRootDirectory) {
|
|
2533
|
-
const shared =
|
|
2872
|
+
const shared = path8.join(path8.dirname(templateRootDirectory), "template-assets", "quality");
|
|
2534
2873
|
if (!existsSync(shared)) throw new Error(`TN_QUALITY_CONFIG_MISSING: ${shared}`);
|
|
2535
2874
|
await cp(shared, target, { errorOnExist: true, recursive: true });
|
|
2536
2875
|
}
|
|
@@ -2543,7 +2882,7 @@ function nonEmptyString2(value, field, file) {
|
|
|
2543
2882
|
return value;
|
|
2544
2883
|
}
|
|
2545
2884
|
function loadManifest(directory) {
|
|
2546
|
-
const file =
|
|
2885
|
+
const file = path8.join(directory, "kit.json");
|
|
2547
2886
|
let raw;
|
|
2548
2887
|
try {
|
|
2549
2888
|
raw = readFileSync(file, "utf8");
|
|
@@ -2561,7 +2900,7 @@ function loadManifest(directory) {
|
|
|
2561
2900
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
2562
2901
|
return invalidManifest(file, "the root must be an object");
|
|
2563
2902
|
const record = value;
|
|
2564
|
-
const directoryName =
|
|
2903
|
+
const directoryName = path8.basename(directory);
|
|
2565
2904
|
const name = nonEmptyString2(record.name, "name", file);
|
|
2566
2905
|
if (!TEMPLATE_NAME.test(name))
|
|
2567
2906
|
return invalidManifest(file, "name must match /^[a-z][a-z0-9-]*$/");
|
|
@@ -2581,7 +2920,7 @@ function loadManifest(directory) {
|
|
|
2581
2920
|
};
|
|
2582
2921
|
}
|
|
2583
2922
|
function discoverKitManifests(root = templateRoot()) {
|
|
2584
|
-
return readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => loadManifest(
|
|
2923
|
+
return readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => loadManifest(path8.join(root, entry.name))).sort((left, right) => left.name.localeCompare(right.name));
|
|
2585
2924
|
}
|
|
2586
2925
|
function discoverTemplateNames(root = templateRoot()) {
|
|
2587
2926
|
return discoverKitManifests(root).map(({ name }) => name);
|
|
@@ -2627,7 +2966,7 @@ function scaffoldNextSteps(target, installed, servers = []) {
|
|
|
2627
2966
|
function projectMcpServers(target) {
|
|
2628
2967
|
try {
|
|
2629
2968
|
return Object.keys(
|
|
2630
|
-
JSON.parse(readFileSync(
|
|
2969
|
+
JSON.parse(readFileSync(path8.join(target, ".mcp.json"), "utf8")).mcpServers ?? {}
|
|
2631
2970
|
);
|
|
2632
2971
|
} catch {
|
|
2633
2972
|
return [];
|
|
@@ -2706,12 +3045,21 @@ function cliHelp() {
|
|
|
2706
3045
|
`;
|
|
2707
3046
|
}
|
|
2708
3047
|
function packageName(target) {
|
|
2709
|
-
const name =
|
|
3048
|
+
const name = path8.basename(target).toLowerCase().replace(/[^a-z0-9-_]+/g, "-");
|
|
2710
3049
|
if (name.length === 0 || name === "-" || name === "_") {
|
|
2711
3050
|
throw new Error(`Cannot derive a package name from '${target}'.`);
|
|
2712
3051
|
}
|
|
2713
3052
|
return name;
|
|
2714
3053
|
}
|
|
3054
|
+
function templateReplacements(target) {
|
|
3055
|
+
const projectName = packageName(target);
|
|
3056
|
+
const compactProjectId = projectName.toLowerCase().replace(/[^a-z0-9]+/gu, "") || "game";
|
|
3057
|
+
const projectId = /^[a-z]/u.test(compactProjectId) ? compactProjectId : `game${compactProjectId}`;
|
|
3058
|
+
return Object.fromEntries([
|
|
3059
|
+
["__PROJECT_NAME__", projectName],
|
|
3060
|
+
["__PROJECT_ID__", projectId]
|
|
3061
|
+
]);
|
|
3062
|
+
}
|
|
2715
3063
|
async function isEmpty(directory) {
|
|
2716
3064
|
const entries = await readdir(directory).catch(
|
|
2717
3065
|
(error) => error?.code === "ENOENT" ? [] : void 0
|
|
@@ -2729,12 +3077,12 @@ function substituteTemplateVariables(content, replacements) {
|
|
|
2729
3077
|
async function renderTemplate(directory, replacements) {
|
|
2730
3078
|
const files = await readdir(directory, { withFileTypes: true });
|
|
2731
3079
|
for (const entry of files) {
|
|
2732
|
-
const source =
|
|
3080
|
+
const source = path8.join(directory, entry.name);
|
|
2733
3081
|
if (entry.isDirectory()) {
|
|
2734
3082
|
await renderTemplate(source, replacements);
|
|
2735
3083
|
continue;
|
|
2736
3084
|
}
|
|
2737
|
-
if (!TEXT_FILE_EXTENSIONS.has(
|
|
3085
|
+
if (!TEXT_FILE_EXTENSIONS.has(path8.extname(entry.name))) continue;
|
|
2738
3086
|
const content = await readFile(source, "utf8");
|
|
2739
3087
|
let rendered = substituteTemplateVariables(content, replacements);
|
|
2740
3088
|
if (entry.name === "AGENTS.md" || entry.name === "CLAUDE.md") {
|
|
@@ -2766,27 +3114,28 @@ var REFERENCE_TOKEN_PATTERN = new RegExp(
|
|
|
2766
3114
|
"gu"
|
|
2767
3115
|
);
|
|
2768
3116
|
async function linkClaudeSkills(target) {
|
|
2769
|
-
const stored =
|
|
3117
|
+
const stored = path8.join(target, ".agents", "skills");
|
|
2770
3118
|
if (!existsSync(stored)) return;
|
|
2771
|
-
const hostSkills =
|
|
2772
|
-
const subagents =
|
|
3119
|
+
const hostSkills = path8.join(target, ".claude", "skills");
|
|
3120
|
+
const subagents = path8.join(target, ".claude", "agents");
|
|
2773
3121
|
await mkdir(hostSkills, { recursive: true });
|
|
2774
3122
|
for (const entry of await readdir(stored, { withFileTypes: true })) {
|
|
2775
3123
|
if (!entry.isDirectory()) continue;
|
|
2776
|
-
if (existsSync(
|
|
2777
|
-
const link =
|
|
2778
|
-
|
|
3124
|
+
if (existsSync(path8.join(subagents, `${entry.name}.md`))) continue;
|
|
3125
|
+
const link = path8.join(hostSkills, entry.name);
|
|
3126
|
+
if (await lstat(link).catch(() => void 0)) continue;
|
|
3127
|
+
const relative = path8.relative(hostSkills, path8.join(stored, entry.name));
|
|
2779
3128
|
try {
|
|
2780
3129
|
await symlink(relative, link, "dir");
|
|
2781
3130
|
} catch (error) {
|
|
2782
3131
|
const code = error.code;
|
|
2783
3132
|
if (code !== "EPERM" && code !== "EACCES") throw error;
|
|
2784
|
-
await cp(
|
|
3133
|
+
await cp(path8.join(stored, entry.name), link, { recursive: true });
|
|
2785
3134
|
}
|
|
2786
3135
|
}
|
|
2787
3136
|
}
|
|
2788
3137
|
async function copyAgentFiles(target, templateRootDirectory) {
|
|
2789
|
-
const source =
|
|
3138
|
+
const source = path8.join(path8.dirname(templateRootDirectory), AGENT_FILES_DIRECTORY);
|
|
2790
3139
|
if (!existsSync(source)) {
|
|
2791
3140
|
throw new Error(
|
|
2792
3141
|
`TN_AGENT_FILES_MISSING: '${source}' is not in the package; every generated project needs the canonical agent roles.`
|
|
@@ -2796,7 +3145,7 @@ async function copyAgentFiles(target, templateRootDirectory) {
|
|
|
2796
3145
|
await linkClaudeSkills(target);
|
|
2797
3146
|
}
|
|
2798
3147
|
async function installAuthoringGitignore(target) {
|
|
2799
|
-
const file =
|
|
3148
|
+
const file = path8.join(target, ".gitignore");
|
|
2800
3149
|
const existing = existsSync(file) ? await readFile(file, "utf8") : "";
|
|
2801
3150
|
const present = new Set(existing.split(/\r?\n/u));
|
|
2802
3151
|
const missing = AUTHORING_GITIGNORE_RULES.filter((entry) => !present.has(entry));
|
|
@@ -2810,8 +3159,8 @@ async function installAuthoringGitignore(target) {
|
|
|
2810
3159
|
);
|
|
2811
3160
|
}
|
|
2812
3161
|
async function assertReferenceBundle(target, templateRootDirectory) {
|
|
2813
|
-
const bundleDirectory =
|
|
2814
|
-
|
|
3162
|
+
const bundleDirectory = path8.join(
|
|
3163
|
+
path8.dirname(templateRootDirectory),
|
|
2815
3164
|
"agent-docs",
|
|
2816
3165
|
"references"
|
|
2817
3166
|
);
|
|
@@ -2823,7 +3172,7 @@ async function assertReferenceBundle(target, templateRootDirectory) {
|
|
|
2823
3172
|
".agents/skills/threenative-assets/SKILL.md",
|
|
2824
3173
|
".claude/skills/threenative-assets/SKILL.md"
|
|
2825
3174
|
]) {
|
|
2826
|
-
const filePath =
|
|
3175
|
+
const filePath = path8.join(target, file);
|
|
2827
3176
|
if (existsSync(filePath)) await assertReferenceTargets(file, filePath, bundleDirectory);
|
|
2828
3177
|
}
|
|
2829
3178
|
}
|
|
@@ -2837,7 +3186,7 @@ async function assertReferenceTargets(from, filePath, bundleDirectory) {
|
|
|
2837
3186
|
`RED observed: referenced recipe missing: '${from}' names '${referenced}', which is not a shipped reference page.`
|
|
2838
3187
|
);
|
|
2839
3188
|
}
|
|
2840
|
-
if (!existsSync(
|
|
3189
|
+
if (!existsSync(path8.join(bundleDirectory, referenced))) {
|
|
2841
3190
|
throw new Error(
|
|
2842
3191
|
`RED observed: referenced recipe missing: '${from}' links '${REFERENCE_BUNDLE_PREFIX}${referenced}', which the package does not ship.`
|
|
2843
3192
|
);
|
|
@@ -2845,7 +3194,7 @@ async function assertReferenceTargets(from, filePath, bundleDirectory) {
|
|
|
2845
3194
|
}
|
|
2846
3195
|
}
|
|
2847
3196
|
async function applyPackageSources(target, packageSources) {
|
|
2848
|
-
const packagePath =
|
|
3197
|
+
const packagePath = path8.join(target, "package.json");
|
|
2849
3198
|
const packageJson = JSON.parse(await readFile(packagePath, "utf8"));
|
|
2850
3199
|
packageJson.packageManager = SUPPORTED_PACKAGE_MANAGER;
|
|
2851
3200
|
if (packageSources === void 0) {
|
|
@@ -2855,7 +3204,7 @@ async function applyPackageSources(target, packageSources) {
|
|
|
2855
3204
|
}
|
|
2856
3205
|
const localSource = (source) => {
|
|
2857
3206
|
const filePath = source.startsWith("file:") ? source.slice("file:".length) : source;
|
|
2858
|
-
return `file:${
|
|
3207
|
+
return `file:${path8.resolve(filePath)}`;
|
|
2859
3208
|
};
|
|
2860
3209
|
for (const [name, source] of Object.entries(packageSources)) {
|
|
2861
3210
|
if (source === void 0) continue;
|
|
@@ -2878,25 +3227,34 @@ async function applyPackageSources(target, packageSources) {
|
|
|
2878
3227
|
`);
|
|
2879
3228
|
}
|
|
2880
3229
|
var FRAMEWORK_PATCH_DIRECTORY = "patches";
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
3230
|
+
async function frameworkPatches(packageRoot) {
|
|
3231
|
+
const manifest = JSON.parse(
|
|
3232
|
+
await readFile(
|
|
3233
|
+
path8.join(packageRoot, "template-assets", FRAMEWORK_PATCH_DIRECTORY, "manifest.json"),
|
|
3234
|
+
"utf8"
|
|
3235
|
+
)
|
|
3236
|
+
);
|
|
3237
|
+
if (manifest.version !== 1 || !Array.isArray(manifest.patches)) {
|
|
3238
|
+
throw new Error("TN_FRAMEWORK_PATCH_MANIFEST: expected version 1 with a patches array.");
|
|
3239
|
+
}
|
|
3240
|
+
return manifest.patches;
|
|
3241
|
+
}
|
|
2886
3242
|
async function copyFrameworkPatches(target, templateRootDirectory) {
|
|
2887
|
-
const manifest = JSON.parse(await readFile(
|
|
2888
|
-
const packageRoot =
|
|
3243
|
+
const manifest = JSON.parse(await readFile(path8.join(target, "package.json"), "utf8"));
|
|
3244
|
+
const packageRoot = path8.dirname(templateRoot());
|
|
3245
|
+
const supported = await frameworkPatches(packageRoot);
|
|
3246
|
+
const repositoryRoot = path8.resolve(packageRoot, "..", "..");
|
|
2889
3247
|
for (const relative of Object.values(manifest.pnpm?.patchedDependencies ?? {})) {
|
|
2890
|
-
const name =
|
|
2891
|
-
const
|
|
2892
|
-
if (
|
|
3248
|
+
const name = path8.basename(relative);
|
|
3249
|
+
const patch = supported.find((candidate) => candidate.name === name);
|
|
3250
|
+
if (patch === void 0 || relative !== `${FRAMEWORK_PATCH_DIRECTORY}/${name}`) {
|
|
2893
3251
|
throw new Error(`TN_FRAMEWORK_PATCH_MISSING: unsupported template patch '${relative}'.`);
|
|
2894
3252
|
}
|
|
2895
|
-
const candidates = [.../* @__PURE__ */ new Set([
|
|
2896
|
-
(root) =>
|
|
3253
|
+
const candidates = [.../* @__PURE__ */ new Set([path8.dirname(templateRootDirectory), packageRoot])].map(
|
|
3254
|
+
(root) => path8.join(root, "template-assets", FRAMEWORK_PATCH_DIRECTORY, name)
|
|
2897
3255
|
);
|
|
2898
|
-
const canonical =
|
|
2899
|
-
if (existsSync(
|
|
3256
|
+
const canonical = path8.resolve(repositoryRoot, patch.source);
|
|
3257
|
+
if (existsSync(path8.join(packageRoot, "src", "index.ts"))) candidates.unshift(canonical);
|
|
2900
3258
|
else candidates.push(canonical);
|
|
2901
3259
|
const source = candidates.find((candidate) => existsSync(candidate));
|
|
2902
3260
|
if (source === void 0) {
|
|
@@ -2904,8 +3262,8 @@ async function copyFrameworkPatches(target, templateRootDirectory) {
|
|
|
2904
3262
|
`TN_FRAMEWORK_PATCH_MISSING: dependency patch '${name}' is absent from the CLI package.`
|
|
2905
3263
|
);
|
|
2906
3264
|
}
|
|
2907
|
-
const destination =
|
|
2908
|
-
await mkdir(
|
|
3265
|
+
const destination = path8.join(target, relative);
|
|
3266
|
+
await mkdir(path8.dirname(destination), { recursive: true });
|
|
2909
3267
|
await cp(source, destination);
|
|
2910
3268
|
}
|
|
2911
3269
|
}
|
|
@@ -2924,8 +3282,18 @@ function writeHostMcpConfigs(target) {
|
|
|
2924
3282
|
}
|
|
2925
3283
|
}
|
|
2926
3284
|
}
|
|
3285
|
+
function assertMcpShims(target) {
|
|
3286
|
+
if (!existsSync(path8.join(target, "node_modules"))) return;
|
|
3287
|
+
for (const [name, entry] of Object.entries(REQUIRED_MCP_SERVERS)) {
|
|
3288
|
+
if (existsSync(path8.resolve(target, entry))) continue;
|
|
3289
|
+
throw new Error(
|
|
3290
|
+
`MCP server '${name}' launches '${entry}', which this project does not have. Run 'pnpm install', or install one release of both: ${ENGINE_PAIR_UPGRADE}`
|
|
3291
|
+
);
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
2927
3294
|
async function assertMcpConfig(target) {
|
|
2928
|
-
|
|
3295
|
+
assertMcpShims(target);
|
|
3296
|
+
const configPath = path8.join(target, ".mcp.json");
|
|
2929
3297
|
const raw = await readFile(configPath, "utf8").catch(() => {
|
|
2930
3298
|
throw new Error(`Scaffold produced no .mcp.json at '${configPath}'.`);
|
|
2931
3299
|
});
|
|
@@ -2938,7 +3306,7 @@ async function assertMcpConfig(target) {
|
|
|
2938
3306
|
throw new Error(`'${configPath}' is missing required MCP server '${name}'.`);
|
|
2939
3307
|
}
|
|
2940
3308
|
}
|
|
2941
|
-
const manifest = JSON.parse(await readFile(
|
|
3309
|
+
const manifest = JSON.parse(await readFile(path8.join(target, "package.json"), "utf8"));
|
|
2942
3310
|
const declared = /* @__PURE__ */ new Set([
|
|
2943
3311
|
...Object.keys(manifest.dependencies ?? {}),
|
|
2944
3312
|
...Object.keys(manifest.devDependencies ?? {})
|
|
@@ -2972,7 +3340,7 @@ async function assertMcpConfig(target) {
|
|
|
2972
3340
|
);
|
|
2973
3341
|
}
|
|
2974
3342
|
}
|
|
2975
|
-
const codexPath =
|
|
3343
|
+
const codexPath = path8.join(target, ".codex", "config.toml");
|
|
2976
3344
|
const codex = await readFile(codexPath, "utf8").catch(() => {
|
|
2977
3345
|
throw new Error(`Scaffold produced no Codex MCP config at '${codexPath}'.`);
|
|
2978
3346
|
});
|
|
@@ -2982,6 +3350,149 @@ async function assertMcpConfig(target) {
|
|
|
2982
3350
|
}
|
|
2983
3351
|
}
|
|
2984
3352
|
}
|
|
3353
|
+
var AUTHORING_STAMP = path8.join(".threenative", "agent-files.json");
|
|
3354
|
+
var KIT_TITLE = /\bthe ([a-z][a-z0-9-]*) kit\b/u;
|
|
3355
|
+
var sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
3356
|
+
async function fileHash(file) {
|
|
3357
|
+
return readFile(file).then(sha256, () => void 0);
|
|
3358
|
+
}
|
|
3359
|
+
async function hashFiles(directory, relative = "") {
|
|
3360
|
+
const hashes = {};
|
|
3361
|
+
for (const entry of await readdir(path8.join(directory, relative), { withFileTypes: true })) {
|
|
3362
|
+
const next = path8.posix.join(relative, entry.name);
|
|
3363
|
+
if (entry.isDirectory()) Object.assign(hashes, await hashFiles(directory, next));
|
|
3364
|
+
else if (entry.isFile()) hashes[next] = sha256(await readFile(path8.join(directory, next)));
|
|
3365
|
+
}
|
|
3366
|
+
return hashes;
|
|
3367
|
+
}
|
|
3368
|
+
async function renderedAuthoringLayer(target, kit, root, directory) {
|
|
3369
|
+
const into = directory ?? await mkdtemp(path8.join(tmpdir(), "threenative-authoring-"));
|
|
3370
|
+
try {
|
|
3371
|
+
for (const file of ["AGENTS.md", "CLAUDE.md"])
|
|
3372
|
+
await cp(path8.join(root, kit, file), path8.join(into, file));
|
|
3373
|
+
await copyAgentFiles(into, root);
|
|
3374
|
+
await renderTemplate(into, templateReplacements(target));
|
|
3375
|
+
return await hashFiles(into);
|
|
3376
|
+
} finally {
|
|
3377
|
+
if (directory === void 0) await rm(into, { force: true, recursive: true });
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
function packageVersion(root) {
|
|
3381
|
+
const manifest = JSON.parse(
|
|
3382
|
+
readFileSync(path8.join(path8.dirname(root), "package.json"), "utf8")
|
|
3383
|
+
);
|
|
3384
|
+
if (typeof manifest.version !== "string")
|
|
3385
|
+
throw new Error("TN_AUTHORING_LAYER_VERSION: create-threenative has no version.");
|
|
3386
|
+
return manifest.version;
|
|
3387
|
+
}
|
|
3388
|
+
async function writeAuthoringStamp(target, kit, files, root) {
|
|
3389
|
+
const stamp = { createThreenative: packageVersion(root), kit, files };
|
|
3390
|
+
await mkdir(path8.join(target, path8.dirname(AUTHORING_STAMP)), { recursive: true });
|
|
3391
|
+
await writeFile(path8.join(target, AUTHORING_STAMP), `${JSON.stringify(stamp, null, 2)}
|
|
3392
|
+
`);
|
|
3393
|
+
}
|
|
3394
|
+
async function readJsonRecord(file) {
|
|
3395
|
+
const text = await readFile(file, "utf8").catch(() => void 0);
|
|
3396
|
+
if (text === void 0) return void 0;
|
|
3397
|
+
const value = JSON.parse(text);
|
|
3398
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
3399
|
+
throw new Error(`TN_AUTHORING_LAYER_STAMP: '${file}' is not a JSON object.`);
|
|
3400
|
+
return value;
|
|
3401
|
+
}
|
|
3402
|
+
async function gameKit(game, stamp, root) {
|
|
3403
|
+
const kits = discoverTemplateNames(root);
|
|
3404
|
+
const kitJson = (await readJsonRecord(path8.join(game, "kit.json")))?.name;
|
|
3405
|
+
const title = (await readFile(path8.join(game, "AGENTS.md"), "utf8").catch(() => "")).split("\n", 1)[0]?.trim();
|
|
3406
|
+
const titleKit = title === void 0 ? void 0 : KIT_TITLE.exec(title)?.[1] ?? title.split(" ").at(-1);
|
|
3407
|
+
return [stamp?.kit, kitJson, titleKit].find(
|
|
3408
|
+
(name) => typeof name === "string" && kits.includes(name)
|
|
3409
|
+
);
|
|
3410
|
+
}
|
|
3411
|
+
async function authoringContext(game, root) {
|
|
3412
|
+
const stamp = await readJsonRecord(path8.join(game, AUTHORING_STAMP));
|
|
3413
|
+
return { kit: await gameKit(game, stamp, root), stamp };
|
|
3414
|
+
}
|
|
3415
|
+
var NO_KIT = 'no stamp, kit.json or kit router title names a kit; write {"kit": "<kit>"} to .threenative/agent-files.json';
|
|
3416
|
+
var ENGINE_PAIR_UPGRADE = "pnpm up --latest create-threenative @threenative/*";
|
|
3417
|
+
async function installedCoreVersion(game) {
|
|
3418
|
+
const manifest = await readFile(
|
|
3419
|
+
path8.join(game, "node_modules", CORE_PACKAGE_NAME, "package.json"),
|
|
3420
|
+
"utf8"
|
|
3421
|
+
).catch(() => void 0);
|
|
3422
|
+
if (manifest === void 0) return void 0;
|
|
3423
|
+
try {
|
|
3424
|
+
const version = JSON.parse(manifest).version;
|
|
3425
|
+
return typeof version === "string" ? version : void 0;
|
|
3426
|
+
} catch {
|
|
3427
|
+
return void 0;
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
async function assertEnginePair(game) {
|
|
3431
|
+
const installed = await installedCoreVersion(game);
|
|
3432
|
+
if (pairsWithCore(installed)) return;
|
|
3433
|
+
const got = installed === void 0 ? "no installed core" : `${CORE_PACKAGE_NAME}@${installed}`;
|
|
3434
|
+
throw new Error(
|
|
3435
|
+
`TN_AUTHORING_LAYER_PAIR: this create-threenative pairs with ${CORE_PACKAGE_NAME}@${CORE_PACKAGE_VERSION} or newer, and this game installs ${got}. Run '${ENGINE_PAIR_UPGRADE}' first, then 'pnpm exec threenative doctor --fix'.`
|
|
3436
|
+
);
|
|
3437
|
+
}
|
|
3438
|
+
async function authoringLayerStatus(game, root = templateRoot()) {
|
|
3439
|
+
const installed = packageVersion(root);
|
|
3440
|
+
const { kit, stamp } = await authoringContext(game, root);
|
|
3441
|
+
const stamped = stamp?.createThreenative;
|
|
3442
|
+
const versions = { installed, ...stamped === void 0 ? {} : { stamped } };
|
|
3443
|
+
if (kit === void 0) return { ...versions, problem: NO_KIT, stale: [] };
|
|
3444
|
+
const expected = await renderedAuthoringLayer(game, kit, root);
|
|
3445
|
+
const stale = [];
|
|
3446
|
+
for (const [file, hash] of Object.entries(expected))
|
|
3447
|
+
if (await fileHash(path8.join(game, file)) !== hash) stale.push(file);
|
|
3448
|
+
for (const file of Object.keys(stamp?.files ?? {}))
|
|
3449
|
+
if (!(file in expected) && existsSync(path8.join(game, file))) stale.push(file);
|
|
3450
|
+
return { ...versions, kit, stale: stale.sort() };
|
|
3451
|
+
}
|
|
3452
|
+
async function fixAuthoringLayer(game, options, root = templateRoot()) {
|
|
3453
|
+
await assertEnginePair(game);
|
|
3454
|
+
assertMcpShims(game);
|
|
3455
|
+
const { kit, stamp } = await authoringContext(game, root);
|
|
3456
|
+
if (kit === void 0) throw new Error(`TN_AUTHORING_LAYER_KIT: ${NO_KIT}.`);
|
|
3457
|
+
const stamped = stamp?.files ?? {};
|
|
3458
|
+
const rendered = await mkdtemp(path8.join(tmpdir(), "threenative-authoring-"));
|
|
3459
|
+
const result = { deleted: [], kept: [], written: [] };
|
|
3460
|
+
try {
|
|
3461
|
+
const expected = await renderedAuthoringLayer(game, kit, root, rendered);
|
|
3462
|
+
for (const [file, hash] of Object.entries(expected).sort(
|
|
3463
|
+
([left], [right]) => left < right ? -1 : 1
|
|
3464
|
+
)) {
|
|
3465
|
+
const current = await fileHash(path8.join(game, file));
|
|
3466
|
+
if (current === hash) continue;
|
|
3467
|
+
if (current !== void 0 && current !== stamped[file] && !options.force) {
|
|
3468
|
+
result.kept.push(file);
|
|
3469
|
+
continue;
|
|
3470
|
+
}
|
|
3471
|
+
await mkdir(path8.dirname(path8.join(game, file)), { recursive: true });
|
|
3472
|
+
await cp(path8.join(rendered, file), path8.join(game, file));
|
|
3473
|
+
result.written.push(file);
|
|
3474
|
+
}
|
|
3475
|
+
for (const file of Object.keys(stamped).sort()) {
|
|
3476
|
+
if (file in expected) continue;
|
|
3477
|
+
const current = await fileHash(path8.join(game, file));
|
|
3478
|
+
if (current === void 0) continue;
|
|
3479
|
+
if (current !== stamped[file] && !options.force) result.kept.push(file);
|
|
3480
|
+
else {
|
|
3481
|
+
await rm(path8.join(game, file));
|
|
3482
|
+
result.deleted.push(file);
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
await linkClaudeSkills(game);
|
|
3486
|
+
writeHostMcpConfigs(game);
|
|
3487
|
+
await assertMcpConfig(game);
|
|
3488
|
+
await installAuthoringGitignore(game);
|
|
3489
|
+
await assertReferenceBundle(game, root);
|
|
3490
|
+
await writeAuthoringStamp(game, kit, expected, root);
|
|
3491
|
+
} finally {
|
|
3492
|
+
await rm(rendered, { force: true, recursive: true });
|
|
3493
|
+
}
|
|
3494
|
+
return result;
|
|
3495
|
+
}
|
|
2985
3496
|
async function runInstall(target) {
|
|
2986
3497
|
await new Promise((resolve, reject) => {
|
|
2987
3498
|
const child = spawn("pnpm", ["install"], { cwd: target, stdio: "inherit" });
|
|
@@ -2998,14 +3509,14 @@ async function discardScaffold(target, existedBefore) {
|
|
|
2998
3509
|
return;
|
|
2999
3510
|
}
|
|
3000
3511
|
for (const entry of await readdir(target)) {
|
|
3001
|
-
await rm(
|
|
3512
|
+
await rm(path8.join(target, entry), { force: true, recursive: true });
|
|
3002
3513
|
}
|
|
3003
3514
|
}
|
|
3004
3515
|
async function createProject(options, cwd = process.cwd(), root = templateRoot()) {
|
|
3005
3516
|
const manifests = discoverKitManifests(root);
|
|
3006
3517
|
const template = options.template ?? DEFAULT_TEMPLATE;
|
|
3007
3518
|
if (!manifests.some(({ name }) => name === template)) kitManifest(template, root);
|
|
3008
|
-
const target =
|
|
3519
|
+
const target = path8.resolve(cwd, options.target);
|
|
3009
3520
|
const targetExists = await isEmpty(target).catch(() => false);
|
|
3010
3521
|
if (!targetExists) {
|
|
3011
3522
|
throw new Error(`Target '${target}' already exists and is not empty.`);
|
|
@@ -3014,26 +3525,20 @@ async function createProject(options, cwd = process.cwd(), root = templateRoot()
|
|
|
3014
3525
|
await mkdir(target, { recursive: true });
|
|
3015
3526
|
const installed = options.install ?? true;
|
|
3016
3527
|
try {
|
|
3017
|
-
const source =
|
|
3528
|
+
const source = path8.join(root, template);
|
|
3018
3529
|
await cp(source, target, { recursive: true, errorOnExist: true });
|
|
3019
|
-
await rm(
|
|
3530
|
+
await rm(path8.join(target, "kit.json"), { force: true });
|
|
3020
3531
|
if (["starter", "collectathon", "adventure", "kart"].includes(template))
|
|
3021
|
-
for (const relative of
|
|
3022
|
-
await cp(canonicalRenderSourcePath(relative, root),
|
|
3532
|
+
for (const relative of ADDED_RENDER_SOURCES)
|
|
3533
|
+
await cp(canonicalRenderSourcePath(relative, root), path8.join(target, relative));
|
|
3023
3534
|
await copyTemplateIcon(target, root);
|
|
3024
3535
|
await copySharedAssets(target, root);
|
|
3025
3536
|
await copyQualityConfig(target, root);
|
|
3026
|
-
if (existsSync(
|
|
3027
|
-
await rename(
|
|
3537
|
+
if (existsSync(path8.join(target, "gitignore"))) {
|
|
3538
|
+
await rename(path8.join(target, "gitignore"), path8.join(target, ".gitignore"));
|
|
3028
3539
|
}
|
|
3029
3540
|
await installAuthoringGitignore(target);
|
|
3030
|
-
const
|
|
3031
|
-
const compactProjectId = projectName.toLowerCase().replace(/[^a-z0-9]+/gu, "") || "game";
|
|
3032
|
-
const projectId = /^[a-z]/u.test(compactProjectId) ? compactProjectId : `game${compactProjectId}`;
|
|
3033
|
-
const replacements = Object.fromEntries([
|
|
3034
|
-
["__PROJECT_NAME__", projectName],
|
|
3035
|
-
["__PROJECT_ID__", projectId]
|
|
3036
|
-
]);
|
|
3541
|
+
const replacements = templateReplacements(target);
|
|
3037
3542
|
await stampTemplateLoading(target, source, root);
|
|
3038
3543
|
await copyAgentFiles(target, root);
|
|
3039
3544
|
await renderTemplate(target, replacements);
|
|
@@ -3042,6 +3547,12 @@ async function createProject(options, cwd = process.cwd(), root = templateRoot()
|
|
|
3042
3547
|
writeHostMcpConfigs(target);
|
|
3043
3548
|
await assertMcpConfig(target);
|
|
3044
3549
|
await assertReferenceBundle(target, root);
|
|
3550
|
+
await writeAuthoringStamp(
|
|
3551
|
+
target,
|
|
3552
|
+
template,
|
|
3553
|
+
await renderedAuthoringLayer(target, template, root),
|
|
3554
|
+
root
|
|
3555
|
+
);
|
|
3045
3556
|
if (installed) await runInstall(target);
|
|
3046
3557
|
} catch (error) {
|
|
3047
3558
|
await discardScaffold(target, existedBefore);
|
|
@@ -3160,7 +3671,7 @@ async function main() {
|
|
|
3160
3671
|
);
|
|
3161
3672
|
}
|
|
3162
3673
|
var entryPath = process.argv[1];
|
|
3163
|
-
if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(
|
|
3674
|
+
if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(path8.resolve(entryPath)) === realpathSync(fileURLToPath(import.meta.url))) {
|
|
3164
3675
|
main().catch((error) => {
|
|
3165
3676
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}
|
|
3166
3677
|
`);
|
|
@@ -3168,4 +3679,4 @@ if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(path7.resolve(
|
|
|
3168
3679
|
});
|
|
3169
3680
|
}
|
|
3170
3681
|
|
|
3171
|
-
export { SHARED_RENDER_SOURCES, canonicalLoadingPath, canonicalRenderSourcePath, cliHelp, createEngineFreshnessPlugin, createProject, createWebBrandPlugin, discoverKitManifests, discoverStampedTemplates, discoverTemplateNames, hashEngineDist, kitManifest, packageNameFromFlag, parseArgs, projectMcpServers, referenceDigest, renderWebManifest, restampSharedRenderCopies, restampTemplateLoadingCopies, scaffoldCompletionMessage, scaffoldNextSteps, stampLoadingSource, templateForGenre, templateRoot, webRuntimeDecoders };
|
|
3682
|
+
export { ADDED_RENDER_SOURCES, SHARED_RENDER_SOURCES, authoringLayerStatus, canonicalLoadingPath, canonicalRenderSourcePath, cliHelp, createEngineCatalogPlugin, createEngineFreshnessPlugin, createProject, createWebBrandPlugin, discoverKitManifests, discoverStampedTemplates, discoverTemplateNames, fixAuthoringLayer, hashEngineDist, kitManifest, packageNameFromFlag, parseArgs, projectMcpServers, referenceDigest, renderWebManifest, restampSharedRenderCopies, restampTemplateLoadingCopies, scaffoldCompletionMessage, scaffoldNextSteps, stampLoadingSource, templateForGenre, templateRoot, webRuntimeDecoders };
|