@playcraft/cli 0.1.53-beta → 0.1.54

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