@playcraft/cli 0.1.54 → 0.1.56-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (454) hide show
  1. package/README.md +83 -15
  2. package/SKILLS_REGISTRY.md +149 -0
  3. package/dist/agent/local-backend.js +1 -1
  4. package/dist/assets/client.js +157 -0
  5. package/dist/assets/messages.js +48 -0
  6. package/dist/auth/account-activation.js +157 -0
  7. package/dist/auth/messages.js +30 -0
  8. package/dist/cli-root-help.js +4 -0
  9. package/dist/commands/assets.js +123 -0
  10. package/dist/commands/build-all.js +5 -19
  11. package/dist/commands/build-temp.js +26 -0
  12. package/dist/commands/build.js +53 -28
  13. package/dist/commands/create.js +26 -33
  14. package/dist/commands/image-layer-messages.js +37 -0
  15. package/dist/commands/image-layer-tools.js +185 -0
  16. package/dist/commands/image.js +2 -73
  17. package/dist/commands/library-messages.js +46 -0
  18. package/dist/commands/library.js +130 -0
  19. package/dist/commands/login.js +84 -42
  20. package/dist/commands/platform-skills.generated.js +19 -0
  21. package/dist/commands/playable.js +53 -0
  22. package/dist/commands/preview-runtime.js +21 -0
  23. package/dist/commands/skills.js +4 -0
  24. package/dist/commands/tools-3d.js +11 -0
  25. package/dist/commands/tools-batch.js +113 -0
  26. package/dist/commands/tools-generation.js +6 -0
  27. package/dist/commands/tools.js +2 -0
  28. package/dist/commands/video.js +122 -0
  29. package/dist/commands/workspace-runtime.js +54 -0
  30. package/dist/commands/workspace.js +40 -0
  31. package/dist/config.js +59 -4
  32. package/dist/index.js +47 -3
  33. package/dist/preview-runtime/distribution.js +77 -0
  34. package/dist/project-skills/builtin-import.js +225 -0
  35. package/dist/project-skills/commands.js +77 -0
  36. package/dist/project-skills/lifecycle.js +28 -0
  37. package/dist/project-skills/local-run.js +112 -0
  38. package/dist/project-skills/local-store.js +221 -0
  39. package/dist/project-skills/messages.js +80 -0
  40. package/dist/project-skills/reconcile.js +62 -0
  41. package/dist/project-skills/remote-cache.js +51 -0
  42. package/dist/project-skills/validation.js +19 -0
  43. package/dist/recording/messages.js +40 -0
  44. package/dist/recording/project-digest.js +85 -0
  45. package/dist/recording/recorder.js +293 -0
  46. package/dist/recording/scenario.js +50 -0
  47. package/dist/remix/clone.js +2 -0
  48. package/dist/remix/init-template.js +2 -0
  49. package/dist/remix/pull.js +2 -0
  50. package/dist/remix/push.js +21 -1
  51. package/dist/skill-registry/client.js +345 -0
  52. package/dist/skill-registry/commands.js +180 -0
  53. package/dist/skill-registry/evaluation-client.js +156 -0
  54. package/dist/skill-registry/evaluation-commands.js +174 -0
  55. package/dist/skill-registry/messages.js +177 -0
  56. package/dist/skill-registry/package.js +275 -0
  57. package/dist/skill-registry/platform-package.js +100 -0
  58. package/dist/utils/agent-api-client.js +245 -30
  59. package/dist/utils/environment-endpoints.js +17 -0
  60. package/dist/utils/error-diagnostics.js +20 -0
  61. package/dist/utils/playcraft-http-client.js +6 -4
  62. package/dist/utils/tool-operation-journal.js +124 -0
  63. package/dist/utils/video-evidence-git.js +81 -0
  64. package/dist/video-replication/client.js +234 -0
  65. package/dist/video-replication/comparison-evidence.js +149 -0
  66. package/dist/video-replication/comparison-files.js +57 -0
  67. package/dist/video-replication/comparison-log.js +72 -0
  68. package/dist/video-replication/comparison-messages.js +104 -0
  69. package/dist/video-replication/comparison-output.js +63 -0
  70. package/dist/video-replication/comparison-preflight.js +66 -0
  71. package/dist/video-replication/comparison.js +230 -0
  72. package/dist/video-replication/diagnostics.js +41 -0
  73. package/dist/video-replication/evidence.js +165 -0
  74. package/dist/video-replication/media.js +112 -0
  75. package/dist/video-replication/messages.js +97 -0
  76. package/dist/workspace/messages.js +67 -0
  77. package/dist/workspace/transfer-client.js +237 -0
  78. package/dist/workspace/transfer-errors.js +48 -0
  79. package/dist/workspace-runtime/batch/content-changes.js +30 -0
  80. package/dist/workspace-runtime/batch/control.js +86 -0
  81. package/dist/workspace-runtime/batch/deliver.js +173 -0
  82. package/dist/workspace-runtime/batch/freeze.js +101 -0
  83. package/dist/workspace-runtime/batch/generate.js +249 -0
  84. package/dist/workspace-runtime/batch/git.js +40 -0
  85. package/dist/workspace-runtime/batch/occupancy.js +8 -0
  86. package/dist/workspace-runtime/batch/policy.js +70 -0
  87. package/dist/workspace-runtime/batch/prepare.js +317 -0
  88. package/dist/workspace-runtime/batch/processes.js +72 -0
  89. package/dist/workspace-runtime/batch/records.js +113 -0
  90. package/dist/workspace-runtime/batch/routes.js +61 -0
  91. package/dist/workspace-runtime/batch/source-candidate.js +86 -0
  92. package/dist/workspace-runtime/batch/source-capture.js +146 -0
  93. package/dist/workspace-runtime/batch/source-failure.js +43 -0
  94. package/dist/workspace-runtime/batch/source-publish.js +130 -0
  95. package/dist/workspace-runtime/codex/app-server.js +1065 -0
  96. package/dist/workspace-runtime/codex/compact.js +46 -0
  97. package/dist/workspace-runtime/codex/config-toml.js +107 -0
  98. package/dist/workspace-runtime/codex/delivery-tools.js +144 -0
  99. package/dist/workspace-runtime/codex/jsonrpc-stdio.js +145 -0
  100. package/dist/workspace-runtime/codex/launcher-client.js +177 -0
  101. package/dist/workspace-runtime/codex/loopback.js +146 -0
  102. package/dist/workspace-runtime/codex/mcp-config.js +39 -0
  103. package/dist/workspace-runtime/codex/model-broker.js +263 -0
  104. package/dist/workspace-runtime/codex/native-adapter.js +9 -0
  105. package/dist/workspace-runtime/codex/permissions.js +79 -0
  106. package/dist/workspace-runtime/codex/thread-image.js +38 -0
  107. package/dist/workspace-runtime/codex/tool-response.js +10 -0
  108. package/dist/workspace-runtime/codex/ui-instructions.js +4 -0
  109. package/dist/workspace-runtime/codex/ui-tools.js +203 -0
  110. package/dist/workspace-runtime/codex/work-mode.js +15 -0
  111. package/dist/workspace-runtime/main.js +10 -0
  112. package/dist/workspace-runtime/persistence/journal.js +365 -0
  113. package/dist/workspace-runtime/persistence/native-subagents.js +162 -0
  114. package/dist/workspace-runtime/persistence/sqlite-client.js +77 -0
  115. package/dist/workspace-runtime/persistence/sqlite-worker.js +1161 -0
  116. package/dist/workspace-runtime/persistence/stopped-execution.js +77 -0
  117. package/dist/workspace-runtime/previews/diagnostics.js +44 -0
  118. package/dist/workspace-runtime/previews/finalize.js +64 -0
  119. package/dist/workspace-runtime/previews/output.js +36 -0
  120. package/dist/workspace-runtime/previews/publish.js +306 -0
  121. package/dist/workspace-runtime/previews/runtime-preview.js +251 -0
  122. package/dist/workspace-runtime/previews/single-file.js +43 -0
  123. package/dist/workspace-runtime/processes/managed-writes.js +69 -0
  124. package/dist/workspace-runtime/serve.js +441 -0
  125. package/dist/workspace-runtime/server/accept-operation.js +61 -0
  126. package/dist/workspace-runtime/server/asset-transfers.js +63 -0
  127. package/dist/workspace-runtime/server/auth.js +21 -0
  128. package/dist/workspace-runtime/server/connectivity.js +211 -0
  129. package/dist/workspace-runtime/server/desktop-host.js +429 -0
  130. package/dist/workspace-runtime/server/desktop-preview-config.js +81 -0
  131. package/dist/workspace-runtime/server/desktop-preview-service.js +157 -0
  132. package/dist/workspace-runtime/server/desktop-preview-static.js +53 -0
  133. package/dist/workspace-runtime/server/desktop-preview.js +189 -0
  134. package/dist/workspace-runtime/server/dispatch.js +1655 -0
  135. package/dist/workspace-runtime/server/endpoints.js +21 -0
  136. package/dist/workspace-runtime/server/execution-group.js +90 -0
  137. package/dist/workspace-runtime/server/http.js +1363 -0
  138. package/dist/workspace-runtime/server/lock.js +53 -0
  139. package/dist/workspace-runtime/server/operation-record.js +33 -0
  140. package/dist/workspace-runtime/server/rfb-watch-gate.js +168 -0
  141. package/dist/workspace-runtime/server/session-restore.js +84 -0
  142. package/dist/workspace-runtime/server/source-uploader.js +138 -0
  143. package/dist/workspace-runtime/server/submit-operation.js +41 -0
  144. package/dist/workspace-runtime/server/terminal-host.js +366 -0
  145. package/dist/workspace-runtime/server/types.js +1 -0
  146. package/dist/workspace-runtime/server/workspace-transfer.js +168 -0
  147. package/dist/workspace-runtime/verify-artifact.js +59 -0
  148. package/dist/workspace-runtime/workspaces/append-only-log.js +62 -0
  149. package/dist/workspace-runtime/workspaces/archive.js +207 -0
  150. package/dist/workspace-runtime/workspaces/artifact-events.js +168 -0
  151. package/dist/workspace-runtime/workspaces/artifact-files.js +201 -0
  152. package/dist/workspace-runtime/workspaces/artifact-receipts.js +112 -0
  153. package/dist/workspace-runtime/workspaces/artifacts.js +380 -0
  154. package/dist/workspace-runtime/workspaces/asset-library-import.js +387 -0
  155. package/dist/workspace-runtime/workspaces/asset-publication-access.js +29 -0
  156. package/dist/workspace-runtime/workspaces/asset-transfer-dependencies.js +81 -0
  157. package/dist/workspace-runtime/workspaces/asset-transfer-publish.js +438 -0
  158. package/dist/workspace-runtime/workspaces/asset-transfer-storage.js +389 -0
  159. package/dist/workspace-runtime/workspaces/attachment-content.js +73 -0
  160. package/dist/workspace-runtime/workspaces/attachments.js +185 -0
  161. package/dist/workspace-runtime/workspaces/batch-commit.js +142 -0
  162. package/dist/workspace-runtime/workspaces/binary-content.js +65 -0
  163. package/dist/workspace-runtime/workspaces/binary-write.js +117 -0
  164. package/dist/workspace-runtime/workspaces/cli-context.js +23 -0
  165. package/dist/workspace-runtime/workspaces/cli-credentials.js +115 -0
  166. package/dist/workspace-runtime/workspaces/composer-context.js +147 -0
  167. package/dist/workspace-runtime/workspaces/context-error.js +2 -0
  168. package/dist/workspace-runtime/workspaces/delivery-build.js +421 -0
  169. package/dist/workspace-runtime/workspaces/delivery-store.js +168 -0
  170. package/dist/workspace-runtime/workspaces/delivery.js +64 -0
  171. package/dist/workspace-runtime/workspaces/dependencies.js +279 -0
  172. package/dist/workspace-runtime/workspaces/developer-command.js +98 -0
  173. package/dist/workspace-runtime/workspaces/directories.js +135 -0
  174. package/dist/workspace-runtime/workspaces/directory-access.js +50 -0
  175. package/dist/workspace-runtime/workspaces/directory-attachments.js +245 -0
  176. package/dist/workspace-runtime/workspaces/directory-create.js +57 -0
  177. package/dist/workspace-runtime/workspaces/directory-maintenance.js +111 -0
  178. package/dist/workspace-runtime/workspaces/directory-mutations.js +238 -0
  179. package/dist/workspace-runtime/workspaces/directory-revisions.js +56 -0
  180. package/dist/workspace-runtime/workspaces/directory-stats.js +49 -0
  181. package/dist/workspace-runtime/workspaces/disk-snapshot.js +31 -0
  182. package/dist/workspace-runtime/workspaces/empty-template.js +43 -0
  183. package/dist/workspace-runtime/workspaces/file-content.js +48 -0
  184. package/dist/workspace-runtime/workspaces/files-search.js +116 -0
  185. package/dist/workspace-runtime/workspaces/files.js +150 -0
  186. package/dist/workspace-runtime/workspaces/git-credential-broker.js +312 -0
  187. package/dist/workspace-runtime/workspaces/git-credential-helper.js +68 -0
  188. package/dist/workspace-runtime/workspaces/git-direct-store.js +155 -0
  189. package/dist/workspace-runtime/workspaces/git.js +683 -0
  190. package/dist/workspace-runtime/workspaces/instructions.js +56 -0
  191. package/dist/workspace-runtime/workspaces/json5-edit.js +313 -0
  192. package/dist/workspace-runtime/workspaces/library-attachments.js +268 -0
  193. package/dist/workspace-runtime/workspaces/operation-log.js +23 -0
  194. package/dist/workspace-runtime/workspaces/optional-platform-skills.js +14 -0
  195. package/dist/workspace-runtime/workspaces/parameter-agent-inputs.js +97 -0
  196. package/dist/workspace-runtime/workspaces/parameter-agent-protocol.js +40 -0
  197. package/dist/workspace-runtime/workspaces/parameter-agent-store.js +58 -0
  198. package/dist/workspace-runtime/workspaces/parameter-agent.js +284 -0
  199. package/dist/workspace-runtime/workspaces/parameter-assets.js +212 -0
  200. package/dist/workspace-runtime/workspaces/parameters.js +369 -0
  201. package/dist/workspace-runtime/workspaces/prepare.js +284 -0
  202. package/dist/workspace-runtime/workspaces/registry.js +251 -0
  203. package/dist/workspace-runtime/workspaces/remix-references.js +301 -0
  204. package/dist/workspace-runtime/workspaces/revisions.js +31 -0
  205. package/dist/workspace-runtime/workspaces/session-image.js +104 -0
  206. package/dist/workspace-runtime/workspaces/shared-git.js +40 -0
  207. package/dist/workspace-runtime/workspaces/skill-artifact-loader.js +95 -0
  208. package/dist/workspace-runtime/workspaces/skills.js +191 -0
  209. package/dist/workspace-runtime/workspaces/theme-asset-index.js +267 -0
  210. package/dist/workspace-runtime/workspaces/transfer-quota.js +69 -0
  211. package/dist/workspace-runtime/workspaces/transfer.js +471 -0
  212. package/dist/workspace-runtime/workspaces/turn-changes.js +75 -0
  213. package/dist/workspace-runtime/workspaces/video-attachments.js +49 -0
  214. package/dist/workspace-runtime/workspaces/worktree-attachments.js +74 -0
  215. package/dist/workspace-runtime/workspaces/worktree-checkout.js +67 -0
  216. package/dist/workspace-runtime/workspaces/worktrees.js +73 -0
  217. package/package.json +16 -5
  218. package/project-template/.claude/skills/playcraft-audio-generation/SKILL.md +31 -4
  219. package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +36 -5
  220. package/project-template/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +1 -1
  221. package/project-template/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +1 -1
  222. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +1 -1
  223. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +1 -1
  224. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +1 -1
  225. package/project-template/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +1 -1
  226. package/project-template/.claude/skills/playcraft-image-generation/reference/ta-image-generation-detail.md +300 -0
  227. package/project-template/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +1 -1
  228. package/project-template/.claude/skills/playcraft-image-processing/SKILL.md +50 -25
  229. package/project-template/.claude/skills/playcraft-replica-validation/SKILL.md +25 -0
  230. package/project-template/.claude/skills/playcraft-replica-validation/references/contracts.md +79 -0
  231. package/project-template/.claude/skills/playcraft-video-understanding/SKILL.md +29 -0
  232. package/project-template/.claude/skills/playcraft-video-understanding/references/contracts.md +37 -0
  233. package/project-template/.claude/skills/playcraft-workspace-assets/SKILL.md +53 -0
  234. package/project-template/.claude/skills/playcraft-workspace-assets/references/requests.json +32 -0
  235. package/project-template-v2/.claude/agents/artist.md +82 -0
  236. package/project-template-v2/.claude/agents/developer.md +153 -0
  237. package/project-template-v2/.claude/agents/game-designer.md +264 -0
  238. package/project-template-v2/.claude/agents/refs/artist-art-style-catalog.md +533 -0
  239. package/project-template-v2/.claude/agents/refs/artist-color-audio-recipes.md +153 -0
  240. package/project-template-v2/.claude/agents/refs/artist-dimension-axis.md +27 -0
  241. package/project-template-v2/.claude/agents/refs/artist-master-composite-recipes.md +208 -0
  242. package/project-template-v2/.claude/agents/refs/atom-skill-library.md +81 -0
  243. package/project-template-v2/.claude/agents/refs/developer-impl-cookbook.md +432 -0
  244. package/project-template-v2/.claude/agents/refs/framework-5-component-filter.md +252 -0
  245. package/project-template-v2/.claude/agents/refs/framework-game-feel-juice.md +266 -0
  246. package/project-template-v2/.claude/agents/refs/framework-mda.md +147 -0
  247. package/project-template-v2/.claude/agents/refs/game-designer-gameplay-sufficiency.md +123 -0
  248. package/project-template-v2/.claude/agents/refs/ta-3d-flip-recipe.md +88 -0
  249. package/project-template-v2/.claude/agents/refs/ta-atlas-deliverable-standard.md +67 -0
  250. package/project-template-v2/.claude/agents/refs/ta-batch-pipeline-recipes.md +120 -0
  251. package/project-template-v2/.claude/agents/refs/ta-image-generation-detail.md +300 -0
  252. package/project-template-v2/.claude/agents/refs/ta-image-ops-reference.md +495 -0
  253. package/project-template-v2/.claude/agents/refs/ta-pipeline-cookbook.md +1141 -0
  254. package/project-template-v2/.claude/agents/refs/ta-tools-reference.md +111 -0
  255. package/project-template-v2/.claude/agents/refs/ta-vfx-preset-catalog.md +365 -0
  256. package/project-template-v2/.claude/agents/refs/threejs-cannon-pitfalls.md +412 -0
  257. package/project-template-v2/.claude/agents/reviewer.md +75 -0
  258. package/project-template-v2/.claude/agents/technical-artist.md +86 -0
  259. package/project-template-v2/.claude/hooks/snapshot-milestone.mjs +243 -0
  260. package/project-template-v2/.claude/hooks/user-prompt.mjs +133 -0
  261. package/project-template-v2/.claude/settings.json +33 -0
  262. package/project-template-v2/.claude/skills/brainstorming/SKILL.md +161 -0
  263. package/project-template-v2/.claude/skills/brainstorming/scripts/frame-template.html +270 -0
  264. package/project-template-v2/.claude/skills/brainstorming/scripts/helper.js +177 -0
  265. package/project-template-v2/.claude/skills/brainstorming/scripts/server.cjs +354 -0
  266. package/project-template-v2/.claude/skills/brainstorming/scripts/start-server.sh +148 -0
  267. package/project-template-v2/.claude/skills/brainstorming/scripts/stop-server.sh +56 -0
  268. package/project-template-v2/.claude/skills/brainstorming/scripts/wait-for-selection.sh +62 -0
  269. package/project-template-v2/.claude/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  270. package/project-template-v2/.claude/skills/brainstorming/visual-companion.md +309 -0
  271. package/project-template-v2/.claude/skills/playcraft-ad-psychology/SKILL.md +182 -0
  272. package/project-template-v2/.claude/skills/playcraft-art-style-guide/SKILL.md +123 -0
  273. package/project-template-v2/.claude/skills/playcraft-asset-state-sheet/SKILL.md +205 -0
  274. package/project-template-v2/.claude/skills/playcraft-audio-generation/SKILL.md +307 -0
  275. package/project-template-v2/.claude/skills/playcraft-batch-pipeline/SKILL.md +184 -0
  276. package/project-template-v2/.claude/skills/playcraft-build-optimizer/SKILL.md +306 -0
  277. package/project-template-v2/.claude/skills/playcraft-image-generation/SKILL.md +401 -0
  278. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +123 -0
  279. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +254 -0
  280. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +333 -0
  281. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +95 -0
  282. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +118 -0
  283. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +136 -0
  284. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +397 -0
  285. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/ta-image-generation-detail.md +300 -0
  286. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +296 -0
  287. package/project-template-v2/.claude/skills/playcraft-image-ops/SKILL.md +122 -0
  288. package/project-template-v2/.claude/skills/playcraft-image-processing/SKILL.md +244 -0
  289. package/project-template-v2/.claude/skills/playcraft-masking/SKILL.md +373 -0
  290. package/project-template-v2/.claude/skills/playcraft-playable-optimization/SKILL.md +161 -0
  291. package/project-template-v2/.claude/skills/playcraft-research/SKILL.md +215 -0
  292. package/project-template-v2/.claude/skills/playcraft-skill-recommender/SKILL.md +382 -0
  293. package/project-template-v2/.claude/skills/playcraft-sprite-generation/SKILL.md +423 -0
  294. package/project-template-v2/.claude/skills/playcraft-sprite-remix/SKILL.md +158 -0
  295. package/project-template-v2/.claude/skills/playcraft-sprite-sheet/SKILL.md +100 -0
  296. package/project-template-v2/.claude/skills/playcraft-storyboard/SKILL.md +167 -0
  297. package/project-template-v2/.claude/skills/playcraft-style-qa/SKILL.md +270 -0
  298. package/project-template-v2/.claude/skills/playcraft-text-rendering/SKILL.md +236 -0
  299. package/project-template-v2/.claude/skills/playcraft-vfx-animation/SKILL.md +130 -0
  300. package/project-template-v2/.claude/skills/playcraft-workspace-assets/SKILL.md +53 -0
  301. package/project-template-v2/.claude/skills/playcraft-workspace-assets/references/requests.json +32 -0
  302. package/project-template-v2/.claude/skills/playwright-cli/SKILL.md +390 -0
  303. package/project-template-v2/.claude/skills/playwright-cli/references/element-attributes.md +23 -0
  304. package/project-template-v2/.claude/skills/playwright-cli/references/playwright-tests.md +39 -0
  305. package/project-template-v2/.claude/skills/playwright-cli/references/request-mocking.md +87 -0
  306. package/project-template-v2/.claude/skills/playwright-cli/references/running-code.md +240 -0
  307. package/project-template-v2/.claude/skills/playwright-cli/references/session-management.md +226 -0
  308. package/project-template-v2/.claude/skills/playwright-cli/references/spec-driven-testing.md +308 -0
  309. package/project-template-v2/.claude/skills/playwright-cli/references/storage-state.md +275 -0
  310. package/project-template-v2/.claude/skills/playwright-cli/references/test-generation.md +134 -0
  311. package/project-template-v2/.claude/skills/playwright-cli/references/tracing.md +142 -0
  312. package/project-template-v2/.claude/skills/playwright-cli/references/video-recording.md +153 -0
  313. package/project-template-v2/.claude/skills/session-analyzer/SKILL.md +386 -0
  314. package/project-template-v2/.claude/skills/session-analyzer/scripts/execution-breakdown.mjs +182 -0
  315. package/project-template-v2/.claude/skills/session-analyzer/scripts/find-turns.mjs +72 -0
  316. package/project-template-v2/.claude/skills/session-analyzer/scripts/heavy-output.mjs +121 -0
  317. package/project-template-v2/.claude/skills/session-analyzer/scripts/resolve-session.mjs +102 -0
  318. package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-stats.mjs +127 -0
  319. package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-tool-timeline.mjs +106 -0
  320. package/project-template-v2/.claude/skills/session-analyzer/scripts/time-gaps.mjs +128 -0
  321. package/project-template-v2/.claude/skills/session-analyzer/scripts/turn-timeline.mjs +67 -0
  322. package/project-template-v2/.claude/snapshot.mjs +263 -0
  323. package/project-template-v2/.playcraft/skills.lock.json +152 -0
  324. package/project-template-v2/CLAUDE.md +146 -0
  325. package/project-template-v2/assets/audio/bgm/.gitkeep +0 -0
  326. package/project-template-v2/assets/audio/sfx/.gitkeep +0 -0
  327. package/project-template-v2/assets/bundles/.gitkeep +0 -0
  328. package/project-template-v2/assets/images/bg/.gitkeep +0 -0
  329. package/project-template-v2/assets/images/reference/.gitkeep +0 -0
  330. package/project-template-v2/assets/images/storyboard/.gitkeep +0 -0
  331. package/project-template-v2/assets/images/tiles/.gitkeep +0 -0
  332. package/project-template-v2/assets/images/ui/.gitkeep +0 -0
  333. package/project-template-v2/assets/images/vfx/.gitkeep +0 -0
  334. package/project-template-v2/assets/models/.gitkeep +0 -0
  335. package/project-template-v2/docs/harness/iteration-1/context-flow.md +254 -0
  336. package/project-template-v2/docs/harness/iteration-1/generate-flow.md +91 -0
  337. package/project-template-v2/docs/harness/iteration-1/ideate-flow.md +214 -0
  338. package/project-template-v2/docs/harness/iteration-1/optimize-flow.md +75 -0
  339. package/project-template-v2/docs/harness/iteration-1/wrapup-flow.md +63 -0
  340. package/project-template-v2/docs/harness/iteration-2/context-flow.md +223 -0
  341. package/project-template-v2/docs/harness/iteration-2/generate-flow.md +129 -0
  342. package/project-template-v2/docs/harness/iteration-2/ideate-flow.md +267 -0
  343. package/project-template-v2/docs/harness/iteration-2/optimize-flow.md +164 -0
  344. package/project-template-v2/docs/harness/iteration-2/wrapup-flow.md +115 -0
  345. package/project-template-v2/docs/harness/orchestrator-flow.md +364 -0
  346. package/project-template-v2/docs/project-state.json +60 -0
  347. package/project-template-v2/docs/project-state.md +72 -0
  348. package/project-template-v2/docs/standards/README.md +225 -0
  349. package/project-template-v2/docs/standards/agent-behavior-standards.md +174 -0
  350. package/project-template-v2/docs/standards/artifacts/design-brief.md +19 -0
  351. package/project-template-v2/docs/standards/artifacts/design.md +22 -0
  352. package/project-template-v2/docs/standards/artifacts/game-code.md +41 -0
  353. package/project-template-v2/docs/standards/artifacts/todo-list.md +41 -0
  354. package/project-template-v2/docs/standards/iter1-agent-behavior-standards.md +343 -0
  355. package/project-template-v2/game/index.ts +18 -0
  356. package/project-template-v2/globals.d.ts +51 -0
  357. package/project-template-v2/index.css +34 -0
  358. package/project-template-v2/index.html +18 -0
  359. package/project-template-v2/main.ts +9 -0
  360. package/project-template-v2/package.json +46 -0
  361. package/project-template-v2/skills/_shared/scripts/dispatch-clear.mjs +31 -0
  362. package/project-template-v2/skills/_shared/scripts/dispatch-set.mjs +86 -0
  363. package/project-template-v2/skills/_shared/scripts/dod-check.mjs +153 -0
  364. package/project-template-v2/skills/_shared/scripts/handoff-append.mjs +70 -0
  365. package/project-template-v2/skills/_shared/scripts/lib/validator-artifacts.mjs +91 -0
  366. package/project-template-v2/skills/_shared/scripts/pipeline/dod-config.mjs +131 -0
  367. package/project-template-v2/skills/_shared/scripts/pipeline/index.mjs +80 -0
  368. package/project-template-v2/skills/_shared/scripts/pipeline/iteration-1-core.mjs +90 -0
  369. package/project-template-v2/skills/_shared/scripts/pipeline/iteration-2-wrap.mjs +93 -0
  370. package/project-template-v2/skills/_shared/scripts/pipeline/iteration-3-visual.mjs +23 -0
  371. package/project-template-v2/skills/_shared/scripts/render-project-state.mjs +230 -0
  372. package/project-template-v2/skills/_shared/scripts/state-advance-stage.mjs +58 -0
  373. package/project-template-v2/skills/_shared/scripts/state-get.mjs +339 -0
  374. package/project-template-v2/skills/_shared/scripts/state-handoff.mjs +39 -0
  375. package/project-template-v2/skills/_shared/scripts/state-set.mjs +94 -0
  376. package/project-template-v2/skills/_shared/scripts/state-store.mjs +783 -0
  377. package/project-template-v2/skills/_shared/scripts/todo-add.mjs +88 -0
  378. package/project-template-v2/skills/_shared/scripts/todo-get.mjs +130 -0
  379. package/project-template-v2/skills/_shared/scripts/todo-remove.mjs +33 -0
  380. package/project-template-v2/skills/_shared/scripts/todo-set.mjs +47 -0
  381. package/project-template-v2/skills/_shared/scripts/verify-asset-code-sync.mjs +268 -0
  382. package/project-template-v2/skills/_shared/scripts/verify-env.mjs +285 -0
  383. package/project-template-v2/skills/_shared/scripts/verify-placeholders.mjs +161 -0
  384. package/project-template-v2/skills/playable-autoplay/SKILL.md +176 -0
  385. package/project-template-v2/skills/playable-autoplay/agents/openai.yaml +4 -0
  386. package/project-template-v2/skills/playable-debug/SKILL.md +116 -0
  387. package/project-template-v2/skills/playable-debug/agents/openai.yaml +4 -0
  388. package/project-template-v2/skills/playable-debug/references/debug-config.md +40 -0
  389. package/project-template-v2/skills/playable-record/SKILL.md +140 -0
  390. package/project-template-v2/skills/playable-record/scripts/lib/dev-server.mjs +104 -0
  391. package/project-template-v2/skills/playable-record/scripts/lib/record-audio-bridge.js +141 -0
  392. package/project-template-v2/skills/playable-record/scripts/record-playable.mjs +425 -0
  393. package/project-template-v2/skills/playable-record/scripts/verify-contract.mjs +261 -0
  394. package/project-template-v2/skills/playable-record/scripts/verify-firstwin.mjs +398 -0
  395. package/project-template-v2/skills/playable-record/scripts/verify-fusion.mjs +322 -0
  396. package/project-template-v2/skills/playable-record/scripts/verify-lifecycle.mjs +105 -0
  397. package/project-template-v2/skills/playable-record/scripts/verify-vlm-video.mjs +230 -0
  398. package/project-template-v2/skills/playable-validate/SKILL.md +61 -0
  399. package/project-template-v2/skills/playable-validate/validation-rules.md +14 -0
  400. package/project-template-v2/skills/playable-verify-ui/SKILL.md +63 -0
  401. package/project-template-v2/skills/playable-verify-ui/scripts/lib/__init__.py +1 -0
  402. package/project-template-v2/skills/playable-verify-ui/scripts/lib/config_expr.js +218 -0
  403. package/project-template-v2/skills/playable-verify-ui/scripts/lib/node_utils.js +51 -0
  404. package/project-template-v2/skills/playable-verify-ui/scripts/lib/profile_loader.py +59 -0
  405. package/project-template-v2/skills/playable-verify-ui/scripts/lib/report.py +106 -0
  406. package/project-template-v2/skills/playable-verify-ui/scripts/lib/runtime_contract.js +116 -0
  407. package/project-template-v2/skills/playable-verify-ui/scripts/verify_fetch_antipatterns.py +59 -0
  408. package/project-template-v2/skills/playable-verify-ui/scripts/verify_hardcoded_layout.js +64 -0
  409. package/project-template-v2/skills/playable-verify-ui/scripts/verify_runtime_contract.js +58 -0
  410. package/project-template-v2/skills/playable-verify-ui/scripts/verify_text_overlap.py +333 -0
  411. package/project-template-v2/ta-workspace/scripts/.gitkeep +0 -0
  412. package/project-template-v2/tsconfig.json +20 -0
  413. package/project-template-v2/vite.config.ts +27 -0
  414. package/project-templates/batch-locks/phaser.yaml +922 -0
  415. package/project-templates/batch-locks/threejs.yaml +978 -0
  416. package/project-templates/empty/AGENTS.md +53 -0
  417. package/project-templates/empty/gitignore +33 -0
  418. package/project-templates/phaser/.claude/skills/playcraft-audio-generation/SKILL.md +31 -4
  419. package/project-templates/phaser/.claude/skills/playcraft-image-generation/SKILL.md +36 -5
  420. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +1 -1
  421. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +1 -1
  422. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +1 -1
  423. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +1 -1
  424. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +1 -1
  425. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +1 -1
  426. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/ta-image-generation-detail.md +300 -0
  427. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +1 -1
  428. package/project-templates/phaser/.claude/skills/playcraft-image-processing/SKILL.md +50 -25
  429. package/project-templates/phaser/.claude/skills/playcraft-workspace-assets/SKILL.md +53 -0
  430. package/project-templates/phaser/.claude/skills/playcraft-workspace-assets/references/requests.json +32 -0
  431. package/project-templates/threejs/.claude/skills/playcraft-audio-generation/SKILL.md +31 -4
  432. package/project-templates/threejs/.claude/skills/playcraft-image-generation/SKILL.md +36 -5
  433. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +1 -1
  434. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +1 -1
  435. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +1 -1
  436. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +1 -1
  437. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +1 -1
  438. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +1 -1
  439. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/ta-image-generation-detail.md +300 -0
  440. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +1 -1
  441. package/project-templates/threejs/.claude/skills/playcraft-image-processing/SKILL.md +50 -25
  442. package/project-templates/threejs/.claude/skills/playcraft-workspace-assets/SKILL.md +53 -0
  443. package/project-templates/threejs/.claude/skills/playcraft-workspace-assets/references/requests.json +32 -0
  444. package/templates/preview-runtime/v1/README.md +79 -0
  445. package/templates/preview-runtime/v1/build-preview.mjs +1324 -0
  446. package/templates/preview-runtime/v1/manifest.json +17 -0
  447. package/templates/preview-runtime/v1/release-guard.mjs +87 -0
  448. package/templates/preview-runtime/v1/runtime.d.mts +3 -0
  449. package/templates/preview-runtime/v1/runtime.d.ts +3 -0
  450. package/templates/preview-runtime/v1/runtime.mjs +1312 -0
  451. package/templates/preview-runtime/v1/types/adapters.d.ts +28 -0
  452. package/templates/preview-runtime/v1/types/preview.d.ts +24 -0
  453. package/templates/preview-runtime/v1/types/protocol.d.ts +131 -0
  454. package/templates/preview-runtime/v1/types/runtime.d.ts +14 -0
