@playcraft/cli 0.1.27 → 0.1.29
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 +3 -38
- package/dist/agent/local-backend.js +1 -1
- package/dist/cli-root-help.js +0 -2
- package/dist/commands/build.js +4 -9
- package/dist/commands/create.js +33 -26
- package/dist/commands/image.js +6 -2
- package/dist/commands/login.js +42 -84
- package/dist/commands/skills.js +0 -2
- package/dist/commands/tools-3d.js +0 -11
- package/dist/commands/tools-generation.js +109 -68
- package/dist/commands/tools-image-context.js +23 -0
- package/dist/commands/tools.js +2 -2
- package/dist/config.js +4 -59
- package/dist/index.js +3 -34
- package/dist/remix/clone.js +0 -2
- package/dist/remix/init-template.js +0 -2
- package/dist/remix/pull.js +0 -2
- package/dist/remix/push.js +1 -21
- package/dist/utils/agent-api-client.js +30 -185
- package/dist/utils/image-asset-context.js +105 -0
- package/dist/utils/playcraft-http-client.js +4 -6
- package/package.json +5 -14
- package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +81 -23
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/SKILL.md +81 -23
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/SKILL.md +81 -23
- package/dist/auth/account-activation.js +0 -157
- package/dist/auth/messages.js +0 -30
- package/dist/commands/platform-skills.generated.js +0 -19
- package/dist/commands/playable.js +0 -53
- package/dist/commands/tools-batch.js +0 -87
- package/dist/commands/video.js +0 -111
- package/dist/commands/workspace-runtime.js +0 -54
- package/dist/project-skills/builtin-import.js +0 -225
- package/dist/project-skills/commands.js +0 -77
- package/dist/project-skills/lifecycle.js +0 -28
- package/dist/project-skills/local-run.js +0 -112
- package/dist/project-skills/local-store.js +0 -221
- package/dist/project-skills/messages.js +0 -80
- package/dist/project-skills/reconcile.js +0 -62
- package/dist/project-skills/remote-cache.js +0 -51
- package/dist/project-skills/validation.js +0 -19
- package/dist/recording/messages.js +0 -40
- package/dist/recording/project-digest.js +0 -85
- package/dist/recording/recorder.js +0 -293
- package/dist/recording/scenario.js +0 -50
- package/dist/utils/environment-endpoints.js +0 -17
- package/dist/utils/tool-operation-journal.js +0 -124
- package/dist/utils/video-evidence-git.js +0 -81
- package/dist/video-replication/client.js +0 -222
- package/dist/video-replication/comparison-evidence.js +0 -149
- package/dist/video-replication/comparison-files.js +0 -57
- package/dist/video-replication/comparison-log.js +0 -72
- package/dist/video-replication/comparison-messages.js +0 -104
- package/dist/video-replication/comparison-output.js +0 -63
- package/dist/video-replication/comparison-preflight.js +0 -66
- package/dist/video-replication/comparison.js +0 -216
- package/dist/video-replication/evidence.js +0 -165
- package/dist/video-replication/media.js +0 -111
- package/dist/video-replication/messages.js +0 -89
- package/dist/workspace-runtime/codex/app-server.js +0 -636
- package/dist/workspace-runtime/codex/config-toml.js +0 -107
- package/dist/workspace-runtime/codex/jsonrpc-stdio.js +0 -123
- package/dist/workspace-runtime/codex/launcher-client.js +0 -163
- package/dist/workspace-runtime/codex/loopback.js +0 -143
- package/dist/workspace-runtime/codex/model-broker.js +0 -258
- package/dist/workspace-runtime/codex/native-adapter.js +0 -9
- package/dist/workspace-runtime/main.js +0 -10
- package/dist/workspace-runtime/persistence/journal.js +0 -355
- package/dist/workspace-runtime/persistence/native-subagents.js +0 -162
- package/dist/workspace-runtime/persistence/sqlite-client.js +0 -77
- package/dist/workspace-runtime/persistence/sqlite-worker.js +0 -1057
- package/dist/workspace-runtime/previews/publish.js +0 -259
- package/dist/workspace-runtime/previews/single-file.js +0 -43
- package/dist/workspace-runtime/processes/managed-writes.js +0 -69
- package/dist/workspace-runtime/production/contracts.js +0 -17
- package/dist/workspace-runtime/production/controller.js +0 -207
- package/dist/workspace-runtime/production/dependencies.js +0 -60
- package/dist/workspace-runtime/production/native.js +0 -90
- package/dist/workspace-runtime/production/processes.js +0 -86
- package/dist/workspace-runtime/production/save-command.js +0 -24
- package/dist/workspace-runtime/production/source-copy.js +0 -91
- package/dist/workspace-runtime/production/stages.js +0 -202
- package/dist/workspace-runtime/production/storage.js +0 -32
- package/dist/workspace-runtime/serve.js +0 -202
- package/dist/workspace-runtime/server/auth.js +0 -21
- package/dist/workspace-runtime/server/connectivity.js +0 -201
- package/dist/workspace-runtime/server/desktop-host.js +0 -429
- package/dist/workspace-runtime/server/desktop-preview-config.js +0 -81
- package/dist/workspace-runtime/server/desktop-preview-service.js +0 -157
- package/dist/workspace-runtime/server/desktop-preview-static.js +0 -53
- package/dist/workspace-runtime/server/desktop-preview.js +0 -189
- package/dist/workspace-runtime/server/dispatch.js +0 -903
- package/dist/workspace-runtime/server/endpoints.js +0 -19
- package/dist/workspace-runtime/server/execution-group.js +0 -85
- package/dist/workspace-runtime/server/http.js +0 -984
- package/dist/workspace-runtime/server/lock.js +0 -53
- package/dist/workspace-runtime/server/rfb-watch-gate.js +0 -168
- package/dist/workspace-runtime/server/terminal-host.js +0 -294
- package/dist/workspace-runtime/server/types.js +0 -1
- package/dist/workspace-runtime/workspaces/artifact-events.js +0 -55
- package/dist/workspace-runtime/workspaces/artifact-files.js +0 -195
- package/dist/workspace-runtime/workspaces/artifact-receipts.js +0 -89
- package/dist/workspace-runtime/workspaces/artifacts.js +0 -260
- package/dist/workspace-runtime/workspaces/attachment-content.js +0 -111
- package/dist/workspace-runtime/workspaces/attachments.js +0 -175
- package/dist/workspace-runtime/workspaces/batch-commit.js +0 -142
- package/dist/workspace-runtime/workspaces/cli-context.js +0 -23
- package/dist/workspace-runtime/workspaces/cli-credentials.js +0 -111
- package/dist/workspace-runtime/workspaces/context-error.js +0 -2
- package/dist/workspace-runtime/workspaces/dependencies.js +0 -264
- package/dist/workspace-runtime/workspaces/developer-command.js +0 -64
- package/dist/workspace-runtime/workspaces/directories.js +0 -113
- package/dist/workspace-runtime/workspaces/directory-access.js +0 -29
- package/dist/workspace-runtime/workspaces/directory-maintenance.js +0 -111
- package/dist/workspace-runtime/workspaces/directory-stats.js +0 -49
- package/dist/workspace-runtime/workspaces/disk-snapshot.js +0 -31
- package/dist/workspace-runtime/workspaces/empty-template.js +0 -40
- package/dist/workspace-runtime/workspaces/files.js +0 -120
- package/dist/workspace-runtime/workspaces/git-credential-broker.js +0 -312
- package/dist/workspace-runtime/workspaces/git-credential-helper.js +0 -68
- package/dist/workspace-runtime/workspaces/git-direct-store.js +0 -155
- package/dist/workspace-runtime/workspaces/git.js +0 -517
- package/dist/workspace-runtime/workspaces/json5-edit.js +0 -170
- package/dist/workspace-runtime/workspaces/parameters.js +0 -272
- package/dist/workspace-runtime/workspaces/prepare.js +0 -264
- package/dist/workspace-runtime/workspaces/registry.js +0 -226
- package/dist/workspace-runtime/workspaces/revisions.js +0 -31
- package/dist/workspace-runtime/workspaces/skill-artifact-loader.js +0 -91
- package/dist/workspace-runtime/workspaces/skills.js +0 -189
- package/dist/workspace-runtime/workspaces/video-attachments.js +0 -49
- package/project-template/.claude/skills/playcraft-replica-validation/SKILL.md +0 -25
- package/project-template/.claude/skills/playcraft-replica-validation/references/contracts.md +0 -79
- package/project-template/.claude/skills/playcraft-video-understanding/SKILL.md +0 -29
- package/project-template/.claude/skills/playcraft-video-understanding/references/contracts.md +0 -37
- package/project-template-v2/.claude/agents/artist.md +0 -82
- package/project-template-v2/.claude/agents/developer.md +0 -153
- package/project-template-v2/.claude/agents/game-designer.md +0 -264
- package/project-template-v2/.claude/agents/refs/artist-art-style-catalog.md +0 -533
- package/project-template-v2/.claude/agents/refs/artist-color-audio-recipes.md +0 -153
- package/project-template-v2/.claude/agents/refs/artist-dimension-axis.md +0 -27
- package/project-template-v2/.claude/agents/refs/artist-master-composite-recipes.md +0 -208
- package/project-template-v2/.claude/agents/refs/atom-skill-library.md +0 -81
- package/project-template-v2/.claude/agents/refs/developer-impl-cookbook.md +0 -432
- package/project-template-v2/.claude/agents/refs/framework-5-component-filter.md +0 -252
- package/project-template-v2/.claude/agents/refs/framework-game-feel-juice.md +0 -266
- package/project-template-v2/.claude/agents/refs/framework-mda.md +0 -147
- package/project-template-v2/.claude/agents/refs/game-designer-gameplay-sufficiency.md +0 -123
- package/project-template-v2/.claude/agents/refs/ta-3d-flip-recipe.md +0 -88
- package/project-template-v2/.claude/agents/refs/ta-atlas-deliverable-standard.md +0 -67
- package/project-template-v2/.claude/agents/refs/ta-batch-pipeline-recipes.md +0 -120
- package/project-template-v2/.claude/agents/refs/ta-image-generation-detail.md +0 -300
- package/project-template-v2/.claude/agents/refs/ta-image-ops-reference.md +0 -495
- package/project-template-v2/.claude/agents/refs/ta-pipeline-cookbook.md +0 -1141
- package/project-template-v2/.claude/agents/refs/ta-tools-reference.md +0 -111
- package/project-template-v2/.claude/agents/refs/ta-vfx-preset-catalog.md +0 -365
- package/project-template-v2/.claude/agents/refs/threejs-cannon-pitfalls.md +0 -412
- package/project-template-v2/.claude/agents/reviewer.md +0 -75
- package/project-template-v2/.claude/agents/technical-artist.md +0 -86
- package/project-template-v2/.claude/hooks/snapshot-milestone.mjs +0 -243
- package/project-template-v2/.claude/hooks/user-prompt.mjs +0 -133
- package/project-template-v2/.claude/settings.json +0 -33
- package/project-template-v2/.claude/skills/brainstorming/SKILL.md +0 -161
- package/project-template-v2/.claude/skills/brainstorming/scripts/frame-template.html +0 -270
- package/project-template-v2/.claude/skills/brainstorming/scripts/helper.js +0 -177
- package/project-template-v2/.claude/skills/brainstorming/scripts/server.cjs +0 -354
- package/project-template-v2/.claude/skills/brainstorming/scripts/start-server.sh +0 -148
- package/project-template-v2/.claude/skills/brainstorming/scripts/stop-server.sh +0 -56
- package/project-template-v2/.claude/skills/brainstorming/scripts/wait-for-selection.sh +0 -62
- package/project-template-v2/.claude/skills/brainstorming/spec-document-reviewer-prompt.md +0 -49
- package/project-template-v2/.claude/skills/brainstorming/visual-companion.md +0 -309
- package/project-template-v2/.claude/skills/playcraft-ad-psychology/SKILL.md +0 -182
- package/project-template-v2/.claude/skills/playcraft-art-style-guide/SKILL.md +0 -123
- package/project-template-v2/.claude/skills/playcraft-asset-state-sheet/SKILL.md +0 -205
- package/project-template-v2/.claude/skills/playcraft-audio-generation/SKILL.md +0 -280
- package/project-template-v2/.claude/skills/playcraft-batch-pipeline/SKILL.md +0 -184
- package/project-template-v2/.claude/skills/playcraft-build-optimizer/SKILL.md +0 -306
- package/project-template-v2/.claude/skills/playcraft-image-generation/SKILL.md +0 -298
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +0 -123
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +0 -254
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +0 -324
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +0 -97
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +0 -118
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +0 -137
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +0 -397
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +0 -296
- package/project-template-v2/.claude/skills/playcraft-image-ops/SKILL.md +0 -122
- package/project-template-v2/.claude/skills/playcraft-image-processing/SKILL.md +0 -219
- package/project-template-v2/.claude/skills/playcraft-masking/SKILL.md +0 -373
- package/project-template-v2/.claude/skills/playcraft-playable-optimization/SKILL.md +0 -161
- package/project-template-v2/.claude/skills/playcraft-research/SKILL.md +0 -215
- package/project-template-v2/.claude/skills/playcraft-skill-recommender/SKILL.md +0 -382
- package/project-template-v2/.claude/skills/playcraft-sprite-generation/SKILL.md +0 -423
- package/project-template-v2/.claude/skills/playcraft-sprite-remix/SKILL.md +0 -158
- package/project-template-v2/.claude/skills/playcraft-sprite-sheet/SKILL.md +0 -100
- package/project-template-v2/.claude/skills/playcraft-storyboard/SKILL.md +0 -167
- package/project-template-v2/.claude/skills/playcraft-style-qa/SKILL.md +0 -270
- package/project-template-v2/.claude/skills/playcraft-text-rendering/SKILL.md +0 -236
- package/project-template-v2/.claude/skills/playcraft-vfx-animation/SKILL.md +0 -130
- package/project-template-v2/.claude/skills/playwright-cli/SKILL.md +0 -390
- package/project-template-v2/.claude/skills/playwright-cli/references/element-attributes.md +0 -23
- package/project-template-v2/.claude/skills/playwright-cli/references/playwright-tests.md +0 -39
- package/project-template-v2/.claude/skills/playwright-cli/references/request-mocking.md +0 -87
- package/project-template-v2/.claude/skills/playwright-cli/references/running-code.md +0 -240
- package/project-template-v2/.claude/skills/playwright-cli/references/session-management.md +0 -226
- package/project-template-v2/.claude/skills/playwright-cli/references/spec-driven-testing.md +0 -308
- package/project-template-v2/.claude/skills/playwright-cli/references/storage-state.md +0 -275
- package/project-template-v2/.claude/skills/playwright-cli/references/test-generation.md +0 -134
- package/project-template-v2/.claude/skills/playwright-cli/references/tracing.md +0 -142
- package/project-template-v2/.claude/skills/playwright-cli/references/video-recording.md +0 -153
- package/project-template-v2/.claude/skills/session-analyzer/SKILL.md +0 -386
- package/project-template-v2/.claude/skills/session-analyzer/scripts/execution-breakdown.mjs +0 -182
- package/project-template-v2/.claude/skills/session-analyzer/scripts/find-turns.mjs +0 -72
- package/project-template-v2/.claude/skills/session-analyzer/scripts/heavy-output.mjs +0 -121
- package/project-template-v2/.claude/skills/session-analyzer/scripts/resolve-session.mjs +0 -102
- package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-stats.mjs +0 -127
- package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-tool-timeline.mjs +0 -106
- package/project-template-v2/.claude/skills/session-analyzer/scripts/time-gaps.mjs +0 -128
- package/project-template-v2/.claude/skills/session-analyzer/scripts/turn-timeline.mjs +0 -67
- package/project-template-v2/.claude/snapshot.mjs +0 -263
- package/project-template-v2/.playcraft/skills.lock.json +0 -152
- package/project-template-v2/CLAUDE.md +0 -146
- 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 +0 -254
- package/project-template-v2/docs/harness/iteration-1/generate-flow.md +0 -91
- package/project-template-v2/docs/harness/iteration-1/ideate-flow.md +0 -214
- package/project-template-v2/docs/harness/iteration-1/optimize-flow.md +0 -75
- package/project-template-v2/docs/harness/iteration-1/wrapup-flow.md +0 -63
- package/project-template-v2/docs/harness/iteration-2/context-flow.md +0 -223
- package/project-template-v2/docs/harness/iteration-2/generate-flow.md +0 -129
- package/project-template-v2/docs/harness/iteration-2/ideate-flow.md +0 -267
- package/project-template-v2/docs/harness/iteration-2/optimize-flow.md +0 -164
- package/project-template-v2/docs/harness/iteration-2/wrapup-flow.md +0 -115
- package/project-template-v2/docs/harness/orchestrator-flow.md +0 -364
- package/project-template-v2/docs/project-state.json +0 -60
- package/project-template-v2/docs/project-state.md +0 -72
- package/project-template-v2/docs/standards/README.md +0 -225
- package/project-template-v2/docs/standards/agent-behavior-standards.md +0 -174
- package/project-template-v2/docs/standards/artifacts/design-brief.md +0 -19
- package/project-template-v2/docs/standards/artifacts/design.md +0 -22
- package/project-template-v2/docs/standards/artifacts/game-code.md +0 -41
- package/project-template-v2/docs/standards/artifacts/todo-list.md +0 -41
- package/project-template-v2/docs/standards/iter1-agent-behavior-standards.md +0 -343
- package/project-template-v2/game/index.ts +0 -18
- package/project-template-v2/globals.d.ts +0 -51
- package/project-template-v2/index.css +0 -34
- package/project-template-v2/index.html +0 -18
- package/project-template-v2/main.ts +0 -9
- package/project-template-v2/package.json +0 -46
- package/project-template-v2/skills/_shared/scripts/dispatch-clear.mjs +0 -31
- package/project-template-v2/skills/_shared/scripts/dispatch-set.mjs +0 -86
- package/project-template-v2/skills/_shared/scripts/dod-check.mjs +0 -153
- package/project-template-v2/skills/_shared/scripts/handoff-append.mjs +0 -70
- package/project-template-v2/skills/_shared/scripts/lib/validator-artifacts.mjs +0 -91
- package/project-template-v2/skills/_shared/scripts/pipeline/dod-config.mjs +0 -131
- package/project-template-v2/skills/_shared/scripts/pipeline/index.mjs +0 -80
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-1-core.mjs +0 -90
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-2-wrap.mjs +0 -93
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-3-visual.mjs +0 -23
- package/project-template-v2/skills/_shared/scripts/render-project-state.mjs +0 -230
- package/project-template-v2/skills/_shared/scripts/state-advance-stage.mjs +0 -58
- package/project-template-v2/skills/_shared/scripts/state-get.mjs +0 -339
- package/project-template-v2/skills/_shared/scripts/state-handoff.mjs +0 -39
- package/project-template-v2/skills/_shared/scripts/state-set.mjs +0 -94
- package/project-template-v2/skills/_shared/scripts/state-store.mjs +0 -783
- package/project-template-v2/skills/_shared/scripts/todo-add.mjs +0 -88
- package/project-template-v2/skills/_shared/scripts/todo-get.mjs +0 -130
- package/project-template-v2/skills/_shared/scripts/todo-remove.mjs +0 -33
- package/project-template-v2/skills/_shared/scripts/todo-set.mjs +0 -47
- package/project-template-v2/skills/_shared/scripts/verify-asset-code-sync.mjs +0 -268
- package/project-template-v2/skills/_shared/scripts/verify-env.mjs +0 -285
- package/project-template-v2/skills/_shared/scripts/verify-placeholders.mjs +0 -161
- package/project-template-v2/skills/playable-autoplay/SKILL.md +0 -176
- package/project-template-v2/skills/playable-autoplay/agents/openai.yaml +0 -4
- package/project-template-v2/skills/playable-debug/SKILL.md +0 -116
- package/project-template-v2/skills/playable-debug/agents/openai.yaml +0 -4
- package/project-template-v2/skills/playable-debug/references/debug-config.md +0 -40
- package/project-template-v2/skills/playable-record/SKILL.md +0 -140
- package/project-template-v2/skills/playable-record/scripts/lib/dev-server.mjs +0 -104
- package/project-template-v2/skills/playable-record/scripts/lib/record-audio-bridge.js +0 -141
- package/project-template-v2/skills/playable-record/scripts/record-playable.mjs +0 -425
- package/project-template-v2/skills/playable-record/scripts/verify-contract.mjs +0 -261
- package/project-template-v2/skills/playable-record/scripts/verify-firstwin.mjs +0 -398
- package/project-template-v2/skills/playable-record/scripts/verify-fusion.mjs +0 -322
- package/project-template-v2/skills/playable-record/scripts/verify-lifecycle.mjs +0 -105
- package/project-template-v2/skills/playable-record/scripts/verify-vlm-video.mjs +0 -230
- package/project-template-v2/skills/playable-validate/SKILL.md +0 -61
- package/project-template-v2/skills/playable-validate/validation-rules.md +0 -14
- package/project-template-v2/skills/playable-verify-ui/SKILL.md +0 -63
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/__init__.py +0 -1
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/config_expr.js +0 -218
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/node_utils.js +0 -51
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/profile_loader.py +0 -59
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/report.py +0 -106
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/runtime_contract.js +0 -116
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_fetch_antipatterns.py +0 -59
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_hardcoded_layout.js +0 -64
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_runtime_contract.js +0 -58
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_text_overlap.py +0 -333
- package/project-template-v2/ta-workspace/scripts/.gitkeep +0 -0
- package/project-template-v2/tsconfig.json +0 -20
- package/project-template-v2/vite.config.ts +0 -27
- package/project-templates/batch-locks/phaser.yaml +0 -922
- package/project-templates/batch-locks/threejs.yaml +0 -978
- package/project-templates/empty/AGENTS.md +0 -25
- package/project-templates/empty/gitignore +0 -33
|
@@ -1,293 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
function publicBase(value) {
|
|
2
|
-
const base = new URL(value);
|
|
3
|
-
if (!['http:', 'https:'].includes(base.protocol) || base.username || base.password || base.search || base.hash) {
|
|
4
|
-
throw new Error('invalid_environment_endpoint');
|
|
5
|
-
}
|
|
6
|
-
base.pathname = base.pathname.replace(/\/+$/, '');
|
|
7
|
-
return base;
|
|
8
|
-
}
|
|
9
|
-
function append(base, path) {
|
|
10
|
-
return new URL(`${base.toString().replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`);
|
|
11
|
-
}
|
|
12
|
-
/** Accept either a public deployment base or its /api endpoint, without duplicating /api. */
|
|
13
|
-
export function businessEndpoint(apiUrl, path) {
|
|
14
|
-
const base = publicBase(apiUrl);
|
|
15
|
-
base.pathname = base.pathname.replace(/\/api$/, '');
|
|
16
|
-
return append(base, path);
|
|
17
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { mkdirSync, readdirSync, readFileSync, writeFileSync, renameSync } from 'node:fs';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
import { isAbsolute, join } from 'node:path';
|
|
5
|
-
import { isAgentToolRequestId } from '@playcraft/common/agent-tools';
|
|
6
|
-
/** Operations this process is sending now; never continued by another call of this process. */
|
|
7
|
-
const inFlight = new Set();
|
|
8
|
-
/** Linux start time of a process, so a reused pid is not taken for the process that held it. */
|
|
9
|
-
function startOf(pid) {
|
|
10
|
-
try {
|
|
11
|
-
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
12
|
-
return stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19] ?? null;
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function holderAlive(holder) {
|
|
19
|
-
if (!holder || holder.pid === process.pid)
|
|
20
|
-
return false;
|
|
21
|
-
try {
|
|
22
|
-
process.kill(holder.pid, 0);
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
if (error.code !== 'EPERM')
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return holder.start === null || startOf(holder.pid) === holder.start;
|
|
29
|
-
}
|
|
30
|
-
/** Persist an identity before sending. Store neither credentials nor request/response bodies. */
|
|
31
|
-
export function beginToolOperation(path, serializedBody, recoverId, options = {}) {
|
|
32
|
-
const directory = process.env.PLAYCRAFT_TOOL_REQUEST_DIR ?? join(homedir(), '.playcraft', 'tool-requests');
|
|
33
|
-
if (!isAbsolute(directory))
|
|
34
|
-
throw new Error('PLAYCRAFT_TOOL_REQUEST_DIR must be an absolute path');
|
|
35
|
-
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
36
|
-
const inputHash = createHash('sha256').update(serializedBody).digest('hex');
|
|
37
|
-
// Rerunning the same command while its outcome is unknown continues that operation: the server
|
|
38
|
-
// answers the same identity with its receipt instead of running it again.
|
|
39
|
-
const unconfirmed = recoverId === undefined && !options.newRequest
|
|
40
|
-
? findUnconfirmed(directory, path, inputHash)
|
|
41
|
-
: undefined;
|
|
42
|
-
const identifier = recoverId ?? unconfirmed?.requestId ?? randomUUID();
|
|
43
|
-
if (!isAgentToolRequestId(identifier))
|
|
44
|
-
throw new Error('Invalid PLAYCRAFT_TOOL_REQUEST_ID');
|
|
45
|
-
const requestId = identifier.toLowerCase();
|
|
46
|
-
const file = join(directory, `${requestId}.json`);
|
|
47
|
-
const now = new Date().toISOString();
|
|
48
|
-
const holder = { pid: process.pid, start: startOf(process.pid) };
|
|
49
|
-
const entry = {
|
|
50
|
-
version: 1,
|
|
51
|
-
requestId,
|
|
52
|
-
path,
|
|
53
|
-
inputHash,
|
|
54
|
-
state: 'unconfirmed',
|
|
55
|
-
holder,
|
|
56
|
-
createdAt: now,
|
|
57
|
-
updatedAt: now,
|
|
58
|
-
};
|
|
59
|
-
let createdNew = false;
|
|
60
|
-
try {
|
|
61
|
-
writeFileSync(file, JSON.stringify(entry), { flag: 'wx', mode: 0o600 });
|
|
62
|
-
createdNew = true;
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
if (error.code !== 'EEXIST')
|
|
66
|
-
throw error;
|
|
67
|
-
const previous = JSON.parse(readFileSync(file, 'utf8'));
|
|
68
|
-
if (previous.version !== 1 ||
|
|
69
|
-
previous.requestId !== requestId ||
|
|
70
|
-
previous.path !== path ||
|
|
71
|
-
previous.inputHash !== inputHash)
|
|
72
|
-
throw new Error(`Tool request ${requestId} conflicts with its durable local record`);
|
|
73
|
-
}
|
|
74
|
-
const update = (change) => {
|
|
75
|
-
const current = JSON.parse(readFileSync(file, 'utf8'));
|
|
76
|
-
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
77
|
-
writeFileSync(temporary, JSON.stringify({ ...current, ...change, updatedAt: new Date().toISOString() }), { flag: 'wx', mode: 0o600 });
|
|
78
|
-
renameSync(temporary, file);
|
|
79
|
-
};
|
|
80
|
-
// Only the sender holds an operation; a concurrent run of the same command gets its own.
|
|
81
|
-
inFlight.add(requestId);
|
|
82
|
-
if (unconfirmed || recoverId !== undefined)
|
|
83
|
-
update({ holder });
|
|
84
|
-
return {
|
|
85
|
-
requestId,
|
|
86
|
-
/** This call created the identity; a refusal cannot settle an older unknown operation. */
|
|
87
|
-
createdNew,
|
|
88
|
-
/** An explicit recovery, or a server that did not acknowledge the identity, reads only. */
|
|
89
|
-
settledOnly: recoverId !== undefined || unconfirmed?.receiptOnly === true,
|
|
90
|
-
file,
|
|
91
|
-
complete: () => update({ state: 'completed' }),
|
|
92
|
-
/** A definite refusal: the request was not carried out, so a rerun is a new operation. */
|
|
93
|
-
reject: () => update({ state: 'rejected' }),
|
|
94
|
-
/** The outcome stays unknown and a rerun may only read the receipt. */
|
|
95
|
-
requireReceipt: () => update({ receiptOnly: true }),
|
|
96
|
-
/** This call is done with the operation; a later run of the command may continue it. */
|
|
97
|
-
release: () => inFlight.delete(requestId),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function findUnconfirmed(directory, path, inputHash) {
|
|
101
|
-
let latest;
|
|
102
|
-
for (const name of readdirSync(directory)) {
|
|
103
|
-
if (!name.endsWith('.json'))
|
|
104
|
-
continue;
|
|
105
|
-
try {
|
|
106
|
-
const entry = JSON.parse(readFileSync(join(directory, name), 'utf8'));
|
|
107
|
-
if (entry.version === 1 &&
|
|
108
|
-
entry.state === 'unconfirmed' &&
|
|
109
|
-
entry.path === path &&
|
|
110
|
-
entry.inputHash === inputHash &&
|
|
111
|
-
isAgentToolRequestId(entry.requestId) &&
|
|
112
|
-
(!latest || entry.updatedAt > latest.updatedAt) &&
|
|
113
|
-
// Still being sent, here or by another live process: that run is not interrupted.
|
|
114
|
-
// Checked last, so only this command's candidates cost a process probe.
|
|
115
|
-
!inFlight.has(entry.requestId) &&
|
|
116
|
-
!holderAlive(entry.holder))
|
|
117
|
-
latest = entry;
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
// A torn or foreign file is not an operation of this command.
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return latest;
|
|
124
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { constants } from 'node:fs';
|
|
2
|
-
import { lstat, mkdir, open, realpath } from 'node:fs/promises';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
const ENTRY = '/.playcraft/video-replication/';
|
|
5
|
-
/** Keep local analysis evidence out of a repository without changing its tracked ignore rules. */
|
|
6
|
-
export async function ensureVideoEvidenceGitExcluded(directory) {
|
|
7
|
-
let root = await realpath(directory);
|
|
8
|
-
while (true) {
|
|
9
|
-
const marker = await lstat(join(root, '.git')).catch((error) => {
|
|
10
|
-
if (error.code === 'ENOENT')
|
|
11
|
-
return undefined;
|
|
12
|
-
throw error;
|
|
13
|
-
});
|
|
14
|
-
if (marker) {
|
|
15
|
-
// Cloud workspaces own a real .git directory; never follow a redirected Git metadata tree.
|
|
16
|
-
if (!marker.isDirectory() || marker.isSymbolicLink())
|
|
17
|
-
return false;
|
|
18
|
-
try {
|
|
19
|
-
await appendExclude(root);
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
if (['EACCES', 'EPERM', 'EROFS'].includes(error.code ?? ''))
|
|
24
|
-
return false;
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const parent = dirname(root);
|
|
29
|
-
if (parent === root)
|
|
30
|
-
return true;
|
|
31
|
-
root = parent;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
async function appendExclude(root) {
|
|
35
|
-
const flags = constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW;
|
|
36
|
-
const handles = [];
|
|
37
|
-
let file;
|
|
38
|
-
try {
|
|
39
|
-
const directory = await open(root, flags);
|
|
40
|
-
handles.push(directory);
|
|
41
|
-
const pinned = (handle, fallback) => process.platform === 'linux' ? `/proc/self/fd/${handle.fd}` : fallback;
|
|
42
|
-
const git = await open(join(pinned(directory, root), '.git'), flags);
|
|
43
|
-
handles.push(git);
|
|
44
|
-
const gitPath = pinned(git, join(root, '.git'));
|
|
45
|
-
await mkdir(join(gitPath, 'info')).catch((error) => {
|
|
46
|
-
if (error.code !== 'EEXIST')
|
|
47
|
-
throw error;
|
|
48
|
-
});
|
|
49
|
-
const info = await open(join(gitPath, 'info'), flags);
|
|
50
|
-
handles.push(info);
|
|
51
|
-
const exclude = join(pinned(info, join(root, '.git/info')), 'exclude');
|
|
52
|
-
const readable = await open(exclude, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK)
|
|
53
|
-
.catch((error) => { if (error.code === 'ENOENT')
|
|
54
|
-
return undefined; throw error; });
|
|
55
|
-
if (readable) {
|
|
56
|
-
try {
|
|
57
|
-
const stat = await readable.stat();
|
|
58
|
-
if (!stat.isFile() || stat.nlink !== 1 || stat.size > 1024 * 1024)
|
|
59
|
-
throw new Error('invalid_git_exclude');
|
|
60
|
-
if ((await readable.readFile('utf8')).split('\n').some(line => line.trim() === ENTRY))
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
await readable.close();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
file = await open(exclude, constants.O_RDWR | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW | constants.O_NONBLOCK, 0o666);
|
|
68
|
-
const stat = await file.stat();
|
|
69
|
-
if (!stat.isFile() || stat.nlink !== 1 || stat.size > 1024 * 1024)
|
|
70
|
-
throw new Error('invalid_git_exclude');
|
|
71
|
-
const current = await file.readFile('utf8');
|
|
72
|
-
if (!current.split('\n').some(line => line.trim() === ENTRY)) {
|
|
73
|
-
await file.writeFile(`${current && !current.endsWith('\n') ? '\n' : ''}${ENTRY}\n`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
await file?.close();
|
|
78
|
-
for (const handle of handles.reverse())
|
|
79
|
-
await handle.close();
|
|
80
|
-
}
|
|
81
|
-
}
|