@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,240 @@
|
|
|
1
|
+
// Phone-tier image files (project/archive/2026-09-22-load-perf.md §P1, ask P5 "cold bytes"). Idempotent; needs ImageMagick + cwebp.
|
|
2
|
+
// Commit the outputs: Vercel's builder has neither tool, so nothing here runs at build time.
|
|
3
|
+
//
|
|
4
|
+
// 1. Poly Haven sets: for every public/assets/tex/<id>/{diffuse,nor_gl,arm}.jpg wider than 1024 px or heavier than
|
|
5
|
+
// 350 KB, write <kind>_1k.jpg beside it (≤ 1024², q82). The phone tier requests these (src/client/engine/core/assets.ts texUrl)
|
|
6
|
+
// instead of downloading a 2048² file it would shrink anyway.
|
|
7
|
+
// 2. Model textures: Poly Haven ships the glTF props' 1k JPEGs at q99 — three times the bytes of q85 for no
|
|
8
|
+
// difference anyone can see at 1k. Re-encoded IN PLACE (both tiers) at q85, normal maps with 4:4:4 chroma (their
|
|
9
|
+
// R and G are independent data, 4:2:0 would smear them). Same for the JPEGs embedded in the `<id>_lod.glb`
|
|
10
|
+
// props (scripts/simplify-models.mjs copies them in at q99). A file already ≤ q90 is left alone.
|
|
11
|
+
// 3. `.phone.webp` copies, picked by `tierUrl()` (src/client/engine/boot/bytes.ts) on the phone tier — for fetchImage, and for
|
|
12
|
+
// three's loaders through DefaultLoadingManager's URL modifier (glTF textures). The boot manifest declares
|
|
13
|
+
// through the same function, so declared bytes = downloaded bytes. WebP q75 (-sharp_yuv) is ~20–25 % smaller
|
|
14
|
+
// than the q82 JPEG it replaces AND measures lower error against the source (forest_ground_04: 0.024 vs 0.032); PNG alpha stays lossless (-exact keeps the RGB under transparent
|
|
15
|
+
// texels, which bilinear filtering and the mips still read). Capped at 1024 px (the phone's maxTexture), AO /
|
|
16
|
+
// roughness / metalness planes of the Poly Haven sets and props at 512 px. Encoded from the best source there
|
|
17
|
+
// is (the original 2k map, not its q82 _1k copy). A copy that is not ≥ 15 % smaller is not kept.
|
|
18
|
+
// 4. `<id>_lod.phone.glb`: the LOD props with their embedded JPEGs as WebP (EXT_texture_webp, which three's
|
|
19
|
+
// GLTFLoader reads), ARM planes at 512 px.
|
|
20
|
+
// Content-addressed: encode only missing source/settings keys, verify cached output hashes with --check.
|
|
21
|
+
// --seed-cache trusts today's committed copies and writes only scripts/tex-tiers.cache.json.
|
|
22
|
+
import { readdirSync, existsSync, statSync, readFileSync, rmSync, mkdtempSync } from 'node:fs';
|
|
23
|
+
import { tmpdir } from 'node:os';
|
|
24
|
+
import { byteWriter, outputHash, jsonBytes } from '@wildshard/engine/scripts/bake-output.mjs';
|
|
25
|
+
import { execFileSync } from 'node:child_process';
|
|
26
|
+
import { join } from 'node:path';
|
|
27
|
+
import { textureTierJobs } from '@wildshard/engine/scripts/texture-inputs.mjs';
|
|
28
|
+
|
|
29
|
+
const ROOT = 'public/assets/tex';
|
|
30
|
+
let made = 0;
|
|
31
|
+
const identify = (fmt, file) => execFileSync('magick', ['identify', '-format', fmt, file]).toString().trim();
|
|
32
|
+
const check = process.argv.includes('--check');
|
|
33
|
+
const seed = process.argv.includes('--seed-cache');
|
|
34
|
+
if (check && seed) throw new Error('tex-tiers: choose --check or --seed-cache');
|
|
35
|
+
const output = byteWriter(check, 'tex-tiers');
|
|
36
|
+
const CACHE = 'scripts/tex-tiers.cache.json';
|
|
37
|
+
const cache = existsSync(CACHE) ? JSON.parse(readFileSync(CACHE, 'utf8')) : {};
|
|
38
|
+
const stale = new Set();
|
|
39
|
+
const want = new Set();
|
|
40
|
+
let seeded = 0, encoded = 0, reused = 0;
|
|
41
|
+
const keyOf = (bytes, settings) => outputHash(Buffer.concat([Buffer.from(JSON.stringify(settings)), bytes]));
|
|
42
|
+
|
|
43
|
+
/** Seeding reads only. Every cache hit verifies the committed output bytes; missing keys alone encode. */
|
|
44
|
+
function copy(src, out, settings, make, inPlace = false) {
|
|
45
|
+
const source = readFileSync(src), key = keyOf(source, settings), hit = cache[key];
|
|
46
|
+
if (seed) {
|
|
47
|
+
if (hit === undefined) { cache[key] = existsSync(out) ? outputHash(readFileSync(out)) : 'none'; seeded++; }
|
|
48
|
+
if (existsSync(out)) want.add(out);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (hit !== undefined) {
|
|
52
|
+
if (hit === 'none') { if (existsSync(out)) stale.add(out); }
|
|
53
|
+
else if (!existsSync(out) || outputHash(readFileSync(out)) !== hit) stale.add(out);
|
|
54
|
+
else want.add(out);
|
|
55
|
+
reused++;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (check) { stale.add(out); return; }
|
|
59
|
+
const bytes = make(source);
|
|
60
|
+
encoded++;
|
|
61
|
+
if (bytes === null) { cache[key] = 'none'; output.remove(out); }
|
|
62
|
+
else {
|
|
63
|
+
cache[key] = outputHash(bytes); output.put(out, bytes); want.add(out);
|
|
64
|
+
if (inPlace) cache[keyOf(bytes, settings)] = outputHash(bytes);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const scratch = mkdtempSync(join(tmpdir(), 'tex-tiers-'));
|
|
68
|
+
let scratchId = 0;
|
|
69
|
+
process.on('exit', () => rmSync(scratch, { recursive: true, force: true }));
|
|
70
|
+
|
|
71
|
+
// ── 1. Poly Haven set _1k siblings ──
|
|
72
|
+
const textureFiles = [];
|
|
73
|
+
const textureWalk = (dir) => { for (const entry of readdirSync(dir, { withFileTypes: true })) { const path = join(dir, entry.name); if (entry.isDirectory()) textureWalk(path); else textureFiles.push(path); } };
|
|
74
|
+
textureWalk(ROOT);
|
|
75
|
+
const tierJobs = textureTierJobs(textureFiles);
|
|
76
|
+
for (const { source: src, output: out } of tierJobs.filter((job) => job.kind === 'resize')) {
|
|
77
|
+
copy(src, out, { format: 'jpg', max: 1024, quality: 82, strip: true, byteLimit: 350 * 1024 }, () => {
|
|
78
|
+
if (Number(identify('%w', src)) <= 1024 && statSync(src).size < 350 * 1024) return null;
|
|
79
|
+
made++;
|
|
80
|
+
return execFileSync('magick', [src, '-resize', '1024x1024', '-quality', '82', '-strip', 'jpg:-'], { maxBuffer: 64 << 20 });
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ── 2. model textures, in place ──
|
|
85
|
+
const isNormal = (name) => /nor(_gl)?/i.test(name);
|
|
86
|
+
const jpegArgs = (name) => ['-quality', '85', ...(isNormal(name) ? ['-sampling-factor', '1x1'] : []), '-strip'];
|
|
87
|
+
/** q85 re-encode of a JPEG buffer, or null when it is already ≤ q90 (idempotence). */
|
|
88
|
+
function squeeze(buf, name) {
|
|
89
|
+
const q = Number(execFileSync('magick', ['identify', '-format', '%Q', 'jpg:-'], { input: buf }).toString().trim());
|
|
90
|
+
if (!(q > 90)) return null;
|
|
91
|
+
return execFileSync('magick', ['jpg:-', ...jpegArgs(name), 'jpg:-'], { input: buf, maxBuffer: 64 << 20 });
|
|
92
|
+
}
|
|
93
|
+
let squeezed = 0, saved = 0;
|
|
94
|
+
const MODELS = 'public/assets/models';
|
|
95
|
+
for (const id of readdirSync(MODELS)) {
|
|
96
|
+
const texDir = join(MODELS, id, 'textures');
|
|
97
|
+
if (existsSync(texDir)) for (const f of readdirSync(texDir).filter((x) => x.endsWith('.jpg'))) {
|
|
98
|
+
const p = join(texDir, f), buf = readFileSync(p);
|
|
99
|
+
copy(p, p, { format: 'jpg', args: jpegArgs(f), squeezeAbove: 90 }, () => {
|
|
100
|
+
const out = squeeze(buf, f);
|
|
101
|
+
if (out && out.length < buf.length) { squeezed++; saved += buf.length - out.length; return out; }
|
|
102
|
+
return buf;
|
|
103
|
+
}, true);
|
|
104
|
+
}
|
|
105
|
+
const glb = join(MODELS, id, `${id}_lod.glb`);
|
|
106
|
+
if (existsSync(glb)) copy(glb, glb, { format: 'glb', quality: 85, squeezeAbove: 90, normalSampling: '1x1', alignment: 4 }, () => squeezeGlb(glb), true);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Re-encode a GLB's embedded JPEGs: rewrite the BIN chunk with each image's bufferView replaced and every
|
|
111
|
+
* bufferView re-packed (4-byte aligned) in its original order. Returns the output bytes.
|
|
112
|
+
*/
|
|
113
|
+
function squeezeGlb(path) {
|
|
114
|
+
const { json, views, size } = readGlb(path);
|
|
115
|
+
let changed = false;
|
|
116
|
+
for (const img of json.images ?? []) {
|
|
117
|
+
if (img.mimeType !== 'image/jpeg' || img.bufferView === undefined) continue;
|
|
118
|
+
const out = squeeze(views[img.bufferView], img.name ?? '');
|
|
119
|
+
if (out && out.length < views[img.bufferView].length) { views[img.bufferView] = out; changed = true; }
|
|
120
|
+
}
|
|
121
|
+
if (!changed) return readFileSync(path);
|
|
122
|
+
const bytes = glbBytes(json, views);
|
|
123
|
+
squeezed++; saved += size - bytes.length;
|
|
124
|
+
return bytes;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function readGlb(path) {
|
|
128
|
+
const b = readFileSync(path);
|
|
129
|
+
if (b.readUInt32LE(0) !== 0x46546c67) throw new Error(`${path}: not a GLB`);
|
|
130
|
+
const jsonLen = b.readUInt32LE(12);
|
|
131
|
+
const json = JSON.parse(b.subarray(20, 20 + jsonLen).toString('utf8'));
|
|
132
|
+
const binStart = 20 + jsonLen + 8;
|
|
133
|
+
const bin = b.subarray(binStart, binStart + b.readUInt32LE(20 + jsonLen));
|
|
134
|
+
const views = json.bufferViews.map((v) => bin.subarray(v.byteOffset ?? 0, (v.byteOffset ?? 0) + v.byteLength));
|
|
135
|
+
return { json, views, size: b.length };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Pack a GLB whose bufferViews are `views`, re-packed 4-byte aligned in order. */
|
|
139
|
+
function glbBytes(json, views) {
|
|
140
|
+
const parts = []; let off = 0;
|
|
141
|
+
json.bufferViews.forEach((v, i) => {
|
|
142
|
+
v.byteOffset = off; v.byteLength = views[i].length;
|
|
143
|
+
parts.push(views[i]); off += views[i].length;
|
|
144
|
+
const pad = (4 - (off % 4)) % 4; if (pad) { parts.push(Buffer.alloc(pad)); off += pad; }
|
|
145
|
+
});
|
|
146
|
+
json.buffers[0].byteLength = off;
|
|
147
|
+
const newBin = Buffer.concat(parts);
|
|
148
|
+
let jsonBuf = Buffer.from(JSON.stringify(json), 'utf8');
|
|
149
|
+
jsonBuf = Buffer.concat([jsonBuf, Buffer.alloc((4 - (jsonBuf.length % 4)) % 4, 0x20)]);
|
|
150
|
+
const header = Buffer.alloc(12); header.writeUInt32LE(0x46546c67, 0); header.writeUInt32LE(2, 4);
|
|
151
|
+
const jh = Buffer.alloc(8); jh.writeUInt32LE(jsonBuf.length, 0); jh.writeUInt32LE(0x4e4f534a, 4);
|
|
152
|
+
const bh = Buffer.alloc(8); bh.writeUInt32LE(newBin.length, 0); bh.writeUInt32LE(0x004e4942, 4);
|
|
153
|
+
const total = 12 + 8 + jsonBuf.length + 8 + newBin.length; header.writeUInt32LE(total, 8);
|
|
154
|
+
return Buffer.concat([header, jh, jsonBuf, bh, newBin]);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ── 3. .phone.webp siblings ──
|
|
158
|
+
const PHONE_MAX = 1024, ARM_MAX = 512;
|
|
159
|
+
/** AO / roughness / metalness planes: low-frequency, the phone gets them at half resolution */
|
|
160
|
+
const isArm = (p) => /(^|[_/-])(arm|rough|roughness|metal|metallic)([_.-]|$)/i.test(p.split('/').pop() ?? p);
|
|
161
|
+
/**
|
|
162
|
+
* [file the other tiers download, best source to encode from, max px] for every image the phone fetches: baked planes (cards, fur, clouds, planet),
|
|
163
|
+
* the twig atlas, every Poly Haven set (encoded from the ORIGINAL map, not the q82 _1k copy — one lossy pass, not
|
|
164
|
+
* two) and the glTF props' textures (through the loaders' URL modifier, src/client/engine/boot/bytes.ts).
|
|
165
|
+
*/
|
|
166
|
+
function phoneJobs() {
|
|
167
|
+
const jobs = [];
|
|
168
|
+
const walk = (dir) => { for (const n of readdirSync(dir)) { const p = join(dir, n); if (statSync(p).isDirectory()) walk(p); else if (/\.(png|jpg)$/.test(n) && !n.includes('.phone.')) jobs.push([p, p, PHONE_MAX]); } };
|
|
169
|
+
walk('public/assets/baked');
|
|
170
|
+
for (const { source, served, max } of textureTierJobs([...new Set([...textureFiles, ...tierJobs.map((job) => job.output)])].filter(existsSync)).filter((job) => job.kind === 'phone')) jobs.push([served, source, max]);
|
|
171
|
+
for (const id of readdirSync(MODELS)) {
|
|
172
|
+
const t = join(MODELS, id, 'textures');
|
|
173
|
+
if (existsSync(t)) for (const n of readdirSync(t)) if (n.endsWith('.jpg') && !n.includes('.phone.')) jobs.push([join(t, n), join(t, n), isArm(n) ? ARM_MAX : PHONE_MAX]);
|
|
174
|
+
}
|
|
175
|
+
return jobs;
|
|
176
|
+
}
|
|
177
|
+
function phoneName(p) { return p.replace(/\.(png|jpg)$/, '.phone.webp'); }
|
|
178
|
+
|
|
179
|
+
/** WebP of `src` (a file or a JPEG buffer) capped at `max` px. PNG alpha stays lossless; RGB under it is kept (-exact). */
|
|
180
|
+
function webp(src, max, out) {
|
|
181
|
+
const tmp = `${out}.tmp.png`;
|
|
182
|
+
const input = Buffer.isBuffer(src) ? ['jpg:-'] : [src];
|
|
183
|
+
const [w, h] = execFileSync('magick', ['identify', '-format', '%w %h', ...input], Buffer.isBuffer(src) ? { input: src } : {}).toString().trim().split(' ').map(Number);
|
|
184
|
+
const resize = Math.max(w, h) > max ? ['-separate', '-resize', `${max}x${max}`, '-combine'] : []; // per channel: the default alpha-weighted resize blackens the RGB under transparent texels
|
|
185
|
+
execFileSync('magick', [...input, ...resize, '-strip', tmp], Buffer.isBuffer(src) ? { input: src } : {});
|
|
186
|
+
execFileSync('cwebp', ['-quiet', '-q', '75', '-sharp_yuv', '-alpha_q', '100', '-exact', '-m', '6', tmp, '-o', out]);
|
|
187
|
+
rmSync(tmp);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let phoneMade = 0, phoneSkipped = 0;
|
|
191
|
+
for (const [served, src, max] of phoneJobs()) {
|
|
192
|
+
const out = phoneName(served);
|
|
193
|
+
copy(src, out, { format: 'webp', max, quality: 75, sharpYuv: true, alphaQuality: 100, exact: true, method: 6, resize: 'separate-combine', minSaving: 0.15, servedHash: outputHash(readFileSync(served)) }, () => {
|
|
194
|
+
const temp = join(scratch, `${++scratchId}.webp`);
|
|
195
|
+
webp(src, max, temp);
|
|
196
|
+
const bytes = readFileSync(temp); rmSync(temp);
|
|
197
|
+
if (bytes.length > statSync(served).size * 0.85) { phoneSkipped++; return null; }
|
|
198
|
+
phoneMade++;
|
|
199
|
+
return bytes;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ── 4. <id>_lod.phone.glb: the props' embedded JPEGs as WebP (EXT_texture_webp), ARM planes at half resolution ──
|
|
204
|
+
for (const id of readdirSync(MODELS)) {
|
|
205
|
+
const glb = join(MODELS, id, `${id}_lod.glb`), out = join(MODELS, id, `${id}_lod.phone.glb`);
|
|
206
|
+
if (!existsSync(glb)) continue;
|
|
207
|
+
copy(glb, out, { format: 'glb-webp', max: PHONE_MAX, armMax: ARM_MAX, quality: 75, sharpYuv: true, alphaQuality: 100, exact: true, method: 6, resize: 'separate-combine', alignment: 4 }, () => {
|
|
208
|
+
const { json, views } = readGlb(glb);
|
|
209
|
+
const tmp = join(scratch, `${++scratchId}.webp`);
|
|
210
|
+
(json.images ?? []).forEach((img, i) => {
|
|
211
|
+
if (img.mimeType !== 'image/jpeg' || img.bufferView === undefined) return;
|
|
212
|
+
webp(views[img.bufferView], isArm(img.name ?? '') ? ARM_MAX : PHONE_MAX, tmp);
|
|
213
|
+
views[img.bufferView] = readFileSync(tmp); rmSync(tmp);
|
|
214
|
+
img.mimeType = 'image/webp';
|
|
215
|
+
for (const t of json.textures ?? []) if (t.source === i) { t.extensions = { ...t.extensions, EXT_texture_webp: { source: i } }; delete t.source; }
|
|
216
|
+
});
|
|
217
|
+
for (const k of ['extensionsUsed', 'extensionsRequired']) json[k] = [...new Set([...(json[k] ?? []), 'EXT_texture_webp'])];
|
|
218
|
+
phoneMade++;
|
|
219
|
+
return glbBytes(json, views);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
// Other pipelines own Nalati rigs, shard-specific phone textures and hand-authored model variants.
|
|
223
|
+
// Sweep only the folders/families this script generates; never remove another pipeline's copies.
|
|
224
|
+
const sweep = (dir) => { for (const n of readdirSync(dir)) { const p = join(dir, n); if (statSync(p).isDirectory()) sweep(p); else if (n.includes('.phone.') && !want.has(p) && !stale.has(p)) output.remove(p); } };
|
|
225
|
+
if (!seed) {
|
|
226
|
+
sweep('public/assets/baked');
|
|
227
|
+
sweep(ROOT);
|
|
228
|
+
for (const id of readdirSync(MODELS)) {
|
|
229
|
+
const out = join(MODELS, id, `${id}_lod.phone.glb`);
|
|
230
|
+
if (existsSync(out) && !want.has(out) && !stale.has(out)) output.remove(out);
|
|
231
|
+
const tex = join(MODELS, id, 'textures');
|
|
232
|
+
if (existsSync(tex)) sweep(tex);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
for (const path of stale) console.log(`tex-tiers: STALE ${path} (source/settings cache entry or output hash missing/mismatched)`);
|
|
236
|
+
if (stale.size > 0) process.exitCode = 1;
|
|
237
|
+
if (!check) output.put(CACHE, jsonBytes(Object.fromEntries(Object.entries(cache).sort(([a], [b]) => a.localeCompare(b)))));
|
|
238
|
+
console.log(`tex-tiers: ${made} _1k encoded · ${squeezed} model files squeezed (−${(saved / 1048576).toFixed(1)} MB) · ${phoneMade} phone copies encoded, ${phoneSkipped} not kept`);
|
|
239
|
+
output.finish();
|
|
240
|
+
console.log(`tex-tiers: ${encoded} encoded, ${reused} reused, ${seeded} seeded${seed ? ' (cache only; assets untouched)' : ''}`);
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// texmem-probe.mjs — the in-page halves of scripts/gpu-texmem.mjs (E157): `ledger`
|
|
2
|
+
// (an init script: the WebGL texture allocation ledger, window.__texmem) and `report` (after the settle: totals by format /
|
|
3
|
+
// source, the scene's textures labelled). Both are serialised into the page by Playwright: self-contained, no imports.
|
|
4
|
+
/** in the page before any script: the WebGL allocation ledger (window.__texmem) */
|
|
5
|
+
export function ledger() {
|
|
6
|
+
const BPP = {
|
|
7
|
+
0x8058: 4, 0x8c43: 4, 0x8051: 4, 0x8c41: 4, 0x1908: 4, 0x1907: 4, // RGBA8 SRGB8_ALPHA8 RGB8 SRGB8 RGBA RGB
|
|
8
|
+
0x8229: 1, 0x822b: 2, 0x1909: 1, 0x190a: 2, 0x1906: 1, 0x8231: 1, 0x8233: 1, // R8 RG8 LUMINANCE LUMINANCE_ALPHA ALPHA R8I R8UI
|
|
9
|
+
0x822d: 2, 0x822f: 4, 0x881a: 8, 0x881b: 8, 0x8814: 16, 0x8815: 16, 0x822e: 4, 0x8230: 8, // R16F RG16F RGBA16F RGB16F RGBA32F RGB32F R32F RG32F
|
|
10
|
+
0x8c3a: 4, 0x8c3d: 4, 0x8059: 4, 0x906f: 4, // R11F_G11F_B10F RGB9_E5 RGB10_A2 RGB10_A2UI
|
|
11
|
+
0x81a5: 2, 0x81a6: 4, 0x8cac: 4, 0x88f0: 4, 0x8cad: 8, 0x1902: 4, 0x84f9: 4, // DEPTH16 DEPTH24 DEPTH32F DEPTH24_STENCIL8 DEPTH32F_STENCIL8 DEPTH_COMPONENT DEPTH_STENCIL
|
|
12
|
+
0x8d62: 2, 0x8056: 2, 0x8057: 2, 0x8d48: 1, // RGB565 RGBA4 RGB5_A1 STENCIL8
|
|
13
|
+
0x8235: 4, 0x8236: 4, 0x823b: 8, 0x823c: 8, 0x8d70: 16, 0x8d71: 12, 0x8d82: 4, 0x8d83: 4, // R32I R32UI RG32I RG32UI RGBA32UI RGB32UI …
|
|
14
|
+
};
|
|
15
|
+
const TYPEB = { 0x1401: 1, 0x1406: 4, 0x140b: 2, 0x8d61: 2, 0x1403: 2, 0x1405: 4 }; // UNSIGNED_BYTE FLOAT HALF_FLOAT HALF_FLOAT_OES UNSIGNED_SHORT UNSIGNED_INT
|
|
16
|
+
const texs = new Map(); // WebGLTexture → { levels: Map<key, bytes>, w, h, d, fmt, rt, compressed, storage }
|
|
17
|
+
const rbs = new Map();
|
|
18
|
+
const T = { id: 0 };
|
|
19
|
+
const P = { texs, rbs, bound: new Map(), unit: 0x84c0, urls: new Set() };
|
|
20
|
+
window.__texmem = P;
|
|
21
|
+
try { performance.setResourceTimingBufferSize(10000); } catch { /* the default 250 drops a big shard's late files */ }
|
|
22
|
+
// where each decoded image came from: Response.blob() tags its blob with the response URL, createImageBitmap passes the
|
|
23
|
+
// tag on (GLB-embedded images arrive as blob: URLs — 'glb'); an <img>'s src is its own tag
|
|
24
|
+
const tags = new WeakMap(); P.tags = tags;
|
|
25
|
+
const ob = Object.getOwnPropertyDescriptor(Response.prototype, 'blob')?.value;
|
|
26
|
+
const resUrl = new WeakMap(); // the game re-wraps responses (the byte counter's tee): remember the URL each fetch asked for
|
|
27
|
+
const tagFetch = (f) => async function taggedFetch(input, init) {
|
|
28
|
+
try { const u0 = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url; if (!u0.startsWith('blob:')) P.urls.add(new URL(u0, location.href).pathname); } catch { /* */ }
|
|
29
|
+
const res = await f.call(window, input, init);
|
|
30
|
+
try { const u = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url; resUrl.set(res, u.startsWith('blob:') ? 'glb-embedded' : new URL(u, location.href).pathname); } catch { /* */ }
|
|
31
|
+
return res;
|
|
32
|
+
};
|
|
33
|
+
let fetchFn = tagFetch(window.fetch);
|
|
34
|
+
Object.defineProperty(window, 'fetch', { configurable: true, get: () => fetchFn, set: (f) => { fetchFn = tagFetch(f); } });
|
|
35
|
+
Response.prototype.blob = async function blob() { const b = await Reflect.apply(ob, this, []); try { const u = resUrl.get(this) ?? this.url; tags.set(b, u.startsWith('blob:') ? 'glb-embedded' : u.startsWith('/') || u === 'glb-embedded' ? u : new URL(u).pathname); } catch { /* */ } return b; };
|
|
36
|
+
const ocib = window.createImageBitmap.bind(window);
|
|
37
|
+
window.createImageBitmap = async function createImageBitmap(src, ...rest) { const bm = await ocib(src, ...rest); const t = tags.get(src) ?? (src instanceof Blob ? 'blob' : src.src ?? src.constructor.name); if (t) tags.set(bm, t); return bm; };
|
|
38
|
+
const tagOf = (src) => { if (!src || typeof src !== 'object') return ''; const t = tags.get(src); if (t) return t; if (src.src) { try { return new URL(src.src).pathname; } catch { return String(src.src).slice(0, 40); } } return src.constructor.name; };
|
|
39
|
+
const cur = (target) => {
|
|
40
|
+
const t2 = target >= 0x8515 && target <= 0x851a ? 0x8513 : target; // cube faces → cube map
|
|
41
|
+
return P.bound.get(`${P.unit}:${t2}`) ?? null;
|
|
42
|
+
};
|
|
43
|
+
const rec = (tex) => { let r = texs.get(tex); if (r === undefined) { r = { id: ++T.id, levels: new Map(), w: 0, h: 0, d: 1, fmt: 0, rt: false, compressed: false, cube: false, mipGen: false, tag: '' }; texs.set(tex, r); } return r; };
|
|
44
|
+
const dimsOf = (src) => {
|
|
45
|
+
const w = src.naturalWidth ?? src.videoWidth ?? src.displayWidth ?? src.width ?? 0;
|
|
46
|
+
const h = src.naturalHeight ?? src.videoHeight ?? src.displayHeight ?? src.height ?? 0;
|
|
47
|
+
return [w, h];
|
|
48
|
+
};
|
|
49
|
+
for (const Ctx of [window.WebGL2RenderingContext, window.WebGLRenderingContext]) {
|
|
50
|
+
const p = Ctx.prototype;
|
|
51
|
+
const wrap = (name, fn) => {
|
|
52
|
+
const o = p[name];
|
|
53
|
+
if (typeof o !== 'function') return;
|
|
54
|
+
p[name] = function wrapped(...a) { try { fn(a); } catch { /* ledger only */ } return Reflect.apply(o, this, a); };
|
|
55
|
+
};
|
|
56
|
+
wrap('activeTexture', (a) => { P.unit = a[0]; });
|
|
57
|
+
wrap('bindTexture', (a) => { P.bound.set(`${P.unit}:${a[0]}`, a[1]); if (a[1]) { const r = rec(a[1]); if (a[0] === 0x8513) r.cube = true; if (a[0] === 0x8c1a || a[0] === 0x806f) r.array = a[0]; } });
|
|
58
|
+
wrap('deleteTexture', (a) => { texs.delete(a[0]); });
|
|
59
|
+
wrap('texStorage2D', (a) => {
|
|
60
|
+
const [target, levels, fmt, w, h] = a; const t = cur(target); if (!t) return; const r = rec(t);
|
|
61
|
+
r.w = w; r.h = h; r.fmt = fmt; r.storage = true; r.levels.clear();
|
|
62
|
+
const faces = target === 0x8513 ? 6 : 1;
|
|
63
|
+
const cfmt = !(fmt in BPP);
|
|
64
|
+
for (let l = 0; l < levels; l++) {
|
|
65
|
+
const lw = Math.max(1, w >> l), lh = Math.max(1, h >> l);
|
|
66
|
+
r.levels.set(`${l}`, cfmt ? Math.ceil(lw / 4) * Math.ceil(lh / 4) * (P.blockBytes?.[fmt] ?? 16) * faces : lw * lh * BPP[fmt] * faces);
|
|
67
|
+
}
|
|
68
|
+
if (cfmt) r.compressed = true;
|
|
69
|
+
});
|
|
70
|
+
wrap('texStorage3D', (a) => {
|
|
71
|
+
const [target, levels, fmt, w, h, d] = a; const t = cur(target); if (!t) return; const r = rec(t);
|
|
72
|
+
r.w = w; r.h = h; r.d = d; r.fmt = fmt; r.storage = true; r.levels.clear();
|
|
73
|
+
const cfmt = !(fmt in BPP);
|
|
74
|
+
for (let l = 0; l < levels; l++) {
|
|
75
|
+
const lw = Math.max(1, w >> l), lh = Math.max(1, h >> l), ld = target === 0x806f ? Math.max(1, d >> l) : d;
|
|
76
|
+
r.levels.set(`${l}`, cfmt ? Math.ceil(lw / 4) * Math.ceil(lh / 4) * (P.blockBytes?.[fmt] ?? 16) * ld : lw * lh * ld * BPP[fmt]);
|
|
77
|
+
}
|
|
78
|
+
if (cfmt) r.compressed = true;
|
|
79
|
+
});
|
|
80
|
+
wrap('texImage2D', (a) => {
|
|
81
|
+
const target = a[0], level = a[1], fmt = a[2]; const t = cur(target); if (!t) return; const r = rec(t);
|
|
82
|
+
let w, h, type;
|
|
83
|
+
if (a.length >= 8) { w = a[3]; h = a[4]; type = a[7]; } else { [w, h] = dimsOf(a[5]); type = a[4]; r.tag = tagOf(a[5]); }
|
|
84
|
+
let bpp = BPP[fmt] ?? 4;
|
|
85
|
+
if (fmt === 0x1908 || fmt === 0x1907) bpp = 4 * (TYPEB[type] ?? 1);
|
|
86
|
+
if (level === 0) { r.w = w; r.h = h; r.fmt = fmt; }
|
|
87
|
+
r.levels.set(`${target}:${level}`, w * h * bpp);
|
|
88
|
+
});
|
|
89
|
+
wrap('texImage3D', (a) => {
|
|
90
|
+
const [target, level, fmt, w, h, d] = a; const type = a[8]; const t = cur(target); if (!t) return; const r = rec(t);
|
|
91
|
+
let bpp = BPP[fmt] ?? 4; if (fmt === 0x1908 || fmt === 0x1907) bpp = 4 * (TYPEB[type] ?? 1);
|
|
92
|
+
if (level === 0) { r.w = w; r.h = h; r.d = d; r.fmt = fmt; }
|
|
93
|
+
r.levels.set(`${target}:${level}`, w * h * d * bpp);
|
|
94
|
+
});
|
|
95
|
+
wrap('compressedTexImage2D', (a) => {
|
|
96
|
+
const [target, level, fmt, w, h] = a; const t = cur(target); if (!t) return; const r = rec(t);
|
|
97
|
+
const data = a[6]; const n = typeof data === 'number' ? data : (a.length > 8 && typeof a[8] === 'number' ? a[8] : data?.byteLength ?? 0);
|
|
98
|
+
if (level === 0) { r.w = w; r.h = h; r.fmt = fmt; }
|
|
99
|
+
r.compressed = true; r.levels.set(`${target}:${level}`, n);
|
|
100
|
+
});
|
|
101
|
+
wrap('compressedTexImage3D', (a) => {
|
|
102
|
+
const [target, level, fmt, w, h, d] = a; const t = cur(target); if (!t) return; const r = rec(t);
|
|
103
|
+
const data = a[7]; const n = typeof data === 'number' ? data : data?.byteLength ?? 0;
|
|
104
|
+
if (level === 0) { r.w = w; r.h = h; r.d = d; r.fmt = fmt; }
|
|
105
|
+
r.compressed = true; r.levels.set(`${target}:${level}`, n);
|
|
106
|
+
});
|
|
107
|
+
wrap('texSubImage2D', (a) => { const t = cur(a[0]); if (!t) return; const src = a[a.length - 1]; const g = tagOf(src); if (g && !/Uint|Float|Int|DataView|Array/.test(g)) { const r = rec(t); if (r.tag === '') r.tag = g; } });
|
|
108
|
+
wrap('texSubImage3D', (a) => { const t = cur(a[0]); if (!t) return; const src = a[a.length - 1]; const g = tagOf(src); if (g && !/Uint|Float|Int|DataView|Array/.test(g)) { const r = rec(t); if (r.tag === '') r.tag = g; else if (!r.tag.includes(g) && !r.tag.endsWith('+')) r.tag = `${r.tag}+`; } });
|
|
109
|
+
wrap('generateMipmap', (a) => {
|
|
110
|
+
const t = cur(a[0]); if (!t) return; const r = rec(t);
|
|
111
|
+
if (r.storage) return; // the chain was allocated by texStorage
|
|
112
|
+
r.mipGen = true;
|
|
113
|
+
const base = [...r.levels.values()].reduce((s, v) => s + v, 0);
|
|
114
|
+
r.levels.set('mips', Math.round(base / 3));
|
|
115
|
+
});
|
|
116
|
+
wrap('framebufferTexture2D', (a) => { if (a[3]) rec(a[3]).rt = true; });
|
|
117
|
+
wrap('framebufferTextureLayer', (a) => { if (a[2]) rec(a[2]).rt = true; });
|
|
118
|
+
wrap('bindRenderbuffer', (a) => { P.rb = a[1]; });
|
|
119
|
+
wrap('deleteRenderbuffer', (a) => { rbs.delete(a[0]); });
|
|
120
|
+
wrap('renderbufferStorage', (a) => { if (P.rb) rbs.set(P.rb, a[2] * a[3] * (BPP[a[1]] ?? 4)); });
|
|
121
|
+
wrap('renderbufferStorageMultisample', (a) => { if (P.rb) rbs.set(P.rb, a[3] * a[4] * (BPP[a[2]] ?? 4) * a[1]); });
|
|
122
|
+
}
|
|
123
|
+
// compressed block sizes (bytes per 4×4 block): ASTC 4x4 16, BC7 16, BC1 8, BC3 16, ETC2 RGB 8, ETC2 RGBA 16, ETC1 8
|
|
124
|
+
P.blockBytes = { 0x93b0: 16, 0x93d0: 16, 0x8e8c: 16, 0x8e8d: 16, 0x83f0: 8, 0x83f1: 8, 0x83f3: 16, 0x8c4c: 8, 0x8c4f: 16, 0x9274: 8, 0x9275: 8, 0x9278: 16, 0x9279: 16, 0x8d64: 8 };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** in the page, after the settle: totals + the scene's textures, labelled */
|
|
128
|
+
export function report(top) {
|
|
129
|
+
const P = window.__texmem, g = window.__wildshard?.world?.game;
|
|
130
|
+
const sum = (r) => [...r.levels.values()].reduce((s, v) => s + v, 0);
|
|
131
|
+
const mb = (b) => Number((b / 1048576).toFixed(1));
|
|
132
|
+
const FMT = { 0x8058: 'RGBA8', 0x8c43: 'SRGB8_A8', 0x8051: 'RGB8', 0x1908: 'RGBA', 0x1907: 'RGB', 0x93b0: 'ASTC4x4', 0x93d0: 'SRGB_ASTC4x4', 0x8e8c: 'BC7', 0x8e8d: 'SRGB_BC7', 0x83f0: 'BC1', 0x83f3: 'BC3', 0x9274: 'ETC2', 0x9275: 'SRGB_ETC2', 0x9278: 'ETC2_EAC', 0x9279: 'SRGB_ETC2_EAC', 0x8d64: 'ETC1', 0x881a: 'RGBA16F', 0x822d: 'R16F', 0x8229: 'R8', 0x822b: 'RG8', 0x88f0: 'D24S8', 0x81a6: 'D24', 0x8cac: 'D32F', 0x8c3a: 'R11G11B10F', 0x8814: 'RGBA32F', 0x822e: 'R32F', 0x1909: 'LUM' };
|
|
133
|
+
const owner = new Map(); // WebGLTexture → labels
|
|
134
|
+
if (g) {
|
|
135
|
+
const props = g.renderer.properties;
|
|
136
|
+
const seen = new Set();
|
|
137
|
+
const label = (tex, where) => {
|
|
138
|
+
if (!tex?.isTexture) return;
|
|
139
|
+
const gl = props.get(tex).__webglTexture; if (!gl) return;
|
|
140
|
+
let o = owner.get(gl); if (o === undefined) { o = { names: new Set(), where: new Set(), src: '' }; owner.set(gl, o); }
|
|
141
|
+
o.where.add(where);
|
|
142
|
+
const im = tex.image;
|
|
143
|
+
if (o.src === '') o.src = tex.isCompressedTexture ? 'compressed' : im?.src ? String(im.src).slice(-60) : im?.constructor?.name ?? '';
|
|
144
|
+
if (tex.name) o.names.add(tex.name);
|
|
145
|
+
};
|
|
146
|
+
const path = (obj) => { const n = []; for (let o = obj; o && n.length < 3; o = o.parent) if (o.name) n.push(o.name); return n.join('<') || obj.type; };
|
|
147
|
+
g.scene.traverse((obj) => {
|
|
148
|
+
const mats = obj.material ? (Array.isArray(obj.material) ? obj.material : [obj.material]) : [];
|
|
149
|
+
for (const m of mats) {
|
|
150
|
+
if (!m || seen.has(m.uuid + obj.uuid)) continue; seen.add(m.uuid + obj.uuid);
|
|
151
|
+
for (const k of Object.keys(m)) { const v = m[k]; if (v?.isTexture) label(v, `${path(obj)}.${k}`); }
|
|
152
|
+
if (m.uniforms) for (const [k, u] of Object.entries(m.uniforms)) { const v = u?.value; if (v?.isTexture) label(v, `${path(obj)}.u:${k}`); if (Array.isArray(v)) for (const x of v) if (x?.isTexture) label(x, `${path(obj)}.u:${k}[]`); }
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
if (g.scene.background?.isTexture) label(g.scene.background, 'scene.background');
|
|
156
|
+
if (g.scene.environment?.isTexture) label(g.scene.environment, 'scene.environment');
|
|
157
|
+
}
|
|
158
|
+
let texBytes = 0, rtBytes = 0, compressedBytes = 0, n = 0, nComp = 0;
|
|
159
|
+
const rows = [];
|
|
160
|
+
for (const [gl, r] of P.texs) {
|
|
161
|
+
const b = sum(r); if (b === 0) continue;
|
|
162
|
+
if (r.rt) { rtBytes += b; continue; }
|
|
163
|
+
texBytes += b; n++;
|
|
164
|
+
if (r.compressed) { compressedBytes += b; nComp++; }
|
|
165
|
+
const o = owner.get(gl);
|
|
166
|
+
rows.push({ id: r.id, mb: Number((b / 1048576).toFixed(2)), w: r.w, h: r.h, d: r.d, fmt: FMT[r.fmt] ?? `0x${r.fmt.toString(16)}`, mips: r.storage ? 'storage' : r.mipGen ? 'gen' : [...r.levels.keys()].length > 1 ? 'up' : 'none', src: r.tag === '' ? o?.src ?? '' : r.tag, name: o ? [...o.names].join(',') : '', where: o ? [...o.where].slice(0, 3).join(' | ') : '(not in scene)' });
|
|
167
|
+
}
|
|
168
|
+
rows.sort((a, b) => b.mb - a.mb);
|
|
169
|
+
let rbBytes = 0; for (const v of P.rbs.values()) rbBytes += v;
|
|
170
|
+
const byFmt = {};
|
|
171
|
+
for (const r of rows) byFmt[r.fmt] = Number(((byFmt[r.fmt] ?? 0) + r.mb).toFixed(2));
|
|
172
|
+
const cls = (r) => { const s = r.src; if (s.startsWith('/assets/')) { const p = s.split('/'); return p.slice(0, p[2] === 'baked' || p[2] === 'models' ? 5 : 4).join('/'); } return s.startsWith('glb') ? 'glb-embedded' : `runtime ${s === '' ? '?' : s}`; };
|
|
173
|
+
const byClass = {};
|
|
174
|
+
for (const r of rows) { const k = cls(r); byClass[k] ??= { mb: 0, n: 0 }; const c = byClass[k]; c.mb = Number((c.mb + r.mb).toFixed(2)); c.n++; }
|
|
175
|
+
const inScene = rows.filter((r) => r.where !== '(not in scene)').reduce((s, r) => s + r.mb, 0);
|
|
176
|
+
const mem = performance.memory ? performance.memory.usedJSHeapSize : 0;
|
|
177
|
+
const info = g ? g.renderer.info.memory : {};
|
|
178
|
+
const ext = g ? g.renderer.getContext().getSupportedExtensions().filter((e) => e.includes('compressed')) : [];
|
|
179
|
+
return {
|
|
180
|
+
textureMB: mb(texBytes), compressedMB: mb(compressedBytes), textures: n, compressedTextures: nComp,
|
|
181
|
+
inSceneMB: Number(inScene.toFixed(1)), renderTargetMB: mb(rtBytes), renderbufferMB: mb(rbBytes),
|
|
182
|
+
jsHeapMB: mb(mem), threeInfo: info, compressedExtensions: ext, byFormat: byFmt, byClass, fetched: [...new Set([...P.urls, ...performance.getEntriesByType('resource').map((e) => { try { return new URL(e.name).pathname; } catch { return ''; } })])].filter((u) => u.startsWith('/assets/') && /\.(glb|gltf|ktx2|webp|jpg|png)$/.test(u)).sort((a, b) => a.localeCompare(b)), top: rows.slice(0, top), all: rows,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// unused-assets.mjs — E161 ("cull and GC stale / unused stuff"): every file under public/ that no build path references.
|
|
3
|
+
//
|
|
4
|
+
// A file is USED when any of these reach it:
|
|
5
|
+
// 1. a shard's boot, per tier (phone, desktop): src/client/engine/boot/manifest.ts `chunkFiles` for every shard — the packs are cut
|
|
6
|
+
// from these same files (scripts/bake-packs.mjs) — plus Rapier's WASM and the navmesh;
|
|
7
|
+
// 2. the audio manifests: every file a public/assets/music/*/music.json or sfx/*/sfx.json names (+ the manifests);
|
|
8
|
+
// 3. a used .gltf's own buffers / images;
|
|
9
|
+
// 4. a sibling of a used file that differs only by its tier / format suffix (`x.phone.webp`, `x.ktx2`, `x.phone.glb`);
|
|
10
|
+
// 5. the game's code and pages naming it: src/ (not the *.generated.ts tables, which list every file),
|
|
11
|
+
// index.html, public/manifest.webmanifest, vite.config.ts, vite/ — by its path, or by its file stem together with its
|
|
12
|
+
// folder's name (`/assets/lut/${slug}.bin`, `${DIR}${kind}.gen.glb` build paths from pieces).
|
|
13
|
+
// A folder the code builds names inside counts whole: its path is named (`'/assets/pine-hollow/journal'` + `${id}.webp`),
|
|
14
|
+
// or it is a texture set / model folder whose id is named (`pbrUrls('stone_wall')` → /assets/tex/stone_wall/*).
|
|
15
|
+
// A file only scripts/ or test/ name is DEV-ONLY: listed, kept.
|
|
16
|
+
// A file (or its folder) a doc under docs/ names is DOCUMENTED — staged for a pass, not wired in yet: listed, kept.
|
|
17
|
+
// Everything else is UNUSED.
|
|
18
|
+
//
|
|
19
|
+
// node scripts/unused-assets.mjs the report (exit 0)
|
|
20
|
+
// node scripts/unused-assets.mjs --delete also delete the UNUSED files (then commit the deletions)
|
|
21
|
+
// node scripts/unused-assets.mjs --warn one warning line when there are unused files (the pre-push gate), exit 0
|
|
22
|
+
// node scripts/unused-assets.mjs --json the lists as JSON
|
|
23
|
+
import { execFileSync } from 'node:child_process';
|
|
24
|
+
import { existsSync, readFileSync, readdirSync, statSync, unlinkSync } from 'node:fs';
|
|
25
|
+
import { dirname, posix, resolve, join } from 'node:path';
|
|
26
|
+
import { pathToFileURL } from 'node:url';
|
|
27
|
+
|
|
28
|
+
const ROOT = resolve(import.meta.dirname, '..');
|
|
29
|
+
const argv = process.argv.slice(2);
|
|
30
|
+
const has = (f) => argv.includes(`--${f}`);
|
|
31
|
+
const collect = argv.find((a) => a.startsWith('--collect='))?.slice(10);
|
|
32
|
+
|
|
33
|
+
// ── child mode: one tier's boot files; initialize its row explicitly before reading assets ──
|
|
34
|
+
if (collect) {
|
|
35
|
+
const imp = (p) => import(pathToFileURL(resolve(ROOT, p)).href);
|
|
36
|
+
const { initializeTier } = await import('@wildshard/engine/core/tier');
|
|
37
|
+
await initializeTier(collect);
|
|
38
|
+
const { SHARDS } = await imp('src/shards.generated.ts');
|
|
39
|
+
const { playable } = await imp('src/client/game/shard/registry.ts');
|
|
40
|
+
const PLAYABLE_SHARDS = SHARDS.filter(playable);
|
|
41
|
+
const { prepareShardAssets } = await imp('src/client/game/shard/load.ts');
|
|
42
|
+
const { registerGpuFiles } = await imp('src/client/engine/boot/gpuFiles.ts');
|
|
43
|
+
await Promise.all(SHARDS.map((m) => prepareShardAssets(m, registerGpuFiles)));
|
|
44
|
+
// Every authored GPU stand-in is shipped runtime data, even when this tier's default boots images.
|
|
45
|
+
const { GPU_FILES: engineGpu } = await imp('src/client/engine/boot/ktx2.generated.ts');
|
|
46
|
+
const { chunkFiles } = await imp('src/client/engine/boot/manifest.ts');
|
|
47
|
+
const out = new Set();
|
|
48
|
+
for (const def of PLAYABLE_SHARDS) for (const list of Object.values(chunkFiles(def))) for (const f of list) out.add(f);
|
|
49
|
+
for (const url of Object.values(engineGpu[collect])) out.add(url);
|
|
50
|
+
for (const def of SHARDS) if (def.ktx2) for (const url of Object.values((await def.ktx2()).GPU_FILES[collect])) out.add(url);
|
|
51
|
+
process.stdout.write(JSON.stringify([...out]));
|
|
52
|
+
process.exit(0);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── the files: tracked under public/, minus what every build regenerates (packs, Rapier's WASM: gitignored anyway) ──
|
|
56
|
+
const tracked = execFileSync('git', ['ls-files', '-z', 'public'], { cwd: ROOT, encoding: 'utf8' }).split('\0').filter(Boolean)
|
|
57
|
+
.filter((f) => existsSync(join(ROOT, f)) && !f.endsWith('.DS_Store'));
|
|
58
|
+
const pub = (f) => f.slice('public'.length); // public/assets/x → /assets/x
|
|
59
|
+
const files = tracked.map(pub);
|
|
60
|
+
const size = (p) => statSync(join(ROOT, 'public', p)).size;
|
|
61
|
+
|
|
62
|
+
const used = new Map(); // path → why
|
|
63
|
+
const use = (p, why) => { if (!used.has(p)) used.set(p, why); };
|
|
64
|
+
|
|
65
|
+
// 1. the boot, both tiers
|
|
66
|
+
for (const tier of ['phone', 'desktop']) {
|
|
67
|
+
const json = execFileSync(process.execPath, ['--import', './scripts/bake-loader.mjs', 'scripts/unused-assets.mjs', `--collect=${tier}`], { cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] });
|
|
68
|
+
for (const f of JSON.parse(json)) use(f, `boot (${tier})`);
|
|
69
|
+
}
|
|
70
|
+
use('/assets/physics/rapier.wasm', 'boot (physics)');
|
|
71
|
+
|
|
72
|
+
// 2. the audio manifests
|
|
73
|
+
const AUDIO_RE = /\.(m4a|mp3|ogg|opus|wav|webm|flac)$/;
|
|
74
|
+
const namedIn = (v, out) => {
|
|
75
|
+
if (typeof v === 'string') { if (AUDIO_RE.test(v) && !v.includes('/')) out.push(v); }
|
|
76
|
+
else if (Array.isArray(v)) for (const x of v) namedIn(x, out);
|
|
77
|
+
else if (v && typeof v === 'object') for (const x of Object.values(v)) namedIn(x, out);
|
|
78
|
+
return out;
|
|
79
|
+
};
|
|
80
|
+
for (const [kind, manifest] of [['music', 'music.json'], ['sfx', 'sfx.json']]) {
|
|
81
|
+
const dir = join(ROOT, 'public/assets', kind);
|
|
82
|
+
if (!existsSync(dir)) continue;
|
|
83
|
+
for (const d of readdirSync(dir)) {
|
|
84
|
+
const m = join(dir, d, manifest);
|
|
85
|
+
if (!existsSync(m)) continue;
|
|
86
|
+
use(`/assets/${kind}/${d}/${manifest}`, 'audio manifest');
|
|
87
|
+
for (const f of namedIn(JSON.parse(readFileSync(m, 'utf8')), [])) use(`/assets/${kind}/${d}/${f}`, `${kind}/${d}/${manifest}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 5. the code and pages (dev corpus separately)
|
|
92
|
+
const walk = (dir, out = []) => {
|
|
93
|
+
if (!existsSync(dir)) return out;
|
|
94
|
+
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
95
|
+
const p = join(dir, e.name);
|
|
96
|
+
if (e.isDirectory()) { if (e.name !== 'node_modules') walk(p, out); } else if (/\.(ts|tsx|js|mjs|cjs|css|html|json|glsl|py|sh|md|webmanifest)$/.test(e.name)) out.push(p);
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
};
|
|
100
|
+
const read = (ps) => ps.filter((p) => !p.endsWith('.generated.ts')).map((p) => readFileSync(p, 'utf8')).join('\n');
|
|
101
|
+
const game = read([
|
|
102
|
+
...walk(join(ROOT, 'src')),
|
|
103
|
+
join(ROOT, 'index.html'), join(ROOT, 'public/manifest.webmanifest'), join(ROOT, 'vite.config.ts'), ...walk(join(ROOT, 'vite')),
|
|
104
|
+
].filter((p) => existsSync(p)));
|
|
105
|
+
const dev = read([...walk(join(ROOT, 'scripts')).filter((p) => !p.endsWith('unused-assets.mjs')), ...walk(join(ROOT, 'test'))]);
|
|
106
|
+
const tokenIn = (text, t) => t.length > 2 && new RegExp(`(^|[^\\w-])${t.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`)}([^\\w-]|$)`).test(text);
|
|
107
|
+
/** named by path, or by stem + folder (a path built from pieces) */
|
|
108
|
+
function named(text, p) {
|
|
109
|
+
if (text.includes(p.slice(1)) || text.includes(p.replace(/\.[^./]+$/, '').slice(1))) return true;
|
|
110
|
+
const base = posix.basename(p), stem = base.split('.')[0], folder = posix.basename(posix.dirname(p));
|
|
111
|
+
if (p.split('/').length <= 2) return text.includes(base); // a root file: /icon-192.png, /trailer-15.mp4
|
|
112
|
+
return tokenIn(text, stem) && tokenIn(text, folder);
|
|
113
|
+
}
|
|
114
|
+
/** a folder the code reads by building names inside it: its path (`JOURNAL_ART = '/assets/pine-hollow/journal'`), or a texture
|
|
115
|
+
* set / model folder named by its id (`pbrUrls('stone_wall')`, `gltf('hatchet')`: `/assets/tex|models/${id}/…`) */
|
|
116
|
+
function folderNamed(text, p) {
|
|
117
|
+
const dir = posix.dirname(p);
|
|
118
|
+
if (text.includes(dir.slice(1))) return true;
|
|
119
|
+
const m = /^\/assets\/(tex|models)\/([^/]+)\//.exec(p);
|
|
120
|
+
return m !== null && tokenIn(text, m[2]);
|
|
121
|
+
}
|
|
122
|
+
for (const p of files) if (!used.has(p) && (named(game, p) || folderNamed(game, p))) use(p, 'named in the game code');
|
|
123
|
+
|
|
124
|
+
// 3 + 4, to a fixed point: glTF dependencies and tier / format siblings of what is used
|
|
125
|
+
const stemKey = (p) => { const d = posix.dirname(p), b = posix.basename(p); return `${d}/${b.split('.')[0]}`; };
|
|
126
|
+
const byStem = new Map();
|
|
127
|
+
for (const p of files) { const k = stemKey(p); byStem.set(k, [...(byStem.get(k) ?? []), p]); }
|
|
128
|
+
for (let grew = true; grew;) {
|
|
129
|
+
grew = false;
|
|
130
|
+
for (const [p, why] of used) { // a Map iterates the entries added meanwhile too
|
|
131
|
+
if (p.endsWith('.gltf') && existsSync(join(ROOT, 'public', p))) {
|
|
132
|
+
try {
|
|
133
|
+
const g = JSON.parse(readFileSync(join(ROOT, 'public', p), 'utf8'));
|
|
134
|
+
for (const r of [...(g.buffers ?? []), ...(g.images ?? [])]) {
|
|
135
|
+
if (typeof r.uri !== 'string' || r.uri.startsWith('data:')) continue;
|
|
136
|
+
const dep = posix.normalize(posix.join(posix.dirname(p), decodeURIComponent(r.uri)));
|
|
137
|
+
if (!used.has(dep)) { use(dep, `${p} (${why})`); grew = true; }
|
|
138
|
+
}
|
|
139
|
+
} catch { /* not JSON: left to the other rules */ }
|
|
140
|
+
}
|
|
141
|
+
for (const s of byStem.get(stemKey(p)) ?? []) if (!used.has(s)) { use(s, `a tier / format copy of ${p}`); grew = true; }
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const devReach = (p) => { if (named(dev, p)) return true; return folderNamed(dev, p); };
|
|
146
|
+
const devOnly = files.filter((p) => !used.has(p) && devReach(p));
|
|
147
|
+
// named by a design doc or a plan (a model set staged for a pass not yet wired in): kept, listed
|
|
148
|
+
const docs = read(walk(join(ROOT, 'docs')));
|
|
149
|
+
/** the file or a folder above it, three levels deep at least (`assets/nalati/sourced`, never plain `assets/nalati`) */
|
|
150
|
+
const ancestors = (p) => { const parts = p.slice(1).split('/'); const out = []; for (let i = parts.length; i >= 3; i--) out.push(parts.slice(0, i).join('/')); return out; };
|
|
151
|
+
const documented = files.filter((p) => !used.has(p) && !devOnly.includes(p) && ancestors(p).some((a) => docs.includes(a)));
|
|
152
|
+
const unused = files.filter((p) => !used.has(p) && !devOnly.includes(p) && !documented.includes(p));
|
|
153
|
+
const sum = (ps) => ps.reduce((s, p) => s + size(p), 0);
|
|
154
|
+
const mb = (b) => `${(b / 1048576).toFixed(2)} MB`;
|
|
155
|
+
|
|
156
|
+
if (has('json')) {
|
|
157
|
+
process.stdout.write(`${JSON.stringify({ files: files.length, used: used.size, devOnly: devOnly.map((p) => [p, size(p)]), documented: documented.map((p) => [p, size(p)]), unused: unused.map((p) => [p, size(p)]) }, null, 1)}\n`);
|
|
158
|
+
process.exit(0);
|
|
159
|
+
}
|
|
160
|
+
if (has('warn')) {
|
|
161
|
+
if (unused.length > 0) console.warn(`unused-assets: WARNING — ${unused.length} file(s) under public/ that nothing references (${mb(sum(unused))}); run node scripts/unused-assets.mjs to list them`);
|
|
162
|
+
process.exit(0);
|
|
163
|
+
}
|
|
164
|
+
console.log(`public/: ${files.length} tracked files, ${mb(sum(files))} · used ${files.length - devOnly.length - documented.length - unused.length} · dev-only ${devOnly.length} (${mb(sum(devOnly))}) · documented ${documented.length} (${mb(sum(documented))}) · UNUSED ${unused.length} (${mb(sum(unused))})`);
|
|
165
|
+
if (devOnly.length > 0) { console.log('\ndev-only (named by scripts/ or test/ — kept):'); for (const p of devOnly) console.log(` ${mb(size(p)).padStart(9)} ${p}`); }
|
|
166
|
+
if (documented.length > 0) { console.log('\ndocumented (named by docs/ — staged for a pass, kept):'); for (const p of documented) console.log(` ${mb(size(p)).padStart(9)} ${p}`); }
|
|
167
|
+
if (unused.length > 0) { console.log('\nUNUSED:'); for (const p of unused) console.log(` ${mb(size(p)).padStart(9)} ${p}`); }
|
|
168
|
+
if (has('delete') && unused.length > 0) {
|
|
169
|
+
const bytes = sum(unused);
|
|
170
|
+
for (const p of unused) unlinkSync(join(ROOT, 'public', p));
|
|
171
|
+
for (const d of new Set(unused.map((p) => dirname(join(ROOT, 'public', p))))) { try { if (readdirSync(d).length === 0) execFileSync('rmdir', [d]); } catch { /* not empty */ } }
|
|
172
|
+
console.log(`\ndeleted ${unused.length} files, ${mb(bytes)}`);
|
|
173
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** A sweep's clock and report-only switch. */
|
|
2
|
+
export interface SweepOptions { now?: number; dryRun?: boolean }
|
|
3
|
+
/** Age, byte cap, clock and report-only switch for the compile cache. */
|
|
4
|
+
export interface CompileCacheOptions extends SweepOptions { capBytes?: number; maxAgeMs?: number }
|
|
5
|
+
/** What one compile cache prune found and removed. */
|
|
6
|
+
export interface CompileCacheReport { files: number; beforeBytes: number; removed: number; keptBytes: number }
|
|
7
|
+
/** Where the run folder lives (default: the repo holding scripts/) and which janitor script a sweep starts. */
|
|
8
|
+
export interface TemporaryRunOptions { root?: string; janitor?: string }
|
|
9
|
+
/** Milliseconds since a path changed; a folder another process has just removed counts as new. */
|
|
10
|
+
export function age(path: string, now: number): number;
|
|
11
|
+
/** Remove tmp/vitest/<pid> of dead processes idle for an hour; returns how many. */
|
|
12
|
+
export function sweepVitestRuns(root: string, options?: SweepOptions): number;
|
|
13
|
+
/** Remove 21-character Vitest folders (only client/ and ssr/ inside) idle for an hour from a system temp dir. */
|
|
14
|
+
export function sweepSystemTemp(directory: string, options?: SweepOptions): { removed: number; files: number };
|
|
15
|
+
/** Remove compile cache entries past a day, then the oldest until under the byte cap. */
|
|
16
|
+
export function pruneCompileCache(directory: string, options?: CompileCacheOptions): CompileCacheReport;
|
|
17
|
+
/** Point TMPDIR and NODE_COMPILE_CACHE at the run's own folder under the repo's tmp/ until cleanup(). */
|
|
18
|
+
export function temporaryRun(env?: NodeJS.ProcessEnv, options?: TemporaryRunOptions): { dir: string; cleanup: () => void };
|
|
19
|
+
/** The Vite/Vitest plugin that keeps a run's temp files under the repo's tmp/vitest/<pid>. */
|
|
20
|
+
export function viteTmpRoot(options?: TemporaryRunOptions): {
|
|
21
|
+
name: string;
|
|
22
|
+
configureVitest: (context: { vitest: { onClose: (listener: () => void) => void } }) => void;
|
|
23
|
+
};
|