@joiner-platform/cli 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/README.md +30 -2
  2. package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
  3. package/bundled-resources/poe-tile-templates/base/README.md +7 -0
  4. package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
  5. package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
  6. package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
  7. package/bundled-resources/poe-tile-templates/base/package.json +36 -0
  8. package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
  9. package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
  10. package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
  11. package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
  12. package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
  13. package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
  14. package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
  15. package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
  16. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
  17. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
  18. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
  19. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
  20. package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
  21. package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
  22. package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
  23. package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
  24. package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
  25. package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
  26. package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
  27. package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
  28. package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
  29. package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
  30. package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
  31. package/bundled-resources/poe-tile-templates/index.ts +27 -0
  32. package/bundled-resources/poe-tile-templates/package.json +31 -0
  33. package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
  34. package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
  35. package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
  36. package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
  37. package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
  38. package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
  39. package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
  40. package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
  41. package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
  42. package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
  43. package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
  44. package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
  45. package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
  46. package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
  47. package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
  48. package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
  49. package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
  50. package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
  51. package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
  52. package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
  53. package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
  54. package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
  55. package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
  56. package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
  57. package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
  58. package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
  59. package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
  60. package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
  61. package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
  62. package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
  63. package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
  64. package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
  65. package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
  66. package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
  67. package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
  68. package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
  69. package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
  70. package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
  71. package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
  72. package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
  73. package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
  74. package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
  75. package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
  76. package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
  77. package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
  78. package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
  79. package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
  80. package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
  81. package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
  82. package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
  83. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
  84. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
  85. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
  86. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
  87. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
  88. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
  89. package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
  90. package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
  91. package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
  92. package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
  93. package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
  94. package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
  95. package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
  96. package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
  97. package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
  98. package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
  99. package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
  100. package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
  101. package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
  102. package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
  103. package/cli.ts +134 -0
  104. package/index.ts +96 -0
  105. package/package.json +48 -5
  106. package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
  107. package/skills/audio-generation/SKILL.md +125 -0
  108. package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
  109. package/skills/finish-prototype/SKILL.md +22 -0
  110. package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
  111. package/skills/help-me-build/SKILL.md +56 -0
  112. package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
  113. package/skills/image-generation/SKILL.md +128 -0
  114. package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
  115. package/skills/one-shot/SKILL.md +22 -0
  116. package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
  117. package/skills/platform-prototype/SKILL.md +60 -0
  118. package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
  119. package/skills/platform-subagent/SKILL.md +16 -0
  120. package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
  121. package/skills/poe-tiles-cli/SKILL.md +609 -0
  122. package/skills/poe-tiles-cli/references/device-motion.md +40 -0
  123. package/skills/poe-tiles-cli/references/player-updates.md +41 -0
  124. package/skills/prototype/.generated-by-poe-templated-docs +0 -0
  125. package/skills/prototype/SKILL.md +149 -0
  126. package/skills/publish/.generated-by-poe-templated-docs +0 -0
  127. package/skills/publish/SKILL.md +73 -0
  128. package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
  129. package/skills/synced-store/SKILL.md +583 -0
  130. package/skills/synced-store/references/actions.md +85 -0
  131. package/skills/synced-store/references/api-patterns.md +245 -0
  132. package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
  133. package/skills/synced-store/references/client-api-reference.md +263 -0
  134. package/skills/synced-store/references/data-visibility.md +95 -0
  135. package/skills/synced-store/references/external-stores.md +162 -0
  136. package/skills/synced-store/references/file-uploads.md +216 -0
  137. package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
  138. package/skills/synced-store/references/limitations.md +72 -0
  139. package/skills/synced-store/references/live-data-limit-hook.md +131 -0
  140. package/skills/synced-store/references/mutator-rules.md +169 -0
  141. package/skills/synced-store/references/platform.md +49 -0
  142. package/skills/synced-store/references/schema-and-bindings.md +85 -0
  143. package/skills/synced-store/references/schema-libraries.md +57 -0
  144. package/skills/synced-store/references/schema-migrations.md +119 -0
  145. package/skills/synced-store/references/searchable-tables.md +27 -0
  146. package/skills/synced-store/references/server-forking.md +115 -0
  147. package/skills/synced-store/references/singleton-tables.md +61 -0
  148. package/skills/synced-store/references/sort-keys.md +253 -0
  149. package/skills/synced-store/references/ui-patterns.md +95 -0
  150. package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
  151. package/skills/tile-creator/SKILL.md +197 -0
  152. package/skills/tile-creator/references/assets.md +124 -0
  153. package/skills/tile-creator/references/backend-api.md +354 -0
  154. package/skills/tile-creator/references/cli-limitations.md +64 -0
  155. package/skills/tile-creator/references/cli.md +604 -0
  156. package/skills/tile-creator/references/client-api.md +2407 -0
  157. package/skills/tile-creator/references/composing-apps.md +166 -0
  158. package/skills/tile-creator/references/e2e-tests.md +55 -0
  159. package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
  160. package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
  161. package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
  162. package/skills/tile-creator/references/native-results.md +100 -0
  163. package/skills/tile-creator/references/platform-integration.md +201 -0
  164. package/skills/tile-creator/references/power-report.md +199 -0
  165. package/skills/tile-creator/references/publish-rollout.md +166 -0
  166. package/skills/tile-creator/references/publishing.md +33 -0
  167. package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
  168. package/skills/tile-creator/references/render-check.md +266 -0
  169. package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
  170. package/skills/tile-creator/references/safe-area-insets.md +79 -0
  171. package/skills/tile-creator/references/sandbox-limitations.md +32 -0
  172. package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
  173. package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
  174. package/skills/tile-creator/references/simulations.md +125 -0
  175. package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
  176. package/skills/tile-creator/references/troubleshooting.md +22 -0
  177. package/skills/tile-creator/references/turn-based-mutator.md +43 -0
  178. package/skills/tile-creator/references/user-erasure.md +14 -0
  179. package/skills/tile-creator/references/vite-plugin.md +166 -0
  180. package/skills/tile-creator/references/workspace-retention.md +72 -0
  181. package/src/admin-conversions-client.ts +28 -0
  182. package/src/admin-reviews-client.ts +36 -0
  183. package/src/api.generated.ts +1527 -0
  184. package/src/auth-token.ts +198 -0
  185. package/src/bounded-read.ts +35 -0
  186. package/src/bun-version.ts +33 -0
  187. package/src/checkout-base.ts +207 -0
  188. package/src/cli-bun-version.ts +16 -0
  189. package/src/cli-env.ts +28 -0
  190. package/src/cli-name.ts +23 -0
  191. package/src/client.ts +2474 -0
  192. package/src/collect-files.ts +226 -0
  193. package/src/commands/accounts.ts +55 -0
  194. package/src/commands/admin-abandon-conversion.ts +60 -0
  195. package/src/commands/admin-reviews.ts +66 -0
  196. package/src/commands/admin.ts +219 -0
  197. package/src/commands/auth.ts +89 -0
  198. package/src/commands/checkout-prototype.ts +67 -0
  199. package/src/commands/creator-source-capability.ts +11 -0
  200. package/src/commands/doctor-bun.ts +145 -0
  201. package/src/commands/doctor-command.ts +64 -0
  202. package/src/commands/doctor-package-json.ts +47 -0
  203. package/src/commands/doctor-sdk-pin.ts +156 -0
  204. package/src/commands/doctor-store-keys-lexer.ts +213 -0
  205. package/src/commands/doctor-store-keys-scan.ts +262 -0
  206. package/src/commands/doctor-store-keys.ts +196 -0
  207. package/src/commands/doctor.ts +371 -0
  208. package/src/commands/init/blank-scaffold-templates.ts +397 -0
  209. package/src/commands/init/index.ts +170 -0
  210. package/src/commands/init/internal-toolchain.ts +49 -0
  211. package/src/commands/init/manager-test-template.ts +107 -0
  212. package/src/commands/init/multiplayer-test-template.ts +217 -0
  213. package/src/commands/init/name-input.tsx +167 -0
  214. package/src/commands/init/no-store-scaffold-templates.ts +281 -0
  215. package/src/commands/init/no-store-scaffold.ts +134 -0
  216. package/src/commands/init/package-json-scripts.ts +72 -0
  217. package/src/commands/init/scaffold.ts +960 -0
  218. package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
  219. package/src/commands/init/sdk-tarball-url.ts +31 -0
  220. package/src/commands/init/template-picker.tsx +147 -0
  221. package/src/commands/inspect-child-entry.ts +107 -0
  222. package/src/commands/inspect-contract.ts +87 -0
  223. package/src/commands/inspect-freshness.ts +217 -0
  224. package/src/commands/inspect-lock.ts +201 -0
  225. package/src/commands/inspect-options.ts +360 -0
  226. package/src/commands/inspect-orchestrate.ts +375 -0
  227. package/src/commands/inspect-process.ts +172 -0
  228. package/src/commands/inspect-ready.ts +65 -0
  229. package/src/commands/inspect-report.ts +235 -0
  230. package/src/commands/inspect-run-state.ts +296 -0
  231. package/src/commands/inspect-run.ts +157 -0
  232. package/src/commands/inspect-watchdog.ts +74 -0
  233. package/src/commands/install-joiner.ts +208 -0
  234. package/src/commands/login.ts +308 -0
  235. package/src/commands/models.ts +40 -0
  236. package/src/commands/parse-options.ts +36 -0
  237. package/src/commands/remix-package-json.ts +64 -0
  238. package/src/commands/remix.ts +379 -0
  239. package/src/commands/sdk-url.ts +141 -0
  240. package/src/commands/simulations.ts +133 -0
  241. package/src/commands/skills.ts +108 -0
  242. package/src/commands/store-files.ts +92 -0
  243. package/src/commands/stores.ts +703 -0
  244. package/src/commands/tiles-channel-commands.ts +115 -0
  245. package/src/commands/tiles-checkout.ts +351 -0
  246. package/src/commands/tiles-gallery-command.ts +95 -0
  247. package/src/commands/tiles-get-helpers.ts +27 -0
  248. package/src/commands/tiles-inspect.ts +276 -0
  249. package/src/commands/tiles-power-command.ts +308 -0
  250. package/src/commands/tiles-power-format.ts +396 -0
  251. package/src/commands/tiles-power-versions.ts +299 -0
  252. package/src/commands/tiles-publish-helpers.ts +145 -0
  253. package/src/commands/tiles-upload-command.ts +277 -0
  254. package/src/commands/tiles-version-commands.ts +201 -0
  255. package/src/commands/tiles-visibility-command.ts +103 -0
  256. package/src/commands/tiles.ts +257 -0
  257. package/src/commands/upgrade.ts +307 -0
  258. package/src/commit-in-progress.ts +42 -0
  259. package/src/creator-source-context.ts +97 -0
  260. package/src/creator-source-publish.ts +52 -0
  261. package/src/deferred-assets.ts +125 -0
  262. package/src/distribution.ts +28 -0
  263. package/src/errors.ts +61 -0
  264. package/src/install-command.ts +43 -0
  265. package/src/output.ts +62 -0
  266. package/src/poe-tile-config-files.ts +100 -0
  267. package/src/poe-tile-config-players.ts +168 -0
  268. package/src/poe-tile-config-remix.ts +166 -0
  269. package/src/poe-tile-config.ts +831 -0
  270. package/src/power-report-client.ts +55 -0
  271. package/src/prototype-startup.ts +21 -0
  272. package/src/publish-change-summary.ts +55 -0
  273. package/src/publish-overrides-validation.ts +49 -0
  274. package/src/publish-pack.ts +167 -0
  275. package/src/publish-phases.ts +57 -0
  276. package/src/publish-retry.ts +51 -0
  277. package/src/publish-tile-from-config.ts +434 -0
  278. package/src/recorder-stream.ts +169 -0
  279. package/src/remix-provenance.ts +156 -0
  280. package/src/resolve-client-credential.ts +71 -0
  281. package/src/resolve-media-uploads.ts +147 -0
  282. package/src/sdk-dependency.ts +54 -0
  283. package/src/sdk-skills.ts +85 -0
  284. package/src/should-skip-client-setup.ts +20 -0
  285. package/src/simulation-snapshot.ts +123 -0
  286. package/src/simulation-types.ts +74 -0
  287. package/src/simulations-client.ts +112 -0
  288. package/src/source-bundle.ts +466 -0
  289. package/src/staged-publish-cleanup.ts +44 -0
  290. package/src/staged-publish-deferred.ts +160 -0
  291. package/src/staged-publish.ts +401 -0
  292. package/src/store-file-upload.ts +268 -0
  293. package/src/store-request.ts +168 -0
  294. package/src/tar-canonical.ts +41 -0
  295. package/src/tar-extensions.ts +159 -0
  296. package/src/tar-extract.ts +193 -0
  297. package/src/tar-parse.ts +224 -0
  298. package/src/tar.ts +231 -0
  299. package/src/template-check-scripts.ts +18 -0
  300. package/src/tile-gallery-client.ts +82 -0
  301. package/src/types.ts +258 -0
  302. package/src/upload-concurrency.ts +54 -0
  303. package/src/whole-tile.ts +52 -0
@@ -0,0 +1,396 @@
1
+ /**
2
+ * Human output for `tiles power`. Pure functions over the route's envelope,
3
+ * so every line has unit coverage without a server.
4
+ *
5
+ * Two rules every line follows, the same as the dashboard's battery card. The
6
+ * report compares a tile against the typical tile on unmatched phones, so an
7
+ * outcome reads as a comparison ("1.3× the typical tile"), never as an
8
+ * absolute current. And a number withheld under its sample floor reads as its
9
+ * count toward that floor ("12 of 30 sessions"), never as zero. Reason and
10
+ * context codes print as the stable identifiers the agent skill explains.
11
+ */
12
+
13
+ import type {
14
+ TilePowerFleet,
15
+ TilePowerReportEnvelope,
16
+ TilePowerTile,
17
+ } from "../power-report-client.js";
18
+
19
+ /**
20
+ * Sessions an outcome measurement (Android current, iOS escalation) needs
21
+ * before its value is shown. Mirrors `OUTCOME_SAMPLE_FLOOR` in
22
+ * `@lib/tile-power-report`; inlined because the CLI has no workspace
23
+ * dependencies, and drift is caught by `src/workspace-sync.test.ts`.
24
+ */
25
+ export const OUTCOME_SAMPLE_FLOOR = 30;
26
+ /** Mirrors `STRUCTURAL_SAMPLE_FLOOR` in `@lib/tile-power-report`. */
27
+ export const STRUCTURAL_SAMPLE_FLOOR = 10;
28
+
29
+ /** Mirrors `roundRatio` in `@lib/tile-power-report`: the precision the verdict compares at. */
30
+ export function roundRatio(ratio: number): number {
31
+ return Math.round(ratio * 10) / 10;
32
+ }
33
+
34
+ /** Mirrors `roundShare` in `@lib/tile-power-report`: whole percent, as a fraction. */
35
+ export function roundShare(share: number): number {
36
+ return Math.round(share * 100) / 100;
37
+ }
38
+
39
+ type MeasuredVersions = NonNullable<TilePowerTile["measured_versions"]>;
40
+
41
+ /**
42
+ * Mirrors `powerVerdictBasis` in `@lib/tile-power-report`: the verdict's
43
+ * qualifier on a default report, none on a version report or without the
44
+ * field (a server from before the measured set).
45
+ */
46
+ export function verdictBasis(
47
+ measured: MeasuredVersions | null | undefined,
48
+ report: "default" | "version",
49
+ ): "latest" | "recent" | null {
50
+ if (!measured || report === "version") return null;
51
+ return measured.bundle_count === 1 &&
52
+ measured.newest === measured.live_version
53
+ ? "latest"
54
+ : "recent";
55
+ }
56
+
57
+ type Row = [string, string];
58
+
59
+ /** One weighted measurement count beside its raw row count. */
60
+ interface Counted {
61
+ value: number | null;
62
+ samples: number;
63
+ rows: number;
64
+ }
65
+
66
+ /** The floor is met only when both counts reach it, so the honest count is the smaller. */
67
+ function sessionCount(measurement: Counted): number {
68
+ return Math.min(measurement.samples, measurement.rows);
69
+ }
70
+
71
+ /** Who a count covers, beyond plain "sessions": "12 mobile sessions, browsers included". */
72
+ interface Cohort {
73
+ kind: string;
74
+ note: string;
75
+ }
76
+
77
+ /** `kind` names a narrower cohort, such as "mobile" in "12 mobile sessions". */
78
+ function sessions(count: number, kind?: string): string {
79
+ const noun = kind === undefined ? "session" : `${kind} session`;
80
+ return `${count.toLocaleString("en-US")} ${noun}${count === 1 ? "" : "s"}`;
81
+ }
82
+
83
+ function percent(share: number): string {
84
+ return `${Math.round(roundShare(share) * 100)}%`;
85
+ }
86
+
87
+ /**
88
+ * Why a value is null. Under the floor the server withholds it and the count
89
+ * says how far along it is; at or above the floor the hourly rotation has not
90
+ * reached the tile yet, and "40 of 30" would contradict itself.
91
+ */
92
+ function withheld(
93
+ measurement: Counted,
94
+ floor: number,
95
+ cohort?: Cohort,
96
+ ): string {
97
+ const count = sessionCount(measurement);
98
+ const noun = cohort === undefined ? "sessions" : `${cohort.kind} sessions`;
99
+ const note = cohort === undefined ? "" : `, ${cohort.note}`;
100
+ if (count === 0) return `no ${noun} yet`;
101
+ if (count >= floor) {
102
+ return `${sessions(count, cohort?.kind)}${note}, not computed yet`;
103
+ }
104
+ return `${count} of ${floor} ${noun}${note}`;
105
+ }
106
+
107
+ function androidReading(tile: Counted, fleet: TilePowerFleet): string {
108
+ if (tile.value === null) return withheld(tile, OUTCOME_SAMPLE_FLOOR);
109
+ const over = `over ${sessions(sessionCount(tile))}`;
110
+ const baseline = fleet.android_p50_current_ma;
111
+ if (baseline === null || baseline <= 0) {
112
+ return `measured ${over}, waiting for the baseline`;
113
+ }
114
+ return `${roundRatio(tile.value / baseline).toFixed(1)}× the typical tile ${over}`;
115
+ }
116
+
117
+ /**
118
+ * " · version 1698" beside a carried figure that came from an earlier
119
+ * version than the set's newest, so a reading always says which code it
120
+ * describes; empty when it is the newest's own or the report has no set.
121
+ */
122
+ function sourceVersion(
123
+ measured: MeasuredVersions | null | undefined,
124
+ source: keyof MeasuredVersions["sources"],
125
+ ): string {
126
+ const version = measured?.sources[source];
127
+ if (!measured || version === null || version === undefined) return "";
128
+ return version === measured.newest ? "" : ` · version ${version}`;
129
+ }
130
+
131
+ /** The "Measured" row: "v1703", or "v1690 to v1703, 5 builds". */
132
+ function measuredReading(measured: MeasuredVersions): string {
133
+ if (measured.newest === measured.oldest) return `v${measured.newest}`;
134
+ return `v${measured.oldest} to v${measured.newest}, ${measured.bundle_count} builds`;
135
+ }
136
+
137
+ /** The verdict word with its qualifier on a default report's hot or watch. */
138
+ function verdictReading(
139
+ tile: TilePowerTile,
140
+ report: "default" | "version",
141
+ ): string {
142
+ if (tile.verdict !== "hot" && tile.verdict !== "watch") return tile.verdict;
143
+ const basis = verdictBasis(tile.measured_versions, report);
144
+ if (basis === "recent") return `${tile.verdict}, based on recent versions`;
145
+ if (basis === "latest") return `${tile.verdict}, based on latest version`;
146
+ return tile.verdict;
147
+ }
148
+
149
+ function iosReading(tile: Counted, fleet: TilePowerFleet): string {
150
+ if (tile.value === null) return withheld(tile, OUTCOME_SAMPLE_FLOOR);
151
+ const over = `over ${sessions(sessionCount(tile))}`;
152
+ const baseline = fleet.ios_escalation_share;
153
+ if (baseline === null) return `measured ${over}, waiting for the baseline`;
154
+ return `${percent(tile.value)} of cool-start sessions warmed up (typical tile ${percent(baseline)}) ${over}`;
155
+ }
156
+
157
+ /**
158
+ * Unlike the battery outcomes, structural measurements count browser sessions
159
+ * too, so every count names its cohort: "14 sessions" of missed frames must
160
+ * not read as 14 phone-app sessions.
161
+ */
162
+ function structuralReading(
163
+ measurement: Counted,
164
+ kind: string,
165
+ format: (value: number) => string,
166
+ ): string {
167
+ const cohort: Cohort = { kind, note: "browsers included" };
168
+ if (measurement.value === null) {
169
+ return withheld(measurement, STRUCTURAL_SAMPLE_FLOOR, cohort);
170
+ }
171
+ return `${format(measurement.value)} over ${sessions(sessionCount(measurement), kind)}, ${cohort.note}`;
172
+ }
173
+
174
+ function fleetBaseline(fleet: TilePowerFleet): string {
175
+ const android = {
176
+ value: fleet.android_p50_current_ma,
177
+ samples: fleet.android_samples,
178
+ rows: fleet.android_rows,
179
+ };
180
+ const ios = {
181
+ value: fleet.ios_escalation_share,
182
+ samples: fleet.ios_cool_start_samples,
183
+ rows: fleet.ios_cool_start_rows,
184
+ };
185
+ const androidPart =
186
+ android.value === null
187
+ ? `Android ${withheld(android, OUTCOME_SAMPLE_FLOOR)}`
188
+ : `Android measured over ${sessions(sessionCount(android))}`;
189
+ const iosPart =
190
+ ios.value === null
191
+ ? `iPhone ${withheld(ios, OUTCOME_SAMPLE_FLOOR)}`
192
+ : `iPhone ${percent(ios.value)} of cool-start sessions warmed up over ${sessions(sessionCount(ios))}`;
193
+ return `${androidPart}; ${iosPart}`;
194
+ }
195
+
196
+ /** The envelope header: when the report was built, how fresh, and the baselines it compares against. */
197
+ export function powerReportHeaderRows(report: TilePowerReportEnvelope): Row[] {
198
+ return [
199
+ [
200
+ "Window",
201
+ `last ${report.window_days} days; battery outcomes from the phone apps only`,
202
+ ],
203
+ ["Generated", `${report.generated_at} (${report.freshness})`],
204
+ [
205
+ "Rotating",
206
+ report.rotating
207
+ ? "yes, some tiles keep an earlier hour's numbers (see Computed)"
208
+ : "no",
209
+ ],
210
+ ["Typical tile", fleetBaseline(report.fleet)],
211
+ ];
212
+ }
213
+
214
+ type CurrentBuild = NonNullable<TilePowerTile["current_build"]>;
215
+
216
+ /** A build's outcome counts are null when the tile is outside the build cohorts. */
217
+ function counted(
218
+ value: number | null,
219
+ samples: number | null,
220
+ rows: number | null,
221
+ ): Counted | null {
222
+ return samples === null || rows === null ? null : { value, samples, rows };
223
+ }
224
+
225
+ function buildOutcomes(build: CurrentBuild) {
226
+ return {
227
+ android: counted(
228
+ build.android_p50_current_ma,
229
+ build.android_samples,
230
+ build.android_rows,
231
+ ),
232
+ ios: counted(
233
+ build.ios_escalation_share,
234
+ build.ios_cool_start_samples,
235
+ build.ios_cool_start_rows,
236
+ ),
237
+ };
238
+ }
239
+
240
+ function measuredBuildReading(
241
+ build: CurrentBuild,
242
+ fleet: TilePowerFleet,
243
+ ): string {
244
+ const { android, ios } = buildOutcomes(build);
245
+ return [
246
+ android?.value == null ? null : `Android ${androidReading(android, fleet)}`,
247
+ ios?.value == null ? null : `iPhone ${iosReading(ios, fleet)}`,
248
+ ]
249
+ .filter((part): part is string => part !== null)
250
+ .join("; ");
251
+ }
252
+
253
+ function collectingBuildReading(build: CurrentBuild): string {
254
+ if (build.sessions === null) return "collecting";
255
+ const { android, ios } = buildOutcomes(build);
256
+ // The platform closest to the floor decides when the line turns measured.
257
+ const collected = Math.max(
258
+ android === null ? 0 : sessionCount(android),
259
+ ios === null ? 0 : sessionCount(ios),
260
+ );
261
+ if (collected === 0) return "collecting, no phone sessions yet";
262
+ if (collected >= OUTCOME_SAMPLE_FLOOR) {
263
+ return `collecting, ${sessions(collected)} so far`;
264
+ }
265
+ return `collecting, ${collected} of ${OUTCOME_SAMPLE_FLOOR} sessions`;
266
+ }
267
+
268
+ function currentBuildReading(
269
+ tile: TilePowerTile,
270
+ fleet: TilePowerFleet,
271
+ ): string {
272
+ const build = tile.current_build;
273
+ if (build === null) return "no published build";
274
+ if (build.status === "pending_refresh") {
275
+ return "published after this report; measured on the next refresh";
276
+ }
277
+ const label =
278
+ build.version_number === null ? "current" : `v${build.version_number}`;
279
+ const reading =
280
+ build.status === "measured"
281
+ ? measuredBuildReading(build, fleet)
282
+ : collectingBuildReading(build);
283
+ return `${label}: ${reading}`;
284
+ }
285
+
286
+ function computedReading(
287
+ computedAt: string | null,
288
+ generatedAt: string,
289
+ ): string {
290
+ if (computedAt === null) return "not yet";
291
+ return new Date(computedAt) < new Date(generatedAt)
292
+ ? `${computedAt} (carried forward; recomputed in hourly rotation)`
293
+ : computedAt;
294
+ }
295
+
296
+ function list(codes: readonly string[]): string {
297
+ return codes.length === 0 ? "none" : codes.join(", ");
298
+ }
299
+
300
+ /**
301
+ * One tile's row as key-value pairs, its reasons and context kept apart.
302
+ * `reportKind` is which report the tile came from: the default one, whose
303
+ * hot and watch carry a basis qualifier and whose "Measured" row names the
304
+ * set, or one picked version (`--version`), which names itself and has no
305
+ * current-build row.
306
+ */
307
+ export function powerTileRows(
308
+ tile: TilePowerTile,
309
+ report: TilePowerReportEnvelope,
310
+ reportKind: "default" | "version" = "default",
311
+ ): Row[] {
312
+ const { metrics, sessions: counts } = tile;
313
+ // An older server omits the field; the generated type reads it as required.
314
+ const measured = tile.measured_versions as
315
+ | TilePowerTile["measured_versions"]
316
+ | undefined;
317
+ const measuredRow: Row[] =
318
+ measured === undefined
319
+ ? []
320
+ : [["Measured", measured === null ? "none" : measuredReading(measured)]];
321
+ return [
322
+ [
323
+ "Tile",
324
+ `${tile.handle}${tile.display_name ? ` (${tile.display_name})` : ""}`,
325
+ ],
326
+ ["Tile ID", tile.tile_id],
327
+ ...measuredRow,
328
+ ["Verdict", verdictReading(tile, reportKind)],
329
+ ["Reasons", list(tile.reasons)],
330
+ ["Context", list(tile.context)],
331
+ ["Computed", computedReading(tile.computed_at, report.generated_at)],
332
+ [
333
+ "Sessions",
334
+ `${counts.total.toLocaleString("en-US")} (Android ${counts.android.toLocaleString("en-US")}, iPhone ${counts.ios.toLocaleString("en-US")}, web ${counts.web.toLocaleString("en-US")})`,
335
+ ],
336
+ [
337
+ "Android",
338
+ `${androidReading(
339
+ {
340
+ value: metrics.android_p50_current_ma,
341
+ samples: metrics.android_samples,
342
+ rows: metrics.android_rows,
343
+ },
344
+ report.fleet,
345
+ )}${sourceVersion(measured, "android")}`,
346
+ ],
347
+ [
348
+ "iPhone",
349
+ iosReading(
350
+ {
351
+ value: metrics.ios_escalation_share,
352
+ samples: metrics.ios_cool_start_samples,
353
+ rows: metrics.ios_cool_start_rows,
354
+ },
355
+ report.fleet,
356
+ ),
357
+ ],
358
+ [
359
+ "Pixel ratio",
360
+ `${structuralReading(
361
+ {
362
+ value: metrics.p50_surface_pixel_ratio,
363
+ samples: metrics.surface_pixel_ratio_samples,
364
+ rows: metrics.surface_pixel_ratio_rows,
365
+ },
366
+ "mobile",
367
+ (ratio) => `p50 ${ratio.toFixed(2)}×`,
368
+ )}${sourceVersion(measured, "surface_pixel_ratio")}`,
369
+ ],
370
+ [
371
+ "Missed frames",
372
+ `${structuralReading(
373
+ {
374
+ // A server from before the p75 omits the field; never fall back to the p95.
375
+ value: metrics.capped_p75_missed_frame_ratio ?? null,
376
+ samples: metrics.capped_missed_frame_samples,
377
+ rows: metrics.capped_missed_frame_rows,
378
+ },
379
+ // Only sessions with a frame-rate cap report missed frames: phones by
380
+ // default, desktop only when the tile sets `targetFps` itself.
381
+ "render-budget",
382
+ (ratio) => `p75 ${percent(ratio)} of frames`,
383
+ )}${sourceVersion(measured, "missed_frames")}`,
384
+ ],
385
+ // A version report measures the version it names; the route nulls
386
+ // its current build.
387
+ ...(reportKind === "version"
388
+ ? []
389
+ : [["Current build", currentBuildReading(tile, report.fleet)] as Row]),
390
+ ];
391
+ }
392
+
393
+ /** The closing line every report carries: the comparison is a lead, not a measurement. */
394
+ export const POWER_SIGNAL_NOTE =
395
+ "A signal to investigate, not a measurement of the tile alone: the typical " +
396
+ "tile was measured on different phones.";
@@ -0,0 +1,299 @@
1
+ /**
2
+ * `tiles power --all-versions`: a tile's newest published versions, each
3
+ * with its own report, in one command, so an agent asked "when did this
4
+ * start" reads the run instead of one `--version` at a time.
5
+ *
6
+ * The CLI composes it from reads the route already serves: the default
7
+ * report, then one version report per version through `version_number`.
8
+ * The route deliberately has no variant that returns every version in one
9
+ * response: that needs a new response shape through both stores for a
10
+ * question the newest versions answer. The price is a cap, because the
11
+ * route allows a fixed number of reads a minute per user. The cap binds
12
+ * only a tile with more versions than that inside the report's 7-day
13
+ * window, and such a tile's versions are usually each too thin to judge on
14
+ * their own anyway. The full reasoning, and what would justify the route
15
+ * variant, is in `docs/tile-power-metrics-queries.md` (Reading a run of
16
+ * versions).
17
+ */
18
+
19
+ import type { SlopPoeClient } from "../client.js";
20
+ import { assertSuccess, CliError } from "../errors.js";
21
+ import { printKeyValue, printTable } from "../output.js";
22
+ import type {
23
+ TilePowerReportBody,
24
+ TilePowerReportEnvelope,
25
+ TilePowerTile,
26
+ } from "../power-report-client.js";
27
+ import type { CliTileChannel, CliTileVersion } from "../types.js";
28
+ import {
29
+ POWER_SIGNAL_NOTE,
30
+ powerReportHeaderRows,
31
+ powerTileRows,
32
+ } from "./tiles-power-format.js";
33
+ import { channelNamesServing, versionLabel } from "./tiles-version-commands.js";
34
+
35
+ /**
36
+ * Reads the route allows one user in a minute. Mirrors the `limit` of the
37
+ * `RATE_LIMIT_TILE_POWER_REPORT_PER_USER_MINUTE` binding in the Worker's
38
+ * wrangler config; drift is caught by `src/workspace-sync.test.ts`.
39
+ */
40
+ export const POWER_REPORT_READS_PER_MINUTE = 60;
41
+ /** A third of a minute's reads, so a run leaves room for a second look. */
42
+ export const ALL_VERSIONS_DEFAULT_LIMIT = 20;
43
+ /**
44
+ * The most versions one run reads. With the default report's own read that
45
+ * is 51, under `POWER_REPORT_READS_PER_MINUTE`, so a run with the minute to
46
+ * itself fits.
47
+ */
48
+ export const ALL_VERSIONS_MAX_LIMIT = 50;
49
+
50
+ /** `--limit <n>` beside `--all-versions`: 1 to the cap, or the default. */
51
+ export function parseAllVersionsLimit(raw: string | undefined): number {
52
+ if (raw === undefined) return ALL_VERSIONS_DEFAULT_LIMIT;
53
+ const limit = Number(raw);
54
+ if (!/^[1-9]\d*$/.test(raw) || limit > ALL_VERSIONS_MAX_LIMIT) {
55
+ throw new CliError(
56
+ `--limit must be a number of versions from 1 to ${ALL_VERSIONS_MAX_LIMIT}.`,
57
+ );
58
+ }
59
+ return limit;
60
+ }
61
+
62
+ /** One published version beside its own report. */
63
+ export interface VersionPowerReport {
64
+ version_number: number;
65
+ published_at: string;
66
+ display_name: string | null;
67
+ /** The channels serving this version, such as `live`. */
68
+ channels: string[];
69
+ report: TilePowerTile;
70
+ }
71
+
72
+ /** The default report's envelope and tile, then each version's own report, newest first. */
73
+ export interface AllVersionsPowerReport extends TilePowerReportEnvelope {
74
+ tile: TilePowerTile;
75
+ versions: VersionPowerReport[];
76
+ /** The tile has older versions than the ones read. */
77
+ more_versions: boolean;
78
+ /**
79
+ * The hourly report was rebuilt between two of the reads, so some
80
+ * versions come from a newer report than `generated_at` and `fleet`
81
+ * describe. Rare (the run takes seconds, the rebuild is hourly), but a
82
+ * row's comparison is then against a baseline its verdict did not use.
83
+ */
84
+ rebuilt_during_read: boolean;
85
+ }
86
+
87
+ /** A version report read; without a version, the default report. */
88
+ type ReadReport = (versionNumber?: number) => Promise<TilePowerReportBody>;
89
+
90
+ /**
91
+ * A rate limit part-way fails the run and prints no rows: a partial table
92
+ * would read as the tile's whole run of versions, and the reads already
93
+ * spent do not come back by printing them. The limit is per account, shared
94
+ * with the dashboard and the account's other sessions, and one run alone
95
+ * never reaches it, so the advice is to wait; a smaller `--limit` only
96
+ * leaves more of the next minute for everything else.
97
+ */
98
+ function rateLimited(read: number, total: number): CliError {
99
+ return new CliError(
100
+ `Rate limited after reading ${read} of ${total} versions: the report ` +
101
+ `allows your account ${POWER_REPORT_READS_PER_MINUTE} reads a minute ` +
102
+ "and --all-versions makes one per version. Wait a minute, then run " +
103
+ "it again; a smaller --limit spends fewer reads.",
104
+ { status: 429 },
105
+ );
106
+ }
107
+
108
+ /**
109
+ * The version's own tile entry and the hourly report it came from; the
110
+ * route answers a version report with exactly one tile.
111
+ */
112
+ async function readVersion(
113
+ read: ReadReport,
114
+ version: CliTileVersion,
115
+ progress: { read: number; total: number },
116
+ ): Promise<{ tile: TilePowerTile; generatedAt: string }> {
117
+ try {
118
+ const report = await read(version.versionNumber);
119
+ const [tile] = report.tiles;
120
+ if (tile === undefined) {
121
+ throw new CliError(`No report for version ${version.versionNumber}.`);
122
+ }
123
+ return { tile, generatedAt: report.generated_at };
124
+ } catch (error) {
125
+ if (error instanceof CliError && error.status === 429) {
126
+ throw rateLimited(progress.read, progress.total);
127
+ }
128
+ throw error;
129
+ }
130
+ }
131
+
132
+ /**
133
+ * The tile's newest versions and its channels, or none of either on a 404.
134
+ * The versions route answers 404 for a tile that is not a published tile
135
+ * (an edit preview, for one), which has a report but no version list; the
136
+ * channels route answers the same tile with an empty list. The report was
137
+ * just read for this tile, so it exists and is the caller's, and a 404 from
138
+ * either read is taken to mean there are no versions to show.
139
+ */
140
+ async function listVersions(
141
+ client: Pick<SlopPoeClient, "listTileVersions" | "getTileChannels">,
142
+ tileId: string,
143
+ limit: number,
144
+ ): Promise<{
145
+ versions: CliTileVersion[];
146
+ channels: CliTileChannel[];
147
+ more: boolean;
148
+ }> {
149
+ try {
150
+ const [listed, channels] = await Promise.all([
151
+ client.listTileVersions(tileId, limit),
152
+ client.getTileChannels(tileId),
153
+ ]);
154
+ assertSuccess(listed);
155
+ assertSuccess(channels);
156
+ return {
157
+ versions: listed.versions,
158
+ channels: channels.channels,
159
+ // The versions route omits its cursor on the last page.
160
+ more: listed.nextCursor != null,
161
+ };
162
+ } catch (error) {
163
+ if (error instanceof CliError && error.status === 404) {
164
+ return { versions: [], channels: [], more: false };
165
+ }
166
+ throw error;
167
+ }
168
+ }
169
+
170
+ /**
171
+ * The default report, then the newest `limit` versions' own reports, read
172
+ * one after another so a tile with many versions never bursts the route.
173
+ *
174
+ * The default report is read first even when the tile is already known: it
175
+ * names the tile for a Creator session, which holds no tile id, it carries
176
+ * the measured set the tile's verdict rests on, and it fails with the
177
+ * command's own explanations before any version is read.
178
+ */
179
+ export async function readAllVersionsReport(
180
+ client: Pick<SlopPoeClient, "listTileVersions" | "getTileChannels">,
181
+ read: ReadReport,
182
+ limit: number,
183
+ ): Promise<AllVersionsPowerReport> {
184
+ const { tiles, next_cursor: _nextCursor, ...envelope } = await read();
185
+ const [tile] = tiles;
186
+ if (tile === undefined) throw new CliError("No tile to report on.");
187
+ const listed = await listVersions(client, tile.tile_id, limit);
188
+ const versions: VersionPowerReport[] = [];
189
+ let rebuilt = false;
190
+ for (const version of listed.versions) {
191
+ // biome-ignore lint/performance/noAwaitInLoops: one read at a time, so many versions never burst the rate-limited route.
192
+ const own = await readVersion(read, version, {
193
+ read: versions.length,
194
+ total: listed.versions.length,
195
+ });
196
+ rebuilt ||= own.generatedAt !== envelope.generated_at;
197
+ versions.push({
198
+ version_number: version.versionNumber,
199
+ published_at: version.publishedAt,
200
+ display_name: version.displayName,
201
+ channels: channelNamesServing(listed.channels, version.versionNumber),
202
+ report: own.tile,
203
+ });
204
+ }
205
+ return {
206
+ ...envelope,
207
+ tile,
208
+ versions,
209
+ more_versions: listed.more,
210
+ rebuilt_during_read: rebuilt,
211
+ };
212
+ }
213
+
214
+ const ALL_VERSIONS_HEADERS = [
215
+ "Version",
216
+ "Published",
217
+ "Verdict",
218
+ "Reasons",
219
+ "Sessions",
220
+ "Android",
221
+ "iPhone",
222
+ ];
223
+
224
+ /**
225
+ * One line per version, in the words its own `--version` report prints: the
226
+ * verdict with no qualifier, and each outcome as a comparison or as its
227
+ * count toward the floor, never as zero. The verdict, reasons and outcome
228
+ * cells are `powerTileRows`' own values, looked up by label so a row words a
229
+ * reading as that report does; `tiles-power-versions.test.ts` pins the
230
+ * labels, since a renamed one would print an empty cell. Sessions is the
231
+ * total alone, without the report's per-platform breakdown. Every row is
232
+ * compared against the default report's baseline, which is each version's
233
+ * own except across a rebuild (`rebuilt_during_read`).
234
+ */
235
+ export function allVersionsTableRows(
236
+ report: AllVersionsPowerReport,
237
+ ): string[][] {
238
+ return report.versions.map((version) => {
239
+ const own = new Map(powerTileRows(version.report, report, "version"));
240
+ return [
241
+ versionLabel(version.version_number, version.channels),
242
+ version.published_at,
243
+ own.get("Verdict") ?? "",
244
+ own.get("Reasons") ?? "",
245
+ version.report.sessions.total.toLocaleString("en-US"),
246
+ own.get("Android") ?? "",
247
+ own.get("iPhone") ?? "",
248
+ ];
249
+ });
250
+ }
251
+
252
+ /** How to read the rows, and what was left out when the tile has older versions. */
253
+ export function allVersionsNotes(report: AllVersionsPowerReport): string[] {
254
+ const count = report.versions.length;
255
+ if (count === 0) return ["No published versions to report."];
256
+ return [
257
+ "Each row is that version's own report over the same window; a version " +
258
+ "with too few sessions reads insufficient_data with its count, so " +
259
+ "read the run, not one row. `--version <n>` prints one version's " +
260
+ "full measurements.",
261
+ ...(report.rebuilt_during_read
262
+ ? [
263
+ "The hourly report was rebuilt while these were read, so some rows " +
264
+ "come from a newer report than the header. Run it again for one " +
265
+ "consistent read.",
266
+ ]
267
+ : []),
268
+ ...(report.more_versions
269
+ ? [
270
+ `Showing the newest ${count} version${count === 1 ? "" : "s"}; the tile has older ones. ` +
271
+ // At the cap there is no larger limit to offer.
272
+ (count < ALL_VERSIONS_MAX_LIMIT
273
+ ? `Pass --limit <n> (at most ${ALL_VERSIONS_MAX_LIMIT}) for more, or read an older one with --version <n>.`
274
+ : "Read an older one with --version <n>."),
275
+ ]
276
+ : []),
277
+ ];
278
+ }
279
+
280
+ export function printAllVersionsReport(report: AllVersionsPowerReport): void {
281
+ console.log("Battery and heat report, by version");
282
+ printKeyValue(powerReportHeaderRows(report));
283
+ console.log("");
284
+ // The default report in full, as `tiles power <tile>` prints it: the
285
+ // header's Rotating line refers to its Computed row, and its verdict
286
+ // needs its reasons beside it.
287
+ printKeyValue(powerTileRows(report.tile, report));
288
+ console.log("");
289
+ if (report.versions.length > 0) {
290
+ printTable({
291
+ headers: ALL_VERSIONS_HEADERS,
292
+ rows: allVersionsTableRows(report),
293
+ });
294
+ console.log("");
295
+ }
296
+ for (const note of allVersionsNotes(report)) console.log(note);
297
+ console.log("");
298
+ console.log(POWER_SIGNAL_NOTE);
299
+ }