@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.
- package/GUIDE.md +790 -0
- package/README.md +14 -4
- package/bin/wildshard.mjs +38 -0
- package/lint/declaration-config.d.mts +2 -0
- package/lint/declaration-config.mjs +19 -0
- package/lint/engine-plugin.d.mts +2 -0
- package/lint/engine-plugin.mjs +40 -0
- package/lint/host-callbacks.d.mts +6 -0
- package/lint/host-callbacks.mjs +123 -0
- package/lint/host-files.d.mts +1 -0
- package/lint/host-files.mjs +7 -0
- package/lint/layer-exports.d.mts +2 -0
- package/lint/layer-exports.mjs +21 -0
- package/lint/legacy-line-basis.json +995 -0
- package/lint/nine-tiling-baseline.json +35 -0
- package/lint/ratchet.json +11 -0
- package/lint/runtime-files.d.mts +12 -0
- package/lint/runtime-files.json +16 -0
- package/lint/runtime-files.mjs +69 -0
- package/lint/runtime-performance.d.mts +6 -0
- package/lint/runtime-performance.mjs +184 -0
- package/lint/sdk-plugin.d.mts +4 -0
- package/lint/sdk-plugin.mjs +134 -0
- package/lint/shardfile-boundaries.d.mts +10 -0
- package/lint/shardfile-boundaries.mjs +122 -0
- package/lint/tile-bake-debt.json +556 -0
- package/package.json +371 -4
- package/scripts/agent-parity.mjs +1524 -0
- package/scripts/agent-sync.mjs +518 -0
- package/scripts/apfs-clone.mjs +67 -0
- package/scripts/assert-store-layout.mjs +23 -0
- package/scripts/astc6-phone-cap.d.mts +3 -0
- package/scripts/astc6-phone-cap.mjs +137 -0
- package/scripts/audit-assets.d.mts +10 -0
- package/scripts/audit-assets.mjs +151 -0
- package/scripts/bake/coatFiles.d.mts +6 -0
- package/scripts/bake/coatFiles.mjs +37 -0
- package/scripts/bake/environment.d.mts +2 -0
- package/scripts/bake/environment.mjs +58 -0
- package/scripts/bake/far-proxies.mjs +45 -0
- package/scripts/bake/keyed-sky.d.mts +4 -0
- package/scripts/bake/keyed-sky.mjs +34 -0
- package/scripts/bake/movers.mjs +56 -0
- package/scripts/bake/nativeWorld.d.mts +6 -0
- package/scripts/bake/nativeWorld.mjs +43 -0
- package/scripts/bake/navmeshGround.ts +22 -0
- package/scripts/bake/near-placeholder.mjs +331 -0
- package/scripts/bake/placeholderShards.mjs +41 -0
- package/scripts/bake/skins.mjs +15 -0
- package/scripts/bake/template-skins.mjs +33 -0
- package/scripts/bake/viewmodelBytes.ts +26 -0
- package/scripts/bake/viewmodelPage.ts +11 -0
- package/scripts/bake/worldHost.d.mts +35 -0
- package/scripts/bake/worldHost.mjs +110 -0
- package/scripts/bake-astc6.cache.json +80 -0
- package/scripts/bake-astc6.far-reach.cache.json +23 -0
- package/scripts/bake-astc6.list.json +111 -0
- package/scripts/bake-astc6.mjs +279 -0
- package/scripts/bake-astc6.nalati-grasslands.cache.json +42 -0
- package/scripts/bake-catalogue.mjs +44 -0
- package/scripts/bake-check.mjs +54 -0
- package/scripts/bake-chunk.mjs +124 -0
- package/scripts/bake-cloud-field.mjs +24 -0
- package/scripts/bake-coats.mjs +110 -0
- package/scripts/bake-data-maps.d.mts +24 -0
- package/scripts/bake-data-maps.mjs +72 -0
- package/scripts/bake-entry-programs.mjs +117 -0
- package/scripts/bake-geometry.mjs +106 -0
- package/scripts/bake-hybrid-tiles.mjs +28 -0
- package/scripts/bake-ktx2.cache.json +276 -0
- package/scripts/bake-ktx2.list.json +365 -0
- package/scripts/bake-ktx2.mjs +477 -0
- package/scripts/bake-map-glb.mjs +127 -0
- package/scripts/bake-map-rest.d.mts +7 -0
- package/scripts/bake-map-rest.mjs +50 -0
- package/scripts/bake-maps.mjs +200 -0
- package/scripts/bake-navmesh.mjs +259 -0
- package/scripts/bake-packs.mjs +129 -0
- package/scripts/bake-pickups.mjs +102 -0
- package/scripts/bake-query-terrain.mjs +64 -0
- package/scripts/bake-recurve-pool.mjs +16 -0
- package/scripts/bake-section-schemas.d.mts +3 -0
- package/scripts/bake-template-shardfile.mjs +32 -0
- package/scripts/bake-textures.mjs +80 -0
- package/scripts/bake-viewmodel-sets.json +45 -0
- package/scripts/bake-viewmodel-sets.mjs +137 -0
- package/scripts/bake-voxel-ao.mjs +119 -0
- package/scripts/bake-water-ripples.mjs +25 -0
- package/scripts/blender/README.md +129 -0
- package/scripts/blender/build.sh +166 -0
- package/scripts/blender/lib/export-scene.mjs +129 -0
- package/scripts/blender/lib/glb-digest.mjs +188 -0
- package/scripts/blender/lib/glb.py +68 -0
- package/scripts/blender/lib/save_blend.py +17 -0
- package/scripts/blender/lib/world_fixture.py +55 -0
- package/scripts/blender/targets.json +591 -0
- package/scripts/build-sdk.mjs +95 -0
- package/scripts/build-shardfiles.d.mts +7 -0
- package/scripts/build-shardfiles.mjs +206 -0
- package/scripts/capture-hero.mjs +137 -0
- package/scripts/check-lift-review.mjs +23 -0
- package/scripts/chromium-keychain-check.mjs +139 -0
- package/scripts/chromium-keychain.d.mts +1 -0
- package/scripts/chromium-keychain.mjs +5 -0
- package/scripts/compile-script.d.mts +3 -0
- package/scripts/compile-script.mjs +8 -0
- package/scripts/creature-color.mjs +255 -0
- package/scripts/decide/calibrate.py +127 -0
- package/scripts/decide/calibration/2026-10-03/labels-s1.tsv +281 -0
- package/scripts/decide/calibration/2026-10-03/labels-s2.tsv +97 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3.tsv +48 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3b.tsv +26 -0
- package/scripts/decide/calibration/2026-10-03/res-capture-status-v1.jsonl +376 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-strings.jsonl +48 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-v1.jsonl +73 -0
- package/scripts/decide/decide.py +262 -0
- package/scripts/decide/decide.sh +50 -0
- package/scripts/decide/layer-purity-pilot.mjs +41 -0
- package/scripts/decide/sets/capture-status.json +46 -0
- package/scripts/decide/sets/layer-purity.json +28 -0
- package/scripts/decide/sets/text-garbled.json +17 -0
- package/scripts/decide/test_decide.py +37 -0
- package/scripts/docs.mjs +15 -0
- package/scripts/entry-reads/crawl.ts +152 -0
- package/scripts/entry-reads/tsconfig.json +25 -0
- package/scripts/gen-format-schema.d.mts +2 -0
- package/scripts/gen-format-schema.mjs +21 -0
- package/scripts/gen-host-catalogue.d.mts +14 -0
- package/scripts/gen-host-catalogue.mjs +108 -0
- package/scripts/gen-shard-layout-doc.d.mts +4 -0
- package/scripts/gen-shard-layout-doc.mjs +55 -0
- package/scripts/gen-shards.d.mts +17 -0
- package/scripts/gen-shards.mjs +311 -0
- package/scripts/goldens/capture-inputs.d.mts +4 -0
- package/scripts/goldens/capture-inputs.mjs +34 -0
- package/scripts/goldens/colour_shift.py +27 -0
- package/scripts/goldens/native-residency.d.mts +10 -0
- package/scripts/goldens/native-residency.mjs +104 -0
- package/scripts/goldens/plot-inputs.d.mts +12 -0
- package/scripts/goldens/plot-inputs.mjs +46 -0
- package/scripts/gpu-texmem.mjs +98 -0
- package/scripts/horizon-matte/config.py +24 -0
- package/scripts/horizon-matte/encode.py +91 -0
- package/scripts/horizon-matte/key.py +141 -0
- package/scripts/horizon-matte/mkjobs.py +33 -0
- package/scripts/horizon-matte/mkjobs_day2.py +11 -0
- package/scripts/horizon-matte/overlap.py +80 -0
- package/scripts/horizon-matte/run_codex.py +57 -0
- package/scripts/horizon-matte/stitch.py +133 -0
- package/scripts/img2mesh/CC0.md +105 -0
- package/scripts/img2mesh/README.md +209 -0
- package/scripts/img2mesh/ab_board.py +102 -0
- package/scripts/img2mesh/birds/birds.json +255 -0
- package/scripts/img2mesh/birds/birds_atlas.py +150 -0
- package/scripts/img2mesh/birds/birds_fix_preview.mjs +103 -0
- package/scripts/img2mesh/birds/birds_fix_render.py +75 -0
- package/scripts/img2mesh/birds/birds_pack.py +110 -0
- package/scripts/img2mesh/birds/birds_phone_b.py +112 -0
- package/scripts/img2mesh/birds/birds_post.py +550 -0
- package/scripts/img2mesh/birds/birds_render.py +125 -0
- package/scripts/img2mesh/birds/birds_sheet.py +33 -0
- package/scripts/img2mesh/birds/birds_view.py +60 -0
- package/scripts/img2mesh/board.py +100 -0
- package/scripts/img2mesh/build_cc0.sh +52 -0
- package/scripts/img2mesh/build_driftwood.sh +12 -0
- package/scripts/img2mesh/build_faces.sh +53 -0
- package/scripts/img2mesh/build_props.py +81 -0
- package/scripts/img2mesh/cc0_export.py +186 -0
- package/scripts/img2mesh/driftwood_post.py +571 -0
- package/scripts/img2mesh/e304_faces.sh +67 -0
- package/scripts/img2mesh/face_remaster.py +911 -0
- package/scripts/img2mesh/face_views.py +95 -0
- package/scripts/img2mesh/faces-e304.json +9 -0
- package/scripts/img2mesh/faces.json +30 -0
- package/scripts/img2mesh/head_cut.py +100 -0
- package/scripts/img2mesh/hi3d_paint.py +94 -0
- package/scripts/img2mesh/hi3d_refine.py +161 -0
- package/scripts/img2mesh/hunyuan_cpu_rasterizer.sh +42 -0
- package/scripts/img2mesh/pine_hollow_phone.sh +13 -0
- package/scripts/img2mesh/props/coral-arch.json +32 -0
- package/scripts/img2mesh/props/ember-furnace.json +30 -0
- package/scripts/img2mesh/props/night-market-gate.json +10 -0
- package/scripts/img2mesh/render_still.py +86 -0
- package/scripts/img2mesh/rig_strip.mjs +46 -0
- package/scripts/img2mesh/rig_transfer.mjs +104 -0
- package/scripts/img2mesh/split_sheet.py +48 -0
- package/scripts/img2mesh/trellis_batch.py +110 -0
- package/scripts/img2mesh/versus_board.py +114 -0
- package/scripts/import-bundle.d.mts +2 -0
- package/scripts/import-bundle.mjs +20 -0
- package/scripts/ktx2-ab-board.py +133 -0
- package/scripts/ktx2-ab.mjs +111 -0
- package/scripts/ktx2-settings.mjs +18 -0
- package/scripts/land.d.mts +14 -0
- package/scripts/land.mjs +809 -0
- package/scripts/lint-dispatch.mjs +14 -0
- package/scripts/map-bake-frames.d.mts +4 -0
- package/scripts/map-bake-frames.mjs +23 -0
- package/scripts/map-geometry.d.mts +9 -0
- package/scripts/map-geometry.mjs +29 -0
- package/scripts/map-world.mjs +162 -0
- package/scripts/mockup-local.sh +46 -0
- package/scripts/music/export-midi.mjs +68 -0
- package/scripts/music/gen/analyze.py +308 -0
- package/scripts/music/gen/audio_jobs.py +46 -0
- package/scripts/music/gen/briefs.json +51 -0
- package/scripts/music/gen/build_page.py +334 -0
- package/scripts/music/gen/folk.json +3187 -0
- package/scripts/music/gen/gen_ace_step.py +156 -0
- package/scripts/music/gen/gen_heartmula.py +187 -0
- package/scripts/music/gen/gen_minimax.py +143 -0
- package/scripts/music/gen/gen_sao.py +122 -0
- package/scripts/music/gen/gen_sao_small.py +104 -0
- package/scripts/music/gen/gen_sfx.py +98 -0
- package/scripts/music/gen/gen_sfx_ezaudio.py +112 -0
- package/scripts/music/gen/gen_sfx_moss.py +112 -0
- package/scripts/music/gen/models.json +61 -0
- package/scripts/music/gen/nalati-jobs.json +104 -0
- package/scripts/music/gen/nalati-score-build.json +119 -0
- package/scripts/music/gen/nalati-score.json +3448 -0
- package/scripts/music/gen/ob7-fit-decisions.json +38 -0
- package/scripts/music/gen/ob7-score-jobs.json +152 -0
- package/scripts/music/gen/ob7-sfx-jobs.json +897 -0
- package/scripts/music/gen/ob7_build.py +469 -0
- package/scripts/music/gen/ob7_generate.py +67 -0
- package/scripts/music/gen/ob7_run.sh +42 -0
- package/scripts/music/gen/orchestral.json +3187 -0
- package/scripts/music/gen/own_score.py +486 -0
- package/scripts/music/gen/ph-jobs.json +27 -0
- package/scripts/music/gen/ph_page.py +222 -0
- package/scripts/music/gen/piano.json +3175 -0
- package/scripts/music/gen/rank_v3.py +248 -0
- package/scripts/music/gen/sfx-best.json +2486 -0
- package/scripts/music/gen/sfx-ezaudio.json +4082 -0
- package/scripts/music/gen/sfx-jobs.json +57 -0
- package/scripts/music/gen/sfx-minimax-jobs.json +16 -0
- package/scripts/music/gen/sfx-minimax.json +289 -0
- package/scripts/music/gen/sfx-moss.json +4082 -0
- package/scripts/music/gen/sfx-nalati-b3-jobs.json +17 -0
- package/scripts/music/gen/sfx-nalati-jobs.json +338 -0
- package/scripts/music/gen/sfx-nalati.json +11202 -0
- package/scripts/music/gen/sfx-nd-jobs.json +57 -0
- package/scripts/music/gen/sfx-nd-moss.json +2097 -0
- package/scripts/music/gen/sfx-nd-sa3-medium.json +2097 -0
- package/scripts/music/gen/sfx-nd-summary.json +38 -0
- package/scripts/music/gen/sfx-peaks.json +7 -0
- package/scripts/music/gen/sfx-ph-jobs.json +169 -0
- package/scripts/music/gen/sfx-ph-moss.json +6564 -0
- package/scripts/music/gen/sfx-ph-sa3-medium.json +7239 -0
- package/scripts/music/gen/sfx-ph-summary.json +63 -0
- package/scripts/music/gen/sfx-sa3-medium.json +4082 -0
- package/scripts/music/gen/sfx-sa3.json +4082 -0
- package/scripts/music/gen/sfx-summary.json +107 -0
- package/scripts/music/gen/sfx_build.py +332 -0
- package/scripts/music/gen/sfx_merge.py +255 -0
- package/scripts/music/gen/sfx_minimax.py +61 -0
- package/scripts/music/gen/sfx_nalati.py +331 -0
- package/scripts/music/gen/sfx_sprite.py +424 -0
- package/scripts/music/gen/stems.py +539 -0
- package/scripts/music/gen/test_loop_meter.py +29 -0
- package/scripts/music/gen/test_ob7_provenance.py +77 -0
- package/scripts/music/gen/v3-folk-build.json +148 -0
- package/scripts/music/gen/v3-folk.json +1818 -0
- package/scripts/music/gen/v3-jobs.json +145 -0
- package/scripts/music/gen/v3-orchestral-build.json +148 -0
- package/scripts/music/gen/v3-orchestral.json +1813 -0
- package/scripts/music/gen/v3-ph-folk-build.json +94 -0
- package/scripts/music/gen/v3-ph-folk.json +1806 -0
- package/scripts/music/gen/v3-ph-orchestral-build.json +94 -0
- package/scripts/music/gen/v3-ph-orchestral.json +1824 -0
- package/scripts/music/gen/v3-ph-piano-build.json +94 -0
- package/scripts/music/gen/v3-ph-piano.json +1818 -0
- package/scripts/music/gen/v3-piano-build.json +148 -0
- package/scripts/music/gen/v3-piano.json +1813 -0
- package/scripts/music/wildshard-theme.mid +0 -0
- package/scripts/music/wildshard-trailer30.mid +0 -0
- package/scripts/named-blob-output.d.mts +8 -0
- package/scripts/named-blob-output.mjs +48 -0
- package/scripts/pack-all.mjs +15 -0
- package/scripts/pid-lock.d.mts +1 -0
- package/scripts/pid-lock.mjs +63 -0
- package/scripts/practice/bake_dummy.py +53 -0
- package/scripts/practice/build_dummies.sh +43 -0
- package/scripts/practice/dummy_parts.py +568 -0
- package/scripts/practice/dummy_rig_gate.py +139 -0
- package/scripts/practice/gate_sheet.py +36 -0
- package/scripts/practice/generate_dummy_unimate.py +132 -0
- package/scripts/practice/pack_dummy.mjs +59 -0
- package/scripts/practice/repair_dummy_weights.mjs +68 -0
- package/scripts/practice/rig_dummy.py +828 -0
- package/scripts/practice/verify_unimate_skin.mjs +356 -0
- package/scripts/preparation-seed.mjs +15 -0
- package/scripts/prepare-basis-tool.mjs +6 -0
- package/scripts/prepare-product.d.mts +14 -0
- package/scripts/prepare-product.mjs +101 -0
- package/scripts/product-build-tools.d.mts +3 -0
- package/scripts/product-build-tools.json +3 -0
- package/scripts/product-build-tools.mjs +31 -0
- package/scripts/publish-public.mjs +7 -0
- package/scripts/push-tables.d.mts +1 -0
- package/scripts/push-tables.mjs +28 -0
- package/scripts/record-shard-mounts.mjs +133 -0
- package/scripts/sdk-externals.d.mts +2 -0
- package/scripts/sdk-externals.mjs +2 -0
- package/scripts/section-inventory.ts +209 -0
- package/scripts/select-candidate.mjs +15 -0
- package/scripts/shard-build-pool.d.mts +4 -0
- package/scripts/shard-build-pool.mjs +53 -0
- package/scripts/shard-line-baseline.json +17 -0
- package/scripts/shard-milestones.d.mts +15 -0
- package/scripts/shard-milestones.mjs +105 -0
- package/scripts/shard-output-report.d.mts +9 -0
- package/scripts/shard-output-report.mjs +85 -0
- package/scripts/shard-platform-cli.mjs +93 -0
- package/scripts/shard-progress.mjs +212 -0
- package/scripts/shard-timelapse.py +102 -0
- package/scripts/shardfile-cold-boot.mjs +79 -0
- package/scripts/shardfile-vite.d.mts +4 -0
- package/scripts/shardfile-vite.mjs +20 -0
- package/scripts/simplify-models.mjs +24 -0
- package/scripts/site-facts.mjs +88 -0
- package/scripts/test-template-gate.mjs +44 -0
- package/scripts/test_golden_compare.py +68 -0
- package/scripts/tex-tiers.cache.json +181 -0
- package/scripts/tex-tiers.mjs +240 -0
- package/scripts/texmem-probe.mjs +184 -0
- package/scripts/unused-assets.mjs +173 -0
- package/scripts/vite-tmp.d.mts +23 -0
- package/scripts/vite-tmp.mjs +157 -0
- package/scripts/wave-line-baselines.json +32 -0
- package/scripts/wildshard.d.mts +4 -0
- package/scripts/wildshard.mjs +105 -0
- package/scripts/witness-checkpoints.d.mts +10 -0
- package/scripts/witness-checkpoints.mjs +84 -0
- package/scripts/witness-generation.d.mts +10 -0
- package/scripts/witness-generation.mjs +45 -0
- package/scripts/witness-manifests.d.mts +8 -0
- package/scripts/witness-manifests.mjs +157 -0
- package/scripts/worktree-ignore.d.mts +4 -0
- package/scripts/worktree-ignore.mjs +36 -0
- package/scripts/worktree-reap.mjs +214 -0
- package/scripts/worktree.mjs +396 -0
- package/scripts/worldclaw/capture-front.sh +28 -0
- package/scripts/worldclaw/design-template.md +62 -0
- package/scripts/worldclaw/spec-map.py +92 -0
- package/scripts/worldclaw/spec.ts +96 -0
- package/skills/wildshard/SKILL.md +50 -0
- package/skills/wildshard-goldens/SKILL.md +54 -0
- package/skills/wildshard-mockup-to-model/SKILL.md +56 -0
- package/skills/wildshard-upgrade/SKILL.md +46 -0
- package/src/.oxfmtrc.json +50 -0
- package/src/.oxlintrc.json +173 -0
- package/src/cli/account/account.ts +199 -0
- package/src/cli/account/command.ts +193 -0
- package/src/cli/account/key.ts +154 -0
- package/src/cli/args.ts +97 -0
- package/src/cli/audio/audio.ts +24 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/delete/delete.ts +258 -0
- package/src/cli/help.ts +196 -0
- package/src/cli/hero/adopt.ts +103 -0
- package/src/cli/hero/hero.ts +112 -0
- package/src/cli/hero/stamp.ts +298 -0
- package/src/cli/main.ts +292 -0
- package/src/cli/report.ts +16 -0
- package/src/cli/shardfile/command.ts +50 -0
- package/src/cli/shardfile/shardfile.ts +192 -0
- package/src/cli/upload/api.ts +246 -0
- package/src/cli/upload/compress.ts +55 -0
- package/src/cli/upload/hero.ts +62 -0
- package/src/cli/upload/placement.ts +115 -0
- package/src/cli/upload/provenance.ts +192 -0
- package/src/cli/upload/signature.ts +30 -0
- package/src/cli/upload/upload.ts +269 -0
- package/src/cli/upload/validate.ts +74 -0
- package/src/cli/upload/wire.ts +147 -0
- package/src/cli/version.ts +63 -0
- package/src/commons/bake/portableMath.ts +187 -0
- package/src/commons/catalogue.ts +10 -0
- package/src/commons/courseProgram.ts +32 -0
- package/src/commons/practiceCourse.ts +16 -0
- package/src/commons/scripts/abi.as +14 -0
- package/src/commons/scripts/bridge.as +14 -0
- package/src/commons/scripts/course.as +63 -0
- package/src/scripts/ask-new.sh +29 -0
- package/src/scripts/asks.mjs +141 -0
- package/src/scripts/herdr-prompt.sh +34 -0
- package/src/scripts/herdr-question-open.sh +67 -0
- package/src/scripts/md-wrap.mjs +229 -0
- package/src/server/app.ts +19 -0
- package/src/server/serve.ts +49 -0
- package/src/sharddev/admission.ts +7 -0
- package/src/sharddev/arenaView.ts +15 -0
- package/src/sharddev/as/groupBankV2.ts +36 -0
- package/src/sharddev/as/groupStepV2.ts +13 -0
- package/src/sharddev/as/ws.ts +30 -0
- package/src/sharddev/as/wsV2.ts +180 -0
- package/src/sharddev/assemblyscriptCompiler.d.mts +5 -0
- package/src/sharddev/assemblyscriptCompiler.mjs +14 -0
- package/src/sharddev/assetHandle.ts +84 -0
- package/src/sharddev/assetOwner.ts +70 -0
- package/src/sharddev/assetScope.ts +30 -0
- package/src/sharddev/assets.ts +21 -0
- package/src/sharddev/audio.ts +9 -0
- package/src/sharddev/audioEncode.ts +211 -0
- package/src/sharddev/author.ts +3 -0
- package/src/sharddev/authorError.ts +28 -0
- package/src/sharddev/authorManifest.ts +39 -0
- package/src/sharddev/bake/annulus.ts +19 -0
- package/src/sharddev/bake/assemblyscriptMemo.ts +76 -0
- package/src/sharddev/bake/assemblyscriptMemoPort.ts +4 -0
- package/src/sharddev/bake/authoredWorld.ts +201 -0
- package/src/sharddev/bake/basisEncoder.ts +95 -0
- package/src/sharddev/bake/basisGlb.ts +85 -0
- package/src/sharddev/bake/basisTool.ts +74 -0
- package/src/sharddev/bake/basisToolInputs.ts +476 -0
- package/src/sharddev/bake/byteCodec.ts +33 -0
- package/src/sharddev/bake/canvasAtlas.ts +406 -0
- package/src/sharddev/bake/coarseCopy.ts +59 -0
- package/src/sharddev/bake/colliders.ts +87 -0
- package/src/sharddev/bake/compactGlb.ts +224 -0
- package/src/sharddev/bake/compileScript.ts +119 -0
- package/src/sharddev/bake/compileScriptV2.ts +75 -0
- package/src/sharddev/bake/contactRows.ts +84 -0
- package/src/sharddev/bake/creaturePlacement.ts +117 -0
- package/src/sharddev/bake/export.ts +67 -0
- package/src/sharddev/bake/facetedGeometry.ts +379 -0
- package/src/sharddev/bake/farImpostor.ts +120 -0
- package/src/sharddev/bake/forest.ts +100 -0
- package/src/sharddev/bake/format-hook.mjs +2 -0
- package/src/sharddev/bake/generatorGlb.ts +23 -0
- package/src/sharddev/bake/geometryBounds.ts +77 -0
- package/src/sharddev/bake/geometryError.ts +48 -0
- package/src/sharddev/bake/glb.ts +355 -0
- package/src/sharddev/bake/glbCompression.ts +143 -0
- package/src/sharddev/bake/gltfSource.ts +59 -0
- package/src/sharddev/bake/groundMap.ts +142 -0
- package/src/sharddev/bake/image.ts +20 -0
- package/src/sharddev/bake/isleMap.ts +64 -0
- package/src/sharddev/bake/json.mjs +84 -0
- package/src/sharddev/bake/keyedSky.ts +47 -0
- package/src/sharddev/bake/keyedSkyMemo.ts +39 -0
- package/src/sharddev/bake/kinds.ts +137 -0
- package/src/sharddev/bake/lightSources.ts +31 -0
- package/src/sharddev/bake/mapAssembly.ts +84 -0
- package/src/sharddev/bake/mapRaster.ts +173 -0
- package/src/sharddev/bake/mapRest.ts +57 -0
- package/src/sharddev/bake/mapScenes.ts +234 -0
- package/src/sharddev/bake/materialGraph.ts +32 -0
- package/src/sharddev/bake/meadow.ts +27 -0
- package/src/sharddev/bake/meshoptChoiceMemo.ts +34 -0
- package/src/sharddev/bake/nativeInteractionFacts.ts +5 -0
- package/src/sharddev/bake/nativeLattice.ts +178 -0
- package/src/sharddev/bake/nativeRaster.ts +106 -0
- package/src/sharddev/bake/nativeTerrainField.ts +11 -0
- package/src/sharddev/bake/navigation-json.mjs +38 -0
- package/src/sharddev/bake/navigation.ts +113 -0
- package/src/sharddev/bake/navigationAsset.ts +18 -0
- package/src/sharddev/bake/nearPlaceholder.ts +206 -0
- package/src/sharddev/bake/normalizeRig.ts +80 -0
- package/src/sharddev/bake/phoneAstc.ts +93 -0
- package/src/sharddev/bake/placeholders.ts +581 -0
- package/src/sharddev/bake/placement.ts +80 -0
- package/src/sharddev/bake/portableBytes.ts +18 -0
- package/src/sharddev/bake/portableBytesMemo.ts +50 -0
- package/src/sharddev/bake/practiceCourse.ts +49 -0
- package/src/sharddev/bake/primitives.ts +96 -0
- package/src/sharddev/bake/props.ts +443 -0
- package/src/sharddev/bake/questPlacement.ts +98 -0
- package/src/sharddev/bake/rawTexture.ts +26 -0
- package/src/sharddev/bake/riderArms.ts +97 -0
- package/src/sharddev/bake/rig.ts +95 -0
- package/src/sharddev/bake/riggedHullRecipes.ts +40 -0
- package/src/sharddev/bake/signPlacements.ts +25 -0
- package/src/sharddev/bake/simplifier.ts +52 -0
- package/src/sharddev/bake/skinned.ts +312 -0
- package/src/sharddev/bake/slabChunks.ts +149 -0
- package/src/sharddev/bake/slabs.ts +263 -0
- package/src/sharddev/bake/source-loader.mjs +55 -0
- package/src/sharddev/bake/sourceMetadata.ts +54 -0
- package/src/sharddev/bake/species.ts +368 -0
- package/src/sharddev/bake/specimenCatalogue.ts +47 -0
- package/src/sharddev/bake/splatGround.ts +141 -0
- package/src/sharddev/bake/staticMaterials.ts +171 -0
- package/src/sharddev/bake/terrain.ts +195 -0
- package/src/sharddev/bake/texture.ts +33 -0
- package/src/sharddev/bake/textureWasm.ts +81 -0
- package/src/sharddev/bake/tileEncoder.ts +11 -0
- package/src/sharddev/bake/tileGrid.ts +62 -0
- package/src/sharddev/bake/v2Finite.ts +160 -0
- package/src/sharddev/bake/v2Fuel.ts +71 -0
- package/src/sharddev/bake/wholePartition.ts +74 -0
- package/src/sharddev/bake/wholePieceJoin.ts +147 -0
- package/src/sharddev/bake/world.ts +173 -0
- package/src/sharddev/bake/worldCollision.ts +128 -0
- package/src/sharddev/bake/worldGeometry.ts +237 -0
- package/src/sharddev/bake/worldGlb.ts +123 -0
- package/src/sharddev/bake/worldImage.ts +12 -0
- package/src/sharddev/bake/worldLod.ts +128 -0
- package/src/sharddev/bake/worldRows.ts +102 -0
- package/src/sharddev/bake/worldTextureMemo.ts +63 -0
- package/src/sharddev/bake/zstdBytesMemo.ts +52 -0
- package/src/sharddev/bake.ts +193 -0
- package/src/sharddev/bakePublication.ts +31 -0
- package/src/sharddev/behaviourSource.ts +94 -0
- package/src/sharddev/bin/wildshard.mjs +7 -0
- package/src/sharddev/blobBytes.ts +65 -0
- package/src/sharddev/blobs.ts +138 -0
- package/src/sharddev/bootInventory.ts +129 -0
- package/src/sharddev/bossProfiles.ts +18 -0
- package/src/sharddev/buildBehaviour.ts +77 -0
- package/src/sharddev/buildCacheMetrics.ts +17 -0
- package/src/sharddev/buildDecisionScripts.ts +122 -0
- package/src/sharddev/check.ts +117 -0
- package/src/sharddev/checkProject.ts +126 -0
- package/src/sharddev/cli.ts +191 -0
- package/src/sharddev/clientChannels.ts +169 -0
- package/src/sharddev/clientScripts.ts +10 -0
- package/src/sharddev/commons.ts +77 -0
- package/src/sharddev/commonsCosts.ts +11 -0
- package/src/sharddev/compileMovers.ts +11 -0
- package/src/sharddev/configBoundary.ts +6 -0
- package/src/sharddev/cookInput.ts +40 -0
- package/src/sharddev/crowds.ts +6 -0
- package/src/sharddev/decisionBindingMap.ts +11 -0
- package/src/sharddev/decisionScriptBindings.ts +117 -0
- package/src/sharddev/decisionScripts.ts +28 -0
- package/src/sharddev/decisionSource.ts +51 -0
- package/src/sharddev/dev.ts +113 -0
- package/src/sharddev/director.ts +26 -0
- package/src/sharddev/directorAbi.ts +77 -0
- package/src/sharddev/discoveryDocument.ts +97 -0
- package/src/sharddev/draft.ts +11 -0
- package/src/sharddev/eliteEntryRows.ts +29 -0
- package/src/sharddev/entries.ts +76 -0
- package/src/sharddev/entryReads.ts +73 -0
- package/src/sharddev/executeBundle.ts +55 -0
- package/src/sharddev/finds.ts +5 -0
- package/src/sharddev/formatJsonSchema.ts +3 -0
- package/src/sharddev/generationCache.ts +257 -0
- package/src/sharddev/generationRecipe.ts +94 -0
- package/src/sharddev/handwritten.ts +110 -0
- package/src/sharddev/immutable.ts +14 -0
- package/src/sharddev/interactions.ts +38 -0
- package/src/sharddev/kit/bakedGeometry.ts +16 -0
- package/src/sharddev/kit/geometryPack.ts +110 -0
- package/src/sharddev/ledger.ts +13 -0
- package/src/sharddev/looks/tileField.ts +67 -0
- package/src/sharddev/materialGraphFiles.ts +57 -0
- package/src/sharddev/materials.ts +574 -0
- package/src/sharddev/measure.ts +18 -0
- package/src/sharddev/modes.ts +115 -0
- package/src/sharddev/moverPrograms.ts +213 -0
- package/src/sharddev/movers.ts +75 -0
- package/src/sharddev/nativePopulationRows.ts +46 -0
- package/src/sharddev/newProject.ts +247 -0
- package/src/sharddev/noise.ts +54 -0
- package/src/sharddev/outputProduct.ts +188 -0
- package/src/sharddev/outputRuntime.ts +66 -0
- package/src/sharddev/performancePolicy.ts +18 -0
- package/src/sharddev/phasedBoss.ts +34 -0
- package/src/sharddev/physics.ts +194 -0
- package/src/sharddev/platformSections.ts +42 -0
- package/src/sharddev/plumbing.ts +8 -0
- package/src/sharddev/productOutput.ts +128 -0
- package/src/sharddev/project.ts +337 -0
- package/src/sharddev/projectCompilerIdentity.ts +94 -0
- package/src/sharddev/projectDecisions.ts +66 -0
- package/src/sharddev/projectEntryProof.ts +32 -0
- package/src/sharddev/projectGeneration.ts +219 -0
- package/src/sharddev/projectInputFiles.ts +47 -0
- package/src/sharddev/projectManifest.ts +108 -0
- package/src/sharddev/projectMap.ts +35 -0
- package/src/sharddev/projectOutput.ts +242 -0
- package/src/sharddev/projectPolicy.ts +17 -0
- package/src/sharddev/projectSections.ts +27 -0
- package/src/sharddev/questGraph.ts +25 -0
- package/src/sharddev/quests.ts +65 -0
- package/src/sharddev/random.ts +61 -0
- package/src/sharddev/refusals.ts +234 -0
- package/src/sharddev/reportCard.ts +13 -0
- package/src/sharddev/returnProjectionV2.ts +81 -0
- package/src/sharddev/rows.ts +192 -0
- package/src/sharddev/runtimeImports.ts +38 -0
- package/src/sharddev/runtimeMirrors.ts +39 -0
- package/src/sharddev/runtimePerformance.ts +38 -0
- package/src/sharddev/scene.ts +321 -0
- package/src/sharddev/sceneAnimation.ts +54 -0
- package/src/sharddev/sceneAudio.ts +64 -0
- package/src/sharddev/sceneDeclarations.ts +100 -0
- package/src/sharddev/sceneGraph.ts +139 -0
- package/src/sharddev/sceneTransform.ts +12 -0
- package/src/sharddev/schemaValidation.ts +61 -0
- package/src/sharddev/sections.ts +47 -0
- package/src/sharddev/shardSource.ts +59 -0
- package/src/sharddev/sourceReader.ts +26 -0
- package/src/sharddev/spawns.ts +38 -0
- package/src/sharddev/species/clips.ts +24 -0
- package/src/sharddev/species.ts +29 -0
- package/src/sharddev/speciesBrains.ts +19 -0
- package/src/sharddev/synth.ts +66 -0
- package/src/sharddev/test/compileDualScriptV2.ts +71 -0
- package/src/sharddev/test/compileSimV2.ts +21 -0
- package/src/sharddev/test/diskScriptScenario.ts +86 -0
- package/src/sharddev/test/scriptScenario.ts +249 -0
- package/src/sharddev/test/scriptSource.ts +12 -0
- package/src/sharddev/version.ts +4 -0
- package/src/sharddev/weapons/bowProfile.ts +20 -0
- package/src/sharddev/weapons/firearmRows.ts +11 -0
- package/src/sharddev/weapons/meleeProfile.ts +71 -0
- package/src/sharddev/weapons/thrownProfile.ts +10 -0
- package/src/sharddev/worldScenes.ts +308 -0
- package/src/sharddev/worldSource.ts +82 -0
- package/src/shards/_template/README.md +78 -0
- package/src/shards/_template/assets/2bf489fdb15f1734ddb4c4f32d500ec6da85c765ec7a4eb28dc6781160e7ec8c +0 -0
- package/src/shards/_template/assets/97ec4d8f75f5fa6239ee919444d6dc19fd35896bb305930c1f050ac6e0e0e6a6 +1 -0
- package/src/shards/_template/assets/a6a587a31327f936b1b04c05ade818c73fc8964260918662db43539465e27586 +0 -0
- package/src/shards/_template/assets/b4fbde0422e125b498c3dc8b9a5cc2516c8598f09e9d0e5f6b639b32f98179e6 +0 -0
- package/src/shards/_template/assets/bfa4dfc9c18979f904557ee8deab0058b8a399be10266f5fb1578b403f482fd4 +1 -0
- package/src/shards/_template/assets/ef3b7ff4fd22715771cb7d68a3977a903c5e7c3dc293542687d04b3ef3ace2cb +0 -0
- package/src/shards/_template/assets/f2db05998615ce1cb79ea96be32c168842eb6a2b34ec01feb86d36404603ee54 +0 -0
- package/src/shards/_template/assets/fef98ebb7fce6f66b26e78ac699e5c90f9bdcfaf8cabeb2b58125347eea8b4ab +0 -0
- package/src/shards/_template/behaviour/boss.as +39 -0
- package/src/shards/_template/behaviour/door.as +32 -0
- package/src/shards/_template/behaviour/hooks.json +129 -0
- package/src/shards/_template/behaviour/idle.as +75 -0
- package/src/shards/_template/behaviour/items.as +22 -0
- package/src/shards/_template/card/landscape.jpg +0 -0
- package/src/shards/_template/card/portrait.jpg +0 -0
- package/src/shards/_template/card/thumb.jpg +0 -0
- package/src/shards/_template/data/audio.json +45 -0
- package/src/shards/_template/data/bossDecision.json +83 -0
- package/src/shards/_template/data/budgets.json +70 -0
- package/src/shards/_template/data/card.json +281 -0
- package/src/shards/_template/data/clientScripts.json +987 -0
- package/src/shards/_template/data/creatures.json +65 -0
- package/src/shards/_template/data/director.json +39 -0
- package/src/shards/_template/data/encounters.json +96 -0
- package/src/shards/_template/data/items.json +172 -0
- package/src/shards/_template/data/layout.json +66 -0
- package/src/shards/_template/data/ledger.json +32 -0
- package/src/shards/_template/data/look.json +521 -0
- package/src/shards/_template/data/map.json +64 -0
- package/src/shards/_template/data/moves.json +16 -0
- package/src/shards/_template/data/placeholder.json +8 -0
- package/src/shards/_template/data/plumbing.json +32 -0
- package/src/shards/_template/data/quests.json +223 -0
- package/src/shards/_template/data/rows.json +423 -0
- package/src/shards/_template/data/skins.json +66 -0
- package/src/shards/_template/data/spawn.json +6 -0
- package/src/shards/_template/data/targets.json +150 -0
- package/src/shards/_template/data/text.json +12 -0
- package/src/shards/_template/data/ui.json +33 -0
- package/src/shards/_template/data/water.json +13 -0
- package/src/shards/_template/generators/behaviour.ts +34 -0
- package/src/shards/_template/generators/boss.ts +29 -0
- package/src/shards/_template/generators/buildOptions.ts +2 -0
- package/src/shards/_template/generators/cell.ts +224 -0
- package/src/shards/_template/generators/districts.ts +215 -0
- package/src/shards/_template/generators/farLook.ts +15 -0
- package/src/shards/_template/generators/generate.ts +27 -0
- package/src/shards/_template/generators/ground.ts +15 -0
- package/src/shards/_template/generators/kit.ts +69 -0
- package/src/shards/_template/generators/landscape.ts +59 -0
- package/src/shards/_template/generators/landscapeNoise.ts +62 -0
- package/src/shards/_template/generators/mapInputs.ts +10 -0
- package/src/shards/_template/generators/product.ts +100 -0
- package/src/shards/_template/generators/productOutput.ts +18 -0
- package/src/shards/_template/generators/props.ts +9 -0
- package/src/shards/_template/generators/templatePropsSource.ts +58 -0
- package/src/shards/_template/generators/terrain.ts +17 -0
- package/src/shards/_template/generators/world.ts +630 -0
- package/src/shards/_template/hero.json +10 -0
- package/src/shards/_template/look/entry-reads.json +20 -0
- package/src/shards/_template/manifest.json +281 -0
- package/src/shards/_template/shard.config.ts +10 -0
- package/src/shared/health.ts +10 -0
- package/src/tools/build-web.ts +59 -0
- package/src/tsconfig.json +30 -0
- package/src/web/app.tsx +53 -0
- package/src/web/index.html +12 -0
- package/src/web/main.tsx +10 -0
- package/src/web/tsconfig.json +13 -0
- package/tsconfig.author.json +23 -0
- package/tsconfig.commons.json +21 -0
- package/tsconfig.json +47 -0
- package/tsconfig.sharddev.json +20 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto'
|
|
2
|
+
import { readFile, readdir, rename, rm, writeFile } from 'node:fs/promises'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { installFormatHook } from '@wildshard/format/formatHook'
|
|
6
|
+
|
|
7
|
+
import { DRAFT_SDK, draftMessage } from '../../sharddev/draft.ts'
|
|
8
|
+
import { refusalHint, refusalNote } from '../../sharddev/refusals.ts'
|
|
9
|
+
import { audioLines } from '../audio/audio.ts'
|
|
10
|
+
import { assertHeroCurrent } from '../hero/hero.ts'
|
|
11
|
+
import { validateShardfile } from '../upload/validate.ts'
|
|
12
|
+
|
|
13
|
+
// The shard file (C0, J137): `wildshard build` (SHARD-AUTHORING SA3, J170)
|
|
14
|
+
// turns the shard file folder it built into the one tarball `api-server`
|
|
15
|
+
// takes, so a shard file stands alone. It writes ustar through format's
|
|
16
|
+
// `writeTar` and runs format's validator on the tarball itself, the check the
|
|
17
|
+
// server runs at commit: what this writes, the server admits once it is
|
|
18
|
+
// prepared. A fresh build is a draft (sdk 0.2) that the server refuses, so
|
|
19
|
+
// this warns about one (J198). `wildshard pack` is the deprecated alias.
|
|
20
|
+
//
|
|
21
|
+
// The same folder writes the same bytes, so the same hash, and a re-upload
|
|
22
|
+
// sends nothing.
|
|
23
|
+
|
|
24
|
+
const BYTES_PER_MB = 1_000_000
|
|
25
|
+
const ONE_DECIMAL = 1
|
|
26
|
+
// The cap in api-server's D31, on a shardfile stored or decoded. J137 raises
|
|
27
|
+
// it only if a real shard needs it, so going over is news and not a refusal:
|
|
28
|
+
// the server's cap is the one that counts.
|
|
29
|
+
const SERVER_CAP_BYTES = 450_000_000
|
|
30
|
+
|
|
31
|
+
/** What `readdir` says about one entry. */
|
|
32
|
+
interface ProductEntry {
|
|
33
|
+
readonly name: string
|
|
34
|
+
readonly parentPath: string
|
|
35
|
+
readonly isDirectory: () => boolean
|
|
36
|
+
readonly isFile: () => boolean
|
|
37
|
+
readonly isSymbolicLink: () => boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface ShardfileOptions {
|
|
41
|
+
/** The built shard file folder: `shard.json` at its root. */
|
|
42
|
+
readonly dir: string
|
|
43
|
+
/** Where the shard file goes; `<slug>.shardfile` beside the folder if unset. */
|
|
44
|
+
readonly out?: string
|
|
45
|
+
/** The shard source the hero check reads; `<root>/src/shards/<name>` for `<root>/out/<name>` if unset. */
|
|
46
|
+
readonly source?: string
|
|
47
|
+
/** Receives one line per step. */
|
|
48
|
+
readonly report: (line: string) => void
|
|
49
|
+
/** False: the caller reports a draft itself (`check`, in its verdict). */
|
|
50
|
+
readonly draftWarning?: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface Tarball {
|
|
54
|
+
readonly tarball: Uint8Array<ArrayBuffer>
|
|
55
|
+
readonly fileCount: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface ShardfileOutcome {
|
|
59
|
+
readonly slug: string
|
|
60
|
+
readonly file: string
|
|
61
|
+
readonly hash: string
|
|
62
|
+
readonly bytes: number
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function sha256(bytes: Readonly<Uint8Array>): string {
|
|
66
|
+
return createHash('sha256').update(bytes).digest('hex')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function mb(bytes: number): string {
|
|
70
|
+
return `${(bytes / BYTES_PER_MB).toFixed(ONE_DECIMAL)} MB`
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// A cook pack repeats files that ship at their own paths: format rebuilds and
|
|
74
|
+
// checks it from them, so a shard file leaves it out (C0). 109 MB of Pine Hollow.
|
|
75
|
+
const PACKS = 'blobs/pack/'
|
|
76
|
+
|
|
77
|
+
function productPath(root: string, entry: ProductEntry): string {
|
|
78
|
+
const file = path.join(entry.parentPath, entry.name)
|
|
79
|
+
if (entry.isSymbolicLink() || !entry.isFile()) {
|
|
80
|
+
throw new Error(`not a regular file: ${file}`)
|
|
81
|
+
}
|
|
82
|
+
return path.relative(root, file).split(path.sep).join('/')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Every file in the product by `/`-separated path; a link is refused. */
|
|
86
|
+
async function readProduct(
|
|
87
|
+
root: string,
|
|
88
|
+
): Promise<ReadonlyMap<string, Uint8Array>> {
|
|
89
|
+
const entries = await readdir(root, { recursive: true, withFileTypes: true })
|
|
90
|
+
const paths = entries
|
|
91
|
+
.filter((entry: ProductEntry): boolean => !entry.isDirectory())
|
|
92
|
+
.map((entry: ProductEntry): string => productPath(root, entry))
|
|
93
|
+
.filter((file: string): boolean => !file.startsWith(PACKS))
|
|
94
|
+
const pairs = await Promise.all(
|
|
95
|
+
paths.map(async (file: string): Promise<readonly [string, Uint8Array]> => {
|
|
96
|
+
const bytes = await readFile(path.join(root, file))
|
|
97
|
+
return [
|
|
98
|
+
file,
|
|
99
|
+
new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.length),
|
|
100
|
+
]
|
|
101
|
+
}),
|
|
102
|
+
)
|
|
103
|
+
return new Map(pairs)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function tarOf(dir: string): Promise<Tarball> {
|
|
107
|
+
installFormatHook()
|
|
108
|
+
const { writeTar } = await import('@wildshard/format/tar')
|
|
109
|
+
const files = await readProduct(dir)
|
|
110
|
+
return { tarball: writeTar(files), fileCount: files.size }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function reportOverCap(options: ShardfileOptions, bytes: number): void {
|
|
114
|
+
if (bytes > SERVER_CAP_BYTES) {
|
|
115
|
+
options.report(
|
|
116
|
+
`warning: ${mb(bytes)} is over api-server's ${mb(SERVER_CAP_BYTES)} cap (its D34)`,
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* J198: a fresh build is a draft (sdk 0.2) that upload and api-server refuse;
|
|
123
|
+
* build still writes it, as `wildshard prepare` works on the folder.
|
|
124
|
+
*/
|
|
125
|
+
function reportDraft(
|
|
126
|
+
options: ShardfileOptions,
|
|
127
|
+
slug: string,
|
|
128
|
+
sdk: string,
|
|
129
|
+
): void {
|
|
130
|
+
if (sdk === DRAFT_SDK && options.draftWarning !== false) {
|
|
131
|
+
const message = draftMessage(slug)
|
|
132
|
+
options.report(`warning: ${message}`)
|
|
133
|
+
options.report(` ${refusalHint(refusalNote('shardfile', message))}`)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Never leaves half a tarball under the final name. */
|
|
138
|
+
async function writeAtomically(
|
|
139
|
+
file: string,
|
|
140
|
+
bytes: Readonly<Uint8Array>,
|
|
141
|
+
): Promise<void> {
|
|
142
|
+
const partial = `${file}.${randomUUID()}.partial`
|
|
143
|
+
try {
|
|
144
|
+
await writeFile(partial, bytes)
|
|
145
|
+
await rename(partial, file)
|
|
146
|
+
} finally {
|
|
147
|
+
await rm(partial, { force: true })
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Check the hero is as new as the content, tar the folder, check the tarball. */
|
|
152
|
+
async function checkedTarball(
|
|
153
|
+
options: ShardfileOptions,
|
|
154
|
+
): Promise<Readonly<{ tarball: Uint8Array<ArrayBuffer>; slug: string }>> {
|
|
155
|
+
await assertHeroCurrent(options.dir, options.report, options.source)
|
|
156
|
+
const { tarball, fileCount } = await tarOf(options.dir)
|
|
157
|
+
const { slug, name, audio, sdk } = await validateShardfile(tarball)
|
|
158
|
+
options.report(`valid: ${slug} (${name}), ${String(fileCount)} files`)
|
|
159
|
+
reportDraft(options, slug, sdk)
|
|
160
|
+
// AUDIO AU5: build prints the audio rules as AMBER and still writes the
|
|
161
|
+
// shard file; only upload and api-server's admission refuse a red.
|
|
162
|
+
for (const line of await audioLines(audio)) {
|
|
163
|
+
options.report(line)
|
|
164
|
+
}
|
|
165
|
+
reportOverCap(options, tarball.length)
|
|
166
|
+
return { tarball, slug }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The shard file's default name: `<slug>.shardfile` beside its folder (SA3). */
|
|
170
|
+
function shardfilePath(dir: string, slug: string): string {
|
|
171
|
+
return path.join(path.dirname(path.resolve(dir)), `${slug}.shardfile`)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Check the folder, then write its shard file; a refusal writes none. */
|
|
175
|
+
async function writeShardfile(
|
|
176
|
+
options: ShardfileOptions,
|
|
177
|
+
): Promise<ShardfileOutcome> {
|
|
178
|
+
const { tarball, slug } = await checkedTarball(options)
|
|
179
|
+
const bytes = tarball.length
|
|
180
|
+
const file = options.out ?? shardfilePath(options.dir, slug)
|
|
181
|
+
const hash = sha256(tarball)
|
|
182
|
+
await writeAtomically(file, tarball)
|
|
183
|
+
options.report(`shard file: ${file}, ${mb(bytes)} (${hash})`)
|
|
184
|
+
return { slug, file, hash, bytes }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export {
|
|
188
|
+
type ShardfileOptions,
|
|
189
|
+
type ShardfileOutcome,
|
|
190
|
+
shardfilePath,
|
|
191
|
+
writeShardfile,
|
|
192
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { safeParse } from 'valibot'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CatalogueSchema,
|
|
5
|
+
CommitAnswerSchema,
|
|
6
|
+
DirectUploadTicketSchema,
|
|
7
|
+
ErrorBodySchema,
|
|
8
|
+
ShardfileListSchema,
|
|
9
|
+
} from './wire.ts'
|
|
10
|
+
|
|
11
|
+
import type { Provenance } from './provenance.ts'
|
|
12
|
+
import type { SignedShardfile } from './signature.ts'
|
|
13
|
+
import type {
|
|
14
|
+
CatalogueShard,
|
|
15
|
+
CommitAnswer,
|
|
16
|
+
DirectUploadTicket,
|
|
17
|
+
ShardfileSummary,
|
|
18
|
+
} from './wire.ts'
|
|
19
|
+
import type { BaseIssue, BaseSchema, InferOutput } from 'valibot'
|
|
20
|
+
|
|
21
|
+
// The large-file protocol of api-server (its docs/design.md, V7): ticket,
|
|
22
|
+
// PUT to R2, commit. Vercel's protection sits in front of the API calls only:
|
|
23
|
+
// the PUT goes straight to R2, so the bypass header never goes with it. The
|
|
24
|
+
// ticket and the commit carry the account key too (meta SHARD-DELETE DEL5,
|
|
25
|
+
// DEL6); the public reads and the PUT never do.
|
|
26
|
+
|
|
27
|
+
const SIGNATURE_HEADER = 'x-wildshard-signature'
|
|
28
|
+
const BYPASS_HEADER = 'x-vercel-protection-bypass'
|
|
29
|
+
const PUT_ATTEMPTS = 3
|
|
30
|
+
const FIRST_SERVER_ERROR = 500
|
|
31
|
+
const FIRST_ATTEMPT = 1
|
|
32
|
+
const BYPASS_HINT =
|
|
33
|
+
'not an api-server reply; a protected deployment needs VERCEL_AUTOMATION_BYPASS_SECRET'
|
|
34
|
+
|
|
35
|
+
interface ApiOptions {
|
|
36
|
+
/** The api-server origin. */
|
|
37
|
+
readonly server: string
|
|
38
|
+
/** The account's `wsk_` key, sent on the ticket and the commit. */
|
|
39
|
+
readonly apiKey: string
|
|
40
|
+
/** Vercel's automation bypass, for a protected deployment. */
|
|
41
|
+
readonly bypassSecret?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface UploadRequest {
|
|
45
|
+
readonly hash: string
|
|
46
|
+
readonly storedBytes: number
|
|
47
|
+
readonly contentEncoding?: 'br'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface PutTarget {
|
|
51
|
+
readonly url: string
|
|
52
|
+
readonly headers: Readonly<Record<string, string>>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type AnySchema = BaseSchema<unknown, unknown, BaseIssue<unknown>>
|
|
56
|
+
|
|
57
|
+
function apiHeaders(options: ApiOptions): Record<string, string> {
|
|
58
|
+
return options.bypassSecret === undefined
|
|
59
|
+
? {}
|
|
60
|
+
: { [BYPASS_HEADER]: options.bypassSecret }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function jsonOf(text: string): unknown {
|
|
64
|
+
try {
|
|
65
|
+
const value: unknown = JSON.parse(text)
|
|
66
|
+
return value
|
|
67
|
+
} catch {
|
|
68
|
+
return undefined
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function refusal(path: string, status: number, body?: unknown): Error {
|
|
73
|
+
const parsed = safeParse(ErrorBodySchema, body)
|
|
74
|
+
const reason = parsed.success ? parsed.output.error : BYPASS_HINT
|
|
75
|
+
return new Error(`${path} answered ${String(status)}: ${reason}`)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The reply's parsed body; a refusal or anything unparseable throws. */
|
|
79
|
+
async function replyOf<Schema extends AnySchema>(
|
|
80
|
+
path: string,
|
|
81
|
+
reply: Response,
|
|
82
|
+
schema: Schema,
|
|
83
|
+
): Promise<InferOutput<Schema>> {
|
|
84
|
+
const body = jsonOf(await reply.text())
|
|
85
|
+
if (!reply.ok) {
|
|
86
|
+
throw refusal(path, reply.status, body)
|
|
87
|
+
}
|
|
88
|
+
const parsed = safeParse(schema, body)
|
|
89
|
+
if (!parsed.success) {
|
|
90
|
+
throw refusal(path, reply.status)
|
|
91
|
+
}
|
|
92
|
+
return parsed.output
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function postSigned<Schema extends AnySchema>(
|
|
96
|
+
options: ApiOptions,
|
|
97
|
+
call: Readonly<{ path: string; signature: string; body: object }>,
|
|
98
|
+
schema: Schema,
|
|
99
|
+
): Promise<InferOutput<Schema>> {
|
|
100
|
+
const reply = await fetch(new URL(call.path, options.server), {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: {
|
|
103
|
+
...apiHeaders(options),
|
|
104
|
+
'content-type': 'application/json',
|
|
105
|
+
authorization: `Bearer ${options.apiKey}`,
|
|
106
|
+
[SIGNATURE_HEADER]: call.signature,
|
|
107
|
+
},
|
|
108
|
+
body: JSON.stringify(call.body),
|
|
109
|
+
})
|
|
110
|
+
return await replyOf(call.path, reply, schema)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The stored shardfile with this hash, if there is one. */
|
|
114
|
+
async function findStored(
|
|
115
|
+
options: ApiOptions,
|
|
116
|
+
hash: string,
|
|
117
|
+
): Promise<ShardfileSummary | undefined> {
|
|
118
|
+
const path = '/api/shardfiles'
|
|
119
|
+
const reply = await fetch(new URL(path, options.server), {
|
|
120
|
+
headers: apiHeaders(options),
|
|
121
|
+
})
|
|
122
|
+
const { shardfiles } = await replyOf(path, reply, ShardfileListSchema)
|
|
123
|
+
return shardfiles.find(
|
|
124
|
+
(stored: Readonly<{ hash: string }>): boolean => stored.hash === hash,
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The slug's entry in `GET /api/catalogue`, if it has one. */
|
|
129
|
+
async function findCatalogued(
|
|
130
|
+
options: ApiOptions,
|
|
131
|
+
slug: string,
|
|
132
|
+
): Promise<CatalogueShard | undefined> {
|
|
133
|
+
const path = '/api/catalogue'
|
|
134
|
+
const reply = await fetch(new URL(path, options.server), {
|
|
135
|
+
headers: apiHeaders(options),
|
|
136
|
+
})
|
|
137
|
+
const { shards } = await replyOf(path, reply, CatalogueSchema)
|
|
138
|
+
return shards.find(
|
|
139
|
+
(shard: Readonly<{ slug: string }>): boolean => shard.slug === slug,
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function requestTicket(
|
|
144
|
+
options: ApiOptions,
|
|
145
|
+
request: UploadRequest,
|
|
146
|
+
signature: string,
|
|
147
|
+
): Promise<DirectUploadTicket> {
|
|
148
|
+
return await postSigned(
|
|
149
|
+
options,
|
|
150
|
+
{ path: '/api/shardfiles/uploads', signature, body: request },
|
|
151
|
+
DirectUploadTicketSchema,
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function attemptPut(
|
|
156
|
+
target: PutTarget,
|
|
157
|
+
body: Readonly<Uint8Array>,
|
|
158
|
+
): Promise<Response | undefined> {
|
|
159
|
+
try {
|
|
160
|
+
return await fetch(target.url, {
|
|
161
|
+
method: 'PUT',
|
|
162
|
+
headers: target.headers,
|
|
163
|
+
body: new Uint8Array(body),
|
|
164
|
+
})
|
|
165
|
+
} catch {
|
|
166
|
+
return undefined
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function retries(reply: Response | undefined): boolean {
|
|
171
|
+
return reply === undefined || reply.status >= FIRST_SERVER_ERROR
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** PUT with exactly the signed headers; a dropped connection or 5xx retries. */
|
|
175
|
+
async function putObject(
|
|
176
|
+
target: PutTarget,
|
|
177
|
+
body: Readonly<Uint8Array>,
|
|
178
|
+
attempt: number = FIRST_ATTEMPT,
|
|
179
|
+
): Promise<void> {
|
|
180
|
+
const reply = await attemptPut(target, body)
|
|
181
|
+
if (reply?.ok === true) {
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
if (retries(reply) && attempt < PUT_ATTEMPTS) {
|
|
185
|
+
await putObject(target, body, attempt + FIRST_ATTEMPT)
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
const answer =
|
|
189
|
+
reply === undefined
|
|
190
|
+
? 'no reply'
|
|
191
|
+
: `${String(reply.status)}: ${await reply.text()}`
|
|
192
|
+
throw new Error(`the PUT to R2 failed: ${answer}`)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The channels an upload may ask for, by their wire names (J301). */
|
|
196
|
+
type Channel = 'staging' | 'production'
|
|
197
|
+
|
|
198
|
+
interface CommitBody extends Provenance {
|
|
199
|
+
readonly contentEncoding?: 'br' | undefined
|
|
200
|
+
readonly channel: Channel
|
|
201
|
+
/** False sends `place: false` (SA32's `--no-place`): no grid cell. */
|
|
202
|
+
readonly place: boolean
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The commit: the bytes' encoding, the shard version and commit (V1), the
|
|
207
|
+
* channel it is for (J301), the versions it was built with (J306) and,
|
|
208
|
+
* for `--no-place`, `place: false` (SA32; the API places by default).
|
|
209
|
+
*/
|
|
210
|
+
async function commitUpload(
|
|
211
|
+
options: ApiOptions,
|
|
212
|
+
signed: SignedShardfile,
|
|
213
|
+
body: CommitBody,
|
|
214
|
+
): Promise<CommitAnswer> {
|
|
215
|
+
const { contentEncoding, version, commit, channel, place } = body
|
|
216
|
+
const { sharddev, engine, shardFormat } = body
|
|
217
|
+
return await postSigned(
|
|
218
|
+
options,
|
|
219
|
+
{
|
|
220
|
+
path: `/api/shardfiles/uploads/${signed.hash}/commit`,
|
|
221
|
+
signature: signed.signature,
|
|
222
|
+
body: {
|
|
223
|
+
...(contentEncoding === undefined ? {} : { contentEncoding }),
|
|
224
|
+
version,
|
|
225
|
+
commit,
|
|
226
|
+
channel,
|
|
227
|
+
sharddev,
|
|
228
|
+
engine,
|
|
229
|
+
shardFormat,
|
|
230
|
+
...(place ? {} : { place: false }),
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
CommitAnswerSchema,
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
type ApiOptions,
|
|
239
|
+
type Channel,
|
|
240
|
+
type UploadRequest,
|
|
241
|
+
commitUpload,
|
|
242
|
+
findCatalogued,
|
|
243
|
+
findStored,
|
|
244
|
+
putObject,
|
|
245
|
+
requestTicket,
|
|
246
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { promisify } from 'node:util'
|
|
2
|
+
import { brotliCompress, constants } from 'node:zlib'
|
|
3
|
+
|
|
4
|
+
// J96: the author's machine compresses. The whole tarball is one Brotli
|
|
5
|
+
// stream, because that is what `Content-Encoding: br` means to R2 and to a
|
|
6
|
+
// browser, so a tar member cannot opt out. It does not need to: the encoder
|
|
7
|
+
// stores incompressible runs raw, so KTX2 costs almost nothing.
|
|
8
|
+
|
|
9
|
+
const compress = promisify(brotliCompress)
|
|
10
|
+
|
|
11
|
+
// Measured on a 271 MB tarball of real game assets mixed to save what Pine
|
|
12
|
+
// Hollow saves at level 5: level 6 stores 216.9 MB in about 2 s, the last
|
|
13
|
+
// cheap step. Level 7 takes three times as long to shed 0.4 MB; level 11 sheds
|
|
14
|
+
// 5.4 MB for 278 s. docs/design.md has the table.
|
|
15
|
+
const DEFAULT_BROTLI_LEVEL = 6
|
|
16
|
+
const MIN_BROTLI_LEVEL = 0
|
|
17
|
+
const MAX_BROTLI_LEVEL = 11
|
|
18
|
+
// A larger window saved nothing at the default level, and every decoder
|
|
19
|
+
// reads this one.
|
|
20
|
+
const WINDOW_BITS = 22
|
|
21
|
+
// Below this, Brotli only adds a decode for every reader of the object.
|
|
22
|
+
const WORTHWHILE_SAVING = 0.01
|
|
23
|
+
const WHOLE = 1
|
|
24
|
+
|
|
25
|
+
interface StoredForm {
|
|
26
|
+
/** What the PUT carries. */
|
|
27
|
+
readonly body: Readonly<Uint8Array>
|
|
28
|
+
/** `br` when `body` is the tarball's Brotli; absent for the tarball. */
|
|
29
|
+
readonly contentEncoding?: 'br'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The tarball's Brotli, or the tarball when that saves next to nothing. */
|
|
33
|
+
async function storedForm(
|
|
34
|
+
tarball: Readonly<Uint8Array>,
|
|
35
|
+
level: number,
|
|
36
|
+
): Promise<StoredForm> {
|
|
37
|
+
const brotli = await compress(tarball, {
|
|
38
|
+
params: {
|
|
39
|
+
[constants.BROTLI_PARAM_QUALITY]: level,
|
|
40
|
+
[constants.BROTLI_PARAM_LGWIN]: WINDOW_BITS,
|
|
41
|
+
[constants.BROTLI_PARAM_SIZE_HINT]: tarball.length,
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
return brotli.length < tarball.length * (WHOLE - WORTHWHILE_SAVING)
|
|
45
|
+
? { body: brotli, contentEncoding: 'br' }
|
|
46
|
+
: { body: tarball }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
DEFAULT_BROTLI_LEVEL,
|
|
51
|
+
MAX_BROTLI_LEVEL,
|
|
52
|
+
MIN_BROTLI_LEVEL,
|
|
53
|
+
type StoredForm,
|
|
54
|
+
storedForm,
|
|
55
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
|
|
3
|
+
// The hero digest (meta SHARD-AUTHORING UP4, J306, choice 4), computed as
|
|
4
|
+
// api-server computes it (`src/server/shardfile/hero.ts`, `79f5ca1`), so
|
|
5
|
+
// the upload pre-check refuses exactly what the commit would. A shard's
|
|
6
|
+
// hero is its SHARD SELECT card, three images; the digest is the SHA-256
|
|
7
|
+
// of `thumb:<hash>\nportrait:<hash>\nlandscape:<hash>`, each the image's
|
|
8
|
+
// blob hash.
|
|
9
|
+
//
|
|
10
|
+
// The card is the manifest's (`manifest.card`, the packed URLs every live
|
|
11
|
+
// shard and the template carry), else the presentation's (bare blob
|
|
12
|
+
// hashes). A packed URL names its blob,
|
|
13
|
+
// `/shardfiles/<folder>/blobs/image/<hash>.<ext>`; a generated `data:`
|
|
14
|
+
// card has no blob, so its hash is the SHA-256 of the URL. A shard with no
|
|
15
|
+
// card has no digest.
|
|
16
|
+
|
|
17
|
+
interface HeroCard {
|
|
18
|
+
readonly thumb: string
|
|
19
|
+
readonly portrait: string
|
|
20
|
+
readonly landscape: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The two places a validated shard file carries its card. */
|
|
24
|
+
interface Carded {
|
|
25
|
+
readonly manifest?: Readonly<{ card: HeroCard }> | undefined
|
|
26
|
+
readonly presentation?: Readonly<{ card: HeroCard }> | undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const BLOB_HASH = /^[a-f0-9]{64}$/u
|
|
30
|
+
const BLOB_URL =
|
|
31
|
+
/^\/shardfiles\/[^/]+\/blobs\/image\/(?<hash>[a-f0-9]{64})\.[a-z0-9]+$/u
|
|
32
|
+
|
|
33
|
+
function sha256(text: string): string {
|
|
34
|
+
return createHash('sha256').update(text).digest('hex')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** One card image's blob hash: a bare hash, the hash a packed URL names, else the URL's own SHA-256. */
|
|
38
|
+
function imageHash(image: string): string {
|
|
39
|
+
if (BLOB_HASH.test(image)) {
|
|
40
|
+
return image
|
|
41
|
+
}
|
|
42
|
+
return BLOB_URL.exec(image)?.groups?.['hash'] ?? sha256(image)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The digest of a card's three images, in choice 4's order. */
|
|
46
|
+
function cardDigest(card: HeroCard): string {
|
|
47
|
+
return sha256(
|
|
48
|
+
[
|
|
49
|
+
`thumb:${imageHash(card.thumb)}`,
|
|
50
|
+
`portrait:${imageHash(card.portrait)}`,
|
|
51
|
+
`landscape:${imageHash(card.landscape)}`,
|
|
52
|
+
].join('\n'),
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The shard's hero digest, or undefined when it has no card. */
|
|
57
|
+
function heroHashOf(shard: Readonly<Carded>): string | undefined {
|
|
58
|
+
const card = shard.manifest?.card ?? shard.presentation?.card
|
|
59
|
+
return card === undefined ? undefined : cardDigest(card)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { type Carded, type HeroCard, cardDigest, heroHashOf }
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { safeParse } from 'valibot'
|
|
2
|
+
|
|
3
|
+
import { PlacementSchema } from './wire.ts'
|
|
4
|
+
|
|
5
|
+
import type { Channel } from './api.ts'
|
|
6
|
+
import type { CommitAnswer, Placement } from './wire.ts'
|
|
7
|
+
|
|
8
|
+
// What the upload says about the grid (meta SHARD-AUTHORING SA32, J314):
|
|
9
|
+
// the cell the API gave the shard, or why it gave none, then the
|
|
10
|
+
// `/slug/<slug>` link on each channel the upload moved. api-server's SA30
|
|
11
|
+
// answers `placement` only while its `GRID_AUTOPLACE` is on, and then not
|
|
12
|
+
// for a shard with no cell past its first upload, so a missing answer says
|
|
13
|
+
// "no new cell" rather than guess which. Only a first upload (catalogue
|
|
14
|
+
// number 1) takes a cell: `--no-place` later leaves a held cell where it
|
|
15
|
+
// is, so that line says the grid was left alone. The page behind the link
|
|
16
|
+
// is SA36 and SA37's, not built yet, and the line says so.
|
|
17
|
+
|
|
18
|
+
/** The API's words for `place: false` and for a failed grid step (SA30). */
|
|
19
|
+
const NOT_ASKED = 'not placed (place: false)'
|
|
20
|
+
const FAILED = 'not placed: the grid step failed'
|
|
21
|
+
const FIRST_UPLOAD = 1
|
|
22
|
+
const NO_PLACE_LINE = 'not placed (--no-place)'
|
|
23
|
+
const LEFT_ALONE_LINE = 'grid left as it was (--no-place)'
|
|
24
|
+
const NO_ANSWER_LINE =
|
|
25
|
+
"no new cell: grid placement is off on the API, or this is not the shard's first upload"
|
|
26
|
+
const FAILED_LINE =
|
|
27
|
+
'not placed: the grid step failed; run the same upload again to retry'
|
|
28
|
+
const UNREAD_LINE = "grid: the API's placement answer was not understood"
|
|
29
|
+
const PAGE_NOT_BUILT = '(page not built yet)'
|
|
30
|
+
|
|
31
|
+
/** Each channel's host (GUIDE.md section 5). */
|
|
32
|
+
const HOSTS = {
|
|
33
|
+
preview: 'preview.wildshard.io',
|
|
34
|
+
staging: 'staging.wildshard.io',
|
|
35
|
+
production: 'play.wildshard.io',
|
|
36
|
+
} as const
|
|
37
|
+
|
|
38
|
+
type ChannelName = keyof typeof HOSTS
|
|
39
|
+
|
|
40
|
+
interface Asked {
|
|
41
|
+
readonly place: boolean
|
|
42
|
+
/** The answer's catalogue number: 1 is the shard's first upload. */
|
|
43
|
+
readonly revision: number
|
|
44
|
+
readonly moved: readonly ChannelName[]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The grid line for a placed shard, naming any moved channel whose grid lacks it. */
|
|
48
|
+
function placedLine(
|
|
49
|
+
placement: Extract<Placement, { placed: true }>,
|
|
50
|
+
moved: readonly ChannelName[],
|
|
51
|
+
): string {
|
|
52
|
+
const [col, row] = placement.cell
|
|
53
|
+
const on = placement.channels.join(', ')
|
|
54
|
+
const missed = moved
|
|
55
|
+
.filter((name: ChannelName): boolean => !placement.channels.includes(name))
|
|
56
|
+
.map((name: ChannelName): string => `; not on ${name}'s grid`)
|
|
57
|
+
return `placed at (${String(col)},${String(row)}) on ${on}${missed.join('')}`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The `--no-place` line: a first upload took no cell; a later one left the grid alone. */
|
|
61
|
+
function noPlaceLine(asked: Asked): string {
|
|
62
|
+
return asked.revision === FIRST_UPLOAD ? NO_PLACE_LINE : LEFT_ALONE_LINE
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The line for `{ placed: false }`, by the API's reason. */
|
|
66
|
+
function notPlacedLine(reason: string, asked: Asked): string {
|
|
67
|
+
if (reason === NOT_ASKED) {
|
|
68
|
+
return noPlaceLine(asked)
|
|
69
|
+
}
|
|
70
|
+
return reason.startsWith(FAILED) ? FAILED_LINE : reason
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The grid line: the cell, or why there is none. */
|
|
74
|
+
function gridLine(raw: unknown, asked: Asked): string {
|
|
75
|
+
if (raw === undefined) {
|
|
76
|
+
return asked.place ? NO_ANSWER_LINE : noPlaceLine(asked)
|
|
77
|
+
}
|
|
78
|
+
const parsed = safeParse(PlacementSchema, raw)
|
|
79
|
+
if (!parsed.success) {
|
|
80
|
+
return UNREAD_LINE
|
|
81
|
+
}
|
|
82
|
+
const placement = parsed.output
|
|
83
|
+
return placement.placed
|
|
84
|
+
? placedLine(placement, asked.moved)
|
|
85
|
+
: notPlacedLine(placement.reason, asked)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The channels an upload moves (J301); a revived shard moves preview only (DEL7). */
|
|
89
|
+
function movedChannels(
|
|
90
|
+
channel: Channel,
|
|
91
|
+
revived: boolean,
|
|
92
|
+
): readonly ChannelName[] {
|
|
93
|
+
if (revived) {
|
|
94
|
+
return ['preview']
|
|
95
|
+
}
|
|
96
|
+
return channel === 'production'
|
|
97
|
+
? ['preview', 'staging', 'production']
|
|
98
|
+
: ['preview', 'staging']
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The grid line, then one `/slug/<slug>` link per channel moved. */
|
|
102
|
+
function placementLines(
|
|
103
|
+
answer: CommitAnswer,
|
|
104
|
+
options: Readonly<{ channel: Channel; place: boolean }>,
|
|
105
|
+
): readonly string[] {
|
|
106
|
+
const moved = movedChannels(options.channel, answer.revived === true)
|
|
107
|
+
const asked = { place: options.place, revision: answer.revision, moved }
|
|
108
|
+
const links = moved.map(
|
|
109
|
+
(name: ChannelName): string =>
|
|
110
|
+
`${name}: https://${HOSTS[name]}/slug/${answer.shard} ${PAGE_NOT_BUILT}`,
|
|
111
|
+
)
|
|
112
|
+
return [gridLine(answer.placement, asked), ...links]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { placementLines }
|