@joiner-platform/cli 0.0.0-stage → 0.1.1

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 +149 -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 +197 -0
  152. package/skills/tile-creator/references/assets.md +124 -0
  153. package/skills/tile-creator/references/backend-api.md +354 -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,4 @@
1
+ // Auto-generated by poe-tiles-sdk/scripts/publish-tar.ts — do not edit
2
+ // publishedAt: 2026-11-24T21:17:53.558Z
3
+ export const SDK_TARBALL_URL =
4
+ "https://misc-dev-uploads.quora-913.workers.dev/f8f3a9b106337f02be4e1a5bca468ff64d5834bb8766fbae7ab12ac2aee99742";
@@ -0,0 +1,31 @@
1
+ // owner: jyoung-q
2
+ /**
3
+ * Read the published poe-tiles-sdk tarball URL.
4
+ *
5
+ * `sdk-tarball-url.generated.ts` (co-located) is regenerated by
6
+ * `scripts/publish-tar.ts` on each SDK release. We read it via the filesystem
7
+ * + regex rather than importing the constant so a checkout that hasn't
8
+ * generated the file yet (or a future build that drops it) degrades to `null`
9
+ * instead of failing to import. Callers fall back to `workspace:*`.
10
+ */
11
+
12
+ import { readFileSync } from "node:fs";
13
+ import { join } from "node:path";
14
+
15
+ /**
16
+ * @param dir Directory holding `sdk-tarball-url.generated.ts`. Defaults to this
17
+ * module's directory (the real generated file); overridable for tests so the
18
+ * missing-file fallback and the no-match branch can be exercised.
19
+ */
20
+ export function readSdkTarballUrl(
21
+ dir: string = import.meta.dir,
22
+ ): string | null {
23
+ try {
24
+ const urlFile = join(dir, "sdk-tarball-url.generated.ts");
25
+ const content = readFileSync(urlFile, "utf-8");
26
+ const match = content.match(/SDK_TARBALL_URL\s*=\s*"([^"]+)"/);
27
+ return match?.[1] ?? null;
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
@@ -0,0 +1,147 @@
1
+ // owner: jyoung-q
2
+ /**
3
+ * Ink-based arrow-key picker for the `tiles init` template prompt. Sibling
4
+ * `name-input.tsx` handles the name prompt; `index.ts` wires both behind
5
+ * dynamic imports so non-interactive runs don't load Ink.
6
+ *
7
+ * Cold-start trick: this module statically imports Ink + React. Callers
8
+ * MUST gate it behind `await import("./template-picker.js")` so the Ink
9
+ * load cost is paid only when a user actually needs the picker. See the
10
+ * dynamic import in `index.ts`.
11
+ */
12
+
13
+ import type React from "react";
14
+ import { createElement, useRef, useState } from "react";
15
+ import { Box, render, Text, useInput } from "ink";
16
+ import { CliError } from "../../errors.js";
17
+ import { TEMPLATES, TEMPLATE_META, type TemplateName } from "./scaffold.js";
18
+
19
+ const NAME_COLUMN_WIDTH = Math.max(...TEMPLATES.map((t) => t.length)) + 2;
20
+
21
+ interface TemplatePickerProps {
22
+ onPick: (template: TemplateName) => void;
23
+ onCancel: () => void;
24
+ }
25
+
26
+ /**
27
+ * Stateless-from-the-outside picker. Takes `onPick` / `onCancel` callbacks
28
+ * rather than resolving a Promise internally so the component is directly
29
+ * testable through the local `render()` helper in `test-utils.ts`; the
30
+ * promise wrapping lives in `pickTemplate` below.
31
+ */
32
+ export function TemplatePicker({
33
+ onPick,
34
+ onCancel,
35
+ }: TemplatePickerProps): React.ReactElement {
36
+ const [index, setIndex] = useState(0);
37
+ // Why a ref: ink's `useInput` rebinds the handler via useEffect, which
38
+ // runs *after* commit. A fast user (or fast test) pressing arrow-then-
39
+ // enter back-to-back can fire the second key while the old handler
40
+ // closure (with the stale `index`) is still registered. Reading from
41
+ // the ref sidesteps that race.
42
+ const indexRef = useRef(index);
43
+ indexRef.current = index;
44
+
45
+ useInput((input, key) => {
46
+ if (key.ctrl && input === "c") {
47
+ onCancel();
48
+ } else if (key.upArrow) {
49
+ setIndex((i) => (i - 1 + TEMPLATES.length) % TEMPLATES.length);
50
+ } else if (key.downArrow) {
51
+ setIndex((i) => (i + 1) % TEMPLATES.length);
52
+ } else if (key.return) {
53
+ // Modulo arithmetic above guarantees the index is in range.
54
+ onPick(TEMPLATES[indexRef.current]!);
55
+ }
56
+ });
57
+
58
+ return (
59
+ <Box flexDirection="column" marginY={1}>
60
+ <Text>Select a template:</Text>
61
+ <Box flexDirection="column" marginTop={1}>
62
+ {TEMPLATES.map((name, i) => {
63
+ const meta = TEMPLATE_META[name];
64
+ const selected = i === index;
65
+ return (
66
+ <Box key={name}>
67
+ <Text color={selected ? "cyan" : undefined} bold={selected}>
68
+ {selected ? "❯ " : " "}
69
+ {name.padEnd(NAME_COLUMN_WIDTH)}
70
+ </Text>
71
+ <Text color={selected ? "cyan" : undefined} dimColor={!selected}>
72
+ {meta.description}
73
+ {meta.recommended ? " (recommended)" : ""}
74
+ </Text>
75
+ </Box>
76
+ );
77
+ })}
78
+ </Box>
79
+ <Box marginTop={1}>
80
+ <Text dimColor>
81
+ ↑/↓ to navigate · Enter to select · Ctrl-C to cancel
82
+ </Text>
83
+ </Box>
84
+ </Box>
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Minimal shape of the renderer `pickTemplate` needs. Satisfied by both
90
+ * ink's real `render` and the synthetic-stream `render` in
91
+ * `test-utils.ts`.
92
+ */
93
+ export type InkRenderer = (tree: React.ReactElement) => {
94
+ unmount: () => void;
95
+ };
96
+
97
+ /**
98
+ * Production default for `pickTemplate`'s `renderFn` parameter.
99
+ * Exported so it can be unit-tested directly via
100
+ * `spyOn(inkModule, "render")`.
101
+ */
102
+ export const defaultRenderer: InkRenderer = (tree) =>
103
+ render(tree, { exitOnCtrlC: false });
104
+
105
+ /**
106
+ * Mount `<TemplatePicker>` against the real terminal and resolve with the
107
+ * user's selection. Throws `CliError` when stdout isn't a TTY (so non-TTY
108
+ * callers get a clear pointer to `--template` instead of a hung process)
109
+ * or when the user presses Ctrl-C.
110
+ *
111
+ * `exitOnCtrlC: false` so cancellation surfaces as a `CliError` the
112
+ * action-handler can act on, instead of Ink calling `process.exit(0)`
113
+ * and leaving the user with no "Cancelled." feedback.
114
+ *
115
+ * `renderFn` is injectable so the wrapper body is fully covered in
116
+ * tests via the synthetic-stream `render` in `test-utils.ts`.
117
+ * Production callers pass nothing and get `defaultRenderer`.
118
+ */
119
+ export async function pickTemplate(
120
+ renderFn: InkRenderer = defaultRenderer,
121
+ ): Promise<TemplateName> {
122
+ // Check BOTH streams: stdin must be a TTY for Ink's `useInput` to call
123
+ // `setRawMode` (otherwise Ink throws inside a useEffect AFTER
124
+ // pickTemplate has returned its Promise — the throw never rejects the
125
+ // Promise, so the process hangs with a stack trace). stdout must be a
126
+ // TTY for ink to render frames the user can see.
127
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
128
+ throw new CliError(
129
+ `Cannot pick a template interactively in a non-TTY environment. ` +
130
+ `Pass --template <name> (one of: ${TEMPLATES.join(", ")}).`,
131
+ );
132
+ }
133
+ return new Promise<TemplateName>((resolve, reject) => {
134
+ const instance = renderFn(
135
+ createElement(TemplatePicker, {
136
+ onPick: (template: TemplateName) => {
137
+ instance.unmount();
138
+ resolve(template);
139
+ },
140
+ onCancel: () => {
141
+ instance.unmount();
142
+ reject(new CliError("Cancelled."));
143
+ },
144
+ }),
145
+ );
146
+ });
147
+ }
@@ -0,0 +1,107 @@
1
+ // owner: aaronroe
2
+ import { SDK_PACKAGE_NAMES } from "../sdk-dependency.js";
3
+
4
+ /**
5
+ * The child entry, written into the run directory. It runs the variant with
6
+ * the tile's own SDK, aborts on SIGTERM, SIGINT, or a parent that is no
7
+ * longer the CLI (the CLI's watchdog also sends SIGTERM when the CLI is gone;
8
+ * see inspect-watchdog.ts), and
9
+ * reports usage errors in `error.json` with exit 2. With `--rebuild` it
10
+ * writes a killed variant's report, rebuilt from the progress log, to the
11
+ * given file.
12
+ */
13
+
14
+ /**
15
+ * The tile's inspect module under each SDK key, in the order `resolveFrom`
16
+ * tries them in `inspect-options.ts`: `joiner-sdk` first, then `poe-tiles-sdk`.
17
+ */
18
+ export const SDK_INSPECT_SPECIFIERS = SDK_PACKAGE_NAMES.map(
19
+ (name) => `${name}/v1/test-utils/inspect.js`,
20
+ );
21
+
22
+ /**
23
+ * Child-side source that picks the first specifier that resolves from the
24
+ * tile. When none resolves, the last one is imported so the error names it.
25
+ */
26
+ const SDK_SPECIFIER_SOURCE = `const SDK_INSPECT_SPECIFIERS = ${JSON.stringify(SDK_INSPECT_SPECIFIERS)};
27
+ const sdkInspectSpecifier = () => {
28
+ for (const specifier of SDK_INSPECT_SPECIFIERS) {
29
+ try {
30
+ import.meta.resolve(specifier);
31
+ return specifier;
32
+ } catch {}
33
+ }
34
+ return SDK_INSPECT_SPECIFIERS[SDK_INSPECT_SPECIFIERS.length - 1];
35
+ };`;
36
+ export const CHILD_ENTRY = `// Written by poe-tiles tiles inspect. Runs one variant.
37
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
38
+ import { join } from "node:path";
39
+
40
+ ${SDK_SPECIFIER_SOURCE}
41
+ const loadSdk = () => import(sdkInspectSpecifier());
42
+
43
+ if (process.argv[2] === "--rebuild") {
44
+ const sdk = await loadSdk();
45
+ writeFileSync(process.argv[5], JSON.stringify(sdk.variantReportFromProgress(process.argv[3], process.argv[4])));
46
+ process.exit(0);
47
+ }
48
+
49
+ const input = JSON.parse(readFileSync(process.argv[2], "utf8"));
50
+
51
+ // Two layers against a lost CLI. Here, when the loop is idle: the parent is
52
+ // no longer the CLI whose pid was passed in (compared from the start, so a
53
+ // CLI lost during the imports below counts). And the CLI's watchdog, a
54
+ // separate process, sends SIGTERM, then SIGKILL, even when a script blocks
55
+ // the loop (inspect-watchdog.ts).
56
+ const controller = new AbortController();
57
+ for (const signal of ["SIGTERM", "SIGINT"]) process.on(signal, () => controller.abort());
58
+ setInterval(() => {
59
+ if (process.ppid !== input.parentPid) controller.abort();
60
+ }, 500).unref();
61
+
62
+ const fail = (code, message) => {
63
+ const dir = join(input.options.runDir, input.variantId);
64
+ mkdirSync(dir, { recursive: true });
65
+ writeFileSync(join(dir, "error.json"), JSON.stringify({ error: { code, message } }));
66
+ process.exit(2);
67
+ };
68
+ const message = (error) => (error instanceof Error ? error.message : String(error));
69
+
70
+ let playwright;
71
+ let sdk;
72
+ try {
73
+ playwright = await import("@playwright/test");
74
+ } catch (error) {
75
+ fail("playwright-missing", "@playwright/test did not load from this tile: " + message(error));
76
+ }
77
+ try {
78
+ sdk = await loadSdk();
79
+ } catch (error) {
80
+ fail("sdk-unsupported", "this tile's SDK has no inspect module: " + message(error));
81
+ }
82
+ if (!input.supportedContracts.includes(sdk.INSPECT_CONTRACT_VERSION)) {
83
+ fail("contract-unsupported", "this tile's SDK speaks inspect contract " + sdk.INSPECT_CONTRACT_VERSION + "; this CLI supports " + input.supportedContracts.join(", "));
84
+ }
85
+
86
+ // The tile's SDK has the last word on the --ready target the CLI checked.
87
+ const readyProblem = input.options.ready && typeof sdk.checkInspectTarget === "function" ? sdk.checkInspectTarget(input.options.ready) : null;
88
+ if (readyProblem) fail("invalid-options", "--" + readyProblem);
89
+
90
+ try {
91
+ await sdk.runTileInspection({
92
+ ...input.options,
93
+ time: input.options.time ? new Date(input.options.time) : null,
94
+ playwright: { chromium: playwright.chromium, devices: playwright.devices, expect: playwright.expect },
95
+ signal: controller.signal,
96
+ });
97
+ process.exit(0);
98
+ } catch (error) {
99
+ if (error instanceof sdk.InspectUsageError) fail(error.code, error.message);
100
+ console.error(error instanceof Error ? error.stack : String(error));
101
+ process.exit(1);
102
+ }
103
+ `;
104
+
105
+ /** Prints the tile's code-mode declarations, for `tiles inspect --help`. */
106
+ export const CODE_API_SNIPPET = `${SDK_SPECIFIER_SOURCE}
107
+ const m = await import(sdkInspectSpecifier()); process.stdout.write(m.inspectCodeDeclarations());`;
@@ -0,0 +1,87 @@
1
+ // owner: aaronroe
2
+ /**
3
+ * The inspect report as this CLI reads it: contract version 1 of
4
+ * `joiner-sdk/v1/test-utils/inspect.js`. Declared here because the
5
+ * tile's SDK, not the CLI's, writes the reports; a tile whose SDK speaks
6
+ * another version is refused before it runs.
7
+ */
8
+
9
+ export type InspectStepIndex = number | string;
10
+
11
+ export type InspectOutcome =
12
+ | { kind: "passed" }
13
+ | { kind: "step-failed"; step: InspectStepIndex; error: string }
14
+ | { kind: "page-error"; step: InspectStepIndex; error: string }
15
+ | { kind: "timed-out"; lastCompletedStep: InspectStepIndex | null }
16
+ | { kind: "not-started" };
17
+
18
+ export interface InspectArtifact {
19
+ kind: "screenshot" | "snapshot" | "value";
20
+ player: number | null;
21
+ client: string | null;
22
+ at: { step: InspectStepIndex } | "final" | "failure";
23
+ name: string | null;
24
+ path: string | null;
25
+ inline: string | null;
26
+ }
27
+
28
+ export interface InspectVariantReport {
29
+ id: string;
30
+ viewport: "phone" | "feed-mobile" | "feed-desktop";
31
+ colorScheme: "light" | "dark";
32
+ outcome: InspectOutcome;
33
+ timings: {
34
+ serverMs: number;
35
+ browserMs: number;
36
+ openMs: number;
37
+ bodyMs: number;
38
+ };
39
+ clients: Array<{
40
+ player: number;
41
+ userId: string;
42
+ clientId: string;
43
+ consoleErrors: string[];
44
+ consoleWarnings: string[];
45
+ pageErrors: string[];
46
+ failedRequests: string[];
47
+ }>;
48
+ steps: Array<{
49
+ index: InspectStepIndex;
50
+ player: number | "all" | null;
51
+ action: string;
52
+ ok: boolean;
53
+ caught: boolean;
54
+ interrupted: boolean;
55
+ ms: number;
56
+ error: string | null;
57
+ }>;
58
+ artifacts: InspectArtifact[];
59
+ actions: Record<string, number>;
60
+ output: string | null;
61
+ returnValue: string | null;
62
+ warnings: string[];
63
+ truncated: string[];
64
+ }
65
+
66
+ export interface InspectReport {
67
+ contractVersion: number;
68
+ runId: string;
69
+ mode: "code" | "script" | "look";
70
+ outcome: "passed" | "failed" | "timed-out";
71
+ stage: "queued" | "building" | "running" | "done";
72
+ timings: {
73
+ slotWaitMs: number;
74
+ buildMs: number;
75
+ variantsMs: number;
76
+ totalMs: number;
77
+ };
78
+ build: {
79
+ ran: boolean;
80
+ reason: "missing" | "changed" | "dist-changed" | null;
81
+ sourceFingerprint: string;
82
+ distFingerprint: string;
83
+ };
84
+ warnings: string[];
85
+ variants: InspectVariantReport[];
86
+ truncated: string[];
87
+ }
@@ -0,0 +1,217 @@
1
+ // owner: aaronroe
2
+ /**
3
+ * Build freshness for `tiles inspect`: content fingerprints of the tile's
4
+ * source (the files the source bundle would publish) and of `dist`, and the
5
+ * record of the last build inspect ran.
6
+ */
7
+
8
+ import { createHash } from "node:crypto";
9
+ import {
10
+ closeSync,
11
+ existsSync,
12
+ openSync,
13
+ readdirSync,
14
+ readFileSync,
15
+ readSync,
16
+ statSync,
17
+ writeFileSync,
18
+ } from "node:fs";
19
+ import { join, relative } from "node:path";
20
+ import {
21
+ RUNTIME_BUNDLE_MAX_FILE_BYTES,
22
+ RUNTIME_BUNDLE_MAX_FILES,
23
+ RUNTIME_BUNDLE_MAX_TOTAL_BYTES,
24
+ } from "../collect-files.js";
25
+ import {
26
+ collectSourceFiles,
27
+ normalizeSourceBundlePath,
28
+ } from "../source-bundle.js";
29
+ import { InspectExit2 } from "./inspect-options.js";
30
+
31
+ export type StaleReason = "missing" | "changed" | "dist-changed";
32
+
33
+ /** A source with no fingerprint; it always counts as changed. */
34
+ export const UNFINGERPRINTED = "unfingerprinted";
35
+
36
+ export interface BuildRecord {
37
+ sourceFingerprint: string;
38
+ distFingerprint: string;
39
+ }
40
+
41
+ const byPath = (a: { path: string }, b: { path: string }) =>
42
+ a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
43
+
44
+ function hashFiles(
45
+ files: ReadonlyArray<{ path: string; data: Uint8Array }>,
46
+ ): string {
47
+ const hash = createHash("sha256");
48
+ for (const file of [...files].sort(byPath)) {
49
+ hash.update(`${file.path}\0${file.data.length}\0`);
50
+ hash.update(file.data);
51
+ }
52
+ return hash.digest("hex");
53
+ }
54
+
55
+ /**
56
+ * SHA-256 over the sorted paths and contents of the tile's source, as the
57
+ * source bundle defines it (its default ignores plus the tile's
58
+ * `.gitignore`), which already leaves out `dist`, `node_modules`, and
59
+ * `.visual-checks/`. When the source cannot be read (past the bundle's
60
+ * limits, an unreadable directory) the fingerprint is UNFINGERPRINTED and
61
+ * `problem` says why.
62
+ */
63
+ export function fingerprintSource(tileDir: string): {
64
+ fingerprint: string;
65
+ problem: string | null;
66
+ } {
67
+ try {
68
+ return {
69
+ fingerprint: hashFiles(collectSourceFiles(tileDir).files),
70
+ problem: null,
71
+ };
72
+ } catch (error) {
73
+ return {
74
+ fingerprint: UNFINGERPRINTED,
75
+ problem: error instanceof Error ? error.message : String(error),
76
+ };
77
+ }
78
+ }
79
+
80
+ export function sourceFingerprint(tileDir: string): string {
81
+ return fingerprintSource(tileDir).fingerprint;
82
+ }
83
+
84
+ /**
85
+ * Limits on `dist/`, the runtime bundle's publish limits: a build past them
86
+ * cannot publish, and inspect will not read it. They are checked on file
87
+ * sizes before any file is read.
88
+ */
89
+ export const DIST_LIMITS = {
90
+ files: RUNTIME_BUNDLE_MAX_FILES,
91
+ totalBytes: RUNTIME_BUNDLE_MAX_TOTAL_BYTES,
92
+ fileBytes: RUNTIME_BUNDLE_MAX_FILE_BYTES,
93
+ } as const;
94
+
95
+ export type DistLimits = { [K in keyof typeof DIST_LIMITS]: number };
96
+
97
+ interface DistFile {
98
+ path: string;
99
+ full: string;
100
+ size: number;
101
+ }
102
+
103
+ function distTooLarge(problem: string): InspectExit2 {
104
+ return new InspectExit2(
105
+ "dist-too-large",
106
+ `${problem}, so inspect will not read it (a build over the runtime bundle limits cannot publish either)`,
107
+ );
108
+ }
109
+
110
+ /** Lists `dist`'s files, refusing it by count and size before reading any. */
111
+ function listDist(
112
+ root: string,
113
+ dir: string,
114
+ limits: DistLimits,
115
+ state: { files: DistFile[]; bytes: number },
116
+ ): void {
117
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
118
+ const full = join(dir, entry.name);
119
+ if (entry.isDirectory()) listDist(root, full, limits, state);
120
+ if (!entry.isFile()) continue;
121
+ const file = {
122
+ path: normalizeSourceBundlePath(relative(root, full)),
123
+ full,
124
+ size: statSync(full).size,
125
+ };
126
+ state.files.push(file);
127
+ state.bytes += file.size;
128
+ checkDist(file, limits, state);
129
+ }
130
+ }
131
+
132
+ /** Throws when the file just listed takes `dist` past a limit. */
133
+ function checkDist(
134
+ file: DistFile,
135
+ limits: DistLimits,
136
+ state: { files: DistFile[]; bytes: number },
137
+ ): void {
138
+ if (file.size > limits.fileBytes)
139
+ throw distTooLarge(
140
+ `dist/${file.path} is ${file.size} bytes, over the ${limits.fileBytes}-byte limit for one file`,
141
+ );
142
+ if (state.files.length > limits.files)
143
+ throw distTooLarge(`dist/ has over ${limits.files} files`);
144
+ if (state.bytes > limits.totalBytes)
145
+ throw distTooLarge(`dist/ is over ${limits.totalBytes} bytes`);
146
+ }
147
+
148
+ /**
149
+ * The same hash as the source's over every file in `dist`, read one file at
150
+ * a time and at most its listed size; null when `dist` is missing or empty.
151
+ * Throws InspectExit2 past DIST_LIMITS.
152
+ */
153
+ export function distFingerprint(
154
+ distDir: string,
155
+ limits: DistLimits = DIST_LIMITS,
156
+ ): string | null {
157
+ if (!existsSync(distDir)) return null;
158
+ const state = { files: [] as DistFile[], bytes: 0 };
159
+ listDist(distDir, distDir, limits, state);
160
+ if (state.files.length === 0) return null;
161
+ const hash = createHash("sha256");
162
+ for (const file of state.files.sort(byPath)) {
163
+ const data = readListedSize(file);
164
+ hash.update(`${file.path}\0${data.length}\0`);
165
+ hash.update(data);
166
+ }
167
+ return hash.digest("hex");
168
+ }
169
+
170
+ /** At most the listed size of a file, so one that grows is still bounded. */
171
+ function readListedSize(file: DistFile): Uint8Array {
172
+ const fd = openSync(file.full, "r");
173
+ try {
174
+ const buffer = Buffer.alloc(file.size);
175
+ return buffer.subarray(0, readSync(fd, buffer, 0, file.size, 0));
176
+ } finally {
177
+ closeSync(fd);
178
+ }
179
+ }
180
+
181
+ export function readBuildRecord(path: string): BuildRecord | null {
182
+ try {
183
+ const record = JSON.parse(
184
+ readFileSync(path, "utf8"),
185
+ ) as Partial<BuildRecord>;
186
+ return typeof record.sourceFingerprint === "string" &&
187
+ typeof record.distFingerprint === "string"
188
+ ? {
189
+ sourceFingerprint: record.sourceFingerprint,
190
+ distFingerprint: record.distFingerprint,
191
+ }
192
+ : null;
193
+ } catch {
194
+ return null;
195
+ }
196
+ }
197
+
198
+ export function writeBuildRecord(path: string, record: BuildRecord): void {
199
+ writeFileSync(path, `${JSON.stringify(record, null, "\t")}\n`);
200
+ }
201
+
202
+ /** Why the build must run, or null when `dist` is the recorded build of this source. */
203
+ export function staleReason(
204
+ source: string,
205
+ dist: string | null,
206
+ record: BuildRecord | null,
207
+ ): StaleReason | null {
208
+ if (dist === null) return "missing";
209
+ if (
210
+ source === UNFINGERPRINTED ||
211
+ record === null ||
212
+ record.sourceFingerprint !== source
213
+ )
214
+ return "changed";
215
+ if (record.distFingerprint !== dist) return "dist-changed";
216
+ return null;
217
+ }