@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,103 @@
1
+ // owner: klu
2
+ /**
3
+ * `tiles visibility` — the only way a tile moves in or out of public discovery.
4
+ *
5
+ * Split from `tiles.ts` for the per-file line budget, the same reason
6
+ * `tiles-channel-commands.ts` exists.
7
+ *
8
+ * It is a standalone command rather than a publish flag because the two answer
9
+ * different questions. A publish says what the tile IS; visibility says who can
10
+ * find it. Folding the second into the first meant every routine publish
11
+ * re-asserted a discovery answer — so an automated preview, or a publish whose
12
+ * flag was simply omitted, could quietly pull a creator's listed tile back out
13
+ * of discovery.
14
+ */
15
+
16
+ import type { Command } from "commander";
17
+ import type { SlopPoeClient } from "../client.js";
18
+ import { assertSuccess, CliError } from "../errors.js";
19
+ import { isJsonMode, printJson, printKeyValue } from "../output.js";
20
+ import {
21
+ SETTABLE_TILE_VISIBILITIES,
22
+ type SettableTileVisibility,
23
+ } from "../types.js";
24
+
25
+ /** Narrow a raw CLI argument to a settable visibility, or throw a `CliError`. */
26
+ function parseVisibility(arg: string): SettableTileVisibility {
27
+ if (!(SETTABLE_TILE_VISIBILITIES as readonly string[]).includes(arg)) {
28
+ const allowed = SETTABLE_TILE_VISIBILITIES.map((one) => `"${one}"`).join(
29
+ " or ",
30
+ );
31
+ throw new CliError(`visibility must be ${allowed} (got "${arg}").`);
32
+ }
33
+ return arg as SettableTileVisibility;
34
+ }
35
+
36
+ /** Register `tiles visibility <tileHandleOrId> <visibility>` on `tiles`. */
37
+ export function addTileVisibilityCommand(
38
+ tiles: Command,
39
+ client: SlopPoeClient,
40
+ ): void {
41
+ tiles
42
+ .command("visibility")
43
+ .description(
44
+ "List a tile in public discovery, or take it back out. Accepts either " +
45
+ "the canonical tile ID or `userHandle/tileHandle`. This is the only " +
46
+ "way to change visibility — publishing never does, and a new tile " +
47
+ "starts unlisted.",
48
+ )
49
+ .argument(
50
+ "<tileHandleOrId>",
51
+ "Tile ID or userHandle/tileHandle of the tile to change",
52
+ )
53
+ .argument(
54
+ "<visibility>",
55
+ `Where the tile sits in discovery: ${SETTABLE_TILE_VISIBILITIES.join(" | ")}`,
56
+ )
57
+ .option(
58
+ "--use-poe-account",
59
+ "Change a tile owned by the @poe system account (requires allowlisted " +
60
+ "API key). Mirrors `rename --use-poe-account`.",
61
+ )
62
+ .action(async function (
63
+ this: Command,
64
+ tileHandleOrId: string,
65
+ visibilityArg: string,
66
+ opts: { usePoeAccount?: boolean },
67
+ ) {
68
+ const visibility = parseVisibility(visibilityArg);
69
+ // Keyed on the canonical tile ID, like `rename`, so either form of
70
+ // identifier works.
71
+ const lookup = await client.getTile(tileHandleOrId);
72
+ assertSuccess(lookup);
73
+ const tileTypeId = lookup.tile.id;
74
+
75
+ const result = await client.setTileVisibility(tileTypeId, visibility, {
76
+ useAsPoeAccount: opts.usePoeAccount,
77
+ });
78
+ if (!result.success) throw new CliError(result.error);
79
+
80
+ reportVisibility(this, tileTypeId, visibility);
81
+ });
82
+ }
83
+
84
+ /** Print the outcome as JSON or as a human-readable confirmation. */
85
+ function reportVisibility(
86
+ command: Command,
87
+ tileTypeId: string,
88
+ visibility: SettableTileVisibility,
89
+ ): void {
90
+ if (isJsonMode(command)) {
91
+ printJson({ id: tileTypeId, visibility });
92
+ return;
93
+ }
94
+ console.log(
95
+ visibility === "public"
96
+ ? "Tile is now listed in public discovery."
97
+ : "Tile is now unlisted — reachable by link, absent from discovery.",
98
+ );
99
+ printKeyValue([
100
+ ["Tile ID", tileTypeId],
101
+ ["Visibility", visibility],
102
+ ]);
103
+ }
@@ -0,0 +1,257 @@
1
+ // owner: jyoung-q
2
+ /**
3
+ * Tile commands: list, get, upload
4
+ */
5
+
6
+ import { writeFileSync } from "node:fs";
7
+ import { resolve } from "node:path";
8
+ import { Command } from "commander";
9
+ import type { SlopPoeClient } from "../client.js";
10
+ import { assertSuccess, CliError } from "../errors.js";
11
+ import { isJsonMode, printJson, printKeyValue, printTable } from "../output.js";
12
+ import { describeInvalidTileHandle } from "../poe-tile-config.js";
13
+ import { createInitCommand } from "./init/index.js";
14
+ import { addTileChannelWriteCommands } from "./tiles-channel-commands.js";
15
+ import { createTilesCheckoutCommand } from "./tiles-checkout.js";
16
+ import { addTileGalleryCommand } from "./tiles-gallery-command.js";
17
+ import { getTileWithOwnerMetadata } from "./tiles-get-helpers.js";
18
+ import { createTilesInspectCommand } from "./tiles-inspect.js";
19
+ import { addTilePowerCommand } from "./tiles-power-command.js";
20
+ import { addTileUploadCommands } from "./tiles-upload-command.js";
21
+ import { addTileVersionCommands } from "./tiles-version-commands.js";
22
+ import { addTileVisibilityCommand } from "./tiles-visibility-command.js";
23
+
24
+ export function createTilesCommands(client: SlopPoeClient): Command {
25
+ const tiles = new Command("tiles").description("Tile management");
26
+
27
+ tiles.addCommand(createInitCommand());
28
+
29
+ tiles
30
+ .command("list")
31
+ .description("List all tiles")
32
+ .action(async function (this: Command) {
33
+ const result = await client.listTiles();
34
+ assertSuccess(result);
35
+ if (isJsonMode(this)) {
36
+ printJson(result.tiles);
37
+ } else {
38
+ if (result.tiles.length === 0) {
39
+ console.log("No tiles found.");
40
+ return;
41
+ }
42
+ printTable({
43
+ headers: ["ID", "Handle", "Creator", "Updated"],
44
+ rows: result.tiles.map((a) => [
45
+ a.id,
46
+ a.handle,
47
+ a.creator_id,
48
+ a.updated_at,
49
+ ]),
50
+ });
51
+ }
52
+ });
53
+
54
+ tiles
55
+ .command("get")
56
+ .description(
57
+ "Show tile details, including its current visibility when you own " +
58
+ "it — query this rather than relying on a visibility you were told " +
59
+ "earlier, since it can be changed from the UI at any time.",
60
+ )
61
+ .argument("<tileHandleOrId>", "Tile ID or userHandle/tileHandle")
62
+ .action(async function (this: Command, tileHandleOrId: string) {
63
+ const result = await getTileWithOwnerMetadata(client, tileHandleOrId);
64
+ assertSuccess(result);
65
+ if (isJsonMode(this)) {
66
+ printJson(result.tile);
67
+ } else {
68
+ printKeyValue([
69
+ ["ID", result.tile.id],
70
+ ["Handle", result.tile.handle],
71
+ ["Creator", result.tile.creator_id],
72
+ // Only the creator is told this, so a viewer who is not the
73
+ // owner sees no row rather than a blank or a guess.
74
+ //
75
+ // Cast rather than `as const`: `printKeyValue` takes MUTABLE
76
+ // tuples, and a `readonly` one is not assignable to them (the
77
+ // simulation row in `tiles-publish-helpers.ts` does the same).
78
+ ...(result.tile.visibility === undefined
79
+ ? []
80
+ : ([["Visibility", result.tile.visibility]] as Array<
81
+ [string, string]
82
+ >)),
83
+ ["Bundle URL", result.tile.bundleUrl],
84
+ ["Created", result.tile.created_at],
85
+ ["Updated", result.tile.updated_at],
86
+ ]);
87
+ }
88
+ });
89
+
90
+ tiles
91
+ .command("channels")
92
+ .description(
93
+ "Show a tile's release channels — which version is live vs each " +
94
+ "custom channel (plus each channel's schema version). Owner only.",
95
+ )
96
+ .argument("<tileHandleOrId>", "Tile ID or userHandle/tileHandle")
97
+ .action(async function (this: Command, tileHandleOrId: string) {
98
+ const lookup = await client.getTile(tileHandleOrId);
99
+ assertSuccess(lookup);
100
+ const result = await client.getTileChannels(lookup.tile.id);
101
+ assertSuccess(result);
102
+ if (isJsonMode(this)) {
103
+ printJson(result.channels);
104
+ } else {
105
+ printKeyValue(
106
+ result.channels.map((channel) => [
107
+ channel.name,
108
+ `v${channel.versionNumber}` +
109
+ (channel.schemaVersion === null
110
+ ? ""
111
+ : ` (schema ${channel.schemaVersion})`) +
112
+ (channel.autoAdvance ? " [auto-advance]" : ""),
113
+ ]),
114
+ );
115
+ }
116
+ });
117
+
118
+ addTileChannelWriteCommands(tiles, client);
119
+ addTileVersionCommands(tiles, client);
120
+
121
+ tiles
122
+ .command("promote")
123
+ .description(
124
+ "Promote (or roll back) a tile's live version — the same move " +
125
+ "`tiles deploy` makes in-band. Owner only.",
126
+ )
127
+ .argument("<tileHandleOrId>", "Tile ID or userHandle/tileHandle")
128
+ .argument("<versionNumber>", "Version number to point `live` at")
129
+ .action(async function (
130
+ this: Command,
131
+ tileHandleOrId: string,
132
+ versionNumber: string,
133
+ ) {
134
+ const version = Number(versionNumber);
135
+ if (!Number.isInteger(version) || version < 1) {
136
+ throw new CliError(
137
+ `Invalid version number: ${versionNumber}. Expected a positive integer (see \`tiles channels\`).`,
138
+ );
139
+ }
140
+ const lookup = await client.getTile(tileHandleOrId);
141
+ assertSuccess(lookup);
142
+ const result = await client.promoteTileLive(lookup.tile.id, version);
143
+ assertSuccess(result);
144
+ if (isJsonMode(this)) {
145
+ printJson({ tileId: lookup.tile.id, live: result.versionNumber });
146
+ } else {
147
+ console.log(`Promoted version ${result.versionNumber} to live.`);
148
+ }
149
+ });
150
+
151
+ tiles
152
+ .command("download-source")
153
+ .description(
154
+ "Download a published tile's uploaded source-code bundle as a .tar.gz archive",
155
+ )
156
+ .argument("<tileHandleOrId>", "Tile ID or userHandle/tileHandle")
157
+ .option(
158
+ "--out <path>",
159
+ "Output path for the downloaded source bundle",
160
+ "source-bundle.tar.gz",
161
+ )
162
+ .action(async function (
163
+ this: Command,
164
+ tileHandleOrId: string,
165
+ opts: { out: string },
166
+ ) {
167
+ const lookup = await client.getTile(tileHandleOrId);
168
+ assertSuccess(lookup);
169
+ const tileTypeId = lookup.tile.id;
170
+ const outPath = resolve(opts.out);
171
+ const { bytes } = await client.downloadSourceBundle(tileTypeId);
172
+ writeFileSync(outPath, bytes);
173
+
174
+ if (isJsonMode(this)) {
175
+ printJson({ id: tileTypeId, out: outPath, bytes: bytes.byteLength });
176
+ } else {
177
+ console.log("Source bundle downloaded.");
178
+ printKeyValue([
179
+ ["Tile ID", tileTypeId],
180
+ ["Output", outPath],
181
+ ["Bytes", String(bytes.byteLength)],
182
+ ]);
183
+ }
184
+ });
185
+
186
+ tiles.addCommand(createTilesCheckoutCommand(client));
187
+
188
+ tiles
189
+ .command("rename")
190
+ .description(
191
+ "Rename one of your own tiles. Accepts either the canonical tile ID " +
192
+ "or `userHandle/tileHandle`; both resolve to the same tile row.",
193
+ )
194
+ .argument(
195
+ "<tileHandleOrId>",
196
+ "Tile ID or userHandle/tileHandle of the tile to rename",
197
+ )
198
+ .argument(
199
+ "<newHandle>",
200
+ "New handle (lowercase alphanumeric + hyphens; UNIQUE per creator)",
201
+ )
202
+ .option(
203
+ "--use-poe-account",
204
+ "Rename a tile owned by the @poe system account (requires allowlisted API key). " +
205
+ "Mirrors `upload --publish-as-poe`; rejected with 403 if the calling API key " +
206
+ "is not in the server's poe-publish allowlist.",
207
+ )
208
+ .action(async function (
209
+ this: Command,
210
+ tileHandleOrId: string,
211
+ newHandle: string,
212
+ opts: { usePoeAccount?: boolean },
213
+ ) {
214
+ // Validate the new handle CLI-side so a typo doesn't burn a
215
+ // round trip. The server re-validates with the same regex.
216
+ const problem = describeInvalidTileHandle(newHandle);
217
+ if (problem !== undefined) {
218
+ throw new CliError(`Invalid handle "${newHandle}": ${problem}.`);
219
+ }
220
+
221
+ // The rename endpoint is keyed on the canonical tile ID. Resolve
222
+ // `userHandle/tileHandle` via getTile first so users can pass either
223
+ // form (matching `tiles get`'s ergonomics).
224
+ const lookup = await client.getTile(tileHandleOrId);
225
+ assertSuccess(lookup);
226
+ const tileTypeId = lookup.tile.id;
227
+
228
+ const result = await client.renameTile(tileTypeId, newHandle, {
229
+ useAsPoeAccount: opts.usePoeAccount,
230
+ });
231
+ if (!result.success) {
232
+ throw new CliError(result.error);
233
+ }
234
+
235
+ if (isJsonMode(this)) {
236
+ printJson({ id: tileTypeId, handle: newHandle });
237
+ } else {
238
+ console.log("Tile renamed.");
239
+ printKeyValue([
240
+ ["Tile ID", tileTypeId],
241
+ ["Handle", newHandle],
242
+ ]);
243
+ }
244
+ });
245
+
246
+ addTileVisibilityCommand(tiles, client);
247
+ addTileGalleryCommand(tiles, client);
248
+
249
+ addTilePowerCommand(tiles, client);
250
+
251
+ addTileUploadCommands(tiles, client);
252
+
253
+ // Hidden until the agent-speed A/B decides on rollout; it still runs.
254
+ tiles.addCommand(createTilesInspectCommand(), { hidden: true });
255
+
256
+ return tiles;
257
+ }
@@ -0,0 +1,307 @@
1
+ // owner: jyoung-q
2
+ /**
3
+ * `poe-tiles upgrade` command.
4
+ *
5
+ * Fetches the latest CLI tarball URL from the stable docs manifest and runs
6
+ * the install command. The manifest file lives at `projects/poe-tiles-docs/
7
+ * public/cli/latest.json` and is generated by `scripts/publish-tar.ts`.
8
+ *
9
+ * Security: the manifest carries ONLY `tarballUrl` + `publishedAt`. The actual
10
+ * install command is constructed CLI-side from `tarballUrl` (we never `sh -c`
11
+ * a string fetched from the network). The fetched tarball URL is also pinned
12
+ * to the expected upload host before we hand it to `bun install -g`, so a
13
+ * compromised docs deploy can't redirect installs to an attacker tarball.
14
+ *
15
+ * Local-only: does not call the API, so the preAction auth hook in `cli.ts`
16
+ * skips client setup for this command. The install itself shells out to
17
+ * `bun install -g`, which updates the global install separately from any
18
+ * monorepo-resident wrapper (`scripts/install-cli.ts`). After a successful
19
+ * install it adds the `joiner` launcher (see `install-joiner.ts`).
20
+ */
21
+
22
+ import { spawnSync } from "node:child_process";
23
+ import { existsSync } from "node:fs";
24
+ import { join, posix } from "node:path";
25
+ import { Command } from "commander";
26
+ import {
27
+ type CliDistribution,
28
+ cliDistribution,
29
+ NPM_PACKAGE_NAME,
30
+ } from "../distribution.js";
31
+ import { CliError } from "../errors.js";
32
+ import { formatSetupCommand, PACKAGE_NAME } from "../install-command.js";
33
+ import {
34
+ type InstallJoinerResult,
35
+ installJoinerForThisCli,
36
+ joinerConflictWarning,
37
+ } from "./install-joiner.js";
38
+
39
+ // Published CLIs bake this host into their self-upgrade path. Keep it stable
40
+ // unless the old host redirects or serves the new manifest.
41
+ export const MANIFEST_URL = "https://joiner-docs.pages.dev/cli/latest.json";
42
+ const ALLOWED_TARBALL_HOSTS = new Set([
43
+ "misc-dev-uploads.quora-913.workers.dev",
44
+ ]);
45
+
46
+ export interface LatestManifest {
47
+ tarballUrl: string;
48
+ publishedAt: string;
49
+ /**
50
+ * Current poe-tiles-sdk tarball URL (the pin `tiles init` writes into
51
+ * scaffolded package.json files). Optional: manifests published before
52
+ * this field existed omit it, and old CLIs ignore it.
53
+ */
54
+ sdkTarballUrl?: string;
55
+ }
56
+
57
+ export function isLatestManifest(value: unknown): value is LatestManifest {
58
+ if (typeof value !== "object" || value === null) return false;
59
+ const v = value as Record<string, unknown>;
60
+ return (
61
+ typeof v["tarballUrl"] === "string" &&
62
+ typeof v["publishedAt"] === "string" &&
63
+ (v["sdkTarballUrl"] === undefined || typeof v["sdkTarballUrl"] === "string")
64
+ );
65
+ }
66
+
67
+ export function assertAllowedTarballUrl(rawUrl: string): URL {
68
+ let url: URL;
69
+ try {
70
+ url = new URL(rawUrl);
71
+ } catch {
72
+ throw new CliError(`Manifest tarballUrl is not a valid URL: ${rawUrl}`);
73
+ }
74
+ if (url.protocol !== "https:") {
75
+ throw new CliError(`Refusing non-https tarballUrl: ${rawUrl}`);
76
+ }
77
+ if (!ALLOWED_TARBALL_HOSTS.has(url.host)) {
78
+ throw new CliError(
79
+ `Refusing tarballUrl on unexpected host ${url.host}. Expected one of: ${[...ALLOWED_TARBALL_HOSTS].join(", ")}`,
80
+ );
81
+ }
82
+ return url;
83
+ }
84
+
85
+ export interface UpgradeDeps {
86
+ fetchManifest?: (url: string) => Promise<Response>;
87
+ spawn?: (
88
+ command: string,
89
+ args: ReadonlyArray<string>,
90
+ ) => { status: number | null };
91
+ stdout?: { write: (chunk: string) => void };
92
+ stderr?: { write: (chunk: string) => void };
93
+ /** Adds the `joiner` launcher after a successful install. */
94
+ installJoiner?: () => InstallJoinerResult;
95
+ distribution?: CliDistribution;
96
+ /** This CLI's install directory, which says which package manager owns it. */
97
+ installDir?: string;
98
+ platform?: NodeJS.Platform;
99
+ }
100
+
101
+ type Upgrade = [command: string, args: string[]];
102
+
103
+ /** The lockfiles Bun writes beside its global `node_modules`. */
104
+ const BUN_LOCKFILES = ["bun.lock", "bun.lockb"];
105
+
106
+ /**
107
+ * The npm package upgrades itself only through npm or Bun, the managers the
108
+ * docs give, and only when its install directory positively identifies
109
+ * which one, so an upgrade never installs a second copy beside a stale one.
110
+ * Bun's global directory is a project with its lockfile beside
111
+ * `node_modules`. npm's global layout is `<prefix>/lib/node_modules`
112
+ * (`<prefix>\node_modules` on Windows) with no `package.json` beside it;
113
+ * upgrading that prefix updates a one-time `--prefix` install in place.
114
+ * Anything else (pnpm, yarn, Bun with lockfiles off) throws and asks the
115
+ * creator to reinstall with the manager they used, which knows its own
116
+ * options such as pnpm's install groups.
117
+ */
118
+ export function npmUpgradeCommand(
119
+ installDir: string,
120
+ platform: NodeJS.Platform = process.platform,
121
+ ): Upgrade {
122
+ const spec = `${NPM_PACKAGE_NAME}@latest`;
123
+ const path =
124
+ platform === "win32" ? installDir.replaceAll("\\", "/") : installDir;
125
+ const at = `${path}/`.indexOf(`/node_modules/${NPM_PACKAGE_NAME}/`);
126
+ const upgrade =
127
+ at === -1
128
+ ? null
129
+ : upgradeForGlobalDir(path.slice(0, at) || "/", platform, spec);
130
+ if (upgrade !== null) return upgrade;
131
+ throw new CliError(
132
+ `Cannot tell which package manager installed this CLI (${installDir}). Reinstall ${spec} with the package manager you installed it with, the same way you installed it.`,
133
+ );
134
+ }
135
+
136
+ /** The upgrade for the directory holding `node_modules`, or null if unknown. */
137
+ function upgradeForGlobalDir(
138
+ dir: string,
139
+ platform: NodeJS.Platform,
140
+ spec: string,
141
+ ): Upgrade | null {
142
+ const has = (file: string) => existsSync(join(dir, file));
143
+ if (BUN_LOCKFILES.some(has)) return ["bun", ["add", "-g", spec]];
144
+ if (has("package.json")) return null;
145
+ if (platform === "win32")
146
+ return ["npm", ["install", "-g", "--prefix", dir, spec]];
147
+ if (posix.basename(dir) !== "lib") return null;
148
+ return ["npm", ["install", "-g", "--prefix", posix.dirname(dir), spec]];
149
+ }
150
+
151
+ /**
152
+ * Quotes an argument for `--print`: POSIX single quotes, or double quotes on
153
+ * Windows, where Command Prompt ignores single quotes.
154
+ */
155
+ export function shellQuote(
156
+ arg: string,
157
+ platform: NodeJS.Platform = process.platform,
158
+ ): string {
159
+ if (/^[\w@%+=:,./-]+$/.test(arg)) return arg;
160
+ return platform === "win32"
161
+ ? `"${arg}"`
162
+ : `'${arg.replaceAll("'", "'\\''")}'`;
163
+ }
164
+
165
+ const defaultSpawn: NonNullable<UpgradeDeps["spawn"]> = (command, args) =>
166
+ spawnSync(command, [...args], { stdio: "inherit" });
167
+
168
+ export async function runUpgrade(
169
+ opts: { print?: boolean },
170
+ deps: UpgradeDeps = {},
171
+ ): Promise<void> {
172
+ if ((deps.distribution ?? cliDistribution()) === "npm")
173
+ return runNpmUpgrade(opts, deps);
174
+ return await runTarballUpgrade(opts, deps);
175
+ }
176
+
177
+ function runNpmUpgrade(opts: { print?: boolean }, deps: UpgradeDeps): void {
178
+ const spawn = deps.spawn ?? defaultSpawn;
179
+ const stdout = deps.stdout ?? process.stdout;
180
+ const [command, args] = npmUpgradeCommand(
181
+ deps.installDir ?? import.meta.dir,
182
+ deps.platform,
183
+ );
184
+ if (opts.print) {
185
+ const quote = (arg: string) => shellQuote(arg, deps.platform);
186
+ stdout.write(`${[command, ...args].map(quote).join(" ")}\n`);
187
+ return;
188
+ }
189
+ const result = spawn(command, args);
190
+ if (result.status === null)
191
+ throw new CliError(
192
+ `Could not run ${command}. This CLI was installed with ${command}; put it on PATH, then run \`joiner upgrade\` again.`,
193
+ );
194
+ if (result.status !== 0) {
195
+ throw new CliError(
196
+ `${command} ${args.join(" ")} failed with exit code ${result.status}.`,
197
+ );
198
+ }
199
+ stdout.write("\nUpgrade complete.\n");
200
+ }
201
+
202
+ async function runTarballUpgrade(
203
+ opts: { print?: boolean },
204
+ deps: UpgradeDeps = {},
205
+ ): Promise<void> {
206
+ const fetchManifest = deps.fetchManifest ?? ((url) => fetch(url));
207
+ const spawn = deps.spawn ?? defaultSpawn;
208
+ const stdout = deps.stdout ?? process.stdout;
209
+ const stderr = deps.stderr ?? process.stderr;
210
+
211
+ const response = await fetchManifest(MANIFEST_URL);
212
+ if (!response.ok) {
213
+ throw new CliError(
214
+ `Failed to fetch latest manifest from ${MANIFEST_URL}: ${response.status} ${response.statusText}`,
215
+ );
216
+ }
217
+ const body: unknown = await response.json();
218
+ if (!isLatestManifest(body)) {
219
+ throw new CliError(
220
+ `Manifest at ${MANIFEST_URL} did not match the expected shape (tarballUrl, publishedAt).`,
221
+ );
222
+ }
223
+
224
+ const tarballUrl = assertAllowedTarballUrl(body.tarballUrl).toString();
225
+
226
+ if (opts.print) {
227
+ // The same steps a normal upgrade runs, including the launcher.
228
+ stdout.write(`${formatSetupCommand(tarballUrl)}\n`);
229
+ return;
230
+ }
231
+
232
+ stdout.write(
233
+ `Upgrading to tarball published ${body.publishedAt}\n ${tarballUrl}\n\n`,
234
+ );
235
+
236
+ // Bun's global install treats two different tarball URLs of the same
237
+ // package name as conflicting "different versions" and rejects the second
238
+ // install with a `dependency loop` error. Remove first so reinstalls work.
239
+ // We ignore the remove exit code — on a fresh machine there's nothing to
240
+ // remove and bun exits non-zero.
241
+ spawn("bun", ["remove", "-g", PACKAGE_NAME]);
242
+
243
+ const installResult = spawn("bun", ["install", "-g", tarballUrl]);
244
+ if (installResult.status !== 0) {
245
+ throw new CliError(
246
+ `bun install -g failed with exit code ${installResult.status ?? "unknown"}.`,
247
+ );
248
+ }
249
+ stdout.write("\nUpgrade complete.\n");
250
+ reportJoinerLauncher({
251
+ installJoiner: deps.installJoiner ?? (() => installJoinerForThisCli()),
252
+ stdout,
253
+ stderr,
254
+ });
255
+ }
256
+
257
+ /**
258
+ * Adds or refreshes the `joiner` launcher after the CLI is installed. It never
259
+ * fails the upgrade: a foreign `joiner` gets a warning, and any other problem
260
+ * names `poe-tiles install-joiner` as the next step. A CLI released before this
261
+ * step cannot run it, so the first upgrade from such a CLI installs only the
262
+ * new CLI; the docs give the same command for that case.
263
+ */
264
+ function reportJoinerLauncher({
265
+ installJoiner,
266
+ stdout,
267
+ stderr,
268
+ }: {
269
+ installJoiner: () => InstallJoinerResult;
270
+ stdout: { write: (chunk: string) => void };
271
+ stderr: { write: (chunk: string) => void };
272
+ }): void {
273
+ let result: InstallJoinerResult;
274
+ try {
275
+ result = installJoiner();
276
+ } catch (error) {
277
+ const reason = error instanceof Error ? ` (${error.message})` : "";
278
+ stderr.write(
279
+ `Warning: the joiner command was not added${reason}. Run \`poe-tiles install-joiner\` to add it. The poe-tiles command remains available.\n`,
280
+ );
281
+ return;
282
+ }
283
+ if (result.outcome === "conflict") {
284
+ stderr.write(joinerConflictWarning(result.path));
285
+ return;
286
+ }
287
+ if (result.outcome !== "unchanged") {
288
+ stdout.write(
289
+ `Installed ${result.path}. The joiner and poe-tiles commands both run this CLI.\n`,
290
+ );
291
+ }
292
+ }
293
+
294
+ export function createUpgradeCommand(): Command {
295
+ return new Command("upgrade")
296
+ .description(
297
+ "Upgrade this CLI to the latest published release: for the npm package, through npm or Bun, whichever installed it (other package managers: reinstall with yours); otherwise from the docs site's latest tarball URL.",
298
+ )
299
+ .option(
300
+ "--print",
301
+ "Print the equivalent install command and exit without running it.",
302
+ )
303
+ .action(
304
+ async (opts: { print?: boolean }): Promise<void> =>
305
+ await runUpgrade(opts),
306
+ );
307
+ }