@@ -0,0 +1,1312 @@
1
+ // ../iframe-bridge/package.json
2
+ var package_default = {
3
+ name: "@playcraft/iframe-bridge",
4
+ version: "0.0.55",
5
+ private: false,
6
+ type: "module",
7
+ description: "PlayCraft iframe postMessage bridge SDK for parent \u2194 child communication",
8
+ sideEffects: false,
9
+ publishConfig: {
10
+ access: "public"
11
+ },
12
+ main: "./dist/index.js",
13
+ types: "./dist/index.d.ts",
14
+ exports: {
15
+ ".": {
16
+ types: "./dist/index.d.ts",
17
+ default: "./dist/index.js"
18
+ }
19
+ },
20
+ files: [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ scripts: {
25
+ build: `node -e "require('fs').rmSync('dist',{recursive:true,force:true})" && rollup -c`,
26
+ dev: "rollup -c -w",
27
+ typecheck: "tsc -p tsconfig.json --noEmit",
28
+ prepublishOnly: "pnpm build",
29
+ test: "vitest run",
30
+ "test:watch": "vitest",
31
+ playground: 'pnpm --filter "@playcraft/iframe-bridge-playground-*" --parallel dev',
32
+ lint: "echo 'No eslint config yet'",
33
+ release: "node ../../scripts/release-npm.mjs --packages=iframe-bridge --skip-install --skip-tests --skip-git-push"
34
+ },
35
+ devDependencies: {
36
+ "@rollup/plugin-json": "6.1.0",
37
+ "@rollup/plugin-node-resolve": "16.0.3",
38
+ "@rollup/plugin-swc": "0.4.0",
39
+ "@swc/core": "1.15.3",
40
+ "@types/node": "^25.2.0",
41
+ "happy-dom": "^20.0.10",
42
+ rollup: "4.57.1",
43
+ "rollup-plugin-dts": "6.3.0",
44
+ typescript: "^5.9.3",
45
+ vite: "^8.0.3",
46
+ vitest: "^3.2.4"
47
+ }
48
+ };
49
+
50
+ // ../iframe-bridge/src/configs/constants.ts
51
+ var PROTOCOL_VERSION = package_default.version;
52
+ var DEFAULT_REQUEST_TIMEOUT_MS = 15e4;
53
+ var BridgeErrorCodes = {
54
+ ABORTED: "ABORTED",
55
+ DESTROYED: "DESTROYED",
56
+ INTERNAL_ERROR: "INTERNAL_ERROR",
57
+ INVALID_PARAM: "INVALID_PARAM",
58
+ METHOD_NOT_FOUND: "METHOD_NOT_FOUND",
59
+ PEER_UNAVAILABLE: "PEER_UNAVAILABLE",
60
+ REQUEST_FAILED: "REQUEST_FAILED",
61
+ TIMEOUT: "TIMEOUT"
62
+ };
63
+ var RetCodes = {
64
+ OK: 0,
65
+ INVALID_PARAM: 1,
66
+ TIMEOUT: 2,
67
+ ABORTED: 3,
68
+ REQUEST_FAILED: 4,
69
+ INTERNAL_ERROR: 5,
70
+ PEER_UNAVAILABLE: 6,
71
+ DESTROYED: 7,
72
+ METHOD_NOT_FOUND: 8
73
+ };
74
+ var ERROR_CODE_TO_RET = {
75
+ [BridgeErrorCodes.INVALID_PARAM]: RetCodes.INVALID_PARAM,
76
+ [BridgeErrorCodes.TIMEOUT]: RetCodes.TIMEOUT,
77
+ [BridgeErrorCodes.ABORTED]: RetCodes.ABORTED,
78
+ [BridgeErrorCodes.REQUEST_FAILED]: RetCodes.REQUEST_FAILED,
79
+ [BridgeErrorCodes.INTERNAL_ERROR]: RetCodes.INTERNAL_ERROR,
80
+ [BridgeErrorCodes.PEER_UNAVAILABLE]: RetCodes.PEER_UNAVAILABLE,
81
+ [BridgeErrorCodes.DESTROYED]: RetCodes.DESTROYED,
82
+ [BridgeErrorCodes.METHOD_NOT_FOUND]: RetCodes.METHOD_NOT_FOUND
83
+ };
84
+ var RET_TO_ERROR_CODE = {
85
+ [RetCodes.INVALID_PARAM]: BridgeErrorCodes.INVALID_PARAM,
86
+ [RetCodes.TIMEOUT]: BridgeErrorCodes.TIMEOUT,
87
+ [RetCodes.ABORTED]: BridgeErrorCodes.ABORTED,
88
+ [RetCodes.REQUEST_FAILED]: BridgeErrorCodes.REQUEST_FAILED,
89
+ [RetCodes.INTERNAL_ERROR]: BridgeErrorCodes.INTERNAL_ERROR,
90
+ [RetCodes.PEER_UNAVAILABLE]: BridgeErrorCodes.PEER_UNAVAILABLE,
91
+ [RetCodes.DESTROYED]: BridgeErrorCodes.DESTROYED,
92
+ [RetCodes.METHOD_NOT_FOUND]: BridgeErrorCodes.METHOD_NOT_FOUND
93
+ };
94
+ function errorCodeToRet(code) {
95
+ return ERROR_CODE_TO_RET[code] ?? RetCodes.REQUEST_FAILED;
96
+ }
97
+ function retToErrorCode(ret) {
98
+ return RET_TO_ERROR_CODE[ret] ?? BridgeErrorCodes.REQUEST_FAILED;
99
+ }
100
+
101
+ // ../iframe-bridge/src/utils/envelope.ts
102
+ function isEnvelopeKind(kind) {
103
+ return kind === "req" || kind === "res";
104
+ }
105
+ function isPlaycraftEnvelopeShape(data) {
106
+ if (!data || typeof data !== "object") return false;
107
+ const env = data;
108
+ return typeof env.__playcraft__ === "string" && isEnvelopeKind(env.kind) && typeof env.id === "string" && typeof env.name === "string";
109
+ }
110
+ function getPlaycraftEnvelopeVersionMismatch(data) {
111
+ if (!isPlaycraftEnvelopeShape(data)) return void 0;
112
+ const peer = data.__playcraft__;
113
+ if (peer === PROTOCOL_VERSION) return void 0;
114
+ return { local: PROTOCOL_VERSION, peer };
115
+ }
116
+ function createEnvelope(kind, id, name, data) {
117
+ return { __playcraft__: PROTOCOL_VERSION, kind, id, name, data };
118
+ }
119
+ function createSuccessResponse(id, name, data) {
120
+ return { ...createEnvelope("res", id, name), ret: RetCodes.OK, data };
121
+ }
122
+ function createErrorResponse(id, name, error) {
123
+ return {
124
+ ...createEnvelope("res", id, name),
125
+ ret: error.ret,
126
+ msg: error.msg
127
+ };
128
+ }
129
+ function isPlaycraftEnvelope(data) {
130
+ return isPlaycraftEnvelopeShape(data);
131
+ }
132
+
133
+ // ../iframe-bridge/src/utils/errors.ts
134
+ var PlaycraftBridgeError = class extends Error {
135
+ code;
136
+ detail;
137
+ constructor(code, message, detail) {
138
+ super(message);
139
+ this.name = "PlaycraftBridgeError";
140
+ this.code = code;
141
+ this.detail = detail;
142
+ }
143
+ };
144
+ function isRpcError(value) {
145
+ return !!value && typeof value === "object" && "ret" in value && "msg" in value && typeof value.ret === "number" && typeof value.msg === "string";
146
+ }
147
+ function isLegacyCodeMessageError(value) {
148
+ return !!value && typeof value === "object" && "code" in value && "message" in value && typeof value.code === "string" && typeof value.message === "string";
149
+ }
150
+ function toPlaycraftError(err) {
151
+ if (isRpcError(err)) {
152
+ return err;
153
+ }
154
+ if (err instanceof PlaycraftBridgeError) {
155
+ return {
156
+ ret: errorCodeToRet(err.code),
157
+ msg: err.message
158
+ };
159
+ }
160
+ if (isLegacyCodeMessageError(err)) {
161
+ return {
162
+ ret: errorCodeToRet(err.code),
163
+ msg: err.message
164
+ };
165
+ }
166
+ return {
167
+ ret: RetCodes.INTERNAL_ERROR,
168
+ msg: err instanceof Error ? err.message : String(err)
169
+ };
170
+ }
171
+
172
+ // ../iframe-bridge/src/configs/method-names.ts
173
+ var BridgeMethods = {
174
+ form: {
175
+ get: "form.get",
176
+ set: "form.set"
177
+ },
178
+ image: {
179
+ aiGenerate: "image.aiGenerate"
180
+ },
181
+ dialog: {
182
+ close: "dialog.close"
183
+ },
184
+ storage: {
185
+ get: "storage.get"
186
+ },
187
+ child: {
188
+ ready: "child.ready"
189
+ },
190
+ host: {
191
+ init: "host.init"
192
+ },
193
+ runtimeParameters: {
194
+ hello: "runtime.parameters.hello",
195
+ snapshot: "runtime.parameters.snapshot",
196
+ patch: "runtime.parameters.patch",
197
+ restart: "runtime.parameters.restart",
198
+ status: "runtime.parameters.status",
199
+ dispose: "runtime.parameters.dispose",
200
+ asset: "runtime.parameters.asset",
201
+ capabilities: "runtime.parameters.capabilities",
202
+ result: "runtime.parameters.result",
203
+ resyncRequired: "runtime.parameters.resync-required"
204
+ }
205
+ };
206
+ var BRIDGE_EVENT_NAMES = [
207
+ BridgeMethods.child.ready,
208
+ BridgeMethods.host.init,
209
+ BridgeMethods.dialog.close,
210
+ BridgeMethods.runtimeParameters.capabilities,
211
+ BridgeMethods.runtimeParameters.result,
212
+ BridgeMethods.runtimeParameters.resyncRequired
213
+ ];
214
+ var BRIDGE_RPC_NAMES = [
215
+ BridgeMethods.form.get,
216
+ BridgeMethods.form.set,
217
+ BridgeMethods.image.aiGenerate,
218
+ BridgeMethods.storage.get,
219
+ BridgeMethods.runtimeParameters.hello,
220
+ BridgeMethods.runtimeParameters.snapshot,
221
+ BridgeMethods.runtimeParameters.patch,
222
+ BridgeMethods.runtimeParameters.restart,
223
+ BridgeMethods.runtimeParameters.status,
224
+ BridgeMethods.runtimeParameters.dispose,
225
+ BridgeMethods.runtimeParameters.asset
226
+ ];
227
+
228
+ // ../iframe-bridge/src/configs/perspective.ts
229
+ var BridgePerspectives = {
230
+ parent: "parent",
231
+ child: "child"
232
+ };
233
+ function bridgePeerForPerspective(perspective) {
234
+ return perspective === BridgePerspectives.parent ? "Parent" : "Child";
235
+ }
236
+
237
+ // ../iframe-bridge/src/utils/debug-log.ts
238
+ var PARENT_TO_CHILD_REQS = /* @__PURE__ */ new Set([BridgeMethods.host.init]);
239
+ var PEER_CONSOLE_STYLES = {
240
+ Parent: "color: #6366f1; font-weight: bold",
241
+ Child: "color: #fead43; font-weight: bold"
242
+ };
243
+ var LOCAL_CONSOLE_STYLES = {
244
+ [BridgePerspectives.parent]: "color: #6366f1; font-weight: bold",
245
+ [BridgePerspectives.child]: "color: #fead43; font-weight: bold"
246
+ };
247
+ function resolveWireFlow(name, kind) {
248
+ if (kind === "res" || PARENT_TO_CHILD_REQS.has(name)) {
249
+ return { from: "Parent", to: "Child" };
250
+ }
251
+ return { from: "Child", to: "Parent" };
252
+ }
253
+ function logBridgeDebug(perspective, direction, msg) {
254
+ if (!perspective) {
255
+ console.debug(`[playcraft:${direction}]`, msg);
256
+ return;
257
+ }
258
+ const { from, to } = resolveWireFlow(msg.name, msg.kind);
259
+ const localLabel = bridgePeerForPerspective(perspective);
260
+ console.debug(
261
+ `%c[${localLabel}]%c %c${from}%c \u2192 %c${to}%c \xB7 ${direction} \xB7 ${msg.kind} \xB7 ${msg.name}`,
262
+ LOCAL_CONSOLE_STYLES[perspective],
263
+ "",
264
+ PEER_CONSOLE_STYLES[from],
265
+ "color: inherit",
266
+ PEER_CONSOLE_STYLES[to],
267
+ "color: inherit",
268
+ msg
269
+ );
270
+ }
271
+
272
+ // ../iframe-bridge/src/utils/is-event-name.ts
273
+ var EVENT_NAMES = new Set(BRIDGE_EVENT_NAMES);
274
+ function isEventName(name) {
275
+ return EVENT_NAMES.has(name);
276
+ }
277
+
278
+ // ../iframe-bridge/src/utils/id.ts
279
+ var idSeq = 0;
280
+ function genId() {
281
+ return `${Date.now()}-${idSeq++}`;
282
+ }
283
+
284
+ // ../iframe-bridge/src/utils/send-req.ts
285
+ function sendReq(bridge, name, data) {
286
+ bridge.postMessage(createEnvelope("req", genId(), name, data));
287
+ }
288
+
289
+ // ../iframe-bridge/src/libs/invoke.ts
290
+ function normalizeInvokeCall(call) {
291
+ if (Array.isArray(call)) {
292
+ const [name, data, options] = call;
293
+ return { name, data, options };
294
+ }
295
+ return call;
296
+ }
297
+ function isInvokeGroups(input) {
298
+ return Array.isArray(input) && input.length > 0 && typeof input[0] === "object" && input[0] !== null && "calls" in input[0];
299
+ }
300
+ async function settleParallel(promises) {
301
+ const settled = await Promise.allSettled(promises);
302
+ return settled.map(
303
+ (outcome) => outcome.status === "fulfilled" ? outcome.value : { error: toPlaycraftError(outcome.reason) }
304
+ );
305
+ }
306
+ async function runInvokeCalls(bridge, calls, mode, batchOptions = {}, defaultTimeout = DEFAULT_REQUEST_TIMEOUT_MS) {
307
+ const normalized = calls.map(normalizeInvokeCall);
308
+ const shared = { timeout: batchOptions.timeout, signal: batchOptions.signal };
309
+ if (mode === "parallel") {
310
+ return settleParallel(
311
+ normalized.map(
312
+ (call) => emitOne(bridge, call.name, call.data, { ...shared, ...call.options }, defaultTimeout)
313
+ )
314
+ );
315
+ }
316
+ const results = [];
317
+ for (const call of normalized) {
318
+ results.push(
319
+ await emitOne(bridge, call.name, call.data, { ...shared, ...call.options }, defaultTimeout)
320
+ );
321
+ }
322
+ return results;
323
+ }
324
+ function emitOne(bridge, name, data, options = {}, defaultTimeout = DEFAULT_REQUEST_TIMEOUT_MS) {
325
+ if (isEventName(name)) {
326
+ sendReq(bridge, name, data ?? {});
327
+ return Promise.resolve(void 0);
328
+ }
329
+ const timeout = options.timeout ?? defaultTimeout;
330
+ const id = genId();
331
+ return new Promise((resolve, reject) => {
332
+ let pending;
333
+ const offMessage = bridge.addEventListener("message", (e) => {
334
+ const msg = e.data;
335
+ if (msg.kind !== "res" || msg.id !== id || msg.name !== name) return;
336
+ clearTimeout(pending.timer);
337
+ pending.cleanupAbortListener?.();
338
+ offMessage();
339
+ if (msg.ret === RetCodes.OK) {
340
+ resolve(msg.data);
341
+ } else {
342
+ reject(
343
+ new PlaycraftBridgeError(
344
+ retToErrorCode(msg.ret ?? RetCodes.REQUEST_FAILED),
345
+ msg.msg ?? "request failed"
346
+ )
347
+ );
348
+ }
349
+ });
350
+ pending = {
351
+ resolve,
352
+ reject,
353
+ timer: setTimeout(() => {
354
+ offMessage();
355
+ reject(
356
+ new PlaycraftBridgeError(
357
+ BridgeErrorCodes.TIMEOUT,
358
+ `[playcraft] emit "${name}" timeout after ${timeout}ms`
359
+ )
360
+ );
361
+ }, timeout),
362
+ offMessage
363
+ };
364
+ if (options.signal) {
365
+ const onAbort = () => {
366
+ clearTimeout(pending.timer);
367
+ offMessage();
368
+ reject(
369
+ new PlaycraftBridgeError(BridgeErrorCodes.ABORTED, `[playcraft] emit "${name}" aborted`)
370
+ );
371
+ };
372
+ if (options.signal.aborted) {
373
+ onAbort();
374
+ return;
375
+ }
376
+ options.signal.addEventListener("abort", onAbort, { once: true });
377
+ pending.cleanupAbortListener = () => options.signal?.removeEventListener("abort", onAbort);
378
+ }
379
+ try {
380
+ bridge.postMessage(createEnvelope("req", id, name, data));
381
+ } catch (err) {
382
+ clearTimeout(pending.timer);
383
+ offMessage();
384
+ reject(err);
385
+ }
386
+ });
387
+ }
388
+ function emitForBridge(bridge, nameOrCalls, dataOrOptions, options) {
389
+ if (typeof nameOrCalls === "string") {
390
+ return emitOne(
391
+ bridge,
392
+ nameOrCalls,
393
+ dataOrOptions,
394
+ options
395
+ );
396
+ }
397
+ const batchOptions = dataOrOptions ?? {};
398
+ if (isInvokeGroups(nameOrCalls)) {
399
+ const outerMode = batchOptions.mode ?? "serial";
400
+ const runGroup = (group) => runInvokeCalls(bridge, group.calls, group.mode ?? "serial", batchOptions);
401
+ if (outerMode === "parallel") {
402
+ return settleParallel(nameOrCalls.map(runGroup));
403
+ }
404
+ return (async () => {
405
+ const results = [];
406
+ for (const group of nameOrCalls) {
407
+ results.push(await runGroup(group));
408
+ }
409
+ return results;
410
+ })();
411
+ }
412
+ return runInvokeCalls(bridge, nameOrCalls, batchOptions.mode ?? "serial", batchOptions);
413
+ }
414
+
415
+ // ../iframe-bridge/src/libs/handle.ts
416
+ function safeReply(bridge, message) {
417
+ try {
418
+ bridge.postMessage(message);
419
+ } catch (err) {
420
+ if (err instanceof PlaycraftBridgeError && (err.code === BridgeErrorCodes.PEER_UNAVAILABLE || err.code === BridgeErrorCodes.DESTROYED)) {
421
+ return;
422
+ }
423
+ throw err;
424
+ }
425
+ }
426
+ function onForBridge(bridge, name, fn) {
427
+ return bridge.addEventListener("message", async (e) => {
428
+ const msg = e.data;
429
+ if (msg.kind !== "req" || msg.name !== name) return;
430
+ if (isEventName(name)) {
431
+ await fn(msg.data);
432
+ return;
433
+ }
434
+ try {
435
+ const data = await fn(msg.data, {
436
+ id: msg.id
437
+ });
438
+ safeReply(bridge, createSuccessResponse(msg.id, msg.name, data));
439
+ } catch (err) {
440
+ safeReply(bridge, createErrorResponse(msg.id, msg.name, toPlaycraftError(err)));
441
+ }
442
+ });
443
+ }
444
+
445
+ // ../iframe-bridge/src/libs/bridge.ts
446
+ var Bridge = class {
447
+ constructor(options) {
448
+ this.options = options;
449
+ this.targetOrigin = options.targetOrigin;
450
+ this.messageTarget = options.messageTarget ?? window;
451
+ this.messageTarget.addEventListener("message", this.onWindowMessage);
452
+ }
453
+ options;
454
+ targetOrigin;
455
+ listeners = /* @__PURE__ */ new Set();
456
+ warnedPeerVersions = /* @__PURE__ */ new Set();
457
+ destroyed = false;
458
+ messageTarget;
459
+ emit(nameOrCalls, dataOrOptions, options) {
460
+ return emitForBridge(this, nameOrCalls, dataOrOptions, options);
461
+ }
462
+ on(name, fn) {
463
+ return onForBridge(this, name, fn);
464
+ }
465
+ postMessage(message, targetOrigin = this.options.targetOrigin, transfer) {
466
+ this.assertAlive();
467
+ const peer = this.options.peer();
468
+ if (!peer) {
469
+ throw new PlaycraftBridgeError(
470
+ BridgeErrorCodes.PEER_UNAVAILABLE,
471
+ "[playcraft] peer window is not available"
472
+ );
473
+ }
474
+ this.log("send", message);
475
+ peer.postMessage(message, targetOrigin, transfer ?? []);
476
+ }
477
+ addEventListener(type, listener) {
478
+ this.assertAlive();
479
+ this.listeners.add(listener);
480
+ return () => this.listeners.delete(listener);
481
+ }
482
+ destroy() {
483
+ if (this.destroyed) return;
484
+ this.destroyed = true;
485
+ this.messageTarget.removeEventListener("message", this.onWindowMessage);
486
+ this.listeners.clear();
487
+ }
488
+ assertAlive() {
489
+ if (this.destroyed) {
490
+ throw new PlaycraftBridgeError(BridgeErrorCodes.DESTROYED, "[playcraft] bridge destroyed");
491
+ }
492
+ }
493
+ log(event, msg) {
494
+ const { debug, perspective } = this.options;
495
+ if (!debug) return;
496
+ if (typeof debug === "function") debug(event, msg);
497
+ else logBridgeDebug(perspective, event, msg);
498
+ }
499
+ warnVersionMismatch(localVersion, peerVersion) {
500
+ if (this.warnedPeerVersions.has(peerVersion)) return;
501
+ this.warnedPeerVersions.add(peerVersion);
502
+ console.warn(
503
+ `[playcraft] protocol version mismatch: local ${localVersion}, peer ${peerVersion}. Messages are still processed; align @playcraft/iframe-bridge versions when possible.`
504
+ );
505
+ }
506
+ onWindowMessage = (e) => {
507
+ const msgEvent = e;
508
+ if (this.destroyed || !this.options.allowedOrigins.includes(msgEvent.origin)) return;
509
+ if (this.options.strictSource) {
510
+ const peer = this.options.peer();
511
+ if (!peer || msgEvent.source !== peer) return;
512
+ }
513
+ if (!isPlaycraftEnvelope(msgEvent.data)) return;
514
+ const mismatch = getPlaycraftEnvelopeVersionMismatch(msgEvent.data);
515
+ if (mismatch) {
516
+ this.warnVersionMismatch(mismatch.local, mismatch.peer);
517
+ }
518
+ this.log("recv", msgEvent.data);
519
+ const event = {
520
+ data: msgEvent.data,
521
+ origin: msgEvent.origin,
522
+ source: msgEvent.source
523
+ };
524
+ this.listeners.forEach((fn) => fn(event));
525
+ };
526
+ };
527
+
528
+ // ../preview-runtime/src/protocol.ts
529
+ var MAX_IMAGE_RESOURCE_BYTES = 32 * 1024 * 1024;
530
+ var ResourceLoadError = class extends Error {
531
+ constructor(message) {
532
+ super(message);
533
+ this.name = "ResourceLoadError";
534
+ }
535
+ };
536
+ var SupersededResourceError = class extends Error {
537
+ constructor() {
538
+ super("A newer image value replaced this resource request");
539
+ this.name = "SupersededResourceError";
540
+ }
541
+ };
542
+ var ProtocolError = class extends Error {
543
+ constructor(code, message) {
544
+ super(message);
545
+ this.code = code;
546
+ this.name = "ProtocolError";
547
+ }
548
+ code;
549
+ };
550
+ var forbidden = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
551
+ var record = (value) => !!value && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
552
+ var exactKeys = (value, allowed) => {
553
+ if (Object.keys(value).some((key) => !allowed.includes(key)))
554
+ throw new ProtocolError("INVALID", "Unexpected message field");
555
+ };
556
+ var string = (v) => typeof v === "string" && v.length > 0 && v.length <= 1024;
557
+ var revision = (v) => Number.isSafeInteger(v) && v >= 0;
558
+ function assertJson(value, depth = 0) {
559
+ if (depth > 64) throw new ProtocolError("LIMIT", "Configuration nesting exceeds limit");
560
+ if (value === null || typeof value === "boolean" || typeof value === "string" || typeof value === "number" && Number.isFinite(value))
561
+ return;
562
+ if (Array.isArray(value)) {
563
+ for (const child of value) assertJson(child, depth + 1);
564
+ return;
565
+ }
566
+ if (record(value)) {
567
+ for (const [key, child] of Object.entries(value)) {
568
+ if (forbidden.has(key)) throw new ProtocolError("INVALID", "Unsafe configuration key");
569
+ assertJson(child, depth + 1);
570
+ }
571
+ return;
572
+ }
573
+ throw new ProtocolError("INVALID", "Configuration must contain finite JSON data");
574
+ }
575
+ function clone(value) {
576
+ return structuredClone(value);
577
+ }
578
+ function freeze(value) {
579
+ if (value && typeof value === "object") {
580
+ Object.freeze(value);
581
+ for (const child of Object.values(value)) freeze(child);
582
+ }
583
+ return value;
584
+ }
585
+ function fingerprint(value) {
586
+ if (Array.isArray(value)) return "[" + value.map(fingerprint).join(",") + "]";
587
+ if (record(value))
588
+ return "{" + Object.keys(value).sort().map((k) => JSON.stringify(k) + ":" + fingerprint(value[k])).join(",") + "}";
589
+ return JSON.stringify(value);
590
+ }
591
+ function assertHello(value) {
592
+ if (!record(value) || value.protocolVersion !== 1 || !string(value.sessionId) || !revision(value.frameEpoch) || !string(value.schemaVersion) || !string(value.configContractVersion) || !string(value.locale) || !record(value.scope))
593
+ throw new ProtocolError("IDENTITY", "Invalid runtime session binding");
594
+ if (!["projectId", "branchName", "themeId"].every(
595
+ (k) => string(value.scope[k])
596
+ ))
597
+ throw new ProtocolError("IDENTITY", "Invalid configuration scope");
598
+ exactKeys(value.scope, ["projectId", "branchName", "themeId"]);
599
+ }
600
+ function assertIdentity(value) {
601
+ assertHello(value);
602
+ if (!string(value.runtimeInstanceId))
603
+ throw new ProtocolError("IDENTITY", "Missing runtime instance");
604
+ }
605
+ function sameIdentity(a, b) {
606
+ try {
607
+ assertIdentity(b);
608
+ } catch {
609
+ return false;
610
+ }
611
+ return [
612
+ "protocolVersion",
613
+ "sessionId",
614
+ "frameEpoch",
615
+ "runtimeInstanceId",
616
+ "schemaVersion",
617
+ "configContractVersion",
618
+ "locale"
619
+ ].every((k) => a[k] === b[k]) && fingerprint(a.scope) === fingerprint(b.scope);
620
+ }
621
+ function assertBinding(expected, actual) {
622
+ if (fingerprint(expected.scope) !== fingerprint(actual.scope) || expected.locale !== actual.locale || expected.schemaVersion !== actual.schemaVersion || expected.configContractVersion !== actual.configContractVersion)
623
+ throw new ProtocolError("CONTRACT", "Scope, locale, schema or configuration contract mismatch");
624
+ }
625
+ function assertDocuments(value) {
626
+ assertJson(value);
627
+ if (!record(value) || Object.values(value).some((v) => !record(v)))
628
+ throw new ProtocolError("INVALID", "Expected raw document objects");
629
+ }
630
+ var identityKeys = [
631
+ "protocolVersion",
632
+ "sessionId",
633
+ "frameEpoch",
634
+ "runtimeInstanceId",
635
+ "scope",
636
+ "schemaVersion",
637
+ "configContractVersion",
638
+ "locale"
639
+ ];
640
+ function assertImageResourceData(value) {
641
+ if (!record(value) || typeof value.mimeType !== "string" || typeof value.dataUrl !== "string")
642
+ throw new ProtocolError("INVALID", "Invalid image resource response");
643
+ const allowed = ["image/png", "image/jpeg", "image/webp", "image/gif", "image/avif", "image/bmp"];
644
+ if (!allowed.includes(value.mimeType))
645
+ throw new ProtocolError("INVALID", "Unsupported image resource type");
646
+ const prefix = `data:${value.mimeType};base64,`;
647
+ const data = value.dataUrl.startsWith(prefix) ? value.dataUrl.slice(prefix.length) : "";
648
+ if (!data || data.length % 4 !== 0 || data.length > Math.ceil(MAX_IMAGE_RESOURCE_BYTES / 3) * 4 || !/^[A-Za-z0-9+/]+={0,2}$/.test(data))
649
+ throw new ProtocolError("LIMIT", "Invalid or oversized image resource data");
650
+ const bytes = data.length / 4 * 3 - (data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0);
651
+ if (bytes > MAX_IMAGE_RESOURCE_BYTES)
652
+ throw new ProtocolError("LIMIT", "Image resource exceeds the byte limit");
653
+ if (value.contentHash !== void 0 && !/^[a-f0-9]{64}$/.test(String(value.contentHash)))
654
+ throw new ProtocolError("INVALID", "Invalid image content fingerprint");
655
+ }
656
+ function assertSnapshot(value) {
657
+ assertIdentity(value);
658
+ exactKeys(value, [
659
+ ...identityKeys,
660
+ "draftRevision",
661
+ "documents"
662
+ ]);
663
+ if (!revision(value.draftRevision))
664
+ throw new ProtocolError("INVALID", "Invalid snapshot revision");
665
+ assertDocuments(value.documents);
666
+ limit(value, 512 * 1024);
667
+ }
668
+ function assertPatch(value) {
669
+ assertIdentity(value);
670
+ const v = value;
671
+ exactKeys(v, [
672
+ ...identityKeys,
673
+ "baseDraftRevision",
674
+ "draftRevision",
675
+ "phase",
676
+ "operations"
677
+ ]);
678
+ if (!revision(v.baseDraftRevision) || !revision(v.draftRevision) || v.draftRevision !== v.baseDraftRevision + 1 || !["preview", "commit"].includes(v.phase) || !Array.isArray(v.operations) || v.operations.length > 256)
679
+ throw new ProtocolError("INVALID", "Invalid patch sequence or operation count");
680
+ for (const op of v.operations) {
681
+ if (!record(op) || !["set", "remove"].includes(op.op) || !string(op.documentId) || forbidden.has(op.documentId) || !Array.isArray(op.path) || !op.path.length || op.path.length > 32 || op.path.some((p) => !string(p) || forbidden.has(p)))
682
+ throw new ProtocolError("INVALID", "Unsafe or invalid operation path");
683
+ exactKeys(
684
+ op,
685
+ op.op === "set" ? ["op", "documentId", "path", "value"] : ["op", "documentId", "path"]
686
+ );
687
+ if (op.op === "set") assertJson(op.value);
688
+ }
689
+ limit(v, 64 * 1024);
690
+ }
691
+ function limit(value, bytes) {
692
+ if (new TextEncoder().encode(JSON.stringify(value)).length > bytes)
693
+ throw new ProtocolError("LIMIT", "Runtime message exceeds byte limit");
694
+ }
695
+ function applyOperations(documents, operations) {
696
+ const next = clone(documents);
697
+ for (const op of operations) {
698
+ if (op.op === "remove" && readPath(next[op.documentId], op.path) === void 0) continue;
699
+ let target = next[op.documentId] ??= {};
700
+ for (const part of op.path.slice(0, -1)) {
701
+ if (!record(target[part])) target[part] = {};
702
+ target = target[part];
703
+ }
704
+ const key = op.path[op.path.length - 1];
705
+ if (op.op === "set") target[key] = clone(op.value);
706
+ else delete target[key];
707
+ }
708
+ return next;
709
+ }
710
+ function readPath(value, path) {
711
+ for (const key of path) {
712
+ if (!record(value) && !Array.isArray(value)) return void 0;
713
+ value = value[key];
714
+ }
715
+ return value;
716
+ }
717
+
718
+ // ../preview-runtime/src/runtime.ts
719
+ function createParameterRuntime(options) {
720
+ const runtimeInstanceId = crypto.randomUUID();
721
+ let identity;
722
+ let controller = new AbortController();
723
+ let queue = Promise.resolve();
724
+ let adapter;
725
+ let target;
726
+ let installed;
727
+ let receivedRevision = -1, installedRevision = -1, appliedRevision = -1;
728
+ let stage = "bootstrap-ready";
729
+ let status = "idle";
730
+ let error;
731
+ let disposed = false;
732
+ let cleanupFailure;
733
+ let recoverable = false;
734
+ const resourceErrors = /* @__PURE__ */ new Map();
735
+ let resultSequence = 0;
736
+ const retiredSessions = /* @__PURE__ */ new Set();
737
+ const groups = /* @__PURE__ */ new Map();
738
+ const receipts = /* @__PURE__ */ new Map();
739
+ const listeners = /* @__PURE__ */ new Set();
740
+ const capabilityListeners = /* @__PURE__ */ new Set();
741
+ async function release(game) {
742
+ try {
743
+ await game?.dispose();
744
+ } catch (e) {
745
+ cleanupFailure = e;
746
+ throw e;
747
+ }
748
+ }
749
+ for (const field of options.fields)
750
+ groups.set(field.groupId, { groupId: field.groupId, appliedRevision: -1, status: "unknown" });
751
+ const capabilities = () => ({
752
+ ...requireIdentity(),
753
+ stage,
754
+ canAcceptSnapshot: true,
755
+ fields: clone(options.fields)
756
+ });
757
+ function requireIdentity() {
758
+ if (!identity || disposed)
759
+ throw new ProtocolError("SESSION", "Runtime session is not connected");
760
+ return identity;
761
+ }
762
+ function check(value) {
763
+ assertIdentity(value);
764
+ if (!sameIdentity(requireIdentity(), value))
765
+ throw new ProtocolError("STALE", "Stale runtime identity");
766
+ }
767
+ const result = () => ({
768
+ ...requireIdentity(),
769
+ resultSequence,
770
+ receivedRevision,
771
+ installedRevision,
772
+ appliedRevision,
773
+ status,
774
+ groups: clone([...groups.values()]),
775
+ ...error ? { error } : {},
776
+ ...recoverable ? { recoverable: true } : {},
777
+ ...resourceErrors.size ? { resourceErrors: clone([...resourceErrors.values()]) } : {}
778
+ });
779
+ function publish() {
780
+ if (!identity || disposed) return;
781
+ resultSequence++;
782
+ const value = result();
783
+ listeners.forEach((fn) => fn(value));
784
+ }
785
+ function context(config, beforeConfig, draftRevision, fields, signal) {
786
+ const images = /* @__PURE__ */ new Map();
787
+ const assertCurrent = () => {
788
+ signal.throwIfAborted();
789
+ if (signal !== controller.signal || disposed)
790
+ throw new ProtocolError("STALE", "Application task expired");
791
+ if (images.size && target) {
792
+ const latest = options.resolve(target);
793
+ for (const { field, value } of images.values())
794
+ if (readPath(latest, field.effectivePath) !== value) throw new SupersededResourceError();
795
+ }
796
+ };
797
+ return {
798
+ config,
799
+ beforeConfig,
800
+ draftRevision,
801
+ fields,
802
+ signal,
803
+ assertCurrent,
804
+ async loadImage(field, value) {
805
+ const registered = options.fields.find(
806
+ (item) => item.resource === "image" && item.documentId === field.documentId && fingerprint(item.path) === fingerprint(field.path)
807
+ );
808
+ if (!registered || typeof value !== "string" || !value)
809
+ throw new ProtocolError("UNSUPPORTED", "Unregistered image resource field");
810
+ if (!options.loadImage)
811
+ throw new ProtocolError("UNSUPPORTED", "Image resource transport is unavailable");
812
+ const key = fingerprint([registered.documentId, registered.path]);
813
+ images.set(key, { field: registered, value });
814
+ assertCurrent();
815
+ try {
816
+ const image = await options.loadImage(
817
+ {
818
+ ...requireIdentity(),
819
+ draftRevision,
820
+ documentId: registered.documentId,
821
+ path: clone(registered.path),
822
+ value
823
+ },
824
+ signal
825
+ );
826
+ assertCurrent();
827
+ resourceErrors.delete(key);
828
+ return image;
829
+ } catch (failure) {
830
+ assertCurrent();
831
+ if (failure instanceof ResourceLoadError)
832
+ resourceErrors.set(key, {
833
+ documentId: registered.documentId,
834
+ path: clone(registered.path),
835
+ error: failure.message
836
+ });
837
+ throw failure;
838
+ }
839
+ }
840
+ };
841
+ }
842
+ function enqueue(work) {
843
+ const signal = controller.signal;
844
+ queue = queue.then(async () => {
845
+ if (signal.aborted) return;
846
+ try {
847
+ await work(signal);
848
+ } catch (e) {
849
+ if (signal.aborted) return;
850
+ if (e instanceof SupersededResourceError) return;
851
+ status = "error";
852
+ recoverable = e instanceof ResourceLoadError;
853
+ if (!recoverable) installedRevision = appliedRevision = -1;
854
+ error = e instanceof Error ? e.message : String(e);
855
+ for (const group of groups.values())
856
+ if (!recoverable || options.fields.some(
857
+ (field) => field.groupId === group.groupId && resourceErrors.has(fingerprint([field.documentId, field.path]))
858
+ ))
859
+ group.status = "unknown";
860
+ publish();
861
+ }
862
+ });
863
+ }
864
+ function remember(kind, request) {
865
+ const key = `${kind}:${request.draftRevision}`;
866
+ const previous = receipts.get(key);
867
+ if (previous) {
868
+ if (previous.fingerprint !== fingerprint(request))
869
+ throw new ProtocolError("CONFLICT", "Revision was already accepted with different content");
870
+ return previous.receipt;
871
+ }
872
+ return void 0;
873
+ }
874
+ function accept(kind, request) {
875
+ receivedRevision = request.draftRevision;
876
+ const receipt = { accepted: true, receivedRevision };
877
+ receipts.set(`${kind}:${receivedRevision}`, { fingerprint: fingerprint(request), receipt });
878
+ if (receipts.size > 256) receipts.delete(receipts.keys().next().value);
879
+ return receipt;
880
+ }
881
+ function updateState(rev, changed) {
882
+ const previousGroups = new Map(groups);
883
+ for (const field of changed)
884
+ groups.set(field.groupId, {
885
+ groupId: field.groupId,
886
+ appliedRevision: rev,
887
+ status: "applied"
888
+ });
889
+ if (resourceErrors.size) {
890
+ status = "error";
891
+ recoverable = true;
892
+ if (changed.length) installedRevision = appliedRevision = -1;
893
+ error = [...resourceErrors.values()].map((item) => item.error).join("; ");
894
+ for (const field of options.fields)
895
+ if (resourceErrors.has(fingerprint([field.documentId, field.path])))
896
+ groups.set(field.groupId, { ...previousGroups.get(field.groupId), status: "unknown" });
897
+ publish();
898
+ return;
899
+ }
900
+ recoverable = false;
901
+ error = void 0;
902
+ let pending = false, reload = false;
903
+ for (const field of options.fields) {
904
+ if (fingerprint(readPath(installed?.[field.documentId], field.path)) !== fingerprint(readPath(target?.[field.documentId], field.path))) {
905
+ const group = groups.get(field.groupId);
906
+ group.status = field.mode === "reload" ? "requires-reload" : "pending-commit";
907
+ pending = true;
908
+ reload ||= field.mode === "reload";
909
+ }
910
+ }
911
+ if (fingerprint(installed) === fingerprint(target)) {
912
+ appliedRevision = receivedRevision;
913
+ installedRevision = receivedRevision;
914
+ status = "applied";
915
+ } else status = reload ? "requires-reload" : pending ? "pending-commit" : "applying";
916
+ publish();
917
+ }
918
+ async function applyTarget(documents, rev, commit, signal, retryResources = /* @__PURE__ */ new Set()) {
919
+ if (status === "error" && !recoverable) return;
920
+ if (!adapter || !installed)
921
+ throw new ProtocolError("STATE", "Initial snapshot must create the game first");
922
+ const operations = [];
923
+ for (const field of options.fields) {
924
+ if (field.mode !== "live" && !(commit && field.mode === "restart-scene")) continue;
925
+ const resourceKey = fingerprint([field.documentId, field.path]);
926
+ if (resourceErrors.has(resourceKey) && !retryResources.has(resourceKey)) continue;
927
+ const value = readPath(documents[field.documentId], field.path);
928
+ operations.push(
929
+ value === void 0 ? { op: "remove", documentId: field.documentId, path: field.path } : {
930
+ op: "set",
931
+ documentId: field.documentId,
932
+ path: field.path,
933
+ value: clone(value)
934
+ }
935
+ );
936
+ }
937
+ const candidate = applyOperations(installed, operations);
938
+ const before = options.source.get();
939
+ const config = freeze(options.resolve(freeze(clone(candidate))));
940
+ const changed = options.fields.filter(
941
+ (field) => resourceErrors.has(fingerprint([field.documentId, field.path])) && retryResources.has(fingerprint([field.documentId, field.path])) && (field.mode === "live" || commit && field.mode === "restart-scene") || fingerprint(readPath(before, field.effectivePath)) !== fingerprint(readPath(config, field.effectivePath))
942
+ );
943
+ const ctx = context(config, before, rev, changed, signal);
944
+ ctx.assertCurrent();
945
+ status = "applying";
946
+ publish();
947
+ options.source.install(config);
948
+ const previousInstalledRevision = installedRevision;
949
+ installedRevision = fingerprint(candidate) === fingerprint(documents) ? rev : -1;
950
+ try {
951
+ if (changed.some((field) => field.mode === "restart-scene")) await adapter.restartScene(ctx);
952
+ else if (changed.length) await adapter.apply(ctx);
953
+ ctx.assertCurrent();
954
+ await adapter.afterRender(ctx);
955
+ ctx.assertCurrent();
956
+ for (const field of changed)
957
+ if (field.resource === "image" && readPath(config, field.effectivePath) === "")
958
+ resourceErrors.delete(fingerprint([field.documentId, field.path]));
959
+ installed = candidate;
960
+ updateState(rev, changed);
961
+ } catch (e) {
962
+ if (!signal.aborted) {
963
+ options.source.install(before);
964
+ installedRevision = previousInstalledRevision;
965
+ }
966
+ throw e;
967
+ }
968
+ }
969
+ return {
970
+ hello(value) {
971
+ assertHello(value);
972
+ assertBinding(options.binding, value);
973
+ if (disposed) throw new ProtocolError("DISPOSED", "Runtime endpoint is disposed");
974
+ if (retiredSessions.has(value.sessionId))
975
+ throw new ProtocolError("STALE", "Retired runtime session");
976
+ if (identity && value.sessionId === identity.sessionId && value.frameEpoch < identity.frameEpoch)
977
+ throw new ProtocolError("STALE", "Old frame epoch");
978
+ if (identity && fingerprint({ ...identity, runtimeInstanceId: void 0 }) === fingerprint({ ...value, runtimeInstanceId: void 0 }))
979
+ return capabilities();
980
+ if (identity && identity.sessionId !== value.sessionId)
981
+ retiredSessions.add(identity.sessionId);
982
+ controller.abort();
983
+ controller = new AbortController();
984
+ const previous = adapter;
985
+ adapter = void 0;
986
+ queue = queue.then(async () => {
987
+ await release(previous);
988
+ }).catch((e) => {
989
+ cleanupFailure = e;
990
+ });
991
+ identity = freeze({ ...clone(value), runtimeInstanceId });
992
+ target = installed = void 0;
993
+ receivedRevision = installedRevision = appliedRevision = -1;
994
+ receipts.clear();
995
+ stage = "bootstrap-ready";
996
+ status = "idle";
997
+ error = void 0;
998
+ recoverable = false;
999
+ resourceErrors.clear();
1000
+ resultSequence = 0;
1001
+ for (const group of groups.values()) {
1002
+ group.appliedRevision = -1;
1003
+ group.status = "unknown";
1004
+ }
1005
+ return capabilities();
1006
+ },
1007
+ snapshot(value) {
1008
+ assertSnapshot(value);
1009
+ check(value);
1010
+ const previous = remember("snapshot", value);
1011
+ if (previous) return previous;
1012
+ if (value.draftRevision < receivedRevision)
1013
+ throw new ProtocolError("STALE", "Old snapshot revision");
1014
+ if (value.draftRevision === receivedRevision && fingerprint(value.documents) !== fingerprint(target))
1015
+ throw new ProtocolError("CONFLICT", "Snapshot cannot change an already accepted revision");
1016
+ const rev = value.draftRevision;
1017
+ const documents = freeze(clone(value.documents));
1018
+ options.resolve(documents);
1019
+ target = documents;
1020
+ const receipt = accept("snapshot", value);
1021
+ enqueue(async (signal) => {
1022
+ if (cleanupFailure)
1023
+ throw new ProtocolError(
1024
+ "RECOVERY",
1025
+ "Previous game cleanup failed; reload the preview frame"
1026
+ );
1027
+ status = "applying";
1028
+ publish();
1029
+ const previousAdapter = adapter;
1030
+ adapter = void 0;
1031
+ stage = "bootstrap-ready";
1032
+ await release(previousAdapter);
1033
+ let nextDocuments = documents;
1034
+ let nextRevision = rev;
1035
+ for (; ; ) {
1036
+ const before = options.source.get();
1037
+ resourceErrors.clear();
1038
+ recoverable = false;
1039
+ const config = freeze(options.resolve(nextDocuments));
1040
+ const ctx = context(config, before, nextRevision, clone(options.fields), signal);
1041
+ ctx.assertCurrent();
1042
+ options.source.install(config);
1043
+ installedRevision = nextRevision;
1044
+ let created;
1045
+ try {
1046
+ created = await options.createGame(ctx);
1047
+ if (signal.aborted) {
1048
+ await release(created);
1049
+ return;
1050
+ }
1051
+ ctx.assertCurrent();
1052
+ adapter = created;
1053
+ stage = "game-ready";
1054
+ capabilityListeners.forEach((fn) => fn(capabilities()));
1055
+ await created.afterRender(ctx);
1056
+ ctx.assertCurrent();
1057
+ installed = clone(nextDocuments);
1058
+ if (resourceErrors.size) installedRevision = -1;
1059
+ error = void 0;
1060
+ updateState(nextRevision, options.fields);
1061
+ return;
1062
+ } catch (e) {
1063
+ if (!signal.aborted) {
1064
+ adapter = void 0;
1065
+ stage = "bootstrap-ready";
1066
+ options.source.install(before);
1067
+ capabilityListeners.forEach((fn) => fn(capabilities()));
1068
+ }
1069
+ await release(created);
1070
+ if (e instanceof SupersededResourceError && !signal.aborted && target) {
1071
+ nextDocuments = freeze(clone(target));
1072
+ nextRevision = receivedRevision;
1073
+ continue;
1074
+ }
1075
+ throw e;
1076
+ }
1077
+ }
1078
+ });
1079
+ return receipt;
1080
+ },
1081
+ patch(value) {
1082
+ assertPatch(value);
1083
+ check(value);
1084
+ const previous = remember("patch", value);
1085
+ if (previous) return previous;
1086
+ if (!target || value.baseDraftRevision !== receivedRevision)
1087
+ throw new ProtocolError("RESYNC", "Patch base does not match received revision");
1088
+ if (status === "error" && !recoverable)
1089
+ throw new ProtocolError(
1090
+ "RECOVERY",
1091
+ "Application state is unknown; send a recovery snapshot"
1092
+ );
1093
+ for (const op of value.operations)
1094
+ if (!options.fields.some(
1095
+ (field) => field.documentId === op.documentId && fingerprint(field.path) === fingerprint(op.path)
1096
+ ))
1097
+ throw new ProtocolError("UNSUPPORTED", "Unregistered parameter path");
1098
+ const documents = freeze(applyOperations(target, value.operations));
1099
+ const rev = value.draftRevision, commit = value.phase === "commit";
1100
+ options.resolve(documents);
1101
+ target = documents;
1102
+ const receipt = accept("patch", value);
1103
+ const retryResources = new Set(
1104
+ value.operations.length ? value.operations.map((operation) => fingerprint([operation.documentId, operation.path])) : options.fields.filter((field) => field.resource === "image").map((field) => fingerprint([field.documentId, field.path]))
1105
+ );
1106
+ enqueue((signal) => applyTarget(documents, rev, commit, signal, retryResources));
1107
+ return receipt;
1108
+ },
1109
+ restart(value) {
1110
+ check(value);
1111
+ if (status === "error" && !recoverable)
1112
+ throw new ProtocolError(
1113
+ "RECOVERY",
1114
+ "Application state is unknown; send a recovery snapshot"
1115
+ );
1116
+ const rev = value.draftRevision;
1117
+ if (rev !== receivedRevision || !target)
1118
+ throw new ProtocolError("STALE", "Restart must name the current target");
1119
+ const documents = clone(target);
1120
+ enqueue(
1121
+ (signal) => applyTarget(
1122
+ documents,
1123
+ rev,
1124
+ true,
1125
+ signal,
1126
+ new Set(
1127
+ options.fields.filter((field) => field.resource === "image").map((field) => fingerprint([field.documentId, field.path]))
1128
+ )
1129
+ )
1130
+ );
1131
+ return { accepted: true, receivedRevision };
1132
+ },
1133
+ status(value) {
1134
+ check(value);
1135
+ return result();
1136
+ },
1137
+ subscribe(fn) {
1138
+ listeners.add(fn);
1139
+ return () => listeners.delete(fn);
1140
+ },
1141
+ onCapabilities(fn) {
1142
+ capabilityListeners.add(fn);
1143
+ return () => capabilityListeners.delete(fn);
1144
+ },
1145
+ async settled() {
1146
+ await queue;
1147
+ },
1148
+ async dispose() {
1149
+ if (disposed) return;
1150
+ disposed = true;
1151
+ controller.abort();
1152
+ listeners.clear();
1153
+ capabilityListeners.clear();
1154
+ await queue;
1155
+ await adapter?.dispose();
1156
+ adapter = void 0;
1157
+ }
1158
+ };
1159
+ }
1160
+
1161
+ // ../preview-runtime/src/preview.ts
1162
+ function decodeImage(dataUrl, signal) {
1163
+ return new Promise((resolve, reject) => {
1164
+ signal.throwIfAborted();
1165
+ const image = new Image();
1166
+ const timer = setTimeout(
1167
+ () => finish(new ResourceLoadError("Image decoding timed out")),
1168
+ 15e3
1169
+ );
1170
+ const cleanup = () => {
1171
+ clearTimeout(timer);
1172
+ image.onload = image.onerror = null;
1173
+ signal.removeEventListener("abort", cancel);
1174
+ };
1175
+ const finish = (error) => {
1176
+ if (!error && (!Number.isSafeInteger(image.naturalWidth) || !Number.isSafeInteger(image.naturalHeight) || image.naturalWidth <= 0 || image.naturalHeight <= 0 || image.naturalWidth * image.naturalHeight > 32 * 1024 * 1024))
1177
+ error = new ResourceLoadError("Image dimensions exceed the pixel limit");
1178
+ cleanup();
1179
+ if (error) {
1180
+ image.src = "";
1181
+ reject(error);
1182
+ } else resolve(image);
1183
+ };
1184
+ const cancel = () => finish(signal.reason);
1185
+ signal.addEventListener("abort", cancel, { once: true });
1186
+ image.onerror = () => finish(new ResourceLoadError("Image decoding failed"));
1187
+ image.onload = () => {
1188
+ if (typeof image.decode !== "function") finish();
1189
+ };
1190
+ image.src = dataUrl;
1191
+ if (typeof image.decode === "function")
1192
+ void image.decode().then(
1193
+ () => finish(),
1194
+ () => finish(new ResourceLoadError("Image decoding failed"))
1195
+ );
1196
+ });
1197
+ }
1198
+ function readWorkspacePreviewContext(expectedContractVersion) {
1199
+ try {
1200
+ const mark = "playcraft-preview-storage:";
1201
+ if (!window.name.startsWith(mark)) throw new Error("Missing workspace context");
1202
+ const context = JSON.parse(window.name.slice(mark.length)).__playcraft_preview_context__;
1203
+ if (!context || typeof context.parentOrigin !== "string" || !context.binding)
1204
+ throw new Error("Missing workspace binding");
1205
+ const parent = new URL(context.parentOrigin);
1206
+ if (!["http:", "https:"].includes(parent.protocol) || parent.origin !== context.parentOrigin || parent.origin === "null")
1207
+ throw new Error("Invalid parent origin");
1208
+ const hello = {
1209
+ ...context.binding,
1210
+ protocolVersion: 1,
1211
+ sessionId: "workspace-context",
1212
+ frameEpoch: 0
1213
+ };
1214
+ assertHello(hello);
1215
+ if (context.binding.configContractVersion !== expectedContractVersion)
1216
+ throw new Error("Unexpected configuration contract");
1217
+ const profiles = document.querySelectorAll("script#playcraft-runtime-profile");
1218
+ if (profiles.length !== 1 || profiles[0].getAttribute("type") !== "application/json")
1219
+ throw new Error("Missing build profile");
1220
+ const profile = JSON.parse(profiles[0].textContent ?? "");
1221
+ if (profile.version !== 1 || profile.protocolVersion !== 1 || profile.target !== "editor-static")
1222
+ throw new Error("Invalid build profile");
1223
+ assertBinding(profile.binding, hello);
1224
+ return freeze(
1225
+ clone({ binding: context.binding, parentOrigin: parent.origin })
1226
+ );
1227
+ } catch (error) {
1228
+ throw new ProtocolError(
1229
+ "CONTEXT",
1230
+ error instanceof Error ? error.message : "Invalid workspace preview context"
1231
+ );
1232
+ }
1233
+ }
1234
+ function connectPreviewRuntime(options) {
1235
+ const origin = new URL(options.parentOrigin).origin;
1236
+ if (origin === "null" || options.parentOrigin !== origin)
1237
+ throw new ProtocolError("ORIGIN", "An exact parent origin is required");
1238
+ const bridge = new Bridge({
1239
+ peer: () => window.parent,
1240
+ targetOrigin: origin,
1241
+ allowedOrigins: [origin],
1242
+ strictSource: true
1243
+ });
1244
+ const names = BridgeMethods.runtimeParameters;
1245
+ const runtime = createParameterRuntime({
1246
+ ...options,
1247
+ async loadImage(request, signal) {
1248
+ const value = await bridge.emit(names.asset, request, { timeout: 16e3, signal });
1249
+ if (!sameIdentity(request, value))
1250
+ throw new ProtocolError("STALE", "Image response belongs to a different runtime");
1251
+ const response = value;
1252
+ if (response.draftRevision !== request.draftRevision || response.documentId !== request.documentId || fingerprint(response.path) !== fingerprint(request.path) || response.value !== request.value)
1253
+ throw new ProtocolError("STALE", "Image response does not match its request");
1254
+ if (response.status === "stale") throw new SupersededResourceError();
1255
+ if (response.status === "failed") {
1256
+ if (typeof response.error !== "string")
1257
+ throw new ProtocolError("INVALID", "Invalid image failure response");
1258
+ throw new ResourceLoadError(response.error);
1259
+ }
1260
+ if (response.status !== "ready")
1261
+ throw new ProtocolError("INVALID", "Invalid image resource response");
1262
+ assertImageResourceData(response);
1263
+ return decodeImage(response.dataUrl, signal);
1264
+ }
1265
+ });
1266
+ const off = [
1267
+ bridge.on(names.hello, (value) => runtime.hello(value)),
1268
+ bridge.on(names.snapshot, (value) => runtime.snapshot(value)),
1269
+ bridge.on(names.patch, (value) => {
1270
+ try {
1271
+ return runtime.patch(value);
1272
+ } catch (error) {
1273
+ if (error instanceof ProtocolError && error.code === "RESYNC")
1274
+ void bridge.emit(
1275
+ names.resyncRequired,
1276
+ { ...runtime.status(value), reason: error.message },
1277
+ { timeout: 1e3 }
1278
+ ).catch(() => {
1279
+ });
1280
+ throw error;
1281
+ }
1282
+ }),
1283
+ bridge.on(names.restart, (value) => runtime.restart(value)),
1284
+ bridge.on(names.status, (value) => runtime.status(value)),
1285
+ bridge.on(names.dispose, async (value) => {
1286
+ runtime.status(value);
1287
+ await runtime.dispose();
1288
+ return { disposed: true };
1289
+ }),
1290
+ runtime.subscribe((value) => {
1291
+ void bridge.emit(names.result, value, { timeout: 1e3 }).catch(() => {
1292
+ });
1293
+ }),
1294
+ runtime.onCapabilities((value) => {
1295
+ void bridge.emit(names.capabilities, value, { timeout: 1e3 }).catch(() => {
1296
+ });
1297
+ })
1298
+ ];
1299
+ return {
1300
+ runtime,
1301
+ async dispose() {
1302
+ off.forEach((fn) => fn());
1303
+ bridge.destroy();
1304
+ await runtime.dispose();
1305
+ }
1306
+ };
1307
+ }
1308
+ export {
1309
+ ResourceLoadError,
1310
+ connectPreviewRuntime,
1311
+ readWorkspacePreviewContext
1312
+ };