@playcraft/cli 0.1.24 → 0.1.26
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 +8 -4
- package/dist/commands/tools.js +2 -0
- 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 +636 -0
- package/dist/workspace-runtime/codex/config-toml.js +107 -0
- package/dist/workspace-runtime/codex/jsonrpc-stdio.js +123 -0
- package/dist/workspace-runtime/codex/launcher-client.js +163 -0
- package/dist/workspace-runtime/codex/loopback.js +143 -0
- package/dist/workspace-runtime/codex/model-broker.js +258 -0
- package/dist/workspace-runtime/codex/native-adapter.js +9 -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 +1057 -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 +90 -0
- package/dist/workspace-runtime/production/processes.js +86 -0
- package/dist/workspace-runtime/production/save-command.js +24 -0
- package/dist/workspace-runtime/production/source-copy.js +91 -0
- package/dist/workspace-runtime/production/stages.js +202 -0
- package/dist/workspace-runtime/production/storage.js +32 -0
- package/dist/workspace-runtime/serve.js +202 -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 +903 -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 +984 -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 +294 -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/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 +113 -0
- package/dist/workspace-runtime/workspaces/directory-access.js +29 -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.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 +481 -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 +200 -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 -61
- 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 -61
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/SKILL.md +23 -61
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
import { lstat, open, readdir, realpath } from 'node:fs/promises';
|
|
4
|
+
import { basename, dirname, relative, resolve, sep } from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { RecordingError } from './messages.js';
|
|
7
|
+
const execute = promisify(execFile);
|
|
8
|
+
const excludedNames = new Set(['.git', 'node_modules', '.DS_Store']);
|
|
9
|
+
const excludedRoots = new Set(['.agents', '.claude', '.codex', '.next', '.vite', '.cache', '.tmp', 'tmp', 'temp', 'dist', 'build', 'coverage', '.playcraft-preview-out', '.playcraft-temp']);
|
|
10
|
+
const excludedInternalPaths = ['.playcraft/video-replication', '.playcraft/skills', '.playcraft/skill-artifacts', '.playcraft/skills.json', '.playcraft/skills.lock.json', '.playcraft/workspace-context.json'];
|
|
11
|
+
const inside = (root, path) => path === root || path.startsWith(`${root}${sep}`);
|
|
12
|
+
const canonicalPath = async (path) => {
|
|
13
|
+
const absolute = resolve(path);
|
|
14
|
+
try {
|
|
15
|
+
return await realpath(absolute);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
const parent = dirname(absolute);
|
|
19
|
+
if (parent === absolute)
|
|
20
|
+
throw new RecordingError('projectUnavailable', 64);
|
|
21
|
+
return resolve(await canonicalPath(parent), basename(absolute));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/** Hash source, resources, configuration and dependency manifests, including untracked inputs. */
|
|
25
|
+
export async function computeProjectInputDigest(root, excludedOutputDirectories = []) {
|
|
26
|
+
try {
|
|
27
|
+
const actualRoot = await realpath(root);
|
|
28
|
+
const excluded = await Promise.all(excludedOutputDirectories.map(canonicalPath));
|
|
29
|
+
if (excluded.some(target => inside(target, actualRoot)))
|
|
30
|
+
throw new RecordingError('projectUnavailable', 64);
|
|
31
|
+
const hash = createHash('sha256');
|
|
32
|
+
let fileCount = 0;
|
|
33
|
+
let totalBytes = 0;
|
|
34
|
+
const walk = async (directory) => {
|
|
35
|
+
const entries = (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name, 'en'));
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
if (excludedNames.has(entry.name) || directory === actualRoot && excludedRoots.has(entry.name))
|
|
38
|
+
continue;
|
|
39
|
+
const path = resolve(directory, entry.name);
|
|
40
|
+
if (excluded.some(target => inside(target, path)))
|
|
41
|
+
continue;
|
|
42
|
+
const rel = relative(actualRoot, path).split(sep).join('/');
|
|
43
|
+
if (excludedInternalPaths.some(target => rel === target || rel.startsWith(`${target}/`)))
|
|
44
|
+
continue;
|
|
45
|
+
const before = await lstat(path);
|
|
46
|
+
if (before.isDirectory()) {
|
|
47
|
+
await walk(path);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (before.isSymbolicLink()) {
|
|
51
|
+
const target = await realpath(path);
|
|
52
|
+
if (!inside(actualRoot, target) || (await lstat(target)).isDirectory())
|
|
53
|
+
throw new RecordingError('projectUnavailable', 64);
|
|
54
|
+
}
|
|
55
|
+
else if (!before.isFile())
|
|
56
|
+
throw new RecordingError('projectUnavailable', 64);
|
|
57
|
+
const file = await open(path, 'r');
|
|
58
|
+
try {
|
|
59
|
+
const initial = await file.stat();
|
|
60
|
+
totalBytes += initial.size;
|
|
61
|
+
if (++fileCount > 50_000 || totalBytes > 1024 * 1024 * 1024)
|
|
62
|
+
throw new RecordingError('projectUnavailable', 64);
|
|
63
|
+
const content = createHash('sha256');
|
|
64
|
+
for await (const bytes of file.createReadStream({ autoClose: false }))
|
|
65
|
+
content.update(bytes);
|
|
66
|
+
const after = await file.stat();
|
|
67
|
+
if (initial.size !== after.size || initial.mtimeMs !== after.mtimeMs || initial.ino !== after.ino)
|
|
68
|
+
throw new RecordingError('projectChanged', 64);
|
|
69
|
+
hash.update(`${JSON.stringify(rel)}:${initial.mode & 0o777}:${initial.size}:${content.digest('hex')}\n`);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await file.close();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
await walk(actualRoot);
|
|
77
|
+
const gitCommit = await execute('git', ['-C', actualRoot, 'rev-parse', 'HEAD'], { timeout: 5000, maxBuffer: 1024, encoding: 'utf8' }).then(value => value.stdout.trim()).catch(() => null);
|
|
78
|
+
return { root: actualRoot, gitCommit: gitCommit && /^[a-f0-9]{40,64}$/.test(gitCommit) ? gitCommit : null, sha256: hash.digest('hex'), fileCount };
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error instanceof RecordingError)
|
|
82
|
+
throw error;
|
|
83
|
+
throw new RecordingError('projectUnavailable', 64);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { createReadStream } from 'node:fs';
|
|
4
|
+
import { access, appendFile, mkdir, readFile, rename, stat, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
6
|
+
import { performance } from 'node:perf_hooks';
|
|
7
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
|
+
import { promisify } from 'node:util';
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
import { canonicalReplicaJson, replicaRecordingMetadataSchema, } from '@playcraft/common/agent-tools';
|
|
11
|
+
import { prepareArtifactDirectory, writeJsonAtomic } from '../video-replication/evidence.js';
|
|
12
|
+
import { probeVideo } from '../video-replication/media.js';
|
|
13
|
+
import { VideoCliError } from '../video-replication/messages.js';
|
|
14
|
+
import { computeProjectInputDigest } from './project-digest.js';
|
|
15
|
+
import { RecordingError, recordingMessage } from './messages.js';
|
|
16
|
+
import { parseRecordingScenario, recordingControls, recordingPoint, recordingUrl } from './scenario.js';
|
|
17
|
+
const execute = promisify(execFile);
|
|
18
|
+
const require = createRequire(import.meta.url);
|
|
19
|
+
const relativeFile = (root, path) => relative(root, path).split(sep).join('/');
|
|
20
|
+
const sha = (value) => createHash('sha256').update(value).digest('hex');
|
|
21
|
+
const printableUrl = (value) => { try {
|
|
22
|
+
const url = new URL(value);
|
|
23
|
+
return `${url.origin}${url.pathname}`;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return '[unavailable]';
|
|
27
|
+
} };
|
|
28
|
+
export async function hashRecordingFile(path) {
|
|
29
|
+
const hash = createHash('sha256');
|
|
30
|
+
for await (const bytes of createReadStream(path))
|
|
31
|
+
hash.update(bytes);
|
|
32
|
+
return hash.digest('hex');
|
|
33
|
+
}
|
|
34
|
+
async function mediaCommand(tool, args, signal) {
|
|
35
|
+
const executable = process.env[tool === 'ffmpeg' ? 'FFMPEG_PATH' : 'FFPROBE_PATH'] || tool;
|
|
36
|
+
if (executable !== tool && !isAbsolute(executable))
|
|
37
|
+
throw new RecordingError('invalidArguments', 64);
|
|
38
|
+
try {
|
|
39
|
+
return (await execute(executable, args, { timeout: 60_000, maxBuffer: 1024 * 1024, encoding: 'utf8', signal })).stdout;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (signal?.aborted)
|
|
43
|
+
throw signal.reason;
|
|
44
|
+
throw new RecordingError('recordingFailed');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export async function waitUntil(origin, atMs, signal) {
|
|
48
|
+
// Timers can wake before a fractional deadline. Never dispatch input or finish a capture early.
|
|
49
|
+
for (;;) {
|
|
50
|
+
signal.throwIfAborted();
|
|
51
|
+
const remaining = origin + atMs - performance.now();
|
|
52
|
+
if (remaining <= 0)
|
|
53
|
+
return;
|
|
54
|
+
await delay(Math.ceil(remaining), undefined, { signal });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function dispatchStep(page, session, scenario, step, origin, signal, emit) {
|
|
58
|
+
const point = recordingPoint(scenario, step.type === 'tap' ? step : step.path[0]);
|
|
59
|
+
if (step.type === 'tap') {
|
|
60
|
+
if (scenario.pointer === 'touch')
|
|
61
|
+
await page.touchscreen.tap(point.x, point.y);
|
|
62
|
+
else
|
|
63
|
+
await page.mouse.click(point.x, point.y);
|
|
64
|
+
emit(point, 'tap', step.atMs);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (scenario.pointer === 'touch')
|
|
68
|
+
await session.send('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: [{ ...point, id: 1 }] });
|
|
69
|
+
else {
|
|
70
|
+
await page.mouse.move(point.x, point.y);
|
|
71
|
+
await page.mouse.down();
|
|
72
|
+
}
|
|
73
|
+
emit(point, 'start', step.atMs);
|
|
74
|
+
let completed = false;
|
|
75
|
+
try {
|
|
76
|
+
for (const next of step.path.slice(1)) {
|
|
77
|
+
await waitUntil(origin, step.atMs + next.offsetMs, signal);
|
|
78
|
+
const actual = recordingPoint(scenario, next);
|
|
79
|
+
if (scenario.pointer === 'touch')
|
|
80
|
+
await session.send('Input.dispatchTouchEvent', { type: 'touchMove', touchPoints: [{ ...actual, id: 1 }] });
|
|
81
|
+
else
|
|
82
|
+
await page.mouse.move(actual.x, actual.y);
|
|
83
|
+
emit(actual, 'move', step.atMs + next.offsetMs);
|
|
84
|
+
}
|
|
85
|
+
completed = true;
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
const release = scenario.pointer === 'touch' ? session.send('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] }) : page.mouse.up();
|
|
89
|
+
if (completed) {
|
|
90
|
+
await release;
|
|
91
|
+
emit(recordingPoint(scenario, step.path.at(-1)), 'end', step.atMs + step.path.at(-1).offsetMs);
|
|
92
|
+
}
|
|
93
|
+
else
|
|
94
|
+
await release.catch(() => { });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function recordOne(browser, root, url, scenario, variant, signal) {
|
|
98
|
+
const directory = variant.kind === 'candidate' ? root : join(root, 'controls', variant.id);
|
|
99
|
+
await mkdir(join(directory, 'screenshots'), { recursive: true });
|
|
100
|
+
const eventPath = join(directory, 'events.jsonl');
|
|
101
|
+
const consolePath = join(directory, 'console.jsonl');
|
|
102
|
+
await writeFile(eventPath, '', { flag: 'wx', mode: 0o600 });
|
|
103
|
+
await writeFile(consolePath, '', { flag: 'wx', mode: 0o600 });
|
|
104
|
+
const context = await browser.newContext({
|
|
105
|
+
viewport: { width: scenario.viewport.width, height: scenario.viewport.height }, deviceScaleFactor: scenario.viewport.deviceScaleFactor,
|
|
106
|
+
hasTouch: scenario.pointer === 'touch', isMobile: scenario.pointer === 'touch', serviceWorkers: 'block',
|
|
107
|
+
acceptDownloads: false, recordVideo: { dir: join(directory, 'capture'), size: { width: scenario.viewport.width, height: scenario.viewport.height } },
|
|
108
|
+
});
|
|
109
|
+
let logs = Promise.resolve();
|
|
110
|
+
let logBytes = 0;
|
|
111
|
+
let failed;
|
|
112
|
+
const runtime = { pageErrors: 0, consoleErrors: 0, failedRequests: 0 };
|
|
113
|
+
let origin = performance.now();
|
|
114
|
+
let inputOriginMs = Date.now();
|
|
115
|
+
const log = (path, value) => {
|
|
116
|
+
const line = `${JSON.stringify(value)}\n`;
|
|
117
|
+
logBytes += Buffer.byteLength(line);
|
|
118
|
+
if (logBytes > 16 * 1024 * 1024) {
|
|
119
|
+
failed = new RecordingError('recordingFailed');
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
logs = logs.then(() => appendFile(path, line));
|
|
123
|
+
};
|
|
124
|
+
const closeOnAbort = () => { void context.close().catch(() => { }); };
|
|
125
|
+
signal.addEventListener('abort', closeOnAbort, { once: true });
|
|
126
|
+
let closed = false;
|
|
127
|
+
try {
|
|
128
|
+
signal.throwIfAborted();
|
|
129
|
+
const page = await context.newPage();
|
|
130
|
+
const video = page.video();
|
|
131
|
+
if (!video)
|
|
132
|
+
throw new RecordingError('browserUnavailable');
|
|
133
|
+
page.on('console', message => {
|
|
134
|
+
if (message.type() === 'error')
|
|
135
|
+
runtime.consoleErrors++;
|
|
136
|
+
log(consolePath, { atMs: performance.now() - origin, kind: 'console', level: message.type(), text: message.text().slice(0, 32768) });
|
|
137
|
+
});
|
|
138
|
+
page.on('pageerror', error => { runtime.pageErrors++; log(consolePath, { atMs: performance.now() - origin, kind: 'pageerror', level: 'error', text: error.message.slice(0, 32768) }); });
|
|
139
|
+
page.on('requestfailed', request => { runtime.failedRequests++; log(consolePath, { atMs: performance.now() - origin, kind: 'requestfailed', level: 'error', url: printableUrl(request.url()), text: request.failure()?.errorText }); });
|
|
140
|
+
context.on('page', popup => { if (popup !== page) {
|
|
141
|
+
runtime.pageErrors++;
|
|
142
|
+
log(consolePath, { atMs: performance.now() - origin, kind: 'popup', level: 'error', text: 'recording.popupUnsupported' });
|
|
143
|
+
void popup.close().catch(() => { });
|
|
144
|
+
} });
|
|
145
|
+
await context.route('**/*', async (route) => {
|
|
146
|
+
if (route.request().isNavigationRequest() && new URL(route.request().url()).origin !== url.origin) {
|
|
147
|
+
failed = new RecordingError('navigationFailed');
|
|
148
|
+
await route.abort();
|
|
149
|
+
}
|
|
150
|
+
else
|
|
151
|
+
await route.continue();
|
|
152
|
+
});
|
|
153
|
+
page.on('dialog', dialog => { runtime.pageErrors++; log(consolePath, { atMs: performance.now() - origin, kind: 'dialog', level: 'error', text: dialog.message().slice(0, 32768) }); void dialog.dismiss(); });
|
|
154
|
+
const response = await page.goto(url.href, { waitUntil: 'load', timeout: 30_000 });
|
|
155
|
+
if (!response?.ok() || new URL(page.url()).origin !== url.origin || page.isClosed())
|
|
156
|
+
throw new RecordingError('navigationFailed');
|
|
157
|
+
const initial = join(directory, 'screenshots', 'initial.png');
|
|
158
|
+
await page.screenshot({ path: initial, timeout: 10_000 });
|
|
159
|
+
origin = performance.now();
|
|
160
|
+
inputOriginMs = Date.now();
|
|
161
|
+
const screenshots = [{ path: relativeFile(root, initial), sha256: await hashRecordingFile(initial), atMs: 0 }];
|
|
162
|
+
const session = await context.newCDPSession(page);
|
|
163
|
+
log(eventPath, { kind: 'recording-start', plannedAtMs: 0, actualAtMs: 0, inputOriginMs, navigationUrl: printableUrl(url.href), finalUrl: printableUrl(page.url()), device: scenario.pointer, reset: scenario.reset, seedApplied: false });
|
|
164
|
+
for (const step of scenario.steps) {
|
|
165
|
+
await waitUntil(origin, step.atMs, signal);
|
|
166
|
+
if (failed)
|
|
167
|
+
throw failed;
|
|
168
|
+
const omitted = variant.omittedStepIds.includes(step.id);
|
|
169
|
+
const points = (step.type === 'tap' ? [{ offsetMs: 0, x: step.x, y: step.y }] : step.path).map(point => ({ ...point, actual: recordingPoint(scenario, point) }));
|
|
170
|
+
if (omitted) {
|
|
171
|
+
log(eventPath, { stepId: step.id, kind: step.type, plannedAtMs: step.atMs, actualAtMs: performance.now() - origin, device: scenario.pointer, points, status: 'omitted' });
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const before = join(directory, 'screenshots', `${step.id}-before.png`);
|
|
175
|
+
await page.screenshot({ path: before, timeout: 10_000 });
|
|
176
|
+
screenshots.push({ path: relativeFile(root, before), sha256: await hashRecordingFile(before), atMs: Math.round(performance.now() - origin) });
|
|
177
|
+
const started = performance.now() - origin;
|
|
178
|
+
log(eventPath, { stepId: step.id, kind: step.type, plannedAtMs: step.atMs, actualAtMs: started, device: scenario.pointer, points, status: 'started' });
|
|
179
|
+
try {
|
|
180
|
+
await dispatchStep(page, session, scenario, step, origin, signal, (point, phase, plannedAtMs) => log(eventPath, { stepId: step.id, kind: 'pointer', phase, plannedAtMs, actualAtMs: performance.now() - origin, device: scenario.pointer, actual: point, status: 'dispatched' }));
|
|
181
|
+
log(eventPath, { stepId: step.id, kind: step.type, plannedAtMs: step.atMs, actualAtMs: started, completedAtMs: performance.now() - origin, device: scenario.pointer, points, status: 'dispatched' });
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
log(eventPath, { stepId: step.id, kind: step.type, plannedAtMs: step.atMs, actualAtMs: started, device: scenario.pointer, points, status: 'failed' });
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
const after = join(directory, 'screenshots', `${step.id}-after.png`);
|
|
188
|
+
await page.screenshot({ path: after, timeout: 10_000 });
|
|
189
|
+
screenshots.push({ path: relativeFile(root, after), sha256: await hashRecordingFile(after), atMs: Math.round(performance.now() - origin) });
|
|
190
|
+
}
|
|
191
|
+
await waitUntil(origin, scenario.durationMs, signal);
|
|
192
|
+
if (failed)
|
|
193
|
+
throw failed;
|
|
194
|
+
log(eventPath, { kind: 'recording-end', plannedAtMs: scenario.durationMs, actualAtMs: performance.now() - origin, status: 'completed' });
|
|
195
|
+
const closingAt = Date.now();
|
|
196
|
+
await context.close();
|
|
197
|
+
closed = true;
|
|
198
|
+
const closedAt = Date.now();
|
|
199
|
+
await logs;
|
|
200
|
+
const raw = join(directory, 'raw-capture.webm');
|
|
201
|
+
await rename(await video.path(), raw);
|
|
202
|
+
const rawProbe = JSON.parse(await mediaCommand('ffprobe', ['-v', 'error', '-show_entries', 'format=duration:stream=avg_frame_rate,codec_type', '-of', 'json', raw], signal));
|
|
203
|
+
const rawDuration = Number(rawProbe.format.duration) * 1000;
|
|
204
|
+
const stream = rawProbe.streams.find(value => value.codec_type === 'video');
|
|
205
|
+
const rate = stream?.avg_frame_rate.split('/').map(Number);
|
|
206
|
+
const fps = rate && rate[0] > 0 && rate[1] > 0 ? rate[0] / rate[1] : 0;
|
|
207
|
+
if (!Number.isFinite(rawDuration) || rawDuration <= 0 || !fps)
|
|
208
|
+
throw new RecordingError('recordingFailed');
|
|
209
|
+
// The encoder's final frame falls inside the measured context-close interval.
|
|
210
|
+
const rawOriginMs = closingAt - rawDuration;
|
|
211
|
+
const offsetMs = Math.max(0, inputOriginMs - rawOriginMs);
|
|
212
|
+
const candidate = join(directory, 'candidate.mp4');
|
|
213
|
+
await mediaCommand('ffmpeg', ['-v', 'error', '-nostdin', '-i', raw, '-ss', (offsetMs / 1000).toFixed(6), '-t', (scenario.durationMs / 1000).toFixed(6), '-an', '-c:v', 'libx264', '-preset', 'ultrafast', '-crf', '20', '-pix_fmt', 'yuv420p', '-movflags', '+faststart', candidate], signal);
|
|
214
|
+
const probed = await probeVideo(candidate, signal);
|
|
215
|
+
const uncertaintyMs = closedAt - closingAt + 1000 / fps + Math.max(0, rawOriginMs - inputOriginMs);
|
|
216
|
+
if (probed.source.width !== scenario.viewport.width || probed.source.height !== scenario.viewport.height || probed.source.durationMs < scenario.durationMs - uncertaintyMs - 1000 / fps)
|
|
217
|
+
throw new RecordingError('recordingFailed');
|
|
218
|
+
return {
|
|
219
|
+
...variant, video: { path: relativeFile(root, candidate), source: probed.source, fps },
|
|
220
|
+
events: { path: relativeFile(root, eventPath), sha256: await hashRecordingFile(eventPath) }, console: { path: relativeFile(root, consolePath), sha256: await hashRecordingFile(consolePath) },
|
|
221
|
+
timing: { inputOriginMs, videoOriginMs: inputOriginMs, uncertaintyMs }, runtime, screenshots,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
signal.removeEventListener('abort', closeOnAbort);
|
|
226
|
+
if (!closed)
|
|
227
|
+
await context.close().catch(() => { });
|
|
228
|
+
await logs;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
export async function recordPlayable(options, signal) {
|
|
232
|
+
const runId = randomUUID();
|
|
233
|
+
let out;
|
|
234
|
+
let browser;
|
|
235
|
+
let prepared = false;
|
|
236
|
+
try {
|
|
237
|
+
const url = recordingUrl(options.url);
|
|
238
|
+
if (!options.scenario || options.browserPath && !isAbsolute(options.browserPath))
|
|
239
|
+
throw new RecordingError('invalidArguments', 64);
|
|
240
|
+
const scenarioStat = await stat(options.scenario).catch(() => { throw new RecordingError('invalidArguments', 64); });
|
|
241
|
+
if (!scenarioStat.isFile() || scenarioStat.size > 1024 * 1024)
|
|
242
|
+
throw new RecordingError('invalidArguments', 64);
|
|
243
|
+
let scenario;
|
|
244
|
+
try {
|
|
245
|
+
scenario = parseRecordingScenario(JSON.parse(await readFile(options.scenario, 'utf8')));
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
throw new RecordingError('invalidArguments', 64);
|
|
249
|
+
}
|
|
250
|
+
const scenarioSha256 = sha(canonicalReplicaJson(scenario));
|
|
251
|
+
const configuredPath = options.browserPath || process.env.PLAYCRAFT_CHROMIUM_PATH || '/usr/bin/chromium';
|
|
252
|
+
if (!isAbsolute(configuredPath))
|
|
253
|
+
throw new RecordingError('invalidArguments', 64);
|
|
254
|
+
await access(configuredPath).catch(() => { throw new RecordingError('browserUnavailable'); });
|
|
255
|
+
out = resolve(options.out || join('.playcraft', 'video-replication', runId, 'recording'));
|
|
256
|
+
const project = await computeProjectInputDigest(process.cwd(), [out]);
|
|
257
|
+
await prepareArtifactDirectory(out, runId, false);
|
|
258
|
+
prepared = true;
|
|
259
|
+
await writeJsonAtomic(join(out, 'metadata.json'), { schemaVersion: 'playcraft.replica-recording.v1', runId, state: 'recording', scenarioSha256 });
|
|
260
|
+
const ffmpeg = (await mediaCommand('ffmpeg', ['-version'], signal)).split('\n')[0];
|
|
261
|
+
if (!process.env.PLAYWRIGHT_BROWSERS_PATH && await access('/opt/playcraft/playwright').then(() => true, () => false))
|
|
262
|
+
process.env.PLAYWRIGHT_BROWSERS_PATH = '/opt/playcraft/playwright';
|
|
263
|
+
const { chromium } = await import('playwright-core');
|
|
264
|
+
browser = await chromium.launch({ executablePath: configuredPath, headless: true, args: ['--mute-audio', '--disable-dev-shm-usage', '--enable-unsafe-swiftshader', '--use-gl=angle', '--use-angle=swiftshader', ...(process.getuid?.() === 0 ? ['--no-sandbox'] : [])] }).catch(() => { throw new RecordingError('browserUnavailable'); });
|
|
265
|
+
process.stderr.write(`[record] ${recordingMessage('recording')}\n`);
|
|
266
|
+
const candidate = await recordOne(browser, out, url, scenario, { id: 'candidate', kind: 'candidate', omittedStepIds: [] }, signal);
|
|
267
|
+
const controls = [];
|
|
268
|
+
for (const control of recordingControls(scenario))
|
|
269
|
+
controls.push(await recordOne(browser, out, url, scenario, control, signal));
|
|
270
|
+
const current = await computeProjectInputDigest(process.cwd(), [out]);
|
|
271
|
+
if (current.sha256 !== project.sha256)
|
|
272
|
+
throw new RecordingError('projectChanged', 64);
|
|
273
|
+
const metadata = replicaRecordingMetadataSchema.parse({
|
|
274
|
+
schemaVersion: 'playcraft.replica-recording.v1', runId, state: 'completed', scenario, scenarioSha256, project,
|
|
275
|
+
toolVersions: { cli: require('../../package.json').version, playwright: require('playwright-core/package.json').version, browser: browser.version(), ffmpeg },
|
|
276
|
+
conditions: { audio: 'muted', seedSupport: scenario.seed ? 'best-effort' : 'not-requested', serverStateReset: 'not-guaranteed' },
|
|
277
|
+
candidate, controls,
|
|
278
|
+
});
|
|
279
|
+
await writeJsonAtomic(join(out, 'metadata.json'), metadata);
|
|
280
|
+
return { exitCode: 0, envelope: { schemaVersion: 'playcraft.video-cli.v1', command: 'playable record', runId, state: 'completed', ok: true,
|
|
281
|
+
artifacts: { metadata: join(out, 'metadata.json'), candidate: join(out, candidate.video.path), controls: controls.map(control => join(out, control.video.path)) }, result: metadata } };
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
const code = error instanceof RecordingError ? error.code : error instanceof VideoCliError && error.code === 'outputConflict' ? 'outputConflict' : signal.aborted ? signal.reason?.name === 'TimeoutError' ? 'timedOut' : 'interrupted' : 'recordingFailed';
|
|
285
|
+
const exitCode = error instanceof RecordingError || error instanceof VideoCliError ? error.exitCode : signal.aborted ? code === 'timedOut' ? 75 : 130 : 4;
|
|
286
|
+
if (out && prepared)
|
|
287
|
+
await writeJsonAtomic(join(out, 'metadata.json'), { schemaVersion: 'playcraft.replica-recording.v1', runId, state: 'failed', error: { code } }).catch(() => { });
|
|
288
|
+
return { exitCode, envelope: { schemaVersion: 'playcraft.video-cli.v1', command: 'playable record', runId, state: 'failed', ok: false, ...(out && prepared ? { artifacts: { metadata: join(out, 'metadata.json') } } : {}), error: { code, message: recordingMessage(code) } } };
|
|
289
|
+
}
|
|
290
|
+
finally {
|
|
291
|
+
await browser?.close().catch(() => { });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { replicaScenarioSchema } from '@playcraft/common/agent-tools';
|
|
2
|
+
import { RecordingError } from './messages.js';
|
|
3
|
+
export function recordingUrl(value) {
|
|
4
|
+
try {
|
|
5
|
+
if (!value)
|
|
6
|
+
throw new Error();
|
|
7
|
+
const url = new URL(value);
|
|
8
|
+
if (url.protocol !== 'http:' || !['127.0.0.1', '[::1]', 'localhost'].includes(url.hostname) || url.username || url.password || url.hash)
|
|
9
|
+
throw new Error();
|
|
10
|
+
return url;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
throw new RecordingError('invalidUrl', 64);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function parseRecordingScenario(value) {
|
|
17
|
+
const parsed = replicaScenarioSchema.safeParse(value);
|
|
18
|
+
if (!parsed.success)
|
|
19
|
+
throw new RecordingError('invalidArguments', 64);
|
|
20
|
+
const scenario = parsed.data;
|
|
21
|
+
if (scenario.draft || scenario.viewport.width % 2 || scenario.viewport.height % 2 || scenario.steps.length > 63 || scenario.steps.some(step => step.id.length > 110))
|
|
22
|
+
throw new RecordingError('invalidArguments', 64);
|
|
23
|
+
const ids = new Set();
|
|
24
|
+
let previousEnd = -1;
|
|
25
|
+
for (const step of scenario.steps) {
|
|
26
|
+
if (ids.has(step.id) || step.atMs < previousEnd)
|
|
27
|
+
throw new RecordingError('invalidArguments', 64);
|
|
28
|
+
ids.add(step.id);
|
|
29
|
+
const end = step.atMs + (step.type === 'drag' ? step.path.at(-1).offsetMs : 0);
|
|
30
|
+
if (end >= scenario.durationMs)
|
|
31
|
+
throw new RecordingError('invalidArguments', 64);
|
|
32
|
+
if (step.type === 'drag' && (step.path[0].offsetMs !== 0 || step.path.some((point, index) => index > 0 && point.offsetMs <= step.path[index - 1].offsetMs)))
|
|
33
|
+
throw new RecordingError('invalidArguments', 64);
|
|
34
|
+
previousEnd = end;
|
|
35
|
+
}
|
|
36
|
+
const required = new Set(scenario.requiredEffects.map(effect => effect.stepId));
|
|
37
|
+
if ([...required].some(id => !ids.has(id)) || (scenario.controls.noInput ? 1 : 0) + (scenario.controls.omitRequiredSteps ? required.size : 0) > 4)
|
|
38
|
+
throw new RecordingError('invalidArguments', 64);
|
|
39
|
+
return scenario;
|
|
40
|
+
}
|
|
41
|
+
export function recordingControls(scenario) {
|
|
42
|
+
return [
|
|
43
|
+
...(scenario.controls.noInput ? [{ id: 'control-no-input', kind: 'no-input', omittedStepIds: scenario.steps.map(step => step.id) }] : []),
|
|
44
|
+
...(scenario.controls.omitRequiredSteps ? [...new Set(scenario.requiredEffects.map(effect => effect.stepId))].map(id => ({ id: `control-omit-${id}`, kind: 'omit-step', omittedStepIds: [id] })) : []),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
export function recordingPoint(scenario, point) {
|
|
48
|
+
const rect = scenario.contentRect;
|
|
49
|
+
return { x: (rect.x + point.x * rect.width) * scenario.viewport.width, y: (rect.y + point.y * rect.height) * scenario.viewport.height };
|
|
50
|
+
}
|
package/dist/remix/clone.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { prepareLocalSkillLifecycle } from '../project-skills/lifecycle.js';
|
|
1
2
|
import { spawnSync } from 'node:child_process';
|
|
2
3
|
import { mkdirSync, writeFileSync, readFileSync, existsSync } from 'node:fs';
|
|
3
4
|
import path from 'node:path';
|
|
@@ -151,6 +152,7 @@ export async function remixClone(options) {
|
|
|
151
152
|
};
|
|
152
153
|
writePlaycraftMeta(targetDir, meta);
|
|
153
154
|
configureRepoCredentialHelper(targetDir);
|
|
155
|
+
await prepareLocalSkillLifecycle(targetDir, 'checkout');
|
|
154
156
|
let projectType;
|
|
155
157
|
try {
|
|
156
158
|
const project = await client.get(`/projects/${encodeURIComponent(projectId)}`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { prepareLocalSkillLifecycle } from '../project-skills/lifecycle.js';
|
|
1
2
|
import * as path from 'node:path';
|
|
2
3
|
import { applyEnginePackToProject, bakeFullTemplate, KNOWN_ADAPTERS, readAdapterFromAtomTree, readEngineMarker, resolveCliPackageRoot, } from '../scaffold/compose.js';
|
|
3
4
|
import { autoLinkSkillsFromAtomTree } from '../commands/skills.js';
|
|
@@ -68,6 +69,7 @@ export async function initTemplateCommand(opts) {
|
|
|
68
69
|
console.log(` ⚠ auto-link skipped: ${err.message}`);
|
|
69
70
|
}
|
|
70
71
|
}
|
|
72
|
+
await prepareLocalSkillLifecycle(projectDir, 'create');
|
|
71
73
|
console.log('\n下一步:');
|
|
72
74
|
console.log(' npm install');
|
|
73
75
|
console.log(' 阅读 .claude/skills/<atom>/SKILL.md(已自动 link)并填 logs/developer-log.md § Skill Preflight');
|
package/dist/remix/pull.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { prepareLocalSkillLifecycle } from '../project-skills/lifecycle.js';
|
|
1
2
|
import { spawnSync } from 'node:child_process';
|
|
2
3
|
import { existsSync } from 'node:fs';
|
|
3
4
|
import path from 'node:path';
|
|
@@ -44,6 +45,7 @@ export async function remixPull(options = {}) {
|
|
|
44
45
|
const detail = [result.stderr, result.stdout].filter(Boolean).join('\n').trim();
|
|
45
46
|
throw new Error(detail || `git pull 失败(exit ${result.status})`);
|
|
46
47
|
}
|
|
48
|
+
await prepareLocalSkillLifecycle(repoDir, 'checkout');
|
|
47
49
|
if (options.json) {
|
|
48
50
|
console.log(JSON.stringify({
|
|
49
51
|
schemaVersion: '1.0',
|
package/dist/remix/push.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { prepareLocalSkillLifecycle } from '../project-skills/lifecycle.js';
|
|
2
|
+
import { reconcileLocalProjectSkills } from '../project-skills/reconcile.js';
|
|
3
|
+
import { projectSkillsMessage as skillMessage } from '../project-skills/messages.js';
|
|
1
4
|
import { spawnSync } from 'node:child_process';
|
|
2
5
|
import { existsSync } from 'node:fs';
|
|
3
6
|
import path from 'node:path';
|
|
@@ -41,6 +44,7 @@ export async function remixPush(options = {}) {
|
|
|
41
44
|
process.stderr.write(`[push] ${meta.cloneUrl}\n`);
|
|
42
45
|
process.stderr.write(`[push] branch=${meta.branch} dir=${repoDir}\n`);
|
|
43
46
|
}
|
|
47
|
+
const skills = await prepareLocalSkillLifecycle(repoDir, 'push');
|
|
44
48
|
const result = runAuthenticatedGit(['push', ...effectiveArgs], {
|
|
45
49
|
cwd: repoDir,
|
|
46
50
|
token: client.token,
|
|
@@ -50,10 +54,24 @@ export async function remixPush(options = {}) {
|
|
|
50
54
|
const detail = [result.stderr, result.stdout].filter(Boolean).join('\n').trim();
|
|
51
55
|
throw new Error(detail || `git push 失败(exit ${result.status})`);
|
|
52
56
|
}
|
|
57
|
+
let skillIndex;
|
|
58
|
+
let skillIndexFailed = false;
|
|
59
|
+
if (skills.managed) {
|
|
60
|
+
try {
|
|
61
|
+
skillIndex = await reconcileLocalProjectSkills(repoDir, { url: options.url, token: options.token });
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
skillIndexFailed = true;
|
|
65
|
+
skillIndex = { indexed: false, message: skillMessage('pushIndexFailed'), detail: error instanceof Error ? error.message : String(error) };
|
|
66
|
+
process.exitCode = 1;
|
|
67
|
+
}
|
|
68
|
+
if (!options.json)
|
|
69
|
+
process.stderr.write(`${JSON.stringify(skillIndex)}\n`);
|
|
70
|
+
}
|
|
53
71
|
if (options.json) {
|
|
54
72
|
console.log(JSON.stringify({
|
|
55
73
|
schemaVersion: '1.0',
|
|
56
|
-
ok:
|
|
74
|
+
ok: !skillIndexFailed,
|
|
57
75
|
command: 'remix.push',
|
|
58
76
|
requestId: client.requestId,
|
|
59
77
|
data: {
|
|
@@ -62,6 +80,8 @@ export async function remixPush(options = {}) {
|
|
|
62
80
|
cloneUrl: meta.cloneUrl,
|
|
63
81
|
dir: repoDir,
|
|
64
82
|
gitArgs: effectiveArgs,
|
|
83
|
+
gitPushed: true,
|
|
84
|
+
skills: skillIndex,
|
|
65
85
|
},
|
|
66
86
|
}));
|
|
67
87
|
return;
|