@playcraft/cli 0.1.54 → 0.1.55-beta
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/README.md +83 -15
- package/SKILLS_REGISTRY.md +149 -0
- package/dist/agent/local-backend.js +1 -1
- package/dist/assets/client.js +157 -0
- package/dist/assets/messages.js +48 -0
- package/dist/auth/account-activation.js +157 -0
- package/dist/auth/messages.js +30 -0
- package/dist/cli-root-help.js +4 -0
- package/dist/commands/assets.js +123 -0
- package/dist/commands/build-all.js +5 -19
- package/dist/commands/build-temp.js +26 -0
- package/dist/commands/build.js +15 -28
- package/dist/commands/create.js +26 -33
- package/dist/commands/image-layer-messages.js +37 -0
- package/dist/commands/image-layer-tools.js +185 -0
- package/dist/commands/image.js +2 -73
- package/dist/commands/library-messages.js +46 -0
- package/dist/commands/library.js +130 -0
- package/dist/commands/login.js +84 -42
- package/dist/commands/platform-skills.generated.js +19 -0
- package/dist/commands/playable.js +53 -0
- package/dist/commands/preview-runtime.js +21 -0
- package/dist/commands/skills.js +4 -0
- package/dist/commands/tools-3d.js +11 -0
- package/dist/commands/tools-batch.js +113 -0
- package/dist/commands/tools-generation.js +6 -0
- package/dist/commands/tools.js +2 -0
- package/dist/commands/video.js +122 -0
- package/dist/commands/workspace-runtime.js +54 -0
- package/dist/commands/workspace.js +40 -0
- package/dist/config.js +59 -4
- package/dist/index.js +47 -3
- package/dist/preview-runtime/distribution.js +77 -0
- package/dist/project-skills/builtin-import.js +225 -0
- package/dist/project-skills/commands.js +77 -0
- package/dist/project-skills/lifecycle.js +28 -0
- package/dist/project-skills/local-run.js +112 -0
- package/dist/project-skills/local-store.js +221 -0
- package/dist/project-skills/messages.js +80 -0
- package/dist/project-skills/reconcile.js +62 -0
- package/dist/project-skills/remote-cache.js +51 -0
- package/dist/project-skills/validation.js +19 -0
- package/dist/recording/messages.js +40 -0
- package/dist/recording/project-digest.js +85 -0
- package/dist/recording/recorder.js +293 -0
- package/dist/recording/scenario.js +50 -0
- package/dist/remix/clone.js +2 -0
- package/dist/remix/init-template.js +2 -0
- package/dist/remix/pull.js +2 -0
- package/dist/remix/push.js +21 -1
- package/dist/skill-registry/client.js +345 -0
- package/dist/skill-registry/commands.js +180 -0
- package/dist/skill-registry/evaluation-client.js +156 -0
- package/dist/skill-registry/evaluation-commands.js +174 -0
- package/dist/skill-registry/messages.js +177 -0
- package/dist/skill-registry/package.js +275 -0
- package/dist/skill-registry/platform-package.js +100 -0
- package/dist/utils/agent-api-client.js +245 -30
- package/dist/utils/environment-endpoints.js +17 -0
- package/dist/utils/error-diagnostics.js +20 -0
- package/dist/utils/playcraft-http-client.js +6 -4
- package/dist/utils/tool-operation-journal.js +124 -0
- package/dist/utils/video-evidence-git.js +81 -0
- package/dist/video-replication/client.js +234 -0
- package/dist/video-replication/comparison-evidence.js +149 -0
- package/dist/video-replication/comparison-files.js +57 -0
- package/dist/video-replication/comparison-log.js +72 -0
- package/dist/video-replication/comparison-messages.js +104 -0
- package/dist/video-replication/comparison-output.js +63 -0
- package/dist/video-replication/comparison-preflight.js +66 -0
- package/dist/video-replication/comparison.js +230 -0
- package/dist/video-replication/diagnostics.js +41 -0
- package/dist/video-replication/evidence.js +165 -0
- package/dist/video-replication/media.js +112 -0
- package/dist/video-replication/messages.js +97 -0
- package/dist/workspace/messages.js +67 -0
- package/dist/workspace/transfer-client.js +237 -0
- package/dist/workspace/transfer-errors.js +48 -0
- package/dist/workspace-runtime/batch/content-changes.js +30 -0
- package/dist/workspace-runtime/batch/control.js +86 -0
- package/dist/workspace-runtime/batch/deliver.js +173 -0
- package/dist/workspace-runtime/batch/freeze.js +101 -0
- package/dist/workspace-runtime/batch/generate.js +249 -0
- package/dist/workspace-runtime/batch/git.js +40 -0
- package/dist/workspace-runtime/batch/occupancy.js +8 -0
- package/dist/workspace-runtime/batch/policy.js +70 -0
- package/dist/workspace-runtime/batch/prepare.js +317 -0
- package/dist/workspace-runtime/batch/processes.js +72 -0
- package/dist/workspace-runtime/batch/records.js +113 -0
- package/dist/workspace-runtime/batch/routes.js +61 -0
- package/dist/workspace-runtime/batch/source-candidate.js +86 -0
- package/dist/workspace-runtime/batch/source-capture.js +146 -0
- package/dist/workspace-runtime/batch/source-failure.js +43 -0
- package/dist/workspace-runtime/batch/source-publish.js +130 -0
- package/dist/workspace-runtime/codex/app-server.js +1065 -0
- package/dist/workspace-runtime/codex/compact.js +46 -0
- package/dist/workspace-runtime/codex/config-toml.js +107 -0
- package/dist/workspace-runtime/codex/delivery-tools.js +144 -0
- package/dist/workspace-runtime/codex/jsonrpc-stdio.js +145 -0
- package/dist/workspace-runtime/codex/launcher-client.js +177 -0
- package/dist/workspace-runtime/codex/loopback.js +146 -0
- package/dist/workspace-runtime/codex/mcp-config.js +39 -0
- package/dist/workspace-runtime/codex/model-broker.js +263 -0
- package/dist/workspace-runtime/codex/native-adapter.js +9 -0
- package/dist/workspace-runtime/codex/permissions.js +79 -0
- package/dist/workspace-runtime/codex/thread-image.js +38 -0
- package/dist/workspace-runtime/codex/tool-response.js +10 -0
- package/dist/workspace-runtime/codex/ui-instructions.js +4 -0
- package/dist/workspace-runtime/codex/ui-tools.js +203 -0
- package/dist/workspace-runtime/codex/work-mode.js +15 -0
- package/dist/workspace-runtime/main.js +10 -0
- package/dist/workspace-runtime/persistence/journal.js +365 -0
- package/dist/workspace-runtime/persistence/native-subagents.js +162 -0
- package/dist/workspace-runtime/persistence/sqlite-client.js +77 -0
- package/dist/workspace-runtime/persistence/sqlite-worker.js +1161 -0
- package/dist/workspace-runtime/persistence/stopped-execution.js +77 -0
- package/dist/workspace-runtime/previews/diagnostics.js +44 -0
- package/dist/workspace-runtime/previews/output.js +36 -0
- package/dist/workspace-runtime/previews/publish.js +283 -0
- package/dist/workspace-runtime/previews/runtime-preview.js +251 -0
- package/dist/workspace-runtime/previews/single-file.js +43 -0
- package/dist/workspace-runtime/processes/managed-writes.js +69 -0
- package/dist/workspace-runtime/serve.js +441 -0
- package/dist/workspace-runtime/server/accept-operation.js +61 -0
- package/dist/workspace-runtime/server/asset-transfers.js +63 -0
- package/dist/workspace-runtime/server/auth.js +21 -0
- package/dist/workspace-runtime/server/connectivity.js +211 -0
- package/dist/workspace-runtime/server/desktop-host.js +429 -0
- package/dist/workspace-runtime/server/desktop-preview-config.js +81 -0
- package/dist/workspace-runtime/server/desktop-preview-service.js +157 -0
- package/dist/workspace-runtime/server/desktop-preview-static.js +53 -0
- package/dist/workspace-runtime/server/desktop-preview.js +189 -0
- package/dist/workspace-runtime/server/dispatch.js +1655 -0
- package/dist/workspace-runtime/server/endpoints.js +21 -0
- package/dist/workspace-runtime/server/execution-group.js +90 -0
- package/dist/workspace-runtime/server/http.js +1363 -0
- package/dist/workspace-runtime/server/lock.js +53 -0
- package/dist/workspace-runtime/server/operation-record.js +33 -0
- package/dist/workspace-runtime/server/rfb-watch-gate.js +168 -0
- package/dist/workspace-runtime/server/session-restore.js +84 -0
- package/dist/workspace-runtime/server/source-uploader.js +138 -0
- package/dist/workspace-runtime/server/submit-operation.js +41 -0
- package/dist/workspace-runtime/server/terminal-host.js +366 -0
- package/dist/workspace-runtime/server/types.js +1 -0
- package/dist/workspace-runtime/server/workspace-transfer.js +168 -0
- package/dist/workspace-runtime/verify-artifact.js +59 -0
- package/dist/workspace-runtime/workspaces/append-only-log.js +62 -0
- package/dist/workspace-runtime/workspaces/archive.js +207 -0
- package/dist/workspace-runtime/workspaces/artifact-events.js +55 -0
- package/dist/workspace-runtime/workspaces/artifact-files.js +199 -0
- package/dist/workspace-runtime/workspaces/artifact-receipts.js +89 -0
- package/dist/workspace-runtime/workspaces/artifacts.js +282 -0
- package/dist/workspace-runtime/workspaces/asset-library-import.js +387 -0
- package/dist/workspace-runtime/workspaces/asset-publication-access.js +25 -0
- package/dist/workspace-runtime/workspaces/asset-transfer-dependencies.js +81 -0
- package/dist/workspace-runtime/workspaces/asset-transfer-publish.js +438 -0
- package/dist/workspace-runtime/workspaces/asset-transfer-storage.js +389 -0
- package/dist/workspace-runtime/workspaces/attachment-content.js +73 -0
- package/dist/workspace-runtime/workspaces/attachments.js +185 -0
- package/dist/workspace-runtime/workspaces/batch-commit.js +142 -0
- package/dist/workspace-runtime/workspaces/binary-content.js +65 -0
- package/dist/workspace-runtime/workspaces/binary-write.js +117 -0
- package/dist/workspace-runtime/workspaces/cli-context.js +23 -0
- package/dist/workspace-runtime/workspaces/cli-credentials.js +115 -0
- package/dist/workspace-runtime/workspaces/composer-context.js +147 -0
- package/dist/workspace-runtime/workspaces/context-error.js +2 -0
- package/dist/workspace-runtime/workspaces/delivery-build.js +331 -0
- package/dist/workspace-runtime/workspaces/delivery-store.js +168 -0
- package/dist/workspace-runtime/workspaces/delivery.js +64 -0
- package/dist/workspace-runtime/workspaces/dependencies.js +279 -0
- package/dist/workspace-runtime/workspaces/developer-command.js +98 -0
- package/dist/workspace-runtime/workspaces/directories.js +135 -0
- package/dist/workspace-runtime/workspaces/directory-access.js +37 -0
- package/dist/workspace-runtime/workspaces/directory-attachments.js +245 -0
- package/dist/workspace-runtime/workspaces/directory-create.js +57 -0
- package/dist/workspace-runtime/workspaces/directory-maintenance.js +111 -0
- package/dist/workspace-runtime/workspaces/directory-mutations.js +238 -0
- package/dist/workspace-runtime/workspaces/directory-revisions.js +56 -0
- package/dist/workspace-runtime/workspaces/directory-stats.js +49 -0
- package/dist/workspace-runtime/workspaces/disk-snapshot.js +31 -0
- package/dist/workspace-runtime/workspaces/empty-template.js +43 -0
- package/dist/workspace-runtime/workspaces/file-content.js +48 -0
- package/dist/workspace-runtime/workspaces/files-search.js +116 -0
- package/dist/workspace-runtime/workspaces/files.js +150 -0
- package/dist/workspace-runtime/workspaces/git-credential-broker.js +312 -0
- package/dist/workspace-runtime/workspaces/git-credential-helper.js +68 -0
- package/dist/workspace-runtime/workspaces/git-direct-store.js +155 -0
- package/dist/workspace-runtime/workspaces/git.js +670 -0
- package/dist/workspace-runtime/workspaces/instructions.js +56 -0
- package/dist/workspace-runtime/workspaces/json5-edit.js +313 -0
- package/dist/workspace-runtime/workspaces/library-attachments.js +268 -0
- package/dist/workspace-runtime/workspaces/operation-log.js +23 -0
- package/dist/workspace-runtime/workspaces/optional-platform-skills.js +14 -0
- package/dist/workspace-runtime/workspaces/parameter-agent-inputs.js +97 -0
- package/dist/workspace-runtime/workspaces/parameter-agent-protocol.js +40 -0
- package/dist/workspace-runtime/workspaces/parameter-agent-store.js +58 -0
- package/dist/workspace-runtime/workspaces/parameter-agent.js +284 -0
- package/dist/workspace-runtime/workspaces/parameter-assets.js +189 -0
- package/dist/workspace-runtime/workspaces/parameters.js +329 -0
- package/dist/workspace-runtime/workspaces/prepare.js +284 -0
- package/dist/workspace-runtime/workspaces/registry.js +251 -0
- package/dist/workspace-runtime/workspaces/remix-references.js +301 -0
- package/dist/workspace-runtime/workspaces/revisions.js +31 -0
- package/dist/workspace-runtime/workspaces/session-image.js +104 -0
- package/dist/workspace-runtime/workspaces/shared-git.js +40 -0
- package/dist/workspace-runtime/workspaces/skill-artifact-loader.js +95 -0
- package/dist/workspace-runtime/workspaces/skills.js +191 -0
- package/dist/workspace-runtime/workspaces/theme-asset-index.js +157 -0
- package/dist/workspace-runtime/workspaces/transfer-quota.js +69 -0
- package/dist/workspace-runtime/workspaces/transfer.js +471 -0
- package/dist/workspace-runtime/workspaces/turn-changes.js +75 -0
- package/dist/workspace-runtime/workspaces/video-attachments.js +49 -0
- package/dist/workspace-runtime/workspaces/worktree-attachments.js +74 -0
- package/dist/workspace-runtime/workspaces/worktree-checkout.js +67 -0
- package/dist/workspace-runtime/workspaces/worktrees.js +73 -0
- package/package.json +16 -5
- package/project-template/.claude/skills/playcraft-audio-generation/SKILL.md +31 -4
- package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +36 -5
- package/project-template/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +1 -1
- package/project-template/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +1 -1
- package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +1 -1
- package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +1 -1
- package/project-template/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +1 -1
- package/project-template/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +1 -1
- package/project-template/.claude/skills/playcraft-image-generation/reference/ta-image-generation-detail.md +300 -0
- package/project-template/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +1 -1
- package/project-template/.claude/skills/playcraft-image-processing/SKILL.md +50 -25
- package/project-template/.claude/skills/playcraft-replica-validation/SKILL.md +25 -0
- package/project-template/.claude/skills/playcraft-replica-validation/references/contracts.md +79 -0
- package/project-template/.claude/skills/playcraft-video-understanding/SKILL.md +29 -0
- package/project-template/.claude/skills/playcraft-video-understanding/references/contracts.md +37 -0
- package/project-template/.claude/skills/playcraft-workspace-assets/SKILL.md +53 -0
- package/project-template/.claude/skills/playcraft-workspace-assets/references/requests.json +32 -0
- package/project-template-v2/.claude/agents/artist.md +82 -0
- package/project-template-v2/.claude/agents/developer.md +153 -0
- package/project-template-v2/.claude/agents/game-designer.md +264 -0
- package/project-template-v2/.claude/agents/refs/artist-art-style-catalog.md +533 -0
- package/project-template-v2/.claude/agents/refs/artist-color-audio-recipes.md +153 -0
- package/project-template-v2/.claude/agents/refs/artist-dimension-axis.md +27 -0
- package/project-template-v2/.claude/agents/refs/artist-master-composite-recipes.md +208 -0
- package/project-template-v2/.claude/agents/refs/atom-skill-library.md +81 -0
- package/project-template-v2/.claude/agents/refs/developer-impl-cookbook.md +432 -0
- package/project-template-v2/.claude/agents/refs/framework-5-component-filter.md +252 -0
- package/project-template-v2/.claude/agents/refs/framework-game-feel-juice.md +266 -0
- package/project-template-v2/.claude/agents/refs/framework-mda.md +147 -0
- package/project-template-v2/.claude/agents/refs/game-designer-gameplay-sufficiency.md +123 -0
- package/project-template-v2/.claude/agents/refs/ta-3d-flip-recipe.md +88 -0
- package/project-template-v2/.claude/agents/refs/ta-atlas-deliverable-standard.md +67 -0
- package/project-template-v2/.claude/agents/refs/ta-batch-pipeline-recipes.md +120 -0
- package/project-template-v2/.claude/agents/refs/ta-image-generation-detail.md +300 -0
- package/project-template-v2/.claude/agents/refs/ta-image-ops-reference.md +495 -0
- package/project-template-v2/.claude/agents/refs/ta-pipeline-cookbook.md +1141 -0
- package/project-template-v2/.claude/agents/refs/ta-tools-reference.md +111 -0
- package/project-template-v2/.claude/agents/refs/ta-vfx-preset-catalog.md +365 -0
- package/project-template-v2/.claude/agents/refs/threejs-cannon-pitfalls.md +412 -0
- package/project-template-v2/.claude/agents/reviewer.md +75 -0
- package/project-template-v2/.claude/agents/technical-artist.md +86 -0
- package/project-template-v2/.claude/hooks/snapshot-milestone.mjs +243 -0
- package/project-template-v2/.claude/hooks/user-prompt.mjs +133 -0
- package/project-template-v2/.claude/settings.json +33 -0
- package/project-template-v2/.claude/skills/brainstorming/SKILL.md +161 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/frame-template.html +270 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/helper.js +177 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/server.cjs +354 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/start-server.sh +148 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/stop-server.sh +56 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/wait-for-selection.sh +62 -0
- package/project-template-v2/.claude/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/project-template-v2/.claude/skills/brainstorming/visual-companion.md +309 -0
- package/project-template-v2/.claude/skills/playcraft-ad-psychology/SKILL.md +182 -0
- package/project-template-v2/.claude/skills/playcraft-art-style-guide/SKILL.md +123 -0
- package/project-template-v2/.claude/skills/playcraft-asset-state-sheet/SKILL.md +205 -0
- package/project-template-v2/.claude/skills/playcraft-audio-generation/SKILL.md +307 -0
- package/project-template-v2/.claude/skills/playcraft-batch-pipeline/SKILL.md +184 -0
- package/project-template-v2/.claude/skills/playcraft-build-optimizer/SKILL.md +306 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/SKILL.md +401 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +123 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +254 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +333 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +95 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +118 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +136 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +397 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/ta-image-generation-detail.md +300 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +296 -0
- package/project-template-v2/.claude/skills/playcraft-image-ops/SKILL.md +122 -0
- package/project-template-v2/.claude/skills/playcraft-image-processing/SKILL.md +244 -0
- package/project-template-v2/.claude/skills/playcraft-masking/SKILL.md +373 -0
- package/project-template-v2/.claude/skills/playcraft-playable-optimization/SKILL.md +161 -0
- package/project-template-v2/.claude/skills/playcraft-research/SKILL.md +215 -0
- package/project-template-v2/.claude/skills/playcraft-skill-recommender/SKILL.md +382 -0
- package/project-template-v2/.claude/skills/playcraft-sprite-generation/SKILL.md +423 -0
- package/project-template-v2/.claude/skills/playcraft-sprite-remix/SKILL.md +158 -0
- package/project-template-v2/.claude/skills/playcraft-sprite-sheet/SKILL.md +100 -0
- package/project-template-v2/.claude/skills/playcraft-storyboard/SKILL.md +167 -0
- package/project-template-v2/.claude/skills/playcraft-style-qa/SKILL.md +270 -0
- package/project-template-v2/.claude/skills/playcraft-text-rendering/SKILL.md +236 -0
- package/project-template-v2/.claude/skills/playcraft-vfx-animation/SKILL.md +130 -0
- package/project-template-v2/.claude/skills/playcraft-workspace-assets/SKILL.md +53 -0
- package/project-template-v2/.claude/skills/playcraft-workspace-assets/references/requests.json +32 -0
- package/project-template-v2/.claude/skills/playwright-cli/SKILL.md +390 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/element-attributes.md +23 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/request-mocking.md +87 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/running-code.md +240 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/session-management.md +226 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/spec-driven-testing.md +308 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/storage-state.md +275 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/test-generation.md +134 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/tracing.md +142 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/video-recording.md +153 -0
- package/project-template-v2/.claude/skills/session-analyzer/SKILL.md +386 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/execution-breakdown.mjs +182 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/find-turns.mjs +72 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/heavy-output.mjs +121 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/resolve-session.mjs +102 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-stats.mjs +127 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-tool-timeline.mjs +106 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/time-gaps.mjs +128 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/turn-timeline.mjs +67 -0
- package/project-template-v2/.claude/snapshot.mjs +263 -0
- package/project-template-v2/.playcraft/skills.lock.json +152 -0
- package/project-template-v2/CLAUDE.md +146 -0
- package/project-template-v2/assets/audio/bgm/.gitkeep +0 -0
- package/project-template-v2/assets/audio/sfx/.gitkeep +0 -0
- package/project-template-v2/assets/bundles/.gitkeep +0 -0
- package/project-template-v2/assets/images/bg/.gitkeep +0 -0
- package/project-template-v2/assets/images/reference/.gitkeep +0 -0
- package/project-template-v2/assets/images/storyboard/.gitkeep +0 -0
- package/project-template-v2/assets/images/tiles/.gitkeep +0 -0
- package/project-template-v2/assets/images/ui/.gitkeep +0 -0
- package/project-template-v2/assets/images/vfx/.gitkeep +0 -0
- package/project-template-v2/assets/models/.gitkeep +0 -0
- package/project-template-v2/docs/harness/iteration-1/context-flow.md +254 -0
- package/project-template-v2/docs/harness/iteration-1/generate-flow.md +91 -0
- package/project-template-v2/docs/harness/iteration-1/ideate-flow.md +214 -0
- package/project-template-v2/docs/harness/iteration-1/optimize-flow.md +75 -0
- package/project-template-v2/docs/harness/iteration-1/wrapup-flow.md +63 -0
- package/project-template-v2/docs/harness/iteration-2/context-flow.md +223 -0
- package/project-template-v2/docs/harness/iteration-2/generate-flow.md +129 -0
- package/project-template-v2/docs/harness/iteration-2/ideate-flow.md +267 -0
- package/project-template-v2/docs/harness/iteration-2/optimize-flow.md +164 -0
- package/project-template-v2/docs/harness/iteration-2/wrapup-flow.md +115 -0
- package/project-template-v2/docs/harness/orchestrator-flow.md +364 -0
- package/project-template-v2/docs/project-state.json +60 -0
- package/project-template-v2/docs/project-state.md +72 -0
- package/project-template-v2/docs/standards/README.md +225 -0
- package/project-template-v2/docs/standards/agent-behavior-standards.md +174 -0
- package/project-template-v2/docs/standards/artifacts/design-brief.md +19 -0
- package/project-template-v2/docs/standards/artifacts/design.md +22 -0
- package/project-template-v2/docs/standards/artifacts/game-code.md +41 -0
- package/project-template-v2/docs/standards/artifacts/todo-list.md +41 -0
- package/project-template-v2/docs/standards/iter1-agent-behavior-standards.md +343 -0
- package/project-template-v2/game/index.ts +18 -0
- package/project-template-v2/globals.d.ts +51 -0
- package/project-template-v2/index.css +34 -0
- package/project-template-v2/index.html +18 -0
- package/project-template-v2/main.ts +9 -0
- package/project-template-v2/package.json +46 -0
- package/project-template-v2/skills/_shared/scripts/dispatch-clear.mjs +31 -0
- package/project-template-v2/skills/_shared/scripts/dispatch-set.mjs +86 -0
- package/project-template-v2/skills/_shared/scripts/dod-check.mjs +153 -0
- package/project-template-v2/skills/_shared/scripts/handoff-append.mjs +70 -0
- package/project-template-v2/skills/_shared/scripts/lib/validator-artifacts.mjs +91 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/dod-config.mjs +131 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/index.mjs +80 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-1-core.mjs +90 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-2-wrap.mjs +93 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-3-visual.mjs +23 -0
- package/project-template-v2/skills/_shared/scripts/render-project-state.mjs +230 -0
- package/project-template-v2/skills/_shared/scripts/state-advance-stage.mjs +58 -0
- package/project-template-v2/skills/_shared/scripts/state-get.mjs +339 -0
- package/project-template-v2/skills/_shared/scripts/state-handoff.mjs +39 -0
- package/project-template-v2/skills/_shared/scripts/state-set.mjs +94 -0
- package/project-template-v2/skills/_shared/scripts/state-store.mjs +783 -0
- package/project-template-v2/skills/_shared/scripts/todo-add.mjs +88 -0
- package/project-template-v2/skills/_shared/scripts/todo-get.mjs +130 -0
- package/project-template-v2/skills/_shared/scripts/todo-remove.mjs +33 -0
- package/project-template-v2/skills/_shared/scripts/todo-set.mjs +47 -0
- package/project-template-v2/skills/_shared/scripts/verify-asset-code-sync.mjs +268 -0
- package/project-template-v2/skills/_shared/scripts/verify-env.mjs +285 -0
- package/project-template-v2/skills/_shared/scripts/verify-placeholders.mjs +161 -0
- package/project-template-v2/skills/playable-autoplay/SKILL.md +176 -0
- package/project-template-v2/skills/playable-autoplay/agents/openai.yaml +4 -0
- package/project-template-v2/skills/playable-debug/SKILL.md +116 -0
- package/project-template-v2/skills/playable-debug/agents/openai.yaml +4 -0
- package/project-template-v2/skills/playable-debug/references/debug-config.md +40 -0
- package/project-template-v2/skills/playable-record/SKILL.md +140 -0
- package/project-template-v2/skills/playable-record/scripts/lib/dev-server.mjs +104 -0
- package/project-template-v2/skills/playable-record/scripts/lib/record-audio-bridge.js +141 -0
- package/project-template-v2/skills/playable-record/scripts/record-playable.mjs +425 -0
- package/project-template-v2/skills/playable-record/scripts/verify-contract.mjs +261 -0
- package/project-template-v2/skills/playable-record/scripts/verify-firstwin.mjs +398 -0
- package/project-template-v2/skills/playable-record/scripts/verify-fusion.mjs +322 -0
- package/project-template-v2/skills/playable-record/scripts/verify-lifecycle.mjs +105 -0
- package/project-template-v2/skills/playable-record/scripts/verify-vlm-video.mjs +230 -0
- package/project-template-v2/skills/playable-validate/SKILL.md +61 -0
- package/project-template-v2/skills/playable-validate/validation-rules.md +14 -0
- package/project-template-v2/skills/playable-verify-ui/SKILL.md +63 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/__init__.py +1 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/config_expr.js +218 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/node_utils.js +51 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/profile_loader.py +59 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/report.py +106 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/runtime_contract.js +116 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_fetch_antipatterns.py +59 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_hardcoded_layout.js +64 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_runtime_contract.js +58 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_text_overlap.py +333 -0
- package/project-template-v2/ta-workspace/scripts/.gitkeep +0 -0
- package/project-template-v2/tsconfig.json +20 -0
- package/project-template-v2/vite.config.ts +27 -0
- package/project-templates/batch-locks/phaser.yaml +922 -0
- package/project-templates/batch-locks/threejs.yaml +978 -0
- package/project-templates/empty/AGENTS.md +53 -0
- package/project-templates/empty/gitignore +33 -0
- package/project-templates/phaser/.claude/skills/playcraft-audio-generation/SKILL.md +31 -4
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/SKILL.md +36 -5
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +1 -1
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +1 -1
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +1 -1
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +1 -1
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +1 -1
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +1 -1
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/ta-image-generation-detail.md +300 -0
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +1 -1
- package/project-templates/phaser/.claude/skills/playcraft-image-processing/SKILL.md +50 -25
- package/project-templates/phaser/.claude/skills/playcraft-workspace-assets/SKILL.md +53 -0
- package/project-templates/phaser/.claude/skills/playcraft-workspace-assets/references/requests.json +32 -0
- package/project-templates/threejs/.claude/skills/playcraft-audio-generation/SKILL.md +31 -4
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/SKILL.md +36 -5
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +1 -1
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +1 -1
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +1 -1
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +1 -1
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +1 -1
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +1 -1
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/ta-image-generation-detail.md +300 -0
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +1 -1
- package/project-templates/threejs/.claude/skills/playcraft-image-processing/SKILL.md +50 -25
- package/project-templates/threejs/.claude/skills/playcraft-workspace-assets/SKILL.md +53 -0
- package/project-templates/threejs/.claude/skills/playcraft-workspace-assets/references/requests.json +32 -0
- package/templates/preview-runtime/v1/README.md +71 -0
- package/templates/preview-runtime/v1/build-preview.mjs +1324 -0
- package/templates/preview-runtime/v1/manifest.json +17 -0
- package/templates/preview-runtime/v1/release-guard.mjs +87 -0
- package/templates/preview-runtime/v1/runtime.d.mts +3 -0
- package/templates/preview-runtime/v1/runtime.d.ts +3 -0
- package/templates/preview-runtime/v1/runtime.mjs +1121 -0
- package/templates/preview-runtime/v1/types/adapters.d.ts +26 -0
- package/templates/preview-runtime/v1/types/preview.d.ts +23 -0
- package/templates/preview-runtime/v1/types/protocol.d.ts +94 -0
- package/templates/preview-runtime/v1/types/runtime.d.ts +14 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, readFile, rm } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { sandboxBatchMemberPrepareSchema, } from '@playcraft/common/cloud-workspace/runtime';
|
|
6
|
+
import { registerWorkspaceDirectory } from '../workspaces/directories.js';
|
|
7
|
+
import { workspaceContainerRoot } from '../workspaces/registry.js';
|
|
8
|
+
import { copyCredentialHelpers, gitRead, gitWrite } from './git.js';
|
|
9
|
+
import { restoreArchive } from './source-capture.js';
|
|
10
|
+
import { groupExited, runProcessGroup } from './processes.js';
|
|
11
|
+
import { filesystemObjectStore, memberStatus, readMember, readSnapshot, readStopMarker, serializeRun, sourceCacheDir, writeMember, } from './records.js';
|
|
12
|
+
const BRANCH = /^remix\/draft-[a-f0-9]{16}$/;
|
|
13
|
+
const LOCKS = [
|
|
14
|
+
'pnpm-lock.yaml',
|
|
15
|
+
'package-lock.json',
|
|
16
|
+
'npm-shrinkwrap.json',
|
|
17
|
+
'yarn.lock',
|
|
18
|
+
'bun.lock',
|
|
19
|
+
'bun.lockb',
|
|
20
|
+
];
|
|
21
|
+
export function frozenInstallCommand() {
|
|
22
|
+
return (process.env.PLAYCRAFT_BATCH_INSTALL_COMMAND ??
|
|
23
|
+
'pnpm install --frozen-lockfile --store-dir /var/cache/playcraft/pnpm-store --ignore-scripts');
|
|
24
|
+
}
|
|
25
|
+
function hashCommand(value) {
|
|
26
|
+
return createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
27
|
+
}
|
|
28
|
+
async function materialize(state, snapshot, destination, store, sourceRoot) {
|
|
29
|
+
const cache = sourceCacheDir(state, snapshot.batchId);
|
|
30
|
+
const cachedDigest = await readFile(`${cache}.digest`, 'utf8').catch(() => '');
|
|
31
|
+
if (cachedDigest.trim() === snapshot.digest &&
|
|
32
|
+
(await lstat(join(cache, '.git')).catch(() => undefined))) {
|
|
33
|
+
await gitWrite(dirnameOf(destination), [
|
|
34
|
+
'clone',
|
|
35
|
+
'--local',
|
|
36
|
+
'--no-hardlinks',
|
|
37
|
+
'--',
|
|
38
|
+
cache,
|
|
39
|
+
destination,
|
|
40
|
+
]);
|
|
41
|
+
await assertFrozenCommit(destination, snapshot.commitHash);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (snapshot.remoteRef) {
|
|
45
|
+
const binding = state.journal.getWorkspace(snapshot.sourceWorkspaceId);
|
|
46
|
+
if (!binding?.repositoryUrl)
|
|
47
|
+
throw new Error('batch_snapshot_mismatch');
|
|
48
|
+
await gitWrite(dirnameOf(destination), ['init', '--initial-branch', 'source', destination]);
|
|
49
|
+
await copyCredentialHelpers(sourceRoot, destination);
|
|
50
|
+
await gitWrite(destination, ['remote', 'add', 'origin', binding.repositoryUrl]);
|
|
51
|
+
try {
|
|
52
|
+
await gitWrite(destination, ['fetch', '--no-tags', 'origin', snapshot.remoteRef]);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
throw new Error('batch_snapshot_mismatch');
|
|
56
|
+
}
|
|
57
|
+
await gitWrite(destination, ['checkout', '--detach', 'FETCH_HEAD']);
|
|
58
|
+
await assertFrozenCommit(destination, snapshot.commitHash);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!snapshot.artifactKey)
|
|
62
|
+
throw new Error('batch_snapshot_mismatch');
|
|
63
|
+
const body = await store.get(snapshot.artifactKey).catch(() => {
|
|
64
|
+
throw new Error('batch_snapshot_mismatch');
|
|
65
|
+
});
|
|
66
|
+
await restoreArchive(body, destination, snapshot.digest);
|
|
67
|
+
}
|
|
68
|
+
function dirnameOf(path) {
|
|
69
|
+
return join(path, '..');
|
|
70
|
+
}
|
|
71
|
+
async function assertFrozenCommit(root, commit) {
|
|
72
|
+
if ((await gitRead(root, ['rev-parse', 'HEAD'])).trim() !== commit)
|
|
73
|
+
throw new Error('batch_snapshot_mismatch');
|
|
74
|
+
}
|
|
75
|
+
/** A bound workspace keeps origin aligned. A local workspace only needs the branch. */
|
|
76
|
+
async function checkoutBranch(root, branchName, commit, repositoryUrl) {
|
|
77
|
+
await gitWrite(root, ['checkout', '-B', branchName, commit]);
|
|
78
|
+
if (repositoryUrl) {
|
|
79
|
+
const origin = await gitRead(root, ['remote', 'get-url', 'origin']).catch(() => '');
|
|
80
|
+
if (!origin.trim())
|
|
81
|
+
await gitWrite(root, ['remote', 'add', 'origin', repositoryUrl]);
|
|
82
|
+
else if (origin.trim() !== repositoryUrl)
|
|
83
|
+
await gitWrite(root, ['remote', 'set-url', 'origin', repositoryUrl]);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
await gitWrite(root, ['remote', 'remove', 'origin']).catch(() => undefined);
|
|
87
|
+
}
|
|
88
|
+
await gitWrite(root, ['config', 'user.name', 'PlayCraft']);
|
|
89
|
+
await gitWrite(root, ['config', 'user.email', 'playcraft@localhost']);
|
|
90
|
+
}
|
|
91
|
+
async function resumeBranch(repositoryUrl, branchName, commit, destination, sourceRoot) {
|
|
92
|
+
if (repositoryUrl) {
|
|
93
|
+
await gitWrite(dirnameOf(destination), [
|
|
94
|
+
'clone',
|
|
95
|
+
'--branch',
|
|
96
|
+
branchName,
|
|
97
|
+
'--single-branch',
|
|
98
|
+
'--',
|
|
99
|
+
repositoryUrl,
|
|
100
|
+
destination,
|
|
101
|
+
]);
|
|
102
|
+
await copyCredentialHelpers(sourceRoot, destination);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
await gitWrite(dirnameOf(destination), [
|
|
106
|
+
'clone',
|
|
107
|
+
'--local',
|
|
108
|
+
'--no-hardlinks',
|
|
109
|
+
'--',
|
|
110
|
+
sourceRoot,
|
|
111
|
+
destination,
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
if ((await gitRead(destination, ['rev-parse', 'HEAD'])).trim() !== commit &&
|
|
115
|
+
!(await gitRead(destination, ['cat-file', '-e', `${commit}^{commit}`]).then(() => true, () => false))) {
|
|
116
|
+
throw new Error('batch_commit_mismatch');
|
|
117
|
+
}
|
|
118
|
+
await gitWrite(destination, ['checkout', '-B', branchName, commit]);
|
|
119
|
+
}
|
|
120
|
+
export async function assertMemberDependencies(root) {
|
|
121
|
+
let manifest;
|
|
122
|
+
try {
|
|
123
|
+
manifest = await readFile(join(root, 'package.json'), 'utf8');
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (error.code === 'ENOENT')
|
|
127
|
+
return 'skip';
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
let names = [];
|
|
131
|
+
try {
|
|
132
|
+
const pkg = JSON.parse(manifest);
|
|
133
|
+
names = [...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})];
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
throw new Error('dependency_lock_mismatch');
|
|
137
|
+
}
|
|
138
|
+
const present = [];
|
|
139
|
+
for (const lock of LOCKS)
|
|
140
|
+
if (await lstat(join(root, lock)).catch(() => undefined))
|
|
141
|
+
present.push(lock);
|
|
142
|
+
if (present.length > 1)
|
|
143
|
+
throw new Error('dependency_locks_conflict');
|
|
144
|
+
if (present.length === 0)
|
|
145
|
+
return 'skip';
|
|
146
|
+
if (present[0] !== 'pnpm-lock.yaml')
|
|
147
|
+
throw new Error('dependency_lock_mismatch');
|
|
148
|
+
const lock = await readFile(join(root, 'pnpm-lock.yaml'), 'utf8');
|
|
149
|
+
if (names.some((name) => !lock.includes(`${name}:`) &&
|
|
150
|
+
!lock.includes(`/${name}@`) &&
|
|
151
|
+
!lock.includes(`'${name}'`) &&
|
|
152
|
+
!lock.includes(`"${name}"`))) {
|
|
153
|
+
throw new Error('dependency_lock_mismatch');
|
|
154
|
+
}
|
|
155
|
+
return 'install';
|
|
156
|
+
}
|
|
157
|
+
export async function prepareBatchMember(state, body, options) {
|
|
158
|
+
if (!body ||
|
|
159
|
+
typeof body !== 'object' ||
|
|
160
|
+
!('occupancyId' in body) ||
|
|
161
|
+
!body.occupancyId)
|
|
162
|
+
throw new Error('occupancy_required');
|
|
163
|
+
const parsed = sandboxBatchMemberPrepareSchema.safeParse(body);
|
|
164
|
+
if (!parsed.success)
|
|
165
|
+
throw new Error(parsed.error.issues.some((issue) => issue.path.includes('branchName'))
|
|
166
|
+
? 'batch_branch_invalid'
|
|
167
|
+
: 'invalid_batch_request');
|
|
168
|
+
const command = parsed.data;
|
|
169
|
+
if (!BRANCH.test(command.branchName))
|
|
170
|
+
throw new Error('batch_branch_invalid');
|
|
171
|
+
const hash = hashCommand(command);
|
|
172
|
+
return serializeRun(command.runId, async () => {
|
|
173
|
+
const marker = await readStopMarker(state, command.runId);
|
|
174
|
+
const existing = await readMember(state, command.runId);
|
|
175
|
+
if (existing && command.ownerFence < existing.ownerFence)
|
|
176
|
+
throw new Error('stale_owner');
|
|
177
|
+
if (marker)
|
|
178
|
+
return memberStatus(await sealStopped(state, command, existing));
|
|
179
|
+
if (existing &&
|
|
180
|
+
existing.ownerFence === command.ownerFence &&
|
|
181
|
+
existing.commandHash?.prepare === hash &&
|
|
182
|
+
existing.state !== 'running' &&
|
|
183
|
+
existing.state !== 'failed') {
|
|
184
|
+
return memberStatus(existing);
|
|
185
|
+
}
|
|
186
|
+
if (existing &&
|
|
187
|
+
existing.ownerFence === command.ownerFence &&
|
|
188
|
+
existing.commandHash?.prepare &&
|
|
189
|
+
existing.commandHash.prepare !== hash)
|
|
190
|
+
throw new Error('batch_command_conflict');
|
|
191
|
+
if (existing?.processes.some((process) => process.role === 'install' && !process.stopped && !groupExited(process.pid)))
|
|
192
|
+
return memberStatus(existing);
|
|
193
|
+
const snapshot = command.snapshot;
|
|
194
|
+
if ((await readSnapshot(state, snapshot.batchId))?.digest === snapshot.digest) {
|
|
195
|
+
/* The local snapshot record is an accelerator; the command snapshot remains authoritative. */
|
|
196
|
+
}
|
|
197
|
+
let record = await writeMember(state, {
|
|
198
|
+
runId: command.runId,
|
|
199
|
+
ownerFence: command.ownerFence,
|
|
200
|
+
occupancyId: command.occupancyId,
|
|
201
|
+
workspaceId: command.workspaceId,
|
|
202
|
+
directoryName: command.directoryName,
|
|
203
|
+
phase: 'prepare',
|
|
204
|
+
state: 'running',
|
|
205
|
+
writersStopped: false,
|
|
206
|
+
holding: true,
|
|
207
|
+
stopRequested: false,
|
|
208
|
+
processes: existing?.processes ?? [],
|
|
209
|
+
commandHash: { ...existing?.commandHash, prepare: hash },
|
|
210
|
+
snapshotDigest: snapshot.digest,
|
|
211
|
+
branchName: command.branchName,
|
|
212
|
+
sourceCommit: snapshot.commitHash,
|
|
213
|
+
beforeTree: existing?.beforeTree,
|
|
214
|
+
updatedAt: new Date().toISOString(),
|
|
215
|
+
});
|
|
216
|
+
let staging;
|
|
217
|
+
try {
|
|
218
|
+
const parent = await workspaceContainerRoot(state, command.workspaceId);
|
|
219
|
+
const root = join(parent, command.directoryName);
|
|
220
|
+
staging = join(parent, `.batch-member-${randomUUID()}`);
|
|
221
|
+
const binding = state.journal.getWorkspace(command.workspaceId);
|
|
222
|
+
if (!binding)
|
|
223
|
+
throw new Error('workspace_not_registered');
|
|
224
|
+
const repositoryUrl = binding.repositoryUrl ?? undefined;
|
|
225
|
+
const sourceRoot = join(parent, snapshot.sourceDirectoryName);
|
|
226
|
+
if (!(await lstat(root).catch(() => undefined))) {
|
|
227
|
+
await mkdir(parent, { recursive: true });
|
|
228
|
+
if (command.resumeFromCommit)
|
|
229
|
+
await resumeBranch(repositoryUrl, command.branchName, command.resumeFromCommit, staging, sourceRoot);
|
|
230
|
+
else
|
|
231
|
+
await materialize(state, snapshot, staging, options?.objectStore ?? filesystemObjectStore(state), sourceRoot);
|
|
232
|
+
const commit = command.resumeFromCommit ?? snapshot.commitHash;
|
|
233
|
+
await checkoutBranch(staging, command.branchName, commit, repositoryUrl);
|
|
234
|
+
const { rename } = await import('node:fs/promises');
|
|
235
|
+
await rename(staging, root);
|
|
236
|
+
}
|
|
237
|
+
await registerWorkspaceDirectory(state, {
|
|
238
|
+
workspaceId: command.workspaceId,
|
|
239
|
+
directoryName: command.directoryName,
|
|
240
|
+
remixId: command.remixId,
|
|
241
|
+
branchName: command.branchName,
|
|
242
|
+
sourceCommit: command.resumeFromCommit ?? snapshot.commitHash,
|
|
243
|
+
}, state.acceptedLeaseFence);
|
|
244
|
+
const plan = await assertMemberDependencies(root);
|
|
245
|
+
if (plan === 'install') {
|
|
246
|
+
const installed = await runProcessGroup(root, frozenInstallCommand(), 'install', async (process) => {
|
|
247
|
+
record = await writeMember(state, {
|
|
248
|
+
...record,
|
|
249
|
+
processes: [...record.processes, process],
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
record = await writeMember(state, {
|
|
253
|
+
...record,
|
|
254
|
+
processes: record.processes.map((process) => process.pid === installed.process.pid
|
|
255
|
+
? { ...installed.process, role: 'install' }
|
|
256
|
+
: process),
|
|
257
|
+
});
|
|
258
|
+
if (await readStopMarker(state, command.runId))
|
|
259
|
+
return memberStatus(await sealStopped(state, command, record));
|
|
260
|
+
if (installed.code !== 0)
|
|
261
|
+
throw new Error('batch_install_failed');
|
|
262
|
+
}
|
|
263
|
+
const head = (await gitRead(root, ['rev-parse', 'HEAD'])).trim();
|
|
264
|
+
record = await writeMember(state, {
|
|
265
|
+
...record,
|
|
266
|
+
state: 'completed',
|
|
267
|
+
writersStopped: true,
|
|
268
|
+
holding: true,
|
|
269
|
+
headCommit: head,
|
|
270
|
+
error: undefined,
|
|
271
|
+
});
|
|
272
|
+
return memberStatus(record);
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
const code = error instanceof Error && /^[a-z0-9_]+$/.test(error.message)
|
|
276
|
+
? error.message
|
|
277
|
+
: 'batch_prepare_failed';
|
|
278
|
+
record = await writeMember(state, {
|
|
279
|
+
...record,
|
|
280
|
+
state: 'failed',
|
|
281
|
+
writersStopped: true,
|
|
282
|
+
holding: false,
|
|
283
|
+
error: code,
|
|
284
|
+
});
|
|
285
|
+
return memberStatus(record);
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
if (staging)
|
|
289
|
+
await rm(staging, { recursive: true, force: true });
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async function sealStopped(state, command, existing) {
|
|
294
|
+
return writeMember(state, {
|
|
295
|
+
runId: command.runId,
|
|
296
|
+
ownerFence: Math.max(command.ownerFence, existing?.ownerFence ?? 0),
|
|
297
|
+
occupancyId: command.occupancyId,
|
|
298
|
+
workspaceId: command.workspaceId,
|
|
299
|
+
directoryName: command.directoryName,
|
|
300
|
+
phase: existing?.phase ?? 'prepare',
|
|
301
|
+
state: 'stopped',
|
|
302
|
+
writersStopped: true,
|
|
303
|
+
holding: false,
|
|
304
|
+
stopRequested: true,
|
|
305
|
+
processes: existing?.processes ?? [],
|
|
306
|
+
sessionId: existing?.sessionId,
|
|
307
|
+
operationId: existing?.operationId,
|
|
308
|
+
headCommit: existing?.headCommit,
|
|
309
|
+
evidence: existing?.evidence,
|
|
310
|
+
commandHash: existing?.commandHash,
|
|
311
|
+
snapshotDigest: existing?.snapshotDigest,
|
|
312
|
+
branchName: existing?.branchName,
|
|
313
|
+
sourceCommit: existing?.sourceCommit,
|
|
314
|
+
beforeTree: existing?.beforeTree,
|
|
315
|
+
updatedAt: new Date().toISOString(),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
+
export async function processBirth(pid) {
|
|
6
|
+
if (process.platform !== 'linux') {
|
|
7
|
+
return promisify(execFile)('ps', ['-p', String(pid), '-o', 'lstart='], { timeout: 2000 }).then(value => value.stdout.trim() || undefined, () => undefined);
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const stat = await readFile(`/proc/${pid}/stat`, 'utf8');
|
|
11
|
+
return stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19];
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function groupExited(pid) {
|
|
18
|
+
try {
|
|
19
|
+
process.kill(-pid, 0);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return error.code === 'ESRCH';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Stops one run's process group. A mismatched birth means the pid was reused, which is not proof
|
|
28
|
+
* that the original writers exited, so the caller must not report writersStopped.
|
|
29
|
+
*/
|
|
30
|
+
export async function stopProcessGroup(record) {
|
|
31
|
+
if (record.stopped || groupExited(record.pid))
|
|
32
|
+
return true;
|
|
33
|
+
if (record.birth && await processBirth(record.pid) !== record.birth)
|
|
34
|
+
return false;
|
|
35
|
+
for (const signal of ['SIGTERM', 'SIGKILL']) {
|
|
36
|
+
try {
|
|
37
|
+
process.kill(-record.pid, signal);
|
|
38
|
+
}
|
|
39
|
+
catch { /* Recheck the group. */ }
|
|
40
|
+
const deadline = Date.now() + 2000;
|
|
41
|
+
while (Date.now() < deadline) {
|
|
42
|
+
if (groupExited(record.pid))
|
|
43
|
+
return true;
|
|
44
|
+
await delay(25);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return groupExited(record.pid);
|
|
48
|
+
}
|
|
49
|
+
export async function runProcessGroup(cwd, command, role, onStart) {
|
|
50
|
+
const child = spawn('bash', ['-lc', command], {
|
|
51
|
+
cwd, detached: true, stdio: ['ignore', 'pipe', 'pipe'],
|
|
52
|
+
env: { PATH: process.env.PATH, HOME: cwd, GIT_TERMINAL_PROMPT: '0' },
|
|
53
|
+
});
|
|
54
|
+
const pid = child.pid;
|
|
55
|
+
if (!pid)
|
|
56
|
+
throw new Error('batch_process_not_started');
|
|
57
|
+
let output = '';
|
|
58
|
+
const collect = (chunk) => { output = (output + String(chunk)).slice(-64 * 1024); };
|
|
59
|
+
child.stdout?.on('data', collect);
|
|
60
|
+
child.stderr?.on('data', collect);
|
|
61
|
+
// Subscribe before any await. A short command can exit during processBirth or onStart,
|
|
62
|
+
// and a late listener never sees that close event.
|
|
63
|
+
const finished = new Promise((resolve) => {
|
|
64
|
+
child.once('error', () => resolve(null));
|
|
65
|
+
child.once('close', resolve);
|
|
66
|
+
});
|
|
67
|
+
const tracked = { pid, birth: await processBirth(pid), stopped: false, role };
|
|
68
|
+
await onStart(tracked);
|
|
69
|
+
const code = await finished;
|
|
70
|
+
tracked.stopped = groupExited(pid);
|
|
71
|
+
return { code, output, process: tracked };
|
|
72
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, readdir, rename, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { batchSourceSnapshotRefSchema, sandboxBatchMemberStatusSchema, } from '@playcraft/common/cloud-workspace/runtime';
|
|
5
|
+
const runs = new Map();
|
|
6
|
+
let freezeChain = Promise.resolve();
|
|
7
|
+
export function serializeFreeze(action) {
|
|
8
|
+
const run = freezeChain.then(action, action);
|
|
9
|
+
freezeChain = run.then(() => undefined, () => undefined);
|
|
10
|
+
return run;
|
|
11
|
+
}
|
|
12
|
+
export function serializeRun(runId, action) {
|
|
13
|
+
const previous = runs.get(runId) ?? Promise.resolve();
|
|
14
|
+
const run = previous.then(action, action);
|
|
15
|
+
runs.set(runId, run.then(() => undefined, () => undefined));
|
|
16
|
+
return run;
|
|
17
|
+
}
|
|
18
|
+
export function snapshotFile(state, batchId) {
|
|
19
|
+
return join(state.config.stateDir, 'batch-sources', `${batchId}.json`);
|
|
20
|
+
}
|
|
21
|
+
export function memberFile(state, runId) {
|
|
22
|
+
return join(state.config.stateDir, 'batch-members', `${runId}.json`);
|
|
23
|
+
}
|
|
24
|
+
export function stopMarkerFile(state, runId) {
|
|
25
|
+
return join(state.config.stateDir, 'batch-stops', `${runId}.json`);
|
|
26
|
+
}
|
|
27
|
+
export function sourceCacheDir(state, batchId) {
|
|
28
|
+
return join(state.config.stateDir, 'batch-source-cache', batchId);
|
|
29
|
+
}
|
|
30
|
+
export function objectFile(state, key) {
|
|
31
|
+
if (key.split('/').some(part => !part || part === '.' || part === '..'))
|
|
32
|
+
throw new Error('batch_object_key_invalid');
|
|
33
|
+
return join(state.config.stateDir, 'batch-objects', key);
|
|
34
|
+
}
|
|
35
|
+
async function writeAtomic(path, body) {
|
|
36
|
+
await mkdir(join(path, '..'), { recursive: true, mode: 0o700 });
|
|
37
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
38
|
+
await writeFile(temporary, body, { mode: 0o600 });
|
|
39
|
+
await rename(temporary, path);
|
|
40
|
+
}
|
|
41
|
+
async function readJson(path) {
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(await readFile(path, 'utf8'));
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error.code === 'ENOENT')
|
|
47
|
+
return undefined;
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function readSnapshot(state, batchId) {
|
|
52
|
+
const value = await readJson(snapshotFile(state, batchId));
|
|
53
|
+
return value ? batchSourceSnapshotRefSchema.parse(value) : undefined;
|
|
54
|
+
}
|
|
55
|
+
export async function writeSnapshot(state, snapshot) {
|
|
56
|
+
const parsed = batchSourceSnapshotRefSchema.parse(snapshot);
|
|
57
|
+
await writeAtomic(snapshotFile(state, parsed.batchId), JSON.stringify(parsed));
|
|
58
|
+
}
|
|
59
|
+
export async function readMember(state, runId) {
|
|
60
|
+
return readJson(memberFile(state, runId));
|
|
61
|
+
}
|
|
62
|
+
export async function writeMember(state, record) {
|
|
63
|
+
const next = { ...record, updatedAt: new Date().toISOString() };
|
|
64
|
+
await writeAtomic(memberFile(state, record.runId), JSON.stringify(next));
|
|
65
|
+
return next;
|
|
66
|
+
}
|
|
67
|
+
export async function listMembers(state) {
|
|
68
|
+
const directory = join(state.config.stateDir, 'batch-members');
|
|
69
|
+
const names = await readdir(directory).catch(error => {
|
|
70
|
+
if (error.code === 'ENOENT')
|
|
71
|
+
return [];
|
|
72
|
+
throw error;
|
|
73
|
+
});
|
|
74
|
+
const records = [];
|
|
75
|
+
for (const name of names) {
|
|
76
|
+
if (!name.endsWith('.json'))
|
|
77
|
+
continue;
|
|
78
|
+
const record = await readJson(join(directory, name));
|
|
79
|
+
if (record)
|
|
80
|
+
records.push(record);
|
|
81
|
+
}
|
|
82
|
+
return records;
|
|
83
|
+
}
|
|
84
|
+
export async function readStopMarker(state, runId) {
|
|
85
|
+
return readJson(stopMarkerFile(state, runId));
|
|
86
|
+
}
|
|
87
|
+
export async function writeStopMarker(state, runId, ownerFence) {
|
|
88
|
+
const path = stopMarkerFile(state, runId);
|
|
89
|
+
if (await readStopMarker(state, runId))
|
|
90
|
+
return;
|
|
91
|
+
await writeAtomic(path, JSON.stringify({ runId, ownerFence, at: new Date().toISOString() }));
|
|
92
|
+
}
|
|
93
|
+
export function memberStatus(record) {
|
|
94
|
+
return sandboxBatchMemberStatusSchema.parse({
|
|
95
|
+
runId: record.runId,
|
|
96
|
+
ownerFence: record.ownerFence,
|
|
97
|
+
phase: record.phase,
|
|
98
|
+
state: record.state,
|
|
99
|
+
writersStopped: record.writersStopped,
|
|
100
|
+
...(record.sessionId ? { sessionId: record.sessionId } : {}),
|
|
101
|
+
...(record.operationId ? { operationId: record.operationId } : {}),
|
|
102
|
+
...(record.headCommit ? { headCommit: record.headCommit } : {}),
|
|
103
|
+
...(record.evidence ? { evidence: record.evidence } : {}),
|
|
104
|
+
...(record.error ? { error: record.error.slice(0, 128) } : {}),
|
|
105
|
+
updatedAt: record.updatedAt,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
export function filesystemObjectStore(state) {
|
|
109
|
+
return {
|
|
110
|
+
async put(key, body) { await writeAtomic(objectFile(state, key), body); },
|
|
111
|
+
async get(key) { return readFile(objectFile(state, key)); },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { batchSourceFreezeResultSchema } from '@playcraft/common/cloud-workspace/runtime';
|
|
2
|
+
import { stopBatchMember, readBatchMemberStatus } from './control.js';
|
|
3
|
+
import { deliverBatchMember } from './deliver.js';
|
|
4
|
+
import { freezeBatchSource } from './freeze.js';
|
|
5
|
+
import { generateBatchMember } from './generate.js';
|
|
6
|
+
import { prepareBatchMember } from './prepare.js';
|
|
7
|
+
import { BatchSourceFreezeError } from './source-failure.js';
|
|
8
|
+
const CLIENT_ERRORS = new Set([
|
|
9
|
+
'occupancy_required', 'invalid_batch_request', 'batch_branch_invalid', 'stale_owner', 'disk_admission_paused',
|
|
10
|
+
'batch_source_push_failed', 'batch_source_upload_failed', 'batch_source_changed', 'batch_source_path_invalid',
|
|
11
|
+
'batch_command_conflict', 'batch_snapshot_mismatch', 'batch_commit_mismatch', 'workspace_not_registered',
|
|
12
|
+
'disk_usage_unavailable', 'batch_object_key_invalid',
|
|
13
|
+
]);
|
|
14
|
+
async function readBody(request) {
|
|
15
|
+
const chunks = [];
|
|
16
|
+
let size = 0;
|
|
17
|
+
for await (const chunk of request) {
|
|
18
|
+
size += chunk.length;
|
|
19
|
+
if (size > 1024 * 1024)
|
|
20
|
+
throw new Error('request_body_too_large');
|
|
21
|
+
chunks.push(Buffer.from(chunk));
|
|
22
|
+
}
|
|
23
|
+
if (!size)
|
|
24
|
+
return {};
|
|
25
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
26
|
+
}
|
|
27
|
+
export async function dispatchBatchRoute(state, request, url) {
|
|
28
|
+
const method = request.method ?? 'GET';
|
|
29
|
+
const path = url.pathname;
|
|
30
|
+
const member = /^\/runtime\/batch-members\/([^/]+)(?:\/(stop))?$/.exec(path);
|
|
31
|
+
if (method === 'GET' && member && !member[2]) {
|
|
32
|
+
const status = await readBatchMemberStatus(state, decodeURIComponent(member[1]));
|
|
33
|
+
return status ? { status: 200, body: status } : { status: 404, body: { error: 'batch_member_not_found' } };
|
|
34
|
+
}
|
|
35
|
+
if (method !== 'POST')
|
|
36
|
+
return undefined;
|
|
37
|
+
try {
|
|
38
|
+
if (path === '/runtime/batch-sources/freeze') {
|
|
39
|
+
const result = batchSourceFreezeResultSchema.parse(await freezeBatchSource(state, await readBody(request)));
|
|
40
|
+
return { status: 200, body: result };
|
|
41
|
+
}
|
|
42
|
+
if (path === '/runtime/batch-members/prepare')
|
|
43
|
+
return { status: 200, body: await prepareBatchMember(state, await readBody(request)) };
|
|
44
|
+
if (path === '/runtime/batch-members/generate')
|
|
45
|
+
return { status: 200, body: await generateBatchMember(state, await readBody(request)) };
|
|
46
|
+
if (path === '/runtime/batch-members/deliver')
|
|
47
|
+
return { status: 200, body: await deliverBatchMember(state, await readBody(request)) };
|
|
48
|
+
if (member?.[2] === 'stop')
|
|
49
|
+
return { status: 200, body: await stopBatchMember(state, decodeURIComponent(member[1]), await readBody(request)) };
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error instanceof BatchSourceFreezeError)
|
|
54
|
+
return { status: 409, body: { error: error.message, failure: error.failure } };
|
|
55
|
+
const code = error instanceof Error && CLIENT_ERRORS.has(error.message) ? error.message : undefined;
|
|
56
|
+
if (!code)
|
|
57
|
+
throw error;
|
|
58
|
+
const status = code === 'occupancy_required' || code === 'invalid_batch_request' || code === 'batch_branch_invalid' ? 400 : 409;
|
|
59
|
+
return { status, body: { error: code } };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { link, mkdir, open, readFile, unlink } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { batchSourceSnapshotRefSchema, } from '@playcraft/common/cloud-workspace/runtime';
|
|
5
|
+
export function sourceCandidateFile(state, batchId) {
|
|
6
|
+
return join(state.config.stateDir, 'batch-source-candidates', `${batchId}.json`);
|
|
7
|
+
}
|
|
8
|
+
export async function readSourceCandidate(state, batchId) {
|
|
9
|
+
let body;
|
|
10
|
+
try {
|
|
11
|
+
body = await readFile(sourceCandidateFile(state, batchId), 'utf8');
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code === 'ENOENT')
|
|
15
|
+
return undefined;
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
let stored;
|
|
19
|
+
try {
|
|
20
|
+
stored = JSON.parse(body);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new Error('batch_source_snapshot_mismatch');
|
|
24
|
+
}
|
|
25
|
+
if (!stored || stored.version !== 1 || !['remote_ref', 'artifact'].includes(stored.persist)
|
|
26
|
+
|| (stored.repositoryUrl !== undefined && typeof stored.repositoryUrl !== 'string')
|
|
27
|
+
|| (stored.projectId !== undefined && stored.projectId !== null && typeof stored.projectId !== 'string')
|
|
28
|
+
|| (stored.branchName !== undefined && typeof stored.branchName !== 'string'))
|
|
29
|
+
throw new Error('batch_source_snapshot_mismatch');
|
|
30
|
+
const parsed = batchSourceSnapshotRefSchema.safeParse(stored.snapshot);
|
|
31
|
+
if (!parsed.success)
|
|
32
|
+
throw new Error('batch_source_snapshot_mismatch');
|
|
33
|
+
const snapshot = parsed.data;
|
|
34
|
+
if (snapshot.batchId !== batchId)
|
|
35
|
+
throw new Error('batch_source_identity_mismatch');
|
|
36
|
+
return { ...stored, snapshot };
|
|
37
|
+
}
|
|
38
|
+
/** The immutable candidate is committed to disk before any request can publish its commit. */
|
|
39
|
+
export async function writeSourceCandidate(state, candidate) {
|
|
40
|
+
const path = sourceCandidateFile(state, candidate.snapshot.batchId);
|
|
41
|
+
const directory = join(path, '..');
|
|
42
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
43
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
44
|
+
const handle = await open(temporary, 'wx', 0o600);
|
|
45
|
+
try {
|
|
46
|
+
await handle.writeFile(JSON.stringify(candidate));
|
|
47
|
+
await handle.sync();
|
|
48
|
+
await handle.close();
|
|
49
|
+
try {
|
|
50
|
+
await link(temporary, path);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error.code !== 'EEXIST')
|
|
54
|
+
throw error;
|
|
55
|
+
const existing = await readSourceCandidate(state, candidate.snapshot.batchId);
|
|
56
|
+
if (JSON.stringify(existing) !== JSON.stringify(candidate))
|
|
57
|
+
throw new Error('batch_source_identity_mismatch');
|
|
58
|
+
}
|
|
59
|
+
const folder = await open(directory, 'r');
|
|
60
|
+
try {
|
|
61
|
+
await folder.sync();
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
await folder.close();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
await handle.close();
|
|
69
|
+
await unlink(temporary).catch(() => undefined);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function assertSourceIdentity(state, request, snapshot, candidate) {
|
|
73
|
+
const binding = state.journal.getWorkspace(request.workspaceId);
|
|
74
|
+
const branchName = request.sourceDirectoryName === 'basic' ? binding?.branchName
|
|
75
|
+
: binding?.directories?.find(directory => directory.directoryName === request.sourceDirectoryName)?.branchName;
|
|
76
|
+
if (snapshot.batchId !== request.batchId || snapshot.sourceWorkspaceId !== request.workspaceId
|
|
77
|
+
|| snapshot.sourceDirectoryName !== request.sourceDirectoryName
|
|
78
|
+
|| (request.persist === 'remote_ref' ? !snapshot.remoteRef || Boolean(snapshot.artifactKey) : !snapshot.artifactKey || Boolean(snapshot.remoteRef))
|
|
79
|
+
|| (candidate && (candidate.persist !== request.persist || candidate.repositoryUrl !== (binding?.repositoryUrl ?? undefined)
|
|
80
|
+
|| candidate.projectId !== binding?.projectId || candidate.branchName !== (branchName ?? undefined)
|
|
81
|
+
|| candidate.snapshot.commitHash !== snapshot.commitHash || candidate.snapshot.digest !== snapshot.digest
|
|
82
|
+
|| candidate.snapshot.frozenAt !== snapshot.frozenAt || candidate.snapshot.remoteRef !== snapshot.remoteRef
|
|
83
|
+
|| candidate.snapshot.artifactKey !== snapshot.artifactKey))) {
|
|
84
|
+
throw new Error('batch_source_identity_mismatch');
|
|
85
|
+
}
|
|
86
|
+
}
|