@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,74 @@
1
+ // owner: klu
2
+ import type { JSONValue } from "./client.js";
3
+
4
+ // Mirrored wire types keep the published CLI independent of workspace packages.
5
+ // simulation-contract.test.ts checks them against the platform's definitions.
6
+ export interface SimulationStore {
7
+ typeId: string;
8
+ instanceId: string;
9
+ }
10
+
11
+ export interface SimulationCreated extends SimulationStore {
12
+ success: true;
13
+ room: SimulationStore;
14
+ container: SimulationStore;
15
+ devUsers: Array<{
16
+ userId: string;
17
+ slug: string;
18
+ displayName: string;
19
+ profilePicture: string;
20
+ }>;
21
+ }
22
+
23
+ export interface SimulationListItem extends SimulationStore {
24
+ createdAt: string;
25
+ containerId: string;
26
+ room: SimulationStore | null;
27
+ puppetSlugs: string[];
28
+ }
29
+
30
+ export interface SimulationList {
31
+ success: true;
32
+ sandboxes: SimulationListItem[];
33
+ buildHasBackend: boolean | null;
34
+ }
35
+
36
+ export interface SimulationSnapshot {
37
+ version: number;
38
+ schemaVersion: number;
39
+ consistent: boolean;
40
+ complete: boolean;
41
+ limits: { maxBytes: number; reservedBytes: number; perSeatBytes: number };
42
+ seats: Array<{
43
+ userId: string;
44
+ slug?: string;
45
+ complete: boolean;
46
+ bytes: number;
47
+ tables: Record<
48
+ string,
49
+ Array<{
50
+ visibility: "public" | "private";
51
+ itemKey: string;
52
+ sortKey: string;
53
+ value: JSONValue;
54
+ }>
55
+ >;
56
+ }>;
57
+ }
58
+
59
+ export type SimulationDebugDocument = Omit<
60
+ SimulationSnapshot,
61
+ "version" | "schemaVersion" | "consistent"
62
+ > & {
63
+ version: 1;
64
+ generatedAt: string;
65
+ takenBy: string;
66
+ build: { typeId: string };
67
+ target: {
68
+ kind: "simulation";
69
+ storeTypeId: string;
70
+ instanceId: string;
71
+ containerId: string;
72
+ };
73
+ store: Pick<SimulationSnapshot, "version" | "schemaVersion" | "consistent">;
74
+ };
@@ -0,0 +1,112 @@
1
+ // owner: klu
2
+ import type { CliWebSocket } from "./client.js";
3
+ import { assertSuccess, CliError } from "./errors.js";
4
+ import {
5
+ isSnapshotActionResponse,
6
+ parseSimulationSnapshot,
7
+ SIMULATION_DEBUG_MAX_BYTES,
8
+ validateDebugOptions,
9
+ } from "./simulation-snapshot.js";
10
+ import type {
11
+ SimulationCreated,
12
+ SimulationDebugDocument,
13
+ SimulationList,
14
+ SimulationStore,
15
+ } from "./simulation-types.js";
16
+ import { sendStoreRequest } from "./store-request.js";
17
+ import type { ApiResult } from "./types.js";
18
+
19
+ const SANDBOX_PATH = "/api/v1/multiplayer-sandboxes";
20
+ const DEFAULT_DEBUG_TIMEOUT_MS = 30_000;
21
+
22
+ export function createSimulationsClient(transport: {
23
+ get<T>(path: string): Promise<T>;
24
+ post<T>(path: string, body: { typeId: string }): Promise<T>;
25
+ currentUserId(): Promise<string>;
26
+ openSocket(timeoutMs: number): Promise<CliWebSocket>;
27
+ }) {
28
+ async function list(typeId: string): Promise<SimulationList> {
29
+ const result = await transport.get<ApiResult<SimulationList>>(
30
+ `${SANDBOX_PATH}?${new URLSearchParams({ typeId })}`,
31
+ );
32
+ assertSuccess(result);
33
+ return result;
34
+ }
35
+ return {
36
+ async create(typeId: string): Promise<SimulationCreated> {
37
+ const result = await transport.post<ApiResult<SimulationCreated>>(
38
+ SANDBOX_PATH,
39
+ { typeId },
40
+ );
41
+ assertSuccess(result);
42
+ return result;
43
+ },
44
+ list,
45
+ async debug(
46
+ options: SimulationStore & { maxBytes?: number; timeoutMs?: number },
47
+ ): Promise<SimulationDebugDocument> {
48
+ const maxBytes = options.maxBytes ?? SIMULATION_DEBUG_MAX_BYTES;
49
+ const timeoutMs = options.timeoutMs ?? DEFAULT_DEBUG_TIMEOUT_MS;
50
+ validateDebugOptions({ maxBytes, timeoutMs });
51
+ const inventory = await list(options.typeId);
52
+ const simulation = inventory.sandboxes.find(
53
+ (item) =>
54
+ item.typeId === options.typeId &&
55
+ item.instanceId === options.instanceId,
56
+ );
57
+ if (!simulation)
58
+ throw new CliError(
59
+ "Simulation not found in your simulations for this type ID. Use `simulations list <typeId>` to find its exact typeId and instanceId.",
60
+ );
61
+ const takenBy = await transport.currentUserId();
62
+ const socket = await transport.openSocket(timeoutMs);
63
+ try {
64
+ const requestId = crypto.randomUUID();
65
+ // Snapshot tables cross the WebSocket JSON boundary correctly. The REST
66
+ // action route cannot serialize their null-prototype maps through DO RPC.
67
+ const response = await sendStoreRequest({
68
+ socket,
69
+ storeTypeId: simulation.typeId,
70
+ instanceId: simulation.instanceId,
71
+ requestId,
72
+ timeoutMs,
73
+ isResponse: isSnapshotActionResponse,
74
+ maxResponseBytes: SIMULATION_DEBUG_MAX_BYTES + 64 * 1024,
75
+ request: {
76
+ type: "action_request",
77
+ request_id: requestId,
78
+ action_name: "poeDebugSnapshot",
79
+ action_input: { maxBytes },
80
+ },
81
+ });
82
+ if (!response.success)
83
+ throw new CliError(
84
+ `Debug snapshot failed: ${response.error.type}: ${response.error.message}`,
85
+ );
86
+ const snapshot = parseSimulationSnapshot(response.result);
87
+ return {
88
+ version: 1,
89
+ generatedAt: new Date().toISOString(),
90
+ takenBy,
91
+ build: { typeId: simulation.typeId },
92
+ target: {
93
+ kind: "simulation",
94
+ storeTypeId: simulation.typeId,
95
+ instanceId: simulation.instanceId,
96
+ containerId: simulation.containerId,
97
+ },
98
+ store: {
99
+ version: snapshot.version,
100
+ schemaVersion: snapshot.schemaVersion,
101
+ consistent: snapshot.consistent,
102
+ },
103
+ seats: snapshot.seats,
104
+ limits: snapshot.limits,
105
+ complete: snapshot.complete,
106
+ };
107
+ } finally {
108
+ socket.close();
109
+ }
110
+ },
111
+ };
112
+ }
@@ -0,0 +1,466 @@
1
+ // owner: aroe
2
+ /**
3
+ * Build a source-code tar.gz bundle for `tiles publish --source-bundle`.
4
+ *
5
+ * Walks a directory, applies a built-in default ignore list plus any
6
+ * `.gitignore` file at the source root and an optional extra ignore file,
7
+ * and packs the surviving files into a gzipped tar via the existing
8
+ * `buildTarGz` helper.
9
+ *
10
+ * ## Ignore semantics — simplified subset of gitignore
11
+ *
12
+ * The matcher is intentionally minimal. It supports:
13
+ * - `# comment` / blank lines (skipped)
14
+ * - `pattern/` (matches directory basename anywhere in the tree)
15
+ * - `pattern` (matches file or directory basename anywhere in the tree)
16
+ * - `*.ext` (suffix glob — matches any basename ending in `.ext`)
17
+ * - `prefix*` (prefix glob — matches any basename starting with `prefix`)
18
+ *
19
+ * It does NOT support:
20
+ * - `!pattern` (negation)
21
+ * - Anchored patterns (`/foo`, `foo/bar`)
22
+ * - `**` (deep wildcards)
23
+ * - Character classes (`[abc]`)
24
+ *
25
+ * The built-in default ignore list ({@link DEFAULT_SOURCE_BUNDLE_IGNORES})
26
+ * covers the common build/output/secret directories. Creators with more
27
+ * sophisticated `.gitignore` rules can opt into explicit patterns via
28
+ * `--source-bundle-ignore <file>`. We accept this trade because the
29
+ * source bundle is a server-side artifact, not a developer-facing
30
+ * artifact, and false-positives (uploading too much) are recoverable
31
+ * (re-publish with stricter ignores) while false-negatives (uploading
32
+ * secrets) are not.
33
+ */
34
+
35
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
36
+ import { join, posix, relative, sep } from "node:path";
37
+ import { readBoundedText } from "./bounded-read.js";
38
+ import { buildTarGz } from "./tar.js";
39
+
40
+ /**
41
+ * Server-side cap on the source bundle. Matches `SOURCE_BUNDLE_MAX_BYTES`
42
+ * in `packages/poe-tiles-api/src/api/tiles/app-publish.ts`. Enforced
43
+ * client-side here so the CLI fails fast with a useful message before a
44
+ * large upload starts.
45
+ */
46
+ export const SOURCE_BUNDLE_MAX_BYTES = 100 * 1024 * 1024;
47
+
48
+ /**
49
+ * Cap on the number of files in a source bundle. Catches "walked into a
50
+ * directory the ignore list missed" regressions early — without this, a
51
+ * `node_modules` or `target/` directory that slipped past the ignore rules
52
+ * could fill the bundle with hundreds of thousands of tiny files before the
53
+ * byte cap ever fires. 50k leaves headroom for genuinely large repos while
54
+ * still flagging the common error mode.
55
+ */
56
+ export const SOURCE_BUNDLE_MAX_FILES = 50_000;
57
+
58
+ /**
59
+ * Names always excluded from source bundles. Mirrors the typical
60
+ * exclusion list creators have in `.gitignore`. Creators can layer
61
+ * additional patterns via `.gitignore` or `--source-bundle-ignore`.
62
+ *
63
+ * Each entry is an exact directory or file basename match, EXCEPT for
64
+ * a small handful of glob entries (`*.log`, `.env*`).
65
+ */
66
+ export const DEFAULT_SOURCE_BUNDLE_IGNORES: readonly string[] = [
67
+ // Build outputs
68
+ "node_modules/",
69
+ "dist/",
70
+ "build/",
71
+ "out/",
72
+ ".next/",
73
+ ".turbo/",
74
+ ".cache/",
75
+ "coverage/",
76
+ "test-results/",
77
+ "playwright-report/",
78
+ // The test report the tile scaffold's bunfig.toml writes on every
79
+ // `bun test`. Without this entry it shipped in source bundles, and a tile
80
+ // that gitignored it read as a narrowed bundle to the Creator bridge, so
81
+ // every preview upload waited for the turn's archive.
82
+ "junit.xml",
83
+ // VCS
84
+ ".git/",
85
+ // Local env / secrets
86
+ ".env",
87
+ ".env*",
88
+ ".dev.vars",
89
+ // Bridge-owned scratch. The creator agent writes this turn's one-line change
90
+ // summary here and the publish reads it, so the file EXISTS at publish time
91
+ // by construction — without this entry it would ship inside every uploaded
92
+ // copy of the creator's source.
93
+ ".poe-tile-change-summary",
94
+ // The creator-v2 prototype phase marker, written beside `.poe-tile.json`
95
+ // while a tile is still a store-less prototype. Bridge state rather
96
+ // than source: it decides which workflow the session is in and means
97
+ // nothing to a published tile, so shipping it inside every uploaded
98
+ // copy of the source would publish a platform detail and carry it into the
99
+ // project a conversion produces.
100
+ ".poe-prototype",
101
+ // Local CLI credential filenames. Keep excluding them so projects do not upload secrets.
102
+ ".poe-tiles-token",
103
+ "poe-tiles-api-key",
104
+ "poe-tiles-session-token",
105
+ // Logs. The glob is also what keeps a creator's prompt attachments out of
106
+ // the bundle: the bridge writes them to `uploads.log/` precisely because a
107
+ // container running an older published CLI already honors this pattern.
108
+ "*.log",
109
+ // Explicit too, so reading the list tells you the directory is excluded on
110
+ // purpose rather than by a coincidence of its name.
111
+ "uploads.log/",
112
+ // The version a `tiles checkout` folder was taken from (`checkout-base.ts`):
113
+ // local state that must not travel into Creator through a merge.
114
+ ".poe-checkout.log",
115
+ // A creator's own skills for the creator-v2 agent (`.poe-skills.log/<name>/
116
+ // SKILL.md`). Their preferences and reference material, never part of a
117
+ // tile's source; the `.log` suffix is what keeps them out of the bundle
118
+ // on a container whose CLI predates this line, and this entry is what says
119
+ // the exclusion is deliberate.
120
+ ".poe-skills.log/",
121
+ // Local verification output: the screenshots and recordings an agent or a
122
+ // creator captures while checking the tile in a browser. They live
123
+ // beside the source because the skill asks for the frames to be left in the
124
+ // workspace, and a 45-minute session's worth of them is what pushed a
125
+ // creator's bundle past the size cap on 2026-09-21 — with only a generic
126
+ // "packaging or uploading failed" to show for it. The template's .gitignore
127
+ // carries the same entry for CLIs that predate this line.
128
+ ".visual-checks/",
129
+ // `tiles inspect` bot scripts: hand-written test code that drives the tile,
130
+ // never part of what ships. Out of the bundle (and so out of the inspect
131
+ // build fingerprint), editing one never rebuilds or republishes the tile.
132
+ // Unlike `.visual-checks/`, Creator keeps it across container sleeps.
133
+ ".inspect-scripts/",
134
+ ];
135
+
136
+ /**
137
+ * Compiled ignore rule. Built once from each pattern line, applied per
138
+ * directory entry during the walk.
139
+ */
140
+ type CompiledRule = {
141
+ /** Original pattern, kept for diagnostics. */
142
+ source: string;
143
+ /** True iff the pattern ends with `/`; only matches directories. */
144
+ dirsOnly: boolean;
145
+ /** Predicate: does this rule match this basename? */
146
+ matches: (basename: string) => boolean;
147
+ };
148
+
149
+ function compilePattern(raw: string): CompiledRule | null {
150
+ let p = raw.trim();
151
+ if (!p || p.startsWith("#")) return null;
152
+ let dirsOnly = false;
153
+ if (p.endsWith("/")) {
154
+ dirsOnly = true;
155
+ p = p.slice(0, -1);
156
+ }
157
+
158
+ // Suffix glob: "*.log"
159
+ if (p.startsWith("*") && !p.slice(1).includes("*")) {
160
+ const suffix = p.slice(1);
161
+ return {
162
+ source: raw,
163
+ dirsOnly,
164
+ matches: (b) => b.endsWith(suffix),
165
+ };
166
+ }
167
+
168
+ // Prefix glob: ".env*"
169
+ if (p.endsWith("*") && !p.slice(0, -1).includes("*")) {
170
+ const prefix = p.slice(0, -1);
171
+ return {
172
+ source: raw,
173
+ dirsOnly,
174
+ matches: (b) => b.startsWith(prefix),
175
+ };
176
+ }
177
+
178
+ // Exact match
179
+ if (!p.includes("*") && !p.includes("/")) {
180
+ return {
181
+ source: raw,
182
+ dirsOnly,
183
+ matches: (b) => b === p,
184
+ };
185
+ }
186
+
187
+ // Anything more complex is silently ignored; the default-ignore list
188
+ // covers the cases this matcher can't express.
189
+ return null;
190
+ }
191
+
192
+ function compilePatterns(lines: readonly string[]): CompiledRule[] {
193
+ const out: CompiledRule[] = [];
194
+ for (const line of lines) {
195
+ const rule = compilePattern(line);
196
+ if (rule) out.push(rule);
197
+ }
198
+ return out;
199
+ }
200
+
201
+ /** An ignore file is lines of patterns; past this it is refused by size before it is read. */
202
+ export const IGNORE_FILE_MAX_BYTES = 1024 * 1024;
203
+
204
+ function readIgnoreFile(path: string): string[] {
205
+ return readBoundedText(
206
+ path,
207
+ IGNORE_FILE_MAX_BYTES,
208
+ (size) =>
209
+ new Error(
210
+ `Ignore file ${path} is ${size} bytes; the maximum is ${IGNORE_FILE_MAX_BYTES}.`,
211
+ ),
212
+ ).split(/\r?\n/);
213
+ }
214
+
215
+ function loadPatternsFromFile(path: string): string[] {
216
+ if (!existsSync(path)) return [];
217
+ const stat = statSync(path);
218
+ if (!stat.isFile()) return [];
219
+ return readIgnoreFile(path);
220
+ }
221
+
222
+ /**
223
+ * Strict variant for files the caller explicitly named via
224
+ * `--source-bundle-ignore`. A non-existent or non-regular-file path here is
225
+ * almost certainly a typo or wrong relative path — silently falling back to
226
+ * "no extra patterns" would let the typo through and ship the bundle with
227
+ * only built-in defaults + project `.gitignore`, defeating the whole point
228
+ * of the flag. Throw so the CLI surfaces the typo at the source.
229
+ */
230
+ function loadRequiredPatternsFromFile(path: string): string[] {
231
+ if (!existsSync(path)) {
232
+ throw new Error(
233
+ `--source-bundle-ignore path does not exist: ${path}\n` +
234
+ `Check that the path is relative to the current working directory ` +
235
+ `(or pass an absolute path).`,
236
+ );
237
+ }
238
+ const stat = statSync(path);
239
+ if (!stat.isFile()) {
240
+ throw new Error(
241
+ `--source-bundle-ignore path is not a regular file: ${path}`,
242
+ );
243
+ }
244
+ return readIgnoreFile(path);
245
+ }
246
+
247
+ function isIgnored(
248
+ rules: readonly CompiledRule[],
249
+ basename: string,
250
+ isDir: boolean,
251
+ ): boolean {
252
+ for (const r of rules) {
253
+ if (r.dirsOnly && !isDir) continue;
254
+ if (r.matches(basename)) return true;
255
+ }
256
+ return false;
257
+ }
258
+
259
+ const DEFAULT_RULES = compilePatterns(DEFAULT_SOURCE_BUNDLE_IGNORES);
260
+
261
+ /**
262
+ * Whether the default ignores exclude a path from every source bundle, as the
263
+ * walk decides it: a directory segment that matches excludes its whole
264
+ * subtree, and the last segment is a file unless `isDirectory` says so.
265
+ * `relativePath` uses `/` and is relative to the bundle root.
266
+ *
267
+ * Exported so a consumer restoring published files can refuse to write, delete
268
+ * or follow any path the published source bundle could not have carried.
269
+ */
270
+ export function isDefaultSourceBundleIgnored(
271
+ relativePath: string,
272
+ isDirectory = false,
273
+ ): boolean {
274
+ const segments = relativePath.split("/").filter((part) => part !== "");
275
+ return segments.some((segment, index) =>
276
+ isIgnored(
277
+ DEFAULT_RULES,
278
+ segment,
279
+ index < segments.length - 1 || isDirectory,
280
+ ),
281
+ );
282
+ }
283
+
284
+ /** A single file collected from the source tree. */
285
+ export type CollectedSourceFile = {
286
+ path: string;
287
+ data: Uint8Array;
288
+ /** Whether anyone may run the file, so the bundle can say so. */
289
+ executable: boolean;
290
+ };
291
+
292
+ /** Result of {@link collectSourceFiles}. */
293
+ export type CollectSourceFilesResult = {
294
+ files: CollectedSourceFile[];
295
+ totalBytes: number;
296
+ };
297
+
298
+ export type CollectSourceFilesOptions = {
299
+ /** Extra ignore-pattern file path (typically passed via `--source-bundle-ignore`). */
300
+ ignoreFile?: string;
301
+ /** Override the default ignore list. Used by tests. */
302
+ defaultIgnores?: readonly string[];
303
+ /** Override the global cap (bytes). Used by tests. */
304
+ maxTotalBytes?: number;
305
+ /** Override the global cap (file count). Used by tests. */
306
+ maxFiles?: number;
307
+ };
308
+
309
+ export function normalizeSourceBundlePath(
310
+ relativePath: string,
311
+ platformSeparator = sep,
312
+ ): string {
313
+ if (platformSeparator === posix.sep) return relativePath;
314
+ return relativePath.split(platformSeparator).join(posix.sep);
315
+ }
316
+
317
+ /**
318
+ * Walk a directory, apply ignore rules, and return a flat list of files
319
+ * suitable for {@link buildTarGz}. Aborts via thrown `Error` if the
320
+ * cumulative byte count exceeds {@link SOURCE_BUNDLE_MAX_BYTES} (or the
321
+ * test-overridden cap), with a message listing the largest contributors
322
+ * collected so far so the creator can target them with explicit ignores.
323
+ */
324
+ export function collectSourceFiles(
325
+ rootDir: string,
326
+ options: CollectSourceFilesOptions = {},
327
+ ): CollectSourceFilesResult {
328
+ const stat = statSync(rootDir, { throwIfNoEntry: false });
329
+ if (!stat?.isDirectory()) {
330
+ throw new Error(`Source bundle directory not found: ${rootDir}`);
331
+ }
332
+
333
+ const defaults = options.defaultIgnores ?? DEFAULT_SOURCE_BUNDLE_IGNORES;
334
+ const gitignoreLines = loadPatternsFromFile(join(rootDir, ".gitignore"));
335
+ // Caller-supplied --source-bundle-ignore: error on a missing path. The
336
+ // project's own .gitignore stays best-effort (loadPatternsFromFile)
337
+ // because not every project has one and that's a normal state.
338
+ const extraLines = options.ignoreFile
339
+ ? loadRequiredPatternsFromFile(options.ignoreFile)
340
+ : [];
341
+ const rules = compilePatterns([
342
+ ...defaults,
343
+ ...gitignoreLines,
344
+ ...extraLines,
345
+ ]);
346
+ const cap = options.maxTotalBytes ?? SOURCE_BUNDLE_MAX_BYTES;
347
+ const fileCap = options.maxFiles ?? SOURCE_BUNDLE_MAX_FILES;
348
+
349
+ const files: CollectedSourceFile[] = [];
350
+ const state = { totalBytes: 0 };
351
+
352
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Existing function exceeds the cognitive-complexity limit; keep the rule enabled for new code.
353
+ function walk(dir: string): void {
354
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
355
+ const fullPath = join(dir, entry.name);
356
+ if (isIgnored(rules, entry.name, entry.isDirectory())) continue;
357
+ if (entry.isDirectory()) {
358
+ walk(fullPath);
359
+ } else if (entry.isFile()) {
360
+ const relPath = normalizeSourceBundlePath(relative(rootDir, fullPath));
361
+ // The cap is checked against the file's SIZE before its contents are
362
+ // allocated, so an oversized file is refused without being read; the
363
+ // check after the read catches one that grew in between.
364
+ const fileStat = statSync(fullPath);
365
+ assertUnderCap(cap, state.totalBytes, files, {
366
+ path: relPath,
367
+ bytes: fileStat.size,
368
+ });
369
+ const data = readFileSync(fullPath);
370
+ // Charged after the read as well: the file may have grown since `stat`.
371
+ assertUnderCap(cap, state.totalBytes, files, {
372
+ path: relPath,
373
+ bytes: data.length,
374
+ });
375
+ state.totalBytes += data.length;
376
+ if (files.length + 1 > fileCap) {
377
+ throw new Error(
378
+ `Source bundle would exceed ${fileCap} files (limit). ` +
379
+ `This usually means the ignore list missed a build/dependency ` +
380
+ `directory (e.g. node_modules/, target/, vendor/). ` +
381
+ `Add patterns to .gitignore or pass --source-bundle-ignore <file>.`,
382
+ );
383
+ }
384
+ files.push({
385
+ path: relPath,
386
+ data,
387
+ executable: (fileStat.mode & 0o111) !== 0,
388
+ });
389
+ }
390
+ }
391
+ }
392
+
393
+ walk(rootDir);
394
+ return { files, totalBytes: state.totalBytes };
395
+ }
396
+
397
+ function formatMB(bytes: number): string {
398
+ return `${(bytes / (1024 * 1024)).toFixed(0)} MB`;
399
+ }
400
+
401
+ /**
402
+ * The cap diagnostic names the file that tripped it. In the typical overflow
403
+ * (one large binary in an otherwise normal source tree) that single file IS
404
+ * the one the creator needs to ignore, so it is listed with the files already
405
+ * collected rather than hidden by them.
406
+ */
407
+ function assertUnderCap(
408
+ cap: number,
409
+ totalBytes: number,
410
+ files: readonly CollectedSourceFile[],
411
+ offender: { path: string; bytes: number },
412
+ ): void {
413
+ if (totalBytes + offender.bytes > cap) throw overCap(cap, files, offender);
414
+ }
415
+
416
+ function overCap(
417
+ cap: number,
418
+ files: readonly CollectedSourceFile[],
419
+ offender: { path: string; bytes: number },
420
+ ): Error {
421
+ const offenders = topContributors(
422
+ [...files.map((f) => ({ path: f.path, bytes: f.data.length })), offender],
423
+ 5,
424
+ );
425
+ return new Error(
426
+ `Source bundle would exceed ${formatMB(cap)} (limit). ` +
427
+ `Largest contributors so far:\n${offenders}\n` +
428
+ `Add patterns to .gitignore or pass --source-bundle-ignore <file> ` +
429
+ `to exclude them. Local verification screenshots and recordings belong ` +
430
+ `under .visual-checks/, which is never bundled.`,
431
+ );
432
+ }
433
+
434
+ function topContributors(
435
+ files: readonly { path: string; bytes: number }[],
436
+ limit: number,
437
+ ): string {
438
+ const sorted = [...files].sort((a, b) => b.bytes - a.bytes);
439
+ return sorted
440
+ .slice(0, limit)
441
+ .map((f) => ` - ${f.path} (${formatMB(f.bytes)})`)
442
+ .join("\n");
443
+ }
444
+
445
+ /** Build a gzipped tar of the source tree. Convenience over {@link collectSourceFiles}. */
446
+ export function buildSourceBundleTarGz(
447
+ rootDir: string,
448
+ options: CollectSourceFilesOptions = {},
449
+ ): Uint8Array {
450
+ const { files } = collectSourceFiles(rootDir, options);
451
+ const fileMap = new Map<string, Uint8Array>();
452
+ const executablePaths = new Set<string>();
453
+ for (const f of files) {
454
+ fileMap.set(f.path, f.data);
455
+ if (f.executable) executablePaths.add(f.path);
456
+ }
457
+ return buildTarGz(fileMap, { executablePaths });
458
+ }
459
+
460
+ /** Verify a value is a valid `source_bundle_visibility` enum value. Exported for the CLI. */
461
+ export type SourceBundleVisibility = "owner_only" | "public";
462
+ export function isSourceBundleVisibility(
463
+ value: string,
464
+ ): value is SourceBundleVisibility {
465
+ return value === "owner_only" || value === "public";
466
+ }
@@ -0,0 +1,44 @@
1
+ // owner: aaronroe
2
+
3
+ import { conflictCode } from "./commit-in-progress";
4
+ import type { publishFormDataStaged } from "./staged-publish";
5
+
6
+ type FetchLike = Parameters<typeof publishFormDataStaged>[0]["fetchFn"];
7
+ /**
8
+ * Release this publish id's staged artifacts after a failure it can never
9
+ * recover from.
10
+ *
11
+ * Staging counts against `MAX_INCOMPLETE_PUBLISHES_PER_USER` until the hourly
12
+ * sweep reclaims it an hour later, and every attempt mints a fresh publish id — so
13
+ * without this, a publish that fails deterministically (a rejected commit) and
14
+ * is retried strands one full session per attempt and eventually answers 429
15
+ * for every OTHER Tile the same account publishes. That is exactly how a local
16
+ * `bun dev` catalog publish took itself down: 16 author-owned Tiles failed
17
+ * their commit, and the sessions they leaked wedged 21 unrelated Tiles.
18
+ *
19
+ * Best-effort by construction: cleanup must never mask the real publish error,
20
+ * so the response is discarded and a transport failure is swallowed — the sweep
21
+ * remains the backstop.
22
+ */
23
+ export async function abandonStagedPublish(input: {
24
+ serverUrl: string;
25
+ fetchFn: FetchLike;
26
+ headers: Record<string, string>;
27
+ publishId: string;
28
+ }): Promise<void> {
29
+ try {
30
+ await input.fetchFn(
31
+ `${input.serverUrl}/api/v1/tiles/publish-sessions/${input.publishId}`,
32
+ { method: "DELETE", headers: input.headers },
33
+ );
34
+ } catch {
35
+ // Swallowed: see above.
36
+ }
37
+ }
38
+
39
+ export async function isPublishCommitClaimConflict(
40
+ response: Response,
41
+ ): Promise<boolean> {
42
+ const code = await conflictCode(response);
43
+ return code === "publish_commit_in_progress" || code === "publish_id_reused";
44
+ }