@playcraft/cli 0.1.29 → 0.1.31
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 +38 -3
- 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.js +9 -4
- 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 +2 -0
- package/dist/commands/tools-3d.js +11 -0
- package/dist/commands/tools-batch.js +87 -0
- package/dist/commands/tools-generation.js +68 -109
- package/dist/commands/tools.js +2 -2
- package/dist/commands/video.js +111 -0
- package/dist/commands/workspace-runtime.js +54 -0
- package/dist/config.js +59 -4
- package/dist/index.js +34 -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/utils/agent-api-client.js +185 -30
- package/dist/utils/environment-endpoints.js +17 -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 +222 -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 +216 -0
- package/dist/video-replication/evidence.js +165 -0
- package/dist/video-replication/media.js +111 -0
- package/dist/video-replication/messages.js +89 -0
- package/dist/workspace-runtime/codex/app-server.js +965 -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 +70 -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 +355 -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 +1096 -0
- package/dist/workspace-runtime/previews/publish.js +259 -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/contracts.js +17 -0
- package/dist/workspace-runtime/production/controller.js +207 -0
- package/dist/workspace-runtime/production/dependencies.js +60 -0
- package/dist/workspace-runtime/production/native.js +203 -0
- package/dist/workspace-runtime/production/processes.js +86 -0
- package/dist/workspace-runtime/production/save-command.js +35 -0
- package/dist/workspace-runtime/production/source-copy.js +91 -0
- package/dist/workspace-runtime/production/stages.js +205 -0
- package/dist/workspace-runtime/production/storage.js +32 -0
- package/dist/workspace-runtime/serve.js +207 -0
- package/dist/workspace-runtime/server/auth.js +21 -0
- package/dist/workspace-runtime/server/connectivity.js +201 -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 +1116 -0
- package/dist/workspace-runtime/server/endpoints.js +19 -0
- package/dist/workspace-runtime/server/execution-group.js +85 -0
- package/dist/workspace-runtime/server/http.js +1038 -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/terminal-host.js +366 -0
- package/dist/workspace-runtime/server/types.js +1 -0
- package/dist/workspace-runtime/workspaces/artifact-events.js +55 -0
- package/dist/workspace-runtime/workspaces/artifact-files.js +195 -0
- package/dist/workspace-runtime/workspaces/artifact-receipts.js +89 -0
- package/dist/workspace-runtime/workspaces/artifacts.js +260 -0
- package/dist/workspace-runtime/workspaces/attachment-content.js +111 -0
- package/dist/workspace-runtime/workspaces/attachments.js +175 -0
- package/dist/workspace-runtime/workspaces/batch-commit.js +142 -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 +125 -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 +116 -0
- package/dist/workspace-runtime/workspaces/directory-access.js +37 -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 +40 -0
- package/dist/workspace-runtime/workspaces/files-search.js +116 -0
- package/dist/workspace-runtime/workspaces/files.js +120 -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 +517 -0
- package/dist/workspace-runtime/workspaces/json5-edit.js +170 -0
- package/dist/workspace-runtime/workspaces/parameters.js +272 -0
- package/dist/workspace-runtime/workspaces/prepare.js +264 -0
- package/dist/workspace-runtime/workspaces/registry.js +234 -0
- package/dist/workspace-runtime/workspaces/revisions.js +31 -0
- package/dist/workspace-runtime/workspaces/skill-artifact-loader.js +91 -0
- package/dist/workspace-runtime/workspaces/skills.js +189 -0
- package/dist/workspace-runtime/workspaces/video-attachments.js +49 -0
- package/package.json +14 -5
- package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +23 -81
- 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 +25 -0
- package/project-templates/empty/gitignore +33 -0
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/SKILL.md +23 -81
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/SKILL.md +23 -81
- package/dist/commands/tools-image-context.js +0 -23
- package/dist/utils/image-asset-context.js +0 -105
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { lstat, mkdir, realpath, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join, relative } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { isLocalWorkspaceGitAuthMode, sameWorkspaceRegistration, workspaceRegistrationSchema, } from '@playcraft/common/cloud-workspace/runtime';
|
|
6
|
+
import { prepareWorkspaceCheckout } from './prepare.js';
|
|
7
|
+
import { WorkspaceContextError } from './context-error.js';
|
|
8
|
+
import { scheduleDependencyInstall } from './dependencies.js';
|
|
9
|
+
import { ensureWorkspaceSkills, readWorkspaceSkills } from './skills.js';
|
|
10
|
+
import { loadWorkspaceSkillArtifact, workspacePlatformSkillAccess } from './skill-artifact-loader.js';
|
|
11
|
+
import { writeWorkspaceCliContext } from './cli-context.js';
|
|
12
|
+
import { attachWorkspaceRemote } from './git.js';
|
|
13
|
+
export { WorkspaceContextError } from './context-error.js';
|
|
14
|
+
const exec = promisify(execFile);
|
|
15
|
+
export function revisionScope(state, workspaceId, directoryName = 'basic') {
|
|
16
|
+
return state.config.workspaceMode === 'multi' ? `${workspaceId}:${directoryName}` : undefined;
|
|
17
|
+
}
|
|
18
|
+
export function workspaceSessions(state, workspaceId, directoryName = 'basic') {
|
|
19
|
+
return state.journal
|
|
20
|
+
.listSessions()
|
|
21
|
+
.filter((item) => state.config.workspaceMode !== 'multi' || (item.workspaceId === workspaceId && (item.directoryName ?? 'basic') === directoryName));
|
|
22
|
+
}
|
|
23
|
+
export async function workspaceRoot(state, workspaceId, directoryName = 'basic') {
|
|
24
|
+
if (state.config.workspaceMode !== 'multi')
|
|
25
|
+
return state.config.workspaceRoot;
|
|
26
|
+
if (!workspaceId || !state.journal.getWorkspace(workspaceId))
|
|
27
|
+
throw new WorkspaceContextError('workspace_not_registered');
|
|
28
|
+
if (!/^(basic|remix-[a-z0-9][a-z0-9-]{3,63})$/.test(directoryName))
|
|
29
|
+
throw new WorkspaceContextError('invalid_workspace_directory');
|
|
30
|
+
if (directoryName !== 'basic' && !state.journal.getWorkspace(workspaceId)?.directories?.some(directory => directory.directoryName === directoryName))
|
|
31
|
+
throw new WorkspaceContextError('workspace_directory_not_registered');
|
|
32
|
+
return checkedDirectory(state, workspaceId, directoryName);
|
|
33
|
+
}
|
|
34
|
+
async function checkedDirectory(state, workspaceId, directoryName = 'basic') {
|
|
35
|
+
if (!/^[0-9a-f-]{36}$/i.test(workspaceId))
|
|
36
|
+
throw new WorkspaceContextError('invalid_workspace');
|
|
37
|
+
const parent = await realpath(state.config.workspaceRoot);
|
|
38
|
+
const container = join(parent, workspaceId);
|
|
39
|
+
const containerStat = await lstat(container).catch(() => undefined);
|
|
40
|
+
if (!containerStat?.isDirectory() || containerStat.isSymbolicLink() || relative(parent, await realpath(container)) !== workspaceId)
|
|
41
|
+
throw new WorkspaceContextError('workspace_not_prepared');
|
|
42
|
+
const target = join(container, directoryName);
|
|
43
|
+
try {
|
|
44
|
+
const stat = await lstat(target);
|
|
45
|
+
if (!stat.isDirectory() ||
|
|
46
|
+
stat.isSymbolicLink() ||
|
|
47
|
+
relative(container, await realpath(target)) !== directoryName) {
|
|
48
|
+
throw new WorkspaceContextError('invalid_workspace_directory');
|
|
49
|
+
}
|
|
50
|
+
const stateDir = await realpath(state.config.stateDir);
|
|
51
|
+
if (stateDir === target || stateDir.startsWith(`${target}/`))
|
|
52
|
+
throw new WorkspaceContextError('invalid_workspace_directory');
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error instanceof WorkspaceContextError)
|
|
57
|
+
throw error;
|
|
58
|
+
throw new WorkspaceContextError('workspace_not_prepared');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Registers a fixed directory; optional first creation is restricted to its trusted binding. */
|
|
62
|
+
export async function workspaceContainerRoot(state, workspaceId) {
|
|
63
|
+
if (state.config.workspaceMode !== 'multi')
|
|
64
|
+
return state.config.workspaceRoot;
|
|
65
|
+
if (!workspaceId || !state.journal.getWorkspace(workspaceId))
|
|
66
|
+
throw new WorkspaceContextError('workspace_not_registered');
|
|
67
|
+
if (!/^[0-9a-f-]{36}$/i.test(workspaceId))
|
|
68
|
+
throw new WorkspaceContextError('invalid_workspace');
|
|
69
|
+
const parent = await realpath(state.config.workspaceRoot);
|
|
70
|
+
const container = join(parent, workspaceId);
|
|
71
|
+
const stat = await lstat(container).catch(() => undefined);
|
|
72
|
+
if (!stat?.isDirectory() || stat.isSymbolicLink() || relative(parent, await realpath(container)) !== workspaceId)
|
|
73
|
+
throw new WorkspaceContextError('workspace_not_prepared');
|
|
74
|
+
const stateDir = await realpath(state.config.stateDir);
|
|
75
|
+
if (stateDir === container || stateDir.startsWith(`${container}/`))
|
|
76
|
+
throw new WorkspaceContextError('invalid_workspace_directory');
|
|
77
|
+
return container;
|
|
78
|
+
}
|
|
79
|
+
export async function sessionWorkspaceRoot(state, workspaceId, directoryName = 'basic') {
|
|
80
|
+
return directoryName === 'root' ? workspaceContainerRoot(state, workspaceId) : workspaceRoot(state, workspaceId, directoryName);
|
|
81
|
+
}
|
|
82
|
+
export async function workspaceContextFromRoot(state, cwd) {
|
|
83
|
+
const parent = await realpath(state.config.workspaceRoot);
|
|
84
|
+
const parts = relative(parent, cwd).split('/');
|
|
85
|
+
if (parts.length !== 1 && parts.length !== 2)
|
|
86
|
+
throw new WorkspaceContextError('workspace_not_registered');
|
|
87
|
+
const workspaceId = parts[0];
|
|
88
|
+
const directoryName = parts.length === 1 ? 'root' : parts[1];
|
|
89
|
+
if (await sessionWorkspaceRoot(state, workspaceId, directoryName) !== cwd)
|
|
90
|
+
throw new WorkspaceContextError('workspace_not_registered');
|
|
91
|
+
return { workspaceId, directoryName };
|
|
92
|
+
}
|
|
93
|
+
export async function registerWorkspace(state, input, leaseFence, preparation, readOnlyBasic = false) {
|
|
94
|
+
if (state.config.workspaceMode !== 'multi')
|
|
95
|
+
throw new WorkspaceContextError('multi_workspace_unavailable');
|
|
96
|
+
const parsed = workspaceRegistrationSchema.safeParse(input);
|
|
97
|
+
if (!parsed.success)
|
|
98
|
+
throw new WorkspaceContextError('invalid_workspace_registration');
|
|
99
|
+
const binding = parsed.data;
|
|
100
|
+
return state.journal.exclusive(`workspace:${binding.workspaceId}`, async () => {
|
|
101
|
+
if (state.journal.destroyed())
|
|
102
|
+
throw new WorkspaceContextError('runtime_destroyed');
|
|
103
|
+
if (leaseFence < state.acceptedLeaseFence)
|
|
104
|
+
throw new WorkspaceContextError('stale_lease');
|
|
105
|
+
state.acceptedLeaseFence = leaseFence;
|
|
106
|
+
await state.journal.setAcceptedLeaseFence(leaseFence);
|
|
107
|
+
const existing = state.journal.getWorkspace(binding.workspaceId);
|
|
108
|
+
const preservedLocalBasic = binding.targetKind !== 'standalone' && binding.preserveLocalBasic === true;
|
|
109
|
+
const localUpgrade = preservedLocalBasic && binding.targetKind === 'main' && existing?.targetKind === 'standalone';
|
|
110
|
+
// A standalone workspace promoted to a project's main keeps its checkout and gains that remote.
|
|
111
|
+
const remoteUpgrade = !preservedLocalBasic && binding.targetKind === 'main' && existing?.targetKind === 'standalone';
|
|
112
|
+
if (existing && !sameWorkspaceRegistration(existing, binding) && !localUpgrade && !remoteUpgrade)
|
|
113
|
+
throw new WorkspaceContextError('workspace_binding_conflict');
|
|
114
|
+
const attachMarker = join(state.config.stateDir, 'workspace-remote-attach', `${binding.workspaceId}.json`);
|
|
115
|
+
const existingByDir = new Map((existing?.directories ?? []).map(item => [item.directoryName, item]));
|
|
116
|
+
const directories = binding.directories
|
|
117
|
+
? binding.directories.map(item => {
|
|
118
|
+
const local = existingByDir.get(item.directoryName);
|
|
119
|
+
return local && local.remixId === item.remixId && local.status === 'ready' && item.status === 'pending'
|
|
120
|
+
? { ...item, status: 'ready', sourceCommit: item.sourceCommit ?? local.sourceCommit }
|
|
121
|
+
: item;
|
|
122
|
+
})
|
|
123
|
+
: existing?.directories;
|
|
124
|
+
if (directories?.some(directory => directory.directoryName === 'basic' && directory.status === 'reclaimed')) {
|
|
125
|
+
// Registration publishes trusted identity. Only an explicit basic ensure restores the checkout.
|
|
126
|
+
const parent = await realpath(state.config.workspaceRoot);
|
|
127
|
+
const container = join(parent, binding.workspaceId);
|
|
128
|
+
await mkdir(container, { mode: 0o2770 }).catch(error => { if (error.code !== 'EEXIST')
|
|
129
|
+
throw error; });
|
|
130
|
+
const registered = { ...binding, directories };
|
|
131
|
+
await state.journal.putWorkspace(registered);
|
|
132
|
+
await workspaceContainerRoot(state, binding.workspaceId);
|
|
133
|
+
return registered;
|
|
134
|
+
}
|
|
135
|
+
let root;
|
|
136
|
+
try {
|
|
137
|
+
root = await checkedDirectory(state, binding.workspaceId);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (existing && error instanceof WorkspaceContextError && error.message === 'workspace_not_prepared')
|
|
141
|
+
throw new WorkspaceContextError('workspace_recovery_required');
|
|
142
|
+
if (!preparation || !(error instanceof WorkspaceContextError) || error.message !== 'workspace_not_prepared')
|
|
143
|
+
throw error;
|
|
144
|
+
await prepareWorkspaceCheckout(state, binding, preparation, leaseFence);
|
|
145
|
+
root = await checkedDirectory(state, binding.workspaceId);
|
|
146
|
+
}
|
|
147
|
+
const git = async (...args) => (await exec('git', ['-C', root, ...args], {
|
|
148
|
+
timeout: 5000,
|
|
149
|
+
maxBuffer: 64 * 1024,
|
|
150
|
+
env: {
|
|
151
|
+
PATH: process.env.PATH,
|
|
152
|
+
HOME: process.env.HOME,
|
|
153
|
+
GIT_CONFIG_NOSYSTEM: '1',
|
|
154
|
+
GIT_CONFIG_GLOBAL: '/dev/null',
|
|
155
|
+
},
|
|
156
|
+
})).stdout.trim();
|
|
157
|
+
// Unfinished if it failed part way: the marker outlives the journal entry written below.
|
|
158
|
+
if (binding.targetKind === 'main' && !preservedLocalBasic && (remoteUpgrade || await lstat(attachMarker).then(() => true, () => false))) {
|
|
159
|
+
if (preparation?.mode !== 'clone' || !state.gitCredentials)
|
|
160
|
+
throw new WorkspaceContextError('workspace_git_gateway_unavailable');
|
|
161
|
+
await mkdir(join(state.config.stateDir, 'workspace-remote-attach'), { recursive: true, mode: 0o700 });
|
|
162
|
+
await writeFile(attachMarker, JSON.stringify({ repositoryUrl: binding.repositoryUrl, branchName: binding.branchName }), { mode: 0o600 });
|
|
163
|
+
// The credential helper only serves a workspace the journal knows to be bound.
|
|
164
|
+
await state.journal.putWorkspace({ ...binding, directories });
|
|
165
|
+
try {
|
|
166
|
+
await state.gitCredentials.configure(binding, preparation);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
throw new WorkspaceContextError('workspace_git_gateway_unavailable');
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
await attachWorkspaceRemote(root, binding.repositoryUrl, binding.branchName);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
throw new WorkspaceContextError('workspace_remote_attach_failed');
|
|
176
|
+
}
|
|
177
|
+
await rm(attachMarker, { force: true });
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
let checkoutMatches;
|
|
181
|
+
if (binding.targetKind === 'standalone' || preservedLocalBasic) {
|
|
182
|
+
const gitDirectory = await lstat(join(root, '.git'));
|
|
183
|
+
checkoutMatches = gitDirectory.isDirectory() && !gitDirectory.isSymbolicLink()
|
|
184
|
+
&& (await git('rev-parse', '--absolute-git-dir')) === join(root, '.git')
|
|
185
|
+
&& (await git('remote')) === '';
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
checkoutMatches = (await git('config', '--get', 'remote.origin.url')) === binding.repositoryUrl
|
|
189
|
+
&& (await git('symbolic-ref', '--short', 'HEAD')) === binding.branchName;
|
|
190
|
+
}
|
|
191
|
+
if ((await realpath(await git('rev-parse', '--show-toplevel'))) !== root || !checkoutMatches) {
|
|
192
|
+
throw new WorkspaceContextError('workspace_checkout_mismatch');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (error instanceof WorkspaceContextError)
|
|
197
|
+
throw error;
|
|
198
|
+
throw new WorkspaceContextError('workspace_not_prepared');
|
|
199
|
+
}
|
|
200
|
+
if (state.journal.destroyed())
|
|
201
|
+
throw new WorkspaceContextError('runtime_destroyed');
|
|
202
|
+
if (leaseFence < state.acceptedLeaseFence)
|
|
203
|
+
throw new WorkspaceContextError('stale_lease');
|
|
204
|
+
if (readOnlyBasic || preservedLocalBasic) {
|
|
205
|
+
await state.journal.putWorkspace({ ...binding, directories });
|
|
206
|
+
return binding;
|
|
207
|
+
}
|
|
208
|
+
if (preparation?.mode === 'clone' && (preparation.transport?.kind === 'git-gateway-v2' || isLocalWorkspaceGitAuthMode(preparation.authMode))) {
|
|
209
|
+
if (!state.gitCredentials)
|
|
210
|
+
throw new WorkspaceContextError('workspace_git_gateway_unavailable');
|
|
211
|
+
try {
|
|
212
|
+
await state.gitCredentials.configure(binding, preparation);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
throw new WorkspaceContextError('workspace_git_gateway_unavailable');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
await ensureWorkspaceSkills(root, join(state.config.stateDir, 'skill-artifacts'), workspacePlatformSkillAccess(state, binding.workspaceId));
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
throw new WorkspaceContextError('workspace_skills_unavailable');
|
|
223
|
+
}
|
|
224
|
+
await writeWorkspaceCliContext(root, binding.workspaceId);
|
|
225
|
+
await state.journal.putWorkspace({ ...binding, directories });
|
|
226
|
+
try {
|
|
227
|
+
await readWorkspaceSkills(root, join(state.config.stateDir, 'skill-artifacts'), entry => loadWorkspaceSkillArtifact(state, binding.workspaceId, entry));
|
|
228
|
+
}
|
|
229
|
+
catch { /* Skills reads and native turns diagnose missing artifacts; files and source repair remain available. */ }
|
|
230
|
+
// Runs in the background; every registration rechecks it, so reopening retries a failed install.
|
|
231
|
+
void scheduleDependencyInstall(state, revisionScope(state, binding.workspaceId), root);
|
|
232
|
+
return binding;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { readWorkspaceFile } from './files.js';
|
|
2
|
+
import { revisionScope, workspaceRoot } from './registry.js';
|
|
3
|
+
/** Observe native/manual edits before checking an editor's conditional write. */
|
|
4
|
+
export async function withObservedFile(state, workspaceId, path, action, directoryName = 'basic') {
|
|
5
|
+
const scope = revisionScope(state, workspaceId, directoryName);
|
|
6
|
+
return state.journal.exclusive(`file:${scope ?? 'single'}:${path}`, async () => {
|
|
7
|
+
const records = state.journal.fileRevisions(scope);
|
|
8
|
+
const previous = records[path];
|
|
9
|
+
let file;
|
|
10
|
+
try {
|
|
11
|
+
file = await readWorkspaceFile(await workspaceRoot(state, workspaceId, directoryName), path, records);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code !== 'ENOENT')
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
const hash = file?.contentHash ?? '';
|
|
18
|
+
const revision = previous ? previous.revision + (previous.contentHash === hash ? 0 : 1) : 0;
|
|
19
|
+
if ((!previous && file) || (previous && previous.contentHash !== hash)) {
|
|
20
|
+
await state.journal.putFileRevision(path, { revision, contentHash: hash }, scope);
|
|
21
|
+
}
|
|
22
|
+
return action({ file: file ? { ...file, revision } : undefined, revision });
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export async function readObservedFile(state, workspaceId, path, directoryName = 'basic') {
|
|
26
|
+
return withObservedFile(state, workspaceId, path, async ({ file }) => {
|
|
27
|
+
if (!file)
|
|
28
|
+
throw Object.assign(new Error('file_not_found'), { code: 'ENOENT' });
|
|
29
|
+
return file;
|
|
30
|
+
}, directoryName);
|
|
31
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { workspaceRoot } from './registry.js';
|
|
3
|
+
import { PLATFORM_ROUTES, platformEndpoint } from '@playcraft/common/cloud-workspace/runtime';
|
|
4
|
+
const MAX_ARTIFACT_BYTES = 80 * 1024 * 1024;
|
|
5
|
+
/** Requests an exact locked artifact using control identity; no storage credentials reach Codex. */
|
|
6
|
+
export async function loadWorkspaceSkillArtifact(state, workspaceId, entry, directoryName = 'basic') {
|
|
7
|
+
await workspaceRoot(state, workspaceId, directoryName);
|
|
8
|
+
return requestWorkspaceSkillArtifact(state, workspaceId, entry);
|
|
9
|
+
}
|
|
10
|
+
async function requestWorkspaceSkillArtifact(state, workspaceId, entry) {
|
|
11
|
+
const epoch = state.runtimeEpoch;
|
|
12
|
+
if (state.journal.destroyed())
|
|
13
|
+
throw new Error('workspace_skills_unavailable');
|
|
14
|
+
const endpoint = platformEndpoint(state.config.publicBaseUrl, PLATFORM_ROUTES.skillArtifacts);
|
|
15
|
+
const response = await fetch(endpoint, {
|
|
16
|
+
method: 'POST', redirect: 'error', signal: AbortSignal.timeout(30_000),
|
|
17
|
+
headers: { authorization: `Bearer ${state.config.controlToken}`, 'content-type': 'application/json', 'playcraft-env': state.config.environment },
|
|
18
|
+
body: JSON.stringify({ runtimeId: state.config.runtimeId, generation: state.config.generation,
|
|
19
|
+
runtimeEpoch: epoch, workspaceId, entryKey: entry.entryKey, revision: entry.revision }),
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok || !response.body)
|
|
22
|
+
throw new Error('workspace_skills_artifact_unavailable');
|
|
23
|
+
const reader = response.body.getReader(), chunks = [];
|
|
24
|
+
let total = 0;
|
|
25
|
+
try {
|
|
26
|
+
while (true) {
|
|
27
|
+
const chunk = await reader.read();
|
|
28
|
+
if (chunk.done)
|
|
29
|
+
break;
|
|
30
|
+
total += chunk.value.byteLength;
|
|
31
|
+
if (total > Math.ceil(MAX_ARTIFACT_BYTES * 4 / 3) + 4096)
|
|
32
|
+
throw new Error('workspace_skills_artifact_too_large');
|
|
33
|
+
chunks.push(chunk.value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
await reader.cancel().catch(() => undefined);
|
|
38
|
+
}
|
|
39
|
+
const result = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
40
|
+
if (typeof result.content !== 'string' || result.artifactHash !== entry.revision.artifactHash
|
|
41
|
+
|| result.content.length > Math.ceil(MAX_ARTIFACT_BYTES * 4 / 3) || result.content.length % 4 !== 0 || /[^A-Za-z0-9+/=]/.test(result.content))
|
|
42
|
+
throw new Error('workspace_skills_digest_mismatch');
|
|
43
|
+
const archive = Buffer.from(result.content, 'base64');
|
|
44
|
+
if (archive.byteLength > MAX_ARTIFACT_BYTES || archive.toString('base64') !== result.content || createHash('sha256').update(archive).digest('hex') !== entry.revision.artifactHash)
|
|
45
|
+
throw new Error('workspace_skills_digest_mismatch');
|
|
46
|
+
if (state.journal.destroyed() || epoch !== state.runtimeEpoch)
|
|
47
|
+
throw new Error('workspace_skills_unavailable');
|
|
48
|
+
return archive;
|
|
49
|
+
}
|
|
50
|
+
/** The platform independently authorizes the trusted binding, including an unpublished checkout. */
|
|
51
|
+
export function workspacePlatformSkillAccess(state, workspaceId) {
|
|
52
|
+
return {
|
|
53
|
+
resolve: async (skillRefs) => {
|
|
54
|
+
const epoch = state.runtimeEpoch;
|
|
55
|
+
if (state.journal.destroyed())
|
|
56
|
+
throw new Error('workspace_skills_unavailable');
|
|
57
|
+
const response = await fetch(`${platformEndpoint(state.config.publicBaseUrl, PLATFORM_ROUTES.skillArtifacts)}/resolve`, {
|
|
58
|
+
method: 'POST', redirect: 'error', signal: AbortSignal.timeout(30_000),
|
|
59
|
+
headers: { authorization: `Bearer ${state.config.controlToken}`, 'content-type': 'application/json', 'playcraft-env': state.config.environment },
|
|
60
|
+
body: JSON.stringify({ runtimeId: state.config.runtimeId, generation: state.config.generation,
|
|
61
|
+
runtimeEpoch: epoch, workspaceId, skillRefs }),
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
await response.body?.cancel();
|
|
65
|
+
throw new Error('workspace_skills_platform_unavailable');
|
|
66
|
+
}
|
|
67
|
+
if (!response.body)
|
|
68
|
+
throw new Error('workspace_skills_platform_unavailable');
|
|
69
|
+
const reader = response.body.getReader(), chunks = [];
|
|
70
|
+
let total = 0;
|
|
71
|
+
try {
|
|
72
|
+
while (true) {
|
|
73
|
+
const part = await reader.read();
|
|
74
|
+
if (part.done)
|
|
75
|
+
break;
|
|
76
|
+
total += part.value.byteLength;
|
|
77
|
+
if (total > 1024 * 1024)
|
|
78
|
+
throw new Error('workspace_skills_platform_unavailable');
|
|
79
|
+
chunks.push(part.value);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
await reader.cancel().catch(() => undefined);
|
|
84
|
+
}
|
|
85
|
+
if (state.journal.destroyed() || epoch !== state.runtimeEpoch)
|
|
86
|
+
throw new Error('workspace_skills_unavailable');
|
|
87
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
88
|
+
},
|
|
89
|
+
loadArtifact: entry => requestWorkspaceSkillArtifact(state, workspaceId, entry),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { cp, lstat, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
4
|
+
import { load } from 'js-yaml';
|
|
5
|
+
import { canonicalProjectSkillsJson, createCanonicalBundleArchive, effectiveProjectSkills, extractBundleArchive, inspectProjectSkills, readProjectSkillSource, readProjectSkillsLockFile, sourceTreeDigest, validateProjectSkillsSnapshot, } from '@playcraft/common/project-skills';
|
|
6
|
+
import { initializeLocalProjectSkills } from '../../project-skills/local-store.js';
|
|
7
|
+
import { resolveCliPackageRoot } from '../../scaffold/compose.js';
|
|
8
|
+
import { selectPlatformSkillSnapshot } from '../../project-skills/builtin-import.js';
|
|
9
|
+
import { EMPTY_WORKSPACE_REPOSITORY_SKILLS, EMPTY_WORKSPACE_PLATFORM_SKILLS } from './empty-template.js';
|
|
10
|
+
import { excludeFromGit } from './dependencies.js';
|
|
11
|
+
/** Runtime availability is determined by the locked metadata, independent of unsynced source edits. */
|
|
12
|
+
export async function readWorkspaceSkillSnapshot(root) {
|
|
13
|
+
const management = await lstat(join(root, '.playcraft'));
|
|
14
|
+
const declaration = join(root, '.playcraft/skills.json');
|
|
15
|
+
const stat = await lstat(declaration);
|
|
16
|
+
if (!management.isDirectory() || management.isSymbolicLink() || !stat.isFile() || stat.isSymbolicLink() || stat.size > 1024 * 1024)
|
|
17
|
+
throw new Error('workspace_skills_invalid');
|
|
18
|
+
return validateProjectSkillsSnapshot(await readFile(declaration, 'utf8'), await readProjectSkillsLockFile(root));
|
|
19
|
+
}
|
|
20
|
+
/** Existing managed projects keep their exact selection. Legacy source folders are adopted once. */
|
|
21
|
+
export async function ensureWorkspaceSkills(root, cache, access) {
|
|
22
|
+
await excludeFromGit(root, '/.playcraft/skills/');
|
|
23
|
+
await excludeFromGit(root, '/.playcraft/skill-artifacts/');
|
|
24
|
+
const raw = await readProjectSkillsLockFile(root);
|
|
25
|
+
if (raw !== null) {
|
|
26
|
+
await readWorkspaceSkillSnapshot(root);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const inventory = await inspectProjectSkills(root);
|
|
30
|
+
if (inventory.issues.length)
|
|
31
|
+
throw new Error('workspace_skills_invalid');
|
|
32
|
+
const names = new Set(inventory.discovered.map(entry => basename(entry.root)));
|
|
33
|
+
const platformNames = EMPTY_WORKSPACE_PLATFORM_SKILLS.filter(name => !names.has(name));
|
|
34
|
+
const selected = platformNames.length ? await selectPlatformSkillSnapshot(platformNames, access) : undefined;
|
|
35
|
+
const added = new Set();
|
|
36
|
+
await initializeLocalProjectSkills(root, cache, { enabledRoots: added, platform: selected,
|
|
37
|
+
prepareSources: async () => {
|
|
38
|
+
for (const name of EMPTY_WORKSPACE_REPOSITORY_SKILLS) {
|
|
39
|
+
if (names.has(name))
|
|
40
|
+
continue;
|
|
41
|
+
await safeDirectory(root, '.agents/skills');
|
|
42
|
+
const source = `.agents/skills/${name}`;
|
|
43
|
+
await mkdir(join(root, source), { mode: 0o755 });
|
|
44
|
+
added.add(source);
|
|
45
|
+
const template = join(resolveCliPackageRoot(), 'project-template/.claude/skills', name);
|
|
46
|
+
for (const child of await readdir(template))
|
|
47
|
+
await cp(join(template, child), join(root, source, child), {
|
|
48
|
+
recursive: true, force: false, errorOnExist: true,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
rollbackSources: async () => {
|
|
53
|
+
for (const source of added)
|
|
54
|
+
await rm(join(root, source), { recursive: true, force: true });
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async function safeDirectory(root, path) {
|
|
59
|
+
let current = root;
|
|
60
|
+
for (const segment of path.split('/')) {
|
|
61
|
+
current = join(current, segment);
|
|
62
|
+
await mkdir(current, { mode: 0o755 }).catch(error => { if (error.code !== 'EEXIST')
|
|
63
|
+
throw error; });
|
|
64
|
+
const stat = await lstat(current);
|
|
65
|
+
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
66
|
+
throw new Error('workspace_skills_invalid');
|
|
67
|
+
}
|
|
68
|
+
return current;
|
|
69
|
+
}
|
|
70
|
+
/** Cache misses may reconstruct only the exact locked repository bytes, never a newer source. */
|
|
71
|
+
async function lockedFiles(root, cache, entry, view, loadArtifact) {
|
|
72
|
+
const persistent = await safeDirectory(root, '.playcraft/skill-artifacts');
|
|
73
|
+
const saved = join(persistent, `${entry.revision.artifactHash}.tar.gz`);
|
|
74
|
+
const path = join(cache, `${entry.revision.artifactHash}.tar.gz`);
|
|
75
|
+
let archive;
|
|
76
|
+
try {
|
|
77
|
+
const stat = await lstat(saved);
|
|
78
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || stat.size > 80 * 1024 * 1024)
|
|
79
|
+
throw new Error('workspace_skills_invalid_bundle');
|
|
80
|
+
archive = await readFile(saved);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error.code !== 'ENOENT')
|
|
84
|
+
throw error;
|
|
85
|
+
try {
|
|
86
|
+
archive = await readFile(path);
|
|
87
|
+
}
|
|
88
|
+
catch (cacheError) {
|
|
89
|
+
if (cacheError.code !== 'ENOENT')
|
|
90
|
+
throw cacheError;
|
|
91
|
+
const declaration = view.declaration.entries.find(item => item.entryKey === entry.entryKey);
|
|
92
|
+
if (entry.revision.kind === 'source' && declaration.source.kind === 'repository') {
|
|
93
|
+
const source = await readProjectSkillSource(root, declaration);
|
|
94
|
+
if (source.sourceTreeHash !== entry.sourceTreeHash)
|
|
95
|
+
throw new Error('workspace_skills_source_changed');
|
|
96
|
+
archive = createCanonicalBundleArchive(source.files.map(file => ({ path: file.path, data: Buffer.from(file.content) })));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
if (!loadArtifact)
|
|
100
|
+
throw new Error('workspace_skills_artifact_unavailable');
|
|
101
|
+
archive = await loadArtifact(entry);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (createHash('sha256').update(archive).digest('hex') !== entry.revision.artifactHash)
|
|
106
|
+
throw new Error('workspace_skills_digest_mismatch');
|
|
107
|
+
const extracted = extractBundleArchive(archive);
|
|
108
|
+
if (extracted.issues.length)
|
|
109
|
+
throw new Error('workspace_skills_invalid_bundle');
|
|
110
|
+
if (entry.revision.kind === 'source' && sourceTreeDigest(extracted.files.map(file => ({ path: file.path, content: file.data }))) !== entry.sourceTreeHash)
|
|
111
|
+
throw new Error('workspace_skills_digest_mismatch');
|
|
112
|
+
const temporary = `${saved}.${randomUUID()}.tmp`;
|
|
113
|
+
try {
|
|
114
|
+
await writeFile(temporary, archive, { flag: 'wx', mode: 0o644 });
|
|
115
|
+
await rename(temporary, saved);
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
await rm(temporary, { force: true });
|
|
119
|
+
}
|
|
120
|
+
return extracted.files;
|
|
121
|
+
}
|
|
122
|
+
function metadata(entryKey, content) {
|
|
123
|
+
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(content);
|
|
124
|
+
const parsed = frontmatter ? load(frontmatter[1]) : {};
|
|
125
|
+
const data = parsed && typeof parsed === 'object' ? parsed : {};
|
|
126
|
+
return { entryKey, name: typeof data.name === 'string' ? data.name : entryKey,
|
|
127
|
+
description: typeof data.description === 'string' ? data.description : '', content };
|
|
128
|
+
}
|
|
129
|
+
export async function readWorkspaceSkills(root, cache, loadArtifact) {
|
|
130
|
+
const snapshot = await readWorkspaceSkillSnapshot(root);
|
|
131
|
+
const skills = await Promise.all(snapshot.lock.entries.map(async (entry) => {
|
|
132
|
+
const files = await lockedFiles(root, cache, entry, snapshot, loadArtifact);
|
|
133
|
+
const body = files.find(file => file.path === 'SKILL.md');
|
|
134
|
+
if (!body)
|
|
135
|
+
throw new Error('workspace_skills_body_missing');
|
|
136
|
+
return metadata(entry.entryKey, body.data.toString('utf8'));
|
|
137
|
+
}));
|
|
138
|
+
return { ...snapshot, lockHash: createHash('sha256').update(canonicalProjectSkillsJson(snapshot.lock)).digest('hex'), skills };
|
|
139
|
+
}
|
|
140
|
+
/** Read-only task generation lives outside source discovery and is omitted from Git/snapshots. */
|
|
141
|
+
export async function freezeWorkspaceSkills(root, cache, loadArtifact) {
|
|
142
|
+
const snapshot = await readWorkspaceSkillSnapshot(root);
|
|
143
|
+
const entries = effectiveProjectSkills(snapshot.declaration, snapshot.lock, 'sandbox-agent');
|
|
144
|
+
const base = await safeDirectory(root, '.playcraft/skills');
|
|
145
|
+
const lockHash = createHash('sha256').update(canonicalProjectSkillsJson(snapshot.lock)).digest('hex');
|
|
146
|
+
const generation = await safeDirectory(base, lockHash);
|
|
147
|
+
const skills = [];
|
|
148
|
+
const expectedFiles = new Set();
|
|
149
|
+
for (const entry of entries) {
|
|
150
|
+
const files = await lockedFiles(root, cache, entry, snapshot, loadArtifact);
|
|
151
|
+
for (const file of files) {
|
|
152
|
+
const target = join(generation, entry.entryKey, file.path);
|
|
153
|
+
const relative = join(entry.entryKey, file.path);
|
|
154
|
+
expectedFiles.add(relative);
|
|
155
|
+
await safeDirectory(generation, dirname(relative));
|
|
156
|
+
await writeFile(target, file.data, { flag: 'wx', mode: 0o444 }).catch(async (error) => {
|
|
157
|
+
if (error.code !== 'EEXIST')
|
|
158
|
+
throw error;
|
|
159
|
+
const stat = await lstat(target);
|
|
160
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || !file.data.equals(await readFile(target)))
|
|
161
|
+
throw new Error('workspace_skills_digest_mismatch');
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
const body = files.find(file => file.path === 'SKILL.md');
|
|
165
|
+
if (!body)
|
|
166
|
+
throw new Error('workspace_skills_body_missing');
|
|
167
|
+
const info = metadata(entry.entryKey, body.data.toString('utf8'));
|
|
168
|
+
skills.push({ name: info.name, description: info.description, skillRef: entry.revision.skillRef,
|
|
169
|
+
revision: entry.revision.kind === 'source' ? entry.revision.sourceRevision : entry.revision.version,
|
|
170
|
+
path: join(generation, entry.entryKey, 'SKILL.md') });
|
|
171
|
+
}
|
|
172
|
+
const verifyTree = async (directory, relative = '') => {
|
|
173
|
+
for (const item of await readdir(directory, { withFileTypes: true })) {
|
|
174
|
+
const path = join(relative, item.name);
|
|
175
|
+
if (item.isSymbolicLink())
|
|
176
|
+
throw new Error('workspace_skills_invalid_bundle');
|
|
177
|
+
if (item.isDirectory()) {
|
|
178
|
+
if (![...expectedFiles].some(file => file.startsWith(`${path}/`)))
|
|
179
|
+
throw new Error('workspace_skills_invalid_bundle');
|
|
180
|
+
await verifyTree(join(directory, item.name), path);
|
|
181
|
+
}
|
|
182
|
+
else if (!item.isFile() || !expectedFiles.has(path))
|
|
183
|
+
throw new Error('workspace_skills_invalid_bundle');
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
await verifyTree(generation);
|
|
187
|
+
return { declarationHash: snapshot.lock.declarationHash,
|
|
188
|
+
lockHash, skills };
|
|
189
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { WORKSPACE_VIDEO_ATTACHMENT_MAX_DURATION_MS, WORKSPACE_VIDEO_ATTACHMENT_MAX_BYTES } from '@playcraft/common/cloud-workspace/runtime';
|
|
4
|
+
/** Probe the opened descriptor so replacing a pathname cannot redirect the media reader. */
|
|
5
|
+
export async function probeAttachmentVideo(handle) {
|
|
6
|
+
const output = await new Promise((resolve, reject) => {
|
|
7
|
+
const child = spawn(process.env.PLAYCRAFT_FFPROBE_PATH ?? 'ffprobe', [
|
|
8
|
+
'-v', 'error', '-protocol_whitelist', 'file,pipe', '-show_entries',
|
|
9
|
+
'format=format_name,duration:stream=codec_type,width,height', '-of', 'json',
|
|
10
|
+
process.platform === 'linux' ? '/proc/self/fd/3' : '/dev/fd/3',
|
|
11
|
+
], { stdio: ['ignore', 'pipe', 'ignore', handle.fd] });
|
|
12
|
+
let text = '';
|
|
13
|
+
const timer = setTimeout(() => { child.kill('SIGKILL'); reject(new Error('invalid_attachment')); }, 15_000);
|
|
14
|
+
timer.unref();
|
|
15
|
+
child.stdout.on('data', (chunk) => {
|
|
16
|
+
text += chunk.toString('utf8');
|
|
17
|
+
if (text.length > 64 * 1024) {
|
|
18
|
+
child.kill('SIGKILL');
|
|
19
|
+
reject(new Error('invalid_attachment'));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
child.once('error', () => { clearTimeout(timer); reject(new Error('video_probe_unavailable')); });
|
|
23
|
+
child.once('close', code => { clearTimeout(timer); code === 0 ? resolve(text) : reject(new Error('invalid_attachment')); });
|
|
24
|
+
});
|
|
25
|
+
const result = JSON.parse(output);
|
|
26
|
+
const stream = result.streams?.find(item => item.codec_type === 'video');
|
|
27
|
+
const durationMs = Math.round(Number(result.format?.duration) * 1000);
|
|
28
|
+
const formats = result.format?.format_name?.split(',') ?? [];
|
|
29
|
+
const mimeType = formats.includes('webm') ? 'video/webm' : formats.includes('mp4') ? 'video/mp4' : formats.includes('mov') ? 'video/quicktime' : undefined;
|
|
30
|
+
if (!stream || !mimeType || !Number.isFinite(durationMs) || durationMs <= 0 || durationMs > WORKSPACE_VIDEO_ATTACHMENT_MAX_DURATION_MS
|
|
31
|
+
|| !Number.isSafeInteger(stream.width) || !Number.isSafeInteger(stream.height) || stream.width <= 0 || stream.height <= 0
|
|
32
|
+
|| stream.width > 16384 || stream.height > 16384)
|
|
33
|
+
throw new Error('invalid_attachment');
|
|
34
|
+
return { mimeType, durationMs, width: stream.width, height: stream.height };
|
|
35
|
+
}
|
|
36
|
+
export async function hashAttachment(handle) {
|
|
37
|
+
const digest = createHash('sha256');
|
|
38
|
+
const chunk = Buffer.allocUnsafe(64 * 1024);
|
|
39
|
+
let position = 0;
|
|
40
|
+
for (;;) {
|
|
41
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.length, position);
|
|
42
|
+
if (!bytesRead)
|
|
43
|
+
return digest.digest('hex');
|
|
44
|
+
digest.update(chunk.subarray(0, bytesRead));
|
|
45
|
+
position += bytesRead;
|
|
46
|
+
if (position > WORKSPACE_VIDEO_ATTACHMENT_MAX_BYTES)
|
|
47
|
+
throw new Error('invalid_attachment');
|
|
48
|
+
}
|
|
49
|
+
}
|