@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,1524 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Agent tooling parity: do Claude Code and Codex CLI load the same rules,
|
|
3
|
+
// skills, hooks and settings in this repo, from one source?
|
|
4
|
+
// (Jake, 2026-11-10; meta docs/plans/MULTI-AGENT-TOOLING-PLAN.md.)
|
|
5
|
+
//
|
|
6
|
+
// node scripts/agent-parity.mjs [--root <dir>] [--kit <repo-kit>] [--json] [--strict]
|
|
7
|
+
// node scripts/agent-parity.mjs --global [--root <home>] [--json] [--strict]
|
|
8
|
+
//
|
|
9
|
+
// --global audits the user-level layer instead (MA8): ~/.claude against
|
|
10
|
+
// ~/.codex and ~/.agents. Rules: ~/.claude/CLAUDE.md must import (`@path`)
|
|
11
|
+
// or be the file ~/.codex/AGENTS.md is. Skills: ~/.claude/skills against
|
|
12
|
+
// ~/.agents/skills and ~/.codex/skills. Hooks: ~/.claude/settings.json against
|
|
13
|
+
// ~/.codex/hooks.json, with scripts named by their path under home (`$HOME/`,
|
|
14
|
+
// `~/` and the literal home path all count) and grouped by that path, since
|
|
15
|
+
// per-tool adapters (herdr's) share a file name. Settings and MCP as in a repo,
|
|
16
|
+
// env compared per variable. One-sided items are accepted in
|
|
17
|
+
// ~/.agents/parity.json. Codex's trust store (`[hooks.state]`) is never a hook.
|
|
18
|
+
//
|
|
19
|
+
// --kit also compares each kit-owned piece (the kit's skills, .agents/hooks/,
|
|
20
|
+
// the hook spec and these two scripts) with the kit's bytes: `drift` when
|
|
21
|
+
// they differ or still sit in the old .claude/ layout, `missing` when absent.
|
|
22
|
+
// The repo's own skills and hook scripts are `accepted` when listed under
|
|
23
|
+
// "owned" in .agents/parity.json, else `drift`.
|
|
24
|
+
//
|
|
25
|
+
// Report-only by default: prints one line per item and exits 0. With
|
|
26
|
+
// --strict it exits 1 when any item is refused (the rollout turns this on
|
|
27
|
+
// per repo once its layout is fixed). Exit 2 is a usage error.
|
|
28
|
+
//
|
|
29
|
+
// Where each tool reads from (codex-cli 0.167.1, Claude Code, 2026-11-10):
|
|
30
|
+
// rules Claude: CLAUDE.md (here always `@AGENTS.md`, J241). Codex: AGENTS.md.
|
|
31
|
+
// skills Claude: .claude/skills/<name>/SKILL.md. Codex: .agents/skills/<name>/SKILL.md.
|
|
32
|
+
// hooks Claude: .claude/settings.json "hooks". Codex: .codex/hooks.json.
|
|
33
|
+
// settings Claude: .claude/settings.json other keys. Codex: .codex/config.toml.
|
|
34
|
+
// mcp Claude: .mcp.json. Codex: [mcp_servers.<name>] in .codex/config.toml.
|
|
35
|
+
// commands Claude: .claude/commands/*.md. Codex has no repo-level prompts.
|
|
36
|
+
// agents Claude: .claude/agents/*.md. Codex: .codex/agents/*.toml.
|
|
37
|
+
// githooks .githooks/ through core.hooksPath: Git runs them for both.
|
|
38
|
+
//
|
|
39
|
+
// Statuses. Passing: `same` (one file or directory, both tools load it),
|
|
40
|
+
// `paired` (both sides exist, formats differ, not compared byte for byte),
|
|
41
|
+
// `shared` (one thing both tools hit) and `accepted` (one-sided, with a
|
|
42
|
+
// reason in .agents/parity.json). Refused under --strict: `claude-only`,
|
|
43
|
+
// `codex-only`, `copy` (identical bytes kept twice by hand), `drift`
|
|
44
|
+
// (copies or registrations that differ), `broken` (points at nothing, or a
|
|
45
|
+
// tool can't load it), `inline` (a hook that runs no repo script) and
|
|
46
|
+
// `missing`. No input makes report mode crash: an unreadable or unparsable
|
|
47
|
+
// file is a `broken` item.
|
|
48
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
49
|
+
import { createHash } from 'node:crypto';
|
|
50
|
+
import { spawnSync } from 'node:child_process';
|
|
51
|
+
import { basename, isAbsolute, join, relative, resolve } from 'node:path';
|
|
52
|
+
import { homedir } from 'node:os';
|
|
53
|
+
import { pathToFileURL } from 'node:url';
|
|
54
|
+
|
|
55
|
+
export const PASSING = new Set(['same', 'paired', 'shared', 'accepted']);
|
|
56
|
+
export const ONE_SIDED = new Set(['claude-only', 'codex-only']);
|
|
57
|
+
export const STATUSES = ['same', 'paired', 'shared', 'accepted', 'claude-only', 'codex-only', 'copy', 'drift', 'broken', 'inline', 'missing'];
|
|
58
|
+
export const REFUSED = STATUSES.filter((status) => !PASSING.has(status));
|
|
59
|
+
export const EXCEPTIONS = '.agents/parity.json';
|
|
60
|
+
/** Codex's default `project_doc_max_bytes`; a repo's .codex/config.toml may set its own. */
|
|
61
|
+
export const CODEX_DOC_BYTES = 32 * 1024;
|
|
62
|
+
|
|
63
|
+
/** Hook events each tool fires. Codex's list is read from the 0.167.1 binary's HookEvent enum. */
|
|
64
|
+
export const EVENTS = {
|
|
65
|
+
claude: new Set(['PreToolUse', 'PostToolUse', 'PostToolUseFailure', 'PermissionRequest', 'Notification', 'UserPromptSubmit', 'SessionStart', 'SessionEnd', 'Stop', 'SubagentStart', 'SubagentStop', 'PreCompact']),
|
|
66
|
+
codex: new Set(['PreModelRequest', 'PostModelRequest', 'PreToolUse', 'PermissionRequest', 'PostToolUse', 'PreCompact', 'PostCompact', 'SessionStart', 'SessionEnd', 'UserPromptSubmit', 'SubagentStart', 'SubagentStop', 'Stop', 'Interrupt']),
|
|
67
|
+
};
|
|
68
|
+
/** Claude settings keys and the Codex config.toml keys that carry the same concept. */
|
|
69
|
+
export const SETTING_MAP = {
|
|
70
|
+
permissions: ['sandbox_mode', 'approval_policy', 'rules'],
|
|
71
|
+
env: ['shell_environment_policy'],
|
|
72
|
+
model: ['model'],
|
|
73
|
+
};
|
|
74
|
+
const INTERPRETERS = new Set(['bash', 'sh', 'zsh', 'node', 'python', 'python3']);
|
|
75
|
+
const TOOLS = { claude: 'Claude Code', codex: 'Codex' };
|
|
76
|
+
|
|
77
|
+
// ---------------------------------------------------------------- file access
|
|
78
|
+
|
|
79
|
+
/** Never throws: `{ text }`, `{ text: null }` when absent, or `{ text: null, error }` when unreadable. */
|
|
80
|
+
function readText(path) {
|
|
81
|
+
try {
|
|
82
|
+
return { text: readFileSync(path, 'utf8'), error: null };
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return { text: null, error: error.code === 'ENOENT' || error.code === 'ENOTDIR' ? null : `${error.code ?? 'error'} reading ${path}` };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const read = (path) => readText(path).text;
|
|
88
|
+
const isDir = (path) => {
|
|
89
|
+
try {
|
|
90
|
+
return statSync(path).isDirectory();
|
|
91
|
+
} catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const isFile = (path) => {
|
|
96
|
+
try {
|
|
97
|
+
return statSync(path).isFile();
|
|
98
|
+
} catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const isLink = (path) => {
|
|
103
|
+
try {
|
|
104
|
+
return lstatSync(path).isSymbolicLink();
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const real = (path) => {
|
|
110
|
+
try {
|
|
111
|
+
return realpathSync(path);
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/** Directory names, sorted; `[]` when absent. An unreadable directory throws, and the audit step reports it as broken. */
|
|
117
|
+
const list = (dir) => {
|
|
118
|
+
try {
|
|
119
|
+
return readdirSync(dir).filter((name) => name !== '.DS_Store').sort();
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR') return [];
|
|
122
|
+
throw Object.assign(new Error(`${error.code ?? 'error'} listing ${dir}`), { code: error.code });
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const parseJson = (text) => {
|
|
126
|
+
if (text === null) return { value: null, error: null };
|
|
127
|
+
try {
|
|
128
|
+
return { value: JSON.parse(text), error: null };
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const at = /position (\d+)/.exec(error.message);
|
|
131
|
+
return { value: null, error: at ? `invalid JSON at line ${text.slice(0, Number(at[1])).split('\n').length}` : 'invalid JSON' };
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
135
|
+
const run = (args, cwd) => {
|
|
136
|
+
const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
137
|
+
return result.error || result.status !== 0 ? '' : (result.stdout ?? '').trim();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Content hash of a file or a directory tree (relative paths and bytes; symlinks followed, each real
|
|
142
|
+
* directory once; .DS_Store skipped). Throws with the unreadable path; callers turn that into `broken`.
|
|
143
|
+
*/
|
|
144
|
+
export function hashPath(path) {
|
|
145
|
+
const hash = createHash('sha256');
|
|
146
|
+
const seen = new Set();
|
|
147
|
+
const walk = (dir, prefix) => {
|
|
148
|
+
const here = realpathSync(dir);
|
|
149
|
+
if (seen.has(here)) return;
|
|
150
|
+
seen.add(here);
|
|
151
|
+
for (const name of readdirSync(dir).sort()) {
|
|
152
|
+
if (name === '.DS_Store' || name === '__pycache__') continue;
|
|
153
|
+
const full = join(dir, name);
|
|
154
|
+
if (isDir(full)) walk(full, `${prefix}${name}/`);
|
|
155
|
+
else if (existsSync(full)) hash.update(`${prefix}${name}\0`).update(readFileSync(full)).update('\0');
|
|
156
|
+
else hash.update(`${prefix}${name}\0dangling\0`);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
if (isDir(path)) walk(path, '');
|
|
160
|
+
else hash.update(readFileSync(path));
|
|
161
|
+
return hash.digest('hex');
|
|
162
|
+
}
|
|
163
|
+
const tryHash = (path) => {
|
|
164
|
+
try {
|
|
165
|
+
return { hash: hashPath(path), error: null };
|
|
166
|
+
} catch (error) {
|
|
167
|
+
return { hash: null, error: `${error.code ?? 'error'} hashing ${error.path ?? path}` };
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// ---------------------------------------------------------------- parsers
|
|
172
|
+
|
|
173
|
+
const unquote = (value) => {
|
|
174
|
+
if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
|
|
175
|
+
try {
|
|
176
|
+
return { value: JSON.parse(value), ok: true };
|
|
177
|
+
} catch {
|
|
178
|
+
return { value: null, ok: false };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (value.length >= 2 && value.startsWith("'") && value.endsWith("'")) return { value: value.slice(1, -1).replace(/''/g, "'"), ok: true };
|
|
182
|
+
return { value, ok: !/^["']/.test(value) };
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/** Index of the quote closing a YAML quoted scalar that opens at 0, or -1 when it doesn't close. */
|
|
186
|
+
function quoteEnd(value) {
|
|
187
|
+
const quote = value[0];
|
|
188
|
+
for (let k = 1; k < value.length; k++) {
|
|
189
|
+
if (quote === '"' && value[k] === '\\') k++;
|
|
190
|
+
else if (quote === "'" && value[k] === "'" && value[k + 1] === "'") k++;
|
|
191
|
+
else if (value[k] === quote) return k;
|
|
192
|
+
}
|
|
193
|
+
return -1;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A YAML value with its trailing comment removed; a `#` inside quotes, or not after a space, is text. */
|
|
197
|
+
function stripYamlComment(text) {
|
|
198
|
+
const value = text.trim();
|
|
199
|
+
if (value.startsWith('#')) return '';
|
|
200
|
+
const quote = value[0] === '"' || value[0] === "'" ? value[0] : null;
|
|
201
|
+
if (quote) {
|
|
202
|
+
let k = 1;
|
|
203
|
+
for (; k < value.length; k++) {
|
|
204
|
+
if (quote === '"' && value[k] === '\\') k++;
|
|
205
|
+
else if (quote === "'" && value[k] === "'" && value[k + 1] === "'") k++;
|
|
206
|
+
else if (value[k] === quote) break;
|
|
207
|
+
}
|
|
208
|
+
if (k >= value.length) return value; // unclosed: unquote() refuses it
|
|
209
|
+
const rest = value.slice(k + 1).trim();
|
|
210
|
+
return rest === '' || rest.startsWith('#') ? value.slice(0, k + 1) : value; // text after the quote: refused below
|
|
211
|
+
}
|
|
212
|
+
return value.replace(/\s+#.*$/, '').trim();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The top-level scalars of a SKILL.md / agent frontmatter block: `{ fields, error }`. Plain, quoted and
|
|
217
|
+
* block (`|`, `>`) scalars become strings; a key whose value is a mapping or list maps to `null`.
|
|
218
|
+
* Malformed lines are an error, so a value never borrows from the next line.
|
|
219
|
+
*/
|
|
220
|
+
export function parseFrontmatter(text) {
|
|
221
|
+
const match = (text ?? '').match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
222
|
+
if (!match) return { fields: null, error: 'no frontmatter' };
|
|
223
|
+
const lines = match[1].split(/\r?\n/);
|
|
224
|
+
const fields = {};
|
|
225
|
+
for (let i = 0; i < lines.length; i++) {
|
|
226
|
+
const line = lines[i];
|
|
227
|
+
if (/^\s*(#.*)?$/.test(line)) continue;
|
|
228
|
+
if (/^\s/.test(line)) return { fields: null, error: `frontmatter line ${i + 2} is indented with no key above it` };
|
|
229
|
+
const pair = line.match(/^([A-Za-z0-9_-]+):(?:\s+(.*))?$/);
|
|
230
|
+
if (!pair) return { fields: null, error: `frontmatter line ${i + 2} does not parse` };
|
|
231
|
+
const [, key] = pair;
|
|
232
|
+
const rest = (pair[2] ?? '').trim();
|
|
233
|
+
// A quote that doesn't close on this line may close on a continuation line: keep it whole for folding.
|
|
234
|
+
const raw = /^["']/.test(rest) && quoteEnd(rest) === -1 ? rest : stripYamlComment(rest);
|
|
235
|
+
const nested = [];
|
|
236
|
+
while (i + 1 < lines.length && (/^\s/.test(lines[i + 1]) || lines[i + 1] === '')) nested.push(lines[++i]);
|
|
237
|
+
if (/^[|>][+-]?\d*$/.test(raw)) {
|
|
238
|
+
// Block scalar: strip the common indent, then literal (|) keeps lines and folded (>) joins
|
|
239
|
+
// them with spaces, a blank line being a newline; chomping (-, +, or clip) sets the end.
|
|
240
|
+
let end = nested.length;
|
|
241
|
+
while (end > 0 && nested[end - 1].trim() === '') end--;
|
|
242
|
+
const body = nested.slice(0, end);
|
|
243
|
+
const indent = Math.min(...body.filter((row) => row.trim()).map((row) => /^\s*/.exec(row)[0].length));
|
|
244
|
+
const rows = body.map((row) => (row.trim() === '' ? '' : row.slice(indent)));
|
|
245
|
+
let value = '';
|
|
246
|
+
if (raw.startsWith('|')) value = rows.join('\n');
|
|
247
|
+
else for (const row of rows) value += row === '' ? '\n' : `${value !== '' && !value.endsWith('\n') ? ' ' : ''}${row}`;
|
|
248
|
+
const chomp = raw.includes('-') ? 'strip' : raw.includes('+') ? 'keep' : 'clip';
|
|
249
|
+
if (value !== '' && chomp !== 'strip') value += '\n'.repeat(chomp === 'keep' ? nested.length - end + 1 : 1);
|
|
250
|
+
fields[key] = value;
|
|
251
|
+
} else if (raw === '') {
|
|
252
|
+
fields[key] = nested.some((row) => row.trim()) ? null : '';
|
|
253
|
+
} else if (/^[[{&*!]/.test(raw) || /^(null|~)$/i.test(raw)) {
|
|
254
|
+
fields[key] = null;
|
|
255
|
+
} else {
|
|
256
|
+
// A scalar may continue on indented lines; YAML folds them with single spaces.
|
|
257
|
+
const folded = [raw, ...nested.map((row) => row.trim()).filter(Boolean)].join(' ');
|
|
258
|
+
const { value, ok } = unquote(/^["']/.test(raw) ? folded : stripYamlComment(folded));
|
|
259
|
+
if (!ok) return { fields: null, error: `frontmatter key ${key} has an unclosed quote` };
|
|
260
|
+
fields[key] = value;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return { fields, error: null };
|
|
264
|
+
}
|
|
265
|
+
const nonEmpty = (value) => typeof value === 'string' && value.trim() !== '';
|
|
266
|
+
|
|
267
|
+
const TOML_ESCAPES = { b: '\b', t: '\t', n: '\n', f: '\f', r: '\r', e: '\x1b', '"': '"', '\\': '\\' };
|
|
268
|
+
const DEC = String.raw`(?:0|[1-9](?:_?\d)*)`;
|
|
269
|
+
const DIGITS = String.raw`\d(?:_?\d)*`;
|
|
270
|
+
const BARE_VALUE = new RegExp(String.raw`^(?:true|false|[+-]?(?:inf|nan)|\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:[Zz]|[+-]\d{2}:\d{2})?)?|\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?|0x[0-9A-Fa-f](?:_?[0-9A-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|[+-]?${DEC}(?:\.${DIGITS})?(?:[eE][+-]?${DIGITS})?)(?=[\s,\]}#]|$)`);
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Enough TOML to know what a config declares: every key path, with string values decoded and bare values
|
|
274
|
+
* (numbers, booleans, dates) kept raw, or an error. Covers headers, array tables, dotted and quoted keys,
|
|
275
|
+
* the four string forms with TOML escapes, arrays (commas required) and inline tables, and refuses
|
|
276
|
+
* duplicate keys. Error messages name a line and a reason, never a value.
|
|
277
|
+
*/
|
|
278
|
+
export function parseToml(text) {
|
|
279
|
+
const entries = new Map();
|
|
280
|
+
const src = text ?? '';
|
|
281
|
+
let i = 0;
|
|
282
|
+
const fail = (why) => ({ entries, error: `line ${src.slice(0, i).split('\n').length}: ${why}` });
|
|
283
|
+
const oops = (why) => {
|
|
284
|
+
throw new Error(why);
|
|
285
|
+
};
|
|
286
|
+
const skipSpace = () => {
|
|
287
|
+
while (src[i] === ' ' || src[i] === '\t') i++;
|
|
288
|
+
};
|
|
289
|
+
// Whitespace, newlines and comments, as allowed between array elements and between statements.
|
|
290
|
+
const skipBlank = () => {
|
|
291
|
+
for (;;) {
|
|
292
|
+
skipSpace();
|
|
293
|
+
if (src[i] === '#') while (i < src.length && src[i] !== '\n') i++;
|
|
294
|
+
else if (src[i] === '\n' || (src[i] === '\r' && src[i + 1] === '\n')) i += src[i] === '\r' ? 2 : 1;
|
|
295
|
+
else return;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
const endOfLine = (what) => {
|
|
299
|
+
skipSpace();
|
|
300
|
+
if (src[i] === '#') while (i < src.length && src[i] !== '\n') i++;
|
|
301
|
+
if (src[i] === '\r') i++;
|
|
302
|
+
if (i < src.length && src[i] !== '\n') oops(`text after ${what}`);
|
|
303
|
+
};
|
|
304
|
+
const decodeBasic = (body, multi) => {
|
|
305
|
+
let out = '';
|
|
306
|
+
for (let k = 0; k < body.length; k++) {
|
|
307
|
+
if (body[k] !== '\\') {
|
|
308
|
+
out += body[k];
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const next = body[++k];
|
|
312
|
+
if (next in TOML_ESCAPES) out += TOML_ESCAPES[next];
|
|
313
|
+
else if (next === 'u' || next === 'U') {
|
|
314
|
+
const size = next === 'u' ? 4 : 8;
|
|
315
|
+
const hex = body.slice(k + 1, k + 1 + size);
|
|
316
|
+
const point = /^[0-9A-Fa-f]+$/.test(hex) && hex.length === size ? parseInt(hex, 16) : -1;
|
|
317
|
+
if (point < 0 || point > 0x10ffff || (point >= 0xd800 && point <= 0xdfff)) oops('bad string escape');
|
|
318
|
+
out += String.fromCodePoint(point);
|
|
319
|
+
k += size;
|
|
320
|
+
} else if (multi && /[ \t\r\n]/.test(next ?? '')) {
|
|
321
|
+
// A line-ending backslash trims the newline and the whitespace after it.
|
|
322
|
+
const rest = body.slice(k).match(/^[ \t]*\r?\n[\s]*/);
|
|
323
|
+
if (!rest) oops('bad string escape');
|
|
324
|
+
k += rest[0].length - 1;
|
|
325
|
+
} else oops('bad string escape');
|
|
326
|
+
}
|
|
327
|
+
return out;
|
|
328
|
+
};
|
|
329
|
+
const scanString = (allowMulti = true) => {
|
|
330
|
+
const quote = src[i];
|
|
331
|
+
if (allowMulti && src.startsWith(quote.repeat(3), i)) {
|
|
332
|
+
const fence = quote.repeat(3);
|
|
333
|
+
let end = src.indexOf(fence, i + 3);
|
|
334
|
+
while (end !== -1 && quote === '"' && /(^|[^\\])(\\\\)*\\$/.test(src.slice(i + 3, end))) end = src.indexOf(fence, end + 1);
|
|
335
|
+
if (end === -1) oops('unclosed multi-line string');
|
|
336
|
+
let close = end + 3;
|
|
337
|
+
while (src[close] === quote && close - end < 5) close++; // up to two quotes may end the body
|
|
338
|
+
const body = src.slice(i + 3, close - 3).replace(/^\r?\n/, '');
|
|
339
|
+
i = close;
|
|
340
|
+
return quote === '"' ? decodeBasic(body, true) : body;
|
|
341
|
+
}
|
|
342
|
+
let k = i + 1;
|
|
343
|
+
while (k < src.length && src[k] !== quote && src[k] !== '\n') k += quote === '"' && src[k] === '\\' ? 2 : 1;
|
|
344
|
+
if (src[k] !== quote) oops('unclosed string');
|
|
345
|
+
const body = src.slice(i + 1, k);
|
|
346
|
+
i = k + 1;
|
|
347
|
+
return quote === '"' ? decodeBasic(body, false) : body;
|
|
348
|
+
};
|
|
349
|
+
const scanKey = () => {
|
|
350
|
+
const parts = [];
|
|
351
|
+
for (;;) {
|
|
352
|
+
skipSpace();
|
|
353
|
+
if (src[i] === '"' || src[i] === "'") parts.push(scanString(false));
|
|
354
|
+
else {
|
|
355
|
+
const match = src.slice(i).match(/^[A-Za-z0-9_-]+/);
|
|
356
|
+
if (!match) oops('bad key');
|
|
357
|
+
parts.push(match[0]);
|
|
358
|
+
i += match[0].length;
|
|
359
|
+
}
|
|
360
|
+
skipSpace();
|
|
361
|
+
if (src[i] !== '.') return parts;
|
|
362
|
+
i++;
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
// One value at i: { string } decoded, { raw } for a bare value, {} for an array or inline table.
|
|
366
|
+
// An inline table at `prefix` records its children as entries (inside an array, prefix is null).
|
|
367
|
+
const scanValue = (prefix = null) => {
|
|
368
|
+
if (src[i] === '"' || src[i] === "'") return { string: scanString() };
|
|
369
|
+
if (src[i] === '[') {
|
|
370
|
+
i++;
|
|
371
|
+
for (;;) {
|
|
372
|
+
skipBlank();
|
|
373
|
+
if (i >= src.length) oops('unclosed array');
|
|
374
|
+
if (src[i] === ']') {
|
|
375
|
+
i++;
|
|
376
|
+
return {};
|
|
377
|
+
}
|
|
378
|
+
scanValue(null);
|
|
379
|
+
skipBlank();
|
|
380
|
+
if (src[i] === ',') i++;
|
|
381
|
+
else if (src[i] !== ']') oops(i >= src.length ? 'unclosed array' : 'missing comma in array');
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (src[i] === '{') {
|
|
385
|
+
i++;
|
|
386
|
+
const seen = new Set();
|
|
387
|
+
skipBlank();
|
|
388
|
+
if (src[i] === '}') {
|
|
389
|
+
i++;
|
|
390
|
+
return {};
|
|
391
|
+
}
|
|
392
|
+
for (;;) {
|
|
393
|
+
const parts = scanKey();
|
|
394
|
+
const key = parts.join('\0');
|
|
395
|
+
if ([...seen].some((other) => other === key || other.startsWith(`${key}\0`) || key.startsWith(`${other}\0`))) oops('duplicate key in inline table');
|
|
396
|
+
seen.add(key);
|
|
397
|
+
if (src[i] !== '=') oops('bad inline table key');
|
|
398
|
+
i++;
|
|
399
|
+
skipSpace();
|
|
400
|
+
const path = prefix && [...prefix, ...parts];
|
|
401
|
+
const child = scanValue(path);
|
|
402
|
+
if (path) entries.set(path.join('\0'), { path, value: child.string ?? null, raw: child.raw ?? null });
|
|
403
|
+
skipBlank();
|
|
404
|
+
if (src[i] === ',') {
|
|
405
|
+
i++;
|
|
406
|
+
skipBlank();
|
|
407
|
+
} else if (src[i] === '}') {
|
|
408
|
+
i++;
|
|
409
|
+
return {};
|
|
410
|
+
} else oops(i >= src.length ? 'unclosed inline table' : 'missing comma in inline table');
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const match = src.slice(i).match(BARE_VALUE);
|
|
414
|
+
if (!match) oops(i >= src.length || /[\r\n#]/.test(src[i]) ? 'empty value' : 'unrecognised value');
|
|
415
|
+
i += match[0].length;
|
|
416
|
+
return { raw: match[0] };
|
|
417
|
+
};
|
|
418
|
+
// Each path's kind: a value, an explicit [table], an [[array]] element, or a table implied by a
|
|
419
|
+
// header ('header') or by a dotted key ('dotted'). TOML refuses redefining any of them.
|
|
420
|
+
const kinds = new Map();
|
|
421
|
+
const implied = (path, kind) => {
|
|
422
|
+
for (let n = 1; n < path.length; n++) {
|
|
423
|
+
const id = path.slice(0, n).join('\0');
|
|
424
|
+
if (kinds.get(id) === 'value') oops(`${path.slice(0, n).join('.')} is already a value`);
|
|
425
|
+
if (!kinds.has(id)) kinds.set(id, kind);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
let section = [];
|
|
429
|
+
// [[array]] elements keep their place: a stored path names each element as `#<n>` after its
|
|
430
|
+
// array's key (MA10 a), so two [[hooks.PreToolUse]] groups stay two. `kinds` stays logical.
|
|
431
|
+
const arrays = new Map();
|
|
432
|
+
// Which positions of a stored path are element markers, so a quoted key that reads "#0" is never one.
|
|
433
|
+
const physical = (logical) => {
|
|
434
|
+
const path = [];
|
|
435
|
+
const elements = [];
|
|
436
|
+
logical.forEach((segment, n) => {
|
|
437
|
+
path.push(segment);
|
|
438
|
+
const id = logical.slice(0, n + 1).join('\0');
|
|
439
|
+
if (arrays.has(id)) {
|
|
440
|
+
elements.push(path.length);
|
|
441
|
+
path.push(`#${arrays.get(id)}`);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
return { path, elements };
|
|
445
|
+
};
|
|
446
|
+
let stored = { path: [], elements: [] };
|
|
447
|
+
try {
|
|
448
|
+
for (;;) {
|
|
449
|
+
skipBlank();
|
|
450
|
+
if (i >= src.length) break;
|
|
451
|
+
if (src[i] === '[') {
|
|
452
|
+
const array = src[i + 1] === '[';
|
|
453
|
+
i += array ? 2 : 1;
|
|
454
|
+
let path;
|
|
455
|
+
try {
|
|
456
|
+
path = scanKey();
|
|
457
|
+
} catch {
|
|
458
|
+
oops('bad table header');
|
|
459
|
+
}
|
|
460
|
+
if (!src.startsWith(array ? ']]' : ']', i)) oops('unclosed table header');
|
|
461
|
+
i += array ? 2 : 1;
|
|
462
|
+
endOfLine('a table header');
|
|
463
|
+
const id = path.join('\0');
|
|
464
|
+
implied(path, 'header');
|
|
465
|
+
const kind = kinds.get(id);
|
|
466
|
+
if (array ? kind !== undefined && kind !== 'array' : kind !== undefined && kind !== 'header') oops('duplicate table');
|
|
467
|
+
if (array) for (const key of [...kinds.keys()]) if (key.startsWith(`${id}\0`)) kinds.delete(key); // a new element
|
|
468
|
+
if (array) {
|
|
469
|
+
for (const key of [...arrays.keys()]) if (key.startsWith(`${id}\0`)) arrays.delete(key); // its own nested arrays restart
|
|
470
|
+
arrays.set(id, (arrays.get(id) ?? -1) + 1);
|
|
471
|
+
}
|
|
472
|
+
kinds.set(id, array ? 'array' : 'table');
|
|
473
|
+
section = path;
|
|
474
|
+
stored = physical(path);
|
|
475
|
+
entries.set(stored.path.join('\0'), { path: stored.path, elements: stored.elements, kind: array ? 'array' : 'table', value: null, raw: null });
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
const key = scanKey();
|
|
479
|
+
if (src[i] !== '=') oops('expected key = value');
|
|
480
|
+
i++;
|
|
481
|
+
skipSpace();
|
|
482
|
+
if (i >= src.length || /[\r\n#]/.test(src[i])) oops(`key ${key.join('.')} has no value`);
|
|
483
|
+
const path = [...section, ...key];
|
|
484
|
+
const id = path.join('\0');
|
|
485
|
+
implied(path, 'dotted');
|
|
486
|
+
if (kinds.has(id)) oops(`duplicate key ${path.join('.')}`);
|
|
487
|
+
kinds.set(id, 'value');
|
|
488
|
+
const at = [...stored.path, ...key];
|
|
489
|
+
const value = scanValue(at);
|
|
490
|
+
endOfLine('a value');
|
|
491
|
+
entries.set(at.join('\0'), { path: at, elements: stored.elements, kind: 'value', value: value.string ?? null, raw: value.raw ?? null });
|
|
492
|
+
}
|
|
493
|
+
} catch (error) {
|
|
494
|
+
return fail(error.message);
|
|
495
|
+
}
|
|
496
|
+
return { entries, error: null };
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** The top-level names a TOML config declares (keys and table heads), for settings pairing. */
|
|
500
|
+
export function tomlKeys(text) {
|
|
501
|
+
const { entries, error } = parseToml(text);
|
|
502
|
+
if (error) return new Set();
|
|
503
|
+
return new Set([...entries.values()].map((entry) => entry.path[0]));
|
|
504
|
+
}
|
|
505
|
+
const tomlValue = (entries, ...path) => entries.get(path.join('\0'))?.value;
|
|
506
|
+
|
|
507
|
+
// ---------------------------------------------------------------- hooks
|
|
508
|
+
|
|
509
|
+
const ROOT = '\u0000ROOT';
|
|
510
|
+
const CLAUDE_ROOT_FORMS = ['${CLAUDE_PROJECT_DIR}', '$CLAUDE_PROJECT_DIR'];
|
|
511
|
+
const GIT_ROOT_FORM = '$(git rev-parse --show-toplevel)';
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* How a hook command runs a repo script, or why it doesn't. Supported shapes: an optional `nohup`,
|
|
515
|
+
* `exec` or `VAR=value` prefix, an optional interpreter (bash, sh, zsh, node, python3) with flags,
|
|
516
|
+
* then the script at the repo root (`$CLAUDE_PROJECT_DIR`, `$(git rev-parse --show-toplevel)`) or a
|
|
517
|
+
* relative path, then plain arguments, output redirections and a trailing `&`. Anything else (pipes,
|
|
518
|
+
* `;`, `&&`, input redirection, other substitutions, absolute paths) is `inline`: the logic lives in
|
|
519
|
+
* the config, not a shared script. Quoting is honoured: a quoted `>` or `&` is text, and only an
|
|
520
|
+
* unquoted or double-quoted, unescaped `$CLAUDE_PROJECT_DIR` is an expansion.
|
|
521
|
+
* @returns {{ script: string|null, runner: string[], args: string[], usesClaudeRoot: boolean, why: string }}
|
|
522
|
+
*/
|
|
523
|
+
export function invocation(command) {
|
|
524
|
+
let usesClaudeRoot = false;
|
|
525
|
+
const none = (why) => ({ script: null, runner: [], args: [], usesClaudeRoot, why });
|
|
526
|
+
const tokens = [];
|
|
527
|
+
let token = null; // { text, ops }: ops when it holds an unquoted & > or <
|
|
528
|
+
let quote = null;
|
|
529
|
+
const begin = () => {
|
|
530
|
+
token ??= { text: '', ops: false };
|
|
531
|
+
return token;
|
|
532
|
+
};
|
|
533
|
+
for (let k = 0; k < command.length; k++) {
|
|
534
|
+
const char = command[k];
|
|
535
|
+
if (quote === "'") {
|
|
536
|
+
if (char === "'") quote = null;
|
|
537
|
+
else begin().text += char;
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
if (char === '\\') {
|
|
541
|
+
const next = command[k + 1];
|
|
542
|
+
if (next === undefined) return none('ends with a backslash');
|
|
543
|
+
if (quote === '"' && !'$`"\\\n'.includes(next)) begin().text += char;
|
|
544
|
+
else if (next === '\n') {
|
|
545
|
+
k++;
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
begin().text += next;
|
|
549
|
+
k++;
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
if (char === '$') {
|
|
553
|
+
if (command.startsWith(GIT_ROOT_FORM, k)) {
|
|
554
|
+
begin().text += ROOT;
|
|
555
|
+
k += GIT_ROOT_FORM.length - 1;
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
const form = CLAUDE_ROOT_FORMS.find((candidate) => command.startsWith(candidate, k) && (candidate.endsWith('}') || !/\w/.test(command[k + candidate.length] ?? '')));
|
|
559
|
+
if (form) {
|
|
560
|
+
usesClaudeRoot = true;
|
|
561
|
+
begin().text += ROOT;
|
|
562
|
+
k += form.length - 1;
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (command[k + 1] === '(') return none('uses a command substitution');
|
|
566
|
+
begin().text += char;
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
if (char === '`') return none('uses a command substitution');
|
|
570
|
+
if (quote === '"') {
|
|
571
|
+
if (char === '"') quote = null;
|
|
572
|
+
else begin().text += char;
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
if (char === '"' || char === "'") {
|
|
576
|
+
quote = char;
|
|
577
|
+
begin();
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
if (/\s/.test(char)) {
|
|
581
|
+
if (char === '\n') return none('uses shell syntax (newline)');
|
|
582
|
+
if (token) tokens.push(token);
|
|
583
|
+
token = null;
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
if (/[;|()<]/.test(char)) return none(`uses shell syntax (${char})`);
|
|
587
|
+
if (char === '&' || char === '>') begin().ops = true;
|
|
588
|
+
begin().text += char;
|
|
589
|
+
}
|
|
590
|
+
if (quote) return none('has an unclosed quote');
|
|
591
|
+
if (token) tokens.push(token);
|
|
592
|
+
if (tokens.some((entry) => entry.ops && (entry.text === '&&' || entry.text === '||'))) return none('chains commands');
|
|
593
|
+
// A trailing `&` and output redirections are allowed; strip them.
|
|
594
|
+
for (;;) {
|
|
595
|
+
const last = tokens.at(-1);
|
|
596
|
+
const before = tokens.at(-2);
|
|
597
|
+
if (last?.ops && /^(?:&|\d?>>?\S+|&>>?\S+|\d?>&\d)$/.test(last.text)) tokens.pop();
|
|
598
|
+
else if (last && !last.ops && before?.ops && /^(?:\d?>>?|&>>?)$/.test(before.text)) tokens.splice(-2, 2); // `> /dev/null`
|
|
599
|
+
else break;
|
|
600
|
+
}
|
|
601
|
+
if (tokens.some((entry) => entry.ops)) return none('uses shell syntax (& or >)');
|
|
602
|
+
const words = tokens.map((entry) => entry.text);
|
|
603
|
+
let at = 0;
|
|
604
|
+
while (at < words.length && (words[at] === 'nohup' || words[at] === 'exec' || /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[at]))) at++;
|
|
605
|
+
if (at < words.length && INTERPRETERS.has(words[at])) {
|
|
606
|
+
at++;
|
|
607
|
+
const interpreter = words[at - 1];
|
|
608
|
+
while (at < words.length && words[at].startsWith('-')) {
|
|
609
|
+
const flag = words[at];
|
|
610
|
+
const shell = ['bash', 'sh', 'zsh'].includes(interpreter) && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(flag);
|
|
611
|
+
const node = interpreter === 'node' && /^(?:-[a-zA-Z]*[ep][a-zA-Z]*|--eval|--print|--eval=.*|--print=.*)$/.test(flag);
|
|
612
|
+
const python = interpreter.startsWith('python') && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(flag);
|
|
613
|
+
if (shell || node || python) return none(`runs inline code (${interpreter} ${flag.split('=')[0]})`); // never a flag's value (J206)
|
|
614
|
+
at++;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
const target = words[at];
|
|
618
|
+
if (!target) return none('runs no script');
|
|
619
|
+
let script;
|
|
620
|
+
if (target.startsWith(`${ROOT}/`)) script = target.slice(ROOT.length + 1);
|
|
621
|
+
else if (!target.includes(ROOT) && !isAbsolute(target) && !/^[~$]/.test(target) && target.includes('/')) script = target;
|
|
622
|
+
else return none(isAbsolute(target) || /^[~$]/.test(target) ? 'runs a file outside the repo' : 'runs no repo script');
|
|
623
|
+
script = script.replace(/^(\.\/)+/, '');
|
|
624
|
+
if (!script || script.split('/').includes('..') || script.includes(ROOT)) return none('runs a path outside the repo');
|
|
625
|
+
const shown = (word) => word.split(ROOT).join('@ROOT');
|
|
626
|
+
return { script, runner: words.slice(0, at).map(shown), args: words.slice(at + 1).map(shown), usesClaudeRoot, why: '' };
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/** The repo script a hook command runs, or null. */
|
|
630
|
+
export const scriptOf = (command) => invocation(command).script;
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* A matcher as the set of tools it covers, in one vocabulary per tool pair: Claude's `Edit` and `Write`
|
|
634
|
+
* together (with or without MultiEdit) equal Codex's `apply_patch`; either alone, or NotebookEdit, does not.
|
|
635
|
+
*/
|
|
636
|
+
export function normalizeMatcher(matcher, tool = 'claude', event = '') {
|
|
637
|
+
if (matcher === undefined || matcher === null || matcher === '' || matcher === '*' || matcher === '.*') return '*';
|
|
638
|
+
const tools = new Set(String(matcher).replace(/^\^\(?|\)?\$$/g, '').split('|').map((name) => name.replace(/^\^|\$$/g, '').trim()).filter(Boolean));
|
|
639
|
+
if (tool === 'codex' && tools.delete('apply_patch')) tools.add('edit');
|
|
640
|
+
if (tool === 'claude' && tools.has('Edit') && tools.has('Write')) {
|
|
641
|
+
for (const name of ['Edit', 'Write', 'MultiEdit']) tools.delete(name);
|
|
642
|
+
tools.add('edit');
|
|
643
|
+
}
|
|
644
|
+
const names = [...tools].sort();
|
|
645
|
+
if (event === 'SessionStart' && names.join('|') === 'clear|compact|resume|startup') return '*';
|
|
646
|
+
return names.join('|');
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/** Every hook handler in a hooks object ({ Event: [{ matcher, hooks: [{ type, command }] }] }), with problems. */
|
|
650
|
+
export function hookEntries(hooks, tool = 'claude') {
|
|
651
|
+
const entries = [];
|
|
652
|
+
const problems = [];
|
|
653
|
+
if (hooks === undefined || hooks === null) return { entries, problems };
|
|
654
|
+
if (!isObject(hooks)) return { entries, problems: ['"hooks" is not an object'] };
|
|
655
|
+
for (const [event, groups] of Object.entries(hooks)) {
|
|
656
|
+
if (!Array.isArray(groups)) {
|
|
657
|
+
problems.push(`${event} is not a list`);
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
for (const group of groups) {
|
|
661
|
+
if (!isObject(group) || !Array.isArray(group.hooks)) {
|
|
662
|
+
problems.push(`${event} has a matcher group without a "hooks" list`);
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
for (const hook of group.hooks) {
|
|
666
|
+
const type = isObject(hook) ? hook.type ?? 'command' : null;
|
|
667
|
+
const matcher = normalizeMatcher(group.matcher, tool, event);
|
|
668
|
+
if (type === 'command' && typeof hook.command === 'string') {
|
|
669
|
+
entries.push({ event, matcher, type, command: hook.command, ...invocation(hook.command) });
|
|
670
|
+
} else {
|
|
671
|
+
const kind = type === 'command' || typeof type !== 'string' ? 'invalid' : type;
|
|
672
|
+
entries.push({ event, matcher, type: kind, command: null, script: null, runner: [], args: [], usesClaudeRoot: false, why: '' });
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
return { entries, problems };
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// ---------------------------------------------------------------- audits
|
|
681
|
+
|
|
682
|
+
const item = (kind, name, status, extra = {}) => ({ kind, name, status, claude: null, codex: null, scripts: [], note: '', ...extra });
|
|
683
|
+
|
|
684
|
+
function auditRules(root, docLimit) {
|
|
685
|
+
const items = [];
|
|
686
|
+
const agentsRead = readText(join(root, 'AGENTS.md'));
|
|
687
|
+
const claudePath = join(root, 'CLAUDE.md');
|
|
688
|
+
const claudeRead = readText(claudePath);
|
|
689
|
+
for (const failed of [agentsRead, claudeRead].filter((result) => result.error)) items.push(item('rules', 'AGENTS.md', 'broken', { note: failed.error }));
|
|
690
|
+
if (items.length) return items;
|
|
691
|
+
const agents = agentsRead.text;
|
|
692
|
+
const claude = claudeRead.text;
|
|
693
|
+
const linked = isLink(claudePath) && real(claudePath) === real(join(root, 'AGENTS.md'));
|
|
694
|
+
const pointer = claude !== null && claude.trim() === '@AGENTS.md';
|
|
695
|
+
const sides = { claude: claude === null ? null : 'CLAUDE.md', codex: agents === null ? null : 'AGENTS.md' };
|
|
696
|
+
if (agents === null && claude === null) items.push(item('rules', 'AGENTS.md', 'missing', { note: 'no AGENTS.md or CLAUDE.md' }));
|
|
697
|
+
else if (agents === null) items.push(item('rules', 'AGENTS.md', 'claude-only', { ...sides, note: 'Codex reads AGENTS.md, not CLAUDE.md' }));
|
|
698
|
+
else if (claude === null) items.push(item('rules', 'AGENTS.md', 'codex-only', { ...sides, note: 'Claude Code reads CLAUDE.md; make it `@AGENTS.md`' }));
|
|
699
|
+
else if (linked || pointer) items.push(item('rules', 'AGENTS.md', 'same', { ...sides, note: linked ? 'CLAUDE.md links to AGENTS.md' : 'CLAUDE.md is `@AGENTS.md`' }));
|
|
700
|
+
else if (claude === agents) items.push(item('rules', 'AGENTS.md', 'copy', { ...sides, note: 'CLAUDE.md copies AGENTS.md; make it `@AGENTS.md`' }));
|
|
701
|
+
else items.push(item('rules', 'AGENTS.md', 'drift', { ...sides, note: 'CLAUDE.md holds rules Codex never sees; move them into AGENTS.md' }));
|
|
702
|
+
if (agents !== null && Buffer.byteLength(agents) > docLimit.bytes) {
|
|
703
|
+
items.push(item('rules', 'AGENTS.md size', 'broken', { codex: 'AGENTS.md', note: `${Buffer.byteLength(agents)} bytes; Codex reads only the first ${docLimit.bytes} (${docLimit.source})` }));
|
|
704
|
+
}
|
|
705
|
+
if (existsSync(join(root, 'AGENTS.override.md'))) {
|
|
706
|
+
items.push(item('rules', 'AGENTS.override.md', 'codex-only', { codex: 'AGENTS.override.md', note: 'Codex reads it instead of AGENTS.md; Claude never does' }));
|
|
707
|
+
}
|
|
708
|
+
return items;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/** The `@path` imports in a CLAUDE.md (one per line, outside code fences), resolved against `home` and `dir`. */
|
|
712
|
+
export function claudeImports(text, home, dir) {
|
|
713
|
+
const out = [];
|
|
714
|
+
let fence = false;
|
|
715
|
+
for (const line of (text ?? '').split('\n')) {
|
|
716
|
+
if (/^\s*(`{3,}|~{3,})/.test(line)) fence = !fence;
|
|
717
|
+
const match = fence ? null : /^\s*@(\S+)\s*$/.exec(line);
|
|
718
|
+
if (!match) continue;
|
|
719
|
+
const target = match[1];
|
|
720
|
+
out.push(target.startsWith('~/') ? join(home, target.slice(2)) : isAbsolute(target) ? target : join(dir, target));
|
|
721
|
+
}
|
|
722
|
+
return out;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/** Global rules: Codex reads ~/.codex/AGENTS.md, Claude ~/.claude/CLAUDE.md; Claude must import (or be) Codex's file. */
|
|
726
|
+
function auditGlobalRules(home, docLimit) {
|
|
727
|
+
const agentsPath = join(home, '.codex/AGENTS.md');
|
|
728
|
+
const claudePath = join(home, '.claude/CLAUDE.md');
|
|
729
|
+
const agentsRead = readText(agentsPath);
|
|
730
|
+
const claudeRead = readText(claudePath);
|
|
731
|
+
const name = '~/.codex/AGENTS.md';
|
|
732
|
+
const failed = [agentsRead, claudeRead].find((result) => result.error);
|
|
733
|
+
if (failed) return [item('rules', name, 'broken', { note: failed.error })];
|
|
734
|
+
const [agents, claude] = [agentsRead.text, claudeRead.text];
|
|
735
|
+
const sides = { claude: claude === null ? null : '.claude/CLAUDE.md', codex: agents === null ? null : '.codex/AGENTS.md' };
|
|
736
|
+
const items = [];
|
|
737
|
+
const shared = real(agentsPath);
|
|
738
|
+
const imports = claudeImports(claude, home, join(home, '.claude'));
|
|
739
|
+
const dangling = imports.filter((path) => real(path) === null);
|
|
740
|
+
if (agents === null && claude === null) items.push(item('rules', name, 'missing', { note: 'no ~/.codex/AGENTS.md or ~/.claude/CLAUDE.md' }));
|
|
741
|
+
else if (agents === null) items.push(item('rules', name, 'claude-only', { ...sides, note: 'Codex reads ~/.codex/AGENTS.md; link it to the shared rules file' }));
|
|
742
|
+
else if (claude === null) items.push(item('rules', name, 'codex-only', { ...sides, note: 'Claude Code reads ~/.claude/CLAUDE.md; import the shared rules file there' }));
|
|
743
|
+
else if (dangling.length) items.push(item('rules', name, 'broken', { ...sides, note: `CLAUDE.md imports a file that does not exist: ${dangling.map((path) => relative(home, path)).join(', ')}` }));
|
|
744
|
+
else if (real(claudePath) === shared) items.push(item('rules', name, 'same', { ...sides, note: 'one file' }));
|
|
745
|
+
else if (imports.some((path) => real(path) === shared)) items.push(item('rules', name, 'same', { ...sides, note: `CLAUDE.md imports ${relative(home, shared)}, the file ~/.codex/AGENTS.md is` }));
|
|
746
|
+
else if (claude === agents) items.push(item('rules', name, 'copy', { ...sides, note: 'two identical files; import one from CLAUDE.md' }));
|
|
747
|
+
else items.push(item('rules', name, 'drift', { ...sides, note: 'CLAUDE.md does not import the file ~/.codex/AGENTS.md is; Codex never sees the shared rules' }));
|
|
748
|
+
if (agents !== null && Buffer.byteLength(agents) > docLimit.bytes) {
|
|
749
|
+
items.push(item('rules', 'AGENTS.md size', 'broken', { codex: '.codex/AGENTS.md', note: `${Buffer.byteLength(agents)} bytes; Codex reads only the first ${docLimit.bytes} (${docLimit.source})` }));
|
|
750
|
+
}
|
|
751
|
+
if (existsSync(join(home, '.codex/AGENTS.override.md'))) {
|
|
752
|
+
items.push(item('rules', 'AGENTS.override.md', 'codex-only', { codex: '.codex/AGENTS.override.md', note: 'Codex reads it instead of AGENTS.md; Claude never does' }));
|
|
753
|
+
}
|
|
754
|
+
return items;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/** Claude Code's own synced-skill store under ~/.claude/skills: app state, not a skill. */
|
|
758
|
+
const GLOBAL_APP_DIRS = new Set(['synced']);
|
|
759
|
+
|
|
760
|
+
const skillDirs = (dir) => {
|
|
761
|
+
const found = new Map();
|
|
762
|
+
for (const name of list(dir)) {
|
|
763
|
+
const full = join(dir, name);
|
|
764
|
+
if (isLink(full) && real(full) === null) found.set(name, { path: full, dangling: true });
|
|
765
|
+
else if (isDir(full)) found.set(name, { path: full, dangling: false });
|
|
766
|
+
}
|
|
767
|
+
return found;
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
/** The skill spec's limits (Claude Code's skill docs; codex-cli 0.167.1's skill validator): a hyphen-case name up to 64 characters, a description up to 1024. */
|
|
771
|
+
export const SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
772
|
+
export const SKILL_NAME_MAX = 64;
|
|
773
|
+
export const SKILL_DESCRIPTION_MAX = 1024;
|
|
774
|
+
|
|
775
|
+
/** Relative markdown link targets in one skill file that don't exist (anchors, URLs and absolute paths skipped). */
|
|
776
|
+
function deadLinks(dir, file) {
|
|
777
|
+
const { text } = readText(join(dir, file));
|
|
778
|
+
if (text === null) return [];
|
|
779
|
+
const dead = [];
|
|
780
|
+
// Links in fenced code and inline code spans are examples or templates, not links.
|
|
781
|
+
let fence = null;
|
|
782
|
+
const prose = text.split('\n').map((line) => {
|
|
783
|
+
const open = /^\s*(`{3,}|~{3,})/.exec(line);
|
|
784
|
+
if (open && (fence === null || open[1][0] === fence[0] && open[1].length >= fence.length)) {
|
|
785
|
+
fence = fence === null ? open[1] : null;
|
|
786
|
+
return '';
|
|
787
|
+
}
|
|
788
|
+
return fence === null ? line.replace(/(`+)[^`]*?\1/g, '') : '';
|
|
789
|
+
}).join('\n');
|
|
790
|
+
for (const match of prose.matchAll(/\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g)) {
|
|
791
|
+
const target = match[1].split('#')[0];
|
|
792
|
+
if (!target || /^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith('/')) continue;
|
|
793
|
+
let decoded = target;
|
|
794
|
+
try {
|
|
795
|
+
decoded = decodeURI(target);
|
|
796
|
+
} catch {
|
|
797
|
+
// A malformed escape is checked as written.
|
|
798
|
+
}
|
|
799
|
+
if (!existsSync(join(real(dir) ?? dir, decoded))) dead.push(`${file} links to ${target}, which does not exist`);
|
|
800
|
+
}
|
|
801
|
+
return dead;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Why Codex (or Claude) would not load a skill, or loads it wrong (the skill lint, MA7): SKILL.md parses,
|
|
806
|
+
* `name` is the directory's name in Codex's hyphen-case, `description` is present and within Codex's cap,
|
|
807
|
+
* and every relative link in the skill's top-level markdown files resolves.
|
|
808
|
+
*/
|
|
809
|
+
function skillProblems(dir, name = basename(dir), global = false) {
|
|
810
|
+
const { text, error } = readText(join(dir, 'SKILL.md'));
|
|
811
|
+
if (error) return [error];
|
|
812
|
+
if (text === null) return ['no SKILL.md'];
|
|
813
|
+
const { fields, error: parseError } = parseFrontmatter(text);
|
|
814
|
+
if (parseError) return [`SKILL.md ${parseError}`];
|
|
815
|
+
const problems = [];
|
|
816
|
+
if (!nonEmpty(fields.name)) problems.push('frontmatter name is missing or empty');
|
|
817
|
+
// --global: a third-party installer (img2) may name the directory apart from the skill; both tools still load it.
|
|
818
|
+
else if (fields.name.trim() !== name && !global) problems.push(`frontmatter name "${fields.name.trim()}" is not the directory name "${name}"`);
|
|
819
|
+
else if (!SKILL_NAME.test(name) || name.length > SKILL_NAME_MAX) problems.push(`name "${name}" is not hyphen-case within ${SKILL_NAME_MAX} characters`);
|
|
820
|
+
if (!nonEmpty(fields.description)) problems.push('frontmatter description is missing or empty');
|
|
821
|
+
else if (fields.description.trim().length > SKILL_DESCRIPTION_MAX) problems.push(`description is ${fields.description.trim().length} characters; the skill spec allows at most ${SKILL_DESCRIPTION_MAX}`);
|
|
822
|
+
for (const file of list(dir).filter((entry) => entry.endsWith('.md'))) problems.push(...deadLinks(dir, file));
|
|
823
|
+
return problems;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function auditSkills(root, global = false) {
|
|
827
|
+
const claude = skillDirs(join(root, '.claude/skills'));
|
|
828
|
+
const codex = skillDirs(join(root, '.agents/skills'));
|
|
829
|
+
if (global) {
|
|
830
|
+
// Codex also reads its own ~/.codex/skills (.system holds its bundled skills); installers write there.
|
|
831
|
+
for (const [name, dir] of skillDirs(join(root, '.codex/skills'))) if (name !== '.system' && !codex.has(name)) codex.set(name, dir);
|
|
832
|
+
for (const name of GLOBAL_APP_DIRS) claude.delete(name);
|
|
833
|
+
}
|
|
834
|
+
const items = [];
|
|
835
|
+
for (const name of [...new Set([...claude.keys(), ...codex.keys()])].sort()) {
|
|
836
|
+
const a = claude.get(name);
|
|
837
|
+
const b = codex.get(name);
|
|
838
|
+
const sides = { claude: a ? relative(root, a.path) : null, codex: b ? relative(root, b.path) : null };
|
|
839
|
+
const dangling = [a, b].filter((side) => side?.dangling).map((side) => relative(root, side.path));
|
|
840
|
+
if (dangling.length) {
|
|
841
|
+
items.push(item('skills', name, 'broken', { ...sides, note: `dangling link: ${dangling.join(', ')}` }));
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
let status;
|
|
845
|
+
let note;
|
|
846
|
+
if (a && b && real(a.path) === real(b.path)) {
|
|
847
|
+
status = 'same';
|
|
848
|
+
note = global ? `one directory: ${relative(root, real(a.path))}` : isLink(b.path) ? '.agents/skills links to .claude/skills' : isLink(a.path) ? '.claude/skills links to .agents/skills' : 'one directory';
|
|
849
|
+
} else if (a && b) {
|
|
850
|
+
const [x, y] = [tryHash(a.path), tryHash(b.path)];
|
|
851
|
+
if (x.error || y.error) {
|
|
852
|
+
items.push(item('skills', name, 'broken', { ...sides, note: x.error ?? y.error }));
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
status = x.hash === y.hash ? 'copy' : 'drift';
|
|
856
|
+
note = status === 'copy' ? 'two identical directories; make one a symlink to the other' : 'two directories that differ';
|
|
857
|
+
} else {
|
|
858
|
+
status = a ? 'claude-only' : 'codex-only';
|
|
859
|
+
note = a ? 'Codex looks in .agents/skills/' : 'Claude looks in .claude/skills/';
|
|
860
|
+
}
|
|
861
|
+
const problems = [...new Set([a, b].filter(Boolean).flatMap((side) => skillProblems(side.path, name, global)))];
|
|
862
|
+
if (problems.length && status !== 'drift') {
|
|
863
|
+
status = 'broken';
|
|
864
|
+
note = problems.join('; ');
|
|
865
|
+
}
|
|
866
|
+
items.push(item('skills', name, status, { ...sides, note }));
|
|
867
|
+
}
|
|
868
|
+
return items;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* A user-level hook command with its home-rooted script written as a repo-root one (--global), so
|
|
873
|
+
* `invocation` reads `$HOME/x`, `${HOME}/x`, `~/x`, `<home>/x` and `'<home>/x'` alike as the script `x` under home.
|
|
874
|
+
*/
|
|
875
|
+
export function homeRooted(command, home) {
|
|
876
|
+
const literal = home.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
877
|
+
return command
|
|
878
|
+
.replace(new RegExp(`'(${literal}/[^'"$\\s]*)'`, 'g'), '"$1"')
|
|
879
|
+
.replace(new RegExp(`(^|[\\s"])(?:\\$HOME|\\$\\{HOME\\}|~|${literal})/`, 'g'), `$1${GIT_ROOT_FORM}/`);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
const homeRootedHooks = (hooks, home) => Object.fromEntries(Object.entries(hooks).map(([event, groups]) => [event, !Array.isArray(groups) ? groups : groups.map((group) => (
|
|
883
|
+
!isObject(group) || !Array.isArray(group.hooks) ? group : { ...group, hooks: group.hooks.map((hook) => (isObject(hook) && typeof hook.command === 'string' ? { ...hook, command: homeRooted(hook.command, home) } : hook)) }
|
|
884
|
+
))]));
|
|
885
|
+
|
|
886
|
+
function readHooks(root, path, tool, global = false) {
|
|
887
|
+
const { text, error } = readText(join(root, path));
|
|
888
|
+
if (error) return { entries: [], problems: [error] };
|
|
889
|
+
const parsed = parseJson(text);
|
|
890
|
+
if (parsed.error) return { entries: [], problems: [`${path} does not parse: ${parsed.error}`] };
|
|
891
|
+
if (parsed.value !== null && !isObject(parsed.value)) return { entries: [], problems: [`${path} is not a JSON object`] };
|
|
892
|
+
const hooks = global && isObject(parsed.value?.hooks) ? homeRootedHooks(parsed.value.hooks, root) : parsed.value?.hooks;
|
|
893
|
+
const { entries, problems } = hookEntries(hooks, tool);
|
|
894
|
+
return { entries, problems: problems.map((problem) => `${path}: ${problem}`) };
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/** A registration without its command text or argument values (configs can carry tokens). */
|
|
898
|
+
const describe = (entry) => {
|
|
899
|
+
if (entry.type !== 'command') return `${entry.event} ${entry.matcher}: (${entry.type} handler)`;
|
|
900
|
+
if (!entry.script) return `${entry.event} ${entry.matcher}: inline command ${commandId(entry.command)}`;
|
|
901
|
+
return `${entry.event} ${entry.matcher}: ${[...entry.runner.filter((word) => !word.includes('=')), entry.script].join(' ')}${entry.args.length ? ` (+${entry.args.length} arg(s))` : ''}`;
|
|
902
|
+
};
|
|
903
|
+
const commandId = (command) => createHash('sha256').update(command).digest('hex').slice(0, 8);
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Codex hooks written in .codex/config.toml (`[[hooks.<Event>]]` groups with `[[hooks.<Event>.hooks]]`
|
|
907
|
+
* handlers), rebuilt into the .codex/hooks.json shape so they are compared like it (MA10 a).
|
|
908
|
+
* @returns {{ hooks: object|null, problems: string[] }}
|
|
909
|
+
*/
|
|
910
|
+
export function tomlHooks(entries) {
|
|
911
|
+
const out = {};
|
|
912
|
+
const problems = new Set();
|
|
913
|
+
const scalar = (entry) => entry.value ?? (entry.raw !== null && /^\d+(?:\.\d+)?$/u.test(entry.raw) ? Number(entry.raw) : entry.raw);
|
|
914
|
+
// An element marker only where the parser put one: a quoted key reading "#0" is a key (J206 review).
|
|
915
|
+
const marker = (entry, at) => ((entry.elements ?? []).includes(at) ? Number(entry.path[at].slice(1)) : undefined);
|
|
916
|
+
for (const entry of entries.values()) {
|
|
917
|
+
const [head, event, , field, , key] = entry.path;
|
|
918
|
+
if (head !== 'hooks' || event === 'state') continue; // [hooks.state."…"]: Codex's trust store, not a hook
|
|
919
|
+
if (event === undefined) {
|
|
920
|
+
if (entry.kind === 'value') problems.add('.codex/config.toml: hooks is a value, not [[hooks.<Event>]] tables');
|
|
921
|
+
continue;
|
|
922
|
+
}
|
|
923
|
+
const group = marker(entry, 2);
|
|
924
|
+
if (group === undefined) {
|
|
925
|
+
problems.add(`.codex/config.toml: hooks.${event} is not written as [[hooks.${event}]] tables, so it can't be compared`);
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
const at = ((out[event] ??= [])[group] ??= { hooks: [] });
|
|
929
|
+
if (entry.path.length === 3) continue;
|
|
930
|
+
if (field !== 'hooks') {
|
|
931
|
+
if (entry.path.length === 4) at[field] = scalar(entry);
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
const slot = marker(entry, 4);
|
|
935
|
+
if (slot === undefined) {
|
|
936
|
+
problems.add(`.codex/config.toml: hooks.${event} lists its handlers inline; write them as [[hooks.${event}.hooks]] tables to be compared`);
|
|
937
|
+
continue;
|
|
938
|
+
}
|
|
939
|
+
const target = (at.hooks[slot] ??= {});
|
|
940
|
+
if (key !== undefined && entry.path.length === 6) target[key] = scalar(entry);
|
|
941
|
+
}
|
|
942
|
+
for (const groups of Object.values(out)) for (const group of groups) if (group) group.hooks = group.hooks.filter(Boolean);
|
|
943
|
+
for (const event of Object.keys(out)) out[event] = out[event].filter(Boolean);
|
|
944
|
+
return { hooks: Object.keys(out).length > 0 ? out : null, problems: [...problems] };
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function auditHooks(root, toml = { entries: new Map(), error: null }, global = false) {
|
|
948
|
+
const claude = readHooks(root, '.claude/settings.json', 'claude', global);
|
|
949
|
+
const codex = readHooks(root, '.codex/hooks.json', 'codex', global);
|
|
950
|
+
if (!toml.error) {
|
|
951
|
+
const inline = tomlHooks(toml.entries);
|
|
952
|
+
const fromToml = hookEntries(inline.hooks, 'codex');
|
|
953
|
+
codex.entries.push(...fromToml.entries.map((entry) => ({ ...entry, from: '.codex/config.toml' })));
|
|
954
|
+
codex.problems.push(...inline.problems, ...fromToml.problems.map((problem) => `.codex/config.toml: ${problem}`));
|
|
955
|
+
}
|
|
956
|
+
const items = [...claude.problems, ...codex.problems].map((problem) => item('hooks', problem.split(':')[0], 'broken', { note: problem }));
|
|
957
|
+
const groups = new Map();
|
|
958
|
+
const add = (name, tool, entry) => {
|
|
959
|
+
if (!groups.has(name)) groups.set(name, { claude: [], codex: [] });
|
|
960
|
+
groups.get(name)[tool].push(entry);
|
|
961
|
+
};
|
|
962
|
+
for (const [tool, { entries }] of [['claude', claude], ['codex', codex]]) {
|
|
963
|
+
for (const entry of entries) {
|
|
964
|
+
if (entry.type !== 'command') add(`${entry.event} ${entry.type} handler (${tool})`, tool, entry);
|
|
965
|
+
else if (entry.script) add(`${entry.event} ${global ? entry.script : basename(entry.script)}`, tool, entry);
|
|
966
|
+
else add(`${entry.event} inline:${commandId(entry.command)}`, tool, entry);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
for (const [name, sides] of [...groups.entries()].sort(([x], [y]) => x.localeCompare(y))) {
|
|
970
|
+
const all = [...sides.claude.map((entry) => ['claude', entry]), ...sides.codex.map((entry) => ['codex', entry])];
|
|
971
|
+
const scripts = [...new Set(all.map(([, entry]) => entry.script).filter(Boolean))];
|
|
972
|
+
const base = {
|
|
973
|
+
claude: sides.claude.length ? sides.claude.map(describe).join(' ; ') : null,
|
|
974
|
+
codex: sides.codex.length ? sides.codex.map(describe).join(' ; ') : null,
|
|
975
|
+
scripts,
|
|
976
|
+
};
|
|
977
|
+
const push = (status, note) => items.push(item('hooks', name, status, { ...base, note }));
|
|
978
|
+
const unknown = all.filter(([tool, entry]) => !EVENTS[tool].has(entry.event));
|
|
979
|
+
if (unknown.length) {
|
|
980
|
+
push('broken', unknown.map(([tool, entry]) => `${TOOLS[tool]} has no ${entry.event} event`).join('; '));
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
const handler = all.find(([, entry]) => entry.type !== 'command');
|
|
984
|
+
if (handler) {
|
|
985
|
+
const [tool, entry] = handler;
|
|
986
|
+
push(entry.type === 'invalid' ? 'broken' : `${tool}-only`, entry.type === 'invalid' ? 'a hook without a command or type' : `a ${entry.type} handler runs only in ${TOOLS[tool]}; use a command hook on a shared script`);
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
const inline = all.find(([, entry]) => !entry.script);
|
|
990
|
+
if (inline) {
|
|
991
|
+
push('inline', `${inline[1].why}; put the command in a shared script both configs call`);
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
if (sides.codex.some((entry) => entry.usesClaudeRoot)) {
|
|
995
|
+
push('broken', 'the Codex entry uses $CLAUDE_PROJECT_DIR, which Codex never sets; use $(git rev-parse --show-toplevel)');
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
const missing = scripts.filter((script) => !isFile(join(root, script)));
|
|
999
|
+
if (missing.length) {
|
|
1000
|
+
push('broken', `script not found: ${missing.join(', ')}`);
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
if (!sides.claude.length || !sides.codex.length) {
|
|
1004
|
+
const [tool, entry] = all[0];
|
|
1005
|
+
const other = tool === 'claude' ? 'codex' : 'claude';
|
|
1006
|
+
push(`${tool}-only`, EVENTS[other].has(entry.event) ? `no ${other === 'codex' ? '.codex/hooks.json' : '.claude/settings.json'} entry` : `${TOOLS[other]} has no ${entry.event} event`);
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
// Both tools register it. Compare every registration: matcher, real script, arguments (as multisets, so
|
|
1010
|
+
// a duplicate registration on one side is drift).
|
|
1011
|
+
const signature = (entry) => JSON.stringify([entry.matcher, entry.runner, real(join(root, entry.script)), entry.args]);
|
|
1012
|
+
const reals = (entries) => [...new Set(entries.map((entry) => real(join(root, entry.script))))].sort();
|
|
1013
|
+
const [ra, rb] = [reals(sides.claude), reals(sides.codex)];
|
|
1014
|
+
if (ra.join('\0') === rb.join('\0')) {
|
|
1015
|
+
const [sa, sb] = [sides.claude.map(signature).sort(), sides.codex.map(signature).sort()];
|
|
1016
|
+
if (sa.join('\0') === sb.join('\0')) push('same', ra.length === 1 && new Set(scripts).size > 1 ? 'two paths, one real script' : 'one script, both configs');
|
|
1017
|
+
else {
|
|
1018
|
+
const shape = (entries) => entries.map((entry) => `${entry.matcher}${entry.args.length ? ` +${entry.args.length} arg(s)` : ''}`).join(', ');
|
|
1019
|
+
push('drift', `registrations differ (matcher, interpreter, arguments or count): Claude [${shape(sides.claude)}] vs Codex [${shape(sides.codex)}]`);
|
|
1020
|
+
}
|
|
1021
|
+
continue;
|
|
1022
|
+
}
|
|
1023
|
+
if (ra.length === 1 && rb.length === 1) {
|
|
1024
|
+
const [x, y] = [tryHash(ra[0]), tryHash(rb[0])];
|
|
1025
|
+
if (x.error || y.error) push('broken', x.error ?? y.error);
|
|
1026
|
+
else push(x.hash === y.hash ? 'copy' : 'drift', `two scripts: ${scripts.join(', ')}`);
|
|
1027
|
+
continue;
|
|
1028
|
+
}
|
|
1029
|
+
push('drift', `several scripts named ${name.slice(name.indexOf(' ') + 1)}: ${scripts.join(', ')}`);
|
|
1030
|
+
}
|
|
1031
|
+
return items;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/** MA9's literal-token grammar (scripts/agent-policy.mjs): what both tools read the same way. */
|
|
1035
|
+
const POLICY_TOKEN = /^[A-Za-z0-9._/@%+=,-]+$/u;
|
|
1036
|
+
|
|
1037
|
+
/**
|
|
1038
|
+
* Claude's Bash denies as token lists (MA9's mapping): `Bash(<tokens>:*)` with plain tokens. Any other
|
|
1039
|
+
* Bash deny (a wildcard, an exact command) has no one Codex prefix rule and is counted as unsupported;
|
|
1040
|
+
* non-Bash denies (Read, Edit…) are no command rule at all.
|
|
1041
|
+
* @returns {{ prefixes: Set<string>, unsupported: number }} prefixes as JSON token lists
|
|
1042
|
+
*/
|
|
1043
|
+
export function claudeDenyPrefixes(deny) {
|
|
1044
|
+
const prefixes = new Set();
|
|
1045
|
+
let unsupported = 0;
|
|
1046
|
+
for (const entry of Array.isArray(deny) ? deny : []) {
|
|
1047
|
+
if (typeof entry !== 'string' || !/^Bash\(/u.test(entry)) continue;
|
|
1048
|
+
const tokens = /^Bash\(([^():]+):\*\)$/u.exec(entry)?.[1]?.split(' ');
|
|
1049
|
+
if (tokens && tokens.every((token) => POLICY_TOKEN.test(token))) prefixes.add(JSON.stringify(tokens));
|
|
1050
|
+
else unsupported++;
|
|
1051
|
+
}
|
|
1052
|
+
return { prefixes, unsupported };
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Codex execpolicy calls in a rules file, read as Starlark source: comments and strings are skipped
|
|
1057
|
+
* when finding `prefix_rule(`, keyword arguments may come in any order. Each call's arguments, or null
|
|
1058
|
+
* when one isn't a double-quoted string, a list of them, or a nested list (alternatives).
|
|
1059
|
+
*/
|
|
1060
|
+
function starlarkCalls(text, name) {
|
|
1061
|
+
const calls = [];
|
|
1062
|
+
let i = 0;
|
|
1063
|
+
const skipString = () => {
|
|
1064
|
+
const quote = text[i];
|
|
1065
|
+
for (i++; i < text.length && text[i] !== quote; i++) if (text[i] === '\\') i++;
|
|
1066
|
+
i++;
|
|
1067
|
+
};
|
|
1068
|
+
while (i < text.length) {
|
|
1069
|
+
const c = text[i];
|
|
1070
|
+
if (c === '#') { while (i < text.length && text[i] !== '\n') i++; continue; }
|
|
1071
|
+
if (c === '"' || c === "'") { skipString(); continue; }
|
|
1072
|
+
if (text.startsWith(`${name}(`, i) && !/[A-Za-z0-9_]/u.test(text[i - 1] ?? '')) {
|
|
1073
|
+
i += name.length + 1;
|
|
1074
|
+
const begin = i;
|
|
1075
|
+
let depth = 1;
|
|
1076
|
+
while (i < text.length && depth > 0) {
|
|
1077
|
+
if (text[i] === '#') { while (i < text.length && text[i] !== '\n') i++; continue; }
|
|
1078
|
+
if (text[i] === '"' || text[i] === "'") { skipString(); continue; }
|
|
1079
|
+
if ('([{'.includes(text[i])) depth++;
|
|
1080
|
+
if (')]}'.includes(text[i])) depth--;
|
|
1081
|
+
i++;
|
|
1082
|
+
}
|
|
1083
|
+
calls.push(text.slice(begin, i - 1).replace(/#[^\n]*/gu, ''));
|
|
1084
|
+
continue;
|
|
1085
|
+
}
|
|
1086
|
+
i++;
|
|
1087
|
+
}
|
|
1088
|
+
return calls.map((body) => {
|
|
1089
|
+
const args = {};
|
|
1090
|
+
for (const part of body.split(/,(?=\s*[A-Za-z_]+\s*=)/u)) {
|
|
1091
|
+
const kw = /^\s*([A-Za-z_]+)\s*=\s*([\s\S]*?)\s*,?\s*$/u.exec(part);
|
|
1092
|
+
if (!kw) return null;
|
|
1093
|
+
try {
|
|
1094
|
+
args[kw[1]] = JSON.parse(kw[2]);
|
|
1095
|
+
} catch {
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
return args;
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/**
|
|
1104
|
+
* The command prefixes Codex forbids in `.codex/rules/*.rules`: each `prefix_rule(pattern=[…],
|
|
1105
|
+
* decision="forbidden")` with MA9's plain tokens. Alternatives, other syntax and unreadable files are
|
|
1106
|
+
* counted, never dropped.
|
|
1107
|
+
* @returns {{ prefixes: Set<string>, unsupported: number }} prefixes as JSON token lists
|
|
1108
|
+
*/
|
|
1109
|
+
export function codexForbiddenPrefixes(texts) {
|
|
1110
|
+
const prefixes = new Set();
|
|
1111
|
+
let unsupported = 0;
|
|
1112
|
+
for (const text of texts) {
|
|
1113
|
+
for (const args of starlarkCalls(text ?? '', 'prefix_rule')) {
|
|
1114
|
+
if (args === null) { unsupported++; continue; }
|
|
1115
|
+
if (args.decision !== 'forbidden') continue;
|
|
1116
|
+
const tokens = args.pattern;
|
|
1117
|
+
if (Array.isArray(tokens) && tokens.length > 0 && tokens.every((token) => typeof token === 'string' && POLICY_TOKEN.test(token))) prefixes.add(JSON.stringify(tokens));
|
|
1118
|
+
else unsupported++;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
return { prefixes, unsupported };
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
/** Claude `permissions.deny` against Codex's forbidden rules: the same prefixes, or drift with counts (never the rules' text). */
|
|
1125
|
+
function comparePermissions(root, settings, global = false) {
|
|
1126
|
+
const claude = claudeDenyPrefixes(settings.permissions?.deny);
|
|
1127
|
+
const rulesDir = join(root, '.codex/rules');
|
|
1128
|
+
// --global: ~/.codex/rules/default.rules is where Codex itself appends the commands you approved (app state).
|
|
1129
|
+
const reads = list(rulesDir).filter((name) => name.endsWith('.rules') && !(global && name === 'default.rules')).map((name) => ({ name, ...readText(join(rulesDir, name)) }));
|
|
1130
|
+
const unreadable = reads.filter((file) => file.error);
|
|
1131
|
+
if (unreadable.length > 0) return { status: 'broken', note: `unreadable .codex/rules file(s): ${unreadable.map((file) => file.name).join(', ')}` };
|
|
1132
|
+
const codex = codexForbiddenPrefixes(reads.map((file) => file.text));
|
|
1133
|
+
if (claude.prefixes.size === 0 && claude.unsupported === 0 && codex.prefixes.size === 0 && codex.unsupported === 0) return null;
|
|
1134
|
+
const onlyClaude = [...claude.prefixes].filter((prefix) => !codex.prefixes.has(prefix)).length + claude.unsupported;
|
|
1135
|
+
const onlyCodex = [...codex.prefixes].filter((prefix) => !claude.prefixes.has(prefix)).length + codex.unsupported;
|
|
1136
|
+
if (onlyClaude === 0 && onlyCodex === 0) return { status: 'paired', note: `the same ${claude.prefixes.size} refused command prefix(es) in permissions.deny and .codex/rules` };
|
|
1137
|
+
return { status: 'drift', note: `refused command prefixes differ: ${onlyClaude} only in Claude permissions.deny, ${onlyCodex} only in .codex/rules (one spec writes both: scripts/agent-policy.mjs)` };
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/** Claude `env` against Codex `shell_environment_policy.set`: same names and string values, or drift naming keys only. */
|
|
1141
|
+
function compareEnv(settings, toml) {
|
|
1142
|
+
const claude = isObject(settings.env) ? settings.env : {};
|
|
1143
|
+
const codex = new Map([...toml.entries.values()].filter((entry) => entry.path[0] === 'shell_environment_policy' && entry.path[1] === 'set' && entry.path.length === 3).map((entry) => [entry.path[2], entry]));
|
|
1144
|
+
const names = [...new Set([...Object.keys(claude), ...codex.keys()])].sort();
|
|
1145
|
+
if (names.length === 0) return null;
|
|
1146
|
+
const differ = names.filter((name) => {
|
|
1147
|
+
const theirs = codex.get(name);
|
|
1148
|
+
return !Object.hasOwn(claude, name) || typeof claude[name] !== 'string' || !theirs || theirs.raw !== null || theirs.value !== claude[name];
|
|
1149
|
+
});
|
|
1150
|
+
return differ.length === 0
|
|
1151
|
+
? { status: 'paired', note: `the same ${names.length} variable(s) in env and shell_environment_policy.set` }
|
|
1152
|
+
: { status: 'drift', note: `env and shell_environment_policy.set differ for: ${differ.join(', ')}` };
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/** --global: Claude `env` against Codex `shell_environment_policy.set` one variable at a time, so a tool's own variable can be accepted. */
|
|
1156
|
+
function envItems(settings, toml) {
|
|
1157
|
+
const claude = isObject(settings.env) ? settings.env : {};
|
|
1158
|
+
const codex = new Map([...toml.entries.values()].filter((entry) => entry.path[0] === 'shell_environment_policy' && entry.path[1] === 'set' && entry.path.length === 3).map((entry) => [entry.path[2], entry]));
|
|
1159
|
+
return [...new Set([...Object.keys(claude), ...codex.keys()])].sort().map((name) => {
|
|
1160
|
+
const theirs = codex.get(name);
|
|
1161
|
+
const sides = { claude: Object.hasOwn(claude, name) ? '.claude/settings.json env' : null, codex: theirs ? '.codex/config.toml shell_environment_policy.set' : null };
|
|
1162
|
+
if (!theirs) return item('settings', `env:${name}`, 'claude-only', { ...sides, note: 'not in shell_environment_policy.set' });
|
|
1163
|
+
if (!Object.hasOwn(claude, name)) return item('settings', `env:${name}`, 'codex-only', { ...sides, note: 'not in Claude env' });
|
|
1164
|
+
const same = typeof claude[name] === 'string' && theirs.raw === null && theirs.value === claude[name];
|
|
1165
|
+
return item('settings', `env:${name}`, same ? 'paired' : 'drift', { ...sides, note: same ? 'same value' : 'values differ' });
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
function auditSettings(root, toml, global = false) {
|
|
1170
|
+
const items = [];
|
|
1171
|
+
const settingsRead = readText(join(root, '.claude/settings.json'));
|
|
1172
|
+
const settingsParsed = parseJson(settingsRead.text);
|
|
1173
|
+
const settings = isObject(settingsParsed.value) ? settingsParsed.value : {};
|
|
1174
|
+
const mcpRead = readText(join(root, '.mcp.json'));
|
|
1175
|
+
const mcpParsed = parseJson(mcpRead.text);
|
|
1176
|
+
if (mcpRead.error || mcpParsed.error) items.push(item('mcp', '.mcp.json', 'broken', { note: mcpRead.error ?? `.mcp.json does not parse: ${mcpParsed.error}` }));
|
|
1177
|
+
else if (mcpRead.text !== null && !isObject(mcpParsed.value?.mcpServers)) items.push(item('mcp', '.mcp.json', 'broken', { note: '.mcp.json must be an object with an "mcpServers" object' }));
|
|
1178
|
+
if (toml.error) items.push(item('settings', '.codex/config.toml', 'broken', { note: toml.error }));
|
|
1179
|
+
const codexKeys = new Set(toml.error ? [] : [...toml.entries.values()].map((entry) => entry.path[0]));
|
|
1180
|
+
if (list(join(root, '.codex/rules')).some((name) => name.endsWith('.rules'))) codexKeys.add('rules');
|
|
1181
|
+
// Hooks in config.toml are compared with the other hooks (auditHooks, MA10 a).
|
|
1182
|
+
const claimed = new Set(['hooks', 'mcp_servers']); // their own kinds
|
|
1183
|
+
for (const key of Object.keys(settings).filter((name) => !['hooks', '$schema', 'mcpServers'].includes(name))) {
|
|
1184
|
+
if (global && key === 'env') {
|
|
1185
|
+
items.push(...envItems(settings, toml));
|
|
1186
|
+
if (codexKeys.has('shell_environment_policy')) claimed.add('shell_environment_policy');
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
const counterparts = (SETTING_MAP[key] ?? []).filter((codexKey) => codexKeys.has(codexKey));
|
|
1190
|
+
counterparts.forEach((codexKey) => claimed.add(codexKey));
|
|
1191
|
+
// MA10 (c): where both sides carry the same meaning in a comparable form, compare it.
|
|
1192
|
+
const meaning = toml.error ? null : key === 'permissions' ? comparePermissions(root, settings, global) : key === 'env' ? compareEnv(settings, toml) : null;
|
|
1193
|
+
if (meaning) ['rules', 'shell_environment_policy'].forEach((codexKey) => codexKeys.has(codexKey) && SETTING_MAP[key].includes(codexKey) && claimed.add(codexKey));
|
|
1194
|
+
items.push(item('settings', key, meaning?.status ?? (counterparts.length ? 'paired' : 'claude-only'), {
|
|
1195
|
+
claude: `.claude/settings.json ${key}`,
|
|
1196
|
+
codex: counterparts.length ? `.codex/config.toml ${counterparts.join(', ')}` : null,
|
|
1197
|
+
note: meaning?.note ?? (counterparts.length ? 'different formats; not compared' : SETTING_MAP[key] ? `Codex counterpart: ${SETTING_MAP[key].join(' / ')}` : 'no Codex counterpart'),
|
|
1198
|
+
}));
|
|
1199
|
+
}
|
|
1200
|
+
for (const key of [...codexKeys].filter((codexKey) => !claimed.has(codexKey)).sort()) {
|
|
1201
|
+
const claudeKey = Object.entries(SETTING_MAP).find(([, values]) => values.includes(key))?.[0];
|
|
1202
|
+
items.push(item('settings', key, 'codex-only', { codex: `.codex/config.toml ${key}`, note: claudeKey ? `Claude counterpart: ${claudeKey}` : 'no Claude counterpart' }));
|
|
1203
|
+
}
|
|
1204
|
+
const claudeMcp = new Set(isObject(mcpParsed.value?.mcpServers) ? Object.keys(mcpParsed.value.mcpServers) : []);
|
|
1205
|
+
const codexMcp = new Set(toml.error ? [] : [...toml.entries.values()].filter((entry) => entry.path[0] === 'mcp_servers' && entry.path.length > 1).map((entry) => entry.path[1]));
|
|
1206
|
+
for (const name of [...new Set([...claudeMcp, ...codexMcp])].sort()) {
|
|
1207
|
+
const both = claudeMcp.has(name) && codexMcp.has(name);
|
|
1208
|
+
items.push(item('mcp', name, both ? 'paired' : claudeMcp.has(name) ? 'claude-only' : 'codex-only', {
|
|
1209
|
+
claude: claudeMcp.has(name) ? '.mcp.json' : null,
|
|
1210
|
+
codex: codexMcp.has(name) ? '.codex/config.toml' : null,
|
|
1211
|
+
note: both ? 'different formats; not compared' : '',
|
|
1212
|
+
}));
|
|
1213
|
+
}
|
|
1214
|
+
return items;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
/** Claude subagents are `.claude/agents/*.md` with name and description; Codex roles are `.codex/agents/*.toml` with developer_instructions. */
|
|
1218
|
+
function auditCommandsAndAgents(root) {
|
|
1219
|
+
const items = [];
|
|
1220
|
+
for (const name of list(join(root, '.claude/commands')).filter((file) => file.endsWith('.md'))) {
|
|
1221
|
+
items.push(item('commands', name, 'claude-only', { claude: `.claude/commands/${name}`, note: 'Codex loads no repo prompts; make it a skill' }));
|
|
1222
|
+
}
|
|
1223
|
+
const claudeAgents = new Map();
|
|
1224
|
+
for (const file of list(join(root, '.claude/agents'))) {
|
|
1225
|
+
const path = join(root, '.claude/agents', file);
|
|
1226
|
+
if (!isFile(path)) continue;
|
|
1227
|
+
if (!file.endsWith('.md')) {
|
|
1228
|
+
items.push(item('agents', file, 'broken', { claude: `.claude/agents/${file}`, note: 'Claude Code loads only .md subagents' }));
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
const { text, error } = readText(path);
|
|
1232
|
+
const { fields, error: parseError } = parseFrontmatter(text);
|
|
1233
|
+
const problem = error ?? (parseError ? `frontmatter: ${parseError}` : !nonEmpty(fields.name) || !nonEmpty(fields.description) ? 'frontmatter needs a nonempty name and description' : null);
|
|
1234
|
+
claudeAgents.set(file.replace(/\.md$/, ''), { file, problem });
|
|
1235
|
+
}
|
|
1236
|
+
const codexAgents = new Map();
|
|
1237
|
+
for (const file of list(join(root, '.codex/agents'))) {
|
|
1238
|
+
const path = join(root, '.codex/agents', file);
|
|
1239
|
+
if (!isFile(path)) continue;
|
|
1240
|
+
if (!file.endsWith('.toml')) {
|
|
1241
|
+
items.push(item('agents', file, 'broken', { codex: `.codex/agents/${file}`, note: 'Codex loads only .toml agent roles' }));
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
const { text, error } = readText(path);
|
|
1245
|
+
const parsed = parseToml(text);
|
|
1246
|
+
const problem = error ?? (parsed.error ? `does not parse: ${parsed.error}` : !nonEmpty(tomlValue(parsed.entries, 'developer_instructions')) ? 'Codex needs a nonempty developer_instructions' : null);
|
|
1247
|
+
codexAgents.set(file.replace(/\.toml$/, ''), { file, problem });
|
|
1248
|
+
}
|
|
1249
|
+
for (const name of [...new Set([...claudeAgents.keys(), ...codexAgents.keys()])].sort()) {
|
|
1250
|
+
const a = claudeAgents.get(name);
|
|
1251
|
+
const b = codexAgents.get(name);
|
|
1252
|
+
const problems = [a?.problem && `.claude/agents/${a.file}: ${a.problem}`, b?.problem && `.codex/agents/${b.file}: ${b.problem}`].filter(Boolean);
|
|
1253
|
+
items.push(item('agents', name, problems.length ? 'broken' : a && b ? 'paired' : a ? 'claude-only' : 'codex-only', {
|
|
1254
|
+
claude: a ? `.claude/agents/${a.file}` : null,
|
|
1255
|
+
codex: b ? `.codex/agents/${b.file}` : null,
|
|
1256
|
+
note: problems.join('; ') || (a && b ? 'different formats; not compared' : ''),
|
|
1257
|
+
}));
|
|
1258
|
+
}
|
|
1259
|
+
return items;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
function auditGitHooks(root) {
|
|
1263
|
+
const hooksDir = join(root, '.githooks');
|
|
1264
|
+
if (!isDir(hooksDir)) return [];
|
|
1265
|
+
const base = { claude: '.githooks', codex: '.githooks' };
|
|
1266
|
+
// A Git checkout of its own: the hooks must be active, not just intended. A directory nested in another
|
|
1267
|
+
// checkout (or no Git at all) has only package.json's intent to go on.
|
|
1268
|
+
const own = real(run(['rev-parse', '--show-toplevel'], root) || '/nonexistent') === real(root);
|
|
1269
|
+
if (own) {
|
|
1270
|
+
const configured = run(['config', '--get', 'core.hooksPath'], root);
|
|
1271
|
+
const active = configured !== '' && real(isAbsolute(configured) ? configured : join(root, configured)) === real(hooksDir);
|
|
1272
|
+
return [item('githooks', '.githooks', active ? 'shared' : 'broken', {
|
|
1273
|
+
...base,
|
|
1274
|
+
note: active ? 'Git runs them for both tools' : `core.hooksPath is ${configured ? JSON.stringify(configured) : 'unset'}, not .githooks; run pnpm install or git config core.hooksPath .githooks`,
|
|
1275
|
+
})];
|
|
1276
|
+
}
|
|
1277
|
+
return [item('githooks', '.githooks', 'broken', { ...base, note: 'not a Git checkout of its own, so no core.hooksPath runs these hooks' })];
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
// ---------------------------------------------------------------- kit drift (MA4)
|
|
1281
|
+
|
|
1282
|
+
/** The files repo-kit stamps into every repo besides its skills and hook scripts (scripts/agent-sync.mjs --from). */
|
|
1283
|
+
export const KIT_SCRIPTS = ['.agents/hooks.json', 'scripts/agent-parity.mjs', 'scripts/agent-sync.mjs'];
|
|
1284
|
+
/** Where the kit's hook scripts lived before MA2; a repo not yet stamped still has them there. */
|
|
1285
|
+
const LEGACY_HOOK_DIR = '.claude/hooks';
|
|
1286
|
+
const realDirs = (dir) => list(dir).filter((name) => isDir(join(dir, name)) && !isLink(join(dir, name)));
|
|
1287
|
+
const filesUnder = (root, dir) => {
|
|
1288
|
+
const out = [];
|
|
1289
|
+
for (const name of list(join(root, dir))) {
|
|
1290
|
+
const path = `${dir}/${name}`;
|
|
1291
|
+
if (isDir(join(root, path)) && !isLink(join(root, path))) out.push(...filesUnder(root, path));
|
|
1292
|
+
else if (isFile(join(root, path))) out.push(path);
|
|
1293
|
+
}
|
|
1294
|
+
return out;
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
/** The kit's own pieces, as drift units: one per skill directory, one per hook file, one per stamped script. */
|
|
1298
|
+
export function kitUnits(kit) {
|
|
1299
|
+
return [
|
|
1300
|
+
...realDirs(join(kit, '.agents/skills')).map((name) => ({ name: `skills/${name}`, path: `.agents/skills/${name}`, legacy: `.claude/skills/${name}` })),
|
|
1301
|
+
...list(join(kit, '.agents/hooks')).filter((name) => !isLink(join(kit, '.agents/hooks', name))).map((name) => {
|
|
1302
|
+
const path = `.agents/hooks/${name}`;
|
|
1303
|
+
return { name: `hooks/${name}`, path, legacy: isFile(join(kit, path)) ? `${LEGACY_HOOK_DIR}/${name}` : null };
|
|
1304
|
+
}),
|
|
1305
|
+
...KIT_SCRIPTS.filter((path) => isFile(join(kit, path))).map((path) => ({ name: path, path, legacy: null })),
|
|
1306
|
+
];
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* Each kit-owned piece of a repo against the kit's bytes (`--kit <repo-kit>`): `same`, `drift` (bytes
|
|
1311
|
+
* differ, or the piece is still in the old .claude/ layout), `missing`, and for the repo's own skills and
|
|
1312
|
+
* hook scripts `accepted` when `.agents/parity.json` lists them under "owned", else `drift`.
|
|
1313
|
+
*/
|
|
1314
|
+
export function auditKit(root, kit, owned = {}) {
|
|
1315
|
+
const items = [];
|
|
1316
|
+
const units = kitUnits(kit);
|
|
1317
|
+
for (const unit of units) {
|
|
1318
|
+
const want = tryHash(join(kit, unit.path));
|
|
1319
|
+
if (want.error) {
|
|
1320
|
+
items.push(item('kit', unit.name, 'broken', { note: `the kit's copy: ${want.error}` }));
|
|
1321
|
+
continue;
|
|
1322
|
+
}
|
|
1323
|
+
const here = existsSync(join(root, unit.path)) ? unit.path : unit.legacy && existsSync(join(root, unit.legacy)) ? unit.legacy : null;
|
|
1324
|
+
if (!here) {
|
|
1325
|
+
items.push(item('kit', unit.name, 'missing', { note: `no ${unit.path}; stamp it: node scripts/agent-sync.mjs --from <repo-kit>` }));
|
|
1326
|
+
continue;
|
|
1327
|
+
}
|
|
1328
|
+
const have = tryHash(join(root, here));
|
|
1329
|
+
if (have.error) items.push(item('kit', unit.name, 'broken', { note: have.error }));
|
|
1330
|
+
else if (here !== unit.path) items.push(item('kit', unit.name, 'drift', { note: `old layout at ${here}${have.hash === want.hash ? ' (same bytes)' : ', bytes differ'}; stamp it: node scripts/agent-sync.mjs --from <repo-kit>` }));
|
|
1331
|
+
else if (have.hash !== want.hash) items.push(item('kit', unit.name, 'drift', { note: `${unit.path} differs from the kit's; fix it in repo-kit, then stamp` }));
|
|
1332
|
+
else items.push(item('kit', unit.name, 'same', { note: 'the kit\'s bytes' }));
|
|
1333
|
+
}
|
|
1334
|
+
// The generated manifests and links, judged by the kit's own generator against this repo's spec.
|
|
1335
|
+
if (isFile(join(root, '.agents/hooks.json')) && isFile(join(kit, 'scripts/agent-sync.mjs'))) {
|
|
1336
|
+
const check = spawnSync(process.execPath, [join(kit, 'scripts/agent-sync.mjs'), '--check', '--root', root], { encoding: 'utf8', timeout: 30_000 });
|
|
1337
|
+
const why = (check.stderr || '').split('\n').filter(Boolean).map((line) => line.replace(/^agent-sync: /, ''));
|
|
1338
|
+
if (check.status === 0) items.push(item('kit', 'generated manifests', 'same', { note: '.claude/settings.json hooks, .codex/hooks.json and .claude/skills links match the spec' }));
|
|
1339
|
+
else items.push(item('kit', 'generated manifests', 'drift', { note: `${why.slice(0, 3).join('; ') || 'agent-sync --check failed'}; run node scripts/agent-sync.mjs` }));
|
|
1340
|
+
}
|
|
1341
|
+
// The repo's own skills and hook scripts: kept on purpose, or drift from a kit that forgot them.
|
|
1342
|
+
const kitNames = new Set(units.map((unit) => unit.name));
|
|
1343
|
+
const extras = new Set();
|
|
1344
|
+
for (const dir of ['.agents/skills', '.claude/skills']) for (const name of list(join(root, dir))) if (isDir(join(root, dir, name))) extras.add(`skills/${name}`);
|
|
1345
|
+
for (const name of list(join(root, '.agents/hooks'))) extras.add(`hooks/${name}`);
|
|
1346
|
+
for (const name of list(join(root, LEGACY_HOOK_DIR))) if (isFile(join(root, LEGACY_HOOK_DIR, name))) extras.add(`hooks/${name}`);
|
|
1347
|
+
for (const name of [...extras].filter((entry) => !kitNames.has(entry)).sort()) {
|
|
1348
|
+
const reason = owned[name];
|
|
1349
|
+
if (typeof reason === 'string' && reason.trim()) items.push(item('kit', name, 'accepted', { note: `this repo's own: ${reason.trim()}` }));
|
|
1350
|
+
else items.push(item('kit', name, 'drift', { note: `not a kit file: list it under "owned" in ${EXCEPTIONS} with a reason, or move it into repo-kit` }));
|
|
1351
|
+
}
|
|
1352
|
+
for (const name of Object.keys(owned).filter((key) => kitNames.has(key) || !extras.has(key))) {
|
|
1353
|
+
items.push(item('exceptions', `owned:${name}`, 'broken', { note: `${EXCEPTIONS} owns ${name}, which ${kitNames.has(name) ? 'is a kit file' : 'this repo does not have'}` }));
|
|
1354
|
+
}
|
|
1355
|
+
return items;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
/**
|
|
1359
|
+
* Reasons for accepted one-sided items, `{ "accept": { "<kind>:<name>": "<why>" } }`, the repo's own skills
|
|
1360
|
+
* and hook scripts for --kit, `{ "owned": { "skills/<name>": "<why>" } }`, and schema problems.
|
|
1361
|
+
*/
|
|
1362
|
+
export function readExceptions(root) {
|
|
1363
|
+
const { text, error: readError } = readText(join(root, EXCEPTIONS));
|
|
1364
|
+
if (readError) return { accept: {}, owned: {}, problems: [readError] };
|
|
1365
|
+
const { value, error } = parseJson(text);
|
|
1366
|
+
if (error) return { accept: {}, owned: {}, problems: [`${EXCEPTIONS} does not parse: ${error}`] };
|
|
1367
|
+
if (text === null) return { accept: {}, owned: {}, problems: [] };
|
|
1368
|
+
const shape = isObject(value) && Object.keys(value).length > 0 && Object.keys(value).every((key) => (key === 'accept' || key === 'owned') && isObject(value[key]));
|
|
1369
|
+
if (!shape) {
|
|
1370
|
+
return { accept: {}, owned: {}, problems: [`${EXCEPTIONS} must be { "accept"?: { "<kind>:<name>": "<reason>" }, "owned"?: { "skills/<name>" or "hooks/<name>": "<reason>" } }`] };
|
|
1371
|
+
}
|
|
1372
|
+
const out = { accept: {}, owned: {}, problems: [] };
|
|
1373
|
+
for (const key of ['accept', 'owned']) {
|
|
1374
|
+
for (const [id, reason] of Object.entries(value[key] ?? {})) {
|
|
1375
|
+
if (typeof reason !== 'string') out.problems.push(`${EXCEPTIONS} reason for ${id} is not a string`);
|
|
1376
|
+
else out[key][id] = reason;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
return out;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
/**
|
|
1383
|
+
* Every agent-tooling item in a repo, with its status. Never throws for repo content. With `kit` (a
|
|
1384
|
+
* repo-kit checkout), also each kit-owned piece against the kit's bytes (MA4).
|
|
1385
|
+
*/
|
|
1386
|
+
export function audit(rootDir, { kit = null, global = false } = {}) {
|
|
1387
|
+
const root = resolve(rootDir);
|
|
1388
|
+
if (global) return applyExceptions(root, auditGlobal(root));
|
|
1389
|
+
const tomlRead = readText(join(root, '.codex/config.toml'));
|
|
1390
|
+
const toml = tomlRead.error ? { entries: new Map(), error: tomlRead.error } : tomlRead.text === null ? { entries: new Map(), error: null } : parseToml(tomlRead.text);
|
|
1391
|
+
const docRaw = toml.entries.get('project_doc_max_bytes')?.raw;
|
|
1392
|
+
const docBytes = docRaw && /^\d[\d_]*$/.test(docRaw) ? Number(docRaw.replace(/_/g, '')) : NaN;
|
|
1393
|
+
const docLimit = docBytes > 0 ? { bytes: docBytes, source: 'this repo\'s project_doc_max_bytes' } : { bytes: CODEX_DOC_BYTES, source: 'Codex\'s default project_doc_max_bytes' };
|
|
1394
|
+
const items = [];
|
|
1395
|
+
for (const [kind, step] of [
|
|
1396
|
+
['rules', () => auditRules(root, docLimit)],
|
|
1397
|
+
['skills', () => auditSkills(root)],
|
|
1398
|
+
['hooks', () => auditHooks(root, toml)],
|
|
1399
|
+
['settings', () => auditSettings(root, toml)],
|
|
1400
|
+
['agents', () => auditCommandsAndAgents(root)],
|
|
1401
|
+
['githooks', () => auditGitHooks(root)],
|
|
1402
|
+
]) {
|
|
1403
|
+
try {
|
|
1404
|
+
items.push(...step());
|
|
1405
|
+
} catch (error) {
|
|
1406
|
+
items.push(item(kind, 'audit', 'broken', { note: `could not audit: ${error.code ?? ''} ${error.message}`.trim() }));
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
const { owned } = readExceptions(root);
|
|
1410
|
+
if (kit) {
|
|
1411
|
+
try {
|
|
1412
|
+
items.push(...auditKit(root, resolve(kit), owned));
|
|
1413
|
+
} catch (error) {
|
|
1414
|
+
items.push(item('kit', 'audit', 'broken', { note: `could not compare with the kit: ${error.code ?? ''} ${error.message}`.trim() }));
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
return applyExceptions(root, items);
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
/** The user-level layer (--global): rules, skills, hooks, settings and MCP of ~/.claude against ~/.codex and ~/.agents. */
|
|
1421
|
+
function auditGlobal(home) {
|
|
1422
|
+
const tomlRead = readText(join(home, '.codex/config.toml'));
|
|
1423
|
+
const toml = tomlRead.error ? { entries: new Map(), error: tomlRead.error } : tomlRead.text === null ? { entries: new Map(), error: null } : parseToml(tomlRead.text);
|
|
1424
|
+
const docRaw = toml.entries.get('project_doc_max_bytes')?.raw;
|
|
1425
|
+
const docBytes = docRaw && /^\d[\d_]*$/.test(docRaw) ? Number(docRaw.replace(/_/g, '')) : NaN;
|
|
1426
|
+
const docLimit = docBytes > 0 ? { bytes: docBytes, source: 'project_doc_max_bytes in ~/.codex/config.toml' } : { bytes: CODEX_DOC_BYTES, source: 'Codex\'s default project_doc_max_bytes' };
|
|
1427
|
+
const items = [];
|
|
1428
|
+
for (const [kind, step] of [
|
|
1429
|
+
['rules', () => auditGlobalRules(home, docLimit)],
|
|
1430
|
+
['skills', () => auditSkills(home, true)],
|
|
1431
|
+
['hooks', () => auditHooks(home, toml, true)],
|
|
1432
|
+
['settings', () => auditSettings(home, toml, true)],
|
|
1433
|
+
['agents', () => auditCommandsAndAgents(home)],
|
|
1434
|
+
]) {
|
|
1435
|
+
try {
|
|
1436
|
+
items.push(...step());
|
|
1437
|
+
} catch (error) {
|
|
1438
|
+
items.push(item(kind, 'audit', 'broken', { note: `could not audit: ${error.code ?? ''} ${error.message}`.trim() }));
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
return items;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
/** One-sided items accepted with a reason in .agents/parity.json become `accepted`; a stale or empty acceptance is `broken`. */
|
|
1445
|
+
function applyExceptions(root, items) {
|
|
1446
|
+
const { accept, problems } = readExceptions(root);
|
|
1447
|
+
for (const problem of problems) items.push(item('exceptions', EXCEPTIONS, 'broken', { note: problem }));
|
|
1448
|
+
const used = new Set();
|
|
1449
|
+
for (const entry of items) {
|
|
1450
|
+
const id = `${entry.kind}:${entry.name}`;
|
|
1451
|
+
const reason = accept[id];
|
|
1452
|
+
if (typeof reason === 'string' && reason.trim() && ONE_SIDED.has(entry.status)) {
|
|
1453
|
+
entry.note = `${entry.status}, accepted: ${reason.trim()}`;
|
|
1454
|
+
entry.status = 'accepted';
|
|
1455
|
+
used.add(id);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
for (const id of Object.keys(accept).filter((key) => !used.has(key))) {
|
|
1459
|
+
const why = accept[id].trim() ? 'accepts an item that is not one-sided here (stale, or not acceptable: only claude-only/codex-only can be)' : 'gives an empty reason';
|
|
1460
|
+
items.push(item('exceptions', id, 'broken', { note: `${EXCEPTIONS} ${why}` }));
|
|
1461
|
+
}
|
|
1462
|
+
return items;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
export const refusals = (items) => items.filter((entry) => !PASSING.has(entry.status));
|
|
1466
|
+
|
|
1467
|
+
export function summarize(items) {
|
|
1468
|
+
const counts = Object.fromEntries(STATUSES.map((status) => [status, 0]));
|
|
1469
|
+
for (const entry of items) counts[entry.status] += 1;
|
|
1470
|
+
return counts;
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
export function format(items, root) {
|
|
1474
|
+
const lines = [`agent parity: ${root}`];
|
|
1475
|
+
for (const entry of items) {
|
|
1476
|
+
const where = entry.scripts.length ? ` [${entry.scripts.join(', ')}]` : '';
|
|
1477
|
+
lines.push(` ${entry.status.padEnd(11)} ${entry.kind.padEnd(8)} ${entry.name}${where}${entry.note ? ` — ${entry.note}` : ''}`);
|
|
1478
|
+
}
|
|
1479
|
+
const counts = summarize(items);
|
|
1480
|
+
lines.push(` ${STATUSES.filter((status) => counts[status]).map((status) => `${status} ${counts[status]}`).join(', ') || 'no agent tooling found'}`);
|
|
1481
|
+
return lines.join('\n');
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
1485
|
+
const args = process.argv.slice(2);
|
|
1486
|
+
let root = null;
|
|
1487
|
+
let json = false;
|
|
1488
|
+
let strict = false;
|
|
1489
|
+
let kit = null;
|
|
1490
|
+
let global = false;
|
|
1491
|
+
for (let i = 0; i < args.length; i++) {
|
|
1492
|
+
if (args[i] === '--json') json = true;
|
|
1493
|
+
else if (args[i] === '--global') global = true;
|
|
1494
|
+
else if (args[i] === '--strict') strict = true;
|
|
1495
|
+
else if (args[i] === '--root' && args[i + 1]) root = args[++i];
|
|
1496
|
+
else if (args[i] === '--kit' && args[i + 1]) kit = args[++i];
|
|
1497
|
+
else {
|
|
1498
|
+
console.error('usage: agent-parity.mjs [--root <dir>] [--kit <repo-kit>] [--json] [--strict]\n agent-parity.mjs --global [--root <home>] [--json] [--strict]');
|
|
1499
|
+
process.exit(2);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
if (global && kit !== null) {
|
|
1503
|
+
console.error('agent-parity: --global audits the user-level layer; --kit applies to a repo');
|
|
1504
|
+
process.exit(2);
|
|
1505
|
+
}
|
|
1506
|
+
root ??= global ? homedir() : run(['rev-parse', '--show-toplevel'], process.cwd()) || process.cwd();
|
|
1507
|
+
if (!isDir(root)) {
|
|
1508
|
+
console.error(`agent-parity: no such directory: ${root}`);
|
|
1509
|
+
process.exit(2);
|
|
1510
|
+
}
|
|
1511
|
+
if (kit !== null && !isDir(kit)) {
|
|
1512
|
+
console.error(`agent-parity: no such directory: ${kit}`);
|
|
1513
|
+
process.exit(2);
|
|
1514
|
+
}
|
|
1515
|
+
const items = audit(root, { kit, global });
|
|
1516
|
+
const refused = refusals(items);
|
|
1517
|
+
if (json) console.log(JSON.stringify({ root: resolve(root), counts: summarize(items), items }, null, 2));
|
|
1518
|
+
else console.log(format(items, resolve(root)));
|
|
1519
|
+
if (strict && refused.length) {
|
|
1520
|
+
console.error(`agent parity: ${refused.length} item(s) refused (--strict). Fix the layout or accept a one-sided item in ${EXCEPTIONS} with a reason.`);
|
|
1521
|
+
process.exit(1);
|
|
1522
|
+
}
|
|
1523
|
+
process.exit(0);
|
|
1524
|
+
}
|