@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,441 @@
|
|
|
1
|
+
import { closeCliCredentials } from './workspaces/cli-credentials.js';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { mkdir, readdir } from 'node:fs/promises';
|
|
4
|
+
import { createServer } from 'node:http';
|
|
5
|
+
import { createPlatformAdapter } from '@playcraft/build';
|
|
6
|
+
import { INCOMPATIBLE_EXIT_CODE, negotiateProtocol, transitionOperation, directoryMutationReceiptSchema, productionSessionAttemptId, } from '@playcraft/common/cloud-workspace/runtime';
|
|
7
|
+
import { RuntimeJournal } from './persistence/journal.js';
|
|
8
|
+
import { createCodexAppServerAdapter } from './codex/app-server.js';
|
|
9
|
+
import { trustedMemberPolicy } from './batch/policy.js';
|
|
10
|
+
import { batchDirectoryHeld } from './batch/occupancy.js';
|
|
11
|
+
import { createLoopbackNativeAdapter } from './codex/loopback.js';
|
|
12
|
+
import { attachNativeCollector, recoverInterruptedParameterVerifications, stopParameterVerifications } from './server/dispatch.js';
|
|
13
|
+
import { handleRuntimeRequest } from './server/http.js';
|
|
14
|
+
import { desktopHost, disposeDesktopHost } from './server/desktop-host.js';
|
|
15
|
+
import { disposeTerminalHost, terminalHost } from './server/terminal-host.js';
|
|
16
|
+
import { handleExecutionGroupCrash } from './server/execution-group.js';
|
|
17
|
+
import { RuntimeProcessLock } from './server/lock.js';
|
|
18
|
+
import { probeGitBinary } from './workspaces/git.js';
|
|
19
|
+
import { WorkspaceGitCredentialBroker } from './workspaces/git-credential-broker.js';
|
|
20
|
+
import { WorkspaceModelBroker } from './codex/model-broker.js';
|
|
21
|
+
import { recoverInterruptedPreviews } from './previews/publish.js';
|
|
22
|
+
import { recoverInterruptedInstalls } from './workspaces/dependencies.js';
|
|
23
|
+
import { DeliveryStore, recoverInterruptedDeliveries } from './workspaces/delivery-store.js';
|
|
24
|
+
import { loadWorkspaceSkillArtifact } from './workspaces/skill-artifact-loader.js';
|
|
25
|
+
import { workspaceContextFromRoot, workspaceRoot } from './workspaces/registry.js';
|
|
26
|
+
import { recoverInterruptedLibraryImports } from './workspaces/asset-library-import.js';
|
|
27
|
+
import { recoverAssetTransfers } from './workspaces/asset-transfer-publish.js';
|
|
28
|
+
import { recoverWorkspaceDirectoryMutation } from './workspaces/directory-mutations.js';
|
|
29
|
+
import { observeWorkspaceDirectories } from './workspaces/directory-revisions.js';
|
|
30
|
+
import { observeWorkspaceBinaryFile } from './workspaces/binary-write.js';
|
|
31
|
+
import { revisionScope } from './workspaces/registry.js';
|
|
32
|
+
import { observeWorkspaceArtifacts } from './workspaces/artifact-events.js';
|
|
33
|
+
import { loadWorkspaceMcpConfig } from './codex/mcp-config.js';
|
|
34
|
+
import { startSourceEventUploader, stopSourceEventUploader } from './server/source-uploader.js';
|
|
35
|
+
import { submitTrustedOperation } from './server/submit-operation.js';
|
|
36
|
+
export async function startWorkspaceRuntime(config, options = {}) {
|
|
37
|
+
process.env.PLAYCRAFT_SKIP_UPDATE_CHECK = '1';
|
|
38
|
+
const negotiated = negotiateProtocol(config);
|
|
39
|
+
if (!negotiated.ok) {
|
|
40
|
+
const error = Object.assign(new Error('protocol_incompatible'), {
|
|
41
|
+
code: 'protocol_incompatible',
|
|
42
|
+
exitCode: INCOMPATIBLE_EXIT_CODE,
|
|
43
|
+
});
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
const lock = new RuntimeProcessLock(config.stateDir);
|
|
47
|
+
lock.acquire();
|
|
48
|
+
let journal;
|
|
49
|
+
let gitCredentials;
|
|
50
|
+
let runtimeState;
|
|
51
|
+
try {
|
|
52
|
+
journal = new RuntimeJournal(config.stateDir);
|
|
53
|
+
await journal.load();
|
|
54
|
+
const previousEpoch = journal.storedRuntimeEpoch();
|
|
55
|
+
const previousGroup = journal.executionGroup();
|
|
56
|
+
const previousIdentityMatches = journal.epochsSnapshot().some((epoch) => epoch.runtime_id === config.runtimeId && epoch.generation === config.generation && epoch.runtime_epoch === previousEpoch);
|
|
57
|
+
await recoverInterruptedInstalls(journal);
|
|
58
|
+
await recoverInterruptedPreviews(journal);
|
|
59
|
+
await recoverInterruptedParameterVerifications(journal);
|
|
60
|
+
await recoverInterruptedDeliveries(config.stateDir);
|
|
61
|
+
await mkdir(config.workspaceRoot, { recursive: true, mode: 0o700 });
|
|
62
|
+
const state = runtimeState = {
|
|
63
|
+
config: { ...config, protocolMinor: negotiated.protocolMinor },
|
|
64
|
+
configPath: options.configPath,
|
|
65
|
+
journal,
|
|
66
|
+
acceptedLeaseFence: journal.acceptedLeaseFence(),
|
|
67
|
+
gitAvailable: await probeGitBinary(),
|
|
68
|
+
native: options.nativeAdapter,
|
|
69
|
+
runtimeEpoch: Math.max(config.runtimeEpoch, journal.storedRuntimeEpoch() ?? 0),
|
|
70
|
+
executionQueue: Promise.resolve(),
|
|
71
|
+
instanceToken: randomUUID(),
|
|
72
|
+
};
|
|
73
|
+
const recoveredImports = new Map();
|
|
74
|
+
const recoveredChanges = [];
|
|
75
|
+
const recoveredWrites = [];
|
|
76
|
+
const recoverLibraryImports = async (root) => {
|
|
77
|
+
const result = await recoverInterruptedLibraryImports(root).catch(() => undefined);
|
|
78
|
+
for (const published of result?.published ?? []) {
|
|
79
|
+
const previous = recoveredImports.get(published.operationId) ?? { paths: [], assetIds: [] };
|
|
80
|
+
recoveredImports.set(published.operationId, { paths: [...new Set([...previous.paths, ...published.paths])],
|
|
81
|
+
assetIds: [...new Set([...previous.assetIds, published.assetId])] });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
if (config.workspaceMode === 'multi') {
|
|
85
|
+
for (const entry of await readdir(config.workspaceRoot, { withFileTypes: true })) {
|
|
86
|
+
if (!entry.isDirectory())
|
|
87
|
+
continue;
|
|
88
|
+
const binding = journal.getWorkspace(entry.name);
|
|
89
|
+
if (!binding)
|
|
90
|
+
continue;
|
|
91
|
+
for (const directory of new Set(['basic', ...(binding.directories ?? []).map(item => item.directoryName)])) {
|
|
92
|
+
const root = await workspaceRoot(state, binding.workspaceId, directory).catch(() => undefined);
|
|
93
|
+
if (root)
|
|
94
|
+
await recoverLibraryImports(root);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
await recoverLibraryImports(config.workspaceRoot);
|
|
100
|
+
for (const { scopeKey, operation } of journal.listOperations()) {
|
|
101
|
+
if (operation.kind !== 'asset.library.import' || !['queued', 'dispatched', 'accepted', 'uncertain'].includes(operation.status))
|
|
102
|
+
continue;
|
|
103
|
+
const published = recoveredImports.get(operation.operationId);
|
|
104
|
+
const result = operation.result && 'paths' in operation.result ? { ...operation.result,
|
|
105
|
+
paths: [...new Set([...operation.result.paths, ...(published?.paths ?? [])])],
|
|
106
|
+
failures: operation.result.failures.filter(failure => !published?.assetIds.includes(failure.assetId)),
|
|
107
|
+
} : undefined;
|
|
108
|
+
const root = await workspaceRoot(state, operation.workspaceId, operation.directoryName).catch(() => undefined);
|
|
109
|
+
if (root && result)
|
|
110
|
+
for (const path of result.paths) {
|
|
111
|
+
const file = await observeWorkspaceBinaryFile(root, path).catch(() => undefined);
|
|
112
|
+
if (!file)
|
|
113
|
+
continue;
|
|
114
|
+
const scope = revisionScope(state, operation.workspaceId, operation.directoryName);
|
|
115
|
+
const previous = journal.fileRevisions(scope)[path];
|
|
116
|
+
await journal.putFileRevision(path, { revision: (previous?.revision ?? 0) + 1, contentHash: file.contentHash }, scope);
|
|
117
|
+
}
|
|
118
|
+
let next = operation;
|
|
119
|
+
if (result && !result.failures.length) {
|
|
120
|
+
if (next.status === 'queued')
|
|
121
|
+
next = transitionOperation(next, 'dispatched');
|
|
122
|
+
if (next.status === 'dispatched')
|
|
123
|
+
next = transitionOperation(next, 'accepted');
|
|
124
|
+
next = transitionOperation(next, 'completed', { result });
|
|
125
|
+
}
|
|
126
|
+
else
|
|
127
|
+
next = transitionOperation(next, 'failed', { error: 'asset_library_import_interrupted', ...(result ? { result } : {}) });
|
|
128
|
+
await journal.putOperation(scopeKey, next);
|
|
129
|
+
if (operation.workspaceId && result?.paths.length)
|
|
130
|
+
recoveredChanges.push({ workspaceId: operation.workspaceId,
|
|
131
|
+
directoryName: operation.directoryName ?? 'basic', paths: result.paths });
|
|
132
|
+
}
|
|
133
|
+
const recoveredBundles = new Map();
|
|
134
|
+
const transferScopes = new Set();
|
|
135
|
+
for (const { operation } of journal.listOperations()) {
|
|
136
|
+
if (operation.kind !== 'asset.bundle.save')
|
|
137
|
+
continue;
|
|
138
|
+
const directoryName = operation.directoryName ?? 'basic';
|
|
139
|
+
const key = `${operation.workspaceId ?? ''}:${directoryName}`;
|
|
140
|
+
if (transferScopes.has(key))
|
|
141
|
+
continue;
|
|
142
|
+
transferScopes.add(key);
|
|
143
|
+
const root = await workspaceRoot(state, operation.workspaceId, directoryName).catch(() => undefined);
|
|
144
|
+
if (!root)
|
|
145
|
+
continue;
|
|
146
|
+
const recovered = await recoverAssetTransfers(root, { environment: config.environment, userId: config.userId,
|
|
147
|
+
workspaceId: operation.workspaceId ?? '', directoryName }).catch(() => []);
|
|
148
|
+
for (const item of recovered)
|
|
149
|
+
recoveredBundles.set(item.operationId, item);
|
|
150
|
+
}
|
|
151
|
+
for (const { scopeKey, operation } of journal.listOperations()) {
|
|
152
|
+
if (operation.kind !== 'asset.bundle.save' || !['queued', 'dispatched', 'accepted', 'uncertain'].includes(operation.status))
|
|
153
|
+
continue;
|
|
154
|
+
const recovered = recoveredBundles.get(operation.operationId), receipt = recovered?.receipt;
|
|
155
|
+
let next = operation;
|
|
156
|
+
if (receipt) {
|
|
157
|
+
const paths = [...receipt.files.map(file => file.path), ...(receipt.directories ?? [])];
|
|
158
|
+
const scope = revisionScope(state, operation.workspaceId, operation.directoryName);
|
|
159
|
+
for (const file of receipt.files) {
|
|
160
|
+
const previous = journal.fileRevisions(scope)[file.path];
|
|
161
|
+
const revision = previous ? previous.revision + (previous.contentHash === file.contentHash ? 0 : 1) : 1;
|
|
162
|
+
await journal.putFileRevision(file.path, { revision,
|
|
163
|
+
contentHash: file.contentHash }, scope);
|
|
164
|
+
const metadata = recovered?.manifest.files.find(item => item.path === file.path);
|
|
165
|
+
recoveredWrites.push({ ...file, revision, writer: 'manual', workspaceId: operation.workspaceId,
|
|
166
|
+
directoryName: operation.directoryName ?? 'basic', operationId: operation.operationId, transferId: receipt.transferId,
|
|
167
|
+
...(metadata?.processing ? { processing: metadata.processing } : {}), recovered: true });
|
|
168
|
+
}
|
|
169
|
+
if (next.status === 'queued')
|
|
170
|
+
next = transitionOperation(next, 'dispatched');
|
|
171
|
+
if (next.status === 'dispatched')
|
|
172
|
+
next = transitionOperation(next, 'accepted');
|
|
173
|
+
next = transitionOperation(next, 'completed', { result: { paths, skippedPaths: [], failures: [], bundleReceipt: receipt } });
|
|
174
|
+
if (operation.workspaceId)
|
|
175
|
+
recoveredChanges.push({ workspaceId: operation.workspaceId, directoryName: operation.directoryName ?? 'basic', paths, source: 'asset.bundle.save' });
|
|
176
|
+
}
|
|
177
|
+
else
|
|
178
|
+
next = transitionOperation(next, 'failed', { error: 'asset_bundle_save_interrupted' });
|
|
179
|
+
await journal.putOperation(scopeKey, next);
|
|
180
|
+
}
|
|
181
|
+
for (const { scopeKey, operation } of journal.listOperations()) {
|
|
182
|
+
if (!['directory.rename', 'directory.delete'].includes(operation.kind)
|
|
183
|
+
|| !['queued', 'dispatched', 'accepted', 'uncertain'].includes(operation.status))
|
|
184
|
+
continue;
|
|
185
|
+
const kind = operation.kind;
|
|
186
|
+
let next = operation;
|
|
187
|
+
try {
|
|
188
|
+
const root = await workspaceRoot(state, operation.workspaceId, operation.directoryName);
|
|
189
|
+
const receipt = await recoverWorkspaceDirectoryMutation(root, kind, { operationId: operation.operationId,
|
|
190
|
+
operationPayloadHash: operation.payloadHash, scope: scopeKey, assertCurrent: async () => {
|
|
191
|
+
if ((operation.leaseFence ?? 0) < state.acceptedLeaseFence || state.journal.destroyed())
|
|
192
|
+
throw new Error('stale_lease');
|
|
193
|
+
if (operation.sessionId && productionSessionAttemptId(operation.sessionId))
|
|
194
|
+
throw new Error('production_session_readonly');
|
|
195
|
+
if (await batchDirectoryHeld(state, operation.workspaceId, operation.directoryName))
|
|
196
|
+
throw new Error('batch_workspace_readonly');
|
|
197
|
+
} });
|
|
198
|
+
if (!receipt)
|
|
199
|
+
throw new Error('directory_mutation_interrupted');
|
|
200
|
+
await observeWorkspaceDirectories(root, journal, revisionScope(state, operation.workspaceId, operation.directoryName));
|
|
201
|
+
const paths = [receipt.path, ...(receipt.newPath ? [receipt.newPath] : [])];
|
|
202
|
+
if (next.status === 'queued')
|
|
203
|
+
next = transitionOperation(next, 'dispatched');
|
|
204
|
+
if (next.status === 'dispatched')
|
|
205
|
+
next = transitionOperation(next, 'accepted');
|
|
206
|
+
next = transitionOperation(next, 'completed', { result: { paths, skippedPaths: [], failures: [], directoryMutation: directoryMutationReceiptSchema.parse(receipt) } });
|
|
207
|
+
if (operation.workspaceId)
|
|
208
|
+
recoveredChanges.push({ workspaceId: operation.workspaceId,
|
|
209
|
+
directoryName: operation.directoryName ?? 'basic', paths, source: kind });
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
const reason = String(error?.code ?? (error instanceof Error ? error.message : ''));
|
|
213
|
+
const code = ['directory_mutation_interrupted', 'stale_lease', 'production_session_readonly', 'batch_workspace_readonly',
|
|
214
|
+
'directory_exists', 'directory_not_found', 'revision_conflict', 'directory_conflict', 'invalid_workspace_path', 'workspace_permission_denied']
|
|
215
|
+
.includes(reason) ? reason : 'directory_recovery_required';
|
|
216
|
+
next = transitionOperation(next, code === 'directory_mutation_interrupted' ? 'failed' : 'uncertain', { error: code });
|
|
217
|
+
}
|
|
218
|
+
await journal.putOperation(scopeKey, next);
|
|
219
|
+
}
|
|
220
|
+
const native = state.native ??= defaultNativeAdapter(state);
|
|
221
|
+
await journal.bindRuntime({
|
|
222
|
+
runtimeId: config.runtimeId,
|
|
223
|
+
generation: config.generation,
|
|
224
|
+
runtimeEpoch: state.runtimeEpoch,
|
|
225
|
+
});
|
|
226
|
+
for (const payload of recoveredWrites)
|
|
227
|
+
await journal.allocateSourceEvent({ runtimeId: config.runtimeId,
|
|
228
|
+
generation: config.generation, runtimeEpoch: state.runtimeEpoch, workspaceId: payload.workspaceId,
|
|
229
|
+
type: 'file.written', occurredAt: new Date().toISOString(), payload });
|
|
230
|
+
for (const change of recoveredChanges)
|
|
231
|
+
await journal.allocateSourceEvent({ runtimeId: config.runtimeId,
|
|
232
|
+
generation: config.generation, runtimeEpoch: state.runtimeEpoch, workspaceId: change.workspaceId,
|
|
233
|
+
type: 'files.changed', occurredAt: new Date().toISOString(), payload: { ...change, source: change.source ?? 'asset.library.import', recovered: true },
|
|
234
|
+
});
|
|
235
|
+
startSourceEventUploader(state);
|
|
236
|
+
if (config.workspaceMode === 'multi') {
|
|
237
|
+
gitCredentials = state.gitCredentials = new WorkspaceGitCredentialBroker(state);
|
|
238
|
+
await gitCredentials.start();
|
|
239
|
+
}
|
|
240
|
+
const stopArtifactObserver = observeWorkspaceArtifacts(state);
|
|
241
|
+
attachNativeCollector(state);
|
|
242
|
+
native?.onUnexpectedExit?.((event) => {
|
|
243
|
+
void handleExecutionGroupCrash(state, event.pid);
|
|
244
|
+
});
|
|
245
|
+
try {
|
|
246
|
+
await native?.start?.();
|
|
247
|
+
const group = native?.executionProcess?.();
|
|
248
|
+
if (group) {
|
|
249
|
+
let previousStopped = false;
|
|
250
|
+
if (previousGroup.pid && previousGroup.pid !== group.pid) {
|
|
251
|
+
try {
|
|
252
|
+
process.kill(previousGroup.pid, 0);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
previousStopped = error.code === 'ESRCH';
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// The supervisor advances the trusted config epoch only after stopping the old
|
|
259
|
+
// native group. Reconfirm its recorded PID before publishing that replacement.
|
|
260
|
+
if (previousIdentityMatches && previousEpoch !== undefined && config.runtimeEpoch > previousEpoch && previousStopped) {
|
|
261
|
+
await journal.writeExecutionEpoch({
|
|
262
|
+
runtimeEpoch: state.runtimeEpoch, ...group, previousPid: previousGroup.pid, previousRuntimeEpoch: previousEpoch, stopConfirmed: true,
|
|
263
|
+
});
|
|
264
|
+
await journal.replaceSessions(journal.listSessions().map((session) => ({ ...session, recoverability: 'history_only' })));
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
await journal.noteExecutionGroup(group);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
const code = error instanceof Error ? error.message : '';
|
|
273
|
+
state.nativeError = code === 'codex_model_catalog_unavailable' ? code : 'codex_start_failed';
|
|
274
|
+
console.error(`[workspace-runtime] ${state.nativeError}`);
|
|
275
|
+
}
|
|
276
|
+
const server = createServer((request, response) => {
|
|
277
|
+
void handleRuntimeRequest(state, request, response);
|
|
278
|
+
});
|
|
279
|
+
server.on('upgrade', (request, socket, head) => {
|
|
280
|
+
const pathname = new URL(request.url ?? '/', 'http://127.0.0.1').pathname;
|
|
281
|
+
if (/^\/runtime\/terminals\/[^/]+\/connect$/.test(pathname)) {
|
|
282
|
+
void terminalHost(state).handleUpgrade(request, socket, head);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (pathname === '/runtime/desktop/connect') {
|
|
286
|
+
desktopHost(state).handleUpgrade(request, socket, head);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
socket.destroy();
|
|
290
|
+
});
|
|
291
|
+
const port = await listenOn(server, config.listen.host, config.listen.port);
|
|
292
|
+
return {
|
|
293
|
+
config: state.config,
|
|
294
|
+
state,
|
|
295
|
+
url: `http://${formatHost(config.listen.host)}:${port}`,
|
|
296
|
+
async close() {
|
|
297
|
+
const serverClosed = closeServer(server);
|
|
298
|
+
await stopParameterVerifications(state);
|
|
299
|
+
await closeCliCredentials(state);
|
|
300
|
+
await gitCredentials?.close();
|
|
301
|
+
try {
|
|
302
|
+
await disposeDesktopHost(state);
|
|
303
|
+
}
|
|
304
|
+
finally {
|
|
305
|
+
disposeTerminalHost(state);
|
|
306
|
+
try {
|
|
307
|
+
await native?.close?.();
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
/* adapter shutdown is best-effort */
|
|
311
|
+
}
|
|
312
|
+
await serverClosed;
|
|
313
|
+
await stopArtifactObserver();
|
|
314
|
+
stopSourceEventUploader(state);
|
|
315
|
+
await journal?.close();
|
|
316
|
+
lock.release();
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
if (runtimeState)
|
|
323
|
+
stopSourceEventUploader(runtimeState);
|
|
324
|
+
await gitCredentials?.close().catch(() => undefined);
|
|
325
|
+
await journal?.close().catch(() => undefined);
|
|
326
|
+
lock.release();
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function listenOn(server, host, port) {
|
|
331
|
+
return new Promise((resolve, reject) => {
|
|
332
|
+
const onError = (error) => reject(error);
|
|
333
|
+
server.once('error', onError);
|
|
334
|
+
server.listen(port, host, () => {
|
|
335
|
+
server.removeListener('error', onError);
|
|
336
|
+
const address = server.address();
|
|
337
|
+
if (!address || typeof address === 'string') {
|
|
338
|
+
reject(new Error('listen_failed'));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
resolve(address.port);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
function closeServer(server) {
|
|
346
|
+
return new Promise((resolve, reject) => {
|
|
347
|
+
server.close((error) => {
|
|
348
|
+
if (error)
|
|
349
|
+
reject(error);
|
|
350
|
+
else
|
|
351
|
+
resolve();
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
function formatHost(host) {
|
|
356
|
+
return host.includes(':') ? `[${host}]` : host;
|
|
357
|
+
}
|
|
358
|
+
function deliveryToolHandlers(state) {
|
|
359
|
+
const contextFor = async (input) => {
|
|
360
|
+
if (input.workspaceId)
|
|
361
|
+
return { workspaceId: input.workspaceId, directoryName: input.directoryName ?? 'basic' };
|
|
362
|
+
if (state.config.workspaceMode !== 'multi' || !input.cwd)
|
|
363
|
+
throw new Error('feature_unavailable');
|
|
364
|
+
return workspaceContextFromRoot(state, input.cwd);
|
|
365
|
+
};
|
|
366
|
+
return {
|
|
367
|
+
async build(input) {
|
|
368
|
+
const { workspaceId, directoryName } = await contextFor(input);
|
|
369
|
+
if (directoryName === 'root')
|
|
370
|
+
throw new Error('invalid_workspace_directory');
|
|
371
|
+
const builds = [];
|
|
372
|
+
for (const channel of input.channels) {
|
|
373
|
+
const operation = await submitTrustedOperation(state, {
|
|
374
|
+
kind: 'delivery.build',
|
|
375
|
+
workspaceId,
|
|
376
|
+
directoryName,
|
|
377
|
+
...(input.sessionId ? { sessionId: input.sessionId } : {}),
|
|
378
|
+
clientRequestId: `${input.clientRequestId.slice(0, 80)}:${channel}`,
|
|
379
|
+
payload: {
|
|
380
|
+
channel,
|
|
381
|
+
format: input.format ?? createPlatformAdapter({ platform: channel, format: 'html' }).getDefaultFormat(),
|
|
382
|
+
actor: 'agent',
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
let record;
|
|
386
|
+
for (let attempt = 0; attempt < 40 && !record; attempt++) {
|
|
387
|
+
record = await new DeliveryStore(state.config.stateDir, workspaceId).read(operation.operationId);
|
|
388
|
+
if (!record)
|
|
389
|
+
await new Promise(resolve => setTimeout(resolve, 25));
|
|
390
|
+
}
|
|
391
|
+
builds.push({
|
|
392
|
+
buildId: operation.operationId,
|
|
393
|
+
channel,
|
|
394
|
+
status: record?.status ?? operation.status,
|
|
395
|
+
...(record?.queuePosition ? { queuePosition: record.queuePosition } : {}),
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
return { builds };
|
|
399
|
+
},
|
|
400
|
+
async get(input) {
|
|
401
|
+
const { workspaceId, directoryName } = await contextFor(input);
|
|
402
|
+
const store = new DeliveryStore(state.config.stateDir, workspaceId);
|
|
403
|
+
const record = input.buildId
|
|
404
|
+
? await store.read(input.buildId)
|
|
405
|
+
: (await store.list(directoryName, input.channel, 20))[0];
|
|
406
|
+
if (!record || record.directoryName !== directoryName)
|
|
407
|
+
throw new Error('delivery_build_not_found');
|
|
408
|
+
const log = await store.readLog(record.buildId, 0).catch(() => undefined);
|
|
409
|
+
return { build: record, ...(log ? { logTail: log.text.slice(-4_000) } : {}) };
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function defaultNativeAdapter(state) {
|
|
414
|
+
const config = state.config;
|
|
415
|
+
if (process.env.PLAYCRAFT_NATIVE_ADAPTER === 'loopback')
|
|
416
|
+
return createLoopbackNativeAdapter();
|
|
417
|
+
const hasLauncher = Boolean(process.env.PLAYCRAFT_LAUNCHER_SOCKET);
|
|
418
|
+
const multi = config.workspaceMode === 'multi';
|
|
419
|
+
if (process.env.PLAYCRAFT_NATIVE_ADAPTER === 'codex' && !multi && !hasLauncher) {
|
|
420
|
+
throw new Error('codex_requires_managed_launcher');
|
|
421
|
+
}
|
|
422
|
+
if (process.env.PLAYCRAFT_NATIVE_ADAPTER === 'codex' || (multi && hasLauncher)) {
|
|
423
|
+
return createCodexAppServerAdapter({
|
|
424
|
+
config,
|
|
425
|
+
workspaceUi: true,
|
|
426
|
+
deliveryTools: deliveryToolHandlers(state),
|
|
427
|
+
...(multi ? { modelBroker: new WorkspaceModelBroker(state) } : {}),
|
|
428
|
+
...(multi ? { loadMcpConfig: async (cwd) => {
|
|
429
|
+
const { workspaceId } = await workspaceContextFromRoot(state, cwd);
|
|
430
|
+
return loadWorkspaceMcpConfig(state, workspaceId);
|
|
431
|
+
} } : {}),
|
|
432
|
+
loadSkillArtifact: async (cwd, entry) => {
|
|
433
|
+
const { workspaceId, directoryName } = await workspaceContextFromRoot(state, cwd);
|
|
434
|
+
return loadWorkspaceSkillArtifact(state, workspaceId, entry, directoryName === 'root' ? 'basic' : directoryName);
|
|
435
|
+
},
|
|
436
|
+
onSkillProcessRestart: process => state.journal.noteExecutionGroup(process),
|
|
437
|
+
trustedExecution: sessionId => trustedMemberPolicy(state, sessionId),
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
return undefined;
|
|
441
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { assertLeaseFence, hashOperationPayload, isLostThreadError, operationScopeKey, resolveIdempotentAccept, runtimeError, } from '@playcraft/common/cloud-workspace/runtime';
|
|
2
|
+
import { canExecuteKind, executeOperation } from './dispatch.js';
|
|
3
|
+
import { buildOperationRecord } from './operation-record.js';
|
|
4
|
+
/**
|
|
5
|
+
* Shared operation acceptance: lease fence, idempotency, capability, record creation and
|
|
6
|
+
* execution. HTTP supplies its transport/session checks through `validate`; in-sandbox Agent
|
|
7
|
+
* tools pass none. The callback runs only when a new operation is about to be created.
|
|
8
|
+
*/
|
|
9
|
+
export async function acceptOperationCore(state, parsed, options) {
|
|
10
|
+
const payloadHash = hashOperationPayload(parsed.payload);
|
|
11
|
+
const scopeKey = operationScopeKey({
|
|
12
|
+
environment: state.config.environment,
|
|
13
|
+
userId: state.config.userId,
|
|
14
|
+
kind: parsed.kind,
|
|
15
|
+
clientRequestId: parsed.clientRequestId,
|
|
16
|
+
workspaceId: parsed.workspaceId,
|
|
17
|
+
directoryName: parsed.directoryName,
|
|
18
|
+
sessionId: parsed.sessionId,
|
|
19
|
+
});
|
|
20
|
+
return state.journal.exclusive(scopeKey, async () => {
|
|
21
|
+
// Recheck after a concurrent dispatcher may have advanced the fence while this request waited.
|
|
22
|
+
if (assertLeaseFence(options.leaseFence, state.acceptedLeaseFence) !== 'ok') {
|
|
23
|
+
return rejected(409, runtimeError('stale_lease', 'leaseFence is behind the accepted dispatcher'));
|
|
24
|
+
}
|
|
25
|
+
const existing = state.journal.getOperation(scopeKey);
|
|
26
|
+
const decision = resolveIdempotentAccept(existing, payloadHash);
|
|
27
|
+
if (decision.action === 'conflict') {
|
|
28
|
+
return rejected(409, runtimeError('idempotency_conflict', 'clientRequestId reused with a different payload', {
|
|
29
|
+
operationId: decision.operation.operationId,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
const retryWithRecovery = decision.action === 'reuse' && parsed.kind === 'session.turn'
|
|
33
|
+
&& Boolean(parsed.sessionRecovery) && decision.operation.status === 'failed'
|
|
34
|
+
&& isLostThreadError(decision.operation.error);
|
|
35
|
+
if (decision.action === 'reuse' && !retryWithRecovery) {
|
|
36
|
+
if (decision.operation.status === 'uncertain') {
|
|
37
|
+
return rejected(409, runtimeError('uncertain_operation', decision.operation.error ?? 'native_receipt_lost', {
|
|
38
|
+
operationId: decision.operation.operationId,
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
return { rejected: false, operation: decision.operation, executed: decision.operation, reused: true };
|
|
42
|
+
}
|
|
43
|
+
const validation = await options.validate?.(scopeKey);
|
|
44
|
+
if (validation)
|
|
45
|
+
return { rejected: true, refusal: validation };
|
|
46
|
+
const executable = canExecuteKind(state, parsed.kind);
|
|
47
|
+
const operation = buildOperationRecord(state, parsed, payloadHash, options.leaseFence, executable);
|
|
48
|
+
if (!executable) {
|
|
49
|
+
const saved = await state.journal.putOperation(scopeKey, operation);
|
|
50
|
+
return rejected(409, runtimeError('capability_unavailable', state.journal.destroyed() ? 'runtime_destroyed' : state.nativeError ?? 'adapter_not_started', { operationId: saved.operationId }));
|
|
51
|
+
}
|
|
52
|
+
state.acceptedLeaseFence = Math.max(state.acceptedLeaseFence, options.leaseFence);
|
|
53
|
+
await state.journal.setAcceptedLeaseFence(state.acceptedLeaseFence);
|
|
54
|
+
const queued = await state.journal.putOperation(scopeKey, operation);
|
|
55
|
+
const executed = await executeOperation(state, scopeKey, queued, options.executionPayload, parsed.sessionRecovery);
|
|
56
|
+
return { rejected: false, operation: queued, executed, reused: false };
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function rejected(status, body) {
|
|
60
|
+
return { rejected: true, refusal: { status, body } };
|
|
61
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ASSET_TRANSFER_BODY_MAX_BYTES, ASSET_TRANSFER_CHUNK_BODY_MAX_BYTES } from '@playcraft/common/cloud-workspace/runtime';
|
|
2
|
+
import { batchDirectoryHeld } from '../batch/occupancy.js';
|
|
3
|
+
import { revisionScope, workspaceRoot } from '../workspaces/registry.js';
|
|
4
|
+
import { AssetTransferError, cancelAssetTransfer, createAssetTransfer, getAssetTransfer, putAssetTransferChunk } from '../workspaces/asset-transfer-storage.js';
|
|
5
|
+
export async function handleAssetTransferRequest(state, request, url) {
|
|
6
|
+
const route = /^\/runtime\/asset-transfers(?:\/([^/]+)(?:\/(chunks))?)?$/.exec(url.pathname);
|
|
7
|
+
if (!route)
|
|
8
|
+
return undefined;
|
|
9
|
+
const workspaceId = url.searchParams.get('workspaceId') ?? '';
|
|
10
|
+
const directoryName = url.searchParams.get('directoryName') ?? 'basic';
|
|
11
|
+
try {
|
|
12
|
+
if (state.journal.destroyed())
|
|
13
|
+
throw new AssetTransferError('runtime_destroyed');
|
|
14
|
+
if (!/^(basic|remix-[a-z0-9][a-z0-9-]{3,63})$/.test(directoryName))
|
|
15
|
+
throw new AssetTransferError('invalid_workspace_directory', 400);
|
|
16
|
+
const [, id, action] = route;
|
|
17
|
+
const valid = !id && request.method === 'POST' || id && !action && ['GET', 'DELETE'].includes(request.method ?? '')
|
|
18
|
+
|| id && action === 'chunks' && request.method === 'PUT';
|
|
19
|
+
if (!valid)
|
|
20
|
+
return { status: 405, body: { error: 'asset_transfer_method_not_allowed' } };
|
|
21
|
+
const scope = { workspaceId, directoryName, environment: state.config.environment, userId: state.config.userId };
|
|
22
|
+
const body = ['POST', 'PUT'].includes(request.method ?? '')
|
|
23
|
+
? await readTransferJson(request, action ? ASSET_TRANSFER_CHUNK_BODY_MAX_BYTES : ASSET_TRANSFER_BODY_MAX_BYTES) : undefined;
|
|
24
|
+
return await state.journal.exclusive(`directory:${workspaceId}:${directoryName}`, async () => state.journal.exclusive(`workspace:${revisionScope(state, workspaceId, directoryName) ?? 'single'}`, async () => {
|
|
25
|
+
if (state.journal.destroyed())
|
|
26
|
+
throw new AssetTransferError('runtime_destroyed');
|
|
27
|
+
if (request.method !== 'GET' && await batchDirectoryHeld(state, workspaceId, directoryName))
|
|
28
|
+
throw new AssetTransferError('batch_workspace_readonly');
|
|
29
|
+
const root = await workspaceRoot(state, workspaceId, directoryName);
|
|
30
|
+
const result = !id ? await createAssetTransfer(root, scope, body)
|
|
31
|
+
: action ? await putAssetTransferChunk(root, scope, id, body)
|
|
32
|
+
: request.method === 'GET' ? await getAssetTransfer(root, scope, id) : await cancelAssetTransfer(root, scope, id);
|
|
33
|
+
return { status: 200, body: result };
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error instanceof AssetTransferError)
|
|
38
|
+
return { status: error.status, body: { error: error.code } };
|
|
39
|
+
if (error.name === 'ZodError')
|
|
40
|
+
return { status: 400, body: { error: 'invalid_asset_transfer' } };
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function readTransferJson(request, limit) {
|
|
45
|
+
const length = request.headers['content-length'];
|
|
46
|
+
if (length && (!/^\d+$/.test(length) || Number(length) > limit))
|
|
47
|
+
throw new AssetTransferError('asset_transfer_too_large', 413);
|
|
48
|
+
const parts = [];
|
|
49
|
+
let size = 0;
|
|
50
|
+
for await (const data of request) {
|
|
51
|
+
const bytes = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
52
|
+
size += bytes.length;
|
|
53
|
+
if (size > limit)
|
|
54
|
+
throw new AssetTransferError('asset_transfer_too_large', 413);
|
|
55
|
+
parts.push(bytes);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(Buffer.concat(parts).toString('utf8'));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
throw new AssetTransferError('invalid_asset_transfer', 400);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
2
|
+
export function extractControlToken(headers) {
|
|
3
|
+
const authorization = headerValue(headers.authorization);
|
|
4
|
+
if (authorization?.startsWith('Bearer ')) {
|
|
5
|
+
return authorization.slice('Bearer '.length).trim() || null;
|
|
6
|
+
}
|
|
7
|
+
const dedicated = headerValue(headers['x-playcraft-control-token']);
|
|
8
|
+
return dedicated?.trim() || null;
|
|
9
|
+
}
|
|
10
|
+
export function controlTokenMatches(expected, actual) {
|
|
11
|
+
if (!actual)
|
|
12
|
+
return false;
|
|
13
|
+
const left = Buffer.from(expected);
|
|
14
|
+
const right = Buffer.from(actual);
|
|
15
|
+
if (left.length !== right.length)
|
|
16
|
+
return false;
|
|
17
|
+
return timingSafeEqual(left, right);
|
|
18
|
+
}
|
|
19
|
+
function headerValue(value) {
|
|
20
|
+
return Array.isArray(value) ? value[0] : value;
|
|
21
|
+
}
|