@wildshard/sdk 0.0.1 → 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 +13 -5
- 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 +365 -3
- 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,199 @@
|
|
|
1
|
+
import { number, object, safeParse, string } from 'valibot'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
draftKeyFile,
|
|
5
|
+
keyFile,
|
|
6
|
+
keyFileExists,
|
|
7
|
+
keyTransport,
|
|
8
|
+
maskKey,
|
|
9
|
+
readApiKey,
|
|
10
|
+
} from './key.ts'
|
|
11
|
+
|
|
12
|
+
import type { ApiKey } from './key.ts'
|
|
13
|
+
|
|
14
|
+
// `wildshard account <email>` and `wildshard whoami` (meta SHARD-DELETE DEL6,
|
|
15
|
+
// J309, J310). The account is api-server's `POST /api/accounts {email}`: a
|
|
16
|
+
// 201 answers `{email, key}`, the only time the key is shown, and an email
|
|
17
|
+
// with an account is a 409 whose key stays as it was. No mail is sent and
|
|
18
|
+
// the email is not proof of anything before DEL13. whoami names the key's
|
|
19
|
+
// source and first characters, then asks `GET /api/accounts/me` (api-server
|
|
20
|
+
// v0.12.0) for its account's email and slug count; an older API's 404 keeps
|
|
21
|
+
// the local lines only.
|
|
22
|
+
|
|
23
|
+
const OK = 200
|
|
24
|
+
const CREATED = 201
|
|
25
|
+
const UNAUTHORIZED = 401
|
|
26
|
+
const CONFLICT = 409
|
|
27
|
+
const NOT_FOUND = 404
|
|
28
|
+
const NONE = 0
|
|
29
|
+
const ONE = 1
|
|
30
|
+
const ME_TIMEOUT_MS = 15_000
|
|
31
|
+
|
|
32
|
+
const AccountSchema = object({ email: string(), key: string() })
|
|
33
|
+
const ErrorSchema = object({ error: string() })
|
|
34
|
+
const MeSchema = object({
|
|
35
|
+
email: string(),
|
|
36
|
+
slugs: number(),
|
|
37
|
+
deletedSlugs: number(),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
interface AccountOptions {
|
|
41
|
+
/** The api-server origin. */
|
|
42
|
+
readonly server: string
|
|
43
|
+
readonly email: string
|
|
44
|
+
/** Replace a key file that is there already. */
|
|
45
|
+
readonly force: boolean
|
|
46
|
+
/** The key file to write; the default is under the user's home. */
|
|
47
|
+
readonly file?: string
|
|
48
|
+
readonly report: (line: string) => void
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function jsonOf(text: string): unknown {
|
|
52
|
+
try {
|
|
53
|
+
const value: unknown = JSON.parse(text)
|
|
54
|
+
return value
|
|
55
|
+
} catch {
|
|
56
|
+
return undefined
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function reasonOf(body: unknown): string {
|
|
61
|
+
const parsed = safeParse(ErrorSchema, body)
|
|
62
|
+
return parsed.success ? parsed.output.error : 'not an api-server reply'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** One `POST /api/accounts`: the new account's email and key. */
|
|
66
|
+
async function createAccount(
|
|
67
|
+
server: string,
|
|
68
|
+
email: string,
|
|
69
|
+
): Promise<{ readonly email: string; readonly key: string }> {
|
|
70
|
+
const reply = await fetch(new URL('/api/accounts', server), {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: { 'content-type': 'application/json' },
|
|
73
|
+
body: JSON.stringify({ email }),
|
|
74
|
+
})
|
|
75
|
+
const body = jsonOf(await reply.text())
|
|
76
|
+
if (reply.status === CONFLICT) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`${email} already has an account; its key is not shown again, and a lost key needs an operator reset`,
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
const parsed = safeParse(AccountSchema, body)
|
|
82
|
+
if (reply.status !== CREATED || !parsed.success) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`/api/accounts answered ${String(reply.status)}: ${reasonOf(body)}`,
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
return parsed.output
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Why no account may be made yet, before any request: never a lost key. */
|
|
91
|
+
async function accountRefusal(
|
|
92
|
+
options: AccountOptions,
|
|
93
|
+
file: string,
|
|
94
|
+
): Promise<string | undefined> {
|
|
95
|
+
if (!options.force && (await keyFileExists(file))) {
|
|
96
|
+
return `${file} already holds a key; pass --force to replace it (the old key keeps working)`
|
|
97
|
+
}
|
|
98
|
+
return keyTransport(options.server)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Make the account and keep its key. An existing key file, a server that is
|
|
103
|
+
* not https and a key folder that can't be written all refuse before any
|
|
104
|
+
* request, so no account is made whose key could not be kept.
|
|
105
|
+
*/
|
|
106
|
+
async function makeAccount(options: AccountOptions): Promise<void> {
|
|
107
|
+
const file = options.file ?? keyFile()
|
|
108
|
+
const refusal = await accountRefusal(options, file)
|
|
109
|
+
if (refusal !== undefined) {
|
|
110
|
+
throw new Error(refusal)
|
|
111
|
+
}
|
|
112
|
+
const draft = await draftKeyFile(file, options.force)
|
|
113
|
+
const account = await createAccount(options.server, options.email).catch(
|
|
114
|
+
async (error: unknown): Promise<never> => {
|
|
115
|
+
await draft.drop()
|
|
116
|
+
throw error
|
|
117
|
+
},
|
|
118
|
+
)
|
|
119
|
+
await draft.keep(account.key)
|
|
120
|
+
options.report(
|
|
121
|
+
`account ${account.email}: key ${maskKey(account.key)} saved to ${file} (mode 600); it is not shown again`,
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The account line: its email and the slugs it owns. */
|
|
126
|
+
function accountLine(body: unknown, status: number): string {
|
|
127
|
+
const parsed = safeParse(MeSchema, body)
|
|
128
|
+
if (status !== OK || !parsed.success) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`/api/accounts/me answered ${String(status)}: ${reasonOf(body)}`,
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
const { email, slugs, deletedSlugs } = parsed.output
|
|
134
|
+
const deleted =
|
|
135
|
+
deletedSlugs > NONE ? ` (and ${String(deletedSlugs)} deleted)` : ''
|
|
136
|
+
const noun = slugs === ONE ? 'slug' : 'slugs'
|
|
137
|
+
return `account ${email} owns ${String(slugs)} ${noun}${deleted}`
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** One `GET /api/accounts/me`: the account line, or the older API's line. */
|
|
141
|
+
async function accountOfKey(server: string, key: string): Promise<string> {
|
|
142
|
+
const refusal = keyTransport(server)
|
|
143
|
+
if (refusal !== undefined) {
|
|
144
|
+
throw new Error(refusal)
|
|
145
|
+
}
|
|
146
|
+
const reply = await fetch(new URL('/api/accounts/me', server), {
|
|
147
|
+
headers: { authorization: `Bearer ${key}` },
|
|
148
|
+
signal: AbortSignal.timeout(ME_TIMEOUT_MS),
|
|
149
|
+
})
|
|
150
|
+
const body = jsonOf(await reply.text())
|
|
151
|
+
if (reply.status === NOT_FOUND) {
|
|
152
|
+
return `${server} has no /api/accounts/me (not api-server, or older than v0.12.0), so the email is not shown`
|
|
153
|
+
}
|
|
154
|
+
if (reply.status === UNAUTHORIZED) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
`${server} does not know this key (401): run wildshard account <email> on this server, or check WILDSHARD_API_KEY`,
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
return accountLine(body, reply.status)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** What whoami needs: the key's sources, the server and where lines go. */
|
|
163
|
+
interface WhoamiOptions {
|
|
164
|
+
/** WILDSHARD_API_KEY. */
|
|
165
|
+
readonly fromEnv: string | undefined
|
|
166
|
+
/** `--server`, else WILDSHARD_API_URL, else empty. */
|
|
167
|
+
readonly server: string
|
|
168
|
+
readonly report: (line: string) => void
|
|
169
|
+
/** The key file; the default is under the user's home. */
|
|
170
|
+
readonly file?: string
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* `wildshard whoami`: report the key's source and first characters, then its account's
|
|
175
|
+
* email and slug count from `server` (no server: say so). The key line is
|
|
176
|
+
* reported before the request, so a failed request still shows it.
|
|
177
|
+
*/
|
|
178
|
+
async function whoami(options: WhoamiOptions): Promise<void> {
|
|
179
|
+
const { fromEnv, server, report } = options
|
|
180
|
+
const file = options.file ?? keyFile()
|
|
181
|
+
const found: ApiKey | undefined = await readApiKey(fromEnv, file)
|
|
182
|
+
if (found === undefined) {
|
|
183
|
+
throw new Error(`no account key in WILDSHARD_API_KEY or ${file}`)
|
|
184
|
+
}
|
|
185
|
+
report(`key ${maskKey(found.key)} from ${found.source}`)
|
|
186
|
+
report(
|
|
187
|
+
server === ''
|
|
188
|
+
? 'no server (pass --server <url> or set WILDSHARD_API_URL), so the email is not shown'
|
|
189
|
+
: await accountOfKey(server, found.key),
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export {
|
|
194
|
+
type AccountOptions,
|
|
195
|
+
type WhoamiOptions,
|
|
196
|
+
createAccount,
|
|
197
|
+
makeAccount,
|
|
198
|
+
whoami,
|
|
199
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline'
|
|
2
|
+
|
|
3
|
+
import { deleteShard } from '../delete/delete.ts'
|
|
4
|
+
import { refuse, reportLine } from '../report.ts'
|
|
5
|
+
import { makeAccount, whoami } from './account.ts'
|
|
6
|
+
import { keyTransport, readApiKey } from './key.ts'
|
|
7
|
+
|
|
8
|
+
import type { CliArgs } from '../args.ts'
|
|
9
|
+
|
|
10
|
+
// The CLI's side of meta SHARD-DELETE DEL6 and DEL10, the commands of the
|
|
11
|
+
// account key: `wildshard account <email>`, `wildshard whoami`, the key
|
|
12
|
+
// upload sends, and `wildshard delete <slug> [--yes]` (the delete itself is
|
|
13
|
+
// ../delete/delete.ts). main.ts reads the environment and hands each value
|
|
14
|
+
// in. Exit codes are main.ts's. A delete with no slug, server or key
|
|
15
|
+
// refuses before any request; a slug typed wrong exits 1 with nothing
|
|
16
|
+
// deleted; a refused call exits 3.
|
|
17
|
+
|
|
18
|
+
const EXIT_OK = 0
|
|
19
|
+
const EXIT_USAGE = 1
|
|
20
|
+
const EXIT_FAILED = 3
|
|
21
|
+
/** A shard slug, as shard-format's upload wire spells it. */
|
|
22
|
+
const SLUG = /^[a-z][\d.a-z-]{0,127}$/u
|
|
23
|
+
|
|
24
|
+
function messageOf(error: unknown): string {
|
|
25
|
+
return error instanceof Error ? error.message : String(error)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** What is missing before `account` may call the API, if anything. */
|
|
29
|
+
function accountUsage(args: CliArgs, server: string): string | undefined {
|
|
30
|
+
if (args.operand === undefined) {
|
|
31
|
+
return 'usage: wildshard account <email> [--server <url>] [--force]'
|
|
32
|
+
}
|
|
33
|
+
return server === ''
|
|
34
|
+
? 'usage: wildshard account <email> --server <url> (or set WILDSHARD_API_URL)'
|
|
35
|
+
: undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** `wildshard account <email>`: make the account and keep its key. */
|
|
39
|
+
async function runAccount(args: CliArgs, server: string): Promise<number> {
|
|
40
|
+
const usage = accountUsage(args, server)
|
|
41
|
+
if (usage !== undefined || args.operand === undefined) {
|
|
42
|
+
refuse('account', '', usage ?? '')
|
|
43
|
+
return EXIT_USAGE
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
await makeAccount({
|
|
47
|
+
server,
|
|
48
|
+
email: args.operand,
|
|
49
|
+
force: args.force,
|
|
50
|
+
report: reportLine,
|
|
51
|
+
})
|
|
52
|
+
return EXIT_OK
|
|
53
|
+
} catch (error: unknown) {
|
|
54
|
+
refuse('account', 'account failed: ', messageOf(error))
|
|
55
|
+
return EXIT_FAILED
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** `wildshard whoami`: the key upload would send, masked, and its account. */
|
|
60
|
+
async function runWhoami(
|
|
61
|
+
fromEnv: string | undefined,
|
|
62
|
+
server: string,
|
|
63
|
+
): Promise<number> {
|
|
64
|
+
try {
|
|
65
|
+
await whoami({ fromEnv, server, report: reportLine })
|
|
66
|
+
return EXIT_OK
|
|
67
|
+
} catch (error: unknown) {
|
|
68
|
+
refuse('account', '', messageOf(error))
|
|
69
|
+
return EXIT_FAILED
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The key upload sends (WILDSHARD_API_KEY, else the key file's), or an
|
|
75
|
+
* Error for a key file that can't be read or a malformed key.
|
|
76
|
+
*/
|
|
77
|
+
async function apiKeyOf(
|
|
78
|
+
fromEnv: string | undefined,
|
|
79
|
+
): Promise<string | Error | undefined> {
|
|
80
|
+
try {
|
|
81
|
+
const found = await readApiKey(fromEnv)
|
|
82
|
+
return found?.key
|
|
83
|
+
} catch (error: unknown) {
|
|
84
|
+
return error instanceof Error ? error : new Error(String(error))
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* What stops upload sending the key, before any request: no key (api-server
|
|
90
|
+
* answers a keyless ticket 401 since DEL5), or a server that is not https.
|
|
91
|
+
*/
|
|
92
|
+
function uploadKeyRefusal(
|
|
93
|
+
server: string,
|
|
94
|
+
apiKey: string | undefined,
|
|
95
|
+
): string | undefined {
|
|
96
|
+
return apiKey === undefined
|
|
97
|
+
? 'upload needs an account key: run wildshard account <email>, or set WILDSHARD_API_KEY'
|
|
98
|
+
: keyTransport(server)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** What `delete` needs from main.ts (meta SHARD-DELETE DEL10). */
|
|
102
|
+
interface DeleteCommand {
|
|
103
|
+
readonly args: CliArgs
|
|
104
|
+
/** `--server`, else WILDSHARD_API_URL, else empty. */
|
|
105
|
+
readonly server: string
|
|
106
|
+
/** WILDSHARD_API_KEY. */
|
|
107
|
+
readonly fromEnv: string | undefined
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Print the prompt and read one line from stdin; undefined at its end. */
|
|
111
|
+
async function typedLine(prompt: string): Promise<string | undefined> {
|
|
112
|
+
process.stdout.write(prompt)
|
|
113
|
+
const lines = createInterface({ input: process.stdin, crlfDelay: Infinity })
|
|
114
|
+
try {
|
|
115
|
+
const first = await lines[Symbol.asyncIterator]().next()
|
|
116
|
+
return first.done === true ? undefined : first.value
|
|
117
|
+
} finally {
|
|
118
|
+
lines.close()
|
|
119
|
+
if (!process.stdin.isTTY) {
|
|
120
|
+
process.stdout.write('\n')
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** What stops `delete` before any request, if anything. */
|
|
126
|
+
function deleteUsage(command: DeleteCommand): string | undefined {
|
|
127
|
+
if (command.args.operand === undefined) {
|
|
128
|
+
return 'usage: wildshard delete <slug> [--yes] [--server <url>]'
|
|
129
|
+
}
|
|
130
|
+
if (!SLUG.test(command.args.operand)) {
|
|
131
|
+
return `usage: wildshard delete <slug>, and a slug is a lower-case letter, then letters, digits, dots or hyphens, not ${command.args.operand}`
|
|
132
|
+
}
|
|
133
|
+
return command.server === ''
|
|
134
|
+
? 'usage: wildshard delete <slug> --server <url> (or set WILDSHARD_API_URL)'
|
|
135
|
+
: undefined
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The key to send, or why there is none (never the key itself). */
|
|
139
|
+
async function deleteKey(
|
|
140
|
+
command: DeleteCommand,
|
|
141
|
+
): Promise<Readonly<{ key: string }> | string> {
|
|
142
|
+
const usage = deleteUsage(command)
|
|
143
|
+
if (usage !== undefined) {
|
|
144
|
+
return usage
|
|
145
|
+
}
|
|
146
|
+
const key = await apiKeyOf(command.fromEnv)
|
|
147
|
+
if (key instanceof Error) {
|
|
148
|
+
return key.message
|
|
149
|
+
}
|
|
150
|
+
if (key === undefined) {
|
|
151
|
+
return 'delete needs an account key: run wildshard account <email>, or set WILDSHARD_API_KEY'
|
|
152
|
+
}
|
|
153
|
+
return keyTransport(command.server) ?? { key }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The delete itself: 0 once deleted, 1 when not confirmed, 3 refused. */
|
|
157
|
+
async function deleteWith(
|
|
158
|
+
command: DeleteCommand,
|
|
159
|
+
apiKey: string,
|
|
160
|
+
slug: string,
|
|
161
|
+
): Promise<number> {
|
|
162
|
+
try {
|
|
163
|
+
const kept = await deleteShard({
|
|
164
|
+
server: command.server,
|
|
165
|
+
apiKey,
|
|
166
|
+
slug,
|
|
167
|
+
yes: command.args.yes,
|
|
168
|
+
ask: typedLine,
|
|
169
|
+
report: reportLine,
|
|
170
|
+
})
|
|
171
|
+
if (kept === undefined) {
|
|
172
|
+
return EXIT_OK
|
|
173
|
+
}
|
|
174
|
+
refuse('delete', '', kept)
|
|
175
|
+
return EXIT_USAGE
|
|
176
|
+
} catch (error: unknown) {
|
|
177
|
+
refuse('delete', '', messageOf(error))
|
|
178
|
+
return EXIT_FAILED
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** `wildshard delete <slug>`: start, the summary, the typed slug, finalize. */
|
|
183
|
+
async function runDelete(command: DeleteCommand): Promise<number> {
|
|
184
|
+
const apiKey = await deleteKey(command)
|
|
185
|
+
const slug = command.args.operand
|
|
186
|
+
if (typeof apiKey === 'string' || slug === undefined) {
|
|
187
|
+
refuse('delete', '', typeof apiKey === 'string' ? apiKey : '')
|
|
188
|
+
return EXIT_USAGE
|
|
189
|
+
}
|
|
190
|
+
return await deleteWith(command, apiKey.key, slug)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { apiKeyOf, runAccount, runDelete, runWhoami, uploadKeyRefusal }
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { link, mkdir, open, readFile, rename, rm } from 'node:fs/promises'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
// The account key (meta SHARD-DELETE DEL6, J309, J310): `wildshard account`
|
|
6
|
+
// stores the `wsk_` key api-server answers once, and upload sends it as
|
|
7
|
+
// `Authorization: Bearer` on the ticket and the commit. WILDSHARD_API_KEY
|
|
8
|
+
// wins over the file, so CI can pass a secret. The key is never printed
|
|
9
|
+
// whole: whoami shows its first characters only, and a malformed key is
|
|
10
|
+
// refused without echoing it.
|
|
11
|
+
|
|
12
|
+
/** Where `wildshard account` keeps the key, under the user's home. */
|
|
13
|
+
const KEY_PATH = ['.config', 'wildshard', 'sharddev-key'] as const
|
|
14
|
+
|
|
15
|
+
const FILE_MODE = 0o600
|
|
16
|
+
const FOLDER_MODE = 0o700
|
|
17
|
+
const FIRST = 0
|
|
18
|
+
const SHOWN = 8
|
|
19
|
+
const HALF = 2
|
|
20
|
+
const KEY_SHAPE = /^wsk_[\w-]+$/u
|
|
21
|
+
const LOOPBACK: ReadonlySet<string> = new Set([
|
|
22
|
+
'localhost',
|
|
23
|
+
'127.0.0.1',
|
|
24
|
+
'[::1]',
|
|
25
|
+
])
|
|
26
|
+
|
|
27
|
+
/** The key and where it came from. */
|
|
28
|
+
interface ApiKey {
|
|
29
|
+
readonly key: string
|
|
30
|
+
/** `WILDSHARD_API_KEY`, or the key file's path. */
|
|
31
|
+
readonly source: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A key file being written: the key lands in `draft`, then at `file`. */
|
|
35
|
+
interface KeyDraft {
|
|
36
|
+
/** Keep the key: write it, then move it to the key file. */
|
|
37
|
+
readonly keep: (key: string) => Promise<void>
|
|
38
|
+
/** Nothing to keep: remove the draft. */
|
|
39
|
+
readonly drop: () => Promise<void>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function keyFile(home: string = homedir()): string {
|
|
43
|
+
return path.join(home, ...KEY_PATH)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function missing(error: unknown): boolean {
|
|
47
|
+
return error instanceof Error && 'code' in error && error.code === 'ENOENT'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The key file's text, trimmed, or undefined with no file. */
|
|
51
|
+
async function readKeyFile(file: string): Promise<string | undefined> {
|
|
52
|
+
try {
|
|
53
|
+
const text = await readFile(file, 'utf8')
|
|
54
|
+
const key = text.trim()
|
|
55
|
+
return key === '' ? undefined : key
|
|
56
|
+
} catch (error: unknown) {
|
|
57
|
+
if (missing(error)) {
|
|
58
|
+
return undefined
|
|
59
|
+
}
|
|
60
|
+
throw error
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The key, refused (never echoed) unless it is shaped like a `wsk_` key. */
|
|
65
|
+
function shaped(found: ApiKey): ApiKey {
|
|
66
|
+
if (!KEY_SHAPE.test(found.key)) {
|
|
67
|
+
throw new Error(`the account key in ${found.source} is not a wsk_ key`)
|
|
68
|
+
}
|
|
69
|
+
return found
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** WILDSHARD_API_KEY when set, else the key file, else undefined. */
|
|
73
|
+
async function readApiKey(
|
|
74
|
+
fromEnv: string | undefined,
|
|
75
|
+
file: string = keyFile(),
|
|
76
|
+
): Promise<ApiKey | undefined> {
|
|
77
|
+
if (fromEnv !== undefined && fromEnv.trim() !== '') {
|
|
78
|
+
return shaped({ key: fromEnv.trim(), source: 'WILDSHARD_API_KEY' })
|
|
79
|
+
}
|
|
80
|
+
const key = await readKeyFile(file)
|
|
81
|
+
return key === undefined ? undefined : shaped({ key, source: file })
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Whether a key file is there already (an empty one counts). */
|
|
85
|
+
async function keyFileExists(file: string): Promise<boolean> {
|
|
86
|
+
try {
|
|
87
|
+
await readFile(file)
|
|
88
|
+
return true
|
|
89
|
+
} catch (error: unknown) {
|
|
90
|
+
if (missing(error)) {
|
|
91
|
+
return false
|
|
92
|
+
}
|
|
93
|
+
throw error
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Open a mode-600 draft beside the key file before the account is made, so
|
|
99
|
+
* a folder that can't be written refuses before the API shows the key.
|
|
100
|
+
* Keeping links the draft to the key file (refusing one that appeared
|
|
101
|
+
* meanwhile) or, with `force`, renames over it; if that fails the key stays
|
|
102
|
+
* in the draft, whose path the error names.
|
|
103
|
+
*/
|
|
104
|
+
async function draftKeyFile(file: string, force: boolean): Promise<KeyDraft> {
|
|
105
|
+
await mkdir(path.dirname(file), { recursive: true, mode: FOLDER_MODE })
|
|
106
|
+
const draft = `${file}.${String(process.pid)}.new`
|
|
107
|
+
const handle = await open(draft, 'wx', FILE_MODE)
|
|
108
|
+
const drop = async (): Promise<void> => {
|
|
109
|
+
await handle.close()
|
|
110
|
+
await rm(draft, { force: true })
|
|
111
|
+
}
|
|
112
|
+
const keep = async (key: string): Promise<void> => {
|
|
113
|
+
await handle.writeFile(`${key}\n`)
|
|
114
|
+
await handle.close()
|
|
115
|
+
try {
|
|
116
|
+
await (force ? rename(draft, file) : link(draft, file))
|
|
117
|
+
} catch (error: unknown) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
`the key is saved in ${draft}, not ${file}: ${String(error)}`,
|
|
120
|
+
{ cause: error },
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
await rm(draft, { force: true })
|
|
124
|
+
}
|
|
125
|
+
return { keep, drop }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The key's first characters and an ellipsis: enough to tell keys apart. */
|
|
129
|
+
function maskKey(key: string): string {
|
|
130
|
+
return `${key.slice(FIRST, Math.min(SHOWN, Math.floor(key.length / HALF)))}…`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** What is wrong with sending a key to `server`: only https, or loopback. */
|
|
134
|
+
function keyTransport(server: string): string | undefined {
|
|
135
|
+
const url = URL.parse(server)
|
|
136
|
+
const safe =
|
|
137
|
+
url !== null &&
|
|
138
|
+
(url.protocol === 'https:' ||
|
|
139
|
+
(url.protocol === 'http:' && LOOPBACK.has(url.hostname)))
|
|
140
|
+
return safe
|
|
141
|
+
? undefined
|
|
142
|
+
: `the account key goes only to an https server (or localhost), not ${server}`
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
type ApiKey,
|
|
147
|
+
type KeyDraft,
|
|
148
|
+
draftKeyFile,
|
|
149
|
+
keyFile,
|
|
150
|
+
keyFileExists,
|
|
151
|
+
keyTransport,
|
|
152
|
+
maskKey,
|
|
153
|
+
readApiKey,
|
|
154
|
+
}
|
package/src/cli/args.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util'
|
|
2
|
+
|
|
3
|
+
// The sharddev CLI's arguments. `--version` prints sharddev's version,
|
|
4
|
+
// except after the `upload` command, where it is the shard version
|
|
5
|
+
// (API-CLOUDFLARE AC16). `--channel` is the upload's channel (J301).
|
|
6
|
+
|
|
7
|
+
interface CliArgs {
|
|
8
|
+
readonly command: string | undefined
|
|
9
|
+
readonly channel: string | undefined
|
|
10
|
+
readonly commit: string | undefined
|
|
11
|
+
readonly shardVersion: string | undefined
|
|
12
|
+
readonly operand: string | undefined
|
|
13
|
+
/** The second operand: `build <folder> [file]`'s shard file (SA3). */
|
|
14
|
+
readonly target: string | undefined
|
|
15
|
+
readonly help: boolean
|
|
16
|
+
/** `account`: replace a key file that is there already. */
|
|
17
|
+
readonly force: boolean
|
|
18
|
+
readonly level: string | undefined
|
|
19
|
+
/** `upload --no-place` (SA32): take no grid cell. */
|
|
20
|
+
readonly noPlace: boolean
|
|
21
|
+
readonly out: string | undefined
|
|
22
|
+
readonly port: string | undefined
|
|
23
|
+
readonly server: string | undefined
|
|
24
|
+
readonly version: boolean
|
|
25
|
+
/** `delete`: skip the typed slug, for scripts (meta SHARD-DELETE DEL10). */
|
|
26
|
+
readonly yes: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const FIRST = 0
|
|
30
|
+
|
|
31
|
+
const OPTIONS = {
|
|
32
|
+
channel: { type: 'string' },
|
|
33
|
+
commit: { type: 'string' },
|
|
34
|
+
force: { type: 'boolean', default: false },
|
|
35
|
+
help: { type: 'boolean', default: false },
|
|
36
|
+
level: { type: 'string' },
|
|
37
|
+
'no-place': { type: 'boolean', default: false },
|
|
38
|
+
out: { type: 'string' },
|
|
39
|
+
port: { type: 'string' },
|
|
40
|
+
server: { type: 'string' },
|
|
41
|
+
yes: { type: 'boolean', default: false },
|
|
42
|
+
} as const
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether `--version` is the shard version (API-CLOUDFLARE AC16): only
|
|
46
|
+
* after an `upload` command. Before any command it prints sharddev's.
|
|
47
|
+
*/
|
|
48
|
+
function shardVersionFlag(argv: readonly string[]): boolean {
|
|
49
|
+
const { tokens } = parseArgs({
|
|
50
|
+
args: [...argv],
|
|
51
|
+
allowPositionals: true,
|
|
52
|
+
strict: false,
|
|
53
|
+
tokens: true,
|
|
54
|
+
options: { ...OPTIONS, version: { type: 'boolean' } },
|
|
55
|
+
})
|
|
56
|
+
const command = tokens.find(
|
|
57
|
+
(token: Readonly<{ kind: string }>): boolean => token.kind === 'positional',
|
|
58
|
+
)
|
|
59
|
+
return (
|
|
60
|
+
command?.kind === 'positional' &&
|
|
61
|
+
command.value === 'upload' &&
|
|
62
|
+
!argv.slice(FIRST, command.index).includes('--version')
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function parseCliArgs(argv: readonly string[]): CliArgs {
|
|
67
|
+
const upload = shardVersionFlag(argv)
|
|
68
|
+
const { values, positionals } = parseArgs({
|
|
69
|
+
args: [...argv],
|
|
70
|
+
allowPositionals: true,
|
|
71
|
+
options: {
|
|
72
|
+
...OPTIONS,
|
|
73
|
+
version: upload ? { type: 'string' } : { type: 'boolean' },
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
const [command, operand, target] = positionals
|
|
77
|
+
const { version } = values
|
|
78
|
+
return {
|
|
79
|
+
command,
|
|
80
|
+
operand,
|
|
81
|
+
target,
|
|
82
|
+
channel: values.channel,
|
|
83
|
+
commit: values.commit,
|
|
84
|
+
shardVersion: typeof version === 'string' ? version : undefined,
|
|
85
|
+
help: values.help,
|
|
86
|
+
force: values.force,
|
|
87
|
+
level: values.level,
|
|
88
|
+
noPlace: values['no-place'],
|
|
89
|
+
out: values.out,
|
|
90
|
+
port: values.port,
|
|
91
|
+
server: values.server,
|
|
92
|
+
version: version === true,
|
|
93
|
+
yes: values.yes,
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { type CliArgs, parseCliArgs }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { installFormatHook } from '@wildshard/format/formatHook'
|
|
2
|
+
|
|
3
|
+
import type { AudioReport } from '@wildshard/format/audioRules'
|
|
4
|
+
|
|
5
|
+
// AUDIO AU5 (meta docs/plans/AUDIO-PLAN.md, J299): format owns the audio
|
|
6
|
+
// rules. `pack` prints every finding as AMBER and still packs; `upload`
|
|
7
|
+
// refuses a red before it spends the upload, as api-server's admission
|
|
8
|
+
// will. A waiver lives in the shard source (`audio-waiver.json`).
|
|
9
|
+
|
|
10
|
+
/** The report as pack prints it: totals, then one AMBER line per finding. */
|
|
11
|
+
async function audioLines(report: Readonly<AudioReport>): Promise<string[]> {
|
|
12
|
+
installFormatHook()
|
|
13
|
+
const { audioReportLines } = await import('@wildshard/format/audioRules')
|
|
14
|
+
return audioReportLines(report)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Refuse a red report, with format's reason. */
|
|
18
|
+
async function assertAudio(report: Readonly<AudioReport>): Promise<void> {
|
|
19
|
+
installFormatHook()
|
|
20
|
+
const { assertAudioAdmission } = await import('@wildshard/format/audioRules')
|
|
21
|
+
assertAudioAdmission(report)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { assertAudio, audioLines }
|
package/src/cli/bin.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { installFormatHook } from '@wildshard/format/formatHook'
|
|
3
|
+
|
|
4
|
+
// The `wildshard` bin. Node will not strip types under node_modules (J53), so
|
|
5
|
+
// an installed CLI needs format's hook before its first .ts. The hook covers
|
|
6
|
+
// everything under node_modules/@wildshard/, this package too.
|
|
7
|
+
installFormatHook()
|
|
8
|
+
await import('./main.ts')
|