@wildshard/sdk 0.0.1 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (688) hide show
  1. package/GUIDE.md +895 -0
  2. package/README.md +13 -5
  3. package/bin/wildshard.mjs +38 -0
  4. package/lint/declaration-config.d.mts +2 -0
  5. package/lint/declaration-config.mjs +19 -0
  6. package/lint/engine-plugin.d.mts +2 -0
  7. package/lint/engine-plugin.mjs +40 -0
  8. package/lint/host-callbacks.d.mts +6 -0
  9. package/lint/host-callbacks.mjs +123 -0
  10. package/lint/host-files.d.mts +1 -0
  11. package/lint/host-files.mjs +7 -0
  12. package/lint/layer-exports.d.mts +2 -0
  13. package/lint/layer-exports.mjs +21 -0
  14. package/lint/legacy-line-basis.json +995 -0
  15. package/lint/nine-tiling-baseline.json +35 -0
  16. package/lint/ratchet.json +11 -0
  17. package/lint/runtime-files.d.mts +12 -0
  18. package/lint/runtime-files.json +16 -0
  19. package/lint/runtime-files.mjs +69 -0
  20. package/lint/runtime-performance.d.mts +6 -0
  21. package/lint/runtime-performance.mjs +184 -0
  22. package/lint/sdk-plugin.d.mts +4 -0
  23. package/lint/sdk-plugin.mjs +134 -0
  24. package/lint/shardfile-boundaries.d.mts +10 -0
  25. package/lint/shardfile-boundaries.mjs +122 -0
  26. package/lint/tile-bake-debt.json +556 -0
  27. package/package.json +365 -3
  28. package/scripts/agent-parity.mjs +1524 -0
  29. package/scripts/agent-sync.mjs +518 -0
  30. package/scripts/apfs-clone.mjs +67 -0
  31. package/scripts/assert-store-layout.mjs +23 -0
  32. package/scripts/astc6-phone-cap.d.mts +3 -0
  33. package/scripts/astc6-phone-cap.mjs +137 -0
  34. package/scripts/audit-assets.d.mts +10 -0
  35. package/scripts/audit-assets.mjs +151 -0
  36. package/scripts/bake/coatFiles.d.mts +6 -0
  37. package/scripts/bake/coatFiles.mjs +37 -0
  38. package/scripts/bake/environment.d.mts +2 -0
  39. package/scripts/bake/environment.mjs +58 -0
  40. package/scripts/bake/far-proxies.mjs +45 -0
  41. package/scripts/bake/keyed-sky.d.mts +4 -0
  42. package/scripts/bake/keyed-sky.mjs +34 -0
  43. package/scripts/bake/movers.mjs +56 -0
  44. package/scripts/bake/nativeWorld.d.mts +6 -0
  45. package/scripts/bake/nativeWorld.mjs +43 -0
  46. package/scripts/bake/navmeshGround.ts +22 -0
  47. package/scripts/bake/near-placeholder.mjs +331 -0
  48. package/scripts/bake/placeholderShards.mjs +41 -0
  49. package/scripts/bake/skins.mjs +15 -0
  50. package/scripts/bake/template-skins.mjs +33 -0
  51. package/scripts/bake/viewmodelBytes.ts +26 -0
  52. package/scripts/bake/viewmodelPage.ts +11 -0
  53. package/scripts/bake/worldHost.d.mts +35 -0
  54. package/scripts/bake/worldHost.mjs +110 -0
  55. package/scripts/bake-astc6.cache.json +80 -0
  56. package/scripts/bake-astc6.far-reach.cache.json +23 -0
  57. package/scripts/bake-astc6.list.json +111 -0
  58. package/scripts/bake-astc6.mjs +279 -0
  59. package/scripts/bake-astc6.nalati-grasslands.cache.json +42 -0
  60. package/scripts/bake-catalogue.mjs +44 -0
  61. package/scripts/bake-check.mjs +54 -0
  62. package/scripts/bake-chunk.mjs +124 -0
  63. package/scripts/bake-cloud-field.mjs +24 -0
  64. package/scripts/bake-coats.mjs +110 -0
  65. package/scripts/bake-data-maps.d.mts +24 -0
  66. package/scripts/bake-data-maps.mjs +72 -0
  67. package/scripts/bake-entry-programs.mjs +117 -0
  68. package/scripts/bake-geometry.mjs +106 -0
  69. package/scripts/bake-hybrid-tiles.mjs +28 -0
  70. package/scripts/bake-ktx2.cache.json +276 -0
  71. package/scripts/bake-ktx2.list.json +365 -0
  72. package/scripts/bake-ktx2.mjs +477 -0
  73. package/scripts/bake-map-glb.mjs +127 -0
  74. package/scripts/bake-map-rest.d.mts +7 -0
  75. package/scripts/bake-map-rest.mjs +50 -0
  76. package/scripts/bake-maps.mjs +200 -0
  77. package/scripts/bake-navmesh.mjs +259 -0
  78. package/scripts/bake-packs.mjs +129 -0
  79. package/scripts/bake-pickups.mjs +102 -0
  80. package/scripts/bake-query-terrain.mjs +64 -0
  81. package/scripts/bake-recurve-pool.mjs +16 -0
  82. package/scripts/bake-section-schemas.d.mts +3 -0
  83. package/scripts/bake-template-shardfile.mjs +32 -0
  84. package/scripts/bake-textures.mjs +80 -0
  85. package/scripts/bake-viewmodel-sets.json +45 -0
  86. package/scripts/bake-viewmodel-sets.mjs +137 -0
  87. package/scripts/bake-voxel-ao.mjs +119 -0
  88. package/scripts/bake-water-ripples.mjs +25 -0
  89. package/scripts/blender/README.md +129 -0
  90. package/scripts/blender/build.sh +166 -0
  91. package/scripts/blender/lib/export-scene.mjs +129 -0
  92. package/scripts/blender/lib/glb-digest.mjs +188 -0
  93. package/scripts/blender/lib/glb.py +68 -0
  94. package/scripts/blender/lib/save_blend.py +17 -0
  95. package/scripts/blender/lib/world_fixture.py +55 -0
  96. package/scripts/blender/targets.json +591 -0
  97. package/scripts/build-sdk.mjs +95 -0
  98. package/scripts/build-shardfiles.d.mts +7 -0
  99. package/scripts/build-shardfiles.mjs +206 -0
  100. package/scripts/capture-hero.mjs +137 -0
  101. package/scripts/check-lift-review.mjs +23 -0
  102. package/scripts/chromium-keychain-check.mjs +139 -0
  103. package/scripts/chromium-keychain.d.mts +1 -0
  104. package/scripts/chromium-keychain.mjs +5 -0
  105. package/scripts/compile-script.d.mts +3 -0
  106. package/scripts/compile-script.mjs +8 -0
  107. package/scripts/creature-color.mjs +255 -0
  108. package/scripts/decide/calibrate.py +127 -0
  109. package/scripts/decide/calibration/2026-10-03/labels-s1.tsv +281 -0
  110. package/scripts/decide/calibration/2026-10-03/labels-s2.tsv +97 -0
  111. package/scripts/decide/calibration/2026-10-03/labels-s3.tsv +48 -0
  112. package/scripts/decide/calibration/2026-10-03/labels-s3b.tsv +26 -0
  113. package/scripts/decide/calibration/2026-10-03/res-capture-status-v1.jsonl +376 -0
  114. package/scripts/decide/calibration/2026-10-03/res-text-garbled-strings.jsonl +48 -0
  115. package/scripts/decide/calibration/2026-10-03/res-text-garbled-v1.jsonl +73 -0
  116. package/scripts/decide/decide.py +262 -0
  117. package/scripts/decide/decide.sh +50 -0
  118. package/scripts/decide/layer-purity-pilot.mjs +41 -0
  119. package/scripts/decide/sets/capture-status.json +46 -0
  120. package/scripts/decide/sets/layer-purity.json +28 -0
  121. package/scripts/decide/sets/text-garbled.json +17 -0
  122. package/scripts/decide/test_decide.py +37 -0
  123. package/scripts/docs.mjs +15 -0
  124. package/scripts/entry-reads/crawl.ts +152 -0
  125. package/scripts/entry-reads/tsconfig.json +25 -0
  126. package/scripts/gen-format-schema.d.mts +2 -0
  127. package/scripts/gen-format-schema.mjs +21 -0
  128. package/scripts/gen-host-catalogue.d.mts +14 -0
  129. package/scripts/gen-host-catalogue.mjs +108 -0
  130. package/scripts/gen-shard-layout-doc.d.mts +4 -0
  131. package/scripts/gen-shard-layout-doc.mjs +55 -0
  132. package/scripts/gen-shards.d.mts +17 -0
  133. package/scripts/gen-shards.mjs +311 -0
  134. package/scripts/goldens/capture-inputs.d.mts +4 -0
  135. package/scripts/goldens/capture-inputs.mjs +34 -0
  136. package/scripts/goldens/colour_shift.py +27 -0
  137. package/scripts/goldens/native-residency.d.mts +10 -0
  138. package/scripts/goldens/native-residency.mjs +104 -0
  139. package/scripts/goldens/plot-inputs.d.mts +12 -0
  140. package/scripts/goldens/plot-inputs.mjs +46 -0
  141. package/scripts/gpu-texmem.mjs +98 -0
  142. package/scripts/horizon-matte/config.py +24 -0
  143. package/scripts/horizon-matte/encode.py +91 -0
  144. package/scripts/horizon-matte/key.py +141 -0
  145. package/scripts/horizon-matte/mkjobs.py +33 -0
  146. package/scripts/horizon-matte/mkjobs_day2.py +11 -0
  147. package/scripts/horizon-matte/overlap.py +80 -0
  148. package/scripts/horizon-matte/run_codex.py +57 -0
  149. package/scripts/horizon-matte/stitch.py +133 -0
  150. package/scripts/img2mesh/CC0.md +105 -0
  151. package/scripts/img2mesh/README.md +209 -0
  152. package/scripts/img2mesh/ab_board.py +102 -0
  153. package/scripts/img2mesh/birds/birds.json +255 -0
  154. package/scripts/img2mesh/birds/birds_atlas.py +150 -0
  155. package/scripts/img2mesh/birds/birds_fix_preview.mjs +103 -0
  156. package/scripts/img2mesh/birds/birds_fix_render.py +75 -0
  157. package/scripts/img2mesh/birds/birds_pack.py +110 -0
  158. package/scripts/img2mesh/birds/birds_phone_b.py +112 -0
  159. package/scripts/img2mesh/birds/birds_post.py +550 -0
  160. package/scripts/img2mesh/birds/birds_render.py +125 -0
  161. package/scripts/img2mesh/birds/birds_sheet.py +33 -0
  162. package/scripts/img2mesh/birds/birds_view.py +60 -0
  163. package/scripts/img2mesh/board.py +100 -0
  164. package/scripts/img2mesh/build_cc0.sh +52 -0
  165. package/scripts/img2mesh/build_driftwood.sh +12 -0
  166. package/scripts/img2mesh/build_faces.sh +53 -0
  167. package/scripts/img2mesh/build_props.py +81 -0
  168. package/scripts/img2mesh/cc0_export.py +186 -0
  169. package/scripts/img2mesh/driftwood_post.py +571 -0
  170. package/scripts/img2mesh/e304_faces.sh +67 -0
  171. package/scripts/img2mesh/face_remaster.py +911 -0
  172. package/scripts/img2mesh/face_views.py +95 -0
  173. package/scripts/img2mesh/faces-e304.json +9 -0
  174. package/scripts/img2mesh/faces.json +30 -0
  175. package/scripts/img2mesh/head_cut.py +100 -0
  176. package/scripts/img2mesh/hi3d_paint.py +94 -0
  177. package/scripts/img2mesh/hi3d_refine.py +161 -0
  178. package/scripts/img2mesh/hunyuan_cpu_rasterizer.sh +42 -0
  179. package/scripts/img2mesh/pine_hollow_phone.sh +13 -0
  180. package/scripts/img2mesh/props/coral-arch.json +32 -0
  181. package/scripts/img2mesh/props/ember-furnace.json +30 -0
  182. package/scripts/img2mesh/props/night-market-gate.json +10 -0
  183. package/scripts/img2mesh/render_still.py +86 -0
  184. package/scripts/img2mesh/rig_strip.mjs +46 -0
  185. package/scripts/img2mesh/rig_transfer.mjs +104 -0
  186. package/scripts/img2mesh/split_sheet.py +48 -0
  187. package/scripts/img2mesh/trellis_batch.py +110 -0
  188. package/scripts/img2mesh/versus_board.py +114 -0
  189. package/scripts/import-bundle.d.mts +2 -0
  190. package/scripts/import-bundle.mjs +20 -0
  191. package/scripts/ktx2-ab-board.py +133 -0
  192. package/scripts/ktx2-ab.mjs +111 -0
  193. package/scripts/ktx2-settings.mjs +18 -0
  194. package/scripts/land.d.mts +14 -0
  195. package/scripts/land.mjs +809 -0
  196. package/scripts/lint-dispatch.mjs +14 -0
  197. package/scripts/map-bake-frames.d.mts +4 -0
  198. package/scripts/map-bake-frames.mjs +23 -0
  199. package/scripts/map-geometry.d.mts +9 -0
  200. package/scripts/map-geometry.mjs +29 -0
  201. package/scripts/map-world.mjs +162 -0
  202. package/scripts/mockup-local.sh +46 -0
  203. package/scripts/music/export-midi.mjs +68 -0
  204. package/scripts/music/gen/analyze.py +308 -0
  205. package/scripts/music/gen/audio_jobs.py +46 -0
  206. package/scripts/music/gen/briefs.json +51 -0
  207. package/scripts/music/gen/build_page.py +334 -0
  208. package/scripts/music/gen/folk.json +3187 -0
  209. package/scripts/music/gen/gen_ace_step.py +156 -0
  210. package/scripts/music/gen/gen_heartmula.py +187 -0
  211. package/scripts/music/gen/gen_minimax.py +143 -0
  212. package/scripts/music/gen/gen_sao.py +122 -0
  213. package/scripts/music/gen/gen_sao_small.py +104 -0
  214. package/scripts/music/gen/gen_sfx.py +98 -0
  215. package/scripts/music/gen/gen_sfx_ezaudio.py +112 -0
  216. package/scripts/music/gen/gen_sfx_moss.py +112 -0
  217. package/scripts/music/gen/models.json +61 -0
  218. package/scripts/music/gen/nalati-jobs.json +104 -0
  219. package/scripts/music/gen/nalati-score-build.json +119 -0
  220. package/scripts/music/gen/nalati-score.json +3448 -0
  221. package/scripts/music/gen/ob7-fit-decisions.json +38 -0
  222. package/scripts/music/gen/ob7-score-jobs.json +152 -0
  223. package/scripts/music/gen/ob7-sfx-jobs.json +897 -0
  224. package/scripts/music/gen/ob7_build.py +469 -0
  225. package/scripts/music/gen/ob7_generate.py +67 -0
  226. package/scripts/music/gen/ob7_run.sh +42 -0
  227. package/scripts/music/gen/orchestral.json +3187 -0
  228. package/scripts/music/gen/own_score.py +486 -0
  229. package/scripts/music/gen/ph-jobs.json +27 -0
  230. package/scripts/music/gen/ph_page.py +222 -0
  231. package/scripts/music/gen/piano.json +3175 -0
  232. package/scripts/music/gen/rank_v3.py +248 -0
  233. package/scripts/music/gen/sfx-best.json +2486 -0
  234. package/scripts/music/gen/sfx-ezaudio.json +4082 -0
  235. package/scripts/music/gen/sfx-jobs.json +57 -0
  236. package/scripts/music/gen/sfx-minimax-jobs.json +16 -0
  237. package/scripts/music/gen/sfx-minimax.json +289 -0
  238. package/scripts/music/gen/sfx-moss.json +4082 -0
  239. package/scripts/music/gen/sfx-nalati-b3-jobs.json +17 -0
  240. package/scripts/music/gen/sfx-nalati-jobs.json +338 -0
  241. package/scripts/music/gen/sfx-nalati.json +11202 -0
  242. package/scripts/music/gen/sfx-nd-jobs.json +57 -0
  243. package/scripts/music/gen/sfx-nd-moss.json +2097 -0
  244. package/scripts/music/gen/sfx-nd-sa3-medium.json +2097 -0
  245. package/scripts/music/gen/sfx-nd-summary.json +38 -0
  246. package/scripts/music/gen/sfx-peaks.json +7 -0
  247. package/scripts/music/gen/sfx-ph-jobs.json +169 -0
  248. package/scripts/music/gen/sfx-ph-moss.json +6564 -0
  249. package/scripts/music/gen/sfx-ph-sa3-medium.json +7239 -0
  250. package/scripts/music/gen/sfx-ph-summary.json +63 -0
  251. package/scripts/music/gen/sfx-sa3-medium.json +4082 -0
  252. package/scripts/music/gen/sfx-sa3.json +4082 -0
  253. package/scripts/music/gen/sfx-summary.json +107 -0
  254. package/scripts/music/gen/sfx_build.py +332 -0
  255. package/scripts/music/gen/sfx_merge.py +255 -0
  256. package/scripts/music/gen/sfx_minimax.py +61 -0
  257. package/scripts/music/gen/sfx_nalati.py +331 -0
  258. package/scripts/music/gen/sfx_sprite.py +424 -0
  259. package/scripts/music/gen/stems.py +539 -0
  260. package/scripts/music/gen/test_loop_meter.py +29 -0
  261. package/scripts/music/gen/test_ob7_provenance.py +77 -0
  262. package/scripts/music/gen/v3-folk-build.json +148 -0
  263. package/scripts/music/gen/v3-folk.json +1818 -0
  264. package/scripts/music/gen/v3-jobs.json +145 -0
  265. package/scripts/music/gen/v3-orchestral-build.json +148 -0
  266. package/scripts/music/gen/v3-orchestral.json +1813 -0
  267. package/scripts/music/gen/v3-ph-folk-build.json +94 -0
  268. package/scripts/music/gen/v3-ph-folk.json +1806 -0
  269. package/scripts/music/gen/v3-ph-orchestral-build.json +94 -0
  270. package/scripts/music/gen/v3-ph-orchestral.json +1824 -0
  271. package/scripts/music/gen/v3-ph-piano-build.json +94 -0
  272. package/scripts/music/gen/v3-ph-piano.json +1818 -0
  273. package/scripts/music/gen/v3-piano-build.json +148 -0
  274. package/scripts/music/gen/v3-piano.json +1813 -0
  275. package/scripts/music/wildshard-theme.mid +0 -0
  276. package/scripts/music/wildshard-trailer30.mid +0 -0
  277. package/scripts/named-blob-output.d.mts +8 -0
  278. package/scripts/named-blob-output.mjs +48 -0
  279. package/scripts/pack-all.mjs +15 -0
  280. package/scripts/pid-lock.d.mts +1 -0
  281. package/scripts/pid-lock.mjs +63 -0
  282. package/scripts/practice/bake_dummy.py +53 -0
  283. package/scripts/practice/build_dummies.sh +43 -0
  284. package/scripts/practice/dummy_parts.py +568 -0
  285. package/scripts/practice/dummy_rig_gate.py +139 -0
  286. package/scripts/practice/gate_sheet.py +36 -0
  287. package/scripts/practice/generate_dummy_unimate.py +132 -0
  288. package/scripts/practice/pack_dummy.mjs +59 -0
  289. package/scripts/practice/repair_dummy_weights.mjs +68 -0
  290. package/scripts/practice/rig_dummy.py +828 -0
  291. package/scripts/practice/verify_unimate_skin.mjs +356 -0
  292. package/scripts/preparation-seed.mjs +15 -0
  293. package/scripts/prepare-basis-tool.mjs +6 -0
  294. package/scripts/prepare-product.d.mts +14 -0
  295. package/scripts/prepare-product.mjs +101 -0
  296. package/scripts/product-build-tools.d.mts +3 -0
  297. package/scripts/product-build-tools.json +3 -0
  298. package/scripts/product-build-tools.mjs +31 -0
  299. package/scripts/publish-public.mjs +7 -0
  300. package/scripts/push-tables.d.mts +1 -0
  301. package/scripts/push-tables.mjs +28 -0
  302. package/scripts/record-shard-mounts.mjs +133 -0
  303. package/scripts/sdk-externals.d.mts +2 -0
  304. package/scripts/sdk-externals.mjs +2 -0
  305. package/scripts/section-inventory.ts +209 -0
  306. package/scripts/select-candidate.mjs +15 -0
  307. package/scripts/shard-build-pool.d.mts +4 -0
  308. package/scripts/shard-build-pool.mjs +53 -0
  309. package/scripts/shard-line-baseline.json +17 -0
  310. package/scripts/shard-milestones.d.mts +15 -0
  311. package/scripts/shard-milestones.mjs +105 -0
  312. package/scripts/shard-output-report.d.mts +9 -0
  313. package/scripts/shard-output-report.mjs +85 -0
  314. package/scripts/shard-platform-cli.mjs +93 -0
  315. package/scripts/shard-progress.mjs +212 -0
  316. package/scripts/shard-timelapse.py +102 -0
  317. package/scripts/shardfile-cold-boot.mjs +79 -0
  318. package/scripts/shardfile-vite.d.mts +4 -0
  319. package/scripts/shardfile-vite.mjs +20 -0
  320. package/scripts/simplify-models.mjs +24 -0
  321. package/scripts/site-facts.mjs +88 -0
  322. package/scripts/test-template-gate.mjs +44 -0
  323. package/scripts/test_golden_compare.py +68 -0
  324. package/scripts/tex-tiers.cache.json +181 -0
  325. package/scripts/tex-tiers.mjs +240 -0
  326. package/scripts/texmem-probe.mjs +184 -0
  327. package/scripts/unused-assets.mjs +173 -0
  328. package/scripts/vite-tmp.d.mts +23 -0
  329. package/scripts/vite-tmp.mjs +157 -0
  330. package/scripts/wave-line-baselines.json +32 -0
  331. package/scripts/wildshard.d.mts +4 -0
  332. package/scripts/wildshard.mjs +105 -0
  333. package/scripts/witness-checkpoints.d.mts +10 -0
  334. package/scripts/witness-checkpoints.mjs +84 -0
  335. package/scripts/witness-generation.d.mts +10 -0
  336. package/scripts/witness-generation.mjs +45 -0
  337. package/scripts/witness-manifests.d.mts +8 -0
  338. package/scripts/witness-manifests.mjs +157 -0
  339. package/scripts/worktree-ignore.d.mts +4 -0
  340. package/scripts/worktree-ignore.mjs +36 -0
  341. package/scripts/worktree-reap.mjs +214 -0
  342. package/scripts/worktree.mjs +396 -0
  343. package/scripts/worldclaw/capture-front.sh +28 -0
  344. package/scripts/worldclaw/design-template.md +62 -0
  345. package/scripts/worldclaw/spec-map.py +92 -0
  346. package/scripts/worldclaw/spec.ts +96 -0
  347. package/skills/wildshard/SKILL.md +50 -0
  348. package/skills/wildshard-goldens/SKILL.md +54 -0
  349. package/skills/wildshard-mockup-to-model/SKILL.md +56 -0
  350. package/skills/wildshard-upgrade/SKILL.md +47 -0
  351. package/src/.oxfmtrc.json +50 -0
  352. package/src/.oxlintrc.json +173 -0
  353. package/src/cli/account/account.ts +199 -0
  354. package/src/cli/account/command.ts +193 -0
  355. package/src/cli/account/key.ts +154 -0
  356. package/src/cli/args.ts +97 -0
  357. package/src/cli/audio/audio.ts +39 -0
  358. package/src/cli/bin.mjs +8 -0
  359. package/src/cli/delete/delete.ts +258 -0
  360. package/src/cli/help.ts +204 -0
  361. package/src/cli/hero/adopt.ts +103 -0
  362. package/src/cli/hero/hero.ts +112 -0
  363. package/src/cli/hero/stamp.ts +298 -0
  364. package/src/cli/main.ts +291 -0
  365. package/src/cli/report.ts +20 -0
  366. package/src/cli/shardfile/command.ts +49 -0
  367. package/src/cli/shardfile/shardfile.ts +192 -0
  368. package/src/cli/upload/api.ts +246 -0
  369. package/src/cli/upload/compress.ts +55 -0
  370. package/src/cli/upload/hero.ts +62 -0
  371. package/src/cli/upload/placement.ts +115 -0
  372. package/src/cli/upload/provenance.ts +192 -0
  373. package/src/cli/upload/signature.ts +30 -0
  374. package/src/cli/upload/upload.ts +269 -0
  375. package/src/cli/upload/validate.ts +74 -0
  376. package/src/cli/upload/wire.ts +147 -0
  377. package/src/cli/version.ts +63 -0
  378. package/src/commons/bake/portableMath.ts +187 -0
  379. package/src/commons/catalogue.ts +10 -0
  380. package/src/commons/courseProgram.ts +32 -0
  381. package/src/commons/practiceCourse.ts +16 -0
  382. package/src/commons/scripts/abi.as +14 -0
  383. package/src/commons/scripts/bridge.as +14 -0
  384. package/src/commons/scripts/course.as +63 -0
  385. package/src/scripts/ask-new.sh +29 -0
  386. package/src/scripts/asks.mjs +141 -0
  387. package/src/scripts/herdr-prompt.sh +34 -0
  388. package/src/scripts/herdr-question-open.sh +67 -0
  389. package/src/scripts/md-wrap.mjs +229 -0
  390. package/src/server/app.ts +19 -0
  391. package/src/server/serve.ts +49 -0
  392. package/src/sharddev/admission.ts +7 -0
  393. package/src/sharddev/agentFiles.ts +127 -0
  394. package/src/sharddev/arenaView.ts +15 -0
  395. package/src/sharddev/as/groupBankV2.ts +36 -0
  396. package/src/sharddev/as/groupStepV2.ts +13 -0
  397. package/src/sharddev/as/ws.ts +30 -0
  398. package/src/sharddev/as/wsV2.ts +180 -0
  399. package/src/sharddev/assemblyscriptCompiler.d.mts +5 -0
  400. package/src/sharddev/assemblyscriptCompiler.mjs +14 -0
  401. package/src/sharddev/assetHandle.ts +84 -0
  402. package/src/sharddev/assetOwner.ts +70 -0
  403. package/src/sharddev/assetScope.ts +30 -0
  404. package/src/sharddev/assets.ts +21 -0
  405. package/src/sharddev/audio.ts +9 -0
  406. package/src/sharddev/audioEncode.ts +211 -0
  407. package/src/sharddev/author.ts +3 -0
  408. package/src/sharddev/authorError.ts +28 -0
  409. package/src/sharddev/authorManifest.ts +39 -0
  410. package/src/sharddev/bake/annulus.ts +19 -0
  411. package/src/sharddev/bake/assemblyscriptMemo.ts +76 -0
  412. package/src/sharddev/bake/assemblyscriptMemoPort.ts +4 -0
  413. package/src/sharddev/bake/authoredWorld.ts +201 -0
  414. package/src/sharddev/bake/basisEncoder.ts +95 -0
  415. package/src/sharddev/bake/basisGlb.ts +85 -0
  416. package/src/sharddev/bake/basisTool.ts +74 -0
  417. package/src/sharddev/bake/basisToolInputs.ts +476 -0
  418. package/src/sharddev/bake/byteCodec.ts +33 -0
  419. package/src/sharddev/bake/canvasAtlas.ts +406 -0
  420. package/src/sharddev/bake/coarseCopy.ts +59 -0
  421. package/src/sharddev/bake/colliders.ts +87 -0
  422. package/src/sharddev/bake/compactGlb.ts +224 -0
  423. package/src/sharddev/bake/compileScript.ts +119 -0
  424. package/src/sharddev/bake/compileScriptV2.ts +75 -0
  425. package/src/sharddev/bake/contactRows.ts +84 -0
  426. package/src/sharddev/bake/creaturePlacement.ts +117 -0
  427. package/src/sharddev/bake/export.ts +67 -0
  428. package/src/sharddev/bake/facetedGeometry.ts +379 -0
  429. package/src/sharddev/bake/farImpostor.ts +120 -0
  430. package/src/sharddev/bake/forest.ts +100 -0
  431. package/src/sharddev/bake/format-hook.mjs +2 -0
  432. package/src/sharddev/bake/generatorGlb.ts +23 -0
  433. package/src/sharddev/bake/geometryBounds.ts +77 -0
  434. package/src/sharddev/bake/geometryError.ts +48 -0
  435. package/src/sharddev/bake/glb.ts +355 -0
  436. package/src/sharddev/bake/glbCompression.ts +143 -0
  437. package/src/sharddev/bake/gltfSource.ts +59 -0
  438. package/src/sharddev/bake/groundMap.ts +142 -0
  439. package/src/sharddev/bake/image.ts +20 -0
  440. package/src/sharddev/bake/isleMap.ts +64 -0
  441. package/src/sharddev/bake/json.mjs +84 -0
  442. package/src/sharddev/bake/keyedSky.ts +47 -0
  443. package/src/sharddev/bake/keyedSkyMemo.ts +39 -0
  444. package/src/sharddev/bake/kinds.ts +137 -0
  445. package/src/sharddev/bake/lightSources.ts +31 -0
  446. package/src/sharddev/bake/mapAssembly.ts +84 -0
  447. package/src/sharddev/bake/mapRaster.ts +173 -0
  448. package/src/sharddev/bake/mapRest.ts +57 -0
  449. package/src/sharddev/bake/mapScenes.ts +234 -0
  450. package/src/sharddev/bake/materialGraph.ts +32 -0
  451. package/src/sharddev/bake/meadow.ts +27 -0
  452. package/src/sharddev/bake/meshoptChoiceMemo.ts +34 -0
  453. package/src/sharddev/bake/nativeInteractionFacts.ts +5 -0
  454. package/src/sharddev/bake/nativeLattice.ts +178 -0
  455. package/src/sharddev/bake/nativeRaster.ts +106 -0
  456. package/src/sharddev/bake/nativeTerrainField.ts +11 -0
  457. package/src/sharddev/bake/navigation-json.mjs +38 -0
  458. package/src/sharddev/bake/navigation.ts +113 -0
  459. package/src/sharddev/bake/navigationAsset.ts +18 -0
  460. package/src/sharddev/bake/nearPlaceholder.ts +206 -0
  461. package/src/sharddev/bake/normalizeRig.ts +80 -0
  462. package/src/sharddev/bake/phoneAstc.ts +93 -0
  463. package/src/sharddev/bake/placeholders.ts +581 -0
  464. package/src/sharddev/bake/placement.ts +80 -0
  465. package/src/sharddev/bake/portableBytes.ts +18 -0
  466. package/src/sharddev/bake/portableBytesMemo.ts +50 -0
  467. package/src/sharddev/bake/practiceCourse.ts +49 -0
  468. package/src/sharddev/bake/primitives.ts +96 -0
  469. package/src/sharddev/bake/props.ts +443 -0
  470. package/src/sharddev/bake/questPlacement.ts +98 -0
  471. package/src/sharddev/bake/rawTexture.ts +26 -0
  472. package/src/sharddev/bake/riderArms.ts +97 -0
  473. package/src/sharddev/bake/rig.ts +95 -0
  474. package/src/sharddev/bake/riggedHullRecipes.ts +40 -0
  475. package/src/sharddev/bake/signPlacements.ts +25 -0
  476. package/src/sharddev/bake/simplifier.ts +52 -0
  477. package/src/sharddev/bake/skinned.ts +312 -0
  478. package/src/sharddev/bake/slabChunks.ts +149 -0
  479. package/src/sharddev/bake/slabs.ts +263 -0
  480. package/src/sharddev/bake/source-loader.mjs +55 -0
  481. package/src/sharddev/bake/sourceMetadata.ts +54 -0
  482. package/src/sharddev/bake/species.ts +368 -0
  483. package/src/sharddev/bake/specimenCatalogue.ts +47 -0
  484. package/src/sharddev/bake/splatGround.ts +141 -0
  485. package/src/sharddev/bake/staticMaterials.ts +171 -0
  486. package/src/sharddev/bake/terrain.ts +195 -0
  487. package/src/sharddev/bake/texture.ts +33 -0
  488. package/src/sharddev/bake/textureWasm.ts +81 -0
  489. package/src/sharddev/bake/tileEncoder.ts +11 -0
  490. package/src/sharddev/bake/tileGrid.ts +62 -0
  491. package/src/sharddev/bake/v2Finite.ts +160 -0
  492. package/src/sharddev/bake/v2Fuel.ts +71 -0
  493. package/src/sharddev/bake/wholePartition.ts +74 -0
  494. package/src/sharddev/bake/wholePieceJoin.ts +147 -0
  495. package/src/sharddev/bake/world.ts +173 -0
  496. package/src/sharddev/bake/worldCollision.ts +128 -0
  497. package/src/sharddev/bake/worldGeometry.ts +237 -0
  498. package/src/sharddev/bake/worldGlb.ts +123 -0
  499. package/src/sharddev/bake/worldImage.ts +12 -0
  500. package/src/sharddev/bake/worldLod.ts +128 -0
  501. package/src/sharddev/bake/worldRows.ts +102 -0
  502. package/src/sharddev/bake/worldTextureMemo.ts +63 -0
  503. package/src/sharddev/bake/zstdBytesMemo.ts +52 -0
  504. package/src/sharddev/bake.ts +193 -0
  505. package/src/sharddev/bakePublication.ts +31 -0
  506. package/src/sharddev/behaviourSource.ts +94 -0
  507. package/src/sharddev/bin/wildshard.mjs +7 -0
  508. package/src/sharddev/blobBytes.ts +65 -0
  509. package/src/sharddev/blobs.ts +138 -0
  510. package/src/sharddev/bootInventory.ts +129 -0
  511. package/src/sharddev/bossProfiles.ts +18 -0
  512. package/src/sharddev/buildBehaviour.ts +77 -0
  513. package/src/sharddev/buildCacheMetrics.ts +17 -0
  514. package/src/sharddev/buildDecisionScripts.ts +122 -0
  515. package/src/sharddev/check.ts +118 -0
  516. package/src/sharddev/checkProject.ts +127 -0
  517. package/src/sharddev/cli.ts +200 -0
  518. package/src/sharddev/clientChannels.ts +169 -0
  519. package/src/sharddev/clientScripts.ts +10 -0
  520. package/src/sharddev/commons.ts +77 -0
  521. package/src/sharddev/commonsCosts.ts +11 -0
  522. package/src/sharddev/compileMovers.ts +11 -0
  523. package/src/sharddev/configBoundary.ts +6 -0
  524. package/src/sharddev/cookInput.ts +40 -0
  525. package/src/sharddev/crowds.ts +6 -0
  526. package/src/sharddev/decisionBindingMap.ts +11 -0
  527. package/src/sharddev/decisionScriptBindings.ts +117 -0
  528. package/src/sharddev/decisionScripts.ts +28 -0
  529. package/src/sharddev/decisionSource.ts +51 -0
  530. package/src/sharddev/dev.ts +113 -0
  531. package/src/sharddev/director.ts +26 -0
  532. package/src/sharddev/directorAbi.ts +77 -0
  533. package/src/sharddev/discoveryDocument.ts +97 -0
  534. package/src/sharddev/draft.ts +11 -0
  535. package/src/sharddev/eliteEntryRows.ts +29 -0
  536. package/src/sharddev/entries.ts +76 -0
  537. package/src/sharddev/entryReads.ts +73 -0
  538. package/src/sharddev/executeBundle.ts +55 -0
  539. package/src/sharddev/finds.ts +5 -0
  540. package/src/sharddev/formatJsonSchema.ts +3 -0
  541. package/src/sharddev/generationCache.ts +257 -0
  542. package/src/sharddev/generationRecipe.ts +94 -0
  543. package/src/sharddev/handwritten.ts +110 -0
  544. package/src/sharddev/immutable.ts +14 -0
  545. package/src/sharddev/interactions.ts +38 -0
  546. package/src/sharddev/kit/bakedGeometry.ts +16 -0
  547. package/src/sharddev/kit/geometryPack.ts +110 -0
  548. package/src/sharddev/ledger.ts +13 -0
  549. package/src/sharddev/looks/tileField.ts +67 -0
  550. package/src/sharddev/materialGraphFiles.ts +57 -0
  551. package/src/sharddev/materials.ts +574 -0
  552. package/src/sharddev/measure.ts +18 -0
  553. package/src/sharddev/modes.ts +115 -0
  554. package/src/sharddev/moverPrograms.ts +213 -0
  555. package/src/sharddev/movers.ts +75 -0
  556. package/src/sharddev/nativePopulationRows.ts +46 -0
  557. package/src/sharddev/newProject.ts +226 -0
  558. package/src/sharddev/noise.ts +54 -0
  559. package/src/sharddev/outputProduct.ts +188 -0
  560. package/src/sharddev/outputRuntime.ts +66 -0
  561. package/src/sharddev/performancePolicy.ts +29 -0
  562. package/src/sharddev/phasedBoss.ts +34 -0
  563. package/src/sharddev/physics.ts +194 -0
  564. package/src/sharddev/platformSections.ts +42 -0
  565. package/src/sharddev/plumbing.ts +8 -0
  566. package/src/sharddev/productOutput.ts +128 -0
  567. package/src/sharddev/project.ts +337 -0
  568. package/src/sharddev/projectCompilerIdentity.ts +94 -0
  569. package/src/sharddev/projectDecisions.ts +66 -0
  570. package/src/sharddev/projectEntryProof.ts +32 -0
  571. package/src/sharddev/projectGeneration.ts +219 -0
  572. package/src/sharddev/projectInputFiles.ts +47 -0
  573. package/src/sharddev/projectManifest.ts +108 -0
  574. package/src/sharddev/projectMap.ts +35 -0
  575. package/src/sharddev/projectOutput.ts +242 -0
  576. package/src/sharddev/projectPolicy.ts +17 -0
  577. package/src/sharddev/projectSections.ts +27 -0
  578. package/src/sharddev/questGraph.ts +25 -0
  579. package/src/sharddev/quests.ts +65 -0
  580. package/src/sharddev/random.ts +61 -0
  581. package/src/sharddev/refusals.ts +304 -0
  582. package/src/sharddev/reportCard.ts +13 -0
  583. package/src/sharddev/returnProjectionV2.ts +81 -0
  584. package/src/sharddev/rows.ts +192 -0
  585. package/src/sharddev/runtimeImports.ts +38 -0
  586. package/src/sharddev/runtimeMirrors.ts +39 -0
  587. package/src/sharddev/runtimePerformance.ts +38 -0
  588. package/src/sharddev/scene.ts +321 -0
  589. package/src/sharddev/sceneAnimation.ts +54 -0
  590. package/src/sharddev/sceneAudio.ts +64 -0
  591. package/src/sharddev/sceneDeclarations.ts +100 -0
  592. package/src/sharddev/sceneGraph.ts +139 -0
  593. package/src/sharddev/sceneTransform.ts +12 -0
  594. package/src/sharddev/schemaValidation.ts +61 -0
  595. package/src/sharddev/sections.ts +47 -0
  596. package/src/sharddev/shardSource.ts +59 -0
  597. package/src/sharddev/sourceReader.ts +26 -0
  598. package/src/sharddev/spawns.ts +38 -0
  599. package/src/sharddev/species/clips.ts +24 -0
  600. package/src/sharddev/species.ts +29 -0
  601. package/src/sharddev/speciesBrains.ts +19 -0
  602. package/src/sharddev/synth.ts +66 -0
  603. package/src/sharddev/test/compileDualScriptV2.ts +71 -0
  604. package/src/sharddev/test/compileSimV2.ts +21 -0
  605. package/src/sharddev/test/diskScriptScenario.ts +86 -0
  606. package/src/sharddev/test/scriptScenario.ts +249 -0
  607. package/src/sharddev/test/scriptSource.ts +12 -0
  608. package/src/sharddev/version.ts +4 -0
  609. package/src/sharddev/weapons/bowProfile.ts +20 -0
  610. package/src/sharddev/weapons/firearmRows.ts +11 -0
  611. package/src/sharddev/weapons/meleeProfile.ts +71 -0
  612. package/src/sharddev/weapons/thrownProfile.ts +10 -0
  613. package/src/sharddev/worldScenes.ts +308 -0
  614. package/src/sharddev/worldSource.ts +82 -0
  615. package/src/shards/_template/README.md +78 -0
  616. package/src/shards/_template/assets/2bf489fdb15f1734ddb4c4f32d500ec6da85c765ec7a4eb28dc6781160e7ec8c +0 -0
  617. package/src/shards/_template/assets/97ec4d8f75f5fa6239ee919444d6dc19fd35896bb305930c1f050ac6e0e0e6a6 +1 -0
  618. package/src/shards/_template/assets/a6a587a31327f936b1b04c05ade818c73fc8964260918662db43539465e27586 +0 -0
  619. package/src/shards/_template/assets/b4fbde0422e125b498c3dc8b9a5cc2516c8598f09e9d0e5f6b639b32f98179e6 +0 -0
  620. package/src/shards/_template/assets/bfa4dfc9c18979f904557ee8deab0058b8a399be10266f5fb1578b403f482fd4 +1 -0
  621. package/src/shards/_template/assets/ef3b7ff4fd22715771cb7d68a3977a903c5e7c3dc293542687d04b3ef3ace2cb +0 -0
  622. package/src/shards/_template/assets/f2db05998615ce1cb79ea96be32c168842eb6a2b34ec01feb86d36404603ee54 +0 -0
  623. package/src/shards/_template/assets/fef98ebb7fce6f66b26e78ac699e5c90f9bdcfaf8cabeb2b58125347eea8b4ab +0 -0
  624. package/src/shards/_template/behaviour/boss.as +39 -0
  625. package/src/shards/_template/behaviour/door.as +32 -0
  626. package/src/shards/_template/behaviour/hooks.json +129 -0
  627. package/src/shards/_template/behaviour/idle.as +75 -0
  628. package/src/shards/_template/behaviour/items.as +22 -0
  629. package/src/shards/_template/card/landscape.jpg +0 -0
  630. package/src/shards/_template/card/portrait.jpg +0 -0
  631. package/src/shards/_template/card/thumb.jpg +0 -0
  632. package/src/shards/_template/data/audio.json +45 -0
  633. package/src/shards/_template/data/bossDecision.json +83 -0
  634. package/src/shards/_template/data/budgets.json +70 -0
  635. package/src/shards/_template/data/card.json +281 -0
  636. package/src/shards/_template/data/clientScripts.json +987 -0
  637. package/src/shards/_template/data/creatures.json +65 -0
  638. package/src/shards/_template/data/director.json +39 -0
  639. package/src/shards/_template/data/encounters.json +96 -0
  640. package/src/shards/_template/data/items.json +172 -0
  641. package/src/shards/_template/data/layout.json +66 -0
  642. package/src/shards/_template/data/ledger.json +32 -0
  643. package/src/shards/_template/data/look.json +521 -0
  644. package/src/shards/_template/data/map.json +64 -0
  645. package/src/shards/_template/data/moves.json +16 -0
  646. package/src/shards/_template/data/placeholder.json +8 -0
  647. package/src/shards/_template/data/plumbing.json +32 -0
  648. package/src/shards/_template/data/quests.json +223 -0
  649. package/src/shards/_template/data/rows.json +423 -0
  650. package/src/shards/_template/data/skins.json +66 -0
  651. package/src/shards/_template/data/spawn.json +6 -0
  652. package/src/shards/_template/data/targets.json +150 -0
  653. package/src/shards/_template/data/text.json +12 -0
  654. package/src/shards/_template/data/ui.json +33 -0
  655. package/src/shards/_template/data/water.json +13 -0
  656. package/src/shards/_template/generators/behaviour.ts +34 -0
  657. package/src/shards/_template/generators/boss.ts +29 -0
  658. package/src/shards/_template/generators/buildOptions.ts +2 -0
  659. package/src/shards/_template/generators/cell.ts +224 -0
  660. package/src/shards/_template/generators/districts.ts +215 -0
  661. package/src/shards/_template/generators/farLook.ts +15 -0
  662. package/src/shards/_template/generators/generate.ts +27 -0
  663. package/src/shards/_template/generators/ground.ts +15 -0
  664. package/src/shards/_template/generators/kit.ts +69 -0
  665. package/src/shards/_template/generators/landscape.ts +59 -0
  666. package/src/shards/_template/generators/landscapeNoise.ts +62 -0
  667. package/src/shards/_template/generators/mapInputs.ts +10 -0
  668. package/src/shards/_template/generators/product.ts +100 -0
  669. package/src/shards/_template/generators/productOutput.ts +18 -0
  670. package/src/shards/_template/generators/props.ts +9 -0
  671. package/src/shards/_template/generators/templatePropsSource.ts +58 -0
  672. package/src/shards/_template/generators/terrain.ts +17 -0
  673. package/src/shards/_template/generators/world.ts +630 -0
  674. package/src/shards/_template/hero.json +10 -0
  675. package/src/shards/_template/look/entry-reads.json +20 -0
  676. package/src/shards/_template/manifest.json +281 -0
  677. package/src/shards/_template/shard.config.ts +10 -0
  678. package/src/shared/health.ts +10 -0
  679. package/src/tools/build-web.ts +59 -0
  680. package/src/tsconfig.json +30 -0
  681. package/src/web/app.tsx +53 -0
  682. package/src/web/index.html +12 -0
  683. package/src/web/main.tsx +10 -0
  684. package/src/web/tsconfig.json +13 -0
  685. package/tsconfig.author.json +23 -0
  686. package/tsconfig.commons.json +21 -0
  687. package/tsconfig.json +47 -0
  688. package/tsconfig.sharddev.json +20 -0
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+ // S4 (SHARD-SIZE-PLAN, E450 B1): Pine's phone building and cabin prop sets at 512. A KTX2 holds its whole mip chain, so a
3
+ // 512 set is the 1024 file less its top level: the same blocks, no re-encode. Only an actual smaller file saves download
4
+ // bytes; `maxSize` at load only skips a mip that was already fetched.
5
+ //
6
+ // What: each row of src/shards/pine-hollow/data/astc6.generated.json under a set in data/astc6Cap.json, wider than `max`,
7
+ // and no #layer twin (a texture array keeps its layers' size); a GLB's embedded 6×6 images likewise. The table is
8
+ // repointed, each .gltf that names a capped file is rewritten, and the 1024 file goes. Idempotent; scripts/bake-astc6.mjs
9
+ // runs it after a full bake.
10
+ //
11
+ // node scripts/astc6-phone-cap.mjs
12
+ import { createHash } from 'node:crypto';
13
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
14
+ import { basename, dirname, join, posix, resolve } from 'node:path';
15
+ import { pathToFileURL } from 'node:url';
16
+
17
+ const HEADER = 48, INDEX = 32, LEVEL = 24;
18
+
19
+ /** A KTX2 without its top mip: every level below keeps its bytes, and the header says the file is half the size.
20
+ * @param {Uint8Array} input @returns {Uint8Array} */
21
+ export function dropTopMip(input) {
22
+ const source = Buffer.from(input), levels = source.readUInt32LE(40), scheme = source.readUInt32LE(44);
23
+ if (source.toString('latin1', 1, 7) !== 'KTX 20' || levels < 2 || scheme === 1) throw new Error('A top mip drop needs a KTX2 with a mip chain and per-level data');
24
+ const dfdAt = source.readUInt32LE(48), dfdBytes = source.readUInt32LE(52), kvdAt = source.readUInt32LE(56), kvdBytes = source.readUInt32LE(60);
25
+ const sgdAt = Number(source.readBigUInt64LE(64)), sgdBytes = Number(source.readBigUInt64LE(72));
26
+ const rows = Array.from({ length: levels }, (_, level) => { const at = HEADER + INDEX + level * LEVEL;
27
+ return { level, offset: Number(source.readBigUInt64LE(at)), bytes: Number(source.readBigUInt64LE(at + 8)), raw: source.readBigUInt64LE(at + 16) }; });
28
+ const kept = rows.slice(1), pad = (at, to) => (to - at % to) % to, tableEnd = HEADER + INDEX + kept.length * LEVEL, pieces = [];
29
+ let at = tableEnd;
30
+ const put = (bytes, align = 1) => { const fill = pad(at, align); if (fill > 0) { pieces.push(Buffer.alloc(fill)); at += fill; } const start = at; pieces.push(bytes); at += bytes.length; return start; };
31
+ const dfd = put(source.subarray(dfdAt, dfdAt + dfdBytes), 4), kvd = kvdBytes === 0 ? 0 : put(source.subarray(kvdAt, kvdAt + kvdBytes), 4), sgd = sgdBytes === 0 ? 0 : put(source.subarray(sgdAt, sgdAt + sgdBytes), 8);
32
+ // A level's alignment: none under supercompression, a block otherwise. Levels stay in the file's order, smallest first.
33
+ for (const row of [...kept].sort((left, right) => left.offset - right.offset)) row.placed = put(source.subarray(row.offset, row.offset + row.bytes), scheme === 0 ? 16 : 1);
34
+ const head = Buffer.alloc(tableEnd);
35
+ source.copy(head, 0, 0, HEADER);
36
+ head.writeUInt32LE(Math.max(1, source.readUInt32LE(20) >> 1), 20); head.writeUInt32LE(source.readUInt32LE(24) >> 1, 24); head.writeUInt32LE(levels - 1, 40);
37
+ head.writeUInt32LE(dfd, 48); head.writeUInt32LE(dfdBytes, 52); head.writeUInt32LE(kvd, 56); head.writeUInt32LE(kvdBytes, 60);
38
+ head.writeBigUInt64LE(BigInt(sgd), 64); head.writeBigUInt64LE(BigInt(sgdBytes), 72);
39
+ kept.forEach((row, index) => { const entry = HEADER + INDEX + index * LEVEL;
40
+ head.writeBigUInt64LE(BigInt(row.placed), entry); head.writeBigUInt64LE(BigInt(row.bytes), entry + 8); head.writeBigUInt64LE(row.raw, entry + 16); });
41
+ return Buffer.concat([head, ...pieces]);
42
+ }
43
+
44
+ // GLB parts: what bake-ktx2.mjs and bake-astc6.mjs read and write.
45
+ export function readGlb(path) {
46
+ const b = Buffer.isBuffer(path) ? path : readFileSync(path);
47
+ if (b.readUInt32LE(0) !== 0x46546c67) throw new Error(`${path}: not a GLB`);
48
+ const jsonLen = b.readUInt32LE(12);
49
+ const json = JSON.parse(b.subarray(20, 20 + jsonLen).toString('utf8'));
50
+ const binStart = 20 + jsonLen + 8;
51
+ return { json, bin: b.subarray(binStart, binStart + b.readUInt32LE(20 + jsonLen)) };
52
+ }
53
+ export const imageBytes = (json, bin, view) => { const v = json.bufferViews[view]; return bin.subarray(v.byteOffset ?? 0, (v.byteOffset ?? 0) + v.byteLength); };
54
+ export function glbBytes(json, bin, swap) {
55
+ const ranges = [];
56
+ for (const [i, v] of json.bufferViews.entries()) {
57
+ if ((v.buffer ?? 0) === 0) ranges.push({ holder: v, off: v.byteOffset ?? 0, len: v.byteLength, data: swap.get(i) });
58
+ const m = v.extensions?.EXT_meshopt_compression;
59
+ if (m && (m.buffer ?? 0) === 0) ranges.push({ holder: m, off: m.byteOffset ?? 0, len: m.byteLength, data: undefined });
60
+ }
61
+ ranges.sort((a, b) => a.off - b.off);
62
+ const parts = []; const placed = new Map(); let at = 0;
63
+ for (const r of ranges) {
64
+ const key = `${r.off}:${r.len}`;
65
+ let where = placed.get(key);
66
+ if (where === undefined || r.data !== undefined) {
67
+ const bytes = r.data ?? bin.subarray(r.off, r.off + r.len);
68
+ const pad = (4 - (at % 4)) % 4; if (pad > 0) { parts.push(Buffer.alloc(pad)); at += pad; }
69
+ where = at; parts.push(bytes); at += bytes.length;
70
+ if (r.data === undefined) placed.set(key, where);
71
+ }
72
+ r.holder.byteOffset = where;
73
+ r.holder.byteLength = r.data?.length ?? r.len;
74
+ }
75
+ const pad = (4 - (at % 4)) % 4; if (pad > 0) { parts.push(Buffer.alloc(pad)); at += pad; }
76
+ json.buffers[0].byteLength = at;
77
+ const out = Buffer.concat(parts);
78
+ let jb = Buffer.from(JSON.stringify(json), 'utf8');
79
+ jb = Buffer.concat([jb, Buffer.alloc((4 - (jb.length % 4)) % 4, 0x20)]);
80
+ const header = Buffer.alloc(12); header.writeUInt32LE(0x46546c67, 0); header.writeUInt32LE(2, 4);
81
+ const jh = Buffer.alloc(8); jh.writeUInt32LE(jb.length, 0); jh.writeUInt32LE(0x4e4f534a, 4);
82
+ const bh = Buffer.alloc(8); bh.writeUInt32LE(out.length, 0); bh.writeUInt32LE(0x004e4942, 4);
83
+ header.writeUInt32LE(12 + 8 + jb.length + 8 + out.length, 8);
84
+ return Buffer.concat([header, jh, jb, bh, out]);
85
+ }
86
+
87
+ /** A GLB with each embedded 6×6 image at `max`. An ETC1S plane keeps its size: its levels share one global codebook.
88
+ * @param {Buffer} input @param {number} max the new bytes, or null if no image changed */
89
+ export function capGlbImages(input, max) {
90
+ const { json, bin } = readGlb(input), swap = new Map();
91
+ for (const image of json.images ?? []) {
92
+ if (image.bufferView === undefined) continue;
93
+ let bytes = Buffer.from(imageBytes(json, bin, image.bufferView));
94
+ if (bytes.toString('latin1', 1, 7) !== 'KTX 20' || bytes.readUInt32LE(44) === 1) continue;
95
+ while (bytes.readUInt32LE(20) > max) bytes = Buffer.from(dropTopMip(bytes));
96
+ if (bytes.length !== json.bufferViews[image.bufferView].byteLength) swap.set(image.bufferView, bytes);
97
+ }
98
+ return swap.size === 0 ? null : glbBytes(json, bin, swap);
99
+ }
100
+
101
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
102
+ const root = resolve(import.meta.dirname, '..'), pub = url => join(root, 'public', url), tableFile = join(root, 'src/shards/pine-hollow/data/astc6.generated.json');
103
+ const { max, sets } = JSON.parse(readFileSync(join(root, 'src/shards/pine-hollow/data/astc6Cap.json'), 'utf8'));
104
+ const table = JSON.parse(readFileSync(tableFile, 'utf8')), moved = new Map();
105
+ const named = (url, bytes, ext) => posix.join(posix.dirname(url), `${basename(url).replace(/-[0-9a-f]{8}\.[a-z0-9]+$/u, '')}-${createHash('sha256').update(bytes).digest('hex').slice(0, 8)}.${ext}`);
106
+ const write = (url, bytes) => { mkdirSync(dirname(pub(url)), { recursive: true }); writeFileSync(pub(url), bytes); };
107
+ for (const [served, url] of Object.entries(table)) {
108
+ if (served.endsWith('#layer') || !sets.some(set => served.startsWith(set))) continue;
109
+ if (url.endsWith('.glb')) {
110
+ const bytes = capGlbImages(readFileSync(pub(url)), max);
111
+ if (bytes !== null) { const next = named(url, bytes, 'glb'); write(next, bytes); table[served] = next; moved.set(url, next); }
112
+ continue;
113
+ }
114
+ if (!url.endsWith('.ktx2')) continue;
115
+ let bytes = readFileSync(pub(url)), changed = false;
116
+ while (bytes.readUInt32LE(20) > max) { bytes = dropTopMip(bytes); changed = true; }
117
+ if (!changed) continue;
118
+ const next = named(url, bytes, 'ktx2');
119
+ write(next, bytes); table[served] = next; moved.set(url, next);
120
+ }
121
+ // A .gltf names its textures relative to its own source folder, as bake-astc6.mjs writes them.
122
+ for (const [served, url] of Object.entries(table)) {
123
+ if (!url.endsWith('.gltf')) continue;
124
+ const doc = JSON.parse(readFileSync(pub(url), 'utf8')), folder = posix.dirname(served); let changed = false;
125
+ for (const image of doc.images ?? []) {
126
+ const next = moved.get(posix.join(folder, decodeURI(image.uri)));
127
+ if (next !== undefined) { image.uri = posix.relative(folder, next); changed = true; }
128
+ }
129
+ if (!changed) continue;
130
+ const bytes = Buffer.from(JSON.stringify(doc)), next = named(url, bytes, 'gltf');
131
+ write(next, bytes); table[served] = next; moved.set(url, next);
132
+ }
133
+ for (const url of moved.keys()) rmSync(pub(url));
134
+ writeFileSync(tableFile, `${JSON.stringify(table, null, 2)}\n`);
135
+ console.log(`astc6-phone-cap: ${moved.size} files moved`);
136
+ console.log(JSON.stringify(Object.fromEntries(moved)));
137
+ }
@@ -0,0 +1,10 @@
1
+ export interface InventoryRow {
2
+ slug: string; tier: string; files: readonly string[]; packFiles: readonly string[];
3
+ packed: readonly string[]; gpu: Readonly<Record<string, string>>; ktxFiles: readonly string[];
4
+ }
5
+ export function auditInventory(rows: readonly InventoryRow[], exists: (url: string) => boolean): string[];
6
+
7
+ export interface TextureReference { url: string; referencedBy: string[] }
8
+ export interface TextureSource { path: string; text: string }
9
+ export function auditTextureReferences(files: readonly string[], rows: readonly InventoryRow[], sources: readonly TextureSource[]): TextureReference[];
10
+ export function textureSources(root: string): TextureSource[];
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env node
2
+ // E357 X3 / T3: validate authored inventories; report unused originals without removing them.
3
+ import { execFileSync } from 'node:child_process';
4
+ import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
5
+ import { dirname, resolve, relative, posix } from 'node:path';
6
+ import { textureTierJobs } from '@wildshard/engine/scripts/texture-inputs.mjs';
7
+ import { pathToFileURL } from 'node:url';
8
+
9
+ export function auditInventory(rows, exists) {
10
+ const errors = [];
11
+ for (const row of rows) {
12
+ const packed = new Set(row.packed);
13
+ for (const file of row.files) if (!exists(file)) errors.push(`${row.slug}/${row.tier}: missing declared file ${file}`);
14
+ for (const file of row.packFiles) if (!packed.has(file)) errors.push(`${row.slug}/${row.tier}: file absent from pack ${file}`);
15
+ for (const file of packed) if (!row.packFiles.includes(file)) errors.push(`${row.slug}/${row.tier}: orphan pack member ${file}`);
16
+ for (const [source, target] of Object.entries(row.gpu)) if (!exists(target)) errors.push(`${row.slug}/${row.tier}: missing GPU stand-in ${source} -> ${target}`);
17
+ for (const file of row.ktxFiles) if (!exists(file)) errors.push(`${row.slug}/${row.tier}: missing KTX2-mode file ${file}`);
18
+ }
19
+ return errors;
20
+ }
21
+
22
+ /** Conservative deletion check: inventories include image fallbacks and GPU source keys, not just served URLs. */
23
+ export function auditTextureReferences(files, rows, sources) {
24
+ const reasons = new Map(files.map((url) => [url, new Set()]));
25
+ const clean = (url) => url.split(/[?#]/)[0];
26
+ const add = (url, why) => reasons.get(clean(url))?.add(why);
27
+ for (const row of rows) {
28
+ const why = `${row.slug}/${row.tier}`;
29
+ for (const url of [...row.files, ...row.ktxFiles, ...row.packFiles]) add(url, `inventory: ${why}`);
30
+ for (const [source, target] of Object.entries(row.gpu)) { add(source, `GPU source: ${why}`); add(target, `GPU target: ${why}`); }
31
+ }
32
+ // Exactly the jobs tex-tiers runs: original sources, selected _1k inputs, and cached output files it verifies.
33
+ for (const job of textureTierJobs(files.map((url) => `public${url}`))) {
34
+ for (const path of new Set([job.source, job.served, job.output])) add(path.slice(6), `scripts/tex-tiers.mjs: ${job.kind} input/cache (${job.source})`);
35
+ }
36
+ for (const url of files) {
37
+ const folder = posix.dirname(url);
38
+ const set = posix.basename(folder);
39
+ const filename = posix.basename(url);
40
+ const stem = filename.split('.')[0];
41
+ for (const source of sources) {
42
+ // Keep named folders too: Blender inputs and interpolated generator paths read their contents.
43
+ if (source.text.includes(url) || source.text.includes(folder) ||
44
+ (source.text.includes(set) && (source.text.includes(filename) || source.text.includes(stem)))) add(url, `source: ${source.path}`);
45
+ }
46
+ }
47
+ return files.map((url) => ({ url, referencedBy: [...(reasons.get(url) ?? [])].sort((a, b) => a.localeCompare(b)) }));
48
+ }
49
+
50
+ /** Generated byte indexes are file catalogues, not uses. Authored GPU tables and generator inputs are uses. */
51
+ export function textureSources(root) {
52
+ const sources = [];
53
+ const walk = (dir) => {
54
+ if (!existsSync(dir)) return;
55
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
56
+ const path = resolve(dir, entry.name);
57
+ if (entry.isDirectory()) walk(path);
58
+ else if (/\.(ts|tsx|js|mjs|cjs|py|sh|json|html|css|glsl)$/.test(entry.name) &&
59
+ (!entry.name.includes('.generated.') || entry.name === 'ktx2.generated.ts') &&
60
+ !['audit-assets.mjs', 'unused-assets.mjs', 'texture-inputs.mjs'].includes(entry.name)) sources.push({ path: relative(root, path), text: readFileSync(path, 'utf8') });
61
+ }
62
+ };
63
+ for (const dir of ['src', 'scripts', 'vite']) walk(resolve(root, dir));
64
+ return sources;
65
+ }
66
+
67
+ const root = resolve(import.meta.dirname, '..');
68
+ const tier = process.argv.find((arg) => arg.startsWith('--collect='))?.slice(10);
69
+ if (tier) {
70
+ if (tier !== 'phone' && tier !== 'desktop') throw new Error(`audit-assets: unknown tier ${tier}`);
71
+ const { initializeTier } = await import('@wildshard/engine/core/tier'); initializeTier(tier);
72
+ const { SHARDS } = await import('../src/shards.generated.ts');
73
+ const { PACKS } = await import('@wildshard/engine/game/boot/packs.generated');
74
+ const { GPU_FILES: shared } = await import('@wildshard/engine/boot/ktx2.generated');
75
+ const { prepareShardAssets } = await import('@wildshard/engine/game/shard/load');
76
+ const { registerGpuFiles, autoTexturePolicy } = await import('@wildshard/engine/boot/gpuFiles');
77
+ const { imagesFirstPlayingBytes } = await import('@wildshard/engine/game/grid/runtimeCost');
78
+ const { bootFileList, bootSourceFiles, bootLateReads } = await import('@wildshard/engine/boot/filePolicy');
79
+ const { chunkFiles } = await import('@wildshard/engine/boot/manifest');
80
+ const { resolveBootAudio } = await import('@wildshard/engine/boot/audioInventory');
81
+ const { productAudioInventory } = await import('@wildshard/engine/scripts/app-build/audioPacks.ts');
82
+ const { bootFetches } = await import('@wildshard/engine/boot/prefetch');
83
+ // Match the pack baker and cold boot: install shard overlays before resolving the same Auto policy and file source.
84
+ await Promise.all(SHARDS.map((manifest) => prepareShardAssets(manifest, registerGpuFiles)));
85
+ const rows = [];
86
+ for (const manifest of SHARDS) {
87
+ if (manifest.status === 'hidden') continue;
88
+ const boot = manifest.boot;
89
+ if (!boot?.sources) throw new Error(`audit-assets: ${manifest.slug} has no authored boot.sources`);
90
+ // A function loads the product from the page's origin; this process has neither, so read the build output.
91
+ const audio = typeof boot.audio === 'function' ? await productAudioInventory(root, manifest.slug) : await resolveBootAudio(boot);
92
+ const art = boot.explore?.art ?? [];
93
+ const shown = [];
94
+ const pictures = (value) => {
95
+ if (typeof value === 'string' && /^\/(src|assets)\/.+\.(jpe?g|png|webp)$/.test(value)) shown.push(value);
96
+ else if (value !== null && typeof value === 'object') for (const child of Object.values(value)) pictures(child);
97
+ };
98
+ pictures(manifest.explore);
99
+ for (const image of shown) if (!art.includes(image)) throw new Error(`${manifest.slug}: Explore image absent from boot.explore.art: ${image}`);
100
+ const table = manifest.ktx2 ? (await manifest.ktx2()).GPU_FILES[tier] : {};
101
+ const gpu = { ...shared[tier], ...table };
102
+ const img = bootSourceFiles(boot.sources, tier, 'img'), ktx = bootSourceFiles(boot.sources, tier, 'ktx2');
103
+ const mode = autoTexturePolicy(manifest.tiers?.[tier]?.textures, imagesFirstPlayingBytes(manifest.runtimeCost))?.mode ?? 'img';
104
+ const packFiles = bootFetches(manifest, chunkFiles(manifest, mode));
105
+ const pack = Object.hasOwn(PACKS, manifest.slug) ? PACKS[manifest.slug]?.[tier] : undefined;
106
+ const packed = pack === undefined ? [] : pack.files.map(([path]) => path);
107
+ rows.push({ slug: manifest.slug, tier, files: [...new Set([...bootFileList(boot.files, tier), ...Object.values(img).flat(), ...bootLateReads(boot.lateReads, tier, 'img'), ...(boot.precache ?? []), ...art, ...Object.values(manifest.card).filter((value) => typeof value === 'string' && value.startsWith('/src/')), ...audio])], packFiles: [...new Set(packFiles)], packed, gpu, ktxFiles: [...new Set([...Object.values(ktx).flat(), ...bootLateReads(boot.lateReads, tier, 'ktx2')])] });
108
+ }
109
+ process.stdout.write(JSON.stringify(rows));
110
+ } else if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
111
+ try {
112
+ const rows = ['phone', 'desktop'].flatMap((value) => JSON.parse(execFileSync(process.execPath, ['--experimental-transform-types', '--import', './scripts/bake-loader.mjs', 'scripts/audit-assets.mjs', `--collect=${value}`], { cwd: root, encoding: 'utf8' })));
113
+ const publicFile = (url) => resolve(root, url.startsWith('/src/') ? '.' : 'public', `.${url.split('#')[0]}`);
114
+ const errors = auditInventory(rows, (url) => existsSync(publicFile(url)));
115
+ // Licenced audio has its attribution beside its inventory. CC0/procedural art needs no credit row.
116
+ const credits = [];
117
+ for (const kind of ['music', 'sfx']) {
118
+ const dir = resolve(root, 'public/assets', kind);
119
+ for (const set of readdirSync(dir)) {
120
+ const path = resolve(dir, set, `${kind}.json`); if (!existsSync(path)) continue;
121
+ const text = readFileSync(path, 'utf8'), manifest = JSON.parse(text);
122
+ const required = kind === 'music' && /MiniMax/i.test(text) ? 'MiniMax-Music3' : kind === 'sfx' && /Stable Audio|Stability AI/i.test(text) ? 'Powered by Stability AI' : null;
123
+ if (required && (typeof manifest.credit !== 'string' || !manifest.credit.includes(required))) errors.push(`${kind}/${set}: missing required credit ${required}`);
124
+ credits.push({ set: `${kind}/${set}`, credit: manifest.credit ?? null, required });
125
+ }
126
+ }
127
+ const originals = [];
128
+ const texRoot = resolve(root, 'public/assets/tex');
129
+ const walk = (dir) => {
130
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
131
+ const path = resolve(dir, entry.name);
132
+ if (entry.isDirectory()) walk(path);
133
+ else {
134
+ const url = `/${path.slice(resolve(root, 'public').length + 1)}`;
135
+ originals.push({ url, bytes: statSync(path).size, referencedBy: rows.filter((row) => row.files.includes(url)).map((row) => `${row.slug}/${row.tier}`), gpu: Object.fromEntries(rows.map((row) => [`${row.slug}/${row.tier}`, row.gpu[url] ?? row.gpu[`${url}#layer`] ?? null]).filter(([, value]) => value !== null)) });
136
+ }
137
+ }
138
+ };
139
+ walk(texRoot);
140
+ const references = auditTextureReferences(originals.map((row) => row.url), rows, textureSources(root));
141
+ for (const row of originals) row.referencedBy = references.find((reference) => reference.url === row.url)?.referencedBy ?? [];
142
+ const unreferenced = originals.filter((row) => row.referencedBy.length === 0);
143
+ const report = { errors, inventories: rows, credits, originals, unreferencedOriginals: unreferenced, unreferencedBytes: unreferenced.reduce((sum, row) => sum + row.bytes, 0), note: 'Deletion candidates exclude runtime/image/phone inventories, GPU source keys, shared tex-tiers input/cache jobs and authored src/scripts references. Conservative source-folder matches are retained; no automatic deletions.' };
144
+ const out = process.argv.find((arg) => arg.startsWith('--out='))?.slice(6);
145
+ if (out) { if (!existsSync(dirname(out))) throw new Error(`audit-assets: output directory does not exist: ${dirname(out)}`); writeFileSync(out, `${JSON.stringify(report, null, 2)}\n`); }
146
+ for (const row of rows) console.log(`${row.slug}/${row.tier}: ${row.files.length} declared, ${row.packed.length} packed, ${row.ktxFiles.length} KTX2-mode files`);
147
+ console.log(`T3: ${originals.length} original texture files; ${unreferenced.length} without runtime or generator references (${(report.unreferencedBytes / 1048576).toFixed(2)} MiB). No deletions.`);
148
+ for (const error of errors) console.error(`audit-assets: ${error}`);
149
+ if (errors.length > 0) process.exitCode = 1;
150
+ } catch (error) { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; }
151
+ }
@@ -0,0 +1,6 @@
1
+ /** Lossless bytes paired with their unchanged coat-table identity. */
2
+ export interface CoatFileBytes { readonly url: string; readonly png: Uint8Array }
3
+ /** Write ordered PNG files and publish a path-only manifest last. */
4
+ export function writeCoatFiles(manifest: string, coats: readonly CoatFileBytes[]): void;
5
+ /** Read the same owned PNG bytes; encoded payloads and escaped paths refuse. */
6
+ export function readCoatFiles(manifest: string): CoatFileBytes[];
@@ -0,0 +1,37 @@
1
+ import { mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
2
+ import { basename, dirname, resolve } from 'node:path';
3
+ import { jsonOutputGuard } from '@wildshard/engine/scripts/json-output-guard.mjs';
4
+
5
+ /** Keep PNG bytes outside JSON during the native painter's process handoff.
6
+ * @param {string} manifest
7
+ * @param {ReadonlyArray<{readonly url:string;readonly png:Uint8Array}>} coats */
8
+ export function writeCoatFiles(manifest, coats) {
9
+ const directory = `${basename(manifest)}.pngs`;
10
+ mkdirSync(resolve(dirname(manifest), directory), { recursive: true });
11
+ const rows = coats.map((coat, index) => {
12
+ const png = `${directory}/${index}.png`;
13
+ writeFileSync(resolve(dirname(manifest), png), coat.png);
14
+ return { url: coat.url, png };
15
+ });
16
+ const wire = JSON.stringify(rows);
17
+ jsonOutputGuard(dirname(manifest))(manifest, wire);
18
+ writeFileSync(manifest, wire);
19
+ }
20
+
21
+ /** Read only the exact ordered files owned by this handoff, never an encoded
22
+ * fallback or a path outside its scratch directory.
23
+ * @param {string} manifest */
24
+ export function readCoatFiles(manifest) {
25
+ /** @type {unknown} */
26
+ const input = JSON.parse(readFileSync(manifest, 'utf8'));
27
+ if (!Array.isArray(input)) throw new Error('Invalid coat file manifest');
28
+ const root = realpathSync(dirname(manifest));
29
+ return input.map((/** @type {unknown} */ row, index) => {
30
+ if (typeof row !== 'object' || row === null || Object.keys(row).length !== 2
31
+ || !('url' in row) || typeof row.url !== 'string' || !('png' in row)
32
+ || row.png !== `${basename(manifest)}.pngs/${index}.png`) throw new Error('Invalid coat file manifest');
33
+ const file = resolve(root, row.png);
34
+ if (realpathSync(file) !== file) throw new Error('Coat file escapes its handoff');
35
+ return { url: row.url, png: readFileSync(file) };
36
+ });
37
+ }
@@ -0,0 +1,2 @@
1
+ /** The same non-drawing DOM and public/file fetch adapter used by the navmesh CLI; no installation on import. */
2
+ export function installBakeEnvironment(root: string): { element: () => HTMLElement; dispose: () => void };
@@ -0,0 +1,58 @@
1
+ // The existing native-bake DOM/fetch adapter. Import is inert; one owned CLI installs it explicitly.
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { relative, resolve, isAbsolute } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ const noop = () => undefined;
7
+ let active = false;
8
+ /** Install the navmesh baker's non-drawing environment once, returning its element factory and owned cleanup. */
9
+ export function installBakeEnvironment(ROOT) {
10
+ if (active) throw new Error('A bake environment is already installed');
11
+ const names = ['location', 'self', 'document', 'window', 'Request', 'fetch', 'createImageBitmap', 'ProgressEvent', 'navigator'];
12
+ const previous = new Map(names.map(name => [name, Object.getOwnPropertyDescriptor(globalThis, name)]));
13
+ const ctx2d = new Proxy({}, { get: (_t, k) => k === 'createImageData' || k === 'getImageData' ? (w = 1, h = 1) => ({ data: new Uint8ClampedArray(4 * w * h), width: w, height: h }) : k === 'createLinearGradient' || k === 'createRadialGradient' || k === 'createPattern' ? () => ({ addColorStop: noop }) : k === 'measureText' ? () => ({ width: 1 }) : noop, set: () => true });
14
+ const el = () => { const listeners = new Map(); return ({ width: 1, height: 1, style: {}, classList: { add: noop, remove: noop, toggle: noop, contains: () => false }, dataset: {},
15
+ getContext: () => ctx2d, append: noop, appendChild: noop, remove: noop, insertBefore: noop, setAttribute: noop, addEventListener: (type, fn) => { listeners.set(type, fn); }, removeEventListener: (type) => { listeners.delete(type); },
16
+ get src() { return ''; },
17
+ set src(_value) { queueMicrotask(() => { listeners.get('load')?.call(this); }); },
18
+ querySelector: () => el(), querySelectorAll: () => [], parentNode: null, textContent: '', innerHTML: '' }); };
19
+ const HOST = 'http://localhost/';
20
+ const NodeRequest = globalThis.Request, nodeFetch = globalThis.fetch;
21
+ Object.assign(globalThis, {
22
+ location: new URL(HOST), self: globalThis,
23
+ document: { createElement: el, createElementNS: el, getElementById: () => null, fonts: { load: () => Promise.resolve([]) }, head: el(), body: el(), addEventListener: noop, removeEventListener: noop, querySelector: () => null, querySelectorAll: () => [], pointerLockElement: null },
24
+ window: { setTimeout, clearTimeout, addEventListener: noop, removeEventListener: noop, devicePixelRatio: 1, innerWidth: 1600, innerHeight: 900, matchMedia: () => ({ matches: false, addEventListener: noop }), location: new URL(HOST) },
25
+ // three's loaders build Requests from site-relative URLs
26
+ Request: class extends NodeRequest { constructor(input, init) { super(typeof input === 'string' ? new URL(input, HOST).href : input, init); } },
27
+ fetch: (input, init) => {
28
+ const url = new URL(typeof input === 'string' ? input : input instanceof URL ? input.href : input.url, HOST);
29
+ // a module's own asset (`new URL('../assets/…', import.meta.url)`, a shard's declared mover scripts): the file itself
30
+ if (url.protocol === 'file:') { const file = fileURLToPath(url); return Promise.resolve(existsSync(file) ? new Response(readFileSync(file)) : new Response(null, { status: 404 })); }
31
+ if (url.origin !== new URL(HOST).origin) return nodeFetch(input, init);
32
+ // Vite's ?url loader names generated source assets under /src/; keep
33
+ // their exact bytes available to the native world and its own admission.
34
+ const pathname = decodeURIComponent(url.pathname);
35
+ const base = resolve(ROOT, pathname.startsWith('/src/') ? 'src' : 'public');
36
+ const file = resolve(base, pathname.startsWith('/src/') ? pathname.slice(5) : pathname.replace(/^\//, ''));
37
+ const local = relative(base, file);
38
+ if (local === '..' || local.startsWith('../') || isAbsolute(local)) return Promise.resolve(new Response(null, { status: 404 }));
39
+ return Promise.resolve(existsSync(file) ? new Response(readFileSync(file)) : new Response(null, { status: 404 }));
40
+ },
41
+ createImageBitmap: () => Promise.resolve({ width: 1, height: 1, close: noop }), // textures are never drawn here
42
+ ProgressEvent: class extends Event { constructor(type, init = {}) { super(type); Object.assign(this, init); } },
43
+ });
44
+ Object.defineProperty(globalThis, 'navigator', { value: { userAgent: 'node', onLine: true, maxTouchPoints: 0, hardwareConcurrency: 8 }, configurable: true });
45
+
46
+ active = true;
47
+ let disposed = false;
48
+ return { element: el, dispose() {
49
+ if (disposed) return;
50
+ disposed = true;
51
+ for (const name of names) {
52
+ const descriptor = previous.get(name);
53
+ if (descriptor === undefined) Reflect.deleteProperty(globalThis, name);
54
+ else Object.defineProperty(globalThis, name, descriptor);
55
+ }
56
+ active = false;
57
+ } };
58
+ }
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ // SHARD-PLATFORM SF23: deterministically regenerate every grid shard's far proxy (public/assets/baked/<slug>/far.glb +
3
+ // far.json, and G539's camera-facing impostor far-impostor.png) from its height grid and its own far look; prints each
4
+ // proxy's resident MB, wire KB and triangles.
5
+ // G348: the shards are the ones that declare a far row in their own `data/placeholder.json` (look, and a grid or model
6
+ // parts when their land is not a height field); the baker is the SDK's (`@wildshard/sdk/bake/placeholders`), the same
7
+ // one `wildshard build` runs for any shardfile. No shard table lives here.
8
+ // SF49: a shard whose land is models (floating islands) merges them in decimated; this runner hands it the SDK's model
9
+ // tools (`placeholderModelTools`: a GLB reader that samples the base colour per vertex, and meshoptimizer's simplifier),
10
+ // the same ones the near bake builds that land with (G380).
11
+ import { build } from 'vite';
12
+ import { mkdirSync, mkdtempSync, rmSync, symlinkSync, realpathSync, writeFileSync } from 'node:fs';
13
+ import { createRequire } from 'node:module';
14
+ import { tmpdir } from 'node:os';
15
+ import { join, resolve } from 'node:path';
16
+ import { pathToFileURL } from 'node:url';
17
+ import { placeholderGridBytes, placeholderShards } from './placeholderShards.mjs';
18
+
19
+ const repo = resolve(import.meta.dirname, '../..'), scratch = mkdtempSync(join(tmpdir(), 'far-proxies-'));
20
+ // sharp comes with the glTF CLI (resolved through it, as scripts/nalati-models-color.mjs does)
21
+ const req = createRequire(realpathSync(join(repo, 'node_modules/@gltf-transform/cli/package.json')));
22
+ const shards = (await placeholderShards(repo)).filter(shard => shard.source.far !== undefined);
23
+ // one bundle: the SDK baker and every declared module, imported by the shard's own data (generated, never committed)
24
+ const modules = [...new Set(shards.flatMap(({ dir, source }) => ['look', 'grid', 'parts'].flatMap(key => source.far[key] === undefined ? [] : [join(dir, source.far[key].module)])))];
25
+ const entry = [`export * as sdk from ${JSON.stringify(join(repo, 'src/sharddev/bake/placeholders.ts'))};`, `export const modules = { ${modules.map((path) => `${JSON.stringify(path)}: () => import(${JSON.stringify(path)})`).join(', ')} };`].join('\n');
26
+ try {
27
+ symlinkSync(join(repo, 'node_modules'), join(scratch, 'node_modules'));
28
+ writeFileSync(join(scratch, 'entry.ts'), entry);
29
+ // sharp (the bundle reaches it through the SDK's asset tools) stays outside the bundle as the runner's own copy: pnpm
30
+ // does not hoist it to the repo root, so an inlined copy cannot find its platform binary, and one libvips per process
31
+ const sharpUrl = pathToFileURL(req.resolve('sharp')).href;
32
+ await build({ plugins: [{ name: 'external-sharp', enforce: 'pre', resolveId: (id) => (id === 'sharp' ? { id: sharpUrl, external: true } : null) }], configFile: false, logLevel: 'silent', build: { target: 'esnext', outDir: join(scratch, 'generator'), emptyOutDir: true, lib: { entry: join(scratch, 'entry.ts'), formats: ['es'], fileName: 'build' }, rolldownOptions: { platform: 'node', external: [/^node:/u, 'vite'] } } });
33
+ const { sdk, modules: load } = await import(pathToFileURL(join(scratch, 'generator/build.js')).href), tools = await sdk.placeholderModelTools(repo);
34
+ const exported = async (dir, ref) => { const value = (await load[join(dir, ref.module)]())[ref.export]; if (value === undefined) throw new Error(`${dir}: ${ref.module} has no export ${ref.export}`); return value; };
35
+ for (const { slug, dir, source: { far: declared } } of shards) {
36
+ const look = await exported(dir, declared.look), parts = declared.parts === undefined ? [] : await (await exported(dir, declared.parts))(tools);
37
+ const ground = declared.grid === undefined ? placeholderGridBytes(repo, dir, slug) : null;
38
+ const grid = ground === null ? (await exported(dir, declared.grid))() : ground.kind === 'baked' ? sdk.bakedTerrainGrid(ground.bytes) : sdk.colliderGrid(ground.bytes);
39
+ const { manifest, bytes, impostor } = await sdk.bakeFarPlaceholder(grid, look, parts), out = join(repo, 'public/assets/baked', slug);
40
+ mkdirSync(out, { recursive: true });
41
+ writeFileSync(join(out, 'far.glb'), bytes); writeFileSync(join(out, 'far-impostor.png'), impostor); writeFileSync(join(out, 'far.json'), sdk.placeholderJson(manifest));
42
+ const { far } = manifest;
43
+ console.log(`${slug.padEnd(18)} resident ${((far.decoded + far.gpu) / 1e6).toFixed(3)} MB wire ${(far.compressed / 1e3).toFixed(0)} KB ${far.triangles} tris ${far.draws} draw`);
44
+ }
45
+ } finally { rmSync(scratch, { recursive: true, force: true }); }
@@ -0,0 +1,4 @@
1
+ /** Build-time RGB channel packing after the original half-float gain decode. */
2
+ export function packGainKey(color: Uint8Array, gain: Uint8Array, width: number, height: number): { data: Uint16Array; horizon: number[] };
3
+ /** Encode packed texels with the shipped platform-independent gzip header. */
4
+ export function encodeGainKey(data: Uint16Array): Uint8Array;
@@ -0,0 +1,34 @@
1
+ // Build-only RGB half-float rows. The upload retains each driver's RGB9_E5 quantization.
2
+ import { gzipSync } from 'node:zlib';
3
+ import { DataUtils } from 'three';
4
+
5
+ /** Keep the shipped gzip OS marker stable across Darwin and Linux producers. */
6
+ export function encodeGainKey(data) {
7
+ const bytes = gzipSync(new Uint8Array(data.buffer, data.byteOffset, data.byteLength), { level: 9 });
8
+ bytes[9] = 19; // Preserve the original Darwin catalogue; this header does not affect inflation.
9
+ return bytes;
10
+ }
11
+
12
+ /** Match BakedSky's gain lookup, drop constant alpha offline, and retain the original horizon means. */
13
+ export function packGainKey(color, gain, width, height) {
14
+ if (color.length !== width * height * 4 || gain.length !== color.length) throw new Error('Sky plane sizes differ');
15
+ const lin = new Float32Array(256), lut = new Uint16Array(65536);
16
+ const f32 = new Float32Array(1), u32 = new Uint32Array(f32.buffer);
17
+ const half = value => {
18
+ f32[0] = value; const x = u32[0], e = ((x >>> 23) & 255) - 112, m = x & 0x7fffff;
19
+ if (e >= 31) return 0x7bff;
20
+ if (e <= 0) return e < -10 ? 0 : ((((m | 0x800000) >>> (1 - e)) + 0x1000) >>> 13);
21
+ return (e << 10) + ((m + 0x1000) >>> 13);
22
+ };
23
+ for (let c = 0; c < 256; c++) { const s = c / 255; lin[c] = s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4; }
24
+ for (let g = 0; g < 256; g++) for (let c = 0; c < 256; c++) lut[g * 256 + c] = half(Math.min(65504, lin[c] * 2 ** (g / 255 * 16)));
25
+ const data = new Uint16Array(width * height * 3), horizon = [0, 0, 0], row = Math.floor(height * 0.47);
26
+ for (let p = 0; p < width * height; p++) {
27
+ const i = p * 4, at = gain[i] * 256;
28
+ for (let c = 0; c < 3; c++) {
29
+ const value = lut[at + color[i + c]]; data[p * 3 + c] = value;
30
+ if (Math.floor(p / width) === row && p % width % 4 === 0) horizon[c] += DataUtils.fromHalfFloat(value);
31
+ }
32
+ }
33
+ return { data, horizon: horizon.map(c => c / Math.ceil(width / 4)) };
34
+ }
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ // Trusted SF30 compiler: immutable admitted modules, never dynamic git operations.
3
+ // G348: the shards it bakes and what each compiles come from their own data (`src/shards/<slug>/generators/moverBake.ts`,
4
+ // `MOVER_BAKE`, schema `@wildshard/format/movers` `MoverBakeSchema`), never a table here.
5
+ // node --experimental-transform-types --import ./scripts/bake-loader.mjs scripts/bake/movers.mjs [--shards=<slug>,…]
6
+ import { compileMoverDriver } from '../../src/sharddev/compileMovers.ts';
7
+ import { MOVER_DRIVER_MODULES } from '@wildshard/format/moverMotion';
8
+ import { moverBake } from '@wildshard/format/movers';
9
+ import { existsSync, mkdirSync, readdirSync, writeFileSync, mkdtempSync, rmSync, symlinkSync } from 'node:fs';
10
+ import { createHash } from 'node:crypto';
11
+ import { resolve, join } from 'node:path';
12
+ import { tmpdir } from 'node:os';
13
+ import { pathToFileURL } from 'node:url';
14
+ import { build } from 'vite';
15
+
16
+ const repo = resolve(import.meta.dirname, '../..');
17
+ /** Every shard folder declaring a mover bake, sorted by folder name. */
18
+ const declared = [];
19
+ for (const slug of readdirSync(join(repo, 'src/shards')).sort()) {
20
+ const file = join(repo, 'src/shards', slug, 'generators/moverBake.ts');
21
+ if (existsSync(file)) declared.push({ slug, bake: moverBake(slug, (await import(pathToFileURL(file).href)).MOVER_BAKE) });
22
+ }
23
+ const selected = process.argv.find(arg => arg.startsWith('--shards='))?.slice('--shards='.length).split(',') ?? declared.map(row => row.slug);
24
+ if (selected.some(slug => !declared.map(row => row.slug).includes(slug))) throw new Error('Unknown mover shard');
25
+ const shards = declared.filter(row => selected.includes(row.slug));
26
+ const hashes = new Map();
27
+ for (const { slug, bake } of shards) for (const module of bake.modules) {
28
+ if (bake.execution === 'native') {
29
+ if (module.emit !== undefined) throw new Error('Native mover does not emit a guest module');
30
+ const hash = MOVER_DRIVER_MODULES[module.driver]; hashes.set(`${slug}/${module.file}`, hash);
31
+ process.stdout.write(`${slug}/${module.file} native ${hash}\n`); continue;
32
+ }
33
+ const bytes = await compileMoverDriver(module.driver);
34
+ const hash = createHash('sha256').update(bytes).digest('hex'), directory = join(repo, 'src/shards', slug, 'assets');
35
+ mkdirSync(directory, { recursive: true }); writeFileSync(join(directory, hash), bytes);
36
+ hashes.set(`${slug}/${module.file}`, hash);
37
+ process.stdout.write(`${slug}/${module.file} ${hash} ${bytes.length}\n`);
38
+ // a module the shard's runtime admits by hash (Sky Reach's shardfile, SF8c socketLift / SF72) gets its data constant
39
+ if (module.emit !== undefined) writeFileSync(join(repo, 'src/shards', slug, module.emit.file), `// Generated by scripts/bake/movers.mjs: ${module.emit.note}.\nexport const ${module.emit.name} = { hash: '${hash}', bytes: ${bytes.length} } as const;\n`);
40
+ }
41
+ const scratch = mkdtempSync(join(tmpdir(), 'mover-export-'));
42
+ try {
43
+ symlinkSync(join(repo, 'node_modules'), join(scratch, 'node_modules'));
44
+ for (const { slug, bake } of shards) {
45
+ const directory = join(scratch, slug);
46
+ await build({ configFile: false, logLevel: 'silent', build: { target: 'esnext', outDir: directory, emptyOutDir: true,
47
+ lib: { entry: join(repo, 'src/shards', slug, 'generators/movers.ts'), formats: ['es'], fileName: 'capture' },
48
+ rolldownOptions: { platform: 'node', external: [/^node:/u] } } });
49
+ const capture = (await import(pathToFileURL(join(directory, 'capture.js')).href))[bake.capture];
50
+ if (typeof capture !== 'function') throw new Error(`${slug}: generators/movers.ts has no ${bake.capture}`);
51
+ const data = capture(...bake.modules.map(module => hashes.get(`${slug}/${module.file}`)));
52
+ const target = join(repo, 'src/shards', slug, 'data'); mkdirSync(target, { recursive: true });
53
+ if (bake.output === 'json') writeFileSync(join(target, 'movers.generated.json'), `${JSON.stringify(data, null, 2)}\n`);
54
+ else writeFileSync(join(target, 'movers.ts'), `// Generated by scripts/bake/movers.mjs from today's collider/rest recipes.\nimport type { MoverData } from '@wildshard/sdk/movers';\n/** Admitted modules own fixed-step motion; the engine owns collision and the rope solver. */\nexport const MOVERS: MoverData = ${JSON.stringify(data, null, 2)};\n`);
55
+ }
56
+ } finally { rmSync(scratch, { recursive: true, force: true }); }
@@ -0,0 +1,6 @@
1
+ import type { ShardManifest } from '@wildshard/engine/game/shard/manifest';
2
+ import type { BakedGrid } from '@wildshard/engine/world/BakedTerrain';
3
+ /** Prepare exact scalar bytes from the project or its declared public assets before native queries. */
4
+ export function prepareNativeScalarBlocks(def: ShardManifest, root: string): void;
5
+ /** Preconfigure live samplers from original native bytes before authored terrain/forest/model construction. */
6
+ export function prepareNativeTerrain(def: ShardManifest, options: { root: string; bytes: Uint8Array }): Promise<BakedGrid>;
@@ -0,0 +1,43 @@
1
+ import {existsSync,readFileSync} from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+
5
+ /** Offline transport for the same definition-owned scalar intake used by products. */
6
+ export function prepareNativeScalarBlocks(def, root) {
7
+ const intake = def.scalarBlocks;
8
+ if (intake === undefined || intake.prepared) return;
9
+ const project = resolve(root, 'src/shards', def.slug);
10
+ intake.prepare(new Map(intake.files.map(file => {
11
+ const local = resolve(project, file);
12
+ const path = !existsSync(local) && file.startsWith('assets/') ? resolve(root, 'public', file) : local;
13
+ return [file, readFileSync(path)];
14
+ })));
15
+ }
16
+
17
+ /** Select the actual authored level and its original native bytes before terrain, forest or model construction. */
18
+ export async function prepareNativeTerrain(def, options) {
19
+ const src = p => import(pathToFileURL(resolve(options.root, 'src', p)).href);
20
+ prepareNativeScalarBlocks(def, options.root);
21
+ const { bytes } = options;
22
+ if (bytes.length < 24) throw new Error('Missing original native terrain');
23
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
24
+ if (view.getUint32(0, true) !== 0x52545357 || view.getUint32(4, true) !== 1 || view.getUint32(8, true) !== 256 || view.getFloat32(12, true) !== 500 || view.getUint32(16, true) !== def.seed) throw new Error('Authored world requires its original WSTR256 terrain and seed');
25
+ const { parseBakedTerrain, installBakedGrid } = await src('engine/shared/world/BakedTerrain.ts');
26
+ const end = 24 + 256 ** 2 * 8;
27
+ if (bytes.length < end) throw new Error('Truncated original native terrain');
28
+ if (bytes.length > end) {
29
+ if (bytes.length < end + 24 || view.getUint32(end, true) !== 0x4c505357 || view.getUint32(end + 4, true) !== 1) throw new Error('Invalid original native placement trailer');
30
+ const decisions = view.getUint32(end + 8, true), kinds = view.getUint32(end + 12, true);
31
+ if (kinds > 256 || decisions > 8_000_000 || bytes.length !== end + 24 + kinds * 4 + Math.ceil(decisions / 8) || !Number.isFinite(view.getFloat64(end + 16 + kinds * 4, true))) throw new Error('Invalid original native placement bounds');
32
+ }
33
+ const grid = parseBakedTerrain(Uint8Array.from(bytes).buffer);
34
+ if (grid === null || grid.heights.some(value => !Number.isFinite(value) || Math.abs(value) > 250)) throw new Error('Invalid original native terrain');
35
+ const { _applyChunkConstants } = await src('engine/shared/core/config.ts');
36
+ const { configureLevel } = await src('engine/shared/level/selection.ts');
37
+ const { toLevelSpec } = await src('game/client/shard/spec.ts');
38
+ const { game } = await src('game/client/shard/registry.ts');
39
+ game.shard = def;
40
+ _applyChunkConstants(def); configureLevel(toLevelSpec(def));
41
+ installBakedGrid(grid);
42
+ return grid;
43
+ }