@playcraft/cli 0.1.40-beta → 0.1.41-prod

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 (368) hide show
  1. package/README.md +3 -58
  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/image.js +6 -2
  8. package/dist/commands/login.js +42 -84
  9. package/dist/commands/skills.js +0 -4
  10. package/dist/commands/tools-3d.js +0 -11
  11. package/dist/commands/tools-generation.js +137 -69
  12. package/dist/commands/tools-image-context.js +29 -0
  13. package/dist/commands/tools-utils.js +12 -0
  14. package/dist/commands/tools.js +2 -2
  15. package/dist/config.js +4 -59
  16. package/dist/index.js +3 -40
  17. package/dist/remix/clone.js +0 -2
  18. package/dist/remix/init-template.js +0 -2
  19. package/dist/remix/pull.js +0 -2
  20. package/dist/remix/push.js +1 -21
  21. package/dist/utils/agent-api-client.js +30 -185
  22. package/dist/utils/image-asset-context.js +228 -0
  23. package/dist/utils/playcraft-http-client.js +4 -6
  24. package/package.json +3 -13
  25. package/project-template/.claude/agents/refs/ta-image-generation-detail.md +67 -123
  26. package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +135 -63
  27. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +42 -33
  28. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +18 -20
  29. package/project-template/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +6 -7
  30. package/project-template/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +39 -39
  31. package/project-templates/phaser/.claude/agents/refs/ta-image-generation-detail.md +59 -59
  32. package/project-templates/phaser/.claude/skills/playcraft-image-generation/SKILL.md +135 -63
  33. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +42 -33
  34. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +18 -20
  35. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +6 -7
  36. package/project-templates/phaser/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +39 -39
  37. package/project-templates/threejs/.claude/agents/refs/ta-image-generation-detail.md +59 -59
  38. package/project-templates/threejs/.claude/skills/playcraft-image-generation/SKILL.md +135 -63
  39. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +42 -33
  40. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +18 -20
  41. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +6 -7
  42. package/project-templates/threejs/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +39 -39
  43. package/SKILLS_REGISTRY.md +0 -149
  44. package/dist/auth/account-activation.js +0 -157
  45. package/dist/auth/messages.js +0 -30
  46. package/dist/commands/build-temp.js +0 -26
  47. package/dist/commands/platform-skills.generated.js +0 -19
  48. package/dist/commands/playable.js +0 -53
  49. package/dist/commands/tools-batch.js +0 -87
  50. package/dist/commands/video.js +0 -111
  51. package/dist/commands/workspace-runtime.js +0 -54
  52. package/dist/commands/workspace.js +0 -35
  53. package/dist/project-skills/builtin-import.js +0 -225
  54. package/dist/project-skills/commands.js +0 -77
  55. package/dist/project-skills/lifecycle.js +0 -28
  56. package/dist/project-skills/local-run.js +0 -112
  57. package/dist/project-skills/local-store.js +0 -221
  58. package/dist/project-skills/messages.js +0 -80
  59. package/dist/project-skills/reconcile.js +0 -62
  60. package/dist/project-skills/remote-cache.js +0 -51
  61. package/dist/project-skills/validation.js +0 -19
  62. package/dist/recording/messages.js +0 -40
  63. package/dist/recording/project-digest.js +0 -85
  64. package/dist/recording/recorder.js +0 -293
  65. package/dist/recording/scenario.js +0 -50
  66. package/dist/skill-registry/client.js +0 -345
  67. package/dist/skill-registry/commands.js +0 -180
  68. package/dist/skill-registry/evaluation-client.js +0 -156
  69. package/dist/skill-registry/evaluation-commands.js +0 -174
  70. package/dist/skill-registry/messages.js +0 -177
  71. package/dist/skill-registry/package.js +0 -275
  72. package/dist/skill-registry/platform-package.js +0 -100
  73. package/dist/utils/environment-endpoints.js +0 -17
  74. package/dist/utils/tool-operation-journal.js +0 -124
  75. package/dist/utils/video-evidence-git.js +0 -81
  76. package/dist/video-replication/client.js +0 -222
  77. package/dist/video-replication/comparison-evidence.js +0 -149
  78. package/dist/video-replication/comparison-files.js +0 -57
  79. package/dist/video-replication/comparison-log.js +0 -72
  80. package/dist/video-replication/comparison-messages.js +0 -104
  81. package/dist/video-replication/comparison-output.js +0 -63
  82. package/dist/video-replication/comparison-preflight.js +0 -66
  83. package/dist/video-replication/comparison.js +0 -216
  84. package/dist/video-replication/evidence.js +0 -165
  85. package/dist/video-replication/media.js +0 -111
  86. package/dist/video-replication/messages.js +0 -89
  87. package/dist/workspace/messages.js +0 -35
  88. package/dist/workspace/transfer-client.js +0 -174
  89. package/dist/workspace-runtime/codex/app-server.js +0 -1040
  90. package/dist/workspace-runtime/codex/compact.js +0 -46
  91. package/dist/workspace-runtime/codex/config-toml.js +0 -107
  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 -70
  99. package/dist/workspace-runtime/codex/thread-image.js +0 -38
  100. package/dist/workspace-runtime/codex/ui-instructions.js +0 -4
  101. package/dist/workspace-runtime/codex/ui-tools.js +0 -183
  102. package/dist/workspace-runtime/codex/work-mode.js +0 -15
  103. package/dist/workspace-runtime/main.js +0 -10
  104. package/dist/workspace-runtime/persistence/journal.js +0 -365
  105. package/dist/workspace-runtime/persistence/native-subagents.js +0 -162
  106. package/dist/workspace-runtime/persistence/sqlite-client.js +0 -77
  107. package/dist/workspace-runtime/persistence/sqlite-worker.js +0 -1161
  108. package/dist/workspace-runtime/persistence/stopped-execution.js +0 -77
  109. package/dist/workspace-runtime/previews/output.js +0 -36
  110. package/dist/workspace-runtime/previews/publish.js +0 -262
  111. package/dist/workspace-runtime/previews/single-file.js +0 -43
  112. package/dist/workspace-runtime/processes/managed-writes.js +0 -69
  113. package/dist/workspace-runtime/production/content-changes.js +0 -36
  114. package/dist/workspace-runtime/production/contracts.js +0 -19
  115. package/dist/workspace-runtime/production/controller.js +0 -218
  116. package/dist/workspace-runtime/production/dependencies.js +0 -60
  117. package/dist/workspace-runtime/production/native.js +0 -212
  118. package/dist/workspace-runtime/production/processes.js +0 -102
  119. package/dist/workspace-runtime/production/save-command.js +0 -35
  120. package/dist/workspace-runtime/production/source-archive.js +0 -137
  121. package/dist/workspace-runtime/production/source-copy.js +0 -91
  122. package/dist/workspace-runtime/production/stages.js +0 -334
  123. package/dist/workspace-runtime/production/storage.js +0 -75
  124. package/dist/workspace-runtime/serve.js +0 -214
  125. package/dist/workspace-runtime/server/auth.js +0 -21
  126. package/dist/workspace-runtime/server/connectivity.js +0 -201
  127. package/dist/workspace-runtime/server/desktop-host.js +0 -429
  128. package/dist/workspace-runtime/server/desktop-preview-config.js +0 -81
  129. package/dist/workspace-runtime/server/desktop-preview-service.js +0 -157
  130. package/dist/workspace-runtime/server/desktop-preview-static.js +0 -53
  131. package/dist/workspace-runtime/server/desktop-preview.js +0 -189
  132. package/dist/workspace-runtime/server/dispatch.js +0 -1217
  133. package/dist/workspace-runtime/server/endpoints.js +0 -21
  134. package/dist/workspace-runtime/server/execution-group.js +0 -90
  135. package/dist/workspace-runtime/server/http.js +0 -1243
  136. package/dist/workspace-runtime/server/lock.js +0 -53
  137. package/dist/workspace-runtime/server/rfb-watch-gate.js +0 -168
  138. package/dist/workspace-runtime/server/source-uploader.js +0 -138
  139. package/dist/workspace-runtime/server/terminal-host.js +0 -366
  140. package/dist/workspace-runtime/server/types.js +0 -1
  141. package/dist/workspace-runtime/server/workspace-transfer.js +0 -99
  142. package/dist/workspace-runtime/workspaces/archive.js +0 -207
  143. package/dist/workspace-runtime/workspaces/artifact-events.js +0 -55
  144. package/dist/workspace-runtime/workspaces/artifact-files.js +0 -197
  145. package/dist/workspace-runtime/workspaces/artifact-receipts.js +0 -89
  146. package/dist/workspace-runtime/workspaces/artifacts.js +0 -282
  147. package/dist/workspace-runtime/workspaces/attachment-content.js +0 -123
  148. package/dist/workspace-runtime/workspaces/attachments.js +0 -185
  149. package/dist/workspace-runtime/workspaces/batch-commit.js +0 -142
  150. package/dist/workspace-runtime/workspaces/cli-context.js +0 -23
  151. package/dist/workspace-runtime/workspaces/cli-credentials.js +0 -111
  152. package/dist/workspace-runtime/workspaces/composer-context.js +0 -147
  153. package/dist/workspace-runtime/workspaces/context-error.js +0 -2
  154. package/dist/workspace-runtime/workspaces/dependencies.js +0 -264
  155. package/dist/workspace-runtime/workspaces/developer-command.js +0 -64
  156. package/dist/workspace-runtime/workspaces/directories.js +0 -133
  157. package/dist/workspace-runtime/workspaces/directory-access.js +0 -37
  158. package/dist/workspace-runtime/workspaces/directory-attachments.js +0 -245
  159. package/dist/workspace-runtime/workspaces/directory-maintenance.js +0 -111
  160. package/dist/workspace-runtime/workspaces/directory-stats.js +0 -49
  161. package/dist/workspace-runtime/workspaces/disk-snapshot.js +0 -31
  162. package/dist/workspace-runtime/workspaces/empty-template.js +0 -42
  163. package/dist/workspace-runtime/workspaces/files-search.js +0 -116
  164. package/dist/workspace-runtime/workspaces/files.js +0 -138
  165. package/dist/workspace-runtime/workspaces/git-credential-broker.js +0 -312
  166. package/dist/workspace-runtime/workspaces/git-credential-helper.js +0 -68
  167. package/dist/workspace-runtime/workspaces/git-direct-store.js +0 -155
  168. package/dist/workspace-runtime/workspaces/git.js +0 -670
  169. package/dist/workspace-runtime/workspaces/instructions.js +0 -56
  170. package/dist/workspace-runtime/workspaces/json5-edit.js +0 -170
  171. package/dist/workspace-runtime/workspaces/library-attachments.js +0 -268
  172. package/dist/workspace-runtime/workspaces/optional-platform-skills.js +0 -14
  173. package/dist/workspace-runtime/workspaces/parameters.js +0 -272
  174. package/dist/workspace-runtime/workspaces/prepare.js +0 -278
  175. package/dist/workspace-runtime/workspaces/registry.js +0 -251
  176. package/dist/workspace-runtime/workspaces/remix-references.js +0 -301
  177. package/dist/workspace-runtime/workspaces/revisions.js +0 -31
  178. package/dist/workspace-runtime/workspaces/session-image.js +0 -104
  179. package/dist/workspace-runtime/workspaces/shared-git.js +0 -40
  180. package/dist/workspace-runtime/workspaces/skill-artifact-loader.js +0 -95
  181. package/dist/workspace-runtime/workspaces/skills.js +0 -191
  182. package/dist/workspace-runtime/workspaces/transfer.js +0 -288
  183. package/dist/workspace-runtime/workspaces/turn-changes.js +0 -75
  184. package/dist/workspace-runtime/workspaces/video-attachments.js +0 -49
  185. package/project-template/.claude/skills/playcraft-replica-validation/SKILL.md +0 -25
  186. package/project-template/.claude/skills/playcraft-replica-validation/references/contracts.md +0 -79
  187. package/project-template/.claude/skills/playcraft-video-understanding/SKILL.md +0 -29
  188. package/project-template/.claude/skills/playcraft-video-understanding/references/contracts.md +0 -37
  189. package/project-template-v2/.claude/agents/artist.md +0 -82
  190. package/project-template-v2/.claude/agents/developer.md +0 -153
  191. package/project-template-v2/.claude/agents/game-designer.md +0 -264
  192. package/project-template-v2/.claude/agents/refs/artist-art-style-catalog.md +0 -533
  193. package/project-template-v2/.claude/agents/refs/artist-color-audio-recipes.md +0 -153
  194. package/project-template-v2/.claude/agents/refs/artist-dimension-axis.md +0 -27
  195. package/project-template-v2/.claude/agents/refs/artist-master-composite-recipes.md +0 -208
  196. package/project-template-v2/.claude/agents/refs/atom-skill-library.md +0 -81
  197. package/project-template-v2/.claude/agents/refs/developer-impl-cookbook.md +0 -432
  198. package/project-template-v2/.claude/agents/refs/framework-5-component-filter.md +0 -252
  199. package/project-template-v2/.claude/agents/refs/framework-game-feel-juice.md +0 -266
  200. package/project-template-v2/.claude/agents/refs/framework-mda.md +0 -147
  201. package/project-template-v2/.claude/agents/refs/game-designer-gameplay-sufficiency.md +0 -123
  202. package/project-template-v2/.claude/agents/refs/ta-3d-flip-recipe.md +0 -88
  203. package/project-template-v2/.claude/agents/refs/ta-atlas-deliverable-standard.md +0 -67
  204. package/project-template-v2/.claude/agents/refs/ta-batch-pipeline-recipes.md +0 -120
  205. package/project-template-v2/.claude/agents/refs/ta-image-generation-detail.md +0 -300
  206. package/project-template-v2/.claude/agents/refs/ta-image-ops-reference.md +0 -495
  207. package/project-template-v2/.claude/agents/refs/ta-pipeline-cookbook.md +0 -1141
  208. package/project-template-v2/.claude/agents/refs/ta-tools-reference.md +0 -111
  209. package/project-template-v2/.claude/agents/refs/ta-vfx-preset-catalog.md +0 -365
  210. package/project-template-v2/.claude/agents/refs/threejs-cannon-pitfalls.md +0 -412
  211. package/project-template-v2/.claude/agents/reviewer.md +0 -75
  212. package/project-template-v2/.claude/agents/technical-artist.md +0 -86
  213. package/project-template-v2/.claude/hooks/snapshot-milestone.mjs +0 -243
  214. package/project-template-v2/.claude/hooks/user-prompt.mjs +0 -133
  215. package/project-template-v2/.claude/settings.json +0 -33
  216. package/project-template-v2/.claude/skills/brainstorming/SKILL.md +0 -161
  217. package/project-template-v2/.claude/skills/brainstorming/scripts/frame-template.html +0 -270
  218. package/project-template-v2/.claude/skills/brainstorming/scripts/helper.js +0 -177
  219. package/project-template-v2/.claude/skills/brainstorming/scripts/server.cjs +0 -354
  220. package/project-template-v2/.claude/skills/brainstorming/scripts/start-server.sh +0 -148
  221. package/project-template-v2/.claude/skills/brainstorming/scripts/stop-server.sh +0 -56
  222. package/project-template-v2/.claude/skills/brainstorming/scripts/wait-for-selection.sh +0 -62
  223. package/project-template-v2/.claude/skills/brainstorming/spec-document-reviewer-prompt.md +0 -49
  224. package/project-template-v2/.claude/skills/brainstorming/visual-companion.md +0 -309
  225. package/project-template-v2/.claude/skills/playcraft-ad-psychology/SKILL.md +0 -182
  226. package/project-template-v2/.claude/skills/playcraft-art-style-guide/SKILL.md +0 -123
  227. package/project-template-v2/.claude/skills/playcraft-asset-state-sheet/SKILL.md +0 -205
  228. package/project-template-v2/.claude/skills/playcraft-audio-generation/SKILL.md +0 -280
  229. package/project-template-v2/.claude/skills/playcraft-batch-pipeline/SKILL.md +0 -184
  230. package/project-template-v2/.claude/skills/playcraft-build-optimizer/SKILL.md +0 -306
  231. package/project-template-v2/.claude/skills/playcraft-image-generation/SKILL.md +0 -298
  232. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +0 -123
  233. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +0 -254
  234. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +0 -324
  235. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +0 -97
  236. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +0 -118
  237. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +0 -137
  238. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +0 -397
  239. package/project-template-v2/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +0 -296
  240. package/project-template-v2/.claude/skills/playcraft-image-ops/SKILL.md +0 -122
  241. package/project-template-v2/.claude/skills/playcraft-image-processing/SKILL.md +0 -219
  242. package/project-template-v2/.claude/skills/playcraft-masking/SKILL.md +0 -373
  243. package/project-template-v2/.claude/skills/playcraft-playable-optimization/SKILL.md +0 -161
  244. package/project-template-v2/.claude/skills/playcraft-research/SKILL.md +0 -215
  245. package/project-template-v2/.claude/skills/playcraft-skill-recommender/SKILL.md +0 -382
  246. package/project-template-v2/.claude/skills/playcraft-sprite-generation/SKILL.md +0 -423
  247. package/project-template-v2/.claude/skills/playcraft-sprite-remix/SKILL.md +0 -158
  248. package/project-template-v2/.claude/skills/playcraft-sprite-sheet/SKILL.md +0 -100
  249. package/project-template-v2/.claude/skills/playcraft-storyboard/SKILL.md +0 -167
  250. package/project-template-v2/.claude/skills/playcraft-style-qa/SKILL.md +0 -270
  251. package/project-template-v2/.claude/skills/playcraft-text-rendering/SKILL.md +0 -236
  252. package/project-template-v2/.claude/skills/playcraft-vfx-animation/SKILL.md +0 -130
  253. package/project-template-v2/.claude/skills/playwright-cli/SKILL.md +0 -390
  254. package/project-template-v2/.claude/skills/playwright-cli/references/element-attributes.md +0 -23
  255. package/project-template-v2/.claude/skills/playwright-cli/references/playwright-tests.md +0 -39
  256. package/project-template-v2/.claude/skills/playwright-cli/references/request-mocking.md +0 -87
  257. package/project-template-v2/.claude/skills/playwright-cli/references/running-code.md +0 -240
  258. package/project-template-v2/.claude/skills/playwright-cli/references/session-management.md +0 -226
  259. package/project-template-v2/.claude/skills/playwright-cli/references/spec-driven-testing.md +0 -308
  260. package/project-template-v2/.claude/skills/playwright-cli/references/storage-state.md +0 -275
  261. package/project-template-v2/.claude/skills/playwright-cli/references/test-generation.md +0 -134
  262. package/project-template-v2/.claude/skills/playwright-cli/references/tracing.md +0 -142
  263. package/project-template-v2/.claude/skills/playwright-cli/references/video-recording.md +0 -153
  264. package/project-template-v2/.claude/skills/session-analyzer/SKILL.md +0 -386
  265. package/project-template-v2/.claude/skills/session-analyzer/scripts/execution-breakdown.mjs +0 -182
  266. package/project-template-v2/.claude/skills/session-analyzer/scripts/find-turns.mjs +0 -72
  267. package/project-template-v2/.claude/skills/session-analyzer/scripts/heavy-output.mjs +0 -121
  268. package/project-template-v2/.claude/skills/session-analyzer/scripts/resolve-session.mjs +0 -102
  269. package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-stats.mjs +0 -127
  270. package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-tool-timeline.mjs +0 -106
  271. package/project-template-v2/.claude/skills/session-analyzer/scripts/time-gaps.mjs +0 -128
  272. package/project-template-v2/.claude/skills/session-analyzer/scripts/turn-timeline.mjs +0 -67
  273. package/project-template-v2/.claude/snapshot.mjs +0 -263
  274. package/project-template-v2/.playcraft/skills.lock.json +0 -152
  275. package/project-template-v2/CLAUDE.md +0 -146
  276. package/project-template-v2/assets/audio/bgm/.gitkeep +0 -0
  277. package/project-template-v2/assets/audio/sfx/.gitkeep +0 -0
  278. package/project-template-v2/assets/bundles/.gitkeep +0 -0
  279. package/project-template-v2/assets/images/bg/.gitkeep +0 -0
  280. package/project-template-v2/assets/images/reference/.gitkeep +0 -0
  281. package/project-template-v2/assets/images/storyboard/.gitkeep +0 -0
  282. package/project-template-v2/assets/images/tiles/.gitkeep +0 -0
  283. package/project-template-v2/assets/images/ui/.gitkeep +0 -0
  284. package/project-template-v2/assets/images/vfx/.gitkeep +0 -0
  285. package/project-template-v2/assets/models/.gitkeep +0 -0
  286. package/project-template-v2/docs/harness/iteration-1/context-flow.md +0 -254
  287. package/project-template-v2/docs/harness/iteration-1/generate-flow.md +0 -91
  288. package/project-template-v2/docs/harness/iteration-1/ideate-flow.md +0 -214
  289. package/project-template-v2/docs/harness/iteration-1/optimize-flow.md +0 -75
  290. package/project-template-v2/docs/harness/iteration-1/wrapup-flow.md +0 -63
  291. package/project-template-v2/docs/harness/iteration-2/context-flow.md +0 -223
  292. package/project-template-v2/docs/harness/iteration-2/generate-flow.md +0 -129
  293. package/project-template-v2/docs/harness/iteration-2/ideate-flow.md +0 -267
  294. package/project-template-v2/docs/harness/iteration-2/optimize-flow.md +0 -164
  295. package/project-template-v2/docs/harness/iteration-2/wrapup-flow.md +0 -115
  296. package/project-template-v2/docs/harness/orchestrator-flow.md +0 -364
  297. package/project-template-v2/docs/project-state.json +0 -60
  298. package/project-template-v2/docs/project-state.md +0 -72
  299. package/project-template-v2/docs/standards/README.md +0 -225
  300. package/project-template-v2/docs/standards/agent-behavior-standards.md +0 -174
  301. package/project-template-v2/docs/standards/artifacts/design-brief.md +0 -19
  302. package/project-template-v2/docs/standards/artifacts/design.md +0 -22
  303. package/project-template-v2/docs/standards/artifacts/game-code.md +0 -41
  304. package/project-template-v2/docs/standards/artifacts/todo-list.md +0 -41
  305. package/project-template-v2/docs/standards/iter1-agent-behavior-standards.md +0 -343
  306. package/project-template-v2/game/index.ts +0 -18
  307. package/project-template-v2/globals.d.ts +0 -51
  308. package/project-template-v2/index.css +0 -34
  309. package/project-template-v2/index.html +0 -18
  310. package/project-template-v2/main.ts +0 -9
  311. package/project-template-v2/package.json +0 -46
  312. package/project-template-v2/skills/_shared/scripts/dispatch-clear.mjs +0 -31
  313. package/project-template-v2/skills/_shared/scripts/dispatch-set.mjs +0 -86
  314. package/project-template-v2/skills/_shared/scripts/dod-check.mjs +0 -153
  315. package/project-template-v2/skills/_shared/scripts/handoff-append.mjs +0 -70
  316. package/project-template-v2/skills/_shared/scripts/lib/validator-artifacts.mjs +0 -91
  317. package/project-template-v2/skills/_shared/scripts/pipeline/dod-config.mjs +0 -131
  318. package/project-template-v2/skills/_shared/scripts/pipeline/index.mjs +0 -80
  319. package/project-template-v2/skills/_shared/scripts/pipeline/iteration-1-core.mjs +0 -90
  320. package/project-template-v2/skills/_shared/scripts/pipeline/iteration-2-wrap.mjs +0 -93
  321. package/project-template-v2/skills/_shared/scripts/pipeline/iteration-3-visual.mjs +0 -23
  322. package/project-template-v2/skills/_shared/scripts/render-project-state.mjs +0 -230
  323. package/project-template-v2/skills/_shared/scripts/state-advance-stage.mjs +0 -58
  324. package/project-template-v2/skills/_shared/scripts/state-get.mjs +0 -339
  325. package/project-template-v2/skills/_shared/scripts/state-handoff.mjs +0 -39
  326. package/project-template-v2/skills/_shared/scripts/state-set.mjs +0 -94
  327. package/project-template-v2/skills/_shared/scripts/state-store.mjs +0 -783
  328. package/project-template-v2/skills/_shared/scripts/todo-add.mjs +0 -88
  329. package/project-template-v2/skills/_shared/scripts/todo-get.mjs +0 -130
  330. package/project-template-v2/skills/_shared/scripts/todo-remove.mjs +0 -33
  331. package/project-template-v2/skills/_shared/scripts/todo-set.mjs +0 -47
  332. package/project-template-v2/skills/_shared/scripts/verify-asset-code-sync.mjs +0 -268
  333. package/project-template-v2/skills/_shared/scripts/verify-env.mjs +0 -285
  334. package/project-template-v2/skills/_shared/scripts/verify-placeholders.mjs +0 -161
  335. package/project-template-v2/skills/playable-autoplay/SKILL.md +0 -176
  336. package/project-template-v2/skills/playable-autoplay/agents/openai.yaml +0 -4
  337. package/project-template-v2/skills/playable-debug/SKILL.md +0 -116
  338. package/project-template-v2/skills/playable-debug/agents/openai.yaml +0 -4
  339. package/project-template-v2/skills/playable-debug/references/debug-config.md +0 -40
  340. package/project-template-v2/skills/playable-record/SKILL.md +0 -140
  341. package/project-template-v2/skills/playable-record/scripts/lib/dev-server.mjs +0 -104
  342. package/project-template-v2/skills/playable-record/scripts/lib/record-audio-bridge.js +0 -141
  343. package/project-template-v2/skills/playable-record/scripts/record-playable.mjs +0 -425
  344. package/project-template-v2/skills/playable-record/scripts/verify-contract.mjs +0 -261
  345. package/project-template-v2/skills/playable-record/scripts/verify-firstwin.mjs +0 -398
  346. package/project-template-v2/skills/playable-record/scripts/verify-fusion.mjs +0 -322
  347. package/project-template-v2/skills/playable-record/scripts/verify-lifecycle.mjs +0 -105
  348. package/project-template-v2/skills/playable-record/scripts/verify-vlm-video.mjs +0 -230
  349. package/project-template-v2/skills/playable-validate/SKILL.md +0 -61
  350. package/project-template-v2/skills/playable-validate/validation-rules.md +0 -14
  351. package/project-template-v2/skills/playable-verify-ui/SKILL.md +0 -63
  352. package/project-template-v2/skills/playable-verify-ui/scripts/lib/__init__.py +0 -1
  353. package/project-template-v2/skills/playable-verify-ui/scripts/lib/config_expr.js +0 -218
  354. package/project-template-v2/skills/playable-verify-ui/scripts/lib/node_utils.js +0 -51
  355. package/project-template-v2/skills/playable-verify-ui/scripts/lib/profile_loader.py +0 -59
  356. package/project-template-v2/skills/playable-verify-ui/scripts/lib/report.py +0 -106
  357. package/project-template-v2/skills/playable-verify-ui/scripts/lib/runtime_contract.js +0 -116
  358. package/project-template-v2/skills/playable-verify-ui/scripts/verify_fetch_antipatterns.py +0 -59
  359. package/project-template-v2/skills/playable-verify-ui/scripts/verify_hardcoded_layout.js +0 -64
  360. package/project-template-v2/skills/playable-verify-ui/scripts/verify_runtime_contract.js +0 -58
  361. package/project-template-v2/skills/playable-verify-ui/scripts/verify_text_overlap.py +0 -333
  362. package/project-template-v2/ta-workspace/scripts/.gitkeep +0 -0
  363. package/project-template-v2/tsconfig.json +0 -20
  364. package/project-template-v2/vite.config.ts +0 -27
  365. package/project-templates/batch-locks/phaser.yaml +0 -922
  366. package/project-templates/batch-locks/threejs.yaml +0 -978
  367. package/project-templates/empty/AGENTS.md +0 -41
  368. package/project-templates/empty/gitignore +0 -33
@@ -1,670 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import { randomUUID } from 'node:crypto';
3
- import { excludeFromGit } from './dependencies.js';
4
- import { copyFile, lstat, readFile, realpath, rm, stat, unlink } from 'node:fs/promises';
5
- import { tmpdir } from 'node:os';
6
- import { basename, dirname, join, relative, resolve, sep } from 'node:path';
7
- import { TURN_CHANGED_FILES_MAX, WORKSPACE_FILE_CONTENT_MAX, gitDiffSchema, gitFileContentSchema, gitGraphSchema, gitStatusSchema, workspaceRelativePathSchema, } from '@playcraft/common/cloud-workspace/runtime';
8
- const GIT_DIFF_MAX_BYTES = 1024 * 1024;
9
- const GIT_PREFIX = [
10
- '-c',
11
- 'core.hooksPath=/dev/null',
12
- '-c',
13
- 'commit.gpgsign=false',
14
- '-c',
15
- 'safe.directory=*',
16
- ];
17
- export class GitWorkspaceError extends Error {
18
- code;
19
- constructor(code, message) {
20
- super(message);
21
- this.code = code;
22
- this.name = 'GitWorkspaceError';
23
- }
24
- }
25
- export async function probeGitBinary() {
26
- try {
27
- const result = await runGitProcess(tmpdir(), ['--version'], 4000);
28
- return result.code === 0;
29
- }
30
- catch (error) {
31
- return error instanceof GitWorkspaceError && error.code === 'git_binary_missing' ? false : false;
32
- }
33
- }
34
- export async function readWorkspaceGitStatus(root) {
35
- const rootReal = await ensureWorkspaceGit(root);
36
- const branchResult = await gitAllowFail(rootReal, ['symbolic-ref', '--short', 'HEAD']);
37
- const branch = branchResult.code === 0 ? branchResult.stdout.trim() || 'HEAD' : 'HEAD';
38
- const upstream = await gitAllowFail(rootReal, ['rev-list', '--left-right', '--count', '@{upstream}...HEAD']);
39
- let ahead = 0;
40
- let behind = 0;
41
- if (upstream.code === 0) {
42
- const [left, right] = upstream.stdout.trim().split(/\s+/);
43
- behind = Number.parseInt(left ?? '0', 10) || 0;
44
- ahead = Number.parseInt(right ?? '0', 10) || 0;
45
- }
46
- const porcelain = await git(rootReal, ['status', '--porcelain=v1', '--untracked-files=all', '-z']);
47
- const merge = await mergeState(rootReal);
48
- // Line counts are a convenience; a repository without commits still lists its files.
49
- const [staged, unstaged] = await Promise.all([
50
- gitAllowFail(rootReal, ['diff', '--cached', '--numstat', '-z']),
51
- gitAllowFail(rootReal, ['diff', '--numstat', '-z']),
52
- ]);
53
- const stagedCounts = staged.code === 0 ? parseNumstat(staged.stdout) : new Map();
54
- const unstagedCounts = unstaged.code === 0 ? parseNumstat(unstaged.stdout) : new Map();
55
- return gitStatusSchema.parse({
56
- initialized: true,
57
- branch,
58
- ahead,
59
- behind,
60
- hasUpstream: upstream.code === 0,
61
- ...merge,
62
- files: parsePorcelain(porcelain).map((entry) => ({
63
- ...entry,
64
- ...(stagedCounts.has(entry.path) ? { staged: stagedCounts.get(entry.path) } : {}),
65
- ...(unstagedCounts.has(entry.path) ? { unstaged: unstagedCounts.get(entry.path) } : {}),
66
- })),
67
- });
68
- }
69
- const SNAPSHOT_TIMEOUT_MS = 120_000;
70
- /**
71
- * Writes the work tree, as `git add -A` would stage it, to a tree object without touching the
72
- * repository's own index or history. A copy of the index keeps its stat cache, so unchanged files
73
- * are not hashed again. Ignored files and credential files are left out of the snapshot.
74
- */
75
- export async function snapshotWorkspaceTree(root) {
76
- const rootReal = await existingWorkspaceGit(root);
77
- const env = { GIT_INDEX_FILE: join(rootReal, '.git', `playcraft-snapshot-${randomUUID()}.index`) };
78
- const run = async (args) => {
79
- const result = await runGitProcess(rootReal, [...GIT_PREFIX, `--git-dir=${join(rootReal, '.git')}`,
80
- `--work-tree=${rootReal}`, ...args], SNAPSHOT_TIMEOUT_MS, env);
81
- if (result.code !== 0)
82
- throw new GitWorkspaceError('git_command_failed', result.stderr.trim() || `git_exit_${result.code}`);
83
- return result.stdout;
84
- };
85
- try {
86
- await copyFile(join(rootReal, '.git', 'index'), env.GIT_INDEX_FILE).catch((error) => {
87
- if (error.code !== 'ENOENT')
88
- throw error;
89
- });
90
- await run(['add', '-A']);
91
- const credentials = (await run(['ls-files', '-z'])).split('\0').filter((path) => path && isCredentialFile(path));
92
- if (credentials.length)
93
- await run(['rm', '--cached', '--quiet', '--', ...credentials]);
94
- return (await run(['write-tree'])).trim();
95
- }
96
- finally {
97
- await rm(env.GIT_INDEX_FILE, { force: true });
98
- }
99
- }
100
- /** Keeps a turn's snapshots from being pruned, so its changes stay readable after Git cleans up. */
101
- export async function retainTurnSnapshots(root, turnId, before, after) {
102
- const rootReal = await existingWorkspaceGit(root);
103
- const name = turnId.replace(/[^A-Za-z0-9_-]/g, '_');
104
- await git(rootReal, ['update-ref', `refs/playcraft/turns/${name}/before`, before]);
105
- await git(rootReal, ['update-ref', `refs/playcraft/turns/${name}/after`, after]);
106
- }
107
- /** The files that differ between two snapshot trees, with line counts for text files. */
108
- export async function diffWorkspaceTrees(root, before, after) {
109
- const rootReal = await existingWorkspaceGit(root);
110
- const diff = (format) => git(rootReal, ['diff-tree', '-r', '-z', '--no-renames', format, before, after], 60000);
111
- const [statuses, counts] = await Promise.all([diff('--name-status'), diff('--numstat')]);
112
- const lines = new Map();
113
- for (const entry of counts.split('\0')) {
114
- const match = /^(\d+|-)\t(\d+|-)\t(.+)$/s.exec(entry);
115
- if (!match)
116
- continue;
117
- const binary = match[1] === '-';
118
- lines.set(match[3], { added: binary ? 0 : Number(match[1]), removed: binary ? 0 : Number(match[2]), binary });
119
- }
120
- const parts = statuses.split('\0');
121
- const files = [];
122
- for (let index = 0; index + 1 < parts.length; index += 2) {
123
- const status = parts[index] === 'A' ? 'added' : parts[index] === 'D' ? 'deleted' : 'modified';
124
- const path = parts[index + 1];
125
- files.push({ path, status, ...(lines.get(path) ?? { added: 0, removed: 0, binary: false }) });
126
- }
127
- return { files: files.slice(0, TURN_CHANGED_FILES_MAX), truncated: files.length > TURN_CHANGED_FILES_MAX };
128
- }
129
- /**
130
- * One file as stored in the last commit, in the index or in a turn snapshot. Reads the blob as is,
131
- * without filters, so the browser compares exactly what Git holds.
132
- */
133
- export async function readWorkspaceGitFile(root, path, ref) {
134
- const rootReal = await ensureWorkspaceGit(root);
135
- assertWorkspacePaths([path]);
136
- const stage = { INDEX: 0, MERGE_BASE: 1, MERGE_OURS: 2, MERGE_THEIRS: 3 }[ref];
137
- const object = stage === undefined ? `${ref}:${path}` : `:${stage}:${path}`;
138
- const absent = gitFileContentSchema.parse({ path, ref, exists: false, binary: false, content: '' });
139
- const size = await gitAllowFail(rootReal, ['cat-file', '-s', object]);
140
- if (size.code !== 0)
141
- return absent;
142
- if (Number.parseInt(size.stdout.trim(), 10) > WORKSPACE_FILE_CONTENT_MAX) {
143
- throw new GitWorkspaceError('git_file_too_large', path);
144
- }
145
- const blob = await gitAllowFail(rootReal, ['cat-file', 'blob', object]);
146
- if (blob.code !== 0)
147
- return absent;
148
- // Git treats a NUL byte as the mark of binary content; so does the diff view.
149
- const binary = blob.stdout.includes('\0');
150
- return gitFileContentSchema.parse({ path, ref, exists: true, binary, content: binary ? '' : blob.stdout });
151
- }
152
- /** Adds the paths to the index, including deletions. */
153
- export async function stageWorkspaceGit(root, payload) {
154
- const rootReal = await ensureWorkspaceGit(root);
155
- assertWorkspacePaths(payload.paths);
156
- await git(rootReal, ['--literal-pathspecs', 'add', '-A', '--', ...payload.paths]);
157
- }
158
- /** Returns the paths' index entries to the last commit, leaving the work tree alone. */
159
- export async function unstageWorkspaceGit(root, payload) {
160
- const rootReal = await ensureWorkspaceGit(root);
161
- assertWorkspacePaths(payload.paths);
162
- const head = await gitAllowFail(rootReal, ['rev-parse', '--verify', '--quiet', 'HEAD']);
163
- if (head.code === 0) {
164
- await git(rootReal, ['--literal-pathspecs', 'restore', '--staged', '--', ...payload.paths]);
165
- }
166
- else {
167
- // Before the first commit there is nothing to restore from; the entries are simply removed.
168
- await git(rootReal, ['--literal-pathspecs', 'rm', '--cached', '-r', '-q', '--ignore-unmatch', '--', ...payload.paths]);
169
- }
170
- }
171
- /**
172
- * Throws away work-tree changes: tracked files return to their staged content, untracked files are
173
- * deleted. Staged content is never touched, so a staged change survives a discard.
174
- */
175
- export async function discardWorkspaceGit(root, payload) {
176
- const rootReal = await ensureWorkspaceGit(root);
177
- assertWorkspacePaths(payload.paths);
178
- const others = await git(rootReal, ['--literal-pathspecs', 'ls-files', '--others', '--exclude-standard', '-z', '--', ...payload.paths]);
179
- const untracked = new Set(others.split('\0').filter((path) => path.length > 0));
180
- const tracked = payload.paths.filter((path) => !untracked.has(path));
181
- if (tracked.length > 0) {
182
- await git(rootReal, ['--literal-pathspecs', 'restore', '--worktree', '--', ...tracked]);
183
- }
184
- for (const path of untracked) {
185
- const target = resolve(rootReal, path);
186
- // The parent must resolve inside the workspace, so a symlinked directory cannot redirect the delete.
187
- assertInsideRoot(rootReal, join(await realpath(dirname(target)), basename(target)));
188
- if ((await lstat(target)).isDirectory())
189
- throw new GitWorkspaceError('invalid_workspace_path', path);
190
- await unlink(target);
191
- }
192
- }
193
- function assertWorkspacePaths(paths) {
194
- for (const relativePath of paths) {
195
- if (!workspaceRelativePathSchema.safeParse(relativePath).success) {
196
- throw new GitWorkspaceError('invalid_workspace_path', relativePath);
197
- }
198
- }
199
- }
200
- export async function readWorkspaceGitDiff(root) {
201
- const rootReal = await ensureWorkspaceGit(root);
202
- const vsHead = await gitAllowFail(rootReal, ['diff', '--no-color', 'HEAD']);
203
- const patch = vsHead.code === 0
204
- ? vsHead.stdout
205
- : `${(await gitAllowFail(rootReal, ['diff', '--no-color'])).stdout}${(await gitAllowFail(rootReal, ['diff', '--no-color', '--cached'])).stdout}`;
206
- if (Buffer.byteLength(patch, 'utf8') > GIT_DIFF_MAX_BYTES) {
207
- throw new GitWorkspaceError('git_diff_too_large', '1MiB');
208
- }
209
- return gitDiffSchema.parse({ patch });
210
- }
211
- export async function readWorkspaceGitGraph(root) {
212
- const rootReal = await ensureWorkspaceGit(root);
213
- const log = await gitAllowFail(rootReal, ['log', '-n', '20', '--format=%H%x09%s%x09%cI']);
214
- if (log.code !== 0)
215
- return gitGraphSchema.parse({ commits: [] });
216
- const commits = log.stdout
217
- .split('\n')
218
- .map((line) => line.trimEnd())
219
- .filter((line) => line.length > 0)
220
- .map((line) => {
221
- const [sha, subject, committedAt] = splitLogLine(line);
222
- return {
223
- sha,
224
- subject: subject.length > 0 ? subject : '(empty)',
225
- committedAt: committedAt.length > 0 ? committedAt : new Date(0).toISOString(),
226
- };
227
- });
228
- return gitGraphSchema.parse({ commits });
229
- }
230
- function splitLogLine(line) {
231
- const first = line.indexOf('\t');
232
- if (first < 0)
233
- return [line, '', ''];
234
- const second = line.indexOf('\t', first + 1);
235
- if (second < 0)
236
- return [line.slice(0, first), line.slice(first + 1), ''];
237
- return [line.slice(0, first), line.slice(first + 1, second), line.slice(second + 1)];
238
- }
239
- /**
240
- * Commit and push stay on the branch the workspace is bound to. A switch made in a shell or by an
241
- * agent is reported, never followed, so work cannot land on another Remix.
242
- */
243
- async function assertBoundBranch(rootReal, boundBranch) {
244
- if (!boundBranch)
245
- return;
246
- const current = await gitAllowFail(rootReal, ['symbolic-ref', '--quiet', '--short', 'HEAD']);
247
- const branch = current.code === 0 ? current.stdout.trim() : '';
248
- if (branch !== boundBranch) {
249
- throw new GitWorkspaceError('workspace_branch_mismatch', branch || 'detached HEAD');
250
- }
251
- }
252
- /**
253
- * A push the remote refused for this ref is a definite outcome, unlike a lost response. Porcelain
254
- * output marks the ref with "!" and says whether the remote has commits this checkout lacks.
255
- */
256
- /**
257
- * The gateway or the host refused the push over HTTP before any ref changed: no write access, the
258
- * gateway's writes switched off, or no such repository. Like a protected-branch refusal, nothing
259
- * was pushed and the commit is kept.
260
- */
261
- function httpRefusal(stderr) {
262
- return /returned error: (?:401|403|404)\b|Authentication failed|Access denied|could not read Username|repository '[^']*' not found/i.test(stderr)
263
- ? 'git_push_rejected'
264
- : undefined;
265
- }
266
- function pushRejection(stdout) {
267
- const line = stdout.split('\n').find((item) => item.startsWith('!\t'));
268
- if (!line)
269
- return undefined;
270
- if (/\[rejected\] \((?:non-fast-forward|fetch first)\)/.test(line))
271
- return 'git_push_remote_ahead';
272
- return 'git_push_rejected';
273
- }
274
- export async function commitWorkspaceGit(root, payload, boundBranch) {
275
- const rootReal = await ensureWorkspaceGit(root);
276
- await assertBoundBranch(rootReal, boundBranch);
277
- // Adding a conflicted file would mark it resolved with its conflict markers in it.
278
- if ((await unmergedPaths(rootReal)).length)
279
- throw new GitWorkspaceError('git_conflicts_unresolved', 'unmerged');
280
- if (payload.stagedOnly) {
281
- // The index is the commit; nothing is added.
282
- }
283
- else if (payload.paths && payload.paths.length > 0) {
284
- assertWorkspacePaths(payload.paths);
285
- await git(rootReal, ['add', '--', ...payload.paths]);
286
- }
287
- else {
288
- await git(rootReal, ['add', '-A']);
289
- }
290
- const cached = await gitAllowFail(rootReal, ['diff', '--cached', '--quiet']);
291
- if (cached.code === 0) {
292
- throw new GitWorkspaceError('nothing_to_commit', payload.message);
293
- }
294
- await git(rootReal, ['commit', '-m', payload.message], 20000);
295
- return (await git(rootReal, ['rev-parse', 'HEAD'])).trim();
296
- }
297
- export async function pushWorkspaceGit(root, boundBranch) {
298
- const rootReal = await ensureWorkspaceGit(root);
299
- await assertBoundBranch(rootReal, boundBranch);
300
- const origin = await gitAllowFail(rootReal, ['remote', 'get-url', 'origin']);
301
- if (origin.code !== 0) {
302
- throw new GitWorkspaceError('remote_not_configured', 'origin');
303
- }
304
- const ref = (await git(rootReal, ['symbolic-ref', '--quiet', 'HEAD'])).trim();
305
- if (!ref.startsWith('refs/heads/'))
306
- throw new GitWorkspaceError('git_command_failed', 'git_branch_required');
307
- const commit = (await git(rootReal, ['rev-parse', '--verify', 'HEAD^{commit}'])).trim();
308
- let pushed;
309
- try {
310
- pushed = await gitAllowFail(rootReal, ['push', '--porcelain', 'origin', `${commit}:${ref}`], 90000);
311
- }
312
- catch { /* A lost response does not prove the remote rejected the update. */ }
313
- if (pushed?.code === 0)
314
- return;
315
- const rejected = pushed ? pushRejection(pushed.stdout) ?? httpRefusal(pushed.stderr) : undefined;
316
- if (rejected)
317
- throw new GitWorkspaceError(rejected, rejected);
318
- try {
319
- const remote = await gitAllowFail(rootReal, ['ls-remote', '--refs', 'origin', ref], 20000);
320
- if (remote.code === 0 && remote.stdout.trim() === `${commit}\t${ref}`)
321
- return;
322
- }
323
- catch { /* Preserve uncertainty; never replay a write automatically. */ }
324
- throw new GitWorkspaceError('git_push_outcome_unknown', 'git_push_outcome_unknown');
325
- }
326
- /**
327
- * Credential files a save never commits, even when `.gitignore` misses them: env files (their
328
- * `.example` / `.sample` / `.template` stay), SSH keys, netrc and Git credential stores, and key
329
- * or certificate bundles.
330
- */
331
- const CREDENTIAL_FILE = /^(?:\.env(?:\.(?!(?:example|sample|template)$)[^/]+)?|id_(?:rsa|dsa|ecdsa|ed25519)|\.netrc|\.git-credentials|[^/]*\.(?:pem|key|p12|pfx))$/i;
332
- export function isCredentialFile(path) {
333
- return CREDENTIAL_FILE.test(path.split('/').pop() ?? '');
334
- }
335
- /**
336
- * Commits every change in the work tree (`git add -A`, credential files aside) and, when asked,
337
- * pushes the branch. A save with nothing new commits nothing and pushes only what the remote
338
- * lacks, so a commit whose push failed goes out with the next save.
339
- */
340
- export async function saveWorkspaceGit(root, input) {
341
- const rootReal = await ensureWorkspaceGit(root);
342
- await assertBoundBranch(rootReal, input.boundBranch);
343
- // A save during a merge would stage conflict markers as resolutions and conclude the merge. The
344
- // user (or an agent) finishes the merge with an explicit commit; saves resume after it.
345
- if ((await mergeState(rootReal)).merging)
346
- return { pushed: false, withheld: [] };
347
- await git(rootReal, ['add', '-A'], 60000);
348
- const staged = (await git(rootReal, ['diff', '--cached', '--name-only', '-z'], 60000)).split('\0').filter(Boolean);
349
- const withheld = staged.filter(isCredentialFile);
350
- await unstage(rootReal, withheld);
351
- const cached = await gitAllowFail(rootReal, ['diff', '--cached', '--quiet'], 60000);
352
- if (cached.code !== 0 && cached.code !== 1) {
353
- throw new GitWorkspaceError('git_command_failed', cached.stderr.trim() || 'git_diff_failed');
354
- }
355
- let commit;
356
- if (cached.code === 1) {
357
- await git(rootReal, [...(await commitIdentity(rootReal)), 'commit', '-q', '-m', input.message], 60000);
358
- commit = (await git(rootReal, ['rev-parse', 'HEAD'])).trim();
359
- }
360
- if (!input.push || (await remoteHasHead(rootReal)))
361
- return { ...(commit ? { commit } : {}), pushed: false, withheld };
362
- await pushWorkspaceGit(rootReal, input.boundBranch);
363
- await recordPushedHead(rootReal);
364
- return { ...(commit ? { commit } : {}), pushed: true, withheld };
365
- }
366
- /**
367
- * `git pull` with a merge, as VS Code runs it: fetch the bound branch from origin, then merge it.
368
- * Uncommitted work is kept unless the incoming commits change the same files, in which case Git
369
- * refuses before touching anything. Conflicts leave the merge in progress for the user to resolve.
370
- */
371
- export async function pullWorkspaceGit(root, boundBranch) {
372
- const rootReal = await ensureWorkspaceGit(root);
373
- await assertBoundBranch(rootReal, boundBranch);
374
- if ((await mergeState(rootReal)).merging)
375
- throw new GitWorkspaceError('git_merge_in_progress', 'merge_in_progress');
376
- if ((await gitAllowFail(rootReal, ['remote', 'get-url', 'origin'])).code !== 0) {
377
- throw new GitWorkspaceError('remote_not_configured', 'origin');
378
- }
379
- const branch = (await gitAllowFail(rootReal, ['symbolic-ref', '--quiet', '--short', 'HEAD'])).stdout.trim();
380
- const born = (await gitAllowFail(rootReal, ['rev-parse', '-q', '--verify', 'HEAD^{commit}'])).code === 0;
381
- if (!branch || !born)
382
- throw new GitWorkspaceError('git_command_failed', 'git_branch_required');
383
- // A fork clone has no fetch refspec for its own branch, so the tracking ref is named here.
384
- const remoteRef = `refs/remotes/origin/${branch}`;
385
- const fetched = await gitAllowFail(rootReal, ['fetch', '--no-tags', 'origin', `+refs/heads/${branch}:${remoteRef}`], 90000);
386
- if (fetched.code !== 0)
387
- throw new GitWorkspaceError(httpRefusal(fetched.stderr) ?? 'git_fetch_failed', 'git_fetch_failed');
388
- if ((await gitAllowFail(rootReal, ['merge-base', '--is-ancestor', remoteRef, 'HEAD'])).code === 0) {
389
- return { outcome: 'up_to_date', conflicts: [] };
390
- }
391
- // The short name gives the merge commit the message `git pull` would write.
392
- const merged = await gitAllowFail(rootReal, [...(await commitIdentity(rootReal)), 'merge', '--no-edit', `origin/${branch}`], 60000);
393
- if (merged.code === 0)
394
- return { outcome: 'merged', conflicts: [] };
395
- const conflicts = await unmergedPaths(rootReal);
396
- if (conflicts.length)
397
- return { outcome: 'conflicts', conflicts };
398
- if (/would be overwritten by merge|untracked working tree files would be (?:overwritten|removed)/i.test(`${merged.stdout}\n${merged.stderr}`)) {
399
- throw new GitWorkspaceError('git_pull_local_changes', 'local_changes');
400
- }
401
- throw new GitWorkspaceError('git_command_failed', merged.stderr.trim() || 'git_merge_failed');
402
- }
403
- /** `git merge --abort`: the work tree and index return to how they were before the merge began. */
404
- export async function abortWorkspaceMerge(root) {
405
- const rootReal = await ensureWorkspaceGit(root);
406
- if (!(await mergeState(rootReal)).merging)
407
- throw new GitWorkspaceError('git_merge_not_in_progress', 'no_merge');
408
- await git(rootReal, ['merge', '--abort'], 60000);
409
- }
410
- /** Paths with unmerged index entries, that is, conflicts not yet marked resolved. */
411
- async function unmergedPaths(rootReal) {
412
- const listed = await gitAllowFail(rootReal, ['diff', '--name-only', '--diff-filter=U', '-z']);
413
- return listed.code === 0 ? listed.stdout.split('\0').filter(Boolean) : [];
414
- }
415
- async function mergeState(rootReal) {
416
- try {
417
- await stat(join(rootReal, '.git', 'MERGE_HEAD'));
418
- }
419
- catch (error) {
420
- if (error.code === 'ENOENT')
421
- return {};
422
- throw error;
423
- }
424
- const message = await readFile(join(rootReal, '.git', 'MERGE_MSG'), 'utf8').catch(() => '');
425
- const text = message.split('\n').filter((line) => !line.startsWith('#')).join('\n').trim().slice(0, 4096);
426
- return { merging: true, ...(text ? { mergeMessage: text } : {}) };
427
- }
428
- /**
429
- * Connects a standalone checkout to the repository it was just given, keeping all its history and
430
- * uncommitted work. The new repository holds one empty commit on `branch`; it becomes the base of an
431
- * unborn checkout, or is merged into existing history, so the next push is a plain fast-forward.
432
- * Credentials come from the workspace's configured helper and never enter the remote URL.
433
- * Safe to run again after a failure part way.
434
- */
435
- export async function attachWorkspaceRemote(root, repositoryUrl, branch) {
436
- const rootReal = await ensureWorkspaceGit(root);
437
- const origin = await gitAllowFail(rootReal, ['remote', 'get-url', 'origin']);
438
- if (origin.code !== 0)
439
- await git(rootReal, ['remote', 'add', 'origin', repositoryUrl]);
440
- else if (origin.stdout.trim() !== repositoryUrl)
441
- throw new GitWorkspaceError('remote_not_configured', 'origin_mismatch');
442
- const remoteRef = `refs/remotes/origin/${branch}`;
443
- const fetched = await gitAllowFail(rootReal, ['fetch', '--no-tags', 'origin', `+refs/heads/${branch}:${remoteRef}`], 90000);
444
- if (fetched.code !== 0)
445
- throw new GitWorkspaceError(httpRefusal(fetched.stderr) ?? 'git_command_failed', 'git_fetch_failed');
446
- const current = (await gitAllowFail(rootReal, ['symbolic-ref', '--quiet', '--short', 'HEAD'])).stdout.trim();
447
- const born = (await gitAllowFail(rootReal, ['rev-parse', '-q', '--verify', 'HEAD^{commit}'])).code === 0;
448
- if (current !== branch) {
449
- await git(rootReal, born ? ['branch', '-M', branch] : ['symbolic-ref', 'HEAD', `refs/heads/${branch}`]);
450
- }
451
- if (!born) {
452
- // Nothing committed yet: start the branch at the remote commit; the files stay as changes.
453
- await git(rootReal, ['update-ref', `refs/heads/${branch}`, remoteRef]);
454
- }
455
- else if ((await gitAllowFail(rootReal, ['merge-base', '--is-ancestor', remoteRef, 'HEAD'])).code !== 0) {
456
- const merged = await gitAllowFail(rootReal, [...(await commitIdentity(rootReal)), 'merge', '--allow-unrelated-histories', '--no-edit', remoteRef], 60000);
457
- if (merged.code !== 0) {
458
- await gitAllowFail(rootReal, ['merge', '--abort']);
459
- throw new GitWorkspaceError('git_command_failed', merged.stderr.trim() || 'git_merge_failed');
460
- }
461
- }
462
- await git(rootReal, ['branch', `--set-upstream-to=origin/${branch}`, branch]);
463
- }
464
- async function unstage(rootReal, paths) {
465
- if (paths.length === 0)
466
- return;
467
- const born = (await gitAllowFail(rootReal, ['rev-parse', '-q', '--verify', 'HEAD'])).code === 0;
468
- for (let start = 0; start < paths.length; start += 100) {
469
- const chunk = paths.slice(start, start + 100);
470
- // Before the first commit there is no HEAD to reset to; dropping the entries does the same.
471
- await git(rootReal, born ? ['reset', '-q', '--', ...chunk] : ['rm', '-q', '--cached', '--', ...chunk]);
472
- }
473
- }
474
- /** A clone carries no committer; the sandbox image sets none either. */
475
- async function commitIdentity(rootReal) {
476
- const email = await gitAllowFail(rootReal, ['config', 'user.email']);
477
- if (email.code === 0 && email.stdout.trim())
478
- return [];
479
- return ['-c', 'user.name=PlayCraft Workspace', '-c', 'user.email=workspace@playcraft.local'];
480
- }
481
- /**
482
- * The remote-tracking ref of the current branch. A fork clone has no fetch refspec for its own
483
- * branch, so the ref is written here after a confirmed push.
484
- */
485
- async function trackingRef(rootReal) {
486
- const branch = (await gitAllowFail(rootReal, ['symbolic-ref', '--quiet', '--short', 'HEAD'])).stdout.trim();
487
- return branch ? `refs/remotes/origin/${branch}` : undefined;
488
- }
489
- async function remoteHasHead(rootReal) {
490
- const ref = await trackingRef(rootReal);
491
- if (!ref)
492
- return false;
493
- const [head, tracked] = await Promise.all([
494
- gitAllowFail(rootReal, ['rev-parse', '-q', '--verify', 'HEAD^{commit}']),
495
- gitAllowFail(rootReal, ['rev-parse', '-q', '--verify', `${ref}^{commit}`]),
496
- ]);
497
- return head.code === 0 && tracked.code === 0 && head.stdout.trim() === tracked.stdout.trim();
498
- }
499
- async function recordPushedHead(rootReal) {
500
- const ref = await trackingRef(rootReal);
501
- if (ref)
502
- await gitAllowFail(rootReal, ['update-ref', ref, 'HEAD']);
503
- }
504
- export async function ensureWorkspaceGit(root) {
505
- const rootReal = await realpath(root);
506
- if (!(await gitMarkerExists(rootReal))) {
507
- const init = await gitAllowFail(rootReal, ['init']);
508
- if (init.code !== 0) {
509
- throw new GitWorkspaceError('git_command_failed', init.stderr.trim() || 'git_init_failed');
510
- }
511
- await git(rootReal, ['config', 'user.name', 'PlayCraft Workspace']);
512
- await git(rootReal, ['config', 'user.email', 'workspace@playcraft.local']);
513
- }
514
- await assertWorkspaceGitRoot(rootReal);
515
- await excludeFromGit(rootReal, '/.tmp/user_uploads/');
516
- return rootReal;
517
- }
518
- /**
519
- * The control user and the development user (terminal, Codex) both write this repository. Git
520
- * creates directories with the writer's umask, so a directory one user made can refuse the
521
- * other's objects. With `core.sharedRepository=group` Git makes new directories group-writable for
522
- * both; the image puts the control user in the development group.
523
- */
524
- export async function shareWorkspaceRepository(root) {
525
- const rootReal = await existingWorkspaceGit(root);
526
- const current = await gitAllowFail(rootReal, ['config', '--get', 'core.sharedRepository']);
527
- if (current.stdout.trim() !== 'group')
528
- await git(rootReal, ['config', 'core.sharedRepository', 'group']);
529
- }
530
- /** Turn snapshots never create a repository; a directory without one simply has no turn changes. */
531
- async function existingWorkspaceGit(root) {
532
- const rootReal = await realpath(root);
533
- if (!(await gitMarkerExists(rootReal)))
534
- throw new GitWorkspaceError('git_command_failed', 'not_a_repository');
535
- await assertWorkspaceGitRoot(rootReal);
536
- return rootReal;
537
- }
538
- async function gitMarkerExists(rootReal) {
539
- try {
540
- await stat(join(rootReal, '.git'));
541
- return true;
542
- }
543
- catch (error) {
544
- if (error.code === 'ENOENT')
545
- return false;
546
- throw error;
547
- }
548
- }
549
- async function assertWorkspaceGitRoot(rootReal) {
550
- const marker = join(rootReal, '.git');
551
- const info = await stat(marker);
552
- if (info.isDirectory()) {
553
- assertInsideRoot(rootReal, await realpath(marker));
554
- return;
555
- }
556
- if (info.isFile()) {
557
- const text = await readFile(marker, 'utf8');
558
- const match = /^gitdir:\s*(.+)$/m.exec(text);
559
- if (!match)
560
- throw new GitWorkspaceError('git_root_escape', 'invalid_gitdir');
561
- const target = resolve(rootReal, match[1].trim());
562
- assertInsideRoot(rootReal, await realpath(target));
563
- return;
564
- }
565
- throw new GitWorkspaceError('git_root_escape', marker);
566
- }
567
- function assertInsideRoot(rootReal, target) {
568
- const rel = relative(rootReal, target);
569
- if (rel === '' || rel.startsWith(`..${sep}`) || rel === '..' || rel.startsWith('..')) {
570
- throw new GitWorkspaceError('git_root_escape', target);
571
- }
572
- }
573
- function parsePorcelain(raw) {
574
- const parts = raw.split('\0').filter((part) => part.length > 0);
575
- const files = [];
576
- for (let i = 0; i < parts.length; i += 1) {
577
- const entry = parts[i] ?? '';
578
- if (entry.length < 3)
579
- continue;
580
- const indexStatus = entry[0] ?? ' ';
581
- const worktreeStatus = entry[1] ?? ' ';
582
- const pathPart = entry.slice(3);
583
- if (indexStatus === 'R' || indexStatus === 'C' || worktreeStatus === 'R' || worktreeStatus === 'C') {
584
- const dest = parts[i + 1] ?? pathPart;
585
- i += 1;
586
- files.push({ path: dest, indexStatus, worktreeStatus });
587
- continue;
588
- }
589
- files.push({ path: pathPart, indexStatus, worktreeStatus });
590
- }
591
- return files;
592
- }
593
- /**
594
- * `diff --numstat -z`: `added<TAB>removed<TAB>path<NUL>`, or for a rename an empty path followed by
595
- * `old<NUL>new<NUL>`. Binary files report `-` and are left out.
596
- */
597
- function parseNumstat(raw) {
598
- const counts = new Map();
599
- const parts = raw.split('\0');
600
- for (let index = 0; index < parts.length; index += 1) {
601
- const match = /^(\d+|-)\t(\d+|-)\t(.*)$/s.exec(parts[index] ?? '');
602
- if (!match)
603
- continue;
604
- let path = match[3];
605
- if (path === '') {
606
- path = parts[index + 2] ?? '';
607
- index += 2;
608
- }
609
- if (match[1] === '-' || !path)
610
- continue;
611
- counts.set(path, { added: Number(match[1]), removed: Number(match[2]) });
612
- }
613
- return counts;
614
- }
615
- async function git(root, args, timeoutMs = 15000) {
616
- const result = await gitAllowFail(root, args, timeoutMs);
617
- if (result.code !== 0) {
618
- throw new GitWorkspaceError('git_command_failed', result.stderr.trim() || `git_exit_${result.code}`);
619
- }
620
- return result.stdout;
621
- }
622
- async function gitAllowFail(root, args, timeoutMs = 15000) {
623
- return runGitProcess(root, [...GIT_PREFIX, `--git-dir=${join(root, '.git')}`, `--work-tree=${root}`, ...args], timeoutMs);
624
- }
625
- function gitEnv() {
626
- const env = { ...process.env };
627
- delete env.GIT_DIR;
628
- delete env.GIT_WORK_TREE;
629
- delete env.GIT_COMMON_DIR;
630
- delete env.GIT_INDEX_FILE;
631
- delete env.GIT_OBJECT_DIRECTORY;
632
- delete env.GIT_ALTERNATE_OBJECT_DIRECTORIES;
633
- env.GIT_OPTIONAL_LOCKS = '0';
634
- env.GIT_TERMINAL_PROMPT = '0';
635
- return env;
636
- }
637
- function runGitProcess(cwd, args, timeoutMs, env) {
638
- return new Promise((resolve, reject) => {
639
- const child = spawn('git', args, { cwd, env: { ...gitEnv(), ...env }, windowsHide: true });
640
- // Chunks are decoded together; a character split across two chunks would otherwise be corrupted.
641
- const stdout = [];
642
- const stderr = [];
643
- const timer = setTimeout(() => {
644
- child.kill('SIGKILL');
645
- reject(new GitWorkspaceError('git_command_failed', 'timeout'));
646
- }, timeoutMs);
647
- child.stdout.on('data', (chunk) => {
648
- stdout.push(Buffer.from(chunk));
649
- });
650
- child.stderr.on('data', (chunk) => {
651
- stderr.push(Buffer.from(chunk));
652
- });
653
- child.on('error', (error) => {
654
- clearTimeout(timer);
655
- if (error.code === 'ENOENT') {
656
- reject(new GitWorkspaceError('git_binary_missing', 'git'));
657
- return;
658
- }
659
- reject(error);
660
- });
661
- child.on('close', (code) => {
662
- clearTimeout(timer);
663
- resolve({
664
- stdout: Buffer.concat(stdout).toString('utf8'),
665
- stderr: Buffer.concat(stderr).toString('utf8'),
666
- code: code ?? 1,
667
- });
668
- });
669
- });
670
- }