@wildshard/sdk 0.0.0 → 0.2.3

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 (687) hide show
  1. package/GUIDE.md +790 -0
  2. package/README.md +14 -4
  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 +371 -4
  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 +46 -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 +24 -0
  358. package/src/cli/bin.mjs +8 -0
  359. package/src/cli/delete/delete.ts +258 -0
  360. package/src/cli/help.ts +196 -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 +292 -0
  365. package/src/cli/report.ts +16 -0
  366. package/src/cli/shardfile/command.ts +50 -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/arenaView.ts +15 -0
  394. package/src/sharddev/as/groupBankV2.ts +36 -0
  395. package/src/sharddev/as/groupStepV2.ts +13 -0
  396. package/src/sharddev/as/ws.ts +30 -0
  397. package/src/sharddev/as/wsV2.ts +180 -0
  398. package/src/sharddev/assemblyscriptCompiler.d.mts +5 -0
  399. package/src/sharddev/assemblyscriptCompiler.mjs +14 -0
  400. package/src/sharddev/assetHandle.ts +84 -0
  401. package/src/sharddev/assetOwner.ts +70 -0
  402. package/src/sharddev/assetScope.ts +30 -0
  403. package/src/sharddev/assets.ts +21 -0
  404. package/src/sharddev/audio.ts +9 -0
  405. package/src/sharddev/audioEncode.ts +211 -0
  406. package/src/sharddev/author.ts +3 -0
  407. package/src/sharddev/authorError.ts +28 -0
  408. package/src/sharddev/authorManifest.ts +39 -0
  409. package/src/sharddev/bake/annulus.ts +19 -0
  410. package/src/sharddev/bake/assemblyscriptMemo.ts +76 -0
  411. package/src/sharddev/bake/assemblyscriptMemoPort.ts +4 -0
  412. package/src/sharddev/bake/authoredWorld.ts +201 -0
  413. package/src/sharddev/bake/basisEncoder.ts +95 -0
  414. package/src/sharddev/bake/basisGlb.ts +85 -0
  415. package/src/sharddev/bake/basisTool.ts +74 -0
  416. package/src/sharddev/bake/basisToolInputs.ts +476 -0
  417. package/src/sharddev/bake/byteCodec.ts +33 -0
  418. package/src/sharddev/bake/canvasAtlas.ts +406 -0
  419. package/src/sharddev/bake/coarseCopy.ts +59 -0
  420. package/src/sharddev/bake/colliders.ts +87 -0
  421. package/src/sharddev/bake/compactGlb.ts +224 -0
  422. package/src/sharddev/bake/compileScript.ts +119 -0
  423. package/src/sharddev/bake/compileScriptV2.ts +75 -0
  424. package/src/sharddev/bake/contactRows.ts +84 -0
  425. package/src/sharddev/bake/creaturePlacement.ts +117 -0
  426. package/src/sharddev/bake/export.ts +67 -0
  427. package/src/sharddev/bake/facetedGeometry.ts +379 -0
  428. package/src/sharddev/bake/farImpostor.ts +120 -0
  429. package/src/sharddev/bake/forest.ts +100 -0
  430. package/src/sharddev/bake/format-hook.mjs +2 -0
  431. package/src/sharddev/bake/generatorGlb.ts +23 -0
  432. package/src/sharddev/bake/geometryBounds.ts +77 -0
  433. package/src/sharddev/bake/geometryError.ts +48 -0
  434. package/src/sharddev/bake/glb.ts +355 -0
  435. package/src/sharddev/bake/glbCompression.ts +143 -0
  436. package/src/sharddev/bake/gltfSource.ts +59 -0
  437. package/src/sharddev/bake/groundMap.ts +142 -0
  438. package/src/sharddev/bake/image.ts +20 -0
  439. package/src/sharddev/bake/isleMap.ts +64 -0
  440. package/src/sharddev/bake/json.mjs +84 -0
  441. package/src/sharddev/bake/keyedSky.ts +47 -0
  442. package/src/sharddev/bake/keyedSkyMemo.ts +39 -0
  443. package/src/sharddev/bake/kinds.ts +137 -0
  444. package/src/sharddev/bake/lightSources.ts +31 -0
  445. package/src/sharddev/bake/mapAssembly.ts +84 -0
  446. package/src/sharddev/bake/mapRaster.ts +173 -0
  447. package/src/sharddev/bake/mapRest.ts +57 -0
  448. package/src/sharddev/bake/mapScenes.ts +234 -0
  449. package/src/sharddev/bake/materialGraph.ts +32 -0
  450. package/src/sharddev/bake/meadow.ts +27 -0
  451. package/src/sharddev/bake/meshoptChoiceMemo.ts +34 -0
  452. package/src/sharddev/bake/nativeInteractionFacts.ts +5 -0
  453. package/src/sharddev/bake/nativeLattice.ts +178 -0
  454. package/src/sharddev/bake/nativeRaster.ts +106 -0
  455. package/src/sharddev/bake/nativeTerrainField.ts +11 -0
  456. package/src/sharddev/bake/navigation-json.mjs +38 -0
  457. package/src/sharddev/bake/navigation.ts +113 -0
  458. package/src/sharddev/bake/navigationAsset.ts +18 -0
  459. package/src/sharddev/bake/nearPlaceholder.ts +206 -0
  460. package/src/sharddev/bake/normalizeRig.ts +80 -0
  461. package/src/sharddev/bake/phoneAstc.ts +93 -0
  462. package/src/sharddev/bake/placeholders.ts +581 -0
  463. package/src/sharddev/bake/placement.ts +80 -0
  464. package/src/sharddev/bake/portableBytes.ts +18 -0
  465. package/src/sharddev/bake/portableBytesMemo.ts +50 -0
  466. package/src/sharddev/bake/practiceCourse.ts +49 -0
  467. package/src/sharddev/bake/primitives.ts +96 -0
  468. package/src/sharddev/bake/props.ts +443 -0
  469. package/src/sharddev/bake/questPlacement.ts +98 -0
  470. package/src/sharddev/bake/rawTexture.ts +26 -0
  471. package/src/sharddev/bake/riderArms.ts +97 -0
  472. package/src/sharddev/bake/rig.ts +95 -0
  473. package/src/sharddev/bake/riggedHullRecipes.ts +40 -0
  474. package/src/sharddev/bake/signPlacements.ts +25 -0
  475. package/src/sharddev/bake/simplifier.ts +52 -0
  476. package/src/sharddev/bake/skinned.ts +312 -0
  477. package/src/sharddev/bake/slabChunks.ts +149 -0
  478. package/src/sharddev/bake/slabs.ts +263 -0
  479. package/src/sharddev/bake/source-loader.mjs +55 -0
  480. package/src/sharddev/bake/sourceMetadata.ts +54 -0
  481. package/src/sharddev/bake/species.ts +368 -0
  482. package/src/sharddev/bake/specimenCatalogue.ts +47 -0
  483. package/src/sharddev/bake/splatGround.ts +141 -0
  484. package/src/sharddev/bake/staticMaterials.ts +171 -0
  485. package/src/sharddev/bake/terrain.ts +195 -0
  486. package/src/sharddev/bake/texture.ts +33 -0
  487. package/src/sharddev/bake/textureWasm.ts +81 -0
  488. package/src/sharddev/bake/tileEncoder.ts +11 -0
  489. package/src/sharddev/bake/tileGrid.ts +62 -0
  490. package/src/sharddev/bake/v2Finite.ts +160 -0
  491. package/src/sharddev/bake/v2Fuel.ts +71 -0
  492. package/src/sharddev/bake/wholePartition.ts +74 -0
  493. package/src/sharddev/bake/wholePieceJoin.ts +147 -0
  494. package/src/sharddev/bake/world.ts +173 -0
  495. package/src/sharddev/bake/worldCollision.ts +128 -0
  496. package/src/sharddev/bake/worldGeometry.ts +237 -0
  497. package/src/sharddev/bake/worldGlb.ts +123 -0
  498. package/src/sharddev/bake/worldImage.ts +12 -0
  499. package/src/sharddev/bake/worldLod.ts +128 -0
  500. package/src/sharddev/bake/worldRows.ts +102 -0
  501. package/src/sharddev/bake/worldTextureMemo.ts +63 -0
  502. package/src/sharddev/bake/zstdBytesMemo.ts +52 -0
  503. package/src/sharddev/bake.ts +193 -0
  504. package/src/sharddev/bakePublication.ts +31 -0
  505. package/src/sharddev/behaviourSource.ts +94 -0
  506. package/src/sharddev/bin/wildshard.mjs +7 -0
  507. package/src/sharddev/blobBytes.ts +65 -0
  508. package/src/sharddev/blobs.ts +138 -0
  509. package/src/sharddev/bootInventory.ts +129 -0
  510. package/src/sharddev/bossProfiles.ts +18 -0
  511. package/src/sharddev/buildBehaviour.ts +77 -0
  512. package/src/sharddev/buildCacheMetrics.ts +17 -0
  513. package/src/sharddev/buildDecisionScripts.ts +122 -0
  514. package/src/sharddev/check.ts +117 -0
  515. package/src/sharddev/checkProject.ts +126 -0
  516. package/src/sharddev/cli.ts +191 -0
  517. package/src/sharddev/clientChannels.ts +169 -0
  518. package/src/sharddev/clientScripts.ts +10 -0
  519. package/src/sharddev/commons.ts +77 -0
  520. package/src/sharddev/commonsCosts.ts +11 -0
  521. package/src/sharddev/compileMovers.ts +11 -0
  522. package/src/sharddev/configBoundary.ts +6 -0
  523. package/src/sharddev/cookInput.ts +40 -0
  524. package/src/sharddev/crowds.ts +6 -0
  525. package/src/sharddev/decisionBindingMap.ts +11 -0
  526. package/src/sharddev/decisionScriptBindings.ts +117 -0
  527. package/src/sharddev/decisionScripts.ts +28 -0
  528. package/src/sharddev/decisionSource.ts +51 -0
  529. package/src/sharddev/dev.ts +113 -0
  530. package/src/sharddev/director.ts +26 -0
  531. package/src/sharddev/directorAbi.ts +77 -0
  532. package/src/sharddev/discoveryDocument.ts +97 -0
  533. package/src/sharddev/draft.ts +11 -0
  534. package/src/sharddev/eliteEntryRows.ts +29 -0
  535. package/src/sharddev/entries.ts +76 -0
  536. package/src/sharddev/entryReads.ts +73 -0
  537. package/src/sharddev/executeBundle.ts +55 -0
  538. package/src/sharddev/finds.ts +5 -0
  539. package/src/sharddev/formatJsonSchema.ts +3 -0
  540. package/src/sharddev/generationCache.ts +257 -0
  541. package/src/sharddev/generationRecipe.ts +94 -0
  542. package/src/sharddev/handwritten.ts +110 -0
  543. package/src/sharddev/immutable.ts +14 -0
  544. package/src/sharddev/interactions.ts +38 -0
  545. package/src/sharddev/kit/bakedGeometry.ts +16 -0
  546. package/src/sharddev/kit/geometryPack.ts +110 -0
  547. package/src/sharddev/ledger.ts +13 -0
  548. package/src/sharddev/looks/tileField.ts +67 -0
  549. package/src/sharddev/materialGraphFiles.ts +57 -0
  550. package/src/sharddev/materials.ts +574 -0
  551. package/src/sharddev/measure.ts +18 -0
  552. package/src/sharddev/modes.ts +115 -0
  553. package/src/sharddev/moverPrograms.ts +213 -0
  554. package/src/sharddev/movers.ts +75 -0
  555. package/src/sharddev/nativePopulationRows.ts +46 -0
  556. package/src/sharddev/newProject.ts +247 -0
  557. package/src/sharddev/noise.ts +54 -0
  558. package/src/sharddev/outputProduct.ts +188 -0
  559. package/src/sharddev/outputRuntime.ts +66 -0
  560. package/src/sharddev/performancePolicy.ts +18 -0
  561. package/src/sharddev/phasedBoss.ts +34 -0
  562. package/src/sharddev/physics.ts +194 -0
  563. package/src/sharddev/platformSections.ts +42 -0
  564. package/src/sharddev/plumbing.ts +8 -0
  565. package/src/sharddev/productOutput.ts +128 -0
  566. package/src/sharddev/project.ts +337 -0
  567. package/src/sharddev/projectCompilerIdentity.ts +94 -0
  568. package/src/sharddev/projectDecisions.ts +66 -0
  569. package/src/sharddev/projectEntryProof.ts +32 -0
  570. package/src/sharddev/projectGeneration.ts +219 -0
  571. package/src/sharddev/projectInputFiles.ts +47 -0
  572. package/src/sharddev/projectManifest.ts +108 -0
  573. package/src/sharddev/projectMap.ts +35 -0
  574. package/src/sharddev/projectOutput.ts +242 -0
  575. package/src/sharddev/projectPolicy.ts +17 -0
  576. package/src/sharddev/projectSections.ts +27 -0
  577. package/src/sharddev/questGraph.ts +25 -0
  578. package/src/sharddev/quests.ts +65 -0
  579. package/src/sharddev/random.ts +61 -0
  580. package/src/sharddev/refusals.ts +234 -0
  581. package/src/sharddev/reportCard.ts +13 -0
  582. package/src/sharddev/returnProjectionV2.ts +81 -0
  583. package/src/sharddev/rows.ts +192 -0
  584. package/src/sharddev/runtimeImports.ts +38 -0
  585. package/src/sharddev/runtimeMirrors.ts +39 -0
  586. package/src/sharddev/runtimePerformance.ts +38 -0
  587. package/src/sharddev/scene.ts +321 -0
  588. package/src/sharddev/sceneAnimation.ts +54 -0
  589. package/src/sharddev/sceneAudio.ts +64 -0
  590. package/src/sharddev/sceneDeclarations.ts +100 -0
  591. package/src/sharddev/sceneGraph.ts +139 -0
  592. package/src/sharddev/sceneTransform.ts +12 -0
  593. package/src/sharddev/schemaValidation.ts +61 -0
  594. package/src/sharddev/sections.ts +47 -0
  595. package/src/sharddev/shardSource.ts +59 -0
  596. package/src/sharddev/sourceReader.ts +26 -0
  597. package/src/sharddev/spawns.ts +38 -0
  598. package/src/sharddev/species/clips.ts +24 -0
  599. package/src/sharddev/species.ts +29 -0
  600. package/src/sharddev/speciesBrains.ts +19 -0
  601. package/src/sharddev/synth.ts +66 -0
  602. package/src/sharddev/test/compileDualScriptV2.ts +71 -0
  603. package/src/sharddev/test/compileSimV2.ts +21 -0
  604. package/src/sharddev/test/diskScriptScenario.ts +86 -0
  605. package/src/sharddev/test/scriptScenario.ts +249 -0
  606. package/src/sharddev/test/scriptSource.ts +12 -0
  607. package/src/sharddev/version.ts +4 -0
  608. package/src/sharddev/weapons/bowProfile.ts +20 -0
  609. package/src/sharddev/weapons/firearmRows.ts +11 -0
  610. package/src/sharddev/weapons/meleeProfile.ts +71 -0
  611. package/src/sharddev/weapons/thrownProfile.ts +10 -0
  612. package/src/sharddev/worldScenes.ts +308 -0
  613. package/src/sharddev/worldSource.ts +82 -0
  614. package/src/shards/_template/README.md +78 -0
  615. package/src/shards/_template/assets/2bf489fdb15f1734ddb4c4f32d500ec6da85c765ec7a4eb28dc6781160e7ec8c +0 -0
  616. package/src/shards/_template/assets/97ec4d8f75f5fa6239ee919444d6dc19fd35896bb305930c1f050ac6e0e0e6a6 +1 -0
  617. package/src/shards/_template/assets/a6a587a31327f936b1b04c05ade818c73fc8964260918662db43539465e27586 +0 -0
  618. package/src/shards/_template/assets/b4fbde0422e125b498c3dc8b9a5cc2516c8598f09e9d0e5f6b639b32f98179e6 +0 -0
  619. package/src/shards/_template/assets/bfa4dfc9c18979f904557ee8deab0058b8a399be10266f5fb1578b403f482fd4 +1 -0
  620. package/src/shards/_template/assets/ef3b7ff4fd22715771cb7d68a3977a903c5e7c3dc293542687d04b3ef3ace2cb +0 -0
  621. package/src/shards/_template/assets/f2db05998615ce1cb79ea96be32c168842eb6a2b34ec01feb86d36404603ee54 +0 -0
  622. package/src/shards/_template/assets/fef98ebb7fce6f66b26e78ac699e5c90f9bdcfaf8cabeb2b58125347eea8b4ab +0 -0
  623. package/src/shards/_template/behaviour/boss.as +39 -0
  624. package/src/shards/_template/behaviour/door.as +32 -0
  625. package/src/shards/_template/behaviour/hooks.json +129 -0
  626. package/src/shards/_template/behaviour/idle.as +75 -0
  627. package/src/shards/_template/behaviour/items.as +22 -0
  628. package/src/shards/_template/card/landscape.jpg +0 -0
  629. package/src/shards/_template/card/portrait.jpg +0 -0
  630. package/src/shards/_template/card/thumb.jpg +0 -0
  631. package/src/shards/_template/data/audio.json +45 -0
  632. package/src/shards/_template/data/bossDecision.json +83 -0
  633. package/src/shards/_template/data/budgets.json +70 -0
  634. package/src/shards/_template/data/card.json +281 -0
  635. package/src/shards/_template/data/clientScripts.json +987 -0
  636. package/src/shards/_template/data/creatures.json +65 -0
  637. package/src/shards/_template/data/director.json +39 -0
  638. package/src/shards/_template/data/encounters.json +96 -0
  639. package/src/shards/_template/data/items.json +172 -0
  640. package/src/shards/_template/data/layout.json +66 -0
  641. package/src/shards/_template/data/ledger.json +32 -0
  642. package/src/shards/_template/data/look.json +521 -0
  643. package/src/shards/_template/data/map.json +64 -0
  644. package/src/shards/_template/data/moves.json +16 -0
  645. package/src/shards/_template/data/placeholder.json +8 -0
  646. package/src/shards/_template/data/plumbing.json +32 -0
  647. package/src/shards/_template/data/quests.json +223 -0
  648. package/src/shards/_template/data/rows.json +423 -0
  649. package/src/shards/_template/data/skins.json +66 -0
  650. package/src/shards/_template/data/spawn.json +6 -0
  651. package/src/shards/_template/data/targets.json +150 -0
  652. package/src/shards/_template/data/text.json +12 -0
  653. package/src/shards/_template/data/ui.json +33 -0
  654. package/src/shards/_template/data/water.json +13 -0
  655. package/src/shards/_template/generators/behaviour.ts +34 -0
  656. package/src/shards/_template/generators/boss.ts +29 -0
  657. package/src/shards/_template/generators/buildOptions.ts +2 -0
  658. package/src/shards/_template/generators/cell.ts +224 -0
  659. package/src/shards/_template/generators/districts.ts +215 -0
  660. package/src/shards/_template/generators/farLook.ts +15 -0
  661. package/src/shards/_template/generators/generate.ts +27 -0
  662. package/src/shards/_template/generators/ground.ts +15 -0
  663. package/src/shards/_template/generators/kit.ts +69 -0
  664. package/src/shards/_template/generators/landscape.ts +59 -0
  665. package/src/shards/_template/generators/landscapeNoise.ts +62 -0
  666. package/src/shards/_template/generators/mapInputs.ts +10 -0
  667. package/src/shards/_template/generators/product.ts +100 -0
  668. package/src/shards/_template/generators/productOutput.ts +18 -0
  669. package/src/shards/_template/generators/props.ts +9 -0
  670. package/src/shards/_template/generators/templatePropsSource.ts +58 -0
  671. package/src/shards/_template/generators/terrain.ts +17 -0
  672. package/src/shards/_template/generators/world.ts +630 -0
  673. package/src/shards/_template/hero.json +10 -0
  674. package/src/shards/_template/look/entry-reads.json +20 -0
  675. package/src/shards/_template/manifest.json +281 -0
  676. package/src/shards/_template/shard.config.ts +10 -0
  677. package/src/shared/health.ts +10 -0
  678. package/src/tools/build-web.ts +59 -0
  679. package/src/tsconfig.json +30 -0
  680. package/src/web/app.tsx +53 -0
  681. package/src/web/index.html +12 -0
  682. package/src/web/main.tsx +10 -0
  683. package/src/web/tsconfig.json +13 -0
  684. package/tsconfig.author.json +23 -0
  685. package/tsconfig.commons.json +21 -0
  686. package/tsconfig.json +47 -0
  687. package/tsconfig.sharddev.json +20 -0
@@ -0,0 +1,129 @@
1
+ import { filePolicy } from '@wildshard/engine/boot/filePolicy';
2
+ import { CLOUD_FIELD_URL } from '@wildshard/engine/boot/bakedApi';
3
+ import { RAPIER_WASM_URL } from '@wildshard/engine/physics/wasmUrl';
4
+
5
+ /** Authoring inputs are explicit presence/byte tables, never a live download service. */
6
+ export type BootInventory = Readonly<Record<string, number | true>>;
7
+ /** One concrete output tier. */
8
+ export type BootTier = 'phone' | 'desktop';
9
+ /** A declared texture encoding. */
10
+ export type BootTextures = 'img' | 'ktx2';
11
+ /** Ordered reads by loading phase. */
12
+ export type BootSources = Readonly<Record<'sky' | 'baked' | 'terrain' | 'trees' | 'physics' | 'cabins' | 'props' | 'art' | 'music' | 'sfx', readonly string[]>>;
13
+ /** A resolved value for each output tier and texture mode. */
14
+ export interface BootModes<T> { readonly modes: Readonly<Record<BootTier, Readonly<Record<BootTextures, T>>>> }
15
+ /** Explicit per-tier GPU aliases, with author aliases overriding shared assets. */
16
+ export type BootGpuFiles = Readonly<Record<BootTier, Readonly<Record<string, string>>>>;
17
+
18
+ /** Resolve phone fallbacks and GPU aliases using only the supplied inventory.
19
+ * Ordering and duplicate handling remain the caller's responsibility. */
20
+ export function bootFilePolicy(tier: BootTier, mode: BootTextures, table: BootGpuFiles, inventory: BootInventory): { phone: (url: string) => string; gpu: (url: string) => string } {
21
+ if (inventory === undefined || inventory === null) throw new Error('Boot authoring requires an explicit inventory');
22
+ const { phone, gpu } = filePolicy(tier, mode, table, inventory);
23
+ return { phone, gpu };
24
+ }
25
+
26
+ /** S4: a shard's phone stand-ins, read off the baked files: `/assets/<folder>/astc6/<the path under /assets/gpu>`, each with its
27
+ * own hash (scripts/bake-astc6.mjs). The overlay is the listing, so no table sits in the source. */
28
+ export function phoneOverlayRows(phone: Readonly<Record<string, string>>, listed: readonly string[], folder: string): Readonly<Record<string, string>> {
29
+ const plain = (url: string): string => url.replace(/-[a-f0-9]{8}(?=\.[a-z0-9]+$)/u, '');
30
+ const baked = new Map(listed.map(url => [plain(url), url]));
31
+ if (baked.size !== listed.length) throw new Error('Two phone overlay files share one name');
32
+ const rows: Record<string, string> = {};
33
+ for (const [served, gpu] of Object.entries(phone)) {
34
+ const file = baked.get(plain(gpu).replace('/assets/gpu/', `/assets/${folder}/astc6/`));
35
+ if (file !== undefined) rows[served] = file;
36
+ }
37
+ return rows;
38
+ }
39
+
40
+ /** Shared sky bytes participate only when explicitly present in the author inventory. */
41
+ export function sharedBootTextures(inventory: BootInventory): string[] {
42
+ return CLOUD_FIELD_URL in inventory ? [CLOUD_FIELD_URL] : [];
43
+ }
44
+
45
+ /** The engine's required physics input in native boot order, as an independent author row. */
46
+ export function sharedBootPhysics(): readonly [typeof RAPIER_WASM_URL] { return [RAPIER_WASM_URL]; }
47
+
48
+ /** Owned native bake-texture namespace used by retained author boot recipes.
49
+ * The owner is a bounded project id, never a caller-supplied URL or path. */
50
+ export function bakedBootTextureSource<const Owner extends string>(owner: Owner): { readonly publicPrefix: `/assets/baked/${Owner}/tex/` } {
51
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(owner) || owner.length > 64) throw new Error('Invalid baked texture owner');
52
+ return { publicPrefix: `/assets/baked/${owner}/tex/` };
53
+ }
54
+
55
+ export interface BootRecipe {
56
+ readonly source: { readonly urls: readonly string[] | Readonly<Record<BootTier, readonly string[]>> }
57
+ | { readonly concat: readonly string[] } | { readonly publicPrefix: string }
58
+ | { readonly pbr: readonly string[] } | { readonly gltf: readonly string[] }
59
+ | { readonly tablePrefix: string } | { readonly pages: string }
60
+ | { readonly available: readonly string[]; readonly fallback: readonly string[] };
61
+ readonly map?: readonly ('gpu' | 'layer')[];
62
+ readonly present?: boolean;
63
+ readonly unique?: boolean;
64
+ readonly excludeParts?: readonly string[];
65
+ readonly excludeBasenamePrefix?: string;
66
+ readonly except?: string;
67
+ readonly aliases?: string;
68
+ }
69
+ /** External immutable inventories and aliases, supplied by the same build/runtime owner as the GPU table. */
70
+ export interface BootRecipeInputs {
71
+ /** Offline presence facts: retained file sizes or guaranteed declared build outputs. */
72
+ readonly inventory: BootInventory;
73
+ readonly pages?: Readonly<Record<string, Readonly<Record<BootTier, Readonly<Record<string, { readonly image: string }>>>>>>;
74
+ readonly aliases?: Readonly<Record<string, Readonly<Record<string, string>>>>;
75
+ }
76
+ export type BootRecipes = Readonly<Record<string, BootRecipe>>;
77
+ const isUrlList = (value: readonly string[] | Readonly<Record<BootTier, readonly string[]>>): value is readonly string[] => Array.isArray(value);
78
+ /** Resolve an ordered author recipe against explicit immutable inventory facts.
79
+ * Keeps native recursion/file limits, transform order and strict metadata refusals; never borrows the page inventory. */
80
+ export function bootRecipeFiles(recipes: BootRecipes, name: string, tier: BootTier, tex: BootTextures,
81
+ table: BootGpuFiles, inputs: BootRecipeInputs): string[] {
82
+ if (inputs === undefined || inputs.inventory === undefined || inputs.inventory === null) throw new Error('Boot authoring requires an explicit inventory');
83
+ const inventory = inputs.inventory, policy = filePolicy(tier, tex, table, inventory);
84
+ let visits = 0;
85
+ const run = (id: string, chain: readonly string[]): string[] => {
86
+ if (chain.includes(id) || chain.length >= 16 || ++visits > 256) throw new Error('Boot recipe cycle or bound exceeded');
87
+ const row = recipes[id];
88
+ if (row === undefined) throw new Error(`Missing boot recipe ${id}`);
89
+ const src = row.source, next = [...chain, id];
90
+ let urls: string[];
91
+ if ('urls' in src) urls = [...(isUrlList(src.urls) ? src.urls : src.urls[tier])];
92
+ else if ('concat' in src) urls = src.concat.flatMap(ref => run(ref, next));
93
+ else if ('publicPrefix' in src) urls = Object.keys(inventory).filter(url => url.startsWith(src.publicPrefix));
94
+ else if ('pbr' in src) urls = src.pbr.flatMap(policy.pbr);
95
+ else if ('gltf' in src) urls = src.gltf.flatMap(assetId => [`/assets/models/${assetId}/${assetId}.gltf`, `/assets/models/${assetId}/${assetId}.bin`, ...['diff', 'nor_gl', 'arm'].map(kind => `/assets/models/${assetId}/textures/${assetId}_${kind}_1k.jpg`)]);
96
+ else if ('tablePrefix' in src) urls = tex === 'ktx2' ? Object.keys(table[tier]).filter(url => url.startsWith(src.tablePrefix)).sort().flatMap(url => table[tier][url] ?? []) : [];
97
+ else if ('pages' in src) {
98
+ const pages = inputs.pages?.[src.pages]?.[tier];
99
+ if (pages === undefined) throw new Error(`Missing boot pages ${src.pages}`);
100
+ urls = Object.keys(pages).sort().map(key => {
101
+ const page = pages[key], mapped = table[tier][key];
102
+ if (tex === 'ktx2' && mapped === undefined) throw new Error(`Missing boot page stand-in ${key}`);
103
+ if (page === undefined) throw new Error(`Missing boot page ${key}`);
104
+ return tex === 'ktx2' ? mapped ?? page.image : page.image;
105
+ });
106
+ } else urls = src.available.every(url => url in inventory) ? [...src.available] : [...src.fallback];
107
+ if (row.excludeParts !== undefined) urls = urls.filter(url => !row.excludeParts?.some(part => url.includes(part)));
108
+ if (row.excludeBasenamePrefix !== undefined) urls = urls.filter(url => !url.slice(url.lastIndexOf('/') + 1).startsWith(row.excludeBasenamePrefix ?? ''));
109
+ if (row.unique === true) urls = [...new Set(urls)];
110
+ for (const transform of row.map ?? []) urls = urls.map(policy[transform]);
111
+ if (row.present === true) urls = urls.filter(url => url in inventory);
112
+ if (row.except !== undefined) { const excluded = new Set(run(row.except, next)); urls = urls.filter(url => !excluded.has(url)); }
113
+ if (row.aliases !== undefined) {
114
+ const aliases = inputs.aliases?.[row.aliases];
115
+ if (aliases === undefined) throw new Error(`Missing boot aliases ${row.aliases}`);
116
+ urls = urls.map(url => aliases[url] ?? url);
117
+ }
118
+ if (urls.length > 4096) throw new Error('Boot recipe file bound exceeded');
119
+ return urls;
120
+ };
121
+ return run(name, []);
122
+ }
123
+ /** Resolve every byte category through the same ordered recipe interpreter. */
124
+ export function bootRecipeSources(recipes: BootRecipes, sources: Readonly<Record<keyof BootSources, string>>,
125
+ tier: BootTier, tex: BootTextures, table: BootGpuFiles, inputs: BootRecipeInputs): BootSources {
126
+ const files = (key: keyof BootSources): readonly string[] => bootRecipeFiles(recipes, sources[key], tier, tex, table, inputs);
127
+ return { sky: files('sky'), baked: files('baked'), terrain: files('terrain'), trees: files('trees'), physics: files('physics'),
128
+ cabins: files('cabins'), props: files('props'), art: files('art'), music: files('music'), sfx: files('sfx') };
129
+ }
@@ -0,0 +1,18 @@
1
+ import { parseBossProfile as parse, type BossProfile } from '@wildshard/format/bossProfiles';
2
+ import { parseRoamingEncounter } from '@wildshard/format/bossEncounter';
3
+ import { RoamingCombatSchema } from '@wildshard/format/roamingCombat';
4
+ import { RoamingBossProjectionSchema } from '@wildshard/format/roamingBossProjection';
5
+ import { parse as admit } from 'valibot';
6
+
7
+ /** Admit data-only arena, roaming, spawned, held and script boss policies through the defining runtime schema.
8
+ * This authoring boundary constructs no fight, body, level or service. */
9
+ export function parseBossProfile(input: unknown): BossProfile { return parse(input); }
10
+
11
+ /** Admit encounter resources against the caller's original boss profile, without a fight owner. */
12
+ export function roamingEncounterRows(...args: Parameters<typeof parseRoamingEncounter>): ReturnType<typeof parseRoamingEncounter> {
13
+ return parseRoamingEncounter(...args);
14
+ }
15
+ /** Admit complete combat policy, projection and presentation without installing runtime systems. */
16
+ export function roamingCombatRows(input: unknown): ReturnType<typeof admit<typeof RoamingCombatSchema>> { return admit(RoamingCombatSchema, input); }
17
+ /** Admit complete rig/effect projection data with the native strict field and numeric rules. */
18
+ export function roamingProjectionRows(input: unknown): ReturnType<typeof admit<typeof RoamingBossProjectionSchema>> { return admit(RoamingBossProjectionSchema, input); }
@@ -0,0 +1,77 @@
1
+ // oxlint-disable-next-line import/no-nodejs-modules -- The author build writes only declared generated files inside its project.
2
+ import { existsSync, mkdirSync, realpathSync, writeFileSync } from 'node:fs';
3
+ // oxlint-disable-next-line import/no-nodejs-modules -- Confine authoring input and generated output paths to the project.
4
+ import { dirname, resolve, sep } from 'node:path';
5
+ // oxlint-disable-next-line import/no-nodejs-modules -- Native consumers retain their existing embedded Wasm representation.
6
+ import { Buffer } from 'node:buffer';
7
+ import * as v from 'valibot';
8
+ import { compileScript } from './bake/compileScript';
9
+ import { generateDirectorAbi } from './directorAbi';
10
+ import { hashImmutableBytes } from './immutable';
11
+ import { readBoundedFile } from './sourceReader';
12
+
13
+ const relativePath = v.pipe(v.string(), v.maxLength(512), v.check(path => path.split('/').every(part => /^[A-Za-z0-9_-][A-Za-z0-9_.-]*$/u.test(part)), 'project-relative path'));
14
+ const jsonPath = v.pipe(relativePath, v.check(path => path.endsWith('.json'), 'JSON output path'));
15
+ /** Author-only generation declarations for compiled modules consumed by a trusted native plugin. No wire format changes. */
16
+ export const BehaviourBuildSchema: v.StrictObjectSchema<{ readonly version: v.LiteralSchema<1, undefined>; readonly modules: v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{ readonly source: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, undefined>, v.CheckAction<string, "project-relative path">]>, v.CheckAction<string, "authored behaviour .as source">]>; readonly director: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, undefined>, v.CheckAction<string, "project-relative path">]>, v.CheckAction<string, "JSON output path">]>, undefined>; readonly maximumPages: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 64, undefined>]>; readonly assets: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, undefined>, v.CheckAction<string, "project-relative path">]>; readonly bindings: v.ArraySchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, undefined>, v.CheckAction<string, "project-relative path">]>, v.CheckAction<string, "JSON output path">]>, undefined>; readonly embedded: v.ArraySchema<v.StrictObjectSchema<{ readonly file: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, undefined>, v.CheckAction<string, "project-relative path">]>, v.CheckAction<string, "JSON output path">]>; readonly generated: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 2048, undefined>]>, undefined>; readonly raw: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; }, undefined>, undefined>; }, undefined>, undefined>, v.MinLengthAction<{ source: string; director?: string | undefined; maximumPages: number; assets: string; bindings: string[]; embedded: { file: string; generated?: string | undefined; raw?: boolean | undefined; }[]; }[], 1, undefined>, v.MaxLengthAction<{ source: string; director?: string | undefined; maximumPages: number; assets: string; bindings: string[]; embedded: { file: string; generated?: string | undefined; raw?: boolean | undefined; }[]; }[], 64, undefined>]>; }, undefined> = v.strictObject({
17
+ version: v.literal(1),
18
+ modules: v.pipe(v.array(v.strictObject({
19
+ source: v.pipe(relativePath, v.check(path => path.startsWith('behaviour/') && path.endsWith('.as'), 'authored behaviour .as source')),
20
+ director: v.optional(jsonPath),
21
+ maximumPages: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(64)),
22
+ assets: relativePath,
23
+ bindings: v.array(jsonPath),
24
+ embedded: v.array(v.strictObject({ file: jsonPath, generated: v.optional(v.pipe(v.string(), v.maxLength(2048))), raw: v.optional(v.boolean()) })),
25
+ })), v.minLength(1), v.maxLength(64)),
26
+ });
27
+
28
+ /** Compile retained AssemblyScript author source with the pinned SDK compiler and name its immutable bytes by SHA256. */
29
+ export async function compileBehaviourModule(source: string, maximumPages = 1, sources: Readonly<Record<string, string>> = {}): Promise<{ bytes: Uint8Array; module: string }> {
30
+ const bytes = await compileScript(source, { maximumPages, sources });
31
+ return { bytes, module: hashImmutableBytes(bytes) };
32
+ }
33
+
34
+ /** Generate explicitly declared native modules before a project build. Missing declarations produce no writes.
35
+ * Every source and output is confined to the project, and all modules compile before any output is published.
36
+ * Historical embedded notices may be retained for byte identity; behaviour/build.json is the current regeneration authority.
37
+ * An embedded row with raw:true writes only its hash and empty bytes; the module remains in its declared asset file. */
38
+ export async function buildBehaviourProject(project: string, options: { check?: boolean } = {}): Promise<readonly string[]> {
39
+ const root = realpathSync(project), descriptor = resolve(root, 'behaviour/build.json');
40
+ if (!existsSync(descriptor)) return [];
41
+ const confined = (path: string): string => {
42
+ const destination = resolve(root, path);
43
+ let parent = destination;
44
+ while (!existsSync(parent)) parent = dirname(parent);
45
+ const actual = realpathSync(parent);
46
+ if (actual !== root && !actual.startsWith(root + sep)) throw new Error('Behaviour build path resolves outside project');
47
+ return destination;
48
+ };
49
+ confined('behaviour/build.json');
50
+ const rows = v.parse(BehaviourBuildSchema, JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(readBoundedFile(descriptor, 1_000_000))));
51
+ const files = new Map<string, Uint8Array>();
52
+ const put = (path: string, bytes: Uint8Array): void => {
53
+ const destination = confined(path);
54
+ if (files.has(destination)) throw new Error('Behaviour build declares a duplicate output');
55
+ files.set(destination, bytes);
56
+ };
57
+ const json = (data: unknown): Uint8Array => new TextEncoder().encode(`${JSON.stringify(data, null, 2)}\n`);
58
+ for (const row of rows.modules) {
59
+ const source = new TextDecoder('utf-8', { fatal: true }).decode(readBoundedFile(confined(row.source), 1_000_000));
60
+ const sources: Readonly<Record<string, string>> = row.director === undefined ? {} : {
61
+ 'wildshard-director.ts': generateDirectorAbi(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(readBoundedFile(confined(row.director), 1_000_000)))),
62
+ };
63
+ const compiled = await compileBehaviourModule(source, row.maximumPages, sources);
64
+ put(`${row.assets}/${compiled.module}`, compiled.bytes);
65
+ for (const path of row.bindings) {
66
+ const data = v.parse(v.record(v.string(), v.unknown()), JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(readBoundedFile(confined(path), 1_000_000))));
67
+ put(path, json({ ...data, module: compiled.module }));
68
+ }
69
+ for (const embedded of row.embedded) put(embedded.file, json({ ...(embedded.generated === undefined ? {} : { generated: embedded.generated }), module: compiled.module, bytes: embedded.raw === true ? '' : Buffer.from(compiled.bytes).toString('base64') }));
70
+ }
71
+ if (options.check === true) {
72
+ for (const [path, bytes] of files) {
73
+ if (!existsSync(path) || hashImmutableBytes(readBoundedFile(path, 16_000_000)) !== hashImmutableBytes(bytes)) throw new Error(`Behaviour build output is stale: ${path.slice(root.length + 1)}`);
74
+ }
75
+ } else for (const [path, bytes] of files) { confined(path.slice(root.length + 1)); mkdirSync(dirname(path), { recursive: true }); writeFileSync(path, bytes); }
76
+ return [...files.keys()].map(path => path.slice(root.length + 1));
77
+ }
@@ -0,0 +1,17 @@
1
+ // oxlint-disable-next-line import/no-nodejs-modules -- Build hosts observe counters without entering product data or cache keys.
2
+ import { channel } from 'node:diagnostics_channel';
3
+
4
+ /** Successful cache payload bytes; no duration, compression ratio or admission authority is inferred. */
5
+ interface BuildCacheMetric {
6
+ readonly version: 1;
7
+ readonly cache: 'assemblyscript-raw' | 'zstd-bytes' | 'generation-step';
8
+ readonly event: 'lookup' | 'disk-hit' | 'memory-hit' | 'miss' | 'computed' | 'population' | 'bypass' | 'write-failure' | 'population-race';
9
+ readonly bytes: number;
10
+ readonly project?: string;
11
+ readonly step?: string;
12
+ }
13
+ const metrics = channel('wildshard.build-cache');
14
+ /** Diagnostics only. The CLI subscribes once and prints a batch after critical work. */
15
+ export function reportBuildCache(metric: Omit<BuildCacheMetric, 'version'>): void {
16
+ if (metrics.hasSubscribers) metrics.publish({ version: 1, ...metric });
17
+ }
@@ -0,0 +1,122 @@
1
+ // oxlint-disable-next-line import/no-nodejs-modules -- Build-only author source intake is confined to the project.
2
+ import { existsSync, readdirSync, realpathSync } from 'node:fs';
3
+ // oxlint-disable-next-line import/no-nodejs-modules -- Resolve only project-owned AssemblyScript input paths.
4
+ import { posix, resolve, sep } from 'node:path';
5
+ import { parseDecisionScripts, type DecisionScriptRow } from '@wildshard/format/decisionScripts';
6
+ import { admitScriptContract } from '@wildshard/format/scriptContract';
7
+ import { buildDecisionRegistries, type DecisionRegistries } from '@wildshard/format/decisionBindings';
8
+ import { parseActorMoves } from '@wildshard/format/actorMoves';
9
+ import { CreaturesSchema } from '@wildshard/format/creatures';
10
+ import { parseRows } from '@wildshard/format/rows';
11
+ import * as v from 'valibot';
12
+ import { compileScript } from './bake/compileScript';
13
+ import { generateDecisionBindings } from './decisionScriptBindings';
14
+ import { inspectDecisionSource, checkDecisionHandlers } from './decisionSource';
15
+ import { nameBlob, type NamedBlob } from './blobs';
16
+ import { readBoundedFile } from './sourceReader';
17
+ import { hashImmutableBytes } from './immutable';
18
+ import { hashAssetBytes } from './assetHandle';
19
+ import { WS_CORE } from './as/ws';
20
+ import { viewGameplayLine } from './productOutput';
21
+
22
+ import type { AssemblyScriptMemo } from './bake/assemblyscriptMemoPort';
23
+
24
+ /** Root adapters supply the sealed legacy count; standalone authors declare their explicit ceiling. */
25
+ export interface DecisionBuildOptions { compileMemo?: AssemblyScriptMemo; decisionLegacyLines?: number; asLineCeiling?: number; development?: boolean; singleSignal?: boolean }
26
+ /** No SDK import reaches repo policy. An explicit legacy denominator overrides a standalone declaration. */
27
+ export function decisionLineCeiling(options: DecisionBuildOptions): number {
28
+ const count = options.decisionLegacyLines ?? options.asLineCeiling;
29
+ if (count === undefined) throw new Error('Decision scripts require buildOptions.asLineCeiling for standalone projects');
30
+ if (!Number.isSafeInteger(count) || count < 0) throw new Error('Invalid authored AssemblyScript line budget');
31
+ return options.decisionLegacyLines === undefined ? count : Math.floor(count / 10);
32
+ }
33
+ /** Compile actual author sources through generated capabilities and the defining v1 admission contract.
34
+ * Bindings and glue stay virtual compiler inputs, so guest i32 globals never pollute host TypeScript. */
35
+ export async function compileDecisionScripts(input: unknown, registries: DecisionRegistries, authored: ReadonlyMap<string, string>, options: DecisionBuildOptions): Promise<{
36
+ rows: readonly DecisionScriptRow[]; blobs: readonly NamedBlob[]; generated: ReadonlyMap<string, string>; lines: number; ceiling: number;
37
+ }> {
38
+ // SERVER-PARITY SS8: a view row that writes gameplay names itself here, ahead of the schema's unnamed row rule.
39
+ const viewWrites = (Array.isArray(input) ? input : []).flatMap((row: unknown) => viewGameplayLine(row));
40
+ if (viewWrites.length > 0) throw new Error(viewWrites.join('\n'));
41
+ const rows=parseDecisionScripts(input),captured=await captureDecisionSources(authored,options),{lines,ceiling}=captured;
42
+ const generated=new Map<string,string>(),compiled:DecisionScriptRow[]=[],blobs=new Map<string,NamedBlob>();
43
+ for(const row of rows){
44
+ const binding=generateDecisionBindings(row,registries,options),sources={...binding.sources,...captured.entry(row,binding.path)};
45
+ const bytes = await compileScript(binding.glue, { abi: 1, maximumPages: row.pages, sources, ...(options.compileMemo === undefined ? {} : { compileMemo: options.compileMemo }) });
46
+ admitScriptContract(bytes, { abi: 1, pages: row.pages });
47
+ const hash = hashAssetBytes(bytes), module = `blobs/wasm/${hash}.wasm`;
48
+ const text = authored.get(row.source);
49
+ if (text === undefined) throw new Error(`Missing decision source: ${row.source}`);
50
+ compiled.push({ ...row, module, sourceHash: hashImmutableBytes(new TextEncoder().encode(text)) });
51
+ if (!blobs.has(hash)) blobs.set(hash, nameBlob(`behaviour/${row.id}.wasm`, 'wasm', bytes, { critical: true, script: { abi: 1, pages: row.pages } }));
52
+ generated.set(binding.path, binding.bindings); generated.set(`${binding.path.slice(0, -3)}.glue.ts`, binding.glue);
53
+ }
54
+ generated.set('sdk/as/ws.ts', WS_CORE);
55
+ return { rows: compiled, blobs: [...blobs.values()], generated, lines, ceiling };
56
+ }
57
+ /** Compile from validated author registry rows and actual move data; no format/compiler import enters a build program. */
58
+ export function compileDeclaredDecisionScripts(input: unknown, source: Omit<Parameters<typeof buildDecisionRegistries>[0], 'creatures' | 'rows'> & { creatures: unknown; rows: unknown }, moves: unknown, authored: ReadonlyMap<string, string>, options: DecisionBuildOptions): ReturnType<typeof compileDecisionScripts> {
59
+ return compileDecisionScripts(input, buildDecisionRegistries({ ...source, creatures: v.parse(CreaturesSchema, source.creatures), rows: parseRows(source.rows) }, parseActorMoves(moves)), authored, options);
60
+ }
61
+ /** Read every authored .as (including unreferenced files) for the budget, refusing symlinks and escapes. */
62
+ export function readDecisionSources(project: string): ReadonlyMap<string, string> {
63
+ const root = realpathSync(project), files = new Map<string, string>(), behaviour = resolve(root, 'behaviour');
64
+ if (!existsSync(behaviour)) return files;
65
+ let entries = 0, bytes = 0;
66
+ const visit = (directory: string): void => {
67
+ if (realpathSync(directory) !== directory || !directory.startsWith(root + sep)) throw new Error('Decision source symlinks are not allowed');
68
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
69
+ if (++entries > 4096 || entry.isSymbolicLink()) throw new Error('Decision source tree exceeds bounds or contains symlinks');
70
+ const path = resolve(directory, entry.name);
71
+ if (entry.isDirectory()) visit(path);
72
+ else if (entry.isFile() && entry.name.endsWith('.as')) {
73
+ const value = readBoundedFile(path, 1_000_000); bytes += value.length;
74
+ if (bytes > 4_000_000) throw new Error('Decision sources exceed byte cap');
75
+ files.set(path.slice(root.length + 1).split(sep).join('/'), new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(value));
76
+ }
77
+ }
78
+ };
79
+ visit(behaviour); return files;
80
+ }
81
+ /** Project entry for the same virtual compiler, with no generated file writes or hidden policy reads. */
82
+ export function buildDecisionScripts(project: string, input: unknown, registries: DecisionRegistries, options: DecisionBuildOptions): ReturnType<typeof compileDecisionScripts> {
83
+ return compileDecisionScripts(input, registries, readDecisionSources(project), options);
84
+ }
85
+
86
+ /** Inspect every authored source once; entries capture only their checked relative
87
+ * closure. ABI2 uses the same budget/handler/import law without executing ABI1. */
88
+ export async function captureDecisionSources(authored:ReadonlyMap<string,string>,options:DecisionBuildOptions):Promise<{
89
+ lines:number;ceiling:number;entry:(row:DecisionScriptRow,bindingPath:string,helpers?:ReadonlySet<string>)=>Record<string,string>;
90
+ }>{
91
+ const ceiling=decisionLineCeiling(options),virtual:Record<string,string>={},inspected=new Map<string,Awaited<ReturnType<typeof inspectDecisionSource>>>();
92
+ let lines = 0;
93
+ if (authored.size > 60) throw new Error('Too many authored AssemblyScript sources');
94
+ for (const [path, text] of authored) {
95
+ if (!/^behaviour\/(?:[A-Za-z0-9_-][A-Za-z0-9_.-]*\/)*[A-Za-z0-9_-][A-Za-z0-9_.-]*\.as$/u.test(path) || path.startsWith('behaviour/generated/')) throw new Error('Invalid authored AssemblyScript path');
96
+ const info = await inspectDecisionSource(text, path); inspected.set(path, info); lines += info.lines;
97
+ virtual[`${path.slice(0, -3)}.ts`] = text;
98
+ }
99
+ if (lines > ceiling) throw new Error(`Authored AssemblyScript budget exceeded: ${lines} > ${ceiling}`);
100
+ return {lines,ceiling,entry:(row,bindingPath,helpers)=>{
101
+ const source=inspected.get(row.source);if(source===undefined)throw new Error(`Missing decision source: ${row.source}`);checkDecisionHandlers(row,source.handlers);
102
+ const sources:Record<string,string>={};
103
+ const pending = [row.source], seen = new Set<string>();
104
+ // Only the entry's transitive AS imports reach this module; other authored AS still counts above.
105
+ while (pending.length > 0) {
106
+ const path = pending.pop(); if (path === undefined || seen.has(path)) continue;
107
+ seen.add(path);
108
+ const info = inspected.get(path), text = authored.get(path);
109
+ if (info === undefined || text === undefined) throw new Error(`Missing decision source: ${path}`);
110
+ const virtualPath = `${path.slice(0, -3)}.ts`; sources[virtualPath] = text;
111
+ for (const specifier of info.imports) {
112
+ if (!specifier.startsWith('.')) throw new Error('Decision source imports must be relative');
113
+ const target = `${posix.normalize(posix.join(posix.dirname(path), specifier)).replace(/\.(?:as|ts)$/u, '')}.ts`;
114
+ // the generated bindings, and SDK helper sources the caller declares (a projection's group helpers)
115
+ if (target === bindingPath || helpers?.has(target) === true) continue;
116
+ if (!Object.hasOwn(virtual, target)) throw new Error(`Undeclared decision source import: ${specifier}`);
117
+ pending.push(`${target.slice(0, -3)}.as`);
118
+ }
119
+ }
120
+ return sources;
121
+ }};
122
+ }
@@ -0,0 +1,117 @@
1
+ // `wildshard check` (meta SHARD-AUTHORING SA4, J317): lint, build, validate, prove and the report card in one verb, with
2
+ // one verdict. The loop is new, dev, check, hero, upload. `--json` prints CheckResult below and nothing else on stdout.
3
+ // SA21: every refusal carries a rule id, a one-line fix and a GUIDE.md link, from refusals.ts.
4
+ import { diagnosticNow } from '@wildshard/engine/core/clock';
5
+ import { authorErrorText } from './authorError';
6
+ import { refusalHint, refusalNote, type RefusalStep } from './refusals';
7
+
8
+ /** The five steps, in the order they run. */
9
+ export type CheckStepName = 'lint' | 'build' | 'validate' | 'prove' | 'report';
10
+ /** A skipped step neither passes nor fails the verdict; its note says why it did not run. */
11
+ export type CheckStatus = 'pass' | 'fail' | 'skip';
12
+
13
+ /** One refusal: what was wrong, the rule that said so, its fix and its GUIDE.md section (`GUIDE.md#<anchor>`). */
14
+ export interface CheckRefusal {
15
+ readonly step: CheckStepName;
16
+ readonly rule: string;
17
+ readonly message: string;
18
+ readonly fix: string;
19
+ readonly guide: string;
20
+ readonly file?: string;
21
+ }
22
+ /** A refusal as a step reports it: a lint diagnostic brings oxlint's code and help; refusals.ts fills in the rest. */
23
+ export interface StepRefusal { readonly message: string; readonly lint?: { readonly code: string | null; readonly help: string | null }; readonly file?: string; readonly as?: RefusalStep }
24
+ /** A warning: the same fields as a refusal, but it does not fail the verdict (an unprepared draft, J198). */
25
+ export type CheckWarning = CheckRefusal;
26
+ /** One step's result and wall-clock duration in milliseconds. */
27
+ export interface CheckStep { readonly name: CheckStepName; readonly status: CheckStatus; readonly ms: number; readonly note?: string }
28
+ /** The `--json` document (version 1). `verdict` is `fail` when any step failed; `output` is the built product folder, null when the build failed.
29
+ * `warnings` never fail the verdict. */
30
+ export interface CheckResult {
31
+ readonly version: 1;
32
+ readonly verdict: 'pass' | 'fail';
33
+ readonly project: string;
34
+ readonly output: string | null;
35
+ readonly ms: number;
36
+ readonly steps: readonly CheckStep[];
37
+ readonly refusals: readonly CheckRefusal[];
38
+ readonly warnings: readonly CheckWarning[];
39
+ }
40
+
41
+ /** What a step reports; a thrown error is a `fail` with the error's words as its one refusal. */
42
+ export interface StepOutcome {
43
+ readonly status: CheckStatus;
44
+ readonly note?: string;
45
+ readonly refusals?: readonly StepRefusal[];
46
+ readonly warnings?: readonly StepRefusal[];
47
+ }
48
+ /** The steps' work; validate, prove and report need a built product, so they skip when build fails. */
49
+ export type CheckSteps = Readonly<Record<CheckStepName, () => Promise<StepOutcome>>>;
50
+
51
+ const ORDER: readonly CheckStepName[] = ['lint', 'build', 'validate', 'prove', 'report'];
52
+ const NEEDS_BUILD = new Set<CheckStepName>(['validate', 'prove', 'report']);
53
+
54
+ async function outcomeOf(work: () => Promise<StepOutcome>): Promise<StepOutcome> {
55
+ try { return await work(); }
56
+ catch (error) { return { status: 'fail', refusals: [{ message: authorErrorText(error) }] }; }
57
+ }
58
+
59
+ /** Run every step in order, timing each, and give the verdict. `output` is read after the build; `now` is for tests. */
60
+ export async function runCheck(project: string, output: () => string | null, steps: CheckSteps, now: () => number = diagnosticNow): Promise<CheckResult> {
61
+ const started = now(), rows: CheckStep[] = [], refusals: CheckRefusal[] = [], warnings: CheckWarning[] = [];
62
+ const named = (step: CheckStepName, { message, lint, file, as }: StepRefusal): CheckRefusal => {
63
+ // SA3: build's shard file step names its rules by its own step (a format refusal is not a source one).
64
+ const { rule, fix, guide } = refusalNote(as ?? step, message, lint);
65
+ return { step, rule, message, fix, guide, ...(file === undefined ? {} : { file }) };
66
+ };
67
+ let built = true;
68
+ for (const name of ORDER) {
69
+ const begun = now();
70
+ const outcome: StepOutcome = NEEDS_BUILD.has(name) && !built ? { status: 'skip', note: 'build failed' } : await outcomeOf(steps[name]);
71
+ if (name === 'build' && outcome.status !== 'pass') built = false;
72
+ const ms = Math.round(now() - begun);
73
+ rows.push({ name, status: outcome.status, ms, ...(outcome.note === undefined ? {} : { note: outcome.note }) });
74
+ for (const refusal of outcome.refusals ?? []) refusals.push(named(name, refusal));
75
+ for (const warning of outcome.warnings ?? []) warnings.push(named(name, warning));
76
+ }
77
+ const verdict = rows.some(row => row.status === 'fail') ? 'fail' : 'pass';
78
+ return { version: 1, verdict, project, output: built ? output() : null, ms: Math.round(now() - started), steps: rows, refusals, warnings };
79
+ }
80
+
81
+ interface LintLabel { readonly span?: { readonly line?: number; readonly column?: number } }
82
+ interface LintDiagnostic { readonly message?: string; readonly code?: string; readonly help?: string; readonly filename?: string; readonly labels?: readonly LintLabel[] }
83
+ const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value);
84
+ const textOrNull = (value: unknown): string | null => (typeof value === 'string' && value !== '' ? value : null);
85
+
86
+ function lintRefusal(raw: LintDiagnostic): StepRefusal {
87
+ const span = raw.labels?.[0]?.span, file = typeof raw.filename === 'string' ? raw.filename : undefined;
88
+ const where = file === undefined ? undefined : span?.line === undefined ? file : `${file}:${span.line}:${span.column ?? 1}`;
89
+ return { message: textOrNull(raw.message) ?? 'lint refusal', lint: { code: textOrNull(raw.code), help: textOrNull(raw.help) }, ...(where === undefined ? {} : { file: where }) };
90
+ }
91
+
92
+ /** Read `oxlint --format json`: each diagnostic becomes a refusal; no linted file is a skip, never a pass. */
93
+ export function lintOutcome(stdout: string, exitCode: number | null): StepOutcome {
94
+ if (stdout.includes('No files found to lint')) return { status: 'skip', note: 'oxlint found no files to lint here (a git-ignored path?)' };
95
+ let parsed: unknown;
96
+ try { parsed = JSON.parse(stdout); }
97
+ catch { return { status: 'fail', refusals: [{ message: `oxlint exited ${String(exitCode)} without a report` }] }; }
98
+ if (!isRecord(parsed) || !Array.isArray(parsed['diagnostics'])) return { status: 'fail', refusals: [{ message: 'oxlint report has no diagnostics' }] };
99
+ const diagnostics: readonly unknown[] = parsed['diagnostics'];
100
+ const refusals = diagnostics.filter(isRecord).map(row => lintRefusal(row));
101
+ if (parsed['number_of_files'] === 0) return { status: 'skip', note: 'oxlint found no files to lint here (a git-ignored path?)' };
102
+ return refusals.length === 0 && exitCode === 0 ? { status: 'pass' } : { status: 'fail', refusals };
103
+ }
104
+
105
+ const SECONDS = 1000;
106
+ /** The plain-text form: one line per step, each refusal and warning with its rule, fix and guide link, then the verdict. */
107
+ export function checkLines(result: CheckResult): string[] {
108
+ const lines = result.steps.map(step => `${step.name.padEnd(8)} ${step.status} (${(step.ms / SECONDS).toFixed(1)} s)${step.note === undefined ? '' : `: ${step.note}`}`);
109
+ for (const refusal of result.refusals) {
110
+ lines.push(` ${refusal.step}${refusal.file === undefined ? '' : ` ${refusal.file}`}: ${refusal.message}`, ` ${refusalHint(refusal)}`);
111
+ }
112
+ for (const warning of result.warnings) {
113
+ lines.push(` ${warning.step}: warning: ${warning.message}`, ` ${refusalHint(warning)}`);
114
+ }
115
+ lines.push(`check ${result.verdict} in ${(result.ms / SECONDS).toFixed(1)} s`);
116
+ return lines;
117
+ }
@@ -0,0 +1,126 @@
1
+ // The real steps behind `wildshard check` (SA4); check.ts runs them in order and gives the verdict.
2
+ // oxlint-disable-next-line import/no-nodejs-modules -- Lint runs the SDK's own oxlint as a child process.
3
+ import { spawnSync } from 'node:child_process';
4
+ // oxlint-disable-next-line import/no-nodejs-modules -- The author proof tape is an explicit local input file.
5
+ import { existsSync, readFileSync } from 'node:fs';
6
+ // oxlint-disable-next-line import/no-nodejs-modules -- Find oxlint the way this installed package resolves it.
7
+ import { createRequire } from 'node:module';
8
+ // oxlint-disable-next-line import/no-nodejs-modules -- Resolve the project, its output and the SDK's lint config.
9
+ import { basename, dirname, resolve } from 'node:path';
10
+ import * as v from 'valibot';
11
+ import { AuthorProofPlanSchema } from '@wildshard/engine/host/tickProtocol';
12
+ import { measureSimulation, proveAuthorSimulation } from '@wildshard/engine/host/headless';
13
+ import type { Shardfile } from '@wildshard/engine/host/shardfile';
14
+ import { buildProject } from './project';
15
+ import { isHandwrittenSource, isRepoSource, shardOutputRoot } from './shardSource';
16
+ import { handwrittenIdentity, settleHandwritten } from './handwritten';
17
+ import { validateOutputProduct } from './outputProduct';
18
+ import { performanceReport, type PerformanceObservations } from './reportCard';
19
+ import { lintOutcome, runCheck, type CheckResult, type StepOutcome } from './check';
20
+ import type { ProjectManifestSource } from './projectManifest';
21
+ import { authorErrorText } from './authorError';
22
+ import { DRAFT_SDK, draftMessage } from './draft';
23
+
24
+ /** The author proof tape `check` runs when the project has one (format: `AuthorProofPlanSchema`). */
25
+ export const PROOF_FILE = 'proof.json';
26
+ /** The author proof tape at `path`; its refusal names the file first, so it reads as the tape's (SA21). */
27
+ export function readProofTape(path: string): v.InferOutput<typeof AuthorProofPlanSchema> {
28
+ try { return v.parse(AuthorProofPlanSchema, JSON.parse(readFileSync(path, 'utf8'))); }
29
+ catch (error) { throw new Error(`${basename(path)}: ${authorErrorText(error)}`, { cause: error }); }
30
+ }
31
+ const unmeasured: PerformanceObservations = { scripts: { p95Micros: 0, maxMicros: 0, samples: 0 }, fuel: { p95: 0, max: 0, samples: 0 } };
32
+ // The bundled CLI defines import.meta.dirname as the package's src/sharddev, so the package root is two up.
33
+ const SDK_ROOT = resolve(import.meta.dirname, '../..');
34
+ const LINT_CONFIG = resolve(SDK_ROOT, '.oxlintrc.author.json');
35
+
36
+ function oxlintBin(): string | undefined {
37
+ try {
38
+ const manifest = createRequire(resolve(SDK_ROOT, 'package.json')).resolve('oxlint/package.json');
39
+ const bin = resolve(dirname(manifest), 'bin/oxlint');
40
+ return existsSync(bin) ? bin : undefined;
41
+ } catch { return undefined; }
42
+ }
43
+
44
+ /** The SDK's author lint (`.oxlintrc.author.json` and its wildshard rules) over the project's source. */
45
+ function lintProject(project: string): StepOutcome {
46
+ const bin = oxlintBin();
47
+ if (bin === undefined || !existsSync(LINT_CONFIG)) return { status: 'skip', note: 'the author lint (oxlint and .oxlintrc.author.json) is not installed with this @wildshard/sdk' };
48
+ // The jsPlugins resolve engine from the working directory: run from the SDK root, as `pnpm lint:author` does.
49
+ const done = spawnSync(bin, ['-c', LINT_CONFIG, '--format', 'json', project], { cwd: SDK_ROOT, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
50
+ if (done.error !== undefined) return { status: 'fail', refusals: [{ message: `oxlint did not run: ${done.error.message}` }] };
51
+ return lintOutcome(`${done.stdout}${done.stdout.trim() === '' ? done.stderr : ''}`, done.status);
52
+ }
53
+
54
+ /** J198: a built folder whose index says sdk 0.2 is a draft; upload refuses it until `wildshard prepare` runs. */
55
+ function isDraft(folder: string): boolean {
56
+ const index: unknown = JSON.parse(readFileSync(resolve(folder, 'shard.json'), 'utf8'));
57
+ return typeof index === 'object' && index !== null && 'sdk' in index && index.sdk === DRAFT_SDK;
58
+ }
59
+
60
+ interface Admitted { readonly shard: Shardfile; readonly observed: PerformanceObservations; readonly policy: 'warn' | 'refuse' }
61
+ export interface CheckOptions { readonly decisionLegacyLines?: number; readonly manifest?: ProjectManifestSource; readonly writeShardfile?: (folder: string, source: string, options?: { readonly draftWarning?: boolean }) => Promise<string> }
62
+
63
+ /** Lint, build (no client; the shard file too, SA3), validate the built folder, prove its tape and read its report card. */
64
+ export async function checkProject(projectPath: string, outputPath: string | undefined, options: CheckOptions = {}): Promise<CheckResult> {
65
+ const project = resolve(projectPath);
66
+ let output = outputPath === undefined ? undefined : resolve(outputPath), admitted: Admitted | undefined;
67
+ const admit = async (shard: Shardfile, assets: ReadonlyMap<string, Uint8Array>, policy: 'warn' | 'refuse', sections: ReadonlyMap<string, unknown>): Promise<void> => {
68
+ // Native hybrids need their trusted recipes for a meaningful measurement; never invent one (as `build` does).
69
+ const observed = shard.runtime === null ? await measureSimulation(shard, assets, undefined, sections) : unmeasured;
70
+ admitted = { shard, observed, policy };
71
+ };
72
+ // SA16 (J314): a hand-written source (`--template blender`) has nothing to build: format's pack settles it into the
73
+ // built folder, which is then admitted as a built shard is.
74
+ const handwritten = isHandwrittenSource(project);
75
+ const settleInto = async (source: string): Promise<Shardfile> => {
76
+ // Its build output goes beside src/, never inside the folder pack reads (or a built folder named as a source).
77
+ if (!isRepoSource(source)) throw new Error(`${source}: a hand-written shard file builds only from a repo's src/: run wildshard check on the repo`);
78
+ output ??= resolve(shardOutputRoot(source), 'public/shardfiles', handwrittenIdentity(source).slug);
79
+ settleHandwritten(source, output);
80
+ const checked = validateOutputProduct(output);
81
+ await admit(checked.shard, checked.assets, checked.shard.runtime === null ? 'refuse' : 'warn', checked.sections);
82
+ return checked.shard;
83
+ };
84
+ const built = (): string => {
85
+ if (output === undefined) throw new Error('no built shard file folder');
86
+ return output;
87
+ };
88
+ return await runCheck(project, (): string | null => output ?? null, {
89
+ lint: async (): Promise<StepOutcome> => await Promise.resolve(handwritten
90
+ ? { status: 'skip', note: 'a hand-written shard file: no code to lint' } : lintProject(project)),
91
+ build: async (): Promise<StepOutcome> => {
92
+ const shard = handwritten ? await settleInto(project) : await buildProject(project, output, { outputFormat: 2, client: null, placeholders: true, admit,
93
+ ...(options.decisionLegacyLines === undefined ? {} : { decisionLegacyLines: options.decisionLegacyLines }),
94
+ ...(options.manifest === undefined ? {} : { manifest: options.manifest }) });
95
+ output ??= resolve(shardOutputRoot(project), 'public/shardfiles', shard.identity.slug);
96
+ let file: string | undefined;
97
+ // The draft warning goes in the verdict (below), so the writer leaves it out.
98
+ try { file = await options.writeShardfile?.(output, project, { draftWarning: false }); }
99
+ catch (error) { return { status: 'fail', refusals: [{ message: authorErrorText(error), as: 'shardfile' }] }; }
100
+ const warnings = isDraft(output) ? [{ message: draftMessage(shard.identity.slug), as: 'shardfile' as const }] : [];
101
+ return { status: 'pass', note: `built ${shard.identity.slug} v${shard.version}${file === undefined ? '' : `, ${file}`}`, warnings };
102
+ },
103
+ validate: async (): Promise<StepOutcome> => {
104
+ const checked = validateOutputProduct(built());
105
+ return await Promise.resolve({ status: 'pass', note: `${checked.shard.identity.slug}: format 2 inventory, byte kinds and section schemas` });
106
+ },
107
+ prove: async (): Promise<StepOutcome> => {
108
+ const tape = resolve(project, PROOF_FILE);
109
+ if (!existsSync(tape)) return { status: 'skip', note: `no ${PROOF_FILE}: add an author proof tape to prove the shard's quests` };
110
+ const { shard, assets } = validateOutputProduct(built());
111
+ if (shard.runtime !== null) return { status: 'skip', note: 'native gameplay: the author proof needs data-only gameplay' };
112
+ const plan = readProofTape(tape);
113
+ const report = await proveAuthorSimulation(shard, assets, plan);
114
+ return { status: 'pass', note: `${report.ticks} ticks, ${report.ledger.facts.length} facts filed` };
115
+ },
116
+ report: async (): Promise<StepOutcome> => {
117
+ if (admitted === undefined) throw new Error('the build admitted no shard to report on');
118
+ const card = performanceReport(admitted.shard, admitted.observed, admitted.policy);
119
+ const refused = card.issues.filter(issue => issue.severity === 'refusal');
120
+ const warnings = card.issues.length - refused.length;
121
+ const note = `${(card.download.total / 1024 / 1024).toFixed(2)} MB download, ~${card.estimatedPlayable.seconds.toFixed(1)} s to playable, ${warnings} warning${warnings === 1 ? '' : 's'}`;
122
+ return await Promise.resolve({ status: card.pass ? 'pass' : 'fail', note,
123
+ refusals: refused.map(issue => ({ message: `${issue.metric}: ${String(issue.actual)} over ${String(issue.limit)}` })) });
124
+ },
125
+ });
126
+ }