@joiner-platform/cli 0.0.0-stage → 0.1.0

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 (303) hide show
  1. package/README.md +30 -2
  2. package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
  3. package/bundled-resources/poe-tile-templates/base/README.md +7 -0
  4. package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
  5. package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
  6. package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
  7. package/bundled-resources/poe-tile-templates/base/package.json +36 -0
  8. package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
  9. package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
  10. package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
  11. package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
  12. package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
  13. package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
  14. package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
  15. package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
  16. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
  17. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
  18. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
  19. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
  20. package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
  21. package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
  22. package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
  23. package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
  24. package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
  25. package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
  26. package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
  27. package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
  28. package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
  29. package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
  30. package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
  31. package/bundled-resources/poe-tile-templates/index.ts +27 -0
  32. package/bundled-resources/poe-tile-templates/package.json +31 -0
  33. package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
  34. package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
  35. package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
  36. package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
  37. package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
  38. package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
  39. package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
  40. package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
  41. package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
  42. package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
  43. package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
  44. package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
  45. package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
  46. package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
  47. package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
  48. package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
  49. package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
  50. package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
  51. package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
  52. package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
  53. package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
  54. package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
  55. package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
  56. package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
  57. package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
  58. package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
  59. package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
  60. package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
  61. package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
  62. package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
  63. package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
  64. package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
  65. package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
  66. package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
  67. package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
  68. package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
  69. package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
  70. package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
  71. package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
  72. package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
  73. package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
  74. package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
  75. package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
  76. package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
  77. package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
  78. package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
  79. package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
  80. package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
  81. package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
  82. package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
  83. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
  84. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
  85. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
  86. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
  87. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
  88. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
  89. package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
  90. package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
  91. package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
  92. package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
  93. package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
  94. package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
  95. package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
  96. package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
  97. package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
  98. package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
  99. package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
  100. package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
  101. package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
  102. package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
  103. package/cli.ts +134 -0
  104. package/index.ts +96 -0
  105. package/package.json +48 -5
  106. package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
  107. package/skills/audio-generation/SKILL.md +125 -0
  108. package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
  109. package/skills/finish-prototype/SKILL.md +22 -0
  110. package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
  111. package/skills/help-me-build/SKILL.md +56 -0
  112. package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
  113. package/skills/image-generation/SKILL.md +128 -0
  114. package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
  115. package/skills/one-shot/SKILL.md +22 -0
  116. package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
  117. package/skills/platform-prototype/SKILL.md +60 -0
  118. package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
  119. package/skills/platform-subagent/SKILL.md +16 -0
  120. package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
  121. package/skills/poe-tiles-cli/SKILL.md +609 -0
  122. package/skills/poe-tiles-cli/references/device-motion.md +40 -0
  123. package/skills/poe-tiles-cli/references/player-updates.md +41 -0
  124. package/skills/prototype/.generated-by-poe-templated-docs +0 -0
  125. package/skills/prototype/SKILL.md +148 -0
  126. package/skills/publish/.generated-by-poe-templated-docs +0 -0
  127. package/skills/publish/SKILL.md +73 -0
  128. package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
  129. package/skills/synced-store/SKILL.md +583 -0
  130. package/skills/synced-store/references/actions.md +85 -0
  131. package/skills/synced-store/references/api-patterns.md +245 -0
  132. package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
  133. package/skills/synced-store/references/client-api-reference.md +263 -0
  134. package/skills/synced-store/references/data-visibility.md +95 -0
  135. package/skills/synced-store/references/external-stores.md +162 -0
  136. package/skills/synced-store/references/file-uploads.md +216 -0
  137. package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
  138. package/skills/synced-store/references/limitations.md +72 -0
  139. package/skills/synced-store/references/live-data-limit-hook.md +131 -0
  140. package/skills/synced-store/references/mutator-rules.md +169 -0
  141. package/skills/synced-store/references/platform.md +49 -0
  142. package/skills/synced-store/references/schema-and-bindings.md +85 -0
  143. package/skills/synced-store/references/schema-libraries.md +57 -0
  144. package/skills/synced-store/references/schema-migrations.md +119 -0
  145. package/skills/synced-store/references/searchable-tables.md +27 -0
  146. package/skills/synced-store/references/server-forking.md +115 -0
  147. package/skills/synced-store/references/singleton-tables.md +61 -0
  148. package/skills/synced-store/references/sort-keys.md +253 -0
  149. package/skills/synced-store/references/ui-patterns.md +95 -0
  150. package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
  151. package/skills/tile-creator/SKILL.md +196 -0
  152. package/skills/tile-creator/references/assets.md +124 -0
  153. package/skills/tile-creator/references/backend-api.md +308 -0
  154. package/skills/tile-creator/references/cli-limitations.md +64 -0
  155. package/skills/tile-creator/references/cli.md +604 -0
  156. package/skills/tile-creator/references/client-api.md +2407 -0
  157. package/skills/tile-creator/references/composing-apps.md +166 -0
  158. package/skills/tile-creator/references/e2e-tests.md +55 -0
  159. package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
  160. package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
  161. package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
  162. package/skills/tile-creator/references/native-results.md +100 -0
  163. package/skills/tile-creator/references/platform-integration.md +201 -0
  164. package/skills/tile-creator/references/power-report.md +199 -0
  165. package/skills/tile-creator/references/publish-rollout.md +166 -0
  166. package/skills/tile-creator/references/publishing.md +33 -0
  167. package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
  168. package/skills/tile-creator/references/render-check.md +266 -0
  169. package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
  170. package/skills/tile-creator/references/safe-area-insets.md +79 -0
  171. package/skills/tile-creator/references/sandbox-limitations.md +32 -0
  172. package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
  173. package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
  174. package/skills/tile-creator/references/simulations.md +125 -0
  175. package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
  176. package/skills/tile-creator/references/troubleshooting.md +22 -0
  177. package/skills/tile-creator/references/turn-based-mutator.md +43 -0
  178. package/skills/tile-creator/references/user-erasure.md +14 -0
  179. package/skills/tile-creator/references/vite-plugin.md +166 -0
  180. package/skills/tile-creator/references/workspace-retention.md +72 -0
  181. package/src/admin-conversions-client.ts +28 -0
  182. package/src/admin-reviews-client.ts +36 -0
  183. package/src/api.generated.ts +1527 -0
  184. package/src/auth-token.ts +198 -0
  185. package/src/bounded-read.ts +35 -0
  186. package/src/bun-version.ts +33 -0
  187. package/src/checkout-base.ts +207 -0
  188. package/src/cli-bun-version.ts +16 -0
  189. package/src/cli-env.ts +28 -0
  190. package/src/cli-name.ts +23 -0
  191. package/src/client.ts +2474 -0
  192. package/src/collect-files.ts +226 -0
  193. package/src/commands/accounts.ts +55 -0
  194. package/src/commands/admin-abandon-conversion.ts +60 -0
  195. package/src/commands/admin-reviews.ts +66 -0
  196. package/src/commands/admin.ts +219 -0
  197. package/src/commands/auth.ts +89 -0
  198. package/src/commands/checkout-prototype.ts +67 -0
  199. package/src/commands/creator-source-capability.ts +11 -0
  200. package/src/commands/doctor-bun.ts +145 -0
  201. package/src/commands/doctor-command.ts +64 -0
  202. package/src/commands/doctor-package-json.ts +47 -0
  203. package/src/commands/doctor-sdk-pin.ts +156 -0
  204. package/src/commands/doctor-store-keys-lexer.ts +213 -0
  205. package/src/commands/doctor-store-keys-scan.ts +262 -0
  206. package/src/commands/doctor-store-keys.ts +196 -0
  207. package/src/commands/doctor.ts +371 -0
  208. package/src/commands/init/blank-scaffold-templates.ts +397 -0
  209. package/src/commands/init/index.ts +170 -0
  210. package/src/commands/init/internal-toolchain.ts +49 -0
  211. package/src/commands/init/manager-test-template.ts +107 -0
  212. package/src/commands/init/multiplayer-test-template.ts +217 -0
  213. package/src/commands/init/name-input.tsx +167 -0
  214. package/src/commands/init/no-store-scaffold-templates.ts +281 -0
  215. package/src/commands/init/no-store-scaffold.ts +134 -0
  216. package/src/commands/init/package-json-scripts.ts +72 -0
  217. package/src/commands/init/scaffold.ts +960 -0
  218. package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
  219. package/src/commands/init/sdk-tarball-url.ts +31 -0
  220. package/src/commands/init/template-picker.tsx +147 -0
  221. package/src/commands/inspect-child-entry.ts +107 -0
  222. package/src/commands/inspect-contract.ts +87 -0
  223. package/src/commands/inspect-freshness.ts +217 -0
  224. package/src/commands/inspect-lock.ts +201 -0
  225. package/src/commands/inspect-options.ts +360 -0
  226. package/src/commands/inspect-orchestrate.ts +375 -0
  227. package/src/commands/inspect-process.ts +172 -0
  228. package/src/commands/inspect-ready.ts +65 -0
  229. package/src/commands/inspect-report.ts +235 -0
  230. package/src/commands/inspect-run-state.ts +296 -0
  231. package/src/commands/inspect-run.ts +157 -0
  232. package/src/commands/inspect-watchdog.ts +74 -0
  233. package/src/commands/install-joiner.ts +208 -0
  234. package/src/commands/login.ts +308 -0
  235. package/src/commands/models.ts +40 -0
  236. package/src/commands/parse-options.ts +36 -0
  237. package/src/commands/remix-package-json.ts +64 -0
  238. package/src/commands/remix.ts +379 -0
  239. package/src/commands/sdk-url.ts +141 -0
  240. package/src/commands/simulations.ts +133 -0
  241. package/src/commands/skills.ts +108 -0
  242. package/src/commands/store-files.ts +92 -0
  243. package/src/commands/stores.ts +703 -0
  244. package/src/commands/tiles-channel-commands.ts +115 -0
  245. package/src/commands/tiles-checkout.ts +351 -0
  246. package/src/commands/tiles-gallery-command.ts +95 -0
  247. package/src/commands/tiles-get-helpers.ts +27 -0
  248. package/src/commands/tiles-inspect.ts +276 -0
  249. package/src/commands/tiles-power-command.ts +308 -0
  250. package/src/commands/tiles-power-format.ts +396 -0
  251. package/src/commands/tiles-power-versions.ts +299 -0
  252. package/src/commands/tiles-publish-helpers.ts +145 -0
  253. package/src/commands/tiles-upload-command.ts +277 -0
  254. package/src/commands/tiles-version-commands.ts +201 -0
  255. package/src/commands/tiles-visibility-command.ts +103 -0
  256. package/src/commands/tiles.ts +257 -0
  257. package/src/commands/upgrade.ts +307 -0
  258. package/src/commit-in-progress.ts +42 -0
  259. package/src/creator-source-context.ts +97 -0
  260. package/src/creator-source-publish.ts +52 -0
  261. package/src/deferred-assets.ts +125 -0
  262. package/src/distribution.ts +28 -0
  263. package/src/errors.ts +61 -0
  264. package/src/install-command.ts +43 -0
  265. package/src/output.ts +62 -0
  266. package/src/poe-tile-config-files.ts +100 -0
  267. package/src/poe-tile-config-players.ts +168 -0
  268. package/src/poe-tile-config-remix.ts +166 -0
  269. package/src/poe-tile-config.ts +831 -0
  270. package/src/power-report-client.ts +55 -0
  271. package/src/prototype-startup.ts +21 -0
  272. package/src/publish-change-summary.ts +55 -0
  273. package/src/publish-overrides-validation.ts +49 -0
  274. package/src/publish-pack.ts +167 -0
  275. package/src/publish-phases.ts +57 -0
  276. package/src/publish-retry.ts +51 -0
  277. package/src/publish-tile-from-config.ts +434 -0
  278. package/src/recorder-stream.ts +169 -0
  279. package/src/remix-provenance.ts +156 -0
  280. package/src/resolve-client-credential.ts +71 -0
  281. package/src/resolve-media-uploads.ts +147 -0
  282. package/src/sdk-dependency.ts +54 -0
  283. package/src/sdk-skills.ts +85 -0
  284. package/src/should-skip-client-setup.ts +20 -0
  285. package/src/simulation-snapshot.ts +123 -0
  286. package/src/simulation-types.ts +74 -0
  287. package/src/simulations-client.ts +112 -0
  288. package/src/source-bundle.ts +466 -0
  289. package/src/staged-publish-cleanup.ts +44 -0
  290. package/src/staged-publish-deferred.ts +160 -0
  291. package/src/staged-publish.ts +401 -0
  292. package/src/store-file-upload.ts +268 -0
  293. package/src/store-request.ts +168 -0
  294. package/src/tar-canonical.ts +41 -0
  295. package/src/tar-extensions.ts +159 -0
  296. package/src/tar-extract.ts +193 -0
  297. package/src/tar-parse.ts +224 -0
  298. package/src/tar.ts +231 -0
  299. package/src/template-check-scripts.ts +18 -0
  300. package/src/tile-gallery-client.ts +82 -0
  301. package/src/types.ts +258 -0
  302. package/src/upload-concurrency.ts +54 -0
  303. package/src/whole-tile.ts +52 -0
@@ -0,0 +1,831 @@
1
+ // owner: aroe
2
+ /* biome-ignore-all lint/nursery/noExcessiveLinesPerFile: existing file exceeds 400 lines; add new tests or code to focused companion files instead. No new exceptions to this rule should be made. */
3
+ /**
4
+ * `.poe-tile.json` — project-local config for `tiles publish`.
5
+ *
6
+ * Lives at the app root (sibling of `package.json`). Records publish
7
+ * defaults so creators don't have to re-pass flags on every publish:
8
+ *
9
+ * {
10
+ * "$schema": "https://joiner-docs.pages.dev/schemas/poe-tile/v10.json",
11
+ * "handle": "my-cool-app",
12
+ * "profilePicture": "./assets/icon.png", // optional — local path OR https URL
13
+ * "shortDescription": "A cool app for cool people", // optional — ≤140 chars
14
+ * "longDescription": "./README.md", // optional — local path to markdown file
15
+ * "screenshots": ["./shots/1.webp", "./shots/2.webp"], // optional (v3+) — local paths OR https URLs
16
+ * "players": { "min": 2, "max": 4, "recommended": { "min": 3, "max": 4 } }, // optional (v5+)
17
+ * "instancing": "per-context", // optional (v7+) — one instance per room context
18
+ * "remixOf": { // optional (v9+) — written by `poe-tiles remix`
19
+ * "tileId": "…", "versionNumber": 3, "sourceBundleId": "…"
20
+ * },
21
+ * "sourceBundle": { // optional
22
+ * "dir": "src", // resolved relative to the config file
23
+ * "visibility": "owner_only", // "owner_only" | "public"
24
+ * "ignoreFile": ".poesourceignore" // optional, relative to config file
25
+ * }
26
+ * }
27
+ *
28
+ * `tiles init` writes this file next to the scaffolded app. `tiles publish`
29
+ * reads it from `process.cwd()` and merges its values into the publish
30
+ * call with **explicit-flag-wins** precedence (so a one-off `tiles publish
31
+ * --source-bundle-visibility=public` overrides the persisted default
32
+ * without needing to edit the file).
33
+ *
34
+ * The file is a normal JSON document — creators can hand-edit it to
35
+ * pre-configure per-project defaults, including app `visibility` and
36
+ * `sourceBundle` for automatic source uploads on every publish.
37
+ *
38
+ * The `$schema` URL doubles as the schema-version pointer: editors use
39
+ * it for autocomplete; the CLI checks it on read so an old CLI refuses
40
+ * a future-shaped config rather than silently misinterpreting it.
41
+ */
42
+
43
+ import { writeFileSync } from "node:fs";
44
+ import { join } from "node:path";
45
+ import {
46
+ POE_APP_CONFIG_SCHEMA_URLS_V2,
47
+ readPoeTileConfigFiles,
48
+ } from "./poe-tile-config-files.js";
49
+ import {
50
+ parsePlayersConfigField,
51
+ type TilePlayerCount,
52
+ } from "./poe-tile-config-players.js";
53
+ import {
54
+ type PoeTileConfigRemixOf,
55
+ parseRemixOfConfigField,
56
+ } from "./poe-tile-config-remix.js";
57
+ import {
58
+ isSourceBundleVisibility,
59
+ type SourceBundleVisibility,
60
+ } from "./source-bundle.js";
61
+
62
+ export type { TilePlayerCount } from "./poe-tile-config-players.js";
63
+ export type { PoeTileConfigRemixOf } from "./poe-tile-config-remix.js";
64
+
65
+ export type PoeTileVisibility = "public" | "unlisted" | "dev";
66
+
67
+ /**
68
+ * How a tile spawns instances across launches (mirrors `TileInstancing` in
69
+ * `@lib/tile-registry`). `per-context` makes launch surfaces reuse an existing
70
+ * instance instead of minting a new one. A string enum (not a boolean) so
71
+ * future modes can be added without a second flag.
72
+ */
73
+ export type TileInstancing = "per-launch" | "per-context";
74
+
75
+ // TODO: remove `"dev"` from `.poe-tile.json` app visibility and keep this
76
+ // config surface creator-facing (`"public" | "unlisted"` only). `dev`
77
+ // still exists in lower-level publish plumbing today, so the config accepts
78
+ // it for now to avoid a broader migration in this change.
79
+ function isPoeTileVisibility(value: string): value is PoeTileVisibility {
80
+ return value === "public" || value === "unlisted" || value === "dev";
81
+ }
82
+
83
+ /**
84
+ * Handle shape and length cap inlined from `@lib/tile-registry` so the
85
+ * published CLI tarball doesn't carry a workspace:* dependency (see
86
+ * `packaging.test.ts`). Drift between this inlined copy and the canonical
87
+ * value upstream is guarded by `workspace-sync.test.ts`.
88
+ */
89
+ export const TILE_HANDLE_REGEX = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
90
+ export const TILE_HANDLE_MAX_LENGTH = 100;
91
+
92
+ /**
93
+ * Validate an app handle against the shape and length rules above. Returns
94
+ * `undefined` when valid, or a short human-readable reason fragment when
95
+ * invalid. Callers prepend their own context (config-file path, CLI flag
96
+ * name, etc.) so the surfaced error matches the ingestion site.
97
+ */
98
+ export function describeInvalidTileHandle(handle: string): string | undefined {
99
+ if (handle.length === 0) {
100
+ return "must be a non-empty string";
101
+ }
102
+ if (handle.length > TILE_HANDLE_MAX_LENGTH) {
103
+ return `is ${handle.length} characters; the maximum is ${TILE_HANDLE_MAX_LENGTH}`;
104
+ }
105
+ if (!TILE_HANDLE_REGEX.test(handle)) {
106
+ return `must match ${TILE_HANDLE_REGEX} (lowercase alphanumeric and hyphens, no leading/trailing hyphens)`;
107
+ }
108
+ return undefined;
109
+ }
110
+
111
+ /** Filename of the project-local config. */
112
+ export const POE_TILE_CONFIG_FILENAME = ".poe-tile.json";
113
+
114
+ /**
115
+ * Canonical schema URL the CLI accepts on read and writes on
116
+ * `tiles init`. Bump the path segment (e.g. `/schemas/poe-tile/v4.json`)
117
+ * when the config shape changes in a breaking way; the old CLI will
118
+ * then refuse the new file with a useful error instead of silently
119
+ * misreading it. The previous version's URL must keep resolving forever
120
+ * so old CLIs in the wild stay functional.
121
+ */
122
+ export const POE_TILE_CONFIG_SCHEMA_URL =
123
+ "https://joiner-docs.pages.dev/schemas/poe-tile/v10.json";
124
+
125
+ /**
126
+ * The docs moved to `joiner-docs.pages.dev`; the old host 301s there. This CLI
127
+ * writes the new host and reads a `$schema` on either host as the same
128
+ * version, so existing configs, including committed tile manifests, keep
129
+ * working on the old host.
130
+ */
131
+ const SCHEMA_ORIGIN = "https://joiner-docs.pages.dev/";
132
+ const ALTERNATE_SCHEMA_ORIGIN = "https://poe-tiles-docs.pages.dev/";
133
+
134
+ function sameHostSchemaUrl(schema: unknown): unknown {
135
+ return typeof schema === "string" &&
136
+ schema.startsWith(ALTERNATE_SCHEMA_ORIGIN)
137
+ ? SCHEMA_ORIGIN + schema.slice(ALTERNATE_SCHEMA_ORIGIN.length)
138
+ : schema;
139
+ }
140
+
141
+ /**
142
+ * Previous config schema URLs. Still accepted on read for backward
143
+ * compatibility. v2 added profilePicture/shortDescription/longDescription/
144
+ * visibility; v3 added the optional `screenshots` field; v4 removes
145
+ * config-level `publishAsPoe`; v5 adds the optional `players` field; v6 adds
146
+ * the optional `video` field; v7 adds the optional `instancing` field; v8 adds
147
+ * the optional `categories` field; v9 adds `remixOf`; v10 removes categories. A
148
+ * config that uses `screenshots` must declare v3+, one that uses `players`
149
+ * must declare v5+, one that uses `video` must declare v6+, one that uses
150
+ * `instancing` must declare v7+, and `remixOf` requires v9+. Categories are
151
+ * rejected regardless of the declared schema (all enforced in
152
+ * {@link validatePoeTileConfig}). The v1 URL is NOT accepted (it predates the
153
+ * metadata fields) — it only drives a tailored upgrade hint.
154
+ */
155
+ export const POE_TILE_CONFIG_SCHEMA_URL_V2 =
156
+ "https://joiner-docs.pages.dev/schemas/poe-tile/v2.json";
157
+ export const POE_TILE_CONFIG_SCHEMA_URL_V3 =
158
+ "https://joiner-docs.pages.dev/schemas/poe-tile/v3.json";
159
+ export const POE_TILE_CONFIG_SCHEMA_URL_V4 =
160
+ "https://joiner-docs.pages.dev/schemas/poe-tile/v4.json";
161
+ export const POE_TILE_CONFIG_SCHEMA_URL_V5 =
162
+ "https://joiner-docs.pages.dev/schemas/poe-tile/v5.json";
163
+ export const POE_TILE_CONFIG_SCHEMA_URL_V6 =
164
+ "https://joiner-docs.pages.dev/schemas/poe-tile/v6.json";
165
+ export const POE_TILE_CONFIG_SCHEMA_URL_V7 =
166
+ "https://joiner-docs.pages.dev/schemas/poe-tile/v7.json";
167
+ export const POE_TILE_CONFIG_SCHEMA_URL_V8 =
168
+ "https://joiner-docs.pages.dev/schemas/poe-tile/v8.json";
169
+ export const POE_TILE_CONFIG_SCHEMA_URL_V9 =
170
+ "https://joiner-docs.pages.dev/schemas/poe-tile/v9.json";
171
+
172
+ /**
173
+ * Caps for the app-metadata fields added in v2 of the config schema:
174
+ * profile picture, short description, long description (markdown).
175
+ *
176
+ * Mirrored by the publish API at its trust boundary; the CLI re-applies
177
+ * them at config-read time so a typo'd or oversized value fails before
178
+ * any network call.
179
+ *
180
+ * `SHORT_DESCRIPTION_MAX_LENGTH` is in characters (one-line tagline).
181
+ * `LONG_DESCRIPTION_MAX_BYTES` is UTF-8 byte length (markdown body —
182
+ * single-byte cap suffices for English but matters for multi-byte
183
+ * scripts where 16 KiB of chars could be 64 KiB of bytes).
184
+ */
185
+ export const SHORT_DESCRIPTION_MAX_LENGTH = 140;
186
+ export const LONG_DESCRIPTION_MAX_BYTES = 16 * 1024;
187
+ export const DISPLAY_NAME_MAX_LENGTH = 80;
188
+
189
+ /**
190
+ * Caps for the v3 `screenshots` list, mirrored from the publish API
191
+ * (`SCREENSHOTS_MAX_COUNT` / `SCREENSHOT_URL_MAX_LENGTH` in
192
+ * `packages/poe-tiles-api/src/api/tiles/tile-publish-screenshots.ts`). Inlined
193
+ * here — like the handle caps above — so the published CLI tarball doesn't
194
+ * carry a workspace dep; drift is the CLI's responsibility to keep in sync.
195
+ */
196
+ export const SCREENSHOTS_MAX_COUNT = 8;
197
+ export const SCREENSHOT_URL_MAX_LENGTH = 2048;
198
+
199
+ /**
200
+ * The v6 `video` field: one gameplay preview clip plus its poster image.
201
+ * Both are **local paths only** (relative to the config file) — unlike
202
+ * screenshots, there is no `https://` pass-through, because an external video
203
+ * URL would bypass the server's size cap, Range guarantees, and immutable
204
+ * caching. The CLI uploads both files' bytes at publish time.
205
+ */
206
+ export type PoeTileConfigVideo = {
207
+ /** Local path to the mp4 preview clip (relative to the config file). */
208
+ src: string;
209
+ /** Local path to the poster image (png/jpg/webp, relative to the config file). */
210
+ poster: string;
211
+ };
212
+
213
+ /** Optional source-bundle preferences persisted in `.poe-tile.json`. */
214
+ export type PoeTileConfigSourceBundle = {
215
+ /** Directory to pack as the source tarball. Resolved relative to the config file. */
216
+ dir: string;
217
+ /** Visibility passed to the server (`source_bundle_visibility`). */
218
+ visibility: SourceBundleVisibility;
219
+ /** Optional extra ignore-pattern file (relative to the config file). */
220
+ ignoreFile?: string;
221
+ };
222
+
223
+ /**
224
+ * Optional runtime-bundle preferences persisted in `.poe-tile.json`.
225
+ * Mirrors {@link PoeTileConfigSourceBundle} so a future runtime-only
226
+ * setting (pre-build hook, validation flag, etc.) has an obvious home.
227
+ */
228
+ export type PoeTileConfigRuntimeBundle = {
229
+ /** Directory containing the built runtime bundle (e.g. `"dist"`, `"static"`). Resolved relative to the config file. */
230
+ dir: string;
231
+ };
232
+
233
+ /** Parsed `.poe-tile.json`. */
234
+ export type PoeTileConfig = {
235
+ $schema: string;
236
+ handle: string;
237
+ /**
238
+ * Optional human-friendly display name shown on Explore and all app
239
+ * cards. Overrides the kebab-case handle on every user-facing surface.
240
+ * Non-empty, ≤{@link DISPLAY_NAME_MAX_LENGTH} chars.
241
+ */
242
+ displayName?: string;
243
+ /**
244
+ * Optional app icon. Either a path relative to the config file (the
245
+ * CLI uploads its bytes to the platform blob store) or an `https://`
246
+ * URL (stored as-is, not proxied). Non-empty string.
247
+ */
248
+ profilePicture?: string;
249
+ /**
250
+ * Optional one-line tagline shown on app cards and at the top of the
251
+ * app page. Non-empty, ≤{@link SHORT_DESCRIPTION_MAX_LENGTH} chars.
252
+ */
253
+ shortDescription?: string;
254
+ /**
255
+ * Optional path (relative to the config file) to a markdown file
256
+ * rendered on the app page below the Launch button. The CLI reads
257
+ * the file contents and ships them as a string; the file itself
258
+ * must be ≤{@link LONG_DESCRIPTION_MAX_BYTES} bytes (UTF-8).
259
+ */
260
+ longDescription?: string;
261
+ /**
262
+ * Optional ordered list of detail-card screenshots (v3+). Each entry is
263
+ * either a path relative to the config file (the CLI uploads its bytes to
264
+ * the platform blob store) or an `https://` URL (stored as-is). At most
265
+ * {@link SCREENSHOTS_MAX_COUNT}; each `https://` entry ≤
266
+ * {@link SCREENSHOT_URL_MAX_LENGTH} chars. Requires `$schema` v3 — present
267
+ * under a v2 `$schema` is a loud error, never a silent drop.
268
+ */
269
+ screenshots?: string[];
270
+ /**
271
+ * Optional player-count facet (v5+). `{ min, max?, recommended? }`,
272
+ * counting total seats (humans + AI). `max` absent = no declared upper
273
+ * bound. Requires `$schema` v5 — present under a pre-v5 `$schema` is a loud
274
+ * error, never a silent drop. `players: null` is the explicit clear
275
+ * sentinel (un-declare on republish).
276
+ */
277
+ players?: TilePlayerCount | null;
278
+ /**
279
+ * Optional gameplay preview video (v6+). `{ src, poster }`, both **local
280
+ * paths** (no `https://` pass-through — see {@link PoeTileConfigVideo}).
281
+ * Requires `$schema` v6 — present under a pre-v6 `$schema` is a loud error,
282
+ * never a silent drop. `video: null` is the explicit clear sentinel
283
+ * (remove the video on republish), independent of `screenshots`.
284
+ */
285
+ video?: PoeTileConfigVideo | null;
286
+ /**
287
+ * Optional instancing mode (v7+). `per-context` makes launch surfaces reuse
288
+ * an existing instance instead of minting a new one: Explore "Play Now"
289
+ * reuses the user's existing solo instance, and the in-group launcher opens
290
+ * the group's existing instance directly instead of showing the instance
291
+ * picker. Requires `$schema` v7 — present under a pre-v7 `$schema` is a loud
292
+ * error, never a silent drop. Two-state on republish: omitted → preserve,
293
+ * `per-launch` → reset to the default (no `null` sentinel).
294
+ */
295
+ instancing?: TileInstancing;
296
+ /**
297
+ * Optional remix provenance (v9+). Names the published app — and the exact
298
+ * publish of it — this app was remixed from. `poe-tiles remix` writes this
299
+ * automatically when it unpacks a source bundle, so most creators never
300
+ * hand-edit it. Requires `$schema` v9 — present under a pre-v9 `$schema` is
301
+ * a loud error, never a silent drop. `remixOf: null` is the explicit clear
302
+ * sentinel (drop the attribution on republish).
303
+ *
304
+ * Shape is validated here, and shape is the only check anywhere: the server
305
+ * does NOT look up the app you name. A credit that does not resolve simply
306
+ * renders nothing on your detail page.
307
+ */
308
+ remixOf?: PoeTileConfigRemixOf | null;
309
+ /**
310
+ * Where the tile should sit in discovery — creator profiles, Explore, For
311
+ * You. Separate from `sourceBundle.visibility`, which controls who can fetch
312
+ * source code.
313
+ *
314
+ * **Declared state, not something publishing applies.** A publish uploads a
315
+ * bundle and never moves a tile in or out of discovery, so this field is read
316
+ * by tooling that reconciles it with an explicit `poe-tiles tiles visibility`
317
+ * call — the first-party deploy scripts, which own their tiles' placement.
318
+ * The `tiles publish` command ignores it: re-asserting a manifest's answer on
319
+ * every routine publish is how an automated republish silently unlists a tile
320
+ * whose owner listed it from the UI.
321
+ */
322
+ visibility?: PoeTileVisibility;
323
+ runtimeBundle?: PoeTileConfigRuntimeBundle;
324
+ sourceBundle?: PoeTileConfigSourceBundle;
325
+ };
326
+
327
+ /**
328
+ * Result of {@link readPoeTileConfig}. Differentiated so callers can tell
329
+ * "no config" (silently fall back to flags) from "config exists but is
330
+ * malformed" (which should fail loudly).
331
+ */
332
+ export type ReadPoeTileConfigResult =
333
+ | { found: false }
334
+ | { found: true; path: string; config: PoeTileConfig };
335
+
336
+ /**
337
+ * Read `.poe-tile.json` or the legacy `.poe-app.json` from `dir` without
338
+ * changing either file. When both exist, their fields must agree; the current
339
+ * filename is preferred only for equivalent configs. Returns `{ found: false }`
340
+ * when neither file exists — callers should treat that as "no defaults" and
341
+ * proceed with whatever flags were passed. Throws when the file exists
342
+ * but is malformed (parse error, unknown `$schema`, missing required
343
+ * fields, invalid `sourceBundle.visibility`, etc.) so creators can't
344
+ * accidentally publish under stale or broken settings.
345
+ */
346
+ export function readPoeTileConfig(dir: string): ReadPoeTileConfigResult {
347
+ return readPoeTileConfigFiles(
348
+ dir,
349
+ POE_TILE_CONFIG_FILENAME,
350
+ validatePoeTileConfig,
351
+ );
352
+ }
353
+
354
+ /**
355
+ * Validate the optional v3 `screenshots` field. Returns the validated list,
356
+ * or `undefined` when the field is absent. Throws when `screenshots` is
357
+ * present under a v2 `$schema` (a loud "bump to v3" error — never a silent
358
+ * drop), when the value isn't an array of non-empty strings, when the list
359
+ * exceeds {@link SCREENSHOTS_MAX_COUNT}, or when an `https://` entry exceeds
360
+ * {@link SCREENSHOT_URL_MAX_LENGTH}.
361
+ */
362
+ function assertValidScreenshotEntry(entry: unknown): void {
363
+ if (typeof entry !== "string" || entry.length === 0) {
364
+ throw new Error(
365
+ `${POE_TILE_CONFIG_FILENAME}.screenshots entries must be non-empty strings (local path or https URL).`,
366
+ );
367
+ }
368
+ if (
369
+ entry.startsWith("https://") &&
370
+ entry.length > SCREENSHOT_URL_MAX_LENGTH
371
+ ) {
372
+ throw new Error(
373
+ `${POE_TILE_CONFIG_FILENAME}.screenshots URL is ${entry.length} characters; the maximum is ${SCREENSHOT_URL_MAX_LENGTH}.`,
374
+ );
375
+ }
376
+ }
377
+
378
+ function parseScreenshotsField(
379
+ raw: unknown,
380
+ schemaSupportsScreenshots: boolean,
381
+ ): string[] | undefined {
382
+ if (raw === undefined) return undefined;
383
+ if (!schemaSupportsScreenshots) {
384
+ throw new Error(
385
+ `${POE_TILE_CONFIG_FILENAME}.screenshots requires $schema ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL)} (v5), ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V4)} (v4), or ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V3)} (v3). Bump the $schema URL to use screenshots — they are not supported under the v2 schema.`,
386
+ );
387
+ }
388
+ if (!Array.isArray(raw)) {
389
+ throw new Error(
390
+ `${POE_TILE_CONFIG_FILENAME}.screenshots, if set, must be an array of strings (local paths or https URLs).`,
391
+ );
392
+ }
393
+ if (raw.length > SCREENSHOTS_MAX_COUNT) {
394
+ throw new Error(
395
+ `${POE_TILE_CONFIG_FILENAME}.screenshots has ${raw.length} entries; the maximum is ${SCREENSHOTS_MAX_COUNT}.`,
396
+ );
397
+ }
398
+ for (const entry of raw) {
399
+ assertValidScreenshotEntry(entry);
400
+ }
401
+ return raw as string[];
402
+ }
403
+
404
+ /** Assert a `video.src`/`video.poster` value is a non-empty LOCAL path. */
405
+ function assertLocalVideoPath(value: unknown, field: "src" | "poster"): string {
406
+ if (typeof value !== "string" || value.length === 0) {
407
+ throw new Error(
408
+ `${POE_TILE_CONFIG_FILENAME}.video.${field} must be a non-empty local path.`,
409
+ );
410
+ }
411
+ if (value.startsWith("https://") || value.startsWith("http://")) {
412
+ throw new Error(
413
+ `${POE_TILE_CONFIG_FILENAME}.video.${field} must be a local path, not a URL — external video/poster URLs are not supported (they bypass the size cap, Range guarantees, and immutable caching).`,
414
+ );
415
+ }
416
+ return value;
417
+ }
418
+
419
+ /**
420
+ * Parse the v7 `instancing` field. Two-state: `undefined` → omit (preserve on
421
+ * republish); a mode literal → set (`per-launch` resets to the default). Gated
422
+ * on the v7 schema — a present `instancing` under a pre-v7 `$schema` is a loud
423
+ * error, never a silent drop.
424
+ */
425
+ function parseInstancingField(
426
+ raw: unknown,
427
+ schemaSupportsInstancing: boolean,
428
+ ): TileInstancing | undefined {
429
+ if (raw === undefined) return undefined;
430
+ if (!schemaSupportsInstancing) {
431
+ throw new Error(
432
+ `${POE_TILE_CONFIG_FILENAME}.instancing requires $schema ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL)} (v7+). Bump the $schema URL to use the instancing field.`,
433
+ );
434
+ }
435
+ if (raw !== "per-launch" && raw !== "per-context") {
436
+ throw new Error(
437
+ `${POE_TILE_CONFIG_FILENAME}.instancing, if set, must be "per-launch" or "per-context".`,
438
+ );
439
+ }
440
+ return raw;
441
+ }
442
+
443
+ /**
444
+ * Parse the v6 `video` field. Tri-state: `undefined` → omit (preserve on
445
+ * republish); `null` → clear; `{ src, poster }` → set (both local paths).
446
+ * Gated on v6+ — a present `video` under a pre-v6 `$schema` is a loud
447
+ * error, never a silent drop.
448
+ */
449
+ function parseVideoField(
450
+ raw: unknown,
451
+ schemaSupportsVideo: boolean,
452
+ ): PoeTileConfigVideo | null | undefined {
453
+ if (raw === undefined) return undefined;
454
+ if (!schemaSupportsVideo) {
455
+ throw new Error(
456
+ `${POE_TILE_CONFIG_FILENAME}.video requires $schema ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL)} (v6+). Bump the $schema URL to use a preview video.`,
457
+ );
458
+ }
459
+ if (raw === null) return null;
460
+ if (typeof raw !== "object" || Array.isArray(raw)) {
461
+ throw new Error(
462
+ `${POE_TILE_CONFIG_FILENAME}.video, if set, must be an object { src, poster } or null.`,
463
+ );
464
+ }
465
+ const obj = raw as Record<string, unknown>;
466
+ return {
467
+ src: assertLocalVideoPath(obj["src"], "src"),
468
+ poster: assertLocalVideoPath(obj["poster"], "poster"),
469
+ };
470
+ }
471
+
472
+ /**
473
+ * Coerce an unknown value into a {@link PoeTileConfig}, throwing a
474
+ * helpful error on any structural violation. Surfaced separately from
475
+ * {@link readPoeTileConfig} so tests and `tiles init` can validate
476
+ * in-memory shapes without going through the filesystem.
477
+ */
478
+
479
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Existing function exceeds the cognitive-complexity limit; keep the rule enabled for new code.
480
+ export function validatePoeTileConfig(value: unknown): PoeTileConfig {
481
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
482
+ throw new Error(
483
+ `${POE_TILE_CONFIG_FILENAME} must be a JSON object, not ${
484
+ value === null ? "null" : Array.isArray(value) ? "array" : typeof value
485
+ }.`,
486
+ );
487
+ }
488
+ const obj = value as Record<string, unknown>;
489
+ if ("categories" in obj) {
490
+ throw new Error(
491
+ "Remove the top-level `categories` field from `.poe-tile.json`; categories are assigned automatically.",
492
+ );
493
+ }
494
+ const declaredSchema = obj["$schema"];
495
+ const schema = sameHostSchemaUrl(declaredSchema);
496
+ // v10 is canonical; v2..v9 are still accepted when they avoid newer/removed
497
+ // fields. v2 added the metadata fields; v3 added screenshots; v4 removed
498
+ // config-level publishAsPoe; v5 added players; v6 added video; v7 added
499
+ // instancing; v8 added categories; v9 added remixOf; v10 removes categories.
500
+ // The v1 URL is not
501
+ // accepted: it predates the metadata fields, so it gets a tailored upgrade
502
+ // hint. Anything else is an unknown schema.
503
+ const isV2 =
504
+ schema === POE_TILE_CONFIG_SCHEMA_URL_V2 ||
505
+ POE_APP_CONFIG_SCHEMA_URLS_V2.some(
506
+ (legacySchema) => declaredSchema === legacySchema,
507
+ );
508
+ const isV3 = schema === POE_TILE_CONFIG_SCHEMA_URL_V3;
509
+ const isV4 = schema === POE_TILE_CONFIG_SCHEMA_URL_V4;
510
+ const isV5 = schema === POE_TILE_CONFIG_SCHEMA_URL_V5;
511
+ const isV6 = schema === POE_TILE_CONFIG_SCHEMA_URL_V6;
512
+ const isV7 = schema === POE_TILE_CONFIG_SCHEMA_URL_V7;
513
+ const isV8 = schema === POE_TILE_CONFIG_SCHEMA_URL_V8;
514
+ const isV9 = schema === POE_TILE_CONFIG_SCHEMA_URL_V9;
515
+ if (
516
+ schema !== POE_TILE_CONFIG_SCHEMA_URL &&
517
+ !isV2 &&
518
+ !isV3 &&
519
+ !isV4 &&
520
+ !isV5 &&
521
+ !isV6 &&
522
+ !isV7 &&
523
+ !isV8 &&
524
+ !isV9
525
+ ) {
526
+ const isLegacyV1 =
527
+ schema === "https://joiner-docs.pages.dev/schemas/poe-tile/v1.json";
528
+ const hint = isLegacyV1
529
+ ? ` Update the $schema URL to ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL)} — v2 adds optional profilePicture, shortDescription, longDescription, and visibility fields; v3 adds screenshots; v4 removes config-level publishAsPoe; v5 adds players; v6 adds video; v7 adds instancing; v8 adds categories; v9 adds remixOf; v10 removes creator categories. Pass --publish-as-poe when publishing under @poe.`
530
+ : " Upgrade the CLI or update the config's $schema URL.";
531
+ throw new Error(
532
+ `${POE_TILE_CONFIG_FILENAME} has $schema=${JSON.stringify(
533
+ declaredSchema,
534
+ )} but this CLI understands $schema=${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL)} (or legacy ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V9)} / ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V8)} / ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V7)} / ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V6)} / ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V5)} / ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V4)} / ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V3)} / ${JSON.stringify(POE_TILE_CONFIG_SCHEMA_URL_V2)}).${hint}`,
535
+ );
536
+ }
537
+ const handle = obj["handle"];
538
+ if (typeof handle !== "string") {
539
+ throw new Error(
540
+ `${POE_TILE_CONFIG_FILENAME}.handle must be a non-empty string.`,
541
+ );
542
+ }
543
+ // `.poe-tiles.json` is a creator-authored input ingested at the CLI's
544
+ // trust boundary. PRINCIPLES.md requires variable-size inputs to have
545
+ // explicit limits enforced at the point of ingestion. The shape (regex)
546
+ // and length cap match the server-side enforcement in
547
+ // `@lib/tile-registry` so a typo'd or oversized handle here fails with
548
+ // the same error the API would have returned — at the CLI, not after
549
+ // an upload that gets rejected mid-flight.
550
+ const handleProblem = describeInvalidTileHandle(handle);
551
+ if (handleProblem !== undefined) {
552
+ throw new Error(`${POE_TILE_CONFIG_FILENAME}.handle ${handleProblem}.`);
553
+ }
554
+ if ("publishAsPoe" in obj) {
555
+ throw new Error(
556
+ `${POE_TILE_CONFIG_FILENAME}.publishAsPoe is no longer supported. Pass --publish-as-poe when publishing under @poe.`,
557
+ );
558
+ }
559
+
560
+ const displayNameRaw = obj["displayName"];
561
+ let displayName: string | undefined;
562
+ if (displayNameRaw !== undefined) {
563
+ if (
564
+ typeof displayNameRaw !== "string" ||
565
+ displayNameRaw.trim().length === 0
566
+ ) {
567
+ throw new Error(
568
+ `${POE_TILE_CONFIG_FILENAME}.displayName, if set, must be a non-empty string.`,
569
+ );
570
+ }
571
+ if (displayNameRaw.length > DISPLAY_NAME_MAX_LENGTH) {
572
+ throw new Error(
573
+ `${POE_TILE_CONFIG_FILENAME}.displayName is ${displayNameRaw.length} characters; the maximum is ${DISPLAY_NAME_MAX_LENGTH}.`,
574
+ );
575
+ }
576
+ displayName = displayNameRaw;
577
+ }
578
+
579
+ // New in v2: optional app-metadata fields. Each is enforced at the
580
+ // CLI's trust boundary so a typo'd or oversized value fails before
581
+ // `tiles publish` opens a network connection.
582
+ const profilePictureRaw = obj["profilePicture"];
583
+ let profilePicture: string | undefined;
584
+ if (profilePictureRaw !== undefined) {
585
+ if (
586
+ typeof profilePictureRaw !== "string" ||
587
+ profilePictureRaw.length === 0
588
+ ) {
589
+ throw new Error(
590
+ `${POE_TILE_CONFIG_FILENAME}.profilePicture, if set, must be a non-empty string (local path or https URL).`,
591
+ );
592
+ }
593
+ profilePicture = profilePictureRaw;
594
+ }
595
+
596
+ const shortDescriptionRaw = obj["shortDescription"];
597
+ let shortDescription: string | undefined;
598
+ if (shortDescriptionRaw !== undefined) {
599
+ if (
600
+ typeof shortDescriptionRaw !== "string" ||
601
+ shortDescriptionRaw.length === 0
602
+ ) {
603
+ throw new Error(
604
+ `${POE_TILE_CONFIG_FILENAME}.shortDescription, if set, must be a non-empty string.`,
605
+ );
606
+ }
607
+ if (shortDescriptionRaw.length > SHORT_DESCRIPTION_MAX_LENGTH) {
608
+ throw new Error(
609
+ `${POE_TILE_CONFIG_FILENAME}.shortDescription is ${shortDescriptionRaw.length} characters; the maximum is ${SHORT_DESCRIPTION_MAX_LENGTH}.`,
610
+ );
611
+ }
612
+ shortDescription = shortDescriptionRaw;
613
+ }
614
+
615
+ const longDescriptionRaw = obj["longDescription"];
616
+ let longDescription: string | undefined;
617
+ if (longDescriptionRaw !== undefined) {
618
+ if (
619
+ typeof longDescriptionRaw !== "string" ||
620
+ longDescriptionRaw.length === 0
621
+ ) {
622
+ throw new Error(
623
+ `${POE_TILE_CONFIG_FILENAME}.longDescription, if set, must be a non-empty string (path to a markdown file).`,
624
+ );
625
+ }
626
+ longDescription = longDescriptionRaw;
627
+ }
628
+
629
+ const screenshots = parseScreenshotsField(obj["screenshots"], !isV2);
630
+
631
+ // New in v5: optional `players` facet. Gated on v5+; a present `players`
632
+ // under a pre-v5 `$schema` is a loud error (never a silent drop). `null`
633
+ // is the explicit clear sentinel and is preserved through to publish.
634
+ const players = parsePlayersConfigField({
635
+ raw: obj["players"],
636
+ schemaSupportsPlayers:
637
+ isV5 ||
638
+ isV6 ||
639
+ isV7 ||
640
+ isV8 ||
641
+ isV9 ||
642
+ schema === POE_TILE_CONFIG_SCHEMA_URL,
643
+ configFilename: POE_TILE_CONFIG_FILENAME,
644
+ schemaUrl: POE_TILE_CONFIG_SCHEMA_URL,
645
+ });
646
+
647
+ // New in v6: optional `video` preview. Gated on v6+; a present `video`
648
+ // under a pre-v6 `$schema` is a loud error (never a silent drop). `null`
649
+ // is the explicit clear sentinel and is preserved through to publish.
650
+ const video = parseVideoField(
651
+ obj["video"],
652
+ isV6 || isV7 || isV8 || isV9 || schema === POE_TILE_CONFIG_SCHEMA_URL,
653
+ );
654
+
655
+ // New in v7: optional `instancing` mode. Gated on v7+; a present
656
+ // `instancing` under a pre-v7 `$schema` is a loud error (never a silent
657
+ // drop). Two-state — `per-launch` resets to default, no `null` sentinel.
658
+ const instancing = parseInstancingField(
659
+ obj["instancing"],
660
+ isV7 || isV8 || isV9 || schema === POE_TILE_CONFIG_SCHEMA_URL,
661
+ );
662
+
663
+ // New in v9: optional `remixOf` provenance. Gated on v9+; a
664
+ // present `remixOf` under a pre-v9 `$schema` is a loud error (never a
665
+ // silent drop). `null` is the explicit clear sentinel and is preserved
666
+ // through to publish, which stores the claim as-is (shape-checked only).
667
+ const remixOf = parseRemixOfConfigField({
668
+ raw: obj["remixOf"],
669
+ schemaSupportsRemixOf: isV9 || schema === POE_TILE_CONFIG_SCHEMA_URL,
670
+ configFilename: POE_TILE_CONFIG_FILENAME,
671
+ schemaUrl: POE_TILE_CONFIG_SCHEMA_URL,
672
+ });
673
+
674
+ const visibilityRaw = obj["visibility"];
675
+ let visibility: PoeTileVisibility | undefined;
676
+ if (visibilityRaw !== undefined) {
677
+ if (
678
+ typeof visibilityRaw !== "string" ||
679
+ !isPoeTileVisibility(visibilityRaw)
680
+ ) {
681
+ throw new Error(
682
+ `${POE_TILE_CONFIG_FILENAME}.visibility must be "public", "unlisted", or "dev".`,
683
+ );
684
+ }
685
+ visibility = visibilityRaw;
686
+ }
687
+
688
+ let runtimeBundle: PoeTileConfigRuntimeBundle | undefined;
689
+ if (obj["runtimeBundle"] !== undefined) {
690
+ const rb = obj["runtimeBundle"];
691
+ if (typeof rb !== "object" || rb === null || Array.isArray(rb)) {
692
+ throw new Error(
693
+ `${POE_TILE_CONFIG_FILENAME}.runtimeBundle must be an object.`,
694
+ );
695
+ }
696
+ const rbObj = rb as Record<string, unknown>;
697
+ const dir = rbObj["dir"];
698
+ if (typeof dir !== "string" || dir.length === 0) {
699
+ throw new Error(
700
+ `${POE_TILE_CONFIG_FILENAME}.runtimeBundle.dir must be a non-empty string.`,
701
+ );
702
+ }
703
+ runtimeBundle = { dir };
704
+ }
705
+
706
+ let sourceBundle: PoeTileConfigSourceBundle | undefined;
707
+ if (obj["sourceBundle"] !== undefined) {
708
+ const sb = obj["sourceBundle"];
709
+ if (typeof sb !== "object" || sb === null || Array.isArray(sb)) {
710
+ throw new Error(
711
+ `${POE_TILE_CONFIG_FILENAME}.sourceBundle must be an object.`,
712
+ );
713
+ }
714
+ const sbObj = sb as Record<string, unknown>;
715
+ const dir = sbObj["dir"];
716
+ if (typeof dir !== "string" || dir.length === 0) {
717
+ throw new Error(
718
+ `${POE_TILE_CONFIG_FILENAME}.sourceBundle.dir must be a non-empty string.`,
719
+ );
720
+ }
721
+ const visibility = sbObj["visibility"];
722
+ if (typeof visibility !== "string") {
723
+ throw new Error(
724
+ `${POE_TILE_CONFIG_FILENAME}.sourceBundle.visibility is required when sourceBundle is set ` +
725
+ `(must be "owner_only" or "public"). Set it explicitly to avoid accidentally ` +
726
+ `uploading source under the server's "public" default.`,
727
+ );
728
+ }
729
+ if (!isSourceBundleVisibility(visibility)) {
730
+ throw new Error(
731
+ `${POE_TILE_CONFIG_FILENAME}.sourceBundle.visibility must be "owner_only" or "public" ` +
732
+ `(got ${JSON.stringify(visibility)}).`,
733
+ );
734
+ }
735
+ const ignoreFile = sbObj["ignoreFile"];
736
+ if (
737
+ ignoreFile !== undefined &&
738
+ (typeof ignoreFile !== "string" || ignoreFile.length === 0)
739
+ ) {
740
+ throw new Error(
741
+ `${POE_TILE_CONFIG_FILENAME}.sourceBundle.ignoreFile, if set, must be a non-empty string.`,
742
+ );
743
+ }
744
+ sourceBundle = {
745
+ dir,
746
+ visibility,
747
+ ...(ignoreFile !== undefined ? { ignoreFile } : {}),
748
+ };
749
+ }
750
+
751
+ return {
752
+ $schema: POE_TILE_CONFIG_SCHEMA_URL,
753
+ handle,
754
+ ...(displayName !== undefined ? { displayName } : {}),
755
+ ...(profilePicture !== undefined ? { profilePicture } : {}),
756
+ ...(shortDescription !== undefined ? { shortDescription } : {}),
757
+ ...(longDescription !== undefined ? { longDescription } : {}),
758
+ ...(screenshots !== undefined ? { screenshots } : {}),
759
+ ...(players !== undefined ? { players } : {}),
760
+ ...(video !== undefined ? { video } : {}),
761
+ ...(instancing !== undefined ? { instancing } : {}),
762
+ ...(remixOf !== undefined ? { remixOf } : {}),
763
+ ...(visibility !== undefined ? { visibility } : {}),
764
+ ...(runtimeBundle !== undefined ? { runtimeBundle } : {}),
765
+ ...(sourceBundle !== undefined ? { sourceBundle } : {}),
766
+ };
767
+ }
768
+
769
+ /**
770
+ * Write `.poe-tile.json` to `dir` with stable formatting. Used by
771
+ * `tiles init` immediately after scaffolding so the new app has a
772
+ * working config from day zero.
773
+ */
774
+ export function writePoeTileConfig(dir: string, config: PoeTileConfig): string {
775
+ // Round-trip through validatePoeTileConfig so we never write a
776
+ // config that we wouldn't accept on read.
777
+ const validated = validatePoeTileConfig(config);
778
+ const path = join(dir, POE_TILE_CONFIG_FILENAME);
779
+ // Tab-indent to match biome's default — without it, a freshly-scaffolded
780
+ // app fails the project's own `biome format` check on first commit.
781
+ const json = `${JSON.stringify(validated, null, "\t")}\n`;
782
+ writeFileSync(path, json);
783
+ return path;
784
+ }
785
+
786
+ /**
787
+ * Default config to write at scaffold time. Includes a `sourceBundle`
788
+ * block pointing at the app root with `public` visibility so that
789
+ * newly-scaffolded apps publish source by default — without source,
790
+ * the parent platform's edit/remix flows can never reach the app.
791
+ *
792
+ * Creators who want a private source bundle can flip
793
+ * `sourceBundle.visibility` to `"owner_only"`; creators who want to
794
+ * skip source upload entirely can delete the `sourceBundle` block.
795
+ * The built-in default ignore list in `source-bundle.ts` keeps
796
+ * `.env*`, `node_modules/`, `dist/`, etc. out of the public bundle.
797
+ *
798
+ * Used by `tiles init`.
799
+ */
800
+ export function defaultPoeTileConfig(opts: {
801
+ handle: string;
802
+ /**
803
+ * Omit the `sourceBundle` block. Used by `tiles init --no-store`: a
804
+ * store-less scaffold is a prototype shape, not something the platform's
805
+ * edit/remix flows are meant to reach, and skipping the source upload keeps
806
+ * its publish turn short. Defaults to including the block.
807
+ */
808
+ sourceBundle?: boolean;
809
+ }): PoeTileConfig {
810
+ const { handle, sourceBundle = true } = opts;
811
+ return {
812
+ $schema: POE_TILE_CONFIG_SCHEMA_URL,
813
+ handle,
814
+ // Placeholder metadata — the scaffold ships a README and these defaults
815
+ // so that publish works out of the box without requiring an image.
816
+ // Creators are expected to customize all fields before publishing
817
+ // (the tile-creator skill prompts for this).
818
+ displayName: `TODO: human-friendly display name (max 80 chars).`,
819
+ shortDescription: `TODO: short description for ${handle} (max 140 chars).`,
820
+ longDescription: "./README.md",
821
+ // Default runtime bundle dir matches the Vite / Bun / esbuild
822
+ // convention almost every scaffolded app uses. Apps that build
823
+ // elsewhere (e.g. `static/`) override this field in their config.
824
+ runtimeBundle: {
825
+ dir: "dist",
826
+ },
827
+ ...(sourceBundle
828
+ ? { sourceBundle: { dir: ".", visibility: "public" as const } }
829
+ : {}),
830
+ };
831
+ }