@playcraft/cli 0.1.42 → 0.1.44-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 +62 -3
- package/SKILLS_REGISTRY.md +149 -0
- package/dist/agent/local-backend.js +1 -1
- package/dist/auth/account-activation.js +157 -0
- package/dist/auth/messages.js +30 -0
- package/dist/cli-root-help.js +2 -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.js +2 -6
- 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/skills.js +4 -0
- package/dist/commands/tools-3d.js +11 -0
- package/dist/commands/tools-batch.js +105 -0
- package/dist/commands/tools-generation.js +69 -137
- package/dist/commands/tools-utils.js +0 -12
- package/dist/commands/tools.js +2 -2
- 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 +40 -3
- 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 +210 -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 +233 -0
- package/dist/workspace/transfer-errors.js +48 -0
- package/dist/workspace-runtime/batch/control.js +80 -0
- package/dist/workspace-runtime/batch/deliver.js +150 -0
- package/dist/workspace-runtime/batch/freeze.js +102 -0
- package/dist/workspace-runtime/batch/generate.js +205 -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 +202 -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 +58 -0
- package/dist/workspace-runtime/batch/source-capture.js +159 -0
- package/dist/workspace-runtime/codex/app-server.js +1040 -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/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/ui-instructions.js +4 -0
- package/dist/workspace-runtime/codex/ui-tools.js +186 -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/output.js +36 -0
- package/dist/workspace-runtime/previews/publish.js +262 -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/production/content-changes.js +36 -0
- package/dist/workspace-runtime/production/contracts.js +19 -0
- package/dist/workspace-runtime/production/controller.js +228 -0
- package/dist/workspace-runtime/production/dependencies.js +60 -0
- package/dist/workspace-runtime/production/native.js +239 -0
- package/dist/workspace-runtime/production/processes.js +102 -0
- package/dist/workspace-runtime/production/save-command.js +35 -0
- package/dist/workspace-runtime/production/source-archive.js +137 -0
- package/dist/workspace-runtime/production/source-copy.js +92 -0
- package/dist/workspace-runtime/production/stages.js +354 -0
- package/dist/workspace-runtime/production/storage.js +75 -0
- package/dist/workspace-runtime/serve.js +283 -0
- package/dist/workspace-runtime/server/auth.js +21 -0
- package/dist/workspace-runtime/server/connectivity.js +209 -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 +1339 -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 +1297 -0
- package/dist/workspace-runtime/server/lock.js +53 -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/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/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 +366 -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 +112 -0
- package/dist/workspace-runtime/workspaces/cli-context.js +23 -0
- package/dist/workspace-runtime/workspaces/cli-credentials.js +111 -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/dependencies.js +264 -0
- package/dist/workspace-runtime/workspaces/developer-command.js +64 -0
- package/dist/workspace-runtime/workspaces/directories.js +137 -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-stats.js +49 -0
- package/dist/workspace-runtime/workspaces/disk-snapshot.js +31 -0
- package/dist/workspace-runtime/workspaces/empty-template.js +42 -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 +170 -0
- package/dist/workspace-runtime/workspaces/library-attachments.js +268 -0
- package/dist/workspace-runtime/workspaces/optional-platform-skills.js +14 -0
- package/dist/workspace-runtime/workspaces/parameters.js +272 -0
- package/dist/workspace-runtime/workspaces/prepare.js +278 -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/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/package.json +15 -5
- package/project-template/.claude/agents/refs/ta-image-generation-detail.md +123 -67
- package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +63 -135
- package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +33 -42
- package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +20 -18
- package/project-template/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +7 -6
- package/project-template/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +39 -39
- 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-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 +280 -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 +298 -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 +324 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +97 -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 +137 -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/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 +219 -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/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 +41 -0
- package/project-templates/empty/gitignore +33 -0
- package/project-templates/phaser/.claude/agents/refs/ta-image-generation-detail.md +59 -59
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/SKILL.md +63 -135
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +33 -42
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +20 -18
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +7 -6
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +39 -39
- package/project-templates/threejs/.claude/agents/refs/ta-image-generation-detail.md +59 -59
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/SKILL.md +63 -135
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +33 -42
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +20 -18
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +7 -6
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +39 -39
- package/dist/commands/tools-image-context.js +0 -29
- package/dist/utils/image-asset-context.js +0 -228
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
+
import { hashOperationPayload, operationScopeKey, sandboxBatchMemberGenerateSchema, } from '@playcraft/common/cloud-workspace/runtime';
|
|
6
|
+
import { attachNativeCollector, executeOperation } from '../server/dispatch.js';
|
|
7
|
+
import { workspaceRoot } from '../workspaces/registry.js';
|
|
8
|
+
import { bindMemberPolicy, memberExecutionPolicy } from './policy.js';
|
|
9
|
+
import { groupExited, stopProcessGroup } from './processes.js';
|
|
10
|
+
import { memberStatus, readMember, readStopMarker, serializeRun, writeMember } from './records.js';
|
|
11
|
+
function hashCommand(value) {
|
|
12
|
+
return hashOperationPayload(value);
|
|
13
|
+
}
|
|
14
|
+
function operation(state, input) {
|
|
15
|
+
const now = new Date().toISOString();
|
|
16
|
+
const record = {
|
|
17
|
+
operationId: randomUUID(), environment: state.config.environment, userId: state.config.userId,
|
|
18
|
+
clientRequestId: input.clientRequestId, kind: input.kind, status: 'queued', payloadHash: hashOperationPayload(input.payload),
|
|
19
|
+
workspaceId: input.workspaceId, directoryName: input.directoryName, sessionId: input.sessionId,
|
|
20
|
+
generation: state.config.generation, runtimeEpoch: state.runtimeEpoch, leaseFence: state.acceptedLeaseFence,
|
|
21
|
+
createdAt: now, updatedAt: now,
|
|
22
|
+
};
|
|
23
|
+
return { scopeKey: operationScopeKey(record), record };
|
|
24
|
+
}
|
|
25
|
+
function turnTerminal(event) {
|
|
26
|
+
if (event.kind === 'approval_request')
|
|
27
|
+
return 'needs_user';
|
|
28
|
+
if (event.method !== 'turn/completed' && event.method !== 'turn.completed' && event.method !== 'turn.failed' && event.method !== 'turn.interrupted')
|
|
29
|
+
return undefined;
|
|
30
|
+
const turn = event.params && typeof event.params === 'object' ? event.params.turn : undefined;
|
|
31
|
+
if (event.method === 'turn.failed' || turn?.status === 'failed')
|
|
32
|
+
return 'failed';
|
|
33
|
+
if (event.method === 'turn.interrupted' || turn?.status === 'interrupted')
|
|
34
|
+
return 'interrupted';
|
|
35
|
+
return 'completed';
|
|
36
|
+
}
|
|
37
|
+
function threadIdOf(event) {
|
|
38
|
+
const params = event.params && typeof event.params === 'object' ? event.params : undefined;
|
|
39
|
+
return typeof params?.threadId === 'string' ? params.threadId : undefined;
|
|
40
|
+
}
|
|
41
|
+
async function proveStopped(record) {
|
|
42
|
+
let stopped = true;
|
|
43
|
+
for (const process of record.processes) {
|
|
44
|
+
if (process.stopped || groupExited(process.pid))
|
|
45
|
+
process.stopped = true;
|
|
46
|
+
else {
|
|
47
|
+
const did = await stopProcessGroup(process);
|
|
48
|
+
process.stopped = did;
|
|
49
|
+
if (!did)
|
|
50
|
+
stopped = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return stopped;
|
|
54
|
+
}
|
|
55
|
+
export async function generateBatchMember(state, body) {
|
|
56
|
+
if (!body || typeof body !== 'object' || !('occupancyId' in body) || !body.occupancyId)
|
|
57
|
+
throw new Error('occupancy_required');
|
|
58
|
+
const parsed = sandboxBatchMemberGenerateSchema.safeParse(body);
|
|
59
|
+
if (!parsed.success)
|
|
60
|
+
throw new Error('invalid_batch_request');
|
|
61
|
+
const command = parsed.data;
|
|
62
|
+
const hash = hashCommand(command);
|
|
63
|
+
return serializeRun(command.runId, async () => {
|
|
64
|
+
attachNativeCollector(state);
|
|
65
|
+
const existing = await readMember(state, command.runId);
|
|
66
|
+
if (existing && command.ownerFence < existing.ownerFence)
|
|
67
|
+
throw new Error('stale_owner');
|
|
68
|
+
if (await readStopMarker(state, command.runId))
|
|
69
|
+
return memberStatus(await stoppedRecord(state, command, existing));
|
|
70
|
+
if (existing && existing.ownerFence === command.ownerFence && existing.commandHash?.generate === hash && existing.phase === 'generate' && existing.state !== 'running') {
|
|
71
|
+
return memberStatus(await reconcileGenerate(state, existing));
|
|
72
|
+
}
|
|
73
|
+
if (existing && existing.ownerFence === command.ownerFence && existing.commandHash?.generate && existing.commandHash.generate !== hash)
|
|
74
|
+
throw new Error('batch_command_conflict');
|
|
75
|
+
const root = await workspaceRoot(state, command.workspaceId, command.directoryName);
|
|
76
|
+
const sessionId = command.sessionId ?? existing?.sessionId ?? `member-${command.runId}`;
|
|
77
|
+
const tempDir = join(state.config.stateDir, 'batch-temp', command.runId);
|
|
78
|
+
await mkdir(tempDir, { recursive: true, mode: 0o700 });
|
|
79
|
+
const policy = memberExecutionPolicy(root, tempDir);
|
|
80
|
+
await bindMemberPolicy(state, sessionId, policy);
|
|
81
|
+
const turnPayload = { text: command.prompt, permissionMode: 'auto', ...(command.model && /^[0-9a-f-]{36}$/i.test(command.model) ? { modelConfigId: command.model } : {}) };
|
|
82
|
+
const turnKey = operation(state, { kind: 'session.turn', clientRequestId: `batch-turn:${command.runId}`, sessionId, workspaceId: command.workspaceId, directoryName: command.directoryName, payload: turnPayload });
|
|
83
|
+
const prior = state.journal.getOperation(turnKey.scopeKey);
|
|
84
|
+
if (prior && prior.payloadHash !== turnKey.record.payloadHash)
|
|
85
|
+
throw new Error('batch_command_conflict');
|
|
86
|
+
let record = await writeMember(state, {
|
|
87
|
+
runId: command.runId, ownerFence: command.ownerFence, occupancyId: command.occupancyId, workspaceId: command.workspaceId,
|
|
88
|
+
directoryName: command.directoryName, phase: 'generate', state: prior ? (prior.status === 'uncertain' ? 'unknown' : prior.status === 'completed' ? 'completed' : 'running') : 'running',
|
|
89
|
+
writersStopped: false, holding: true, stopRequested: false, processes: existing?.processes ?? [], sessionId,
|
|
90
|
+
operationId: prior?.operationId, commandHash: { ...existing?.commandHash, generate: hash },
|
|
91
|
+
snapshotDigest: existing?.snapshotDigest, branchName: existing?.branchName, headCommit: existing?.headCommit,
|
|
92
|
+
updatedAt: new Date().toISOString(),
|
|
93
|
+
});
|
|
94
|
+
if (prior)
|
|
95
|
+
return memberStatus(await finishGenerate(state, record, prior, root));
|
|
96
|
+
if (!state.native?.ready()) {
|
|
97
|
+
record = await writeMember(state, { ...record, state: 'failed', writersStopped: true, holding: false, error: 'capability_unavailable' });
|
|
98
|
+
return memberStatus(record);
|
|
99
|
+
}
|
|
100
|
+
const terminals = new Map();
|
|
101
|
+
const unsubscribe = state.native.onCollected?.((event) => {
|
|
102
|
+
const threadId = threadIdOf(event);
|
|
103
|
+
const terminal = turnTerminal(event);
|
|
104
|
+
if (!threadId || !terminal)
|
|
105
|
+
return;
|
|
106
|
+
if (terminals.get(threadId) === 'needs_user')
|
|
107
|
+
return;
|
|
108
|
+
terminals.set(threadId, terminal);
|
|
109
|
+
});
|
|
110
|
+
try {
|
|
111
|
+
if (!state.journal.getSession(sessionId)) {
|
|
112
|
+
const created = operation(state, { kind: 'session.create', clientRequestId: `batch-create:${command.runId}`, sessionId, workspaceId: command.workspaceId, directoryName: command.directoryName, payload: { permissionMode: 'auto' } });
|
|
113
|
+
if (!state.journal.getOperation(created.scopeKey))
|
|
114
|
+
await executeOperation(state, created.scopeKey, created.record, { permissionMode: 'auto' });
|
|
115
|
+
}
|
|
116
|
+
if (await readStopMarker(state, command.runId))
|
|
117
|
+
return memberStatus(await stoppedRecord(state, command, record));
|
|
118
|
+
const started = await executeOperation(state, turnKey.scopeKey, turnKey.record, turnPayload);
|
|
119
|
+
record = await writeMember(state, { ...record, operationId: started.operationId, sessionId });
|
|
120
|
+
return memberStatus(await finishGenerate(state, record, started, root, () => {
|
|
121
|
+
const threadId = state.journal.getSession(sessionId)?.threadId;
|
|
122
|
+
return threadId ? terminals.get(threadId) : undefined;
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
unsubscribe?.();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async function finishGenerate(state, record, started, root, early) {
|
|
131
|
+
if (await readStopMarker(state, record.runId))
|
|
132
|
+
return stoppedRecord(state, { ...record, occupancyId: record.occupancyId }, record);
|
|
133
|
+
const sessionId = record.sessionId;
|
|
134
|
+
let terminal = early?.();
|
|
135
|
+
if (!terminal && (started.status === 'uncertain' || started.error === 'native_receipt_lost')) {
|
|
136
|
+
return writeMember(state, { ...record, state: 'unknown', writersStopped: false, holding: true, operationId: started.operationId, error: 'native_receipt_lost' });
|
|
137
|
+
}
|
|
138
|
+
if (!terminal && started.status === 'failed') {
|
|
139
|
+
const writersStopped = await proveStopped(record);
|
|
140
|
+
return writeMember(state, { ...record, state: writersStopped ? 'failed' : 'stopping', writersStopped, holding: !writersStopped, operationId: started.operationId, error: started.error ?? 'batch_turn_failed' });
|
|
141
|
+
}
|
|
142
|
+
const deadline = Date.now() + 5_000;
|
|
143
|
+
while (!terminal && Date.now() < deadline) {
|
|
144
|
+
terminal = early?.();
|
|
145
|
+
const session = state.journal.getSession(sessionId);
|
|
146
|
+
if (session?.turnStatus === 'waiting_for_user')
|
|
147
|
+
terminal = 'needs_user';
|
|
148
|
+
else if (session?.turnStatus === 'completed')
|
|
149
|
+
terminal = 'completed';
|
|
150
|
+
else if (session?.turnStatus === 'failed')
|
|
151
|
+
terminal = 'failed';
|
|
152
|
+
else if (session?.turnStatus === 'interrupted')
|
|
153
|
+
terminal = 'interrupted';
|
|
154
|
+
if (!terminal)
|
|
155
|
+
await delay(15);
|
|
156
|
+
}
|
|
157
|
+
if (terminal === 'needs_user') {
|
|
158
|
+
const session = state.journal.getSession(sessionId);
|
|
159
|
+
if (session?.threadId)
|
|
160
|
+
await state.native?.interrupt?.({ sessionId, threadId: session.threadId }).catch(() => undefined);
|
|
161
|
+
const writersStopped = await proveStopped(record);
|
|
162
|
+
if (await readStopMarker(state, record.runId))
|
|
163
|
+
return stoppedRecord(state, record, record);
|
|
164
|
+
return writeMember(state, {
|
|
165
|
+
...record, state: writersStopped ? 'needs_user' : 'stopping', writersStopped, holding: writersStopped ? false : true,
|
|
166
|
+
operationId: started.operationId, error: writersStopped ? 'needs_user' : undefined,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (terminal === 'completed') {
|
|
170
|
+
const writersStopped = await proveStopped(record);
|
|
171
|
+
if (!writersStopped)
|
|
172
|
+
return writeMember(state, { ...record, state: 'stopping', writersStopped: false, holding: true, operationId: started.operationId });
|
|
173
|
+
if (await readStopMarker(state, record.runId))
|
|
174
|
+
return stoppedRecord(state, record, record);
|
|
175
|
+
const head = await import('./git.js').then(git => git.gitRead(root, ['rev-parse', 'HEAD'])).then(value => value.trim()).catch(() => record.headCommit);
|
|
176
|
+
return writeMember(state, { ...record, state: 'completed', writersStopped: true, holding: true, operationId: started.operationId, headCommit: head, error: undefined });
|
|
177
|
+
}
|
|
178
|
+
const writersStopped = await proveStopped(record);
|
|
179
|
+
return writeMember(state, {
|
|
180
|
+
...record, state: writersStopped ? (terminal === 'interrupted' ? 'stopped' : 'failed') : 'unknown',
|
|
181
|
+
writersStopped, holding: !writersStopped, operationId: started.operationId,
|
|
182
|
+
error: writersStopped ? (terminal === 'interrupted' ? undefined : 'batch_turn_failed') : 'native_receipt_lost',
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async function reconcileGenerate(state, record) {
|
|
186
|
+
const session = record.sessionId ? state.journal.getSession(record.sessionId) : undefined;
|
|
187
|
+
if (record.state === 'unknown' && session?.turnStatus === 'completed') {
|
|
188
|
+
const writersStopped = await proveStopped(record);
|
|
189
|
+
if (writersStopped && !await readStopMarker(state, record.runId)) {
|
|
190
|
+
return writeMember(state, { ...record, state: 'completed', writersStopped: true, holding: true, error: undefined });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return record;
|
|
194
|
+
}
|
|
195
|
+
async function stoppedRecord(state, command, existing) {
|
|
196
|
+
if (existing)
|
|
197
|
+
await proveStopped(existing);
|
|
198
|
+
return writeMember(state, {
|
|
199
|
+
runId: command.runId, ownerFence: command.ownerFence, occupancyId: command.occupancyId, workspaceId: command.workspaceId,
|
|
200
|
+
directoryName: command.directoryName, phase: existing?.phase ?? 'generate', state: 'stopped', writersStopped: true, holding: false,
|
|
201
|
+
stopRequested: true, processes: existing?.processes ?? [], sessionId: existing?.sessionId, operationId: existing?.operationId,
|
|
202
|
+
headCommit: existing?.headCommit, evidence: existing?.evidence, commandHash: existing?.commandHash, snapshotDigest: existing?.snapshotDigest,
|
|
203
|
+
branchName: existing?.branchName, updatedAt: new Date().toISOString(),
|
|
204
|
+
});
|
|
205
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
const execute = promisify(execFile);
|
|
5
|
+
/** Read-only git. An empty credential helper keeps the source checkout from authenticating or writing. */
|
|
6
|
+
export async function gitRead(root, args) {
|
|
7
|
+
return runGit(root, ['-c', 'credential.helper=', ...args]);
|
|
8
|
+
}
|
|
9
|
+
/** Push and fetch. Local credential helpers copied onto this repo stay in effect. */
|
|
10
|
+
export async function gitWrite(root, args) {
|
|
11
|
+
return runGit(root, args);
|
|
12
|
+
}
|
|
13
|
+
async function runGit(root, args) {
|
|
14
|
+
const { stdout } = await execute('git', [
|
|
15
|
+
'-c', 'core.hooksPath=/dev/null', '-c', 'init.templateDir=', '-c', 'core.fsmonitor=false', '-C', root, ...args,
|
|
16
|
+
], {
|
|
17
|
+
timeout: 90_000, maxBuffer: 64 * 1024 * 1024,
|
|
18
|
+
env: {
|
|
19
|
+
PATH: process.env.PATH, HOME: dirname(root), GIT_OPTIONAL_LOCKS: '0',
|
|
20
|
+
GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1', GIT_TERMINAL_PROMPT: '0',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return stdout;
|
|
24
|
+
}
|
|
25
|
+
/** Copies URL credential helpers onto a snapshot repo without reading or writing the source config. */
|
|
26
|
+
export async function copyCredentialHelpers(sourceRoot, destinationRoot) {
|
|
27
|
+
const listed = await gitRead(sourceRoot, ['config', '--local', '--get-regexp', '^(credential\\.|http\\.|url\\.)']).catch(() => '');
|
|
28
|
+
for (const line of listed.split('\n')) {
|
|
29
|
+
if (!line)
|
|
30
|
+
continue;
|
|
31
|
+
const space = line.indexOf(' ');
|
|
32
|
+
if (space < 1)
|
|
33
|
+
continue;
|
|
34
|
+
const key = line.slice(0, space);
|
|
35
|
+
const value = line.slice(space + 1);
|
|
36
|
+
if (!/^(credential\.|http\.|url\.)/.test(key) || /[\r\n]/.test(value))
|
|
37
|
+
continue;
|
|
38
|
+
await gitWrite(destinationRoot, ['config', '--local', key, value]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { listMembers } from './records.js';
|
|
2
|
+
/** True while a member Run still holds the directory. Other sandbox write entries must refuse it. */
|
|
3
|
+
export async function batchDirectoryHeld(state, workspaceId, directoryName) {
|
|
4
|
+
if (!workspaceId)
|
|
5
|
+
return false;
|
|
6
|
+
const members = await listMembers(state);
|
|
7
|
+
return members.some(record => record.holding && record.workspaceId === workspaceId && record.directoryName === directoryName);
|
|
8
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readFileSync, mkdirSync, writeFileSync, renameSync } from 'node:fs';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
const memory = new WeakMap();
|
|
5
|
+
/** Unattended member execution: workspace-write to the member directory and one controlled temp dir. */
|
|
6
|
+
export function memberExecutionPolicy(cwd, tempDir) {
|
|
7
|
+
return {
|
|
8
|
+
cwd,
|
|
9
|
+
approvalPolicy: 'never',
|
|
10
|
+
sandboxPolicy: {
|
|
11
|
+
type: 'workspaceWrite',
|
|
12
|
+
writableRoots: [cwd, tempDir],
|
|
13
|
+
networkAccess: true,
|
|
14
|
+
excludeTmpdirEnvVar: true,
|
|
15
|
+
excludeSlashTmp: true,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function policyPath(state, sessionId) {
|
|
20
|
+
return join(state.config.stateDir, 'batch-sessions', `${sessionId.replace(/[^a-zA-Z0-9._-]/g, '_')}.json`);
|
|
21
|
+
}
|
|
22
|
+
function parsePolicy(raw) {
|
|
23
|
+
const value = JSON.parse(raw);
|
|
24
|
+
if (value?.approvalPolicy !== 'never' || value.sandboxPolicy?.type !== 'workspaceWrite')
|
|
25
|
+
return undefined;
|
|
26
|
+
if (!value.cwd || !Array.isArray(value.sandboxPolicy.writableRoots) || value.sandboxPolicy.writableRoots.length === 0)
|
|
27
|
+
return undefined;
|
|
28
|
+
if (!value.sandboxPolicy.excludeSlashTmp || !value.sandboxPolicy.excludeTmpdirEnvVar)
|
|
29
|
+
return undefined;
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
export async function bindMemberPolicy(state, sessionId, policy) {
|
|
33
|
+
const path = policyPath(state, sessionId);
|
|
34
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
35
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
36
|
+
writeFileSync(temporary, JSON.stringify(policy), { mode: 0o600 });
|
|
37
|
+
renameSync(temporary, path);
|
|
38
|
+
const map = memory.get(state) ?? new Map();
|
|
39
|
+
map.set(sessionId, policy);
|
|
40
|
+
memory.set(state, map);
|
|
41
|
+
}
|
|
42
|
+
/** Synchronous: the shared session adapter reapplies this on every thread start and resume. */
|
|
43
|
+
export function trustedMemberPolicy(state, sessionId) {
|
|
44
|
+
const cached = memory.get(state)?.get(sessionId);
|
|
45
|
+
if (cached)
|
|
46
|
+
return cached;
|
|
47
|
+
try {
|
|
48
|
+
const parsed = parsePolicy(readFileSync(policyPath(state, sessionId), 'utf8'));
|
|
49
|
+
if (!parsed) {
|
|
50
|
+
return {
|
|
51
|
+
cwd: state.config.workspaceRoot,
|
|
52
|
+
approvalPolicy: 'never',
|
|
53
|
+
sandboxPolicy: { type: 'readOnly', networkAccess: false },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const map = memory.get(state) ?? new Map();
|
|
57
|
+
map.set(sessionId, parsed);
|
|
58
|
+
memory.set(state, map);
|
|
59
|
+
return parsed;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error.code === 'ENOENT')
|
|
63
|
+
return undefined;
|
|
64
|
+
return {
|
|
65
|
+
cwd: state.config.workspaceRoot,
|
|
66
|
+
approvalPolicy: 'never',
|
|
67
|
+
sandboxPolicy: { type: 'readOnly', networkAccess: false },
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
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 { digestFiles, readSourceFiles, 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 = ['pnpm-lock.yaml', 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'bun.lock', 'bun.lockb'];
|
|
14
|
+
export function frozenInstallCommand() {
|
|
15
|
+
return process.env.PLAYCRAFT_BATCH_INSTALL_COMMAND
|
|
16
|
+
?? 'pnpm install --frozen-lockfile --store-dir /var/cache/playcraft/pnpm-store --ignore-scripts';
|
|
17
|
+
}
|
|
18
|
+
function hashCommand(value) {
|
|
19
|
+
return createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
20
|
+
}
|
|
21
|
+
async function materialize(state, snapshot, destination, store, sourceRoot) {
|
|
22
|
+
const cache = sourceCacheDir(state, snapshot.batchId);
|
|
23
|
+
const cachedDigest = await readFile(`${cache}.digest`, 'utf8').catch(() => '');
|
|
24
|
+
if (cachedDigest.trim() === snapshot.digest && await lstat(join(cache, '.git')).catch(() => undefined)) {
|
|
25
|
+
await gitWrite(dirnameOf(destination), ['clone', '--local', '--no-hardlinks', '--', cache, destination]);
|
|
26
|
+
if (digestFiles(await readSourceFiles(destination)) !== snapshot.digest)
|
|
27
|
+
throw new Error('batch_snapshot_mismatch');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (snapshot.remoteRef) {
|
|
31
|
+
const binding = state.journal.getWorkspace(snapshot.sourceWorkspaceId);
|
|
32
|
+
if (!binding?.repositoryUrl)
|
|
33
|
+
throw new Error('batch_snapshot_mismatch');
|
|
34
|
+
await gitWrite(dirnameOf(destination), ['init', '--initial-branch', 'source', destination]);
|
|
35
|
+
await copyCredentialHelpers(sourceRoot, destination);
|
|
36
|
+
await gitWrite(destination, ['remote', 'add', 'origin', binding.repositoryUrl]);
|
|
37
|
+
try {
|
|
38
|
+
await gitWrite(destination, ['fetch', '--no-tags', 'origin', snapshot.remoteRef]);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw new Error('batch_snapshot_mismatch');
|
|
42
|
+
}
|
|
43
|
+
await gitWrite(destination, ['checkout', '--detach', 'FETCH_HEAD']);
|
|
44
|
+
if ((await gitRead(destination, ['rev-parse', 'HEAD'])).trim() !== snapshot.commitHash)
|
|
45
|
+
throw new Error('batch_snapshot_mismatch');
|
|
46
|
+
if (digestFiles(await readSourceFiles(destination)) !== snapshot.digest)
|
|
47
|
+
throw new Error('batch_snapshot_mismatch');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!snapshot.artifactKey)
|
|
51
|
+
throw new Error('batch_snapshot_mismatch');
|
|
52
|
+
const body = await store.get(snapshot.artifactKey).catch(() => { throw new Error('batch_snapshot_mismatch'); });
|
|
53
|
+
await restoreArchive(body, destination, snapshot.digest);
|
|
54
|
+
}
|
|
55
|
+
function dirnameOf(path) {
|
|
56
|
+
return join(path, '..');
|
|
57
|
+
}
|
|
58
|
+
async function checkoutBranch(root, branchName, commit, repositoryUrl) {
|
|
59
|
+
await gitWrite(root, ['checkout', '-B', branchName, commit]);
|
|
60
|
+
const origin = await gitRead(root, ['remote', 'get-url', 'origin']).catch(() => '');
|
|
61
|
+
if (!origin.trim())
|
|
62
|
+
await gitWrite(root, ['remote', 'add', 'origin', repositoryUrl]);
|
|
63
|
+
else if (origin.trim() !== repositoryUrl)
|
|
64
|
+
await gitWrite(root, ['remote', 'set-url', 'origin', repositoryUrl]);
|
|
65
|
+
await gitWrite(root, ['config', 'user.name', 'PlayCraft']);
|
|
66
|
+
await gitWrite(root, ['config', 'user.email', 'playcraft@localhost']);
|
|
67
|
+
}
|
|
68
|
+
async function resumeBranch(repositoryUrl, branchName, commit, destination, sourceRoot) {
|
|
69
|
+
await gitWrite(dirnameOf(destination), ['clone', '--branch', branchName, '--single-branch', '--', repositoryUrl, destination]);
|
|
70
|
+
await copyCredentialHelpers(sourceRoot, destination);
|
|
71
|
+
if ((await gitRead(destination, ['rev-parse', 'HEAD'])).trim() !== commit && !(await gitRead(destination, ['cat-file', '-e', `${commit}^{commit}`]).then(() => true, () => false))) {
|
|
72
|
+
throw new Error('batch_commit_mismatch');
|
|
73
|
+
}
|
|
74
|
+
await gitWrite(destination, ['checkout', '-B', branchName, commit]);
|
|
75
|
+
}
|
|
76
|
+
export async function assertMemberDependencies(root) {
|
|
77
|
+
let manifest;
|
|
78
|
+
try {
|
|
79
|
+
manifest = await readFile(join(root, 'package.json'), 'utf8');
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (error.code === 'ENOENT')
|
|
83
|
+
return 'skip';
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
let names = [];
|
|
87
|
+
try {
|
|
88
|
+
const pkg = JSON.parse(manifest);
|
|
89
|
+
names = [...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})];
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
throw new Error('dependency_lock_mismatch');
|
|
93
|
+
}
|
|
94
|
+
const present = [];
|
|
95
|
+
for (const lock of LOCKS)
|
|
96
|
+
if (await lstat(join(root, lock)).catch(() => undefined))
|
|
97
|
+
present.push(lock);
|
|
98
|
+
if (present.length > 1)
|
|
99
|
+
throw new Error('dependency_locks_conflict');
|
|
100
|
+
if (present.length === 0)
|
|
101
|
+
return 'skip';
|
|
102
|
+
if (present[0] !== 'pnpm-lock.yaml')
|
|
103
|
+
throw new Error('dependency_lock_mismatch');
|
|
104
|
+
const lock = await readFile(join(root, 'pnpm-lock.yaml'), 'utf8');
|
|
105
|
+
if (names.some(name => !lock.includes(`${name}:`) && !lock.includes(`/${name}@`) && !lock.includes(`'${name}'`) && !lock.includes(`"${name}"`))) {
|
|
106
|
+
throw new Error('dependency_lock_mismatch');
|
|
107
|
+
}
|
|
108
|
+
return 'install';
|
|
109
|
+
}
|
|
110
|
+
export async function prepareBatchMember(state, body, options) {
|
|
111
|
+
if (!body || typeof body !== 'object' || !('occupancyId' in body) || !body.occupancyId)
|
|
112
|
+
throw new Error('occupancy_required');
|
|
113
|
+
const parsed = sandboxBatchMemberPrepareSchema.safeParse(body);
|
|
114
|
+
if (!parsed.success)
|
|
115
|
+
throw new Error(parsed.error.issues.some(issue => issue.path.includes('branchName')) ? 'batch_branch_invalid' : 'invalid_batch_request');
|
|
116
|
+
const command = parsed.data;
|
|
117
|
+
if (!BRANCH.test(command.branchName))
|
|
118
|
+
throw new Error('batch_branch_invalid');
|
|
119
|
+
const hash = hashCommand(command);
|
|
120
|
+
return serializeRun(command.runId, async () => {
|
|
121
|
+
const marker = await readStopMarker(state, command.runId);
|
|
122
|
+
const existing = await readMember(state, command.runId);
|
|
123
|
+
if (existing && command.ownerFence < existing.ownerFence)
|
|
124
|
+
throw new Error('stale_owner');
|
|
125
|
+
if (marker)
|
|
126
|
+
return memberStatus(await sealStopped(state, command, existing));
|
|
127
|
+
if (existing && existing.ownerFence === command.ownerFence && existing.commandHash?.prepare === hash && existing.state !== 'running' && existing.state !== 'failed') {
|
|
128
|
+
return memberStatus(existing);
|
|
129
|
+
}
|
|
130
|
+
if (existing && existing.ownerFence === command.ownerFence && existing.commandHash?.prepare && existing.commandHash.prepare !== hash)
|
|
131
|
+
throw new Error('batch_command_conflict');
|
|
132
|
+
if (existing?.processes.some(process => process.role === 'install' && !process.stopped && !groupExited(process.pid)))
|
|
133
|
+
return memberStatus(existing);
|
|
134
|
+
const snapshot = command.snapshot;
|
|
135
|
+
if ((await readSnapshot(state, snapshot.batchId))?.digest === snapshot.digest) {
|
|
136
|
+
/* The local snapshot record is an accelerator; the command snapshot remains authoritative. */
|
|
137
|
+
}
|
|
138
|
+
let record = await writeMember(state, {
|
|
139
|
+
runId: command.runId, ownerFence: command.ownerFence, occupancyId: command.occupancyId,
|
|
140
|
+
workspaceId: command.workspaceId, directoryName: command.directoryName, phase: 'prepare', state: 'running',
|
|
141
|
+
writersStopped: false, holding: true, stopRequested: false, processes: existing?.processes ?? [],
|
|
142
|
+
commandHash: { ...existing?.commandHash, prepare: hash }, snapshotDigest: snapshot.digest, branchName: command.branchName,
|
|
143
|
+
updatedAt: new Date().toISOString(),
|
|
144
|
+
});
|
|
145
|
+
const parent = await workspaceContainerRoot(state, command.workspaceId);
|
|
146
|
+
const root = join(parent, command.directoryName);
|
|
147
|
+
const staging = join(parent, `.batch-member-${randomUUID()}`);
|
|
148
|
+
const binding = state.journal.getWorkspace(command.workspaceId);
|
|
149
|
+
if (!binding?.repositoryUrl)
|
|
150
|
+
throw new Error('workspace_not_registered');
|
|
151
|
+
const sourceRoot = join(parent, snapshot.sourceDirectoryName);
|
|
152
|
+
try {
|
|
153
|
+
if (!await lstat(root).catch(() => undefined)) {
|
|
154
|
+
await mkdir(parent, { recursive: true });
|
|
155
|
+
if (command.resumeFromCommit)
|
|
156
|
+
await resumeBranch(binding.repositoryUrl, command.branchName, command.resumeFromCommit, staging, sourceRoot);
|
|
157
|
+
else
|
|
158
|
+
await materialize(state, snapshot, staging, options?.objectStore ?? filesystemObjectStore(state), sourceRoot);
|
|
159
|
+
const commit = command.resumeFromCommit ?? snapshot.commitHash;
|
|
160
|
+
await checkoutBranch(staging, command.branchName, commit, binding.repositoryUrl);
|
|
161
|
+
const { rename } = await import('node:fs/promises');
|
|
162
|
+
await rename(staging, root);
|
|
163
|
+
}
|
|
164
|
+
await registerWorkspaceDirectory(state, {
|
|
165
|
+
workspaceId: command.workspaceId, directoryName: command.directoryName, remixId: command.remixId,
|
|
166
|
+
branchName: command.branchName, sourceCommit: command.resumeFromCommit ?? snapshot.commitHash,
|
|
167
|
+
}, state.acceptedLeaseFence);
|
|
168
|
+
const plan = await assertMemberDependencies(root);
|
|
169
|
+
if (plan === 'install') {
|
|
170
|
+
const installed = await runProcessGroup(root, frozenInstallCommand(), 'install', async (process) => {
|
|
171
|
+
record = await writeMember(state, { ...record, processes: [...record.processes, process] });
|
|
172
|
+
});
|
|
173
|
+
record = await writeMember(state, { ...record, processes: record.processes.map(process => process.pid === installed.process.pid ? { ...installed.process, role: 'install' } : process) });
|
|
174
|
+
if (await readStopMarker(state, command.runId))
|
|
175
|
+
return memberStatus(await sealStopped(state, command, record));
|
|
176
|
+
if (installed.code !== 0)
|
|
177
|
+
throw new Error('batch_install_failed');
|
|
178
|
+
}
|
|
179
|
+
const head = (await gitRead(root, ['rev-parse', 'HEAD'])).trim();
|
|
180
|
+
record = await writeMember(state, { ...record, state: 'completed', writersStopped: true, holding: true, headCommit: head, error: undefined });
|
|
181
|
+
return memberStatus(record);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
const code = error instanceof Error && /^[a-z0-9_]+$/.test(error.message) ? error.message : 'batch_prepare_failed';
|
|
185
|
+
record = await writeMember(state, { ...record, state: 'failed', writersStopped: true, holding: false, error: code });
|
|
186
|
+
return memberStatus(record);
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
await rm(staging, { recursive: true, force: true });
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async function sealStopped(state, command, existing) {
|
|
194
|
+
return writeMember(state, {
|
|
195
|
+
runId: command.runId, ownerFence: Math.max(command.ownerFence, existing?.ownerFence ?? 0), occupancyId: command.occupancyId,
|
|
196
|
+
workspaceId: command.workspaceId, directoryName: command.directoryName, phase: existing?.phase ?? 'prepare',
|
|
197
|
+
state: 'stopped', writersStopped: true, holding: false, stopRequested: true, processes: existing?.processes ?? [],
|
|
198
|
+
sessionId: existing?.sessionId, operationId: existing?.operationId, headCommit: existing?.headCommit, evidence: existing?.evidence,
|
|
199
|
+
commandHash: existing?.commandHash, snapshotDigest: existing?.snapshotDigest, branchName: existing?.branchName,
|
|
200
|
+
updatedAt: new Date().toISOString(),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
@@ -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
|
+
}
|