@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,198 @@
1
+ // owner: jyoung-q
2
+ /**
3
+ * Authentication token discovery for the CLI entry points.
4
+ */
5
+
6
+ import {
7
+ chmodSync,
8
+ existsSync,
9
+ mkdirSync,
10
+ readFileSync,
11
+ rmSync,
12
+ statSync,
13
+ writeFileSync,
14
+ } from "node:fs";
15
+ import { homedir } from "node:os";
16
+ import { dirname, join } from "node:path";
17
+ import { readCliEnv } from "./cli-env.js";
18
+ import { cliName } from "./cli-name.js";
19
+ import { CliError } from "./errors.js";
20
+
21
+ export const POE_TILES_CONFIG_DIR = ".poe-tiles";
22
+ export const POE_TILES_API_KEY_FILENAME = "poe-tiles-api-key";
23
+ export const POE_TILES_SESSION_TOKEN_FILENAME = "poe-tiles-session-token";
24
+
25
+ export interface PoeApiKeyFileSystem {
26
+ existsSync(path: string): boolean;
27
+ statSync(path: string): { isFile(): boolean };
28
+ readFileSync(path: string, encoding: "utf8"): string;
29
+ }
30
+
31
+ const nodeFileSystem: PoeApiKeyFileSystem = {
32
+ existsSync,
33
+ statSync,
34
+ readFileSync: (path, encoding) => readFileSync(path, encoding),
35
+ };
36
+
37
+ export interface ResolvePoeApiKeyOptions {
38
+ apiKey?: string;
39
+ env: Record<string, string | undefined>;
40
+ fileSystem?: PoeApiKeyFileSystem;
41
+ homeDir?: string;
42
+ }
43
+
44
+ export interface ResolvePoeTilesSessionTokenOptions {
45
+ env: Record<string, string | undefined>;
46
+ fileSystem?: PoeApiKeyFileSystem;
47
+ homeDir?: string;
48
+ }
49
+
50
+ export function resolvePoeApiKey({
51
+ apiKey,
52
+ env,
53
+ fileSystem = nodeFileSystem,
54
+ homeDir = homedir(),
55
+ }: ResolvePoeApiKeyOptions): string | undefined {
56
+ const explicitToken = apiKey?.trim();
57
+ if (explicitToken) return explicitToken;
58
+
59
+ const envToken = env["POE_API_KEY"]?.trim();
60
+ if (envToken) return envToken;
61
+
62
+ const tokenPath = poeTilesApiKeyPath({ homeDir });
63
+ if (!fileSystem.existsSync(tokenPath)) return undefined;
64
+ return readPoeTilesTokenFile({
65
+ fileSystem,
66
+ tokenPath,
67
+ tokenDescription: "Poe Tiles API key",
68
+ });
69
+ }
70
+
71
+ export function resolvePoeTilesSessionToken({
72
+ env,
73
+ fileSystem = nodeFileSystem,
74
+ homeDir = homedir(),
75
+ }: ResolvePoeTilesSessionTokenOptions): string | undefined {
76
+ const envToken = readCliEnv(env, "SESSION_TOKEN");
77
+ if (envToken) return envToken;
78
+
79
+ const tokenPath = poeTilesSessionTokenPath({ homeDir });
80
+ if (!fileSystem.existsSync(tokenPath)) return undefined;
81
+ return readPoeTilesTokenFile({
82
+ fileSystem,
83
+ tokenPath,
84
+ tokenDescription: "Poe Tiles session token",
85
+ });
86
+ }
87
+
88
+ export function missingPoeApiKeyMessage(): string {
89
+ const tokenPath = poeTilesApiKeyPath({ homeDir: "~" });
90
+ return (
91
+ `--api-key, POE_API_KEY environment variable, or ${tokenPath} file is required.\n` +
92
+ "Get your key at https://poe.com/api/keys\n" +
93
+ `To use a local token file, save the raw key in ${tokenPath}.`
94
+ );
95
+ }
96
+
97
+ export function missingPoeCliCredentialMessage(): string {
98
+ const apiKeyPath = poeTilesApiKeyPath({ homeDir: "~" });
99
+ const sessionPath = poeTilesSessionTokenPath({ homeDir: "~" });
100
+ return (
101
+ `Run ${cliName()} login to create a local session token, or provide --api-key, POE_API_KEY, or ${apiKeyPath}.\n` +
102
+ `For automation, POE_TILES_SESSION_TOKEN or ${sessionPath} can provide an existing session token.`
103
+ );
104
+ }
105
+
106
+ export function poeTilesApiKeyPath({
107
+ homeDir = homedir(),
108
+ }: {
109
+ homeDir?: string;
110
+ } = {}): string {
111
+ return join(homeDir, POE_TILES_CONFIG_DIR, POE_TILES_API_KEY_FILENAME);
112
+ }
113
+
114
+ export function poeTilesSessionTokenPath({
115
+ homeDir = homedir(),
116
+ }: {
117
+ homeDir?: string;
118
+ } = {}): string {
119
+ return join(homeDir, POE_TILES_CONFIG_DIR, POE_TILES_SESSION_TOKEN_FILENAME);
120
+ }
121
+
122
+ export function writePoeTilesSessionToken({
123
+ sessionToken,
124
+ homeDir = homedir(),
125
+ }: {
126
+ sessionToken: string;
127
+ homeDir?: string;
128
+ }): string {
129
+ const tokenPath = poeTilesSessionTokenPath({ homeDir });
130
+ mkdirSync(dirname(tokenPath), { recursive: true });
131
+ writeFileSync(tokenPath, `${sessionToken.trim()}\n`, {
132
+ encoding: "utf8",
133
+ mode: 0o600,
134
+ });
135
+ chmodSync(tokenPath, 0o600);
136
+ return tokenPath;
137
+ }
138
+
139
+ export function removePoeTilesSessionToken({
140
+ homeDir = homedir(),
141
+ }: {
142
+ homeDir?: string;
143
+ } = {}): void {
144
+ rmSync(poeTilesSessionTokenPath({ homeDir }), { force: true });
145
+ }
146
+
147
+ function readPoeTilesTokenFile({
148
+ fileSystem,
149
+ tokenPath,
150
+ tokenDescription,
151
+ }: {
152
+ fileSystem: PoeApiKeyFileSystem;
153
+ tokenPath: string;
154
+ tokenDescription: string;
155
+ }): string {
156
+ let stats: ReturnType<PoeApiKeyFileSystem["statSync"]>;
157
+ try {
158
+ stats = fileSystem.statSync(tokenPath);
159
+ } catch (error) {
160
+ throw new CliError(
161
+ `Could not read ${tokenDescription} file: ${errorMessage(error)}`,
162
+ );
163
+ }
164
+ if (!stats.isFile()) {
165
+ throw new CliError(
166
+ `${tokenDescription} path must be a regular file: ${tokenPath}`,
167
+ );
168
+ }
169
+
170
+ let raw: string;
171
+ try {
172
+ raw = fileSystem.readFileSync(tokenPath, "utf8");
173
+ } catch (error) {
174
+ throw new CliError(
175
+ `Could not read ${tokenDescription} file: ${errorMessage(error)}`,
176
+ );
177
+ }
178
+
179
+ const nonEmptyLines = raw
180
+ .split(/\r?\n/)
181
+ .map((line) => line.trim())
182
+ .filter((line) => line.length > 0);
183
+
184
+ if (nonEmptyLines.length === 0) {
185
+ throw new CliError(`${tokenDescription} file is empty: ${tokenPath}`);
186
+ }
187
+ if (nonEmptyLines.length > 1) {
188
+ throw new CliError(
189
+ `${tokenDescription} file must contain exactly one token line: ${tokenPath}`,
190
+ );
191
+ }
192
+
193
+ return nonEmptyLines[0]!;
194
+ }
195
+
196
+ function errorMessage(error: unknown): string {
197
+ return error instanceof Error ? error.message : String(error);
198
+ }
@@ -0,0 +1,35 @@
1
+ // owner: aaronroe
2
+
3
+ /**
4
+ * A file read that refuses the file by its SIZE before allocating its
5
+ * contents, then checks the bytes it got for a file that grew in between.
6
+ *
7
+ * Every variable-size input the publish reads goes through here — config
8
+ * files, ignore files, the long description, media, and (with their own
9
+ * budgets) the bundle walks. The server caps them all anyway; the point of
10
+ * checking first is that Creator's bridge runs this code in its own process,
11
+ * where a multi-gigabyte file the server would refuse is not a failed publish
12
+ * but a stalled session.
13
+ */
14
+
15
+ import { readFileSync, statSync } from "node:fs";
16
+
17
+ export function readBoundedFile(
18
+ path: string,
19
+ maxBytes: number,
20
+ overCap: (size: number) => Error,
21
+ ): Uint8Array {
22
+ const size = statSync(path).size;
23
+ if (size > maxBytes) throw overCap(size);
24
+ const bytes = new Uint8Array(readFileSync(path));
25
+ if (bytes.byteLength > maxBytes) throw overCap(bytes.byteLength);
26
+ return bytes;
27
+ }
28
+
29
+ export function readBoundedText(
30
+ path: string,
31
+ maxBytes: number,
32
+ overCap: (size: number) => Error,
33
+ ): string {
34
+ return new TextDecoder().decode(readBoundedFile(path, maxBytes, overCap));
35
+ }
@@ -0,0 +1,33 @@
1
+ // owner: jyoung-q
2
+ /** Also copied into standalone scaffolds so checks do not require the CLI. */
3
+ export const TESTED_BUN_RANGE = ">=1.4.2 <1.5.0";
4
+
5
+ /** Any other Bun 1.x is allowed with a warning; only non-1.x fails. */
6
+ export type BunSupport = "tested" | "untested" | "unsupported";
7
+
8
+ export function bunSupport(version: string): BunSupport {
9
+ const match = /^(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.+-]+)?$/.exec(version.trim());
10
+ if (!match || Number(match[1]) !== 1) return "unsupported";
11
+ const tested =
12
+ Number(match[2]) === 4 && Number(match[3]) >= 2 && match[4] === undefined;
13
+ return tested ? "tested" : "untested";
14
+ }
15
+
16
+ export function untestedBunWarning(version: string): string {
17
+ return `Bun ${version} is untested; this creator toolchain is tested with Bun ${TESTED_BUN_RANGE}. If install, build, or preview fails, install Bun 1.4.2 using https://bun.com/docs/installation#installing-older-versions.`;
18
+ }
19
+
20
+ export function assertSupportedBun(
21
+ version = Bun.version,
22
+ warn: (message: string) => void = console.warn,
23
+ ): void {
24
+ const support = bunSupport(version);
25
+ if (support === "unsupported") {
26
+ throw new Error(
27
+ `Found Bun ${version}; this creator toolchain needs Bun 1.x and is tested with ${TESTED_BUN_RANGE}. Install Bun 1.4.2 using https://bun.com/docs/installation#installing-older-versions, then retry.`,
28
+ );
29
+ }
30
+ if (support === "untested") warn(untestedBunWarning(version));
31
+ }
32
+
33
+ if (import.meta.main) assertSupportedBun();
@@ -0,0 +1,207 @@
1
+ // owner: aaronroe
2
+ /**
3
+ * The version a `tiles checkout` folder was taken from, so a later deploy from
4
+ * that folder can notice newer versions it would replace.
5
+ *
6
+ * External publishes have no server-side guard: Creator is the one that must
7
+ * merge or confirm (`docs/publish-recovery.md`). A creator who checks out a
8
+ * tile, goes back to Creator, keeps publishing there, and later deploys the old
9
+ * folder would silently replace that newer Creator work. This file is what lets
10
+ * the CLI ask first.
11
+ *
12
+ * The name ends in `.log` so the source-bundle walk excludes it even in a CLI
13
+ * that predates its explicit entry in `DEFAULT_SOURCE_BUNDLE_IGNORES`: it is
14
+ * local state, not tile source, and must not reach Creator through a merge.
15
+ */
16
+
17
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
18
+ import { join } from "node:path";
19
+ import { createInterface } from "node:readline/promises";
20
+ import type { SlopPoeClient } from "./client.js";
21
+ import { CliError } from "./errors.js";
22
+
23
+ export const CHECKOUT_BASE_FILE = ".poe-checkout.log";
24
+
25
+ export type CheckoutBase = { tileId: string; baseVersion: number };
26
+
27
+ /** Record the version a folder now matches. */
28
+ export function writeCheckoutBase(dir: string, base: CheckoutBase): void {
29
+ writeFileSync(
30
+ join(dir, CHECKOUT_BASE_FILE),
31
+ `${JSON.stringify(base, null, "\t")}\n`,
32
+ );
33
+ }
34
+
35
+ /**
36
+ * The recorded base, or `null` when there is none. Throws when a record exists
37
+ * but cannot be read or parsed, so the caller can say the check is off.
38
+ */
39
+ export function readCheckoutBase(dir: string): CheckoutBase | null {
40
+ const path = join(dir, CHECKOUT_BASE_FILE);
41
+ if (!existsSync(path)) return null;
42
+ let parsed: unknown;
43
+ try {
44
+ parsed = JSON.parse(readFileSync(path, "utf8")) as unknown;
45
+ } catch (error) {
46
+ throw new Error(`${CHECKOUT_BASE_FILE} is unreadable (${describe(error)})`);
47
+ }
48
+ const { tileId, baseVersion } =
49
+ typeof parsed === "object" && parsed !== null
50
+ ? (parsed as Record<string, unknown>)
51
+ : {};
52
+ if (
53
+ typeof tileId !== "string" ||
54
+ tileId === "" ||
55
+ !Number.isSafeInteger(baseVersion) ||
56
+ (baseVersion as number) < 1
57
+ ) {
58
+ throw new Error(
59
+ `${CHECKOUT_BASE_FILE} has no valid tileId and baseVersion`,
60
+ );
61
+ }
62
+ return { tileId, baseVersion: baseVersion as number };
63
+ }
64
+
65
+ function describe(error: unknown): string {
66
+ return error instanceof Error ? error.message : String(error);
67
+ }
68
+
69
+ /** Ask a yes/no question on the terminal; anything but "y"/"yes" is no. */
70
+ export type ConfirmPrompt = (question: string) => Promise<boolean>;
71
+
72
+ export const terminalConfirm: ConfirmPrompt = async (question) => {
73
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
74
+ try {
75
+ const answer = await rl.question(`${question} [y/N] `);
76
+ return /^y(es)?$/i.test(answer.trim());
77
+ } finally {
78
+ rl.close();
79
+ }
80
+ };
81
+
82
+ /**
83
+ * Refuse, or ask before, a deploy that would replace versions published after
84
+ * this folder's checkout. Folders without a recorded base (scaffolded, or
85
+ * checked out by an older CLI) are not checked, and neither is a deploy whose
86
+ * handle names another tile. An unreadable record or a failed tile read warns
87
+ * and continues: this check protects against a mistake, it is not a lock.
88
+ */
89
+ export async function confirmCheckoutIsCurrent(input: {
90
+ client: Pick<SlopPoeClient, "getTile" | "listTileVersions">;
91
+ dir: string;
92
+ /** The handle this deploy publishes to, when known. */
93
+ handle: string | undefined;
94
+ /** Can a person answer a prompt (a TTY, and not `--json`)? */
95
+ interactive: boolean;
96
+ /** `--overwrite-newer`: the caller already accepted replacing newer versions. */
97
+ overwriteNewer: boolean;
98
+ confirm?: ConfirmPrompt;
99
+ warn?: (message: string) => void;
100
+ }): Promise<void> {
101
+ const warn = input.warn ?? ((message: string) => console.error(message));
102
+ const message = await describeNewerVersions(input, warn);
103
+ if (message === undefined) return;
104
+ if (input.overwriteNewer) {
105
+ warn(`${message} Continuing because --overwrite-newer was passed.`);
106
+ return;
107
+ }
108
+ if (!input.interactive) {
109
+ throw new CliError(
110
+ `${message} Check out the tile again into a new folder and copy your changes into it, ` +
111
+ "or pass --overwrite-newer to replace them.",
112
+ );
113
+ }
114
+ const confirm = input.confirm ?? terminalConfirm;
115
+ if (!(await confirm(`${message} Deploy anyway?`))) {
116
+ throw new CliError(
117
+ "Deploy canceled. To keep the newer changes, check out the tile again into a new folder and copy your changes into it.",
118
+ );
119
+ }
120
+ }
121
+
122
+ /**
123
+ * The versions this deploy would replace, as a message, or `undefined` when it
124
+ * replaces none or cannot tell (it warns then).
125
+ */
126
+ async function describeNewerVersions(
127
+ input: {
128
+ client: Pick<SlopPoeClient, "getTile" | "listTileVersions">;
129
+ dir: string;
130
+ handle: string | undefined;
131
+ },
132
+ warn: (message: string) => void,
133
+ ): Promise<string | undefined> {
134
+ let base: CheckoutBase | null;
135
+ try {
136
+ base = readCheckoutBase(input.dir);
137
+ } catch (error) {
138
+ warn(
139
+ `${describe(error)}, so this deploy cannot check whether it replaces newer versions; deploying anyway.`,
140
+ );
141
+ return undefined;
142
+ }
143
+ if (base === null) return undefined;
144
+ const recorded = await readRecordedTile(input.client, base.tileId);
145
+ if (recorded === undefined) {
146
+ warn(
147
+ "Could not check whether this tile has newer versions than this folder; deploying anyway.",
148
+ );
149
+ return undefined;
150
+ }
151
+ // The handle names another tile, so the recorded tile's versions are not at risk.
152
+ if (input.handle !== undefined && input.handle !== recorded.handle)
153
+ return undefined;
154
+ const latest = recorded.latestVersion;
155
+ if (latest <= base.baseVersion) return undefined;
156
+ return (
157
+ `This folder was checked out at version ${base.baseVersion}, but version ${latest} ` +
158
+ "has been published since, for example from Creator. Deploying this folder replaces " +
159
+ "those newer changes."
160
+ );
161
+ }
162
+
163
+ /** The recorded tile's current handle and latest version, or `undefined`. */
164
+ async function readRecordedTile(
165
+ client: Pick<SlopPoeClient, "getTile" | "listTileVersions">,
166
+ tileId: string,
167
+ ): Promise<{ handle: string; latestVersion: number } | undefined> {
168
+ try {
169
+ const [lookup, page] = await Promise.all([
170
+ client.getTile(tileId),
171
+ client.listTileVersions(tileId, 1),
172
+ ]);
173
+ const latestVersion = page.success
174
+ ? page.versions[0]?.versionNumber
175
+ : undefined;
176
+ if (!lookup.success || latestVersion === undefined) return undefined;
177
+ return { handle: lookup.tile.handle, latestVersion };
178
+ } catch {
179
+ return undefined;
180
+ }
181
+ }
182
+
183
+ /**
184
+ * After a deploy lands, the folder matches the version it just published. The
185
+ * deploy has already landed, so a record that cannot be read or written warns
186
+ * and does not fail the command.
187
+ */
188
+ export function recordDeployedVersion(
189
+ dir: string,
190
+ published: { tileId: string; versionNumber: number | undefined },
191
+ warn: (message: string) => void = (message) => console.error(message),
192
+ ): void {
193
+ if (published.versionNumber === undefined) return;
194
+ try {
195
+ const base = readCheckoutBase(dir);
196
+ if (base === null || base.tileId !== published.tileId) return;
197
+ writeCheckoutBase(dir, {
198
+ tileId: base.tileId,
199
+ baseVersion: published.versionNumber,
200
+ });
201
+ } catch (error) {
202
+ warn(
203
+ `Version ${published.versionNumber} is published, but ${CHECKOUT_BASE_FILE} was not updated (${describe(error)}). ` +
204
+ `The next deploy from this folder can ask about version ${published.versionNumber}.`,
205
+ );
206
+ }
207
+ }
@@ -0,0 +1,16 @@
1
+ // owner: jyoung-q
2
+ import { assertSupportedBun } from "./bun-version";
3
+ import { CliError } from "./errors";
4
+
5
+ /** Format runtime validation through the CLI's normal error boundary. */
6
+ export function assertSupportedCliBun(
7
+ version: string,
8
+ options: { internalMonoRepo?: boolean } = {},
9
+ ): void {
10
+ if (options.internalMonoRepo) return;
11
+ try {
12
+ assertSupportedBun(version);
13
+ } catch (error) {
14
+ throw new CliError(error instanceof Error ? error.message : String(error));
15
+ }
16
+ }
package/src/cli-env.ts ADDED
@@ -0,0 +1,28 @@
1
+ // owner: jyoung-q
2
+ /**
3
+ * Reads a CLI environment variable under its `JOINER_` name, then under its
4
+ * compatible `POE_TILES_` name.
5
+ *
6
+ * An empty or whitespace-only value counts as unset. Scrubbers clear
7
+ * credentials by setting them to "", so a plain `??` would let a scrubbed
8
+ * `JOINER_PUBLISH_TOKEN=""` hide the scoped `POE_TILES_PUBLISH_TOKEN`.
9
+ *
10
+ * Always pass the environment the caller was given; never read `process.env`
11
+ * behind a caller that passes a scoped environment.
12
+ */
13
+
14
+ export type CliEnvSuffix =
15
+ | "SESSION_TOKEN"
16
+ | "PUBLISH_TOKEN"
17
+ | "SDK_TARBALL_OVERRIDE";
18
+
19
+ export function readCliEnv(
20
+ env: Record<string, string | undefined>,
21
+ suffix: CliEnvSuffix,
22
+ ): string | undefined {
23
+ for (const name of [`JOINER_${suffix}`, `POE_TILES_${suffix}`]) {
24
+ const value = env[name]?.trim();
25
+ if (value) return value;
26
+ }
27
+ return undefined;
28
+ }
@@ -0,0 +1,23 @@
1
+ // owner: jyoung-q
2
+ /**
3
+ * The command name this process was started as.
4
+ *
5
+ * The `joiner` launcher runs the `poe-tiles` executable, so `argv[1]` never
6
+ * says `joiner`. The launcher sets `JOINER_CLI_INVOKED_AS=joiner` instead.
7
+ * Only `joiner` is accepted; any other value means `poe-tiles`. The npm
8
+ * package's only bin is `joiner`, so it is always `joiner`.
9
+ */
10
+
11
+ import { type CliDistribution, cliDistribution } from "./distribution.js";
12
+
13
+ export const CLI_INVOKED_AS_ENV = "JOINER_CLI_INVOKED_AS";
14
+
15
+ export type CliName = "joiner" | "poe-tiles";
16
+
17
+ export function cliName(
18
+ env: Record<string, string | undefined> = process.env,
19
+ distribution: CliDistribution = cliDistribution(),
20
+ ): CliName {
21
+ if (distribution === "npm") return "joiner";
22
+ return env[CLI_INVOKED_AS_ENV] === "joiner" ? "joiner" : "poe-tiles";
23
+ }