@clockgrove/assetgrove 0.0.0-stage → 0.3.2
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/LICENSE +21 -0
- package/README.md +277 -2
- package/dist/animation/commands.d.ts +180 -0
- package/dist/animation/commands.js +515 -0
- package/dist/animation/facing.d.ts +44 -0
- package/dist/animation/facing.js +100 -0
- package/dist/animation/fix.d.ts +136 -0
- package/dist/animation/fix.js +529 -0
- package/dist/animation/flicker.d.ts +44 -0
- package/dist/animation/flicker.js +117 -0
- package/dist/animation/halo.d.ts +72 -0
- package/dist/animation/halo.js +253 -0
- package/dist/animation/holes.d.ts +122 -0
- package/dist/animation/holes.js +262 -0
- package/dist/animation/preview.d.ts +38 -0
- package/dist/animation/preview.js +161 -0
- package/dist/animation/qa.d.ts +57 -0
- package/dist/animation/qa.js +418 -0
- package/dist/animation/run.d.ts +109 -0
- package/dist/animation/run.js +182 -0
- package/dist/animation/strip.d.ts +13 -0
- package/dist/animation/strip.js +41 -0
- package/dist/animation/template-choice.d.ts +75 -0
- package/dist/animation/template-choice.js +153 -0
- package/dist/animation/templates.d.ts +39 -0
- package/dist/animation/templates.js +333 -0
- package/dist/animation/types.d.ts +257 -0
- package/dist/animation/types.js +1 -0
- package/dist/approvals.d.ts +156 -0
- package/dist/approvals.js +369 -0
- package/dist/audio/aac.d.ts +61 -0
- package/dist/audio/aac.js +152 -0
- package/dist/audio/checks.d.ts +38 -0
- package/dist/audio/checks.js +254 -0
- package/dist/audio/delivery.d.ts +52 -0
- package/dist/audio/delivery.js +105 -0
- package/dist/audio/engine.d.ts +65 -0
- package/dist/audio/engine.js +164 -0
- package/dist/audio/handoff.d.ts +75 -0
- package/dist/audio/handoff.js +185 -0
- package/dist/audio/kinds.d.ts +6 -0
- package/dist/audio/kinds.js +315 -0
- package/dist/audio/loudness.d.ts +22 -0
- package/dist/audio/loudness.js +72 -0
- package/dist/audio/ogg.d.ts +27 -0
- package/dist/audio/ogg.js +65 -0
- package/dist/audio/operations.d.ts +20 -0
- package/dist/audio/operations.js +335 -0
- package/dist/audio/opus.d.ts +40 -0
- package/dist/audio/opus.js +108 -0
- package/dist/audio/profile.d.ts +200 -0
- package/dist/audio/profile.js +126 -0
- package/dist/audio/run.d.ts +83 -0
- package/dist/audio/run.js +192 -0
- package/dist/audio/vorbis-comments.d.ts +25 -0
- package/dist/audio/vorbis-comments.js +243 -0
- package/dist/audio/waveform.d.ts +13 -0
- package/dist/audio/waveform.js +52 -0
- package/dist/audio-parameters.d.ts +17 -0
- package/dist/audio-parameters.js +45 -0
- package/dist/audit/bar.d.ts +65 -0
- package/dist/audit/bar.js +97 -0
- package/dist/audit/members.d.ts +40 -0
- package/dist/audit/members.js +119 -0
- package/dist/bible-view.d.ts +10 -0
- package/dist/bible-view.js +122 -0
- package/dist/bible.d.ts +272 -0
- package/dist/bible.js +641 -0
- package/dist/budget.d.ts +119 -0
- package/dist/budget.js +227 -0
- package/dist/call-parameters.d.ts +71 -0
- package/dist/call-parameters.js +90 -0
- package/dist/calls.d.ts +145 -0
- package/dist/calls.js +788 -0
- package/dist/cli/main.d.ts +22 -0
- package/dist/cli/main.js +137 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +5 -0
- package/dist/commands/animation-qa.d.ts +1 -0
- package/dist/commands/animation-qa.js +240 -0
- package/dist/commands/apply.d.ts +12 -0
- package/dist/commands/apply.js +181 -0
- package/dist/commands/audit.d.ts +92 -0
- package/dist/commands/audit.js +555 -0
- package/dist/commands/bible.d.ts +1 -0
- package/dist/commands/bible.js +39 -0
- package/dist/commands/browse.d.ts +12 -0
- package/dist/commands/browse.js +113 -0
- package/dist/commands/card.d.ts +3 -0
- package/dist/commands/card.js +445 -0
- package/dist/commands/compare.d.ts +1 -0
- package/dist/commands/compare.js +90 -0
- package/dist/commands/confirm.d.ts +1 -0
- package/dist/commands/confirm.js +267 -0
- package/dist/commands/context.d.ts +43 -0
- package/dist/commands/context.js +115 -0
- package/dist/commands/deliver.d.ts +1 -0
- package/dist/commands/deliver.js +99 -0
- package/dist/commands/disclosure.d.ts +1 -0
- package/dist/commands/disclosure.js +80 -0
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/doctor.js +112 -0
- package/dist/commands/estimate.d.ts +2 -0
- package/dist/commands/estimate.js +80 -0
- package/dist/commands/extensions.d.ts +2 -0
- package/dist/commands/extensions.js +70 -0
- package/dist/commands/fix-frame.d.ts +1 -0
- package/dist/commands/fix-frame.js +206 -0
- package/dist/commands/generate-sheet.d.ts +1 -0
- package/dist/commands/generate-sheet.js +245 -0
- package/dist/commands/identity-check.d.ts +1 -0
- package/dist/commands/identity-check.js +110 -0
- package/dist/commands/identity-eval.d.ts +1 -0
- package/dist/commands/identity-eval.js +197 -0
- package/dist/commands/import.d.ts +7 -0
- package/dist/commands/import.js +472 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +117 -0
- package/dist/commands/intake.d.ts +1 -0
- package/dist/commands/intake.js +56 -0
- package/dist/commands/labels.d.ts +1 -0
- package/dist/commands/labels.js +101 -0
- package/dist/commands/library.d.ts +9 -0
- package/dist/commands/library.js +711 -0
- package/dist/commands/lod.d.ts +1 -0
- package/dist/commands/lod.js +93 -0
- package/dist/commands/look-dev.d.ts +1 -0
- package/dist/commands/look-dev.js +148 -0
- package/dist/commands/materials.d.ts +1 -0
- package/dist/commands/materials.js +223 -0
- package/dist/commands/mcp.d.ts +1 -0
- package/dist/commands/mcp.js +53 -0
- package/dist/commands/migrate.d.ts +1 -0
- package/dist/commands/migrate.js +123 -0
- package/dist/commands/op.d.ts +5 -0
- package/dist/commands/op.js +114 -0
- package/dist/commands/ops.d.ts +1 -0
- package/dist/commands/ops.js +17 -0
- package/dist/commands/pick-batch.d.ts +24 -0
- package/dist/commands/pick-batch.js +343 -0
- package/dist/commands/pick.d.ts +48 -0
- package/dist/commands/pick.js +469 -0
- package/dist/commands/plan.d.ts +3 -0
- package/dist/commands/plan.js +156 -0
- package/dist/commands/recipe.d.ts +1 -0
- package/dist/commands/recipe.js +52 -0
- package/dist/commands/registry.d.ts +5 -0
- package/dist/commands/registry.js +121 -0
- package/dist/commands/render-sprite.d.ts +1 -0
- package/dist/commands/render-sprite.js +67 -0
- package/dist/commands/rendition.d.ts +1 -0
- package/dist/commands/rendition.js +56 -0
- package/dist/commands/request-change.d.ts +2 -0
- package/dist/commands/request-change.js +950 -0
- package/dist/commands/result.d.ts +34 -0
- package/dist/commands/result.js +237 -0
- package/dist/commands/review.d.ts +28 -0
- package/dist/commands/review.js +444 -0
- package/dist/commands/rig.d.ts +1 -0
- package/dist/commands/rig.js +74 -0
- package/dist/commands/runner.d.ts +45 -0
- package/dist/commands/runner.js +297 -0
- package/dist/commands/runs.d.ts +22 -0
- package/dist/commands/runs.js +159 -0
- package/dist/commands/search.d.ts +69 -0
- package/dist/commands/search.js +638 -0
- package/dist/commands/settings.d.ts +2 -0
- package/dist/commands/settings.js +284 -0
- package/dist/commands/spend.d.ts +2 -0
- package/dist/commands/spend.js +159 -0
- package/dist/commands/stage-source.d.ts +1 -0
- package/dist/commands/stage-source.js +58 -0
- package/dist/commands/stage.d.ts +9 -0
- package/dist/commands/stage.js +229 -0
- package/dist/commands/storage.d.ts +3 -0
- package/dist/commands/storage.js +200 -0
- package/dist/commands/turnaround.d.ts +1 -0
- package/dist/commands/turnaround.js +171 -0
- package/dist/commands/types.d.ts +195 -0
- package/dist/commands/types.js +7 -0
- package/dist/commands/vary.d.ts +2 -0
- package/dist/commands/vary.js +222 -0
- package/dist/commands/write-families.d.ts +14 -0
- package/dist/commands/write-families.js +158 -0
- package/dist/compare.d.ts +87 -0
- package/dist/compare.js +306 -0
- package/dist/confirm/delegation.d.ts +30 -0
- package/dist/confirm/delegation.js +31 -0
- package/dist/confirm/index.d.ts +84 -0
- package/dist/confirm/index.js +176 -0
- package/dist/confirm/mcp.d.ts +60 -0
- package/dist/confirm/mcp.js +253 -0
- package/dist/confirm/pending.d.ts +11 -0
- package/dist/confirm/pending.js +40 -0
- package/dist/confirm/prompt.d.ts +65 -0
- package/dist/confirm/prompt.js +68 -0
- package/dist/confirm/records.d.ts +17 -0
- package/dist/confirm/records.js +63 -0
- package/dist/contact.d.ts +80 -0
- package/dist/contact.js +224 -0
- package/dist/credentials.d.ts +170 -0
- package/dist/credentials.js +598 -0
- package/dist/dataflows.d.ts +32 -0
- package/dist/dataflows.js +42 -0
- package/dist/delivery.d.ts +89 -0
- package/dist/delivery.js +355 -0
- package/dist/disclosure.d.ts +84 -0
- package/dist/disclosure.js +397 -0
- package/dist/env.d.ts +90 -0
- package/dist/env.js +236 -0
- package/dist/errors.d.ts +90 -0
- package/dist/errors.js +105 -0
- package/dist/extension/api.d.ts +389 -0
- package/dist/extension/api.js +20 -0
- package/dist/extension/context.d.ts +9 -0
- package/dist/extension/context.js +60 -0
- package/dist/extension/helpers.d.ts +75 -0
- package/dist/extension/helpers.js +107 -0
- package/dist/extension/http.d.ts +32 -0
- package/dist/extension/http.js +104 -0
- package/dist/extension/setup.d.ts +53 -0
- package/dist/extension/setup.js +162 -0
- package/dist/extension/tools.d.ts +97 -0
- package/dist/extension/tools.js +235 -0
- package/dist/extensions/core.d.ts +7 -0
- package/dist/extensions/core.js +18 -0
- package/dist/extensions/errors.d.ts +22 -0
- package/dist/extensions/errors.js +34 -0
- package/dist/extensions/registry.d.ts +119 -0
- package/dist/extensions/registry.js +535 -0
- package/dist/extensions/version.d.ts +9 -0
- package/dist/extensions/version.js +57 -0
- package/dist/formats.d.ts +46 -0
- package/dist/formats.js +81 -0
- package/dist/frames.d.ts +58 -0
- package/dist/frames.js +80 -0
- package/dist/gateway/anthropic.d.ts +22 -0
- package/dist/gateway/anthropic.js +65 -0
- package/dist/gateway/elevenlabs.d.ts +36 -0
- package/dist/gateway/elevenlabs.js +192 -0
- package/dist/gateway/failure.d.ts +29 -0
- package/dist/gateway/failure.js +70 -0
- package/dist/gateway/openai-compatible.d.ts +20 -0
- package/dist/gateway/openai-compatible.js +76 -0
- package/dist/gateway/openai.d.ts +28 -0
- package/dist/gateway/openai.js +101 -0
- package/dist/gateway/provider.d.ts +380 -0
- package/dist/gateway/provider.js +5 -0
- package/dist/gateway/scripted.d.ts +252 -0
- package/dist/gateway/scripted.js +244 -0
- package/dist/gateway/stability.d.ts +38 -0
- package/dist/gateway/stability.js +232 -0
- package/dist/gateway/structured.d.ts +31 -0
- package/dist/gateway/structured.js +83 -0
- package/dist/gateway/tripo.d.ts +48 -0
- package/dist/gateway/tripo.js +374 -0
- package/dist/gateway/vercel.d.ts +52 -0
- package/dist/gateway/vercel.js +298 -0
- package/dist/generators/generator.d.ts +236 -0
- package/dist/generators/generator.js +12 -0
- package/dist/generators/image.d.ts +21 -0
- package/dist/generators/image.js +286 -0
- package/dist/generators/spec-schema.d.ts +29 -0
- package/dist/generators/spec-schema.js +21 -0
- package/dist/git-marker.d.ts +3 -0
- package/dist/git-marker.js +13 -0
- package/dist/gitlfs.d.ts +38 -0
- package/dist/gitlfs.js +171 -0
- package/dist/guard.d.ts +55 -0
- package/dist/guard.js +323 -0
- package/dist/handoff/current-profile.d.ts +48 -0
- package/dist/handoff/current-profile.js +127 -0
- package/dist/handoff/doctor.d.ts +26 -0
- package/dist/handoff/doctor.js +249 -0
- package/dist/handoff/mark-check.d.ts +17 -0
- package/dist/handoff/mark-check.js +66 -0
- package/dist/handoff/presets/aseprite-json.d.ts +5 -0
- package/dist/handoff/presets/aseprite-json.js +45 -0
- package/dist/handoff/presets/atlas-json.d.ts +44 -0
- package/dist/handoff/presets/atlas-json.js +195 -0
- package/dist/handoff/presets/atlas-pack.d.ts +14 -0
- package/dist/handoff/presets/atlas-pack.js +431 -0
- package/dist/handoff/presets/index.d.ts +273 -0
- package/dist/handoff/presets/index.js +58 -0
- package/dist/handoff/presets/manifest.d.ts +2 -0
- package/dist/handoff/presets/manifest.js +49 -0
- package/dist/handoff/usage.d.ts +27 -0
- package/dist/handoff/usage.js +159 -0
- package/dist/handoff.d.ts +345 -0
- package/dist/handoff.js +1221 -0
- package/dist/identity-eval.d.ts +156 -0
- package/dist/identity-eval.js +321 -0
- package/dist/identity.d.ts +293 -0
- package/dist/identity.js +675 -0
- package/dist/image/apply-style.d.ts +4 -0
- package/dist/image/apply-style.js +37 -0
- package/dist/image/digits.d.ts +5 -0
- package/dist/image/digits.js +40 -0
- package/dist/image/ktx2.d.ts +83 -0
- package/dist/image/ktx2.js +196 -0
- package/dist/image/raster.d.ts +23 -0
- package/dist/image/raster.js +77 -0
- package/dist/image/resample.d.ts +10 -0
- package/dist/image/resample.js +82 -0
- package/dist/image/webp.d.ts +17 -0
- package/dist/image/webp.js +323 -0
- package/dist/init.d.ts +132 -0
- package/dist/init.js +425 -0
- package/dist/inputs.d.ts +67 -0
- package/dist/inputs.js +151 -0
- package/dist/json.d.ts +7 -0
- package/dist/json.js +27 -0
- package/dist/keys.d.ts +34 -0
- package/dist/keys.js +198 -0
- package/dist/kind-schemas.d.ts +17 -0
- package/dist/kind-schemas.js +205 -0
- package/dist/library/actions.d.ts +76 -0
- package/dist/library/actions.js +212 -0
- package/dist/library/adopt.d.ts +177 -0
- package/dist/library/adopt.js +624 -0
- package/dist/library/canonical.d.ts +7 -0
- package/dist/library/canonical.js +29 -0
- package/dist/library/card.d.ts +138 -0
- package/dist/library/card.js +532 -0
- package/dist/library/credits.d.ts +70 -0
- package/dist/library/credits.js +222 -0
- package/dist/library/describe.d.ts +48 -0
- package/dist/library/describe.js +199 -0
- package/dist/library/diff.d.ts +26 -0
- package/dist/library/diff.js +208 -0
- package/dist/library/exact.d.ts +15 -0
- package/dist/library/exact.js +47 -0
- package/dist/library/extent.d.ts +56 -0
- package/dist/library/extent.js +205 -0
- package/dist/library/folder.d.ts +85 -0
- package/dist/library/folder.js +291 -0
- package/dist/library/labels.d.ts +29 -0
- package/dist/library/labels.js +112 -0
- package/dist/library/lfs.d.ts +42 -0
- package/dist/library/lfs.js +140 -0
- package/dist/library/maintain.d.ts +100 -0
- package/dist/library/maintain.js +750 -0
- package/dist/library/media-metadata.d.ts +19 -0
- package/dist/library/media-metadata.js +92 -0
- package/dist/library/paths.d.ts +7 -0
- package/dist/library/paths.js +65 -0
- package/dist/library/relations.d.ts +59 -0
- package/dist/library/relations.js +176 -0
- package/dist/library/review.d.ts +204 -0
- package/dist/library/review.js +545 -0
- package/dist/library/stale.d.ts +88 -0
- package/dist/library/stale.js +229 -0
- package/dist/library/suggestions.d.ts +37 -0
- package/dist/library/suggestions.js +146 -0
- package/dist/library/summary.d.ts +65 -0
- package/dist/library/summary.js +138 -0
- package/dist/library/undo.d.ts +18 -0
- package/dist/library/undo.js +141 -0
- package/dist/library/worklist.d.ts +42 -0
- package/dist/library/worklist.js +91 -0
- package/dist/library/write.d.ts +282 -0
- package/dist/library/write.js +790 -0
- package/dist/license.d.ts +67 -0
- package/dist/license.js +205 -0
- package/dist/limits.d.ts +51 -0
- package/dist/limits.js +100 -0
- package/dist/loop.d.ts +244 -0
- package/dist/loop.js +377 -0
- package/dist/material/core.d.ts +70 -0
- package/dist/material/core.js +238 -0
- package/dist/material/engine.d.ts +15 -0
- package/dist/material/engine.js +141 -0
- package/dist/material/flicker.d.ts +26 -0
- package/dist/material/flicker.js +71 -0
- package/dist/material/operations.d.ts +2 -0
- package/dist/material/operations.js +48 -0
- package/dist/material/pipeline.d.ts +51 -0
- package/dist/material/pipeline.js +431 -0
- package/dist/material/profile.d.ts +29 -0
- package/dist/material/profile.js +97 -0
- package/dist/material/rendition.d.ts +5 -0
- package/dist/material/rendition.js +76 -0
- package/dist/mcp.d.ts +72 -0
- package/dist/mcp.js +514 -0
- package/dist/media.d.ts +36 -0
- package/dist/media.js +46 -0
- package/dist/metadata.d.ts +61 -0
- package/dist/metadata.js +748 -0
- package/dist/model-declarations.d.ts +28 -0
- package/dist/model-declarations.js +14 -0
- package/dist/model3d/clip-map.d.ts +49 -0
- package/dist/model3d/clip-map.js +129 -0
- package/dist/model3d/core-checks.d.ts +61 -0
- package/dist/model3d/core-checks.js +278 -0
- package/dist/model3d/facing.d.ts +49 -0
- package/dist/model3d/facing.js +125 -0
- package/dist/model3d/generator.d.ts +19 -0
- package/dist/model3d/generator.js +482 -0
- package/dist/model3d/glb.d.ts +120 -0
- package/dist/model3d/glb.js +155 -0
- package/dist/model3d/handoff.d.ts +37 -0
- package/dist/model3d/handoff.js +131 -0
- package/dist/model3d/lod/chain.d.ts +50 -0
- package/dist/model3d/lod/chain.js +447 -0
- package/dist/model3d/lod/command.d.ts +38 -0
- package/dist/model3d/lod/command.js +377 -0
- package/dist/model3d/lod/qa.d.ts +36 -0
- package/dist/model3d/lod/qa.js +189 -0
- package/dist/model3d/lod/settings.d.ts +36 -0
- package/dist/model3d/lod/settings.js +137 -0
- package/dist/model3d/lod/simplify.d.ts +35 -0
- package/dist/model3d/lod/simplify.js +337 -0
- package/dist/model3d/lod/textures.d.ts +46 -0
- package/dist/model3d/lod/textures.js +190 -0
- package/dist/model3d/lookdev/command.d.ts +219 -0
- package/dist/model3d/lookdev/command.js +1795 -0
- package/dist/model3d/lookdev/edit.d.ts +44 -0
- package/dist/model3d/lookdev/edit.js +241 -0
- package/dist/model3d/lookdev/groom.d.ts +86 -0
- package/dist/model3d/lookdev/groom.js +462 -0
- package/dist/model3d/lookdev/markings.d.ts +98 -0
- package/dist/model3d/lookdev/markings.js +319 -0
- package/dist/model3d/lookdev/project.d.ts +100 -0
- package/dist/model3d/lookdev/project.js +721 -0
- package/dist/model3d/lookdev/settings.d.ts +65 -0
- package/dist/model3d/lookdev/settings.js +103 -0
- package/dist/model3d/lookdev/texels.d.ts +32 -0
- package/dist/model3d/lookdev/texels.js +192 -0
- package/dist/model3d/profile.d.ts +101 -0
- package/dist/model3d/profile.js +132 -0
- package/dist/model3d/prop.d.ts +29 -0
- package/dist/model3d/prop.js +317 -0
- package/dist/model3d/qa.d.ts +27 -0
- package/dist/model3d/qa.js +105 -0
- package/dist/model3d/render.d.ts +172 -0
- package/dist/model3d/render.js +791 -0
- package/dist/model3d/rig/build.d.ts +14 -0
- package/dist/model3d/rig/build.js +210 -0
- package/dist/model3d/rig/candidate.d.ts +50 -0
- package/dist/model3d/rig/candidate.js +132 -0
- package/dist/model3d/rig/command.d.ts +50 -0
- package/dist/model3d/rig/command.js +229 -0
- package/dist/model3d/rig/fit.d.ts +88 -0
- package/dist/model3d/rig/fit.js +568 -0
- package/dist/model3d/rig/gait.d.ts +105 -0
- package/dist/model3d/rig/gait.js +334 -0
- package/dist/model3d/rig/math.d.ts +27 -0
- package/dist/model3d/rig/math.js +92 -0
- package/dist/model3d/rig/motion.d.ts +26 -0
- package/dist/model3d/rig/motion.js +223 -0
- package/dist/model3d/rig/qa.d.ts +76 -0
- package/dist/model3d/rig/qa.js +357 -0
- package/dist/model3d/rig/rig.d.ts +55 -0
- package/dist/model3d/rig/rig.js +213 -0
- package/dist/model3d/rig/template.d.ts +195 -0
- package/dist/model3d/rig/template.js +456 -0
- package/dist/model3d/scene.d.ts +115 -0
- package/dist/model3d/scene.js +684 -0
- package/dist/model3d/views.d.ts +77 -0
- package/dist/model3d/views.js +190 -0
- package/dist/origin.d.ts +162 -0
- package/dist/origin.js +134 -0
- package/dist/paths.d.ts +53 -0
- package/dist/paths.js +240 -0
- package/dist/planning.d.ts +261 -0
- package/dist/planning.js +1470 -0
- package/dist/policy/blocklist.d.ts +28 -0
- package/dist/policy/blocklist.js +58 -0
- package/dist/policy/brief.d.ts +67 -0
- package/dist/policy/brief.js +110 -0
- package/dist/policy/cuts.d.ts +26 -0
- package/dist/policy/cuts.js +80 -0
- package/dist/policy/model.d.ts +69 -0
- package/dist/policy/model.js +202 -0
- package/dist/policy/text.d.ts +183 -0
- package/dist/policy/text.js +285 -0
- package/dist/postprocess.d.ts +68 -0
- package/dist/postprocess.js +302 -0
- package/dist/profile.d.ts +5 -0
- package/dist/profile.js +98 -0
- package/dist/project-rules.d.ts +54 -0
- package/dist/project-rules.js +105 -0
- package/dist/provenance-binding.d.ts +55 -0
- package/dist/provenance-binding.js +352 -0
- package/dist/providers/adapter.d.ts +176 -0
- package/dist/providers/adapter.js +418 -0
- package/dist/providers/index.d.ts +33 -0
- package/dist/providers/index.js +49 -0
- package/dist/providers/script.d.ts +13 -0
- package/dist/providers/script.js +65 -0
- package/dist/providers/set.d.ts +76 -0
- package/dist/providers/set.js +134 -0
- package/dist/pure-cbor.d.ts +1 -0
- package/dist/pure-cbor.js +8 -0
- package/dist/qa/stability.d.ts +215 -0
- package/dist/qa/stability.js +393 -0
- package/dist/qa/stability.json +32 -0
- package/dist/qa.d.ts +36 -0
- package/dist/qa.js +148 -0
- package/dist/reconcile.d.ts +111 -0
- package/dist/reconcile.js +416 -0
- package/dist/redact.d.ts +29 -0
- package/dist/redact.js +74 -0
- package/dist/regions.d.ts +49 -0
- package/dist/regions.js +113 -0
- package/dist/release-policy.d.ts +99 -0
- package/dist/release-policy.js +266 -0
- package/dist/request.d.ts +74 -0
- package/dist/request.js +249 -0
- package/dist/routes.d.ts +327 -0
- package/dist/routes.js +1166 -0
- package/dist/runs/dir.d.ts +33 -0
- package/dist/runs/dir.js +30 -0
- package/dist/runs/execute.d.ts +86 -0
- package/dist/runs/execute.js +422 -0
- package/dist/runs/journal.d.ts +150 -0
- package/dist/runs/journal.js +216 -0
- package/dist/runs/lock.d.ts +57 -0
- package/dist/runs/lock.js +322 -0
- package/dist/runs/plan.d.ts +261 -0
- package/dist/runs/plan.js +404 -0
- package/dist/search/near-match.d.ts +32 -0
- package/dist/search/near-match.js +86 -0
- package/dist/search/reader.d.ts +17 -0
- package/dist/search/reader.js +334 -0
- package/dist/search/sheet.d.ts +4 -0
- package/dist/search/sheet.js +28 -0
- package/dist/search/style-outliers.d.ts +77 -0
- package/dist/search/style-outliers.js +166 -0
- package/dist/settings-write.d.ts +78 -0
- package/dist/settings-write.js +374 -0
- package/dist/settings.d.ts +436 -0
- package/dist/settings.js +622 -0
- package/dist/shared-settings.d.ts +4 -0
- package/dist/shared-settings.js +24 -0
- package/dist/sheet/blobs.d.ts +33 -0
- package/dist/sheet/blobs.js +145 -0
- package/dist/sheet/generate.d.ts +71 -0
- package/dist/sheet/generate.js +278 -0
- package/dist/sheet/group.d.ts +20 -0
- package/dist/sheet/group.js +191 -0
- package/dist/sheet/import.d.ts +315 -0
- package/dist/sheet/import.js +832 -0
- package/dist/sheet/matte.d.ts +25 -0
- package/dist/sheet/matte.js +508 -0
- package/dist/sheet/media-import.d.ts +41 -0
- package/dist/sheet/media-import.js +118 -0
- package/dist/sheet/register.d.ts +17 -0
- package/dist/sheet/register.js +176 -0
- package/dist/sheet/slice.d.ts +73 -0
- package/dist/sheet/slice.js +912 -0
- package/dist/sheet/types.d.ts +225 -0
- package/dist/sheet/types.js +1 -0
- package/dist/source/aseprite.d.ts +14 -0
- package/dist/source/aseprite.js +124 -0
- package/dist/source/stage.d.ts +24 -0
- package/dist/source/stage.js +172 -0
- package/dist/spend.d.ts +220 -0
- package/dist/spend.js +436 -0
- package/dist/sprite/render.d.ts +22 -0
- package/dist/sprite/render.js +272 -0
- package/dist/storage.d.ts +135 -0
- package/dist/storage.js +405 -0
- package/dist/style.d.ts +19 -0
- package/dist/style.js +26 -0
- package/dist/template.d.ts +29 -0
- package/dist/template.js +98 -0
- package/dist/testing/aseprite.d.ts +54 -0
- package/dist/testing/aseprite.js +191 -0
- package/dist/testing/cli.d.ts +24 -0
- package/dist/testing/cli.js +91 -0
- package/dist/testing/conformance.d.ts +61 -0
- package/dist/testing/conformance.js +455 -0
- package/dist/testing/index.d.ts +23 -0
- package/dist/testing/index.js +15 -0
- package/dist/testing/mcp.d.ts +25 -0
- package/dist/testing/mcp.js +80 -0
- package/dist/testing/project.d.ts +81 -0
- package/dist/testing/project.js +215 -0
- package/dist/testing/samples.d.ts +42 -0
- package/dist/testing/samples.js +122 -0
- package/dist/transform/operations.d.ts +5 -0
- package/dist/transform/operations.js +320 -0
- package/dist/transform/raster-engine.d.ts +9 -0
- package/dist/transform/raster-engine.js +329 -0
- package/dist/transform/rendition.d.ts +65 -0
- package/dist/transform/rendition.js +317 -0
- package/dist/transform/run.d.ts +138 -0
- package/dist/transform/run.js +442 -0
- package/dist/transform/schema.d.ts +33 -0
- package/dist/transform/schema.js +73 -0
- package/dist/transform/types.d.ts +101 -0
- package/dist/transform/types.js +1 -0
- package/dist/tree/address.d.ts +18 -0
- package/dist/tree/address.js +59 -0
- package/dist/tree/list.d.ts +18 -0
- package/dist/tree/list.js +101 -0
- package/dist/tree/project.d.ts +61 -0
- package/dist/tree/project.js +145 -0
- package/dist/tree/read.d.ts +43 -0
- package/dist/tree/read.js +715 -0
- package/dist/tree/search.d.ts +20 -0
- package/dist/tree/search.js +44 -0
- package/dist/tree/serve.d.ts +79 -0
- package/dist/tree/serve.js +415 -0
- package/dist/tree/thumbs.d.ts +26 -0
- package/dist/tree/thumbs.js +134 -0
- package/dist/turnaround.d.ts +195 -0
- package/dist/turnaround.js +622 -0
- package/dist/types.d.ts +595 -0
- package/dist/types.js +1 -0
- package/package.json +112 -3
- package/policy/blocklist.json +47 -0
- package/policy/prompt-policy-cuts.json +15 -0
- package/skills/art-direction/SKILL.md +16 -0
- package/skills/art-direction/default.md +14 -0
- package/skills/art-direction/presets/cozy-storybook.md +121 -0
- package/skills/art-direction/presets/dark-gritty-isometric.md +121 -0
- package/skills/art-direction/presets/flat-cartoon-kids.md +121 -0
- package/skills/art-direction/references/bible-format.md +47 -0
- package/skills/assetgrove/SKILL.md +109 -0
- package/skills/assetgrove/references/commands.md +723 -0
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
import { evaluateProjectRules, enforceProjectRules, measuredRuleMedia, } from "../project-rules.js";
|
|
2
|
+
/**
|
|
3
|
+
* The library write of a hand-off (design sections 1 to 1.3): after the media and its provenance,
|
|
4
|
+
* the version goes into `<assetId>.review.json` (the commit point), then the card `<assetId>.md`,
|
|
5
|
+
* each `index.md` from the library root down, and the folder's `log.md`. Every file is written to
|
|
6
|
+
* a temporary file in its own folder and renamed over the target, and the caller holds the library
|
|
7
|
+
* write lock. Re-running a half-finished write completes it: a version already in the record is
|
|
8
|
+
* not appended again, and the projections are rewritten from the records.
|
|
9
|
+
*/
|
|
10
|
+
import { randomBytes } from "node:crypto";
|
|
11
|
+
import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
12
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
13
|
+
import { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep, } from "node:path";
|
|
14
|
+
import { InputError } from "../errors.js";
|
|
15
|
+
import { sha256Hex } from "./canonical.js";
|
|
16
|
+
import { CREDITS_JSON, CREDITS_MD, currentCredits, renderCreditsJson, renderCreditsMarkdown, } from "./credits.js";
|
|
17
|
+
import { applySummary, checkCardPaths, isCardText, machineFields, newCard, parseCard, rewriteMachineFields, writeCard, } from "./card.js";
|
|
18
|
+
import { checkedVocabulary, editLabels } from "./labels.js";
|
|
19
|
+
import { summaryEntry, summaryState } from "./summary.js";
|
|
20
|
+
import { indexAssetsFor, logEntriesFromReview, logLinesFor, renderIndex, renderLog, } from "./folder.js";
|
|
21
|
+
import { parseLfsPointer } from "./lfs.js";
|
|
22
|
+
import { measureMediaBytes } from "./media-metadata.js";
|
|
23
|
+
import { libraryPath } from "./paths.js";
|
|
24
|
+
import { annotationId, appendAnnotation, appendVersion, checkReviewPaths, emptyReview, nextStamp, parseReview, updateVersionLineage, versionNumber, versionStatus, writeReview, } from "./review.js";
|
|
25
|
+
/** Asset ids the asset tree uses for its own files and views (design section 1). */
|
|
26
|
+
export const RESERVED_IDS = [
|
|
27
|
+
"index",
|
|
28
|
+
"log",
|
|
29
|
+
"by-kind",
|
|
30
|
+
"by-subject",
|
|
31
|
+
"by-tag",
|
|
32
|
+
"stale",
|
|
33
|
+
"runs",
|
|
34
|
+
"find",
|
|
35
|
+
"like",
|
|
36
|
+
"where",
|
|
37
|
+
];
|
|
38
|
+
export class AssetIdError extends InputError {
|
|
39
|
+
code;
|
|
40
|
+
constructor(code, message) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = "AssetIdError";
|
|
43
|
+
this.code = code;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The directory segments of a layout template before the first one holding a placeholder. */
|
|
47
|
+
export function staticPrefix(template) {
|
|
48
|
+
const segments = template.replaceAll("\\", "/").split("/").slice(0, -1);
|
|
49
|
+
const fixed = [];
|
|
50
|
+
for (const segment of segments) {
|
|
51
|
+
if (segment.includes("{{"))
|
|
52
|
+
break;
|
|
53
|
+
fixed.push(segment);
|
|
54
|
+
}
|
|
55
|
+
return fixed.filter((s) => s !== "" && s !== ".").join("/");
|
|
56
|
+
}
|
|
57
|
+
/** A game id from a profile name: lower case, every run of other characters one `-`. */
|
|
58
|
+
export function gameSlug(name) {
|
|
59
|
+
const slug = name
|
|
60
|
+
.normalize("NFKD")
|
|
61
|
+
.toLowerCase()
|
|
62
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
63
|
+
.replace(/^-+|-+$/g, "");
|
|
64
|
+
return slug === "" ? "game" : slug;
|
|
65
|
+
}
|
|
66
|
+
export function within(root, path) {
|
|
67
|
+
const rel = relative(root, path);
|
|
68
|
+
return rel === "" || (!rel.startsWith(`..${sep}`) && rel !== ".." && !isAbsolute(rel));
|
|
69
|
+
}
|
|
70
|
+
/** The profile's `library` block with its defaults, for a target directory. */
|
|
71
|
+
export function libraryConfig(profile, targetDir) {
|
|
72
|
+
const block = profile.library ?? {};
|
|
73
|
+
const rootRel = (block.root ?? staticPrefix(profile.layout.media)).replaceAll("\\", "/");
|
|
74
|
+
if (isAbsolute(rootRel) || posix.isAbsolute(rootRel)) {
|
|
75
|
+
throw new InputError(`library.root "${rootRel}" must be a path inside the target`);
|
|
76
|
+
}
|
|
77
|
+
const root = resolve(targetDir, rootRel);
|
|
78
|
+
if (!within(resolve(targetDir), root)) {
|
|
79
|
+
throw new InputError(`library.root "${rootRel}" leaves the target directory`);
|
|
80
|
+
}
|
|
81
|
+
const game = block.game ?? gameSlug(profile.name);
|
|
82
|
+
if (game === "" || /[/\\\s]/.test(game)) {
|
|
83
|
+
throw new InputError(`library.game "${game}" must be one path segment without spaces`);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
root,
|
|
87
|
+
rootRel: relative(resolve(targetDir), root).split(sep).join("/"),
|
|
88
|
+
game,
|
|
89
|
+
log: block.log !== false,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** The library id of a hand-off's asset: the spec's id, and its animation family when it names one. */
|
|
93
|
+
export function assetIdOf(spec) {
|
|
94
|
+
return spec.animationFamily ? `${spec.assetId}-${spec.animationFamily}` : spec.assetId;
|
|
95
|
+
}
|
|
96
|
+
const SKIP_DIR = (name) => name.startsWith(".") || name === "node_modules" || name.endsWith(".review");
|
|
97
|
+
/**
|
|
98
|
+
* Every card under the library root: a Markdown file other than `index.md` and `log.md` whose
|
|
99
|
+
* front matter says `type: Game Asset` and parses. Links are not followed, nor dot folders,
|
|
100
|
+
* `node_modules` or `<id>.review` folders.
|
|
101
|
+
*/
|
|
102
|
+
export function scanCards(root) {
|
|
103
|
+
return scanLibrary(root).cards;
|
|
104
|
+
}
|
|
105
|
+
/** Every card under the library root, and the cards there that do not parse. */
|
|
106
|
+
export function scanLibrary(root) {
|
|
107
|
+
const found = [];
|
|
108
|
+
const unreadable = [];
|
|
109
|
+
const walk = (dir) => {
|
|
110
|
+
let entries;
|
|
111
|
+
try {
|
|
112
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
for (const entry of entries) {
|
|
118
|
+
const path = join(dir, entry.name);
|
|
119
|
+
if (entry.isDirectory()) {
|
|
120
|
+
if (!SKIP_DIR(entry.name))
|
|
121
|
+
walk(path);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (!entry.isFile() || !entry.name.endsWith(".md"))
|
|
125
|
+
continue;
|
|
126
|
+
if (entry.name === "index.md" || entry.name === "log.md")
|
|
127
|
+
continue;
|
|
128
|
+
let text;
|
|
129
|
+
try {
|
|
130
|
+
text = readFileSync(path, "utf8");
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const id = entry.name.slice(0, -".md".length);
|
|
136
|
+
if (!isCardText(text)) {
|
|
137
|
+
// Not a card, unless a review record beside it says it is one: then it is a card that does
|
|
138
|
+
// not parse (a whole-file conflict puts a marker on line 1), and its rows are kept.
|
|
139
|
+
if (existsSync(join(dir, `${id}.review.json`))) {
|
|
140
|
+
unreadable.push({ file: path, code: "card_invalid" });
|
|
141
|
+
}
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const card = parseCard(text, path);
|
|
146
|
+
const data = card.data;
|
|
147
|
+
found.push({
|
|
148
|
+
dir,
|
|
149
|
+
id,
|
|
150
|
+
title: data.title,
|
|
151
|
+
...(typeof data.description === "string" && { description: data.description }),
|
|
152
|
+
...((data.bible ?? data.lock?.bible) !== undefined && {
|
|
153
|
+
bible: String(data.bible ?? data.lock?.bible),
|
|
154
|
+
}),
|
|
155
|
+
...(typeof data.resource === "string" && { resource: data.resource }),
|
|
156
|
+
...(typeof data.lock?.sha256 === "string" && { sha256: data.lock.sha256 }),
|
|
157
|
+
...(typeof data.kind === "string" && { kind: data.kind }),
|
|
158
|
+
...(typeof data.subject === "string" && { subject: data.subject }),
|
|
159
|
+
...(typeof data.animationFamily === "string" && {
|
|
160
|
+
animationFamily: data.animationFamily,
|
|
161
|
+
}),
|
|
162
|
+
...(typeof data.action === "string" && { action: data.action }),
|
|
163
|
+
...(typeof data.facing === "string" && { facing: data.facing }),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// Not a card this build reads; `library check` reports it, and its folder's projections keep
|
|
168
|
+
// its rows as they are.
|
|
169
|
+
unreadable.push({ file: path, code: "card_invalid" });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
walk(root);
|
|
174
|
+
return { cards: found, unreadable };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The asset ids in `folder` whose rows a projection carries over as they are, because a file of
|
|
178
|
+
* theirs does not parse: the index's for an unreadable card, the log's for either file.
|
|
179
|
+
*/
|
|
180
|
+
function heldIds(unreadable, folder, projection) {
|
|
181
|
+
const ids = new Set();
|
|
182
|
+
for (const { file, code } of unreadable) {
|
|
183
|
+
if (dirname(file) !== folder || code === "index_invalid")
|
|
184
|
+
continue;
|
|
185
|
+
if (projection === "index" && code !== "card_invalid")
|
|
186
|
+
continue;
|
|
187
|
+
const name = basename(file);
|
|
188
|
+
ids.add(name.slice(0, -(code === "card_invalid" ? ".md" : ".review.json").length));
|
|
189
|
+
}
|
|
190
|
+
return ids;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The version checks of a hand-off: bytes of an older version exit 2 `version_exists`; a current
|
|
194
|
+
* version other than the one the pick confirmed replacing, or than the one a request_change was
|
|
195
|
+
* made on, exits 2 `version_changed`.
|
|
196
|
+
*/
|
|
197
|
+
function checkVersions(versions, assetId, expects) {
|
|
198
|
+
const current = versions.at(-1)?.sha256;
|
|
199
|
+
const { sha256 } = expects;
|
|
200
|
+
if (sha256 !== undefined)
|
|
201
|
+
olderVersionCheck(versions, sha256, assetId, expects.contentSha256);
|
|
202
|
+
if (expects.replaces !== undefined &&
|
|
203
|
+
sha256 !== current &&
|
|
204
|
+
(current ?? null) !== expects.replaces) {
|
|
205
|
+
throw new AssetIdError("version_changed", `asset "${assetId}" is now at ${current === undefined ? "no version" : `version ${versions.length} (sha256 ${current})`}, not the ${expects.replaces === null ? "empty asset" : `version ${expects.replaces}`} this pick confirmed replacing; pick again`);
|
|
206
|
+
}
|
|
207
|
+
if (expects.answers !== undefined && sha256 !== current && current !== expects.answers.version) {
|
|
208
|
+
throw changeVersionChanged(assetId, versions.length, current, expects.answers.version);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Checks the plan's versions again against the review record as it is now; the caller holds the
|
|
213
|
+
* library write lock, so a pick prepared before another committed cannot replace the same version.
|
|
214
|
+
*/
|
|
215
|
+
export async function recheckLibraryWrite(plan) {
|
|
216
|
+
const review = await readOwnReview(plan.reviewPath, plan.config.root, plan.dir, undefined);
|
|
217
|
+
checkVersions(review?.versions ?? [], plan.assetId, plan.expects);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Checks a hand-off's library write before anything is written: the asset id is not reserved
|
|
221
|
+
* (exit 2 `asset_id_reserved`) and not carded at another path (exit 2 `asset_conflict`), the
|
|
222
|
+
* media lies inside the library root, and the asset's own card and review record, when present,
|
|
223
|
+
* parse and name only paths inside the root.
|
|
224
|
+
*/
|
|
225
|
+
export async function prepareLibraryWrite(input) {
|
|
226
|
+
const config = libraryConfig(input.profile, input.targetDir);
|
|
227
|
+
const assetId = assetIdOf(input.spec);
|
|
228
|
+
if (assetId === "" || assetId === "." || assetId === ".." || /[/\\\0]/.test(assetId)) {
|
|
229
|
+
throw new InputError(`asset id "${assetId}" is not a plain name`);
|
|
230
|
+
}
|
|
231
|
+
if (RESERVED_IDS.includes(assetId.toLowerCase())) {
|
|
232
|
+
throw new AssetIdError("asset_id_reserved", `asset id "${assetId}" is reserved by the library (${RESERVED_IDS.join(", ")}); choose another`);
|
|
233
|
+
}
|
|
234
|
+
const dir = dirname(resolve(input.mediaPath));
|
|
235
|
+
if (!within(config.root, dir)) {
|
|
236
|
+
throw new InputError(`the media ${input.mediaPath} lies outside the library root ${config.root} (library.root)`);
|
|
237
|
+
}
|
|
238
|
+
const cards = scanCards(config.root);
|
|
239
|
+
const resource = basename(resolve(input.mediaPath));
|
|
240
|
+
const elsewhere = cards.find((card) => card.id === assetId &&
|
|
241
|
+
(card.dir !== dir || (card.resource !== undefined && card.resource !== resource)));
|
|
242
|
+
if (elsewhere) {
|
|
243
|
+
const at = join(elsewhere.dir, elsewhere.resource ?? `${assetId}.md`);
|
|
244
|
+
throw new AssetIdError("asset_conflict", `asset id "${assetId}" is already carded for ${at}; asset ids are unique per game`);
|
|
245
|
+
}
|
|
246
|
+
const cardPath = join(dir, `${assetId}.md`);
|
|
247
|
+
const reviewPath = join(dir, `${assetId}.review.json`);
|
|
248
|
+
const existingCard = await readOwnCard(cardPath, config.root, dir);
|
|
249
|
+
const vocabulary = checkedVocabulary(input.targetDir);
|
|
250
|
+
if (!existingCard && input.spec.fields?.["tags"] !== undefined)
|
|
251
|
+
editLabels(input.spec.fields["tags"], [], vocabulary);
|
|
252
|
+
const review = await readOwnReview(reviewPath, config.root, dir, undefined);
|
|
253
|
+
const lineage = input.sources?.map((source) => ({
|
|
254
|
+
relation: source.relation,
|
|
255
|
+
file: libraryRelative(config.root, source.path),
|
|
256
|
+
sha256: source.sha256,
|
|
257
|
+
}));
|
|
258
|
+
const sha256 = input.mediaBytes && sha256Hex(input.mediaBytes);
|
|
259
|
+
const expects = {
|
|
260
|
+
...(sha256 !== undefined && { sha256 }),
|
|
261
|
+
...(input.contentSha256 !== undefined && { contentSha256: input.contentSha256 }),
|
|
262
|
+
...(input.replaces !== undefined && { replaces: input.replaces }),
|
|
263
|
+
...(input.answers !== undefined && { answers: input.answers }),
|
|
264
|
+
};
|
|
265
|
+
checkVersions(review?.versions ?? [], assetId, expects);
|
|
266
|
+
const source = [input.provenancePath, input.manifestPath].find((path) => path !== undefined && within(config.root, resolve(path)));
|
|
267
|
+
return {
|
|
268
|
+
config,
|
|
269
|
+
assetId,
|
|
270
|
+
dir,
|
|
271
|
+
mediaPath: resolve(input.mediaPath),
|
|
272
|
+
cardPath,
|
|
273
|
+
reviewPath,
|
|
274
|
+
...(source !== undefined && { provenanceSource: resolve(source) }),
|
|
275
|
+
cards,
|
|
276
|
+
...(lineage?.length && { lineage }),
|
|
277
|
+
expects,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/** An editable source's `/`-separated path relative to the profile's library root; exit 2 outside it. */
|
|
281
|
+
export function libraryFile(profile, targetDir, path) {
|
|
282
|
+
return libraryRelative(libraryConfig(profile, targetDir).root, path);
|
|
283
|
+
}
|
|
284
|
+
/** The `/`-separated path of an editable source relative to the library root, compared by real path. */
|
|
285
|
+
function libraryRelative(root, path) {
|
|
286
|
+
const real = (p) => {
|
|
287
|
+
try {
|
|
288
|
+
return realpathSync.native(p);
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
return resolve(p);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const realRoot = real(root);
|
|
295
|
+
const rel = relative(realRoot, real(path)).split(sep).join("/");
|
|
296
|
+
try {
|
|
297
|
+
libraryPath(realRoot, realRoot, rel, "the editable source");
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
throw new InputError(`the editable source ${path} lies outside the library root ${root} (library.root); keep it inside the library so the version can record where it came from`);
|
|
301
|
+
}
|
|
302
|
+
return rel;
|
|
303
|
+
}
|
|
304
|
+
/** The error for a candidate made on a version that is no longer the asset's current one. */
|
|
305
|
+
export function changeVersionChanged(assetId, count, current, made) {
|
|
306
|
+
return new AssetIdError("version_changed", `asset "${assetId}" is now at ${current === undefined ? "no version" : `version ${count} (sha256 ${current})`}, not version ${made} this candidate was made on by request_change; request the change again on the current version`);
|
|
307
|
+
}
|
|
308
|
+
/** Bytes identical to a version other than the current one exit 2 `version_exists`. */
|
|
309
|
+
function olderVersionCheck(versions, sha256, assetId, contentSha256) {
|
|
310
|
+
// A signed image is new bytes each time it is signed: its content is what it was signed over.
|
|
311
|
+
const index = versions.findIndex((v) => v.sha256 === sha256 || (contentSha256 !== undefined && v.contentSha256 === contentSha256));
|
|
312
|
+
if (index !== -1 && index !== versions.length - 1) {
|
|
313
|
+
throw new AssetIdError("version_exists", `these bytes are version ${index + 1} of asset "${assetId}" (sha256 ${sha256}), not its current version ${versions.length}; a version is identified by its sha256, so it cannot be picked again as a new one`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/** The current version of a spec's asset in a target's library, read without writing. */
|
|
317
|
+
export async function currentVersion(profile, spec, targetDir) {
|
|
318
|
+
const config = libraryConfig(profile, targetDir);
|
|
319
|
+
const assetId = assetIdOf(spec);
|
|
320
|
+
const card = scanCards(config.root).find((c) => c.id === assetId);
|
|
321
|
+
if (!card)
|
|
322
|
+
return { assetId, outsideChange: false };
|
|
323
|
+
const review = await readOwnReview(join(card.dir, `${assetId}.review.json`), config.root, card.dir, undefined);
|
|
324
|
+
const versions = review?.versions ?? [];
|
|
325
|
+
let outsideChange = false;
|
|
326
|
+
if (card.resource !== undefined && card.sha256 !== undefined) {
|
|
327
|
+
const media = resolve(card.dir, card.resource);
|
|
328
|
+
if (within(config.root, media)) {
|
|
329
|
+
let bytes;
|
|
330
|
+
try {
|
|
331
|
+
bytes = new Uint8Array(await readFile(media));
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
bytes = undefined;
|
|
335
|
+
}
|
|
336
|
+
// A Git LFS pointer counts as present: its oid stands for the bytes (design section 1).
|
|
337
|
+
const held = bytes && (parseLfsPointer(bytes)?.oid ?? sha256Hex(bytes));
|
|
338
|
+
outsideChange = held !== card.sha256;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const last = versions.at(-1);
|
|
342
|
+
const sha256 = last?.sha256;
|
|
343
|
+
return {
|
|
344
|
+
assetId,
|
|
345
|
+
...(sha256 !== undefined && { sha256, version: versions.length }),
|
|
346
|
+
...(last?.run !== undefined && { run: last.run }),
|
|
347
|
+
...(last?.candidate !== undefined && { candidate: last.candidate }),
|
|
348
|
+
outsideChange,
|
|
349
|
+
...(card.resource !== undefined && { media: resolve(card.dir, card.resource) }),
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
export async function readText(path) {
|
|
353
|
+
try {
|
|
354
|
+
return await readFile(path, "utf8");
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
if (error.code === "ENOENT")
|
|
358
|
+
return undefined;
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
export async function readOwnCard(path, root, dir) {
|
|
363
|
+
const text = await readText(path);
|
|
364
|
+
if (text === undefined)
|
|
365
|
+
return undefined;
|
|
366
|
+
const card = parseCard(text, path);
|
|
367
|
+
checkCardPaths(card, root, dir, path);
|
|
368
|
+
return card;
|
|
369
|
+
}
|
|
370
|
+
export async function readOwnReview(path, root, dir, address) {
|
|
371
|
+
const text = await readText(path);
|
|
372
|
+
if (text === undefined)
|
|
373
|
+
return address === undefined ? undefined : emptyReview(address);
|
|
374
|
+
const record = parseReview(text, path);
|
|
375
|
+
checkReviewPaths(record, root, dir, path);
|
|
376
|
+
return record;
|
|
377
|
+
}
|
|
378
|
+
/** Writes `content` to a temporary file in the target's folder, then renames it over the target. */
|
|
379
|
+
export async function writeAtomic(path, content) {
|
|
380
|
+
await mkdir(dirname(path), { recursive: true });
|
|
381
|
+
const temporary = join(dirname(path), `.${basename(path)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
|
|
382
|
+
try {
|
|
383
|
+
await writeFile(temporary, content);
|
|
384
|
+
await rename(temporary, path);
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
await rm(temporary, { force: true });
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Writes `text` atomically unless the file already holds it, through `journal` when given (so it
|
|
393
|
+
* can be put back); whether it wrote.
|
|
394
|
+
*/
|
|
395
|
+
export async function writeIfChanged(path, text, journal) {
|
|
396
|
+
if ((await readText(path)) === text)
|
|
397
|
+
return false;
|
|
398
|
+
if (journal)
|
|
399
|
+
await journal.write(path, text);
|
|
400
|
+
else
|
|
401
|
+
await writeAtomic(path, text);
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
function relPosix(from, to) {
|
|
405
|
+
return relative(from, to).split(sep).join("/");
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* The candidate's annotations, retargeted at the asset: an object target's source becomes the
|
|
409
|
+
* media file and its version the new one, a reply or resolution follows the ids it names, and
|
|
410
|
+
* each mask or linked file is copied to `<assetId>.review/<sha256>.<ext>`.
|
|
411
|
+
*/
|
|
412
|
+
async function carryAnnotations(record, candidate, plan, resource, sha256, copies) {
|
|
413
|
+
const text = await readText(candidate.path);
|
|
414
|
+
if (text === undefined)
|
|
415
|
+
return record;
|
|
416
|
+
const source = parseReview(text, candidate.path);
|
|
417
|
+
const from = dirname(candidate.path);
|
|
418
|
+
const ids = new Map();
|
|
419
|
+
const copy = async (rel) => {
|
|
420
|
+
const path = libraryPath(candidate.root, from, rel, candidate.path);
|
|
421
|
+
const bytes = new Uint8Array(await readFile(path));
|
|
422
|
+
const name = `${plan.assetId}.review/${sha256Hex(bytes)}${extname(path).toLowerCase()}`;
|
|
423
|
+
copies.push([join(plan.dir, name), bytes]);
|
|
424
|
+
return name;
|
|
425
|
+
};
|
|
426
|
+
let next = record;
|
|
427
|
+
for (const annotation of source.annotations) {
|
|
428
|
+
const { id: oldId, ...content } = annotation;
|
|
429
|
+
const target = content.target;
|
|
430
|
+
if (typeof target === "string") {
|
|
431
|
+
content.target = ids.get(target) ?? (target.startsWith("#") ? target : resource);
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
const retargeted = { ...target, source: resource, "ag:version": sha256 };
|
|
435
|
+
if (target["ag:mask"] !== undefined)
|
|
436
|
+
retargeted["ag:mask"] = await copy(target["ag:mask"]);
|
|
437
|
+
content.target = retargeted;
|
|
438
|
+
}
|
|
439
|
+
const resolves = content["ag:resolves"];
|
|
440
|
+
if (resolves !== undefined)
|
|
441
|
+
content["ag:resolves"] = ids.get(resolves) ?? resolves;
|
|
442
|
+
if (content.body !== undefined) {
|
|
443
|
+
const parts = [content.body].flat();
|
|
444
|
+
const copied = [];
|
|
445
|
+
for (const part of parts) {
|
|
446
|
+
copied.push(part.type === "SpecificResource" ? { ...part, source: await copy(part.source) } : part);
|
|
447
|
+
}
|
|
448
|
+
content.body = Array.isArray(content.body) ? copied : copied[0];
|
|
449
|
+
}
|
|
450
|
+
ids.set(oldId, annotationId(content));
|
|
451
|
+
next = appendAnnotation(next, content);
|
|
452
|
+
}
|
|
453
|
+
return next;
|
|
454
|
+
}
|
|
455
|
+
const BIBLE_LINE = /^- (\d{2}:\d{2}:\d{2})Z bible (.*) → (.*)$/;
|
|
456
|
+
function unescapeText(text) {
|
|
457
|
+
return text.replace(/\\([\\[\]<>|])/g, "$1");
|
|
458
|
+
}
|
|
459
|
+
/** The `bible` lines of a log, oldest first. */
|
|
460
|
+
export function bibleLines(text) {
|
|
461
|
+
const lines = [];
|
|
462
|
+
let date;
|
|
463
|
+
for (const raw of (text ?? "").split(/\r?\n/)) {
|
|
464
|
+
const line = raw.trimEnd();
|
|
465
|
+
const heading = /^## (\d{4}-\d{2}-\d{2})$/.exec(line);
|
|
466
|
+
if (heading) {
|
|
467
|
+
date = heading[1];
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const match = date === undefined ? null : BIBLE_LINE.exec(line);
|
|
471
|
+
if (!match)
|
|
472
|
+
continue;
|
|
473
|
+
lines.push({
|
|
474
|
+
at: `${date}T${match[1]}Z`,
|
|
475
|
+
action: "bible",
|
|
476
|
+
from: unescapeText(match[2]),
|
|
477
|
+
to: unescapeText(match[3]),
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
return lines.sort((a, b) => Date.parse(a.at) - Date.parse(b.at));
|
|
481
|
+
}
|
|
482
|
+
export function newer(a, b) {
|
|
483
|
+
return a.localeCompare(b, "en", { numeric: true }) > 0;
|
|
484
|
+
}
|
|
485
|
+
async function prepareLibraryVersion(plan, input) {
|
|
486
|
+
const { config, assetId, dir } = plan;
|
|
487
|
+
const sha256 = sha256Hex(input.mediaBytes);
|
|
488
|
+
const resource = basename(plan.mediaPath);
|
|
489
|
+
const address = `asset://${config.game}/${assetId}/review`;
|
|
490
|
+
// Project the next version without writing, so preflight checks the exact card we commit.
|
|
491
|
+
let record = (await readOwnReview(plan.reviewPath, config.root, dir, address));
|
|
492
|
+
const copies = [];
|
|
493
|
+
if (input.candidateReview) {
|
|
494
|
+
record = await carryAnnotations(record, input.candidateReview, plan, resource, sha256, copies);
|
|
495
|
+
}
|
|
496
|
+
olderVersionCheck(record.versions, sha256, assetId, input.contentSha256);
|
|
497
|
+
// Read under the lock: what this write appends sorts after everything the record holds.
|
|
498
|
+
const at = nextStamp(record, input.now);
|
|
499
|
+
const appended = !record.versions.some((v) => v.sha256 === sha256);
|
|
500
|
+
if (appended) {
|
|
501
|
+
const first = record.versions.length === 0;
|
|
502
|
+
const confirmation = input.confirmation && {
|
|
503
|
+
method: input.confirmation.method,
|
|
504
|
+
digest: input.confirmation.digest,
|
|
505
|
+
...(input.confirmation.operator !== undefined && {
|
|
506
|
+
operator: input.confirmation.operator,
|
|
507
|
+
}),
|
|
508
|
+
...(input.confirmation.delegatedBy !== undefined && {
|
|
509
|
+
delegatedBy: input.confirmation.delegatedBy,
|
|
510
|
+
}),
|
|
511
|
+
};
|
|
512
|
+
const editing = new Set(record.annotations.filter((a) => a.motivation === "editing").map((a) => a.id));
|
|
513
|
+
const answers = (input.answers ?? []).filter((id) => editing.has(id));
|
|
514
|
+
record = appendVersion(record, {
|
|
515
|
+
sha256,
|
|
516
|
+
...(answers.length > 0 && { answers }),
|
|
517
|
+
...(input.provenanceBytes !== undefined && {
|
|
518
|
+
provenanceSha256: sha256Hex(input.provenanceBytes),
|
|
519
|
+
}),
|
|
520
|
+
...(input.contentSha256 !== undefined && { contentSha256: input.contentSha256 }),
|
|
521
|
+
...(plan.lineage !== undefined && { lineage: plan.lineage }),
|
|
522
|
+
run: input.run,
|
|
523
|
+
candidate: input.candidate,
|
|
524
|
+
at,
|
|
525
|
+
...(confirmation && { confirmation }),
|
|
526
|
+
...(input.digitalSourceType !== undefined && { digitalSourceType: input.digitalSourceType }),
|
|
527
|
+
});
|
|
528
|
+
record = appendAnnotation(record, {
|
|
529
|
+
type: "Annotation",
|
|
530
|
+
motivation: "moderating",
|
|
531
|
+
created: at,
|
|
532
|
+
target: { source: resource, "ag:version": sha256 },
|
|
533
|
+
"ag:action": answers.length > 0 ? "answer" : (input.action ?? (first ? "pick" : "replace")),
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
else if (plan.lineage !== undefined) {
|
|
537
|
+
// A source edit that renders the same media (another tag, a timing change) appends nothing,
|
|
538
|
+
// but the version now derives from the edited bytes: record them, so the source is not listed
|
|
539
|
+
// as changed against a version it still matches.
|
|
540
|
+
record = updateVersionLineage(record, sha256, plan.lineage);
|
|
541
|
+
}
|
|
542
|
+
// 4. The card: machine fields from the records; person fields set once, then kept.
|
|
543
|
+
const fields = machineFields({
|
|
544
|
+
resource,
|
|
545
|
+
provenance: input.provenance,
|
|
546
|
+
media: measureMediaBytes(input.mediaBytes, sha256),
|
|
547
|
+
...(plan.provenanceSource !== undefined && {
|
|
548
|
+
provenanceResource: relPosix(dir, plan.provenanceSource),
|
|
549
|
+
}),
|
|
550
|
+
review: record,
|
|
551
|
+
reviewResource: `${assetId}.review.json`,
|
|
552
|
+
kind: input.spec.kind,
|
|
553
|
+
subject: input.spec.subject ?? input.spec.assetId,
|
|
554
|
+
...(input.spec.animationFamily !== undefined && {
|
|
555
|
+
animationFamily: input.spec.animationFamily,
|
|
556
|
+
}),
|
|
557
|
+
...(input.spec.action !== undefined && { action: input.spec.action }),
|
|
558
|
+
...(input.spec.facing !== undefined && { facing: input.spec.facing }),
|
|
559
|
+
...musicFields(input.spec),
|
|
560
|
+
assetgrove: input.assetgrove,
|
|
561
|
+
...(input.storage !== undefined && { storage: input.storage }),
|
|
562
|
+
});
|
|
563
|
+
const existing = await readOwnCard(plan.cardPath, config.root, dir);
|
|
564
|
+
const extra = input.spec.fields ?? {};
|
|
565
|
+
const tags = extra["tags"];
|
|
566
|
+
const base = existing
|
|
567
|
+
? rewriteMachineFields(existing, fields, plan.cardPath)
|
|
568
|
+
: newCard({
|
|
569
|
+
title: typeof extra["title"] === "string" ? extra["title"] : assetId,
|
|
570
|
+
...(typeof extra["description"] === "string" && { description: extra["description"] }),
|
|
571
|
+
...(Array.isArray(tags) &&
|
|
572
|
+
tags.every((tag) => typeof tag === "string") && {
|
|
573
|
+
tags: editLabels(tags, [], checkedVocabulary(dir)),
|
|
574
|
+
}),
|
|
575
|
+
}, fields);
|
|
576
|
+
const summary = input.summary;
|
|
577
|
+
const card = summary !== undefined && summaryState(base.data).state !== "person"
|
|
578
|
+
? applySummary(base, { description: summary.description, tags: summary.tags }, summaryEntry(summary, summary.operation, summary.model, at), plan.cardPath)
|
|
579
|
+
: base;
|
|
580
|
+
return { record, copies, at, appended, card };
|
|
581
|
+
}
|
|
582
|
+
/** A `music` spec's form and requested tempo (its loop's bpm, else its bpm), for the card. */
|
|
583
|
+
function musicFields(spec) {
|
|
584
|
+
const music = spec;
|
|
585
|
+
if (music.kind !== "music")
|
|
586
|
+
return {};
|
|
587
|
+
const tempo = [music.loop?.bpm, music.bpm].find((v) => typeof v === "number");
|
|
588
|
+
return {
|
|
589
|
+
...(typeof music.form === "string" && { form: music.form }),
|
|
590
|
+
...(typeof tempo === "number" && { tempo }),
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
export async function checkLibraryRules(plan, input, rules) {
|
|
594
|
+
if (!rules?.length)
|
|
595
|
+
return [];
|
|
596
|
+
const { card } = await prepareLibraryVersion(plan, input);
|
|
597
|
+
const findings = evaluateProjectRules({
|
|
598
|
+
rules,
|
|
599
|
+
asset: plan.assetId,
|
|
600
|
+
spec: input.spec,
|
|
601
|
+
card: card.data,
|
|
602
|
+
media: measuredRuleMedia(input.mediaBytes),
|
|
603
|
+
});
|
|
604
|
+
enforceProjectRules(findings);
|
|
605
|
+
return findings;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Appends the version to the review record (the commit point), then writes the card, each
|
|
609
|
+
* `index.md` from the library root down, and the folder's `log.md` unless the profile turns logs
|
|
610
|
+
* off. The caller holds the library write lock and has written the media and provenance.
|
|
611
|
+
*/
|
|
612
|
+
export async function commitLibraryWrite(plan, input, journal) {
|
|
613
|
+
const { config, assetId, dir } = plan;
|
|
614
|
+
const files = [];
|
|
615
|
+
const { record, copies, at, appended, card } = await prepareLibraryVersion(plan, input);
|
|
616
|
+
for (const [path, bytes] of copies) {
|
|
617
|
+
if (!existsSync(path)) {
|
|
618
|
+
if (journal)
|
|
619
|
+
await journal.write(path, bytes);
|
|
620
|
+
else
|
|
621
|
+
await writeAtomic(path, bytes);
|
|
622
|
+
files.push(path);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
if (await writeIfChanged(plan.reviewPath, writeReview(record), journal))
|
|
626
|
+
files.push(plan.reviewPath);
|
|
627
|
+
if (await writeIfChanged(plan.cardPath, writeCard(card), journal))
|
|
628
|
+
files.push(plan.cardPath);
|
|
629
|
+
const title = card.data.title;
|
|
630
|
+
// 5. Each index.md from the library root down.
|
|
631
|
+
const { cards, unreadable } = scanLibrary(config.root);
|
|
632
|
+
files.push(...(await writeIndexes(config, cards, unreadable, journal)));
|
|
633
|
+
files.push(...(await writeCredits(config, cards, journal)));
|
|
634
|
+
// 6. log.md, projected from the review records, unless logs are off.
|
|
635
|
+
if (config.log) {
|
|
636
|
+
files.push(...(await writeLogs(config, cards, {
|
|
637
|
+
dir,
|
|
638
|
+
assetId,
|
|
639
|
+
title,
|
|
640
|
+
record,
|
|
641
|
+
at,
|
|
642
|
+
bibleVersion: input.provenance.bibleVersion,
|
|
643
|
+
before: plan.cards,
|
|
644
|
+
}, unreadable, journal)));
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
assetId,
|
|
648
|
+
version: versionNumber(record, record.versions.at(-1).sha256),
|
|
649
|
+
sha256: record.versions.at(-1).sha256,
|
|
650
|
+
state: versionStatus(record, record.versions.at(-1).sha256),
|
|
651
|
+
appended,
|
|
652
|
+
files,
|
|
653
|
+
...(unreadable.length > 0 && { unreadable }),
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* The existing library files `commitLibraryWrite` may rewrite for `plan`: the review record, the
|
|
658
|
+
* card, each folder's `index.md` from the library root down to every card and to the asset, and
|
|
659
|
+
* the asset folder's and the root's `log.md` when logs are on. An adopt reads each before its
|
|
660
|
+
* first write, so one it cannot read stops it there.
|
|
661
|
+
*/
|
|
662
|
+
export function libraryWritePaths(plan) {
|
|
663
|
+
const { config } = plan;
|
|
664
|
+
const folders = new Set([config.root]);
|
|
665
|
+
for (const dir of [plan.dir, ...plan.cards.map((card) => card.dir)]) {
|
|
666
|
+
for (let folder = dir; within(config.root, folder); folder = dirname(folder)) {
|
|
667
|
+
folders.add(folder);
|
|
668
|
+
if (folder === config.root)
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const paths = [plan.reviewPath, plan.cardPath];
|
|
673
|
+
for (const folder of [...folders].sort())
|
|
674
|
+
paths.push(join(folder, "index.md"));
|
|
675
|
+
if (config.log)
|
|
676
|
+
paths.push(join(plan.dir, "log.md"), join(config.root, "log.md"));
|
|
677
|
+
paths.push(join(config.root, CREDITS_JSON), join(config.root, CREDITS_MD));
|
|
678
|
+
return [...new Set(paths)];
|
|
679
|
+
}
|
|
680
|
+
/** Writes the library's credits report (`credits.report.json`, `credits.report.md`) from its cards; the files it changed. */
|
|
681
|
+
export async function writeCredits(config, cards, journal) {
|
|
682
|
+
const report = currentCredits(config, cards);
|
|
683
|
+
const files = [];
|
|
684
|
+
for (const [name, text] of [
|
|
685
|
+
[CREDITS_JSON, renderCreditsJson(report)],
|
|
686
|
+
[CREDITS_MD, renderCreditsMarkdown(report)],
|
|
687
|
+
]) {
|
|
688
|
+
const path = join(config.root, name);
|
|
689
|
+
if (await writeIfChanged(path, text, journal))
|
|
690
|
+
files.push(path);
|
|
691
|
+
}
|
|
692
|
+
return files;
|
|
693
|
+
}
|
|
694
|
+
/** Writes each `index.md` from the library root down to every card; the files it changed. */
|
|
695
|
+
export async function writeIndexes(config, cards, unreadable = [], journal) {
|
|
696
|
+
const files = [];
|
|
697
|
+
const folders = new Set([config.root]);
|
|
698
|
+
const held = unreadable.filter((u) => u.code === "card_invalid").map((u) => dirname(u.file));
|
|
699
|
+
for (const dir of [...cards.map((c) => c.dir), ...held]) {
|
|
700
|
+
for (let folder = dir; within(config.root, folder); folder = dirname(folder)) {
|
|
701
|
+
folders.add(folder);
|
|
702
|
+
if (folder === config.root)
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
for (const folder of [...folders].sort()) {
|
|
707
|
+
const isRoot = folder === config.root;
|
|
708
|
+
const path = join(folder, "index.md");
|
|
709
|
+
// A card that does not parse keeps the row the index has for it.
|
|
710
|
+
const kept = indexAssetsFor(await readText(path), heldIds(unreadable, folder, "index"));
|
|
711
|
+
if (kept === undefined) {
|
|
712
|
+
// The rows of an unreadable card are in an index that does not parse either: rewritten, the
|
|
713
|
+
// index would lose them, so it is left as it is and reported.
|
|
714
|
+
unreadable.push({ file: path, code: "index_invalid" });
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
const text = renderIndex({
|
|
718
|
+
name: isRoot ? config.game : basename(folder),
|
|
719
|
+
...(isRoot && { root: { game: config.game } }),
|
|
720
|
+
folders: [...folders]
|
|
721
|
+
.filter((f) => f !== folder && dirname(f) === folder)
|
|
722
|
+
.map((f) => basename(f)),
|
|
723
|
+
assets: cards
|
|
724
|
+
.filter((c) => c.dir === folder)
|
|
725
|
+
.map((c) => ({
|
|
726
|
+
id: c.id,
|
|
727
|
+
title: c.title,
|
|
728
|
+
...(c.description !== undefined && { description: c.description }),
|
|
729
|
+
}))
|
|
730
|
+
.concat(kept),
|
|
731
|
+
});
|
|
732
|
+
if (await writeIfChanged(path, text, journal))
|
|
733
|
+
files.push(path);
|
|
734
|
+
}
|
|
735
|
+
return files;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Writes the asset folder's `log.md` from the review records of the cards in it, and the root log
|
|
739
|
+
* when a `bible` line is added (it keeps its `bible` lines); the files it changed. A card or review
|
|
740
|
+
* record that does not parse keeps the lines the log has for its asset: each review record found
|
|
741
|
+
* unreadable here is added to `unreadable`.
|
|
742
|
+
*/
|
|
743
|
+
export async function writeLogs(config, cards, subject, unreadable = [], journal) {
|
|
744
|
+
const files = [];
|
|
745
|
+
const { dir, assetId, title, record, at } = subject;
|
|
746
|
+
const rootLog = join(config.root, "log.md");
|
|
747
|
+
const bible = bibleLines(await readText(rootLog));
|
|
748
|
+
const baseline = bible.at(-1)?.to ??
|
|
749
|
+
subject.before
|
|
750
|
+
.map((c) => c.bible)
|
|
751
|
+
.filter((v) => v !== undefined)
|
|
752
|
+
.reduce((max, v) => (max === undefined || newer(v, max) ? v : max), undefined);
|
|
753
|
+
const current = subject.bibleVersion;
|
|
754
|
+
const bibleChanged = baseline !== undefined && current !== undefined && newer(current, baseline);
|
|
755
|
+
if (bibleChanged)
|
|
756
|
+
bible.push({ at, action: "bible", from: baseline, to: current });
|
|
757
|
+
const logFolders = new Set([dir]);
|
|
758
|
+
if (bibleChanged)
|
|
759
|
+
logFolders.add(config.root);
|
|
760
|
+
for (const folder of logFolders) {
|
|
761
|
+
const entries = folder === config.root ? [...bible] : [];
|
|
762
|
+
for (const found of cards.filter((c) => c.dir === folder)) {
|
|
763
|
+
const own = found.id === assetId && folder === dir;
|
|
764
|
+
let review = own ? record : undefined;
|
|
765
|
+
if (!review) {
|
|
766
|
+
const reviewPath = join(folder, `${found.id}.review.json`);
|
|
767
|
+
try {
|
|
768
|
+
review = await readOwnReview(reviewPath, config.root, folder, undefined);
|
|
769
|
+
}
|
|
770
|
+
catch {
|
|
771
|
+
unreadable.push({ file: reviewPath, code: "review_invalid" });
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
if (review) {
|
|
776
|
+
entries.push(...logEntriesFromReview(review, { id: found.id, title: own ? title : found.title }));
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
const path = join(folder, "log.md");
|
|
780
|
+
const kept = logLinesFor(await readText(path), heldIds(unreadable, folder, "log"));
|
|
781
|
+
if (await writeIfChanged(path, renderLog(entries, kept), journal))
|
|
782
|
+
files.push(path);
|
|
783
|
+
}
|
|
784
|
+
return files;
|
|
785
|
+
}
|
|
786
|
+
/** This build's package version, for the card's `generated.by`. */
|
|
787
|
+
export function assetgroveVersion() {
|
|
788
|
+
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
789
|
+
return pkg.version;
|
|
790
|
+
}
|