@playcraft/cli 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -3
- package/dist/agent/local-backend.js +1 -1
- package/dist/auth/account-activation.js +157 -0
- package/dist/auth/messages.js +30 -0
- package/dist/cli-root-help.js +2 -0
- package/dist/commands/build.js +9 -4
- package/dist/commands/create.js +26 -33
- package/dist/commands/image.js +2 -6
- package/dist/commands/login.js +84 -42
- package/dist/commands/platform-skills.generated.js +19 -0
- package/dist/commands/playable.js +53 -0
- package/dist/commands/skills.js +2 -0
- package/dist/commands/tools-3d.js +11 -0
- package/dist/commands/tools-batch.js +87 -0
- package/dist/commands/tools-generation.js +68 -109
- package/dist/commands/tools.js +2 -2
- package/dist/commands/video.js +111 -0
- package/dist/commands/workspace-runtime.js +54 -0
- package/dist/config.js +59 -4
- package/dist/index.js +34 -3
- package/dist/project-skills/builtin-import.js +225 -0
- package/dist/project-skills/commands.js +77 -0
- package/dist/project-skills/lifecycle.js +28 -0
- package/dist/project-skills/local-run.js +112 -0
- package/dist/project-skills/local-store.js +221 -0
- package/dist/project-skills/messages.js +80 -0
- package/dist/project-skills/reconcile.js +62 -0
- package/dist/project-skills/remote-cache.js +51 -0
- package/dist/project-skills/validation.js +19 -0
- package/dist/recording/messages.js +40 -0
- package/dist/recording/project-digest.js +85 -0
- package/dist/recording/recorder.js +293 -0
- package/dist/recording/scenario.js +50 -0
- package/dist/remix/clone.js +2 -0
- package/dist/remix/init-template.js +2 -0
- package/dist/remix/pull.js +2 -0
- package/dist/remix/push.js +21 -1
- package/dist/utils/agent-api-client.js +185 -30
- package/dist/utils/environment-endpoints.js +17 -0
- package/dist/utils/playcraft-http-client.js +6 -4
- package/dist/utils/tool-operation-journal.js +124 -0
- package/dist/utils/video-evidence-git.js +81 -0
- package/dist/video-replication/client.js +222 -0
- package/dist/video-replication/comparison-evidence.js +149 -0
- package/dist/video-replication/comparison-files.js +57 -0
- package/dist/video-replication/comparison-log.js +72 -0
- package/dist/video-replication/comparison-messages.js +104 -0
- package/dist/video-replication/comparison-output.js +63 -0
- package/dist/video-replication/comparison-preflight.js +66 -0
- package/dist/video-replication/comparison.js +216 -0
- package/dist/video-replication/evidence.js +165 -0
- package/dist/video-replication/media.js +111 -0
- package/dist/video-replication/messages.js +89 -0
- package/dist/workspace-runtime/codex/app-server.js +965 -0
- package/dist/workspace-runtime/codex/compact.js +46 -0
- package/dist/workspace-runtime/codex/config-toml.js +107 -0
- package/dist/workspace-runtime/codex/jsonrpc-stdio.js +145 -0
- package/dist/workspace-runtime/codex/launcher-client.js +177 -0
- package/dist/workspace-runtime/codex/loopback.js +146 -0
- package/dist/workspace-runtime/codex/mcp-config.js +39 -0
- package/dist/workspace-runtime/codex/model-broker.js +263 -0
- package/dist/workspace-runtime/codex/native-adapter.js +9 -0
- package/dist/workspace-runtime/codex/permissions.js +70 -0
- package/dist/workspace-runtime/codex/work-mode.js +15 -0
- package/dist/workspace-runtime/main.js +10 -0
- package/dist/workspace-runtime/persistence/journal.js +355 -0
- package/dist/workspace-runtime/persistence/native-subagents.js +162 -0
- package/dist/workspace-runtime/persistence/sqlite-client.js +77 -0
- package/dist/workspace-runtime/persistence/sqlite-worker.js +1096 -0
- package/dist/workspace-runtime/previews/publish.js +259 -0
- package/dist/workspace-runtime/previews/single-file.js +43 -0
- package/dist/workspace-runtime/processes/managed-writes.js +69 -0
- package/dist/workspace-runtime/production/contracts.js +17 -0
- package/dist/workspace-runtime/production/controller.js +207 -0
- package/dist/workspace-runtime/production/dependencies.js +60 -0
- package/dist/workspace-runtime/production/native.js +203 -0
- package/dist/workspace-runtime/production/processes.js +86 -0
- package/dist/workspace-runtime/production/save-command.js +35 -0
- package/dist/workspace-runtime/production/source-copy.js +91 -0
- package/dist/workspace-runtime/production/stages.js +205 -0
- package/dist/workspace-runtime/production/storage.js +32 -0
- package/dist/workspace-runtime/serve.js +207 -0
- package/dist/workspace-runtime/server/auth.js +21 -0
- package/dist/workspace-runtime/server/connectivity.js +201 -0
- package/dist/workspace-runtime/server/desktop-host.js +429 -0
- package/dist/workspace-runtime/server/desktop-preview-config.js +81 -0
- package/dist/workspace-runtime/server/desktop-preview-service.js +157 -0
- package/dist/workspace-runtime/server/desktop-preview-static.js +53 -0
- package/dist/workspace-runtime/server/desktop-preview.js +189 -0
- package/dist/workspace-runtime/server/dispatch.js +1116 -0
- package/dist/workspace-runtime/server/endpoints.js +19 -0
- package/dist/workspace-runtime/server/execution-group.js +85 -0
- package/dist/workspace-runtime/server/http.js +1038 -0
- package/dist/workspace-runtime/server/lock.js +53 -0
- package/dist/workspace-runtime/server/rfb-watch-gate.js +168 -0
- package/dist/workspace-runtime/server/terminal-host.js +366 -0
- package/dist/workspace-runtime/server/types.js +1 -0
- package/dist/workspace-runtime/workspaces/artifact-events.js +55 -0
- package/dist/workspace-runtime/workspaces/artifact-files.js +195 -0
- package/dist/workspace-runtime/workspaces/artifact-receipts.js +89 -0
- package/dist/workspace-runtime/workspaces/artifacts.js +260 -0
- package/dist/workspace-runtime/workspaces/attachment-content.js +111 -0
- package/dist/workspace-runtime/workspaces/attachments.js +175 -0
- package/dist/workspace-runtime/workspaces/batch-commit.js +142 -0
- package/dist/workspace-runtime/workspaces/cli-context.js +23 -0
- package/dist/workspace-runtime/workspaces/cli-credentials.js +111 -0
- package/dist/workspace-runtime/workspaces/composer-context.js +125 -0
- package/dist/workspace-runtime/workspaces/context-error.js +2 -0
- package/dist/workspace-runtime/workspaces/dependencies.js +264 -0
- package/dist/workspace-runtime/workspaces/developer-command.js +64 -0
- package/dist/workspace-runtime/workspaces/directories.js +116 -0
- package/dist/workspace-runtime/workspaces/directory-access.js +37 -0
- package/dist/workspace-runtime/workspaces/directory-maintenance.js +111 -0
- package/dist/workspace-runtime/workspaces/directory-stats.js +49 -0
- package/dist/workspace-runtime/workspaces/disk-snapshot.js +31 -0
- package/dist/workspace-runtime/workspaces/empty-template.js +40 -0
- package/dist/workspace-runtime/workspaces/files-search.js +116 -0
- package/dist/workspace-runtime/workspaces/files.js +120 -0
- package/dist/workspace-runtime/workspaces/git-credential-broker.js +312 -0
- package/dist/workspace-runtime/workspaces/git-credential-helper.js +68 -0
- package/dist/workspace-runtime/workspaces/git-direct-store.js +155 -0
- package/dist/workspace-runtime/workspaces/git.js +517 -0
- package/dist/workspace-runtime/workspaces/json5-edit.js +170 -0
- package/dist/workspace-runtime/workspaces/parameters.js +272 -0
- package/dist/workspace-runtime/workspaces/prepare.js +264 -0
- package/dist/workspace-runtime/workspaces/registry.js +234 -0
- package/dist/workspace-runtime/workspaces/revisions.js +31 -0
- package/dist/workspace-runtime/workspaces/skill-artifact-loader.js +91 -0
- package/dist/workspace-runtime/workspaces/skills.js +189 -0
- package/dist/workspace-runtime/workspaces/video-attachments.js +49 -0
- package/package.json +14 -5
- package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +23 -81
- package/project-template/.claude/skills/playcraft-replica-validation/SKILL.md +25 -0
- package/project-template/.claude/skills/playcraft-replica-validation/references/contracts.md +79 -0
- package/project-template/.claude/skills/playcraft-video-understanding/SKILL.md +29 -0
- package/project-template/.claude/skills/playcraft-video-understanding/references/contracts.md +37 -0
- package/project-template-v2/.claude/agents/artist.md +82 -0
- package/project-template-v2/.claude/agents/developer.md +153 -0
- package/project-template-v2/.claude/agents/game-designer.md +264 -0
- package/project-template-v2/.claude/agents/refs/artist-art-style-catalog.md +533 -0
- package/project-template-v2/.claude/agents/refs/artist-color-audio-recipes.md +153 -0
- package/project-template-v2/.claude/agents/refs/artist-dimension-axis.md +27 -0
- package/project-template-v2/.claude/agents/refs/artist-master-composite-recipes.md +208 -0
- package/project-template-v2/.claude/agents/refs/atom-skill-library.md +81 -0
- package/project-template-v2/.claude/agents/refs/developer-impl-cookbook.md +432 -0
- package/project-template-v2/.claude/agents/refs/framework-5-component-filter.md +252 -0
- package/project-template-v2/.claude/agents/refs/framework-game-feel-juice.md +266 -0
- package/project-template-v2/.claude/agents/refs/framework-mda.md +147 -0
- package/project-template-v2/.claude/agents/refs/game-designer-gameplay-sufficiency.md +123 -0
- package/project-template-v2/.claude/agents/refs/ta-3d-flip-recipe.md +88 -0
- package/project-template-v2/.claude/agents/refs/ta-atlas-deliverable-standard.md +67 -0
- package/project-template-v2/.claude/agents/refs/ta-batch-pipeline-recipes.md +120 -0
- package/project-template-v2/.claude/agents/refs/ta-image-generation-detail.md +300 -0
- package/project-template-v2/.claude/agents/refs/ta-image-ops-reference.md +495 -0
- package/project-template-v2/.claude/agents/refs/ta-pipeline-cookbook.md +1141 -0
- package/project-template-v2/.claude/agents/refs/ta-tools-reference.md +111 -0
- package/project-template-v2/.claude/agents/refs/ta-vfx-preset-catalog.md +365 -0
- package/project-template-v2/.claude/agents/refs/threejs-cannon-pitfalls.md +412 -0
- package/project-template-v2/.claude/agents/reviewer.md +75 -0
- package/project-template-v2/.claude/agents/technical-artist.md +86 -0
- package/project-template-v2/.claude/hooks/snapshot-milestone.mjs +243 -0
- package/project-template-v2/.claude/hooks/user-prompt.mjs +133 -0
- package/project-template-v2/.claude/settings.json +33 -0
- package/project-template-v2/.claude/skills/brainstorming/SKILL.md +161 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/frame-template.html +270 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/helper.js +177 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/server.cjs +354 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/start-server.sh +148 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/stop-server.sh +56 -0
- package/project-template-v2/.claude/skills/brainstorming/scripts/wait-for-selection.sh +62 -0
- package/project-template-v2/.claude/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/project-template-v2/.claude/skills/brainstorming/visual-companion.md +309 -0
- package/project-template-v2/.claude/skills/playcraft-ad-psychology/SKILL.md +182 -0
- package/project-template-v2/.claude/skills/playcraft-art-style-guide/SKILL.md +123 -0
- package/project-template-v2/.claude/skills/playcraft-asset-state-sheet/SKILL.md +205 -0
- package/project-template-v2/.claude/skills/playcraft-audio-generation/SKILL.md +280 -0
- package/project-template-v2/.claude/skills/playcraft-batch-pipeline/SKILL.md +184 -0
- package/project-template-v2/.claude/skills/playcraft-build-optimizer/SKILL.md +306 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/SKILL.md +298 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +123 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +254 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +324 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +97 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +118 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +137 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +397 -0
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +296 -0
- package/project-template-v2/.claude/skills/playcraft-image-ops/SKILL.md +122 -0
- package/project-template-v2/.claude/skills/playcraft-image-processing/SKILL.md +219 -0
- package/project-template-v2/.claude/skills/playcraft-masking/SKILL.md +373 -0
- package/project-template-v2/.claude/skills/playcraft-playable-optimization/SKILL.md +161 -0
- package/project-template-v2/.claude/skills/playcraft-research/SKILL.md +215 -0
- package/project-template-v2/.claude/skills/playcraft-skill-recommender/SKILL.md +382 -0
- package/project-template-v2/.claude/skills/playcraft-sprite-generation/SKILL.md +423 -0
- package/project-template-v2/.claude/skills/playcraft-sprite-remix/SKILL.md +158 -0
- package/project-template-v2/.claude/skills/playcraft-sprite-sheet/SKILL.md +100 -0
- package/project-template-v2/.claude/skills/playcraft-storyboard/SKILL.md +167 -0
- package/project-template-v2/.claude/skills/playcraft-style-qa/SKILL.md +270 -0
- package/project-template-v2/.claude/skills/playcraft-text-rendering/SKILL.md +236 -0
- package/project-template-v2/.claude/skills/playcraft-vfx-animation/SKILL.md +130 -0
- package/project-template-v2/.claude/skills/playwright-cli/SKILL.md +390 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/element-attributes.md +23 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/request-mocking.md +87 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/running-code.md +240 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/session-management.md +226 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/spec-driven-testing.md +308 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/storage-state.md +275 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/test-generation.md +134 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/tracing.md +142 -0
- package/project-template-v2/.claude/skills/playwright-cli/references/video-recording.md +153 -0
- package/project-template-v2/.claude/skills/session-analyzer/SKILL.md +386 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/execution-breakdown.mjs +182 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/find-turns.mjs +72 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/heavy-output.mjs +121 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/resolve-session.mjs +102 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-stats.mjs +127 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-tool-timeline.mjs +106 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/time-gaps.mjs +128 -0
- package/project-template-v2/.claude/skills/session-analyzer/scripts/turn-timeline.mjs +67 -0
- package/project-template-v2/.claude/snapshot.mjs +263 -0
- package/project-template-v2/.playcraft/skills.lock.json +152 -0
- package/project-template-v2/CLAUDE.md +146 -0
- package/project-template-v2/assets/audio/bgm/.gitkeep +0 -0
- package/project-template-v2/assets/audio/sfx/.gitkeep +0 -0
- package/project-template-v2/assets/bundles/.gitkeep +0 -0
- package/project-template-v2/assets/images/bg/.gitkeep +0 -0
- package/project-template-v2/assets/images/reference/.gitkeep +0 -0
- package/project-template-v2/assets/images/storyboard/.gitkeep +0 -0
- package/project-template-v2/assets/images/tiles/.gitkeep +0 -0
- package/project-template-v2/assets/images/ui/.gitkeep +0 -0
- package/project-template-v2/assets/images/vfx/.gitkeep +0 -0
- package/project-template-v2/assets/models/.gitkeep +0 -0
- package/project-template-v2/docs/harness/iteration-1/context-flow.md +254 -0
- package/project-template-v2/docs/harness/iteration-1/generate-flow.md +91 -0
- package/project-template-v2/docs/harness/iteration-1/ideate-flow.md +214 -0
- package/project-template-v2/docs/harness/iteration-1/optimize-flow.md +75 -0
- package/project-template-v2/docs/harness/iteration-1/wrapup-flow.md +63 -0
- package/project-template-v2/docs/harness/iteration-2/context-flow.md +223 -0
- package/project-template-v2/docs/harness/iteration-2/generate-flow.md +129 -0
- package/project-template-v2/docs/harness/iteration-2/ideate-flow.md +267 -0
- package/project-template-v2/docs/harness/iteration-2/optimize-flow.md +164 -0
- package/project-template-v2/docs/harness/iteration-2/wrapup-flow.md +115 -0
- package/project-template-v2/docs/harness/orchestrator-flow.md +364 -0
- package/project-template-v2/docs/project-state.json +60 -0
- package/project-template-v2/docs/project-state.md +72 -0
- package/project-template-v2/docs/standards/README.md +225 -0
- package/project-template-v2/docs/standards/agent-behavior-standards.md +174 -0
- package/project-template-v2/docs/standards/artifacts/design-brief.md +19 -0
- package/project-template-v2/docs/standards/artifacts/design.md +22 -0
- package/project-template-v2/docs/standards/artifacts/game-code.md +41 -0
- package/project-template-v2/docs/standards/artifacts/todo-list.md +41 -0
- package/project-template-v2/docs/standards/iter1-agent-behavior-standards.md +343 -0
- package/project-template-v2/game/index.ts +18 -0
- package/project-template-v2/globals.d.ts +51 -0
- package/project-template-v2/index.css +34 -0
- package/project-template-v2/index.html +18 -0
- package/project-template-v2/main.ts +9 -0
- package/project-template-v2/package.json +46 -0
- package/project-template-v2/skills/_shared/scripts/dispatch-clear.mjs +31 -0
- package/project-template-v2/skills/_shared/scripts/dispatch-set.mjs +86 -0
- package/project-template-v2/skills/_shared/scripts/dod-check.mjs +153 -0
- package/project-template-v2/skills/_shared/scripts/handoff-append.mjs +70 -0
- package/project-template-v2/skills/_shared/scripts/lib/validator-artifacts.mjs +91 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/dod-config.mjs +131 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/index.mjs +80 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-1-core.mjs +90 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-2-wrap.mjs +93 -0
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-3-visual.mjs +23 -0
- package/project-template-v2/skills/_shared/scripts/render-project-state.mjs +230 -0
- package/project-template-v2/skills/_shared/scripts/state-advance-stage.mjs +58 -0
- package/project-template-v2/skills/_shared/scripts/state-get.mjs +339 -0
- package/project-template-v2/skills/_shared/scripts/state-handoff.mjs +39 -0
- package/project-template-v2/skills/_shared/scripts/state-set.mjs +94 -0
- package/project-template-v2/skills/_shared/scripts/state-store.mjs +783 -0
- package/project-template-v2/skills/_shared/scripts/todo-add.mjs +88 -0
- package/project-template-v2/skills/_shared/scripts/todo-get.mjs +130 -0
- package/project-template-v2/skills/_shared/scripts/todo-remove.mjs +33 -0
- package/project-template-v2/skills/_shared/scripts/todo-set.mjs +47 -0
- package/project-template-v2/skills/_shared/scripts/verify-asset-code-sync.mjs +268 -0
- package/project-template-v2/skills/_shared/scripts/verify-env.mjs +285 -0
- package/project-template-v2/skills/_shared/scripts/verify-placeholders.mjs +161 -0
- package/project-template-v2/skills/playable-autoplay/SKILL.md +176 -0
- package/project-template-v2/skills/playable-autoplay/agents/openai.yaml +4 -0
- package/project-template-v2/skills/playable-debug/SKILL.md +116 -0
- package/project-template-v2/skills/playable-debug/agents/openai.yaml +4 -0
- package/project-template-v2/skills/playable-debug/references/debug-config.md +40 -0
- package/project-template-v2/skills/playable-record/SKILL.md +140 -0
- package/project-template-v2/skills/playable-record/scripts/lib/dev-server.mjs +104 -0
- package/project-template-v2/skills/playable-record/scripts/lib/record-audio-bridge.js +141 -0
- package/project-template-v2/skills/playable-record/scripts/record-playable.mjs +425 -0
- package/project-template-v2/skills/playable-record/scripts/verify-contract.mjs +261 -0
- package/project-template-v2/skills/playable-record/scripts/verify-firstwin.mjs +398 -0
- package/project-template-v2/skills/playable-record/scripts/verify-fusion.mjs +322 -0
- package/project-template-v2/skills/playable-record/scripts/verify-lifecycle.mjs +105 -0
- package/project-template-v2/skills/playable-record/scripts/verify-vlm-video.mjs +230 -0
- package/project-template-v2/skills/playable-validate/SKILL.md +61 -0
- package/project-template-v2/skills/playable-validate/validation-rules.md +14 -0
- package/project-template-v2/skills/playable-verify-ui/SKILL.md +63 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/__init__.py +1 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/config_expr.js +218 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/node_utils.js +51 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/profile_loader.py +59 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/report.py +106 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/runtime_contract.js +116 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_fetch_antipatterns.py +59 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_hardcoded_layout.js +64 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_runtime_contract.js +58 -0
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_text_overlap.py +333 -0
- package/project-template-v2/ta-workspace/scripts/.gitkeep +0 -0
- package/project-template-v2/tsconfig.json +20 -0
- package/project-template-v2/vite.config.ts +27 -0
- package/project-templates/batch-locks/phaser.yaml +922 -0
- package/project-templates/batch-locks/threejs.yaml +978 -0
- package/project-templates/empty/AGENTS.md +25 -0
- package/project-templates/empty/gitignore +33 -0
- package/project-templates/phaser/.claude/skills/playcraft-image-generation/SKILL.md +23 -81
- package/project-templates/threejs/.claude/skills/playcraft-image-generation/SKILL.md +23 -81
- package/dist/commands/tools-image-context.js +0 -23
- package/dist/utils/image-asset-context.js +0 -105
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
4
|
import { loadGlobalConfig } from '../config.js';
|
|
5
5
|
import { DEFAULT_PLAYCRAFT_CLOUD_BASE } from '../commands/login.js';
|
|
6
|
+
import { AGENT_TOOL_OPERATION_PROTOCOL, AGENT_TOOL_OPERATION_HEADERS, AGENT_TOOL_OPERATION_CAPABILITIES_PATH, } from '@playcraft/common/agent-tools';
|
|
7
|
+
import { beginToolOperation } from './tool-operation-journal.js';
|
|
8
|
+
import { businessEndpoint } from './environment-endpoints.js';
|
|
9
|
+
import { AccountActivationError, parseErrorPayload, pendingAccountActivationError, } from '../auth/account-activation.js';
|
|
6
10
|
/**
|
|
7
11
|
* 判断 token 是否为用户 PAT(Personal Access Token)。
|
|
8
12
|
* PAT 以 "playcraft_pat_" 开头;沙箱 JWT 为三段式 base64。
|
|
@@ -15,8 +19,8 @@ function isPatToken(token) {
|
|
|
15
19
|
* or from the CLI after `playcraft login`.
|
|
16
20
|
*
|
|
17
21
|
* 凭证解析优先级:
|
|
18
|
-
* API URL : PLAYCRAFT_API_URL → .playcraft.json → ~/.playcraft/config.json → DEFAULT_PLAYCRAFT_CLOUD_BASE
|
|
19
|
-
* Token : PLAYCRAFT_SANDBOX_TOKEN → .playcraft.json
|
|
22
|
+
* API URL : PLAYCRAFT_API_URL → sandbox global .playcraft.json → project .playcraft.json → ~/.playcraft/config.json → DEFAULT_PLAYCRAFT_CLOUD_BASE
|
|
23
|
+
* Token : PLAYCRAFT_SANDBOX_TOKEN → sandbox global .playcraft.json → project .playcraft.json → ~/.playcraft/config.json token (PAT)
|
|
20
24
|
*
|
|
21
25
|
* 鉴权 header 自动选择:
|
|
22
26
|
* - 沙箱 JWT (非 PAT) → X-Sandbox-Token: <token>(后端 @SandboxToken 路由的沙箱分支)
|
|
@@ -25,7 +29,7 @@ function isPatToken(token) {
|
|
|
25
29
|
export class AgentApiClient {
|
|
26
30
|
apiUrl;
|
|
27
31
|
token;
|
|
28
|
-
|
|
32
|
+
credentialFile;
|
|
29
33
|
playcraftEnv;
|
|
30
34
|
constructor() {
|
|
31
35
|
const localConfig = AgentApiClient.loadLocalConfig();
|
|
@@ -36,7 +40,7 @@ export class AgentApiClient {
|
|
|
36
40
|
globalConfig.backendUrl ||
|
|
37
41
|
globalConfig.url ||
|
|
38
42
|
DEFAULT_PLAYCRAFT_CLOUD_BASE).replace(/\/+$/, '');
|
|
39
|
-
// Token:
|
|
43
|
+
// Token: 环境变量 → 沙箱全局配置 → 项目配置 → 用户登录配置
|
|
40
44
|
const token = process.env.PLAYCRAFT_SANDBOX_TOKEN ||
|
|
41
45
|
localConfig.token ||
|
|
42
46
|
globalConfig.token ||
|
|
@@ -47,43 +51,147 @@ export class AgentApiClient {
|
|
|
47
51
|
}
|
|
48
52
|
this.apiUrl = apiUrl;
|
|
49
53
|
this.token = token;
|
|
50
|
-
this.
|
|
51
|
-
this.playcraftEnv = (process.env.PLAYCRAFT_ENV ||
|
|
52
|
-
localConfig.env ||
|
|
53
|
-
'').trim();
|
|
54
|
+
this.credentialFile = localConfig.credentialFile;
|
|
55
|
+
this.playcraftEnv = (process.env.PLAYCRAFT_ENV || localConfig.env || '').trim();
|
|
54
56
|
}
|
|
55
57
|
/** 根据 token 类型构造鉴权 headers */
|
|
56
58
|
authHeaders() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
let token = this.token;
|
|
60
|
+
// Polling commands can outlive a credential: read the atomically refreshed file per request.
|
|
61
|
+
if (this.credentialFile && !process.env.PLAYCRAFT_SANDBOX_TOKEN) {
|
|
62
|
+
try {
|
|
63
|
+
token = JSON.parse(readFileSync(this.credentialFile, 'utf8')).token || token;
|
|
64
|
+
}
|
|
65
|
+
catch { /* Keep the last credential if a local file is temporarily unavailable. */ }
|
|
66
|
+
}
|
|
67
|
+
const headers = isPatToken(token)
|
|
68
|
+
? { Authorization: `Bearer ${token}` }
|
|
69
|
+
: { 'X-Sandbox-Token': token };
|
|
60
70
|
if (this.playcraftEnv) {
|
|
61
71
|
headers['playcraft-env'] = this.playcraftEnv;
|
|
62
72
|
}
|
|
63
73
|
return headers;
|
|
64
74
|
}
|
|
65
|
-
/**
|
|
75
|
+
/** Deployment-relative pathname under /api/agent/tools (path may omit leading slash). */
|
|
66
76
|
toolsRequestUrl(path) {
|
|
67
77
|
const p = path.startsWith('/') ? path : `/${path}`;
|
|
68
|
-
return
|
|
78
|
+
return businessEndpoint(this.apiUrl, `/api/agent/tools${p}`);
|
|
69
79
|
}
|
|
70
|
-
async post(path, body) {
|
|
71
|
-
const url = this.toolsRequestUrl(path)
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
body: JSON.stringify(body),
|
|
80
|
+
async post(path, body, options) {
|
|
81
|
+
const url = this.toolsRequestUrl(path);
|
|
82
|
+
const serializedBody = JSON.stringify(body);
|
|
83
|
+
if (serializedBody === undefined)
|
|
84
|
+
throw new Error('Tool request body is required');
|
|
85
|
+
const recoverId = options?.requestId ?? process.env.PLAYCRAFT_TOOL_REQUEST_ID;
|
|
86
|
+
const operation = beginToolOperation(url.pathname, serializedBody, recoverId, {
|
|
87
|
+
newRequest: options?.newRequest ?? process.env.PLAYCRAFT_TOOL_NEW_REQUEST === '1',
|
|
79
88
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
const unknownOutcome = `Tool request ${operation.requestId}: the outcome is unknown. Rerun the same command to ` +
|
|
90
|
+
`continue this request: it returns the result if the request finished, or finishes it if ` +
|
|
91
|
+
`the tool can be safely redone; it never starts a second operation. Record: ${operation.file}.`;
|
|
92
|
+
try {
|
|
93
|
+
try {
|
|
94
|
+
await options?.onPrepared?.({ requestId: operation.requestId, file: operation.file });
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
operation.reject();
|
|
98
|
+
throw new ToolRequestError('Tool request preparation failed; no operation was sent');
|
|
99
|
+
}
|
|
100
|
+
const capabilityResponse = await fetch(this.toolsRequestUrl(AGENT_TOOL_OPERATION_CAPABILITIES_PATH), {
|
|
101
|
+
headers: this.authHeaders(),
|
|
102
|
+
redirect: 'error',
|
|
103
|
+
signal: options?.signal
|
|
104
|
+
? AbortSignal.any([options.signal, AbortSignal.timeout(30_000)])
|
|
105
|
+
: AbortSignal.timeout(30_000),
|
|
106
|
+
});
|
|
107
|
+
if (!capabilityResponse.ok) {
|
|
108
|
+
if (capabilityResponse.status === 403) {
|
|
109
|
+
const pending = pendingAccountActivationError(403, parseErrorPayload(await capabilityResponse.clone().text().catch(() => '')));
|
|
110
|
+
if (pending) {
|
|
111
|
+
if (operation.createdNew && !operation.settledOnly)
|
|
112
|
+
operation.reject();
|
|
113
|
+
throw pending;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
await capabilityResponse.body?.cancel();
|
|
117
|
+
throw new ToolRequestError(`Business tool protocol unavailable (${capabilityResponse.status}); no operation was sent`);
|
|
118
|
+
}
|
|
119
|
+
const capabilities = (await capabilityResponse.json());
|
|
120
|
+
if (capabilities.protocol !== AGENT_TOOL_OPERATION_PROTOCOL ||
|
|
121
|
+
capabilities.settledOnly !== true)
|
|
122
|
+
throw new ToolRequestError('Business tool protocol is incompatible; no operation was sent');
|
|
123
|
+
const res = await fetch(url, {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
redirect: 'error',
|
|
126
|
+
signal: options?.signal
|
|
127
|
+
? AbortSignal.any([options.signal, AbortSignal.timeout(30 * 60_000)])
|
|
128
|
+
: AbortSignal.timeout(30 * 60_000),
|
|
129
|
+
headers: {
|
|
130
|
+
'Content-Type': 'application/json',
|
|
131
|
+
...this.authHeaders(),
|
|
132
|
+
[AGENT_TOOL_OPERATION_HEADERS.protocol]: AGENT_TOOL_OPERATION_PROTOCOL,
|
|
133
|
+
[AGENT_TOOL_OPERATION_HEADERS.requestId]: operation.requestId,
|
|
134
|
+
...(operation.settledOnly ? { [AGENT_TOOL_OPERATION_HEADERS.settledOnly]: 'true' } : {}),
|
|
135
|
+
},
|
|
136
|
+
body: serializedBody,
|
|
137
|
+
});
|
|
138
|
+
if (res.headers.get(AGENT_TOOL_OPERATION_HEADERS.protocol) !== AGENT_TOOL_OPERATION_PROTOCOL ||
|
|
139
|
+
res.headers.get(AGENT_TOOL_OPERATION_HEADERS.requestId) !== operation.requestId) {
|
|
140
|
+
if (res.status === 403) {
|
|
141
|
+
const pending = pendingAccountActivationError(403, parseErrorPayload(await res.clone().text().catch(() => '')));
|
|
142
|
+
if (pending) {
|
|
143
|
+
if (operation.createdNew && !operation.settledOnly)
|
|
144
|
+
operation.reject();
|
|
145
|
+
throw pending;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
await res.body?.cancel();
|
|
149
|
+
// Possibly an instance that ignores identities: a rerun may only read the receipt.
|
|
150
|
+
operation.requireReceipt();
|
|
151
|
+
throw new Error('Business did not acknowledge a durable receipt; outcome remains unconfirmed');
|
|
152
|
+
}
|
|
153
|
+
if (!res.ok) {
|
|
154
|
+
const text = await res.text().catch(() => res.statusText);
|
|
155
|
+
const pending = pendingAccountActivationError(res.status, parseErrorPayload(text));
|
|
156
|
+
if (pending)
|
|
157
|
+
throw pending;
|
|
158
|
+
const code = errorCode(text);
|
|
159
|
+
if (res.status === 409 && code === 'business_operation_in_progress')
|
|
160
|
+
throw new ToolRequestError(`API 409: ${text}\nTool request ${operation.requestId} is still running. Rerun the ` +
|
|
161
|
+
'same command later to get its result.');
|
|
162
|
+
if (res.status === 409 && code === 'business_operation_requires_reconciliation')
|
|
163
|
+
throw new ToolRequestError(recoverId !== undefined
|
|
164
|
+
? // A receipt query never runs the request, even for a tool that can be safely redone.
|
|
165
|
+
`API 409: ${text}\nTool request ${operation.requestId} has no settled result yet. ` +
|
|
166
|
+
'Rerun the same command without PLAYCRAFT_TOOL_REQUEST_ID: a tool that can be ' +
|
|
167
|
+
'safely redone continues this request; any other tool then needs reconciliation.'
|
|
168
|
+
: `API 409: ${text}\nTool request ${operation.requestId} needs reconciliation: its ` +
|
|
169
|
+
'outcome is unknown, and rerunning the same command will not run it again. Only ' +
|
|
170
|
+
'after confirming it had no effect, rerun with PLAYCRAFT_TOOL_NEW_REQUEST=1 to ' +
|
|
171
|
+
'start a new operation.');
|
|
172
|
+
if (res.status >= 400 && res.status < 500) {
|
|
173
|
+
// The request itself was refused and not carried out: a rerun is a new operation.
|
|
174
|
+
operation.reject();
|
|
175
|
+
throw new ToolRequestError(`API ${res.status}: ${text}`);
|
|
176
|
+
}
|
|
177
|
+
throw new Error(`API ${res.status}: ${text}`);
|
|
178
|
+
}
|
|
179
|
+
const result = (await res.json());
|
|
180
|
+
operation.complete();
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (error instanceof ToolRequestError || error instanceof AccountActivationError)
|
|
185
|
+
throw error;
|
|
186
|
+
throw new Error(`${error instanceof Error ? error.message : String(error)}\n${operation.settledOnly
|
|
187
|
+
? `Tool request ${operation.requestId}; record: ${operation.file}. Its settled result is not available yet.`
|
|
188
|
+
: unknownOutcome}`);
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
operation.release();
|
|
83
192
|
}
|
|
84
|
-
return res.json();
|
|
85
193
|
}
|
|
86
|
-
async get(path, params) {
|
|
194
|
+
async get(path, params, options) {
|
|
87
195
|
const url = this.toolsRequestUrl(path);
|
|
88
196
|
if (params) {
|
|
89
197
|
for (const [k, v] of Object.entries(params)) {
|
|
@@ -93,27 +201,62 @@ export class AgentApiClient {
|
|
|
93
201
|
}
|
|
94
202
|
const res = await fetch(url, {
|
|
95
203
|
headers: this.authHeaders(),
|
|
204
|
+
redirect: 'error',
|
|
205
|
+
signal: options?.signal ?? AbortSignal.timeout(30_000),
|
|
96
206
|
});
|
|
97
207
|
if (!res.ok) {
|
|
98
208
|
const text = await res.text().catch(() => res.statusText);
|
|
209
|
+
const pending = pendingAccountActivationError(res.status, parseErrorPayload(text));
|
|
210
|
+
if (pending)
|
|
211
|
+
throw pending;
|
|
99
212
|
throw new Error(`API ${res.status}: ${text}`);
|
|
100
213
|
}
|
|
101
214
|
return res.json();
|
|
102
215
|
}
|
|
216
|
+
/** Stream only to the authenticated, same-service video upload endpoint. */
|
|
217
|
+
async putVideoMedia(path, body, headers, signal) {
|
|
218
|
+
if (!/^\/video-media\/[a-f0-9-]{36}\/content\?/.test(path))
|
|
219
|
+
throw new Error('invalid_video_upload_target');
|
|
220
|
+
const url = this.toolsRequestUrl(path);
|
|
221
|
+
const keys = [...url.searchParams.keys()].sort();
|
|
222
|
+
if (keys.join(',') !== 'expires,signature,workspaceId')
|
|
223
|
+
throw new Error('invalid_video_upload_target');
|
|
224
|
+
const allowed = new Set(['content-type', 'content-md5', 'content-length']);
|
|
225
|
+
if (Object.keys(headers).some(key => !allowed.has(key.toLowerCase())))
|
|
226
|
+
throw new Error('invalid_video_upload_headers');
|
|
227
|
+
const response = await fetch(url, {
|
|
228
|
+
method: 'PUT', redirect: 'error', signal,
|
|
229
|
+
headers: { ...headers, ...this.authHeaders() },
|
|
230
|
+
body: body,
|
|
231
|
+
duplex: 'half',
|
|
232
|
+
});
|
|
233
|
+
if (!response.ok) {
|
|
234
|
+
await response.body?.cancel();
|
|
235
|
+
throw new Error(`video_upload_failed:${response.status}`);
|
|
236
|
+
}
|
|
237
|
+
await response.body?.cancel();
|
|
238
|
+
}
|
|
103
239
|
/**
|
|
104
240
|
* 按顺序搜索本地 .playcraft.json 文件(沙箱内或项目目录)。
|
|
105
241
|
* 与全局 login 配置(~/.playcraft/config.json)不同,前者专用于沙箱 token。
|
|
106
242
|
*/
|
|
107
243
|
static loadLocalConfig() {
|
|
244
|
+
const ancestors = [];
|
|
245
|
+
for (let directory = process.cwd();; directory = dirname(directory)) {
|
|
246
|
+
ancestors.push(join(directory, '.playcraft.json'));
|
|
247
|
+
if (dirname(directory) === directory)
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
108
250
|
const searchPaths = [
|
|
109
|
-
|
|
251
|
+
process.env.PLAYCRAFT_SANDBOX_CONFIG_PATH || '/workspaces/.playcraft.json',
|
|
252
|
+
...ancestors,
|
|
110
253
|
'/project/.playcraft.json',
|
|
111
254
|
join(homedir(), '.playcraft.json'),
|
|
112
255
|
];
|
|
113
256
|
for (const p of searchPaths) {
|
|
114
257
|
if (existsSync(p)) {
|
|
115
258
|
try {
|
|
116
|
-
return JSON.parse(readFileSync(p, 'utf-8'));
|
|
259
|
+
return { ...JSON.parse(readFileSync(p, 'utf-8')), credentialFile: p };
|
|
117
260
|
}
|
|
118
261
|
catch {
|
|
119
262
|
continue;
|
|
@@ -123,3 +266,15 @@ export class AgentApiClient {
|
|
|
123
266
|
return { apiUrl: '', token: '' };
|
|
124
267
|
}
|
|
125
268
|
}
|
|
269
|
+
/** A failure whose meaning is settled; no recovery hint applies. */
|
|
270
|
+
class ToolRequestError extends Error {
|
|
271
|
+
}
|
|
272
|
+
function errorCode(text) {
|
|
273
|
+
try {
|
|
274
|
+
const message = JSON.parse(text).message;
|
|
275
|
+
return typeof message === 'string' ? message : undefined;
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { loadGlobalConfig } from '../config.js';
|
|
3
3
|
import { DEFAULT_PLAYCRAFT_CLOUD_BASE } from '../commands/login.js';
|
|
4
|
+
import { pendingAccountActivationError } from '../auth/account-activation.js';
|
|
4
5
|
export class PlayCraftApiError extends Error {
|
|
5
6
|
code;
|
|
6
7
|
status;
|
|
@@ -95,19 +96,20 @@ export class PlayCraftHttpClient {
|
|
|
95
96
|
}
|
|
96
97
|
if (!response.ok) {
|
|
97
98
|
const error = payload?.error;
|
|
98
|
-
const
|
|
99
|
-
const
|
|
99
|
+
const pending = pendingAccountActivationError(response.status, payload);
|
|
100
|
+
const code = pending?.code ?? (typeof error?.code === 'string' ? error.code : statusCode(response.status));
|
|
101
|
+
const message = pending?.message ?? (typeof error?.message === 'string'
|
|
100
102
|
? error.message
|
|
101
103
|
: typeof payload?.message === 'string'
|
|
102
104
|
? payload.message
|
|
103
105
|
: typeof payload === 'string'
|
|
104
106
|
? payload
|
|
105
|
-
: response.statusText || 'PlayCraft request failed';
|
|
107
|
+
: response.statusText || 'PlayCraft request failed');
|
|
106
108
|
throw new PlayCraftApiError({
|
|
107
109
|
code,
|
|
108
110
|
message,
|
|
109
111
|
status: response.status,
|
|
110
|
-
details: error?.details ?? payload,
|
|
112
|
+
details: pending ? { loginCommand: 'playcraft login --activate' } : error?.details ?? payload,
|
|
111
113
|
retryable: response.status >= 500,
|
|
112
114
|
});
|
|
113
115
|
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
}
|