@wildshard/sdk 0.0.1 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GUIDE.md +895 -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 +47 -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 +39 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/delete/delete.ts +258 -0
- package/src/cli/help.ts +204 -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 +291 -0
- package/src/cli/report.ts +20 -0
- package/src/cli/shardfile/command.ts +49 -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/agentFiles.ts +127 -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 +118 -0
- package/src/sharddev/checkProject.ts +127 -0
- package/src/sharddev/cli.ts +200 -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 +226 -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 +29 -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 +304 -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,518 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Agent tooling from one source: write what Claude Code and Codex CLI
|
|
3
|
+
// each load from the repo's single spec (meta
|
|
4
|
+
// docs/plans/MULTI-AGENT-TOOLING-PLAN.md, MA2 and MA3).
|
|
5
|
+
//
|
|
6
|
+
// node scripts/agent-sync.mjs [--root <dir>] write it
|
|
7
|
+
// node scripts/agent-sync.mjs --check [--root <dir>] exit 1 if stale or invalid
|
|
8
|
+
// node scripts/agent-sync.mjs --from <repo-kit> [--root <dir>]
|
|
9
|
+
// stamp the kit's agent layout, then write
|
|
10
|
+
//
|
|
11
|
+
// The source, edited by hand:
|
|
12
|
+
// .agents/hooks.json kit-owned hook spec: [{ event, tools?, script,
|
|
13
|
+
// args?, status?, timeout? }]; tools is "shell"
|
|
14
|
+
// (Claude and Codex Bash) or "edit" (Claude
|
|
15
|
+
// Edit|Write|MultiEdit, Codex apply_patch)
|
|
16
|
+
// .agents/hooks.local.json optional, the repo's own hooks, same shape
|
|
17
|
+
// .agents/hooks/ the scripts both tools run (lib/payload.mjs
|
|
18
|
+
// reads either tool's stdin)
|
|
19
|
+
// .agents/skills/<name>/ one directory per skill (Codex reads here)
|
|
20
|
+
// What this writes, never edited by hand:
|
|
21
|
+
// .claude/settings.json its "hooks" key; other keys are kept
|
|
22
|
+
// .codex/hooks.json all of it
|
|
23
|
+
// .claude/skills/<name> a relative symlink to ../../.agents/skills/<name>
|
|
24
|
+
//
|
|
25
|
+
// Claude's command spells the root $CLAUDE_PROJECT_DIR, which stays put
|
|
26
|
+
// when an agent cd's elsewhere; Codex sets no such variable, so its
|
|
27
|
+
// command asks git. The scripts themselves find the root with git.
|
|
28
|
+
//
|
|
29
|
+
// --from stamps a repo from the kit (MA3): it copies the kit-owned files
|
|
30
|
+
// (kitFiles below), removes the old .claude/hooks copies and the old
|
|
31
|
+
// .claude/skills directories of kit skills, moves the repo's own
|
|
32
|
+
// .claude/skills directories into .agents/skills, then writes. It
|
|
33
|
+
// refuses a repo with uncommitted changes in those paths, or whose
|
|
34
|
+
// .claude/settings.json runs hooks the spec doesn't name: git keeps
|
|
35
|
+
// every replaced byte, and nothing outside these paths is touched.
|
|
36
|
+
// Exit 0 ok, 1 stale, invalid or refused, 2 usage.
|
|
37
|
+
import { spawnSync } from 'node:child_process';
|
|
38
|
+
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
39
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
40
|
+
import { pathToFileURL } from 'node:url';
|
|
41
|
+
import { EVENTS, KIT_SCRIPTS, invocation, normalizeMatcher } from './agent-parity.mjs';
|
|
42
|
+
|
|
43
|
+
export const SPEC = '.agents/hooks.json';
|
|
44
|
+
export const LOCAL_SPEC = '.agents/hooks.local.json';
|
|
45
|
+
export const CLAUDE_SETTINGS = '.claude/settings.json';
|
|
46
|
+
export const CODEX_HOOKS = '.codex/hooks.json';
|
|
47
|
+
export const SKILLS = '.agents/skills';
|
|
48
|
+
export const CLAUDE_SKILLS = '.claude/skills';
|
|
49
|
+
/** What a spec's `tools` becomes in each tool's matcher (recorded payloads: .agents/hooks/test/fixtures/). */
|
|
50
|
+
export const MATCHERS = {
|
|
51
|
+
shell: { claude: 'Bash', codex: 'Bash' },
|
|
52
|
+
edit: { claude: 'Edit|Write|MultiEdit', codex: 'apply_patch' },
|
|
53
|
+
};
|
|
54
|
+
const TOOL_EVENTS = new Set(['PreToolUse', 'PostToolUse']);
|
|
55
|
+
const RUNNERS = { '.sh': 'bash', '.mjs': 'node', '.js': 'node', '.py': 'python3' };
|
|
56
|
+
const ROOTS = { claude: '"$CLAUDE_PROJECT_DIR/', codex: '"$(git rev-parse --show-toplevel)/' };
|
|
57
|
+
const SPEC_KEYS = new Set(['event', 'tools', 'script', 'args', 'status', 'timeout']);
|
|
58
|
+
/** The command-handler fields each tool accepts, with their types (Claude Code's settings docs; Codex 0.167.1's HookHandlerConfig::Command). */
|
|
59
|
+
const positiveInt = (value) => Number.isInteger(value) && value > 0;
|
|
60
|
+
const nonEmptyString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
61
|
+
const HANDLER_FIELDS = {
|
|
62
|
+
claude: { type: (value) => value === 'command', command: nonEmptyString, timeout: positiveInt, statusMessage: nonEmptyString },
|
|
63
|
+
codex: { type: (value) => value === 'command', command: nonEmptyString, commandWindows: nonEmptyString, timeout: positiveInt, async: (value) => typeof value === 'boolean', statusMessage: nonEmptyString, additionalContextLimit: positiveInt },
|
|
64
|
+
};
|
|
65
|
+
/** The kit's own hook scripts before MA2, removed by --from. */
|
|
66
|
+
const LEGACY_HOOKS = ['session-brief.sh', 'guard-git-add.sh', 'md-prose-width.sh', 'herdr-peers.sh', 'guard-herdr-prompt.sh'];
|
|
67
|
+
|
|
68
|
+
const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
69
|
+
const lexists = (path) => {
|
|
70
|
+
try {
|
|
71
|
+
lstatSync(path);
|
|
72
|
+
return true;
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const isLink = (path) => lexists(path) && lstatSync(path).isSymbolicLink();
|
|
78
|
+
const isRealDir = (path) => lexists(path) && lstatSync(path).isDirectory();
|
|
79
|
+
const isFile = (path) => lexists(path) && lstatSync(path).isFile();
|
|
80
|
+
const readMaybe = (path) => (existsSync(path) ? readFileSync(path, 'utf8') : null);
|
|
81
|
+
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
82
|
+
|
|
83
|
+
// ---------------------------------------------------------------- the spec
|
|
84
|
+
|
|
85
|
+
/** Read one spec file: its entries and every problem, never a throw. */
|
|
86
|
+
function readSpec(root, path, required) {
|
|
87
|
+
const text = readMaybe(join(root, path));
|
|
88
|
+
if (text === null) return { entries: [], problems: required ? [`${path} is missing`] : [] };
|
|
89
|
+
let value;
|
|
90
|
+
try {
|
|
91
|
+
value = JSON.parse(text);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
return { entries: [], problems: [`${path} does not parse: ${error.message}`] };
|
|
94
|
+
}
|
|
95
|
+
if (!isObject(value) || !Array.isArray(value.hooks) || Object.keys(value).some((key) => key !== 'hooks')) {
|
|
96
|
+
return { entries: [], problems: [`${path} must be { "hooks": [ ... ] }`] };
|
|
97
|
+
}
|
|
98
|
+
const problems = [];
|
|
99
|
+
value.hooks.forEach((entry, index) => {
|
|
100
|
+
const at = `${path} hooks[${index}]`;
|
|
101
|
+
if (!isObject(entry)) {
|
|
102
|
+
problems.push(`${at} is not an object`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
for (const key of Object.keys(entry)) if (!SPEC_KEYS.has(key)) problems.push(`${at} has an unknown key "${key}"`);
|
|
106
|
+
const { event, tools, script, args = [], status, timeout } = entry;
|
|
107
|
+
if (!EVENTS.claude.has(event) || !EVENTS.codex.has(event)) problems.push(`${at} event ${JSON.stringify(event)} is not one both tools fire`);
|
|
108
|
+
if (TOOL_EVENTS.has(event) && !Object.hasOwn(MATCHERS, tools)) problems.push(`${at} needs "tools": "shell" or "edit"`);
|
|
109
|
+
if (!TOOL_EVENTS.has(event) && tools !== undefined) problems.push(`${at} ${event} takes no "tools"`);
|
|
110
|
+
if (typeof script !== 'string' || isAbsolute(script) || script.split('/').includes('..') || !/^(?:\.agents\/hooks|scripts)\/[\w./-]+$/.test(script)) {
|
|
111
|
+
problems.push(`${at} script must be a path under .agents/hooks/ or scripts/`);
|
|
112
|
+
} else if (!RUNNERS[script.slice(script.lastIndexOf('.'))]) {
|
|
113
|
+
problems.push(`${at} script must end in ${Object.keys(RUNNERS).join(', ')}`);
|
|
114
|
+
} else if (!existsSync(join(root, script)) || !statSync(join(root, script)).isFile()) {
|
|
115
|
+
problems.push(`${at} script not found: ${script}`);
|
|
116
|
+
}
|
|
117
|
+
if (!Array.isArray(args) || args.some((arg) => typeof arg !== 'string' || !/^[\w.,=:@%+/-]+$/.test(arg))) problems.push(`${at} args must be plain words (no shell syntax)`);
|
|
118
|
+
if (status !== undefined && (typeof status !== 'string' || status.length > 80 || status.trim() === '')) problems.push(`${at} status must be a short string`);
|
|
119
|
+
if (timeout !== undefined && (!Number.isInteger(timeout) || timeout < 1 || timeout > 600)) problems.push(`${at} timeout must be 1 to 600 seconds`);
|
|
120
|
+
});
|
|
121
|
+
return { entries: problems.length ? [] : value.hooks, problems };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The kit spec and the repo's own, as one list. */
|
|
125
|
+
export function loadSpec(root) {
|
|
126
|
+
const kit = readSpec(root, SPEC, true);
|
|
127
|
+
const local = readSpec(root, LOCAL_SPEC, false);
|
|
128
|
+
return { entries: [...kit.entries, ...local.entries], problems: [...kit.problems, ...local.problems] };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** One tool's "hooks" object from spec entries. */
|
|
132
|
+
export function renderHooks(entries, tool) {
|
|
133
|
+
const hooks = {};
|
|
134
|
+
for (const { event, tools, script, args = [], status, timeout } of entries) {
|
|
135
|
+
const runner = RUNNERS[script.slice(script.lastIndexOf('.'))];
|
|
136
|
+
const handler = { type: 'command', command: [runner, `${ROOTS[tool]}${script}"`, ...args].join(' ') };
|
|
137
|
+
if (timeout !== undefined) handler.timeout = timeout;
|
|
138
|
+
if (tool === 'codex' && status !== undefined) handler.statusMessage = status;
|
|
139
|
+
const matcher = tools === undefined ? undefined : MATCHERS[tools][tool];
|
|
140
|
+
hooks[event] ??= [];
|
|
141
|
+
let group = hooks[event].find((candidate) => candidate.matcher === matcher);
|
|
142
|
+
if (!group) {
|
|
143
|
+
group = matcher === undefined ? { hooks: [] } : { matcher, hooks: [] };
|
|
144
|
+
hooks[event].push(group);
|
|
145
|
+
}
|
|
146
|
+
group.hooks.push(handler);
|
|
147
|
+
}
|
|
148
|
+
return hooks;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Problems with a hooks object as either tool would load it: event names, group and handler keys. */
|
|
152
|
+
export function hookShapeProblems(hooks, tool, path) {
|
|
153
|
+
if (hooks === undefined) return [];
|
|
154
|
+
if (!isObject(hooks)) return [`${path}: "hooks" is not an object`];
|
|
155
|
+
const problems = [];
|
|
156
|
+
for (const [event, groups] of Object.entries(hooks)) {
|
|
157
|
+
if (!EVENTS[tool].has(event)) problems.push(`${path}: ${event} is not a ${tool === 'claude' ? 'Claude Code' : 'Codex'} hook event`);
|
|
158
|
+
if (!Array.isArray(groups)) {
|
|
159
|
+
problems.push(`${path}: ${event} is not a list`);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
for (const group of groups) {
|
|
163
|
+
if (!isObject(group) || !Array.isArray(group.hooks) || Object.keys(group).some((key) => key !== 'matcher' && key !== 'hooks') || (group.matcher !== undefined && typeof group.matcher !== 'string')) {
|
|
164
|
+
problems.push(`${path}: ${event} has a group that is not { matcher?, hooks: [...] }`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
for (const handler of group.hooks) {
|
|
168
|
+
const fields = HANDLER_FIELDS[tool];
|
|
169
|
+
if (!isObject(handler) || handler.type !== 'command' || !nonEmptyString(handler.command)) {
|
|
170
|
+
problems.push(`${path}: ${event} has a handler that is not { type: "command", command: "<text>" }`);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
for (const [key, value] of Object.entries(handler)) {
|
|
174
|
+
if (!Object.hasOwn(fields, key)) problems.push(`${path}: ${event} handler has a key ${tool === 'claude' ? 'Claude Code' : 'Codex'} doesn't take: "${key}"`);
|
|
175
|
+
else if (!fields[key](value)) problems.push(`${path}: ${event} handler "${key}" has the wrong type`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return problems;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ---------------------------------------------------------------- the plan
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Every file and link the spec implies, against what is on disk.
|
|
187
|
+
* @returns {{ actions: { path: string, kind: 'write'|'link'|'unlink', want?: string }[], problems: string[] }}
|
|
188
|
+
*/
|
|
189
|
+
export function plan(root) {
|
|
190
|
+
const { entries, problems } = loadSpec(root);
|
|
191
|
+
const actions = [];
|
|
192
|
+
// Hooks: nothing is written from an invalid spec.
|
|
193
|
+
if (!problems.length) {
|
|
194
|
+
const settingsText = readMaybe(join(root, CLAUDE_SETTINGS));
|
|
195
|
+
let settings = {};
|
|
196
|
+
if (settingsText !== null) {
|
|
197
|
+
try {
|
|
198
|
+
settings = JSON.parse(settingsText);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
problems.push(`${CLAUDE_SETTINGS} does not parse: ${error.message}`);
|
|
201
|
+
}
|
|
202
|
+
if (!isObject(settings)) problems.push(`${CLAUDE_SETTINGS} is not a JSON object`);
|
|
203
|
+
}
|
|
204
|
+
if (!problems.length) {
|
|
205
|
+
const claude = renderHooks(entries, 'claude');
|
|
206
|
+
const codex = renderHooks(entries, 'codex');
|
|
207
|
+
problems.push(...hookShapeProblems(claude, 'claude', CLAUDE_SETTINGS), ...hookShapeProblems(codex, 'codex', CODEX_HOOKS));
|
|
208
|
+
const next = { ...settings, hooks: claude };
|
|
209
|
+
if (!Object.keys(claude).length) delete next.hooks;
|
|
210
|
+
const wantSettings = json(next);
|
|
211
|
+
if (settingsText !== wantSettings) actions.push({ path: CLAUDE_SETTINGS, kind: 'write', want: wantSettings });
|
|
212
|
+
const wantCodex = json({ hooks: codex });
|
|
213
|
+
if (readMaybe(join(root, CODEX_HOOKS)) !== wantCodex) actions.push({ path: CODEX_HOOKS, kind: 'write', want: wantCodex });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Skills: each .agents/skills/<name> gets a .claude/skills/<name> link.
|
|
217
|
+
const skillsDir = join(root, SKILLS);
|
|
218
|
+
const names = existsSync(skillsDir) ? readdirSync(skillsDir).filter((name) => existsSync(join(skillsDir, name, 'SKILL.md'))).sort() : [];
|
|
219
|
+
for (const name of names) {
|
|
220
|
+
const path = `${CLAUDE_SKILLS}/${name}`;
|
|
221
|
+
const want = `../../${SKILLS}/${name}`;
|
|
222
|
+
if (isLink(join(root, path))) {
|
|
223
|
+
if (readlinkSync(join(root, path)) !== want) actions.push({ path, kind: 'link', want });
|
|
224
|
+
} else if (lexists(join(root, path))) {
|
|
225
|
+
problems.push(`${path} is a real directory beside ${SKILLS}/${name}: keep one (agent-sync --from moves it)`);
|
|
226
|
+
} else actions.push({ path, kind: 'link', want });
|
|
227
|
+
}
|
|
228
|
+
// A link into .agents/skills whose skill is gone.
|
|
229
|
+
const claudeSkills = join(root, CLAUDE_SKILLS);
|
|
230
|
+
for (const name of existsSync(claudeSkills) || isLink(claudeSkills) ? readdirSync(claudeSkills).sort() : []) {
|
|
231
|
+
const full = join(claudeSkills, name);
|
|
232
|
+
if (isLink(full) && readlinkSync(full).startsWith(`../../${SKILLS}/`) && !names.includes(name)) actions.push({ path: `${CLAUDE_SKILLS}/${name}`, kind: 'unlink' });
|
|
233
|
+
}
|
|
234
|
+
return { actions, problems };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Carry out a plan's actions. */
|
|
238
|
+
export function apply(root, actions) {
|
|
239
|
+
for (const action of actions) {
|
|
240
|
+
const full = join(root, action.path);
|
|
241
|
+
mkdirSync(dirname(full), { recursive: true });
|
|
242
|
+
if (action.kind === 'write') writeFileSync(full, action.want);
|
|
243
|
+
else {
|
|
244
|
+
if (isLink(full)) unlinkSync(full);
|
|
245
|
+
if (action.kind === 'link') symlinkSync(action.want, full);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// ---------------------------------------------------------------- the stamp
|
|
251
|
+
|
|
252
|
+
/** Every file under a directory, repo-relative, sorted. */
|
|
253
|
+
function walk(root, dir) {
|
|
254
|
+
const out = [];
|
|
255
|
+
const full = join(root, dir);
|
|
256
|
+
if (!isRealDir(full)) return out;
|
|
257
|
+
for (const name of readdirSync(full).sort()) {
|
|
258
|
+
const path = `${dir}/${name}`;
|
|
259
|
+
if (isRealDir(join(root, path))) out.push(...walk(root, path));
|
|
260
|
+
else if (lstatSync(join(root, path)).isFile()) out.push(path);
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Every non-directory entry under a directory, files and links alike (links never followed), repo-relative, sorted. */
|
|
266
|
+
function entriesUnder(root, dir) {
|
|
267
|
+
const out = [];
|
|
268
|
+
if (!isRealDir(join(root, dir))) return out;
|
|
269
|
+
for (const name of readdirSync(join(root, dir)).sort()) {
|
|
270
|
+
const path = `${dir}/${name}`;
|
|
271
|
+
if (isRealDir(join(root, path))) out.push(...entriesUnder(root, path));
|
|
272
|
+
else out.push(path);
|
|
273
|
+
}
|
|
274
|
+
return out;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** The kit-owned files a stamp copies: the hook scripts, the kit spec, the kit's skills and the two scripts. */
|
|
278
|
+
export function kitFiles(kit) {
|
|
279
|
+
return [...walk(kit, '.agents/hooks'), ...walk(kit, SKILLS), ...KIT_SCRIPTS].filter((path) => existsSync(join(kit, path))).sort();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** The kit's skill names. */
|
|
283
|
+
export const kitSkills = (kit) => (isRealDir(join(kit, SKILLS)) ? readdirSync(join(kit, SKILLS)).filter((name) => isRealDir(join(kit, SKILLS, name))).sort() : []);
|
|
284
|
+
|
|
285
|
+
const gitOut = (root, args) => spawnSync('git', ['-C', root, ...args], { encoding: 'utf8' });
|
|
286
|
+
|
|
287
|
+
/** The first symlink at or above `rel` inside root, component by component, or null. */
|
|
288
|
+
function linkOnPath(root, rel) {
|
|
289
|
+
const parts = rel.split('/');
|
|
290
|
+
for (let k = 1; k <= parts.length; k++) {
|
|
291
|
+
const sub = parts.slice(0, k).join('/');
|
|
292
|
+
if (isLink(join(root, sub))) return sub;
|
|
293
|
+
if (!lexists(join(root, sub))) return null;
|
|
294
|
+
}
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Handler fields that change what a hook does (statusMessage is display only). */
|
|
299
|
+
const BEHAVIOUR = ['timeout', 'async', 'commandWindows', 'additionalContextLimit'];
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Each registration a hooks object makes, comparably: event, matcher (one vocabulary for both tools),
|
|
303
|
+
* runner, script (an old .claude/hooks/<name> reads as .agents/hooks/<name>), arguments and every
|
|
304
|
+
* behaviour field. Unreadable groups count as registrations, so they are never silently dropped.
|
|
305
|
+
*/
|
|
306
|
+
function registrations(hooks, tool) {
|
|
307
|
+
const out = [];
|
|
308
|
+
if (!isObject(hooks)) return out;
|
|
309
|
+
for (const [event, groups] of Object.entries(hooks)) {
|
|
310
|
+
for (const group of Array.isArray(groups) ? groups : [null]) {
|
|
311
|
+
for (const handler of isObject(group) && Array.isArray(group.hooks) ? group.hooks : [null]) {
|
|
312
|
+
const matcher = normalizeMatcher(isObject(group) ? group.matcher : undefined, tool, event);
|
|
313
|
+
const command = isObject(handler) && typeof handler.command === 'string' ? handler.command : null;
|
|
314
|
+
const run = command === null ? null : invocation(command);
|
|
315
|
+
const script = run?.script?.replace(/^\.claude\/hooks\//, '.agents/hooks/') ?? null;
|
|
316
|
+
const type = isObject(handler) ? handler.type ?? 'command' : 'unreadable';
|
|
317
|
+
const fields = BEHAVIOUR.map((key) => (isObject(handler) && handler[key] !== undefined ? [key, handler[key]] : null)).filter(Boolean);
|
|
318
|
+
out.push({
|
|
319
|
+
key: JSON.stringify([event, matcher, type, script, script ? run.runner : command, script ? run.args : [], fields]),
|
|
320
|
+
shown: `${event} ${matcher} ${script ?? (type === 'command' ? 'inline command' : `${type} handler`)}${fields.length ? ` (${fields.map(([key]) => key).join(', ')})` : ''}`,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** Registrations in `old` that `fresh` doesn't make (as multisets: a dropped duplicate counts). */
|
|
329
|
+
function dropped(old, fresh, tool) {
|
|
330
|
+
const left = new Map();
|
|
331
|
+
for (const { key } of registrations(fresh, tool)) left.set(key, (left.get(key) ?? 0) + 1);
|
|
332
|
+
const out = [];
|
|
333
|
+
for (const { key, shown } of registrations(old, tool)) {
|
|
334
|
+
if (left.get(key)) left.set(key, left.get(key) - 1);
|
|
335
|
+
else out.push(shown);
|
|
336
|
+
}
|
|
337
|
+
return out;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function parseManifest(root, path, problems) {
|
|
341
|
+
const text = readMaybe(join(root, path));
|
|
342
|
+
if (text === null) return null;
|
|
343
|
+
try {
|
|
344
|
+
const value = JSON.parse(text);
|
|
345
|
+
if (isObject(value)) return value;
|
|
346
|
+
} catch {
|
|
347
|
+
// reported below
|
|
348
|
+
}
|
|
349
|
+
problems.push(`${path} is not a JSON object; fix it first`);
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const realOr = (path) => {
|
|
354
|
+
try {
|
|
355
|
+
return realpathSync(path);
|
|
356
|
+
} catch {
|
|
357
|
+
return path;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Stamp the kit's agent layout into a repo. Everything is checked before anything is written: the kit,
|
|
363
|
+
* the repo's specs and manifests, every registration the new manifests would drop, symlinks on every
|
|
364
|
+
* path it writes or removes, and uncommitted, untracked or ignored files under those paths.
|
|
365
|
+
* @returns {{ changed: string[], replaced: string[], problems: string[] }}
|
|
366
|
+
*/
|
|
367
|
+
export function stamp(kitDir, rootDir) {
|
|
368
|
+
const kit = resolve(kitDir);
|
|
369
|
+
const root = resolve(rootDir);
|
|
370
|
+
const refuse = (problems) => ({ changed: [], replaced: [], problems });
|
|
371
|
+
if (!isRealDir(kit) || !existsSync(join(kit, SPEC))) return refuse([`${kit} is not a repo-kit checkout (no ${SPEC})`]);
|
|
372
|
+
const top = gitOut(root, ['rev-parse', '--show-toplevel']);
|
|
373
|
+
if (top.status !== 0) return refuse([`${root} is not a git checkout`]);
|
|
374
|
+
if (realOr(top.stdout.trim()) !== realOr(root)) return refuse([`${root} is not the top of its checkout`]);
|
|
375
|
+
if (realOr(kit) === realOr(root)) return refuse(['--from names this repo itself']);
|
|
376
|
+
|
|
377
|
+
const problems = [];
|
|
378
|
+
const kitSpec = readSpec(kit, SPEC, true);
|
|
379
|
+
problems.push(...kitSpec.problems.map((problem) => `the kit's ${problem}`));
|
|
380
|
+
const files = kitFiles(kit);
|
|
381
|
+
if (!files.length) problems.push(`${kit} has no kit files`);
|
|
382
|
+
const localSpec = readSpec(root, LOCAL_SPEC, false);
|
|
383
|
+
problems.push(...localSpec.problems);
|
|
384
|
+
// The manifests after the stamp must keep every registration the repo has today, in both tools.
|
|
385
|
+
const oldClaude = parseManifest(root, CLAUDE_SETTINGS, problems);
|
|
386
|
+
const oldCodex = parseManifest(root, CODEX_HOOKS, problems);
|
|
387
|
+
if (!kitSpec.problems.length && !localSpec.problems.length) {
|
|
388
|
+
const entries = [...kitSpec.entries, ...localSpec.entries];
|
|
389
|
+
for (const [tool, old, path] of [['claude', oldClaude, CLAUDE_SETTINGS], ['codex', oldCodex, CODEX_HOOKS]]) {
|
|
390
|
+
for (const shown of dropped(old?.hooks, renderHooks(entries, tool), tool)) problems.push(`${path} registers ${shown}, which the spec doesn't: move it into ${LOCAL_SPEC} first`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
const skills = kitSkills(kit);
|
|
394
|
+
const claudeSkills = join(root, CLAUDE_SKILLS);
|
|
395
|
+
const own = isRealDir(claudeSkills) ? readdirSync(claudeSkills).filter((name) => isRealDir(join(claudeSkills, name)) && !skills.includes(name)).sort() : [];
|
|
396
|
+
for (const name of own) if (lexists(join(root, SKILLS, name))) problems.push(`${CLAUDE_SKILLS}/${name} and ${SKILLS}/${name} both exist: keep one`);
|
|
397
|
+
const oldKitSkills = skills.filter((name) => isRealDir(join(claudeSkills, name)));
|
|
398
|
+
for (const name of oldKitSkills) {
|
|
399
|
+
const dir = `${CLAUDE_SKILLS}/${name}`;
|
|
400
|
+
// Every entry, links included (never followed): a link or a file the kit's skill lacks is the repo's own.
|
|
401
|
+
const extra = entriesUnder(root, dir).filter((path) => isLink(join(root, path)) || !isFile(join(kit, SKILLS, name, relative(dir, path))));
|
|
402
|
+
if (extra.length) problems.push(`${dir} holds files the kit's ${name} doesn't (${extra.join(', ')}): move them out first`);
|
|
403
|
+
}
|
|
404
|
+
// Each skill link the stamp will write: absent, ours already, or a directory it removes or moves.
|
|
405
|
+
const agentSkills = isRealDir(join(root, SKILLS)) ? readdirSync(join(root, SKILLS)) : [];
|
|
406
|
+
const linked = [...new Set([...skills, ...own, ...agentSkills])].sort();
|
|
407
|
+
for (const name of linked) {
|
|
408
|
+
const path = `${CLAUDE_SKILLS}/${name}`;
|
|
409
|
+
const full = join(root, path);
|
|
410
|
+
if (isLink(full) && readlinkSync(full) !== `../../${SKILLS}/${name}`) problems.push(`${path} is a link to ${readlinkSync(full)}, not ../../${SKILLS}/${name}: move it first`);
|
|
411
|
+
else if (lexists(full) && !isLink(full) && !isRealDir(full)) problems.push(`${path} is a file where the stamp writes a skill link: move it first`);
|
|
412
|
+
}
|
|
413
|
+
const stale = isRealDir(claudeSkills) ? readdirSync(claudeSkills).filter((name) => isLink(join(claudeSkills, name)) && !linked.includes(name)).map((name) => `${CLAUDE_SKILLS}/${name}`) : [];
|
|
414
|
+
const legacy = LEGACY_HOOKS.map((name) => `.claude/hooks/${name}`).filter((path) => lexists(join(root, path)));
|
|
415
|
+
// No write or removal may go through a symlink.
|
|
416
|
+
const writes = [...files, CLAUDE_SETTINGS, CODEX_HOOKS, ...own.map((name) => `${SKILLS}/${name}`)];
|
|
417
|
+
const links = linked.map((name) => `${CLAUDE_SKILLS}/${name}`);
|
|
418
|
+
const removes = [...legacy, ...stale, ...oldKitSkills.map((name) => `${CLAUDE_SKILLS}/${name}`), ...own.map((name) => `${CLAUDE_SKILLS}/${name}`)];
|
|
419
|
+
for (const path of [...new Set([...writes, `${CLAUDE_SKILLS}/x`, ...removes.map((entry) => `${dirname(entry)}/x`)])]) {
|
|
420
|
+
const link = linkOnPath(root, path);
|
|
421
|
+
if (link) problems.push(`${link} is a symlink; refusing to write through it`);
|
|
422
|
+
}
|
|
423
|
+
// Nothing uncommitted, untracked or ignored under a path it writes or removes.
|
|
424
|
+
const affected = [...new Set([...writes, ...links, ...removes])];
|
|
425
|
+
const status = gitOut(root, ['-c', 'status.showUntrackedFiles=all', 'status', '--porcelain=v1', '--ignored=matching', '--untracked-files=all', '--', ...affected]);
|
|
426
|
+
if (status.status !== 0) problems.push('git status failed');
|
|
427
|
+
else if (status.stdout.trim()) problems.push(`uncommitted, untracked or ignored files where the stamp writes; commit or clear them first:\n${status.stdout.trimEnd()}`);
|
|
428
|
+
if (problems.length) return refuse(problems);
|
|
429
|
+
|
|
430
|
+
const changed = new Set();
|
|
431
|
+
// Copies the stamp replaces whose bytes differ from the kit's: git keeps the old bytes; the caller reviews them.
|
|
432
|
+
const replaced = [];
|
|
433
|
+
for (const path of legacy) {
|
|
434
|
+
const want = join(kit, '.agents/hooks', path.slice('.claude/hooks/'.length));
|
|
435
|
+
if (!existsSync(want) || !readFileSync(join(root, path)).equals(readFileSync(want))) replaced.push(path);
|
|
436
|
+
rmSync(join(root, path));
|
|
437
|
+
changed.add(path);
|
|
438
|
+
}
|
|
439
|
+
if (isRealDir(join(root, '.claude/hooks')) && !readdirSync(join(root, '.claude/hooks')).length) rmdirSync(join(root, '.claude/hooks'));
|
|
440
|
+
for (const name of oldKitSkills) {
|
|
441
|
+
const path = `${CLAUDE_SKILLS}/${name}`;
|
|
442
|
+
for (const file of entriesUnder(root, path)) {
|
|
443
|
+
if (!readFileSync(join(root, file)).equals(readFileSync(join(kit, SKILLS, name, relative(path, file))))) replaced.push(file);
|
|
444
|
+
changed.add(file);
|
|
445
|
+
}
|
|
446
|
+
rmSync(join(root, path), { recursive: true });
|
|
447
|
+
}
|
|
448
|
+
for (const name of own) {
|
|
449
|
+
mkdirSync(join(root, SKILLS), { recursive: true });
|
|
450
|
+
for (const file of entriesUnder(root, `${CLAUDE_SKILLS}/${name}`)) {
|
|
451
|
+
changed.add(file);
|
|
452
|
+
changed.add(`${SKILLS}/${relative(CLAUDE_SKILLS, file)}`);
|
|
453
|
+
}
|
|
454
|
+
renameSync(join(root, CLAUDE_SKILLS, name), join(root, SKILLS, name));
|
|
455
|
+
}
|
|
456
|
+
for (const path of files) {
|
|
457
|
+
const from = join(kit, path);
|
|
458
|
+
const to = join(root, path);
|
|
459
|
+
const bytes = readFileSync(from);
|
|
460
|
+
const mode = statSync(from).mode & 0o777;
|
|
461
|
+
const same = existsSync(to) && readFileSync(to).equals(bytes);
|
|
462
|
+
if (!same || (statSync(to).mode & 0o777) !== mode) {
|
|
463
|
+
if (existsSync(to) && !same) replaced.push(path);
|
|
464
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
465
|
+
writeFileSync(to, bytes);
|
|
466
|
+
chmodSync(to, mode);
|
|
467
|
+
changed.add(path);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const next = plan(root);
|
|
471
|
+
if (next.problems.length) return { changed: [...changed].sort(), replaced, problems: next.problems };
|
|
472
|
+
apply(root, next.actions);
|
|
473
|
+
for (const action of next.actions) changed.add(action.path);
|
|
474
|
+
return { changed: [...changed].sort(), replaced: [...new Set(replaced)].sort(), problems: [] };
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// ---------------------------------------------------------------- main
|
|
478
|
+
|
|
479
|
+
function main(argv) {
|
|
480
|
+
let root = process.cwd();
|
|
481
|
+
let check = false;
|
|
482
|
+
let from = null;
|
|
483
|
+
for (let k = 0; k < argv.length; k++) {
|
|
484
|
+
const arg = argv[k];
|
|
485
|
+
if (arg === '--check') check = true;
|
|
486
|
+
else if ((arg === '--root' || arg === '--from') && argv[k + 1] && !argv[k + 1].startsWith('--')) {
|
|
487
|
+
if (arg === '--root') root = argv[++k];
|
|
488
|
+
else from = argv[++k];
|
|
489
|
+
} else {
|
|
490
|
+
process.stderr.write('usage: agent-sync.mjs [--check] [--from <repo-kit>] [--root <dir>]\n');
|
|
491
|
+
return 2;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (check && from) {
|
|
495
|
+
process.stderr.write('agent-sync: --check and --from do not mix\n');
|
|
496
|
+
return 2;
|
|
497
|
+
}
|
|
498
|
+
root = resolve(root);
|
|
499
|
+
if (from) {
|
|
500
|
+
const { changed, replaced, problems } = stamp(resolve(from), root);
|
|
501
|
+
for (const path of changed) process.stdout.write(`stamped ${path}\n`);
|
|
502
|
+
for (const path of replaced) process.stdout.write(`replaced ${path}: its bytes differed from the kit's; check git diff for a local edit\n`);
|
|
503
|
+
for (const problem of problems) process.stderr.write(`agent-sync: ${problem}\n`);
|
|
504
|
+
return problems.length ? 1 : 0;
|
|
505
|
+
}
|
|
506
|
+
const { actions, problems } = plan(root);
|
|
507
|
+
for (const problem of problems) process.stderr.write(`agent-sync: ${problem}\n`);
|
|
508
|
+
if (check) {
|
|
509
|
+
for (const action of actions) process.stderr.write(`agent-sync: ${action.path} is out of date (run node scripts/agent-sync.mjs)\n`);
|
|
510
|
+
return problems.length || actions.length ? 1 : 0;
|
|
511
|
+
}
|
|
512
|
+
if (problems.length) return 1;
|
|
513
|
+
apply(root, actions);
|
|
514
|
+
for (const action of actions) process.stdout.write(`${action.kind === 'unlink' ? 'removed' : 'wrote'} ${action.path}\n`);
|
|
515
|
+
return 0;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) process.exitCode = main(process.argv.slice(2));
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// DEV-SPEED DS12: real APFS clones from Node. Node's `COPYFILE_FICLONE` makes a full copy on macOS (measured: a
|
|
2
|
+
// clone's ATTR_CMNEXT_PRIVATESIZE equals its size, so every "clone" cost its bytes again) and `cpSync` ignores the
|
|
3
|
+
// flag, so a clone here is fclonefileat(2), called through python3's ctypes: one process for every pair.
|
|
4
|
+
//
|
|
5
|
+
// Each source is opened without following a final symlink and must be a regular file or a directory by its open
|
|
6
|
+
// descriptor, so a path swapped for a link between any check and the clone is refused, never followed. A directory is
|
|
7
|
+
// cloned whole in one call; links inside it stay links, so a caller that needs regular files walks the result. The
|
|
8
|
+
// target must not exist. A clone shares every block with its source until either side writes, so it costs no disk;
|
|
9
|
+
// a caller that must trust the bytes hashes them afterwards (pins-reuse.mjs does).
|
|
10
|
+
//
|
|
11
|
+
// Off macOS, or when the filesystem refuses clones (another volume, no clone support), each pair is copied instead,
|
|
12
|
+
// with the same refusal of a linked source.
|
|
13
|
+
import {spawnSync} from 'node:child_process';
|
|
14
|
+
import {closeSync,constants,cpSync,fstatSync,lstatSync,openSync,readFileSync,writeFileSync} from 'node:fs';
|
|
15
|
+
|
|
16
|
+
const CLONE=`import ctypes, os, stat, sys
|
|
17
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
18
|
+
libc.fclonefileat.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_char_p, ctypes.c_uint32]
|
|
19
|
+
AT_FDCWD, CLONE_NOOWNERCOPY = -2, 2
|
|
20
|
+
parts = sys.stdin.buffer.read().split(b'\\0')[:-1]
|
|
21
|
+
for source, target in zip(parts[0::2], parts[1::2]):
|
|
22
|
+
try:
|
|
23
|
+
fd = os.open(source, os.O_RDONLY | os.O_NOFOLLOW)
|
|
24
|
+
except OSError as error:
|
|
25
|
+
sys.exit(f'{source.decode()}: {error.strerror}')
|
|
26
|
+
try:
|
|
27
|
+
mode = os.fstat(fd).st_mode
|
|
28
|
+
if not (stat.S_ISREG(mode) or stat.S_ISDIR(mode)):
|
|
29
|
+
sys.exit(f'{source.decode()}: not a regular file or directory')
|
|
30
|
+
if libc.fclonefileat(fd, AT_FDCWD, target, CLONE_NOOWNERCOPY) != 0:
|
|
31
|
+
sys.exit(f'{target.decode()}: {os.strerror(ctypes.get_errno())}')
|
|
32
|
+
finally:
|
|
33
|
+
os.close(fd)`;
|
|
34
|
+
|
|
35
|
+
/** Copy one pair, refusing a linked source the same way the clone does. @param {string} source @param {string} target */
|
|
36
|
+
function copyPair(source,target){
|
|
37
|
+
const fd=openSync(source,constants.O_RDONLY|constants.O_NOFOLLOW);
|
|
38
|
+
try{
|
|
39
|
+
const stat=fstatSync(fd);
|
|
40
|
+
if(stat.isFile()){writeFileSync(target,readFileSync(fd),{flag:'wx',mode:stat.mode&0o777});return;}
|
|
41
|
+
if(!stat.isDirectory())throw new Error(`${source}: not a regular file or directory`);
|
|
42
|
+
}finally{closeSync(fd);}
|
|
43
|
+
cpSync(source,target,{recursive:true,errorOnExist:true,force:false,verbatimSymlinks:true});
|
|
44
|
+
if(!lstatSync(target).isDirectory())throw new Error(`${target}: copy is not a directory`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Clone each `[source, target]` pair. Returns `clone` when every pair is an APFS clone, `copy` when some were copied.
|
|
49
|
+
* Throws when a source is a link, missing or neither a file nor a directory, or a target exists; a pair cloned before
|
|
50
|
+
* the failure stays.
|
|
51
|
+
* @param {readonly (readonly [string,string])[]} pairs @param {{platform?:string}} [options]
|
|
52
|
+
* @returns {'clone'|'copy'|'none'}
|
|
53
|
+
*/
|
|
54
|
+
export function clonePaths(pairs,{platform=process.platform}={}){
|
|
55
|
+
if(pairs.length===0)return 'none';
|
|
56
|
+
let rest=pairs;
|
|
57
|
+
if(platform==='darwin'){
|
|
58
|
+
const result=spawnSync('python3',['-I','-c',CLONE],{input:`${pairs.flat().join('\0')}\0`,encoding:'utf8',maxBuffer:64<<20});
|
|
59
|
+
if(result.status===0)return 'clone';
|
|
60
|
+
const reason=result.error?.message??result.stderr.trim();
|
|
61
|
+
// Only a refusal the filesystem gives (no clone support, another volume) falls back to copies; anything else stops.
|
|
62
|
+
if(!/Operation not supported|Cross-device link/u.test(reason))throw new Error(`clonefile: ${reason}`);
|
|
63
|
+
rest=pairs.filter(([,target])=>{try{lstatSync(target);return false;}catch{return true;}});
|
|
64
|
+
}
|
|
65
|
+
for(const [source,target] of rest)copyPair(source,target);
|
|
66
|
+
return 'copy';
|
|
67
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// J230: the hosted install must really use the cached global virtual store.
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
5
|
+
import { resolve, sep } from 'node:path';
|
|
6
|
+
|
|
7
|
+
const modules = JSON.parse(readFileSync('node_modules/.modules.yaml', 'utf8'));
|
|
8
|
+
assert.equal(typeof modules.storeDir, 'string');
|
|
9
|
+
assert.equal(typeof modules.virtualStoreDir, 'string');
|
|
10
|
+
const store = realpathSync(modules.storeDir);
|
|
11
|
+
const links = realpathSync(resolve('node_modules', modules.virtualStoreDir));
|
|
12
|
+
assert.equal(links, resolve(store, 'links'), 'The installer selected a checkout-local virtual store');
|
|
13
|
+
for (const name of ['valibot', 'vite', 'sharp', '@wildshard/engine']) {
|
|
14
|
+
const slot = realpathSync(resolve('node_modules', name));
|
|
15
|
+
assert.ok(slot.startsWith(links + sep), `${name} did not resolve into the registered store`);
|
|
16
|
+
console.log(`global-store-slot ${JSON.stringify({ name, slot })}`);
|
|
17
|
+
}
|
|
18
|
+
console.log(`global-store-layout ${JSON.stringify({ store, links, runnerCi: process.env.CI })}`);
|
|
19
|
+
|
|
20
|
+
const fromEngine = createRequire(new URL('./src/sharddev/package.json', import.meta.resolve('@wildshard/engine/package.json')));
|
|
21
|
+
const engineSharp = realpathSync(fromEngine.resolve('sharp'));
|
|
22
|
+
assert.ok(engineSharp.startsWith(links + sep), 'The installed engine map helper reached an ambient Sharp decoder');
|
|
23
|
+
console.log(`global-store-map-decoder ${JSON.stringify({ engineSharp })}`);
|