@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.
- package/README.md +30 -2
- package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
- package/bundled-resources/poe-tile-templates/base/README.md +7 -0
- package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
- package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
- package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
- package/bundled-resources/poe-tile-templates/base/package.json +36 -0
- package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
- package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
- package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
- package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
- package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
- package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
- package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
- package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
- package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
- package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
- package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
- package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
- package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
- package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
- package/bundled-resources/poe-tile-templates/index.ts +27 -0
- package/bundled-resources/poe-tile-templates/package.json +31 -0
- package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
- package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
- package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
- package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
- package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
- package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
- package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
- package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
- package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
- package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
- package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
- package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
- package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
- package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
- package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
- package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
- package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
- package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
- package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
- package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
- package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
- package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
- package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
- package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
- package/cli.ts +134 -0
- package/index.ts +96 -0
- package/package.json +48 -5
- package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/audio-generation/SKILL.md +125 -0
- package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/finish-prototype/SKILL.md +22 -0
- package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
- package/skills/help-me-build/SKILL.md +56 -0
- package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/image-generation/SKILL.md +128 -0
- package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
- package/skills/one-shot/SKILL.md +22 -0
- package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-prototype/SKILL.md +60 -0
- package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-subagent/SKILL.md +16 -0
- package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
- package/skills/poe-tiles-cli/SKILL.md +609 -0
- package/skills/poe-tiles-cli/references/device-motion.md +40 -0
- package/skills/poe-tiles-cli/references/player-updates.md +41 -0
- package/skills/prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/prototype/SKILL.md +149 -0
- package/skills/publish/.generated-by-poe-templated-docs +0 -0
- package/skills/publish/SKILL.md +73 -0
- package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
- package/skills/synced-store/SKILL.md +583 -0
- package/skills/synced-store/references/actions.md +85 -0
- package/skills/synced-store/references/api-patterns.md +245 -0
- package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
- package/skills/synced-store/references/client-api-reference.md +263 -0
- package/skills/synced-store/references/data-visibility.md +95 -0
- package/skills/synced-store/references/external-stores.md +162 -0
- package/skills/synced-store/references/file-uploads.md +216 -0
- package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
- package/skills/synced-store/references/limitations.md +72 -0
- package/skills/synced-store/references/live-data-limit-hook.md +131 -0
- package/skills/synced-store/references/mutator-rules.md +169 -0
- package/skills/synced-store/references/platform.md +49 -0
- package/skills/synced-store/references/schema-and-bindings.md +85 -0
- package/skills/synced-store/references/schema-libraries.md +57 -0
- package/skills/synced-store/references/schema-migrations.md +119 -0
- package/skills/synced-store/references/searchable-tables.md +27 -0
- package/skills/synced-store/references/server-forking.md +115 -0
- package/skills/synced-store/references/singleton-tables.md +61 -0
- package/skills/synced-store/references/sort-keys.md +253 -0
- package/skills/synced-store/references/ui-patterns.md +95 -0
- package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
- package/skills/tile-creator/SKILL.md +197 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +354 -0
- package/skills/tile-creator/references/cli-limitations.md +64 -0
- package/skills/tile-creator/references/cli.md +604 -0
- package/skills/tile-creator/references/client-api.md +2407 -0
- package/skills/tile-creator/references/composing-apps.md +166 -0
- package/skills/tile-creator/references/e2e-tests.md +55 -0
- package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
- package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
- package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
- package/skills/tile-creator/references/native-results.md +100 -0
- package/skills/tile-creator/references/platform-integration.md +201 -0
- package/skills/tile-creator/references/power-report.md +199 -0
- package/skills/tile-creator/references/publish-rollout.md +166 -0
- package/skills/tile-creator/references/publishing.md +33 -0
- package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
- package/skills/tile-creator/references/render-check.md +266 -0
- package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
- package/skills/tile-creator/references/safe-area-insets.md +79 -0
- package/skills/tile-creator/references/sandbox-limitations.md +32 -0
- package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
- package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
- package/skills/tile-creator/references/simulations.md +125 -0
- package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
- package/skills/tile-creator/references/troubleshooting.md +22 -0
- package/skills/tile-creator/references/turn-based-mutator.md +43 -0
- package/skills/tile-creator/references/user-erasure.md +14 -0
- package/skills/tile-creator/references/vite-plugin.md +166 -0
- package/skills/tile-creator/references/workspace-retention.md +72 -0
- package/src/admin-conversions-client.ts +28 -0
- package/src/admin-reviews-client.ts +36 -0
- package/src/api.generated.ts +1527 -0
- package/src/auth-token.ts +198 -0
- package/src/bounded-read.ts +35 -0
- package/src/bun-version.ts +33 -0
- package/src/checkout-base.ts +207 -0
- package/src/cli-bun-version.ts +16 -0
- package/src/cli-env.ts +28 -0
- package/src/cli-name.ts +23 -0
- package/src/client.ts +2474 -0
- package/src/collect-files.ts +226 -0
- package/src/commands/accounts.ts +55 -0
- package/src/commands/admin-abandon-conversion.ts +60 -0
- package/src/commands/admin-reviews.ts +66 -0
- package/src/commands/admin.ts +219 -0
- package/src/commands/auth.ts +89 -0
- package/src/commands/checkout-prototype.ts +67 -0
- package/src/commands/creator-source-capability.ts +11 -0
- package/src/commands/doctor-bun.ts +145 -0
- package/src/commands/doctor-command.ts +64 -0
- package/src/commands/doctor-package-json.ts +47 -0
- package/src/commands/doctor-sdk-pin.ts +156 -0
- package/src/commands/doctor-store-keys-lexer.ts +213 -0
- package/src/commands/doctor-store-keys-scan.ts +262 -0
- package/src/commands/doctor-store-keys.ts +196 -0
- package/src/commands/doctor.ts +371 -0
- package/src/commands/init/blank-scaffold-templates.ts +397 -0
- package/src/commands/init/index.ts +170 -0
- package/src/commands/init/internal-toolchain.ts +49 -0
- package/src/commands/init/manager-test-template.ts +107 -0
- package/src/commands/init/multiplayer-test-template.ts +217 -0
- package/src/commands/init/name-input.tsx +167 -0
- package/src/commands/init/no-store-scaffold-templates.ts +281 -0
- package/src/commands/init/no-store-scaffold.ts +134 -0
- package/src/commands/init/package-json-scripts.ts +72 -0
- package/src/commands/init/scaffold.ts +960 -0
- package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
- package/src/commands/init/sdk-tarball-url.ts +31 -0
- package/src/commands/init/template-picker.tsx +147 -0
- package/src/commands/inspect-child-entry.ts +107 -0
- package/src/commands/inspect-contract.ts +87 -0
- package/src/commands/inspect-freshness.ts +217 -0
- package/src/commands/inspect-lock.ts +201 -0
- package/src/commands/inspect-options.ts +360 -0
- package/src/commands/inspect-orchestrate.ts +375 -0
- package/src/commands/inspect-process.ts +172 -0
- package/src/commands/inspect-ready.ts +65 -0
- package/src/commands/inspect-report.ts +235 -0
- package/src/commands/inspect-run-state.ts +296 -0
- package/src/commands/inspect-run.ts +157 -0
- package/src/commands/inspect-watchdog.ts +74 -0
- package/src/commands/install-joiner.ts +208 -0
- package/src/commands/login.ts +308 -0
- package/src/commands/models.ts +40 -0
- package/src/commands/parse-options.ts +36 -0
- package/src/commands/remix-package-json.ts +64 -0
- package/src/commands/remix.ts +379 -0
- package/src/commands/sdk-url.ts +141 -0
- package/src/commands/simulations.ts +133 -0
- package/src/commands/skills.ts +108 -0
- package/src/commands/store-files.ts +92 -0
- package/src/commands/stores.ts +703 -0
- package/src/commands/tiles-channel-commands.ts +115 -0
- package/src/commands/tiles-checkout.ts +351 -0
- package/src/commands/tiles-gallery-command.ts +95 -0
- package/src/commands/tiles-get-helpers.ts +27 -0
- package/src/commands/tiles-inspect.ts +276 -0
- package/src/commands/tiles-power-command.ts +308 -0
- package/src/commands/tiles-power-format.ts +396 -0
- package/src/commands/tiles-power-versions.ts +299 -0
- package/src/commands/tiles-publish-helpers.ts +145 -0
- package/src/commands/tiles-upload-command.ts +277 -0
- package/src/commands/tiles-version-commands.ts +201 -0
- package/src/commands/tiles-visibility-command.ts +103 -0
- package/src/commands/tiles.ts +257 -0
- package/src/commands/upgrade.ts +307 -0
- package/src/commit-in-progress.ts +42 -0
- package/src/creator-source-context.ts +97 -0
- package/src/creator-source-publish.ts +52 -0
- package/src/deferred-assets.ts +125 -0
- package/src/distribution.ts +28 -0
- package/src/errors.ts +61 -0
- package/src/install-command.ts +43 -0
- package/src/output.ts +62 -0
- package/src/poe-tile-config-files.ts +100 -0
- package/src/poe-tile-config-players.ts +168 -0
- package/src/poe-tile-config-remix.ts +166 -0
- package/src/poe-tile-config.ts +831 -0
- package/src/power-report-client.ts +55 -0
- package/src/prototype-startup.ts +21 -0
- package/src/publish-change-summary.ts +55 -0
- package/src/publish-overrides-validation.ts +49 -0
- package/src/publish-pack.ts +167 -0
- package/src/publish-phases.ts +57 -0
- package/src/publish-retry.ts +51 -0
- package/src/publish-tile-from-config.ts +434 -0
- package/src/recorder-stream.ts +169 -0
- package/src/remix-provenance.ts +156 -0
- package/src/resolve-client-credential.ts +71 -0
- package/src/resolve-media-uploads.ts +147 -0
- package/src/sdk-dependency.ts +54 -0
- package/src/sdk-skills.ts +85 -0
- package/src/should-skip-client-setup.ts +20 -0
- package/src/simulation-snapshot.ts +123 -0
- package/src/simulation-types.ts +74 -0
- package/src/simulations-client.ts +112 -0
- package/src/source-bundle.ts +466 -0
- package/src/staged-publish-cleanup.ts +44 -0
- package/src/staged-publish-deferred.ts +160 -0
- package/src/staged-publish.ts +401 -0
- package/src/store-file-upload.ts +268 -0
- package/src/store-request.ts +168 -0
- package/src/tar-canonical.ts +41 -0
- package/src/tar-extensions.ts +159 -0
- package/src/tar-extract.ts +193 -0
- package/src/tar-parse.ts +224 -0
- package/src/tar.ts +231 -0
- package/src/template-check-scripts.ts +18 -0
- package/src/tile-gallery-client.ts +82 -0
- package/src/types.ts +258 -0
- package/src/upload-concurrency.ts +54 -0
- package/src/whole-tile.ts +52 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* `poe-tiles tiles inspect [dir]`: open the built tile in the SDK's local
|
|
4
|
+
* test server as admitted players, run code or a script against it at the
|
|
5
|
+
* requested sizes and color schemes, and report errors, steps, and
|
|
6
|
+
* screenshots. Hidden from `--help` until the agent-speed A/B decides on
|
|
7
|
+
* rollout; it still runs, and `tiles inspect --help` documents it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { resolve } from "node:path";
|
|
11
|
+
import { Command, type CommanderError } from "commander";
|
|
12
|
+
import { cliName } from "../cli-name.js";
|
|
13
|
+
import { isJsonMode, printJson } from "../output.js";
|
|
14
|
+
import { CODE_API_SNIPPET } from "./inspect-child-entry.js";
|
|
15
|
+
import {
|
|
16
|
+
checkCapability,
|
|
17
|
+
findTileRoot,
|
|
18
|
+
InspectExit2,
|
|
19
|
+
planInspection,
|
|
20
|
+
type RawInspectOptions,
|
|
21
|
+
SDK_PIN_FIX,
|
|
22
|
+
} from "./inspect-options.js";
|
|
23
|
+
import {
|
|
24
|
+
defaultSlotDir,
|
|
25
|
+
type InspectDeps,
|
|
26
|
+
runInspection,
|
|
27
|
+
} from "./inspect-orchestrate.js";
|
|
28
|
+
import { runInGroup } from "./inspect-process.js";
|
|
29
|
+
import { exitCodeFor, formatReport } from "./inspect-report.js";
|
|
30
|
+
import { runVariant, writeChildEntry } from "./inspect-run.js";
|
|
31
|
+
|
|
32
|
+
const HELP = `
|
|
33
|
+
Code mode (--code '<js>' or --code @file.js): an async function body that calls
|
|
34
|
+
inspect's actions as \`await tools.<action>({...})\`; loops, conditions, and
|
|
35
|
+
try/catch are plain JavaScript. Script mode (--script file.ts, kept in
|
|
36
|
+
.inspect-scripts/): \`export default async (ctx) => {...}\` receives ready
|
|
37
|
+
players (page, frame, context), the store, step(), screenshot(), snapshot(),
|
|
38
|
+
record(), addPlayer(), and per player reopen() and addClient(); an optional
|
|
39
|
+
\`export async function setup(ctx)\` seeds the store before pages open.
|
|
40
|
+
|
|
41
|
+
Every run captures console errors, page errors, failed requests, and final
|
|
42
|
+
screenshots under .visual-checks/inspect/<run>/ (temporary). Exit codes: 0 every variant
|
|
43
|
+
passed; 1 a failed step, expectation, script error, or page error; 2 usage,
|
|
44
|
+
build, or environment error; 3 the deadline expired.`;
|
|
45
|
+
|
|
46
|
+
/** The code API of the tile at or above `dir`, rendered by its SDK; best effort for help text. */
|
|
47
|
+
export function codeApiHelp(dir: string): string {
|
|
48
|
+
let tileDir: string;
|
|
49
|
+
try {
|
|
50
|
+
tileDir = findTileRoot(resolve(process.cwd(), dir));
|
|
51
|
+
} catch {
|
|
52
|
+
return `\nRun \`${cliName()} tiles inspect [dir] --help\` inside a tile, or name its directory, to see its code API.\n`;
|
|
53
|
+
}
|
|
54
|
+
const result = Bun.spawnSync([process.execPath, "-e", CODE_API_SNIPPET], {
|
|
55
|
+
cwd: tileDir,
|
|
56
|
+
timeout: 10_000,
|
|
57
|
+
});
|
|
58
|
+
if (result.exitCode === 0)
|
|
59
|
+
return `\nCode API (from this tile's SDK):\n${result.stdout.toString()}\n`;
|
|
60
|
+
if (result.exitCode === null)
|
|
61
|
+
return "\nThe tile's SDK took longer than 10 s to show its code API; try again.\n";
|
|
62
|
+
const detail = result.stderr.toString().trim().split("\n").at(-1) ?? "";
|
|
63
|
+
return `\nThe code API could not be read from this tile's SDK${detail ? ` (${detail})` : ""}. ${SDK_PIN_FIX}\n`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The `[dir]` operand while help prints. Commander does not parse options
|
|
68
|
+
* after `--help`, so `args` holds `--help` and whatever follows it: skip
|
|
69
|
+
* option names and the values of options that take one.
|
|
70
|
+
*/
|
|
71
|
+
function dirOperand(command: Command): string {
|
|
72
|
+
const args = command.args;
|
|
73
|
+
for (let i = 0; i < args.length; i++) {
|
|
74
|
+
const arg = args[i]!;
|
|
75
|
+
if (!arg.startsWith("-")) return arg;
|
|
76
|
+
const option = command.options.find(
|
|
77
|
+
(o) => o.long === arg || o.short === arg,
|
|
78
|
+
);
|
|
79
|
+
if (option?.required || option?.optional) i++;
|
|
80
|
+
}
|
|
81
|
+
return ".";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Test-only: the grace between a variant's SIGTERM and SIGKILL, in ms. The
|
|
86
|
+
* slow suite sets it so a script that blocks its event loop is not waited on
|
|
87
|
+
* for the production 7 s. Unset or not a positive integer keeps the default.
|
|
88
|
+
*/
|
|
89
|
+
export const KILL_GRACE_ENV = "POE_TILES_INSPECT_KILL_GRACE_MS";
|
|
90
|
+
|
|
91
|
+
export function killGraceFromEnv(env: NodeJS.ProcessEnv): number | undefined {
|
|
92
|
+
const raw = env[KILL_GRACE_ENV];
|
|
93
|
+
const ms = Number(raw);
|
|
94
|
+
return raw && Number.isSafeInteger(ms) && ms > 0 ? ms : undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function realInspectDeps(
|
|
98
|
+
json: boolean,
|
|
99
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
100
|
+
): InspectDeps {
|
|
101
|
+
const killGraceMs = killGraceFromEnv(env);
|
|
102
|
+
return {
|
|
103
|
+
runBuild: (tileDir, inheritFds, signal) =>
|
|
104
|
+
runInGroup({
|
|
105
|
+
command: process.execPath,
|
|
106
|
+
args: ["run", "build"],
|
|
107
|
+
cwd: tileDir,
|
|
108
|
+
inheritFds,
|
|
109
|
+
signal,
|
|
110
|
+
outputBytes: 64 * 1024,
|
|
111
|
+
onOutput: (chunk) => process.stderr.write(chunk),
|
|
112
|
+
}),
|
|
113
|
+
runVariant: (params) =>
|
|
114
|
+
runVariant({
|
|
115
|
+
...params,
|
|
116
|
+
entry: `${params.input.options.runDir}/entry.mjs`,
|
|
117
|
+
...(killGraceMs === undefined ? {} : { killGraceMs }),
|
|
118
|
+
}),
|
|
119
|
+
writeEntry: (runDir) => {
|
|
120
|
+
writeChildEntry(runDir);
|
|
121
|
+
},
|
|
122
|
+
slotDir: defaultSlotDir(),
|
|
123
|
+
now: () => Date.now(),
|
|
124
|
+
log: (message) => {
|
|
125
|
+
if (!json) process.stderr.write(`${message}\n`);
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** One deadline for everything, also aborted by SIGINT and SIGTERM. */
|
|
131
|
+
function deadline(timeoutMs: number): { signal: AbortSignal; dispose(): void } {
|
|
132
|
+
const controller = new AbortController();
|
|
133
|
+
const onSignal = () => controller.abort(new Error("interrupted"));
|
|
134
|
+
process.once("SIGINT", onSignal);
|
|
135
|
+
process.once("SIGTERM", onSignal);
|
|
136
|
+
return {
|
|
137
|
+
signal: AbortSignal.any([
|
|
138
|
+
controller.signal,
|
|
139
|
+
AbortSignal.timeout(timeoutMs),
|
|
140
|
+
]),
|
|
141
|
+
dispose: () => {
|
|
142
|
+
process.off("SIGINT", onSignal);
|
|
143
|
+
process.off("SIGTERM", onSignal);
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function exit2(
|
|
149
|
+
error: InspectExit2,
|
|
150
|
+
json: boolean,
|
|
151
|
+
warnings: readonly string[] = [],
|
|
152
|
+
): void {
|
|
153
|
+
if (json) {
|
|
154
|
+
printJson({
|
|
155
|
+
error: {
|
|
156
|
+
code: error.code,
|
|
157
|
+
message: error.message,
|
|
158
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
console.error(`Error: ${error.message}`);
|
|
163
|
+
for (const warning of warnings) console.error(`warning: ${warning}`);
|
|
164
|
+
}
|
|
165
|
+
process.exitCode = 2;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function inspectAction(
|
|
169
|
+
dir: string,
|
|
170
|
+
raw: RawInspectOptions,
|
|
171
|
+
json: boolean,
|
|
172
|
+
deps: InspectDeps = realInspectDeps(json),
|
|
173
|
+
): Promise<number> {
|
|
174
|
+
let plan: ReturnType<typeof planInspection>;
|
|
175
|
+
try {
|
|
176
|
+
plan = planInspection(dir, raw, process.cwd());
|
|
177
|
+
checkCapability(plan.tileDir);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (!(error instanceof InspectExit2)) throw error;
|
|
180
|
+
exit2(error, json);
|
|
181
|
+
return 2;
|
|
182
|
+
}
|
|
183
|
+
const limit = deadline(plan.timeoutMs);
|
|
184
|
+
try {
|
|
185
|
+
const result = await runInspection(plan, deps, limit.signal);
|
|
186
|
+
if ("error" in result) {
|
|
187
|
+
exit2(result.error, json, result.warnings);
|
|
188
|
+
return 2;
|
|
189
|
+
}
|
|
190
|
+
if (json) printJson(result.report);
|
|
191
|
+
else console.log(formatReport(result.report));
|
|
192
|
+
const code = exitCodeFor(result.report);
|
|
193
|
+
process.exitCode = code;
|
|
194
|
+
return code;
|
|
195
|
+
} finally {
|
|
196
|
+
limit.dispose();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
type Exit = (code: number) => never;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Commander's parse errors (a missing option value, an unknown option) are
|
|
204
|
+
* usage errors like any other: exit 2, and under --json the JSON error
|
|
205
|
+
* alone on stdout. Help (exit 0) is left to Commander.
|
|
206
|
+
*/
|
|
207
|
+
export function onParseExit(
|
|
208
|
+
command: Command,
|
|
209
|
+
error: CommanderError,
|
|
210
|
+
exit: Exit,
|
|
211
|
+
): void {
|
|
212
|
+
if (error.exitCode === 0) return;
|
|
213
|
+
if (isJsonMode(command)) {
|
|
214
|
+
const message = error.message.replace(/^error: /, "");
|
|
215
|
+
printJson({ error: { code: "invalid-options", message } });
|
|
216
|
+
}
|
|
217
|
+
exit(2);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function createTilesInspectCommand(
|
|
221
|
+
exit: Exit = (code) => process.exit(code),
|
|
222
|
+
): Command {
|
|
223
|
+
const command: Command = new Command("inspect");
|
|
224
|
+
return command
|
|
225
|
+
.exitOverride((error) => onParseExit(command, error, exit))
|
|
226
|
+
.configureOutput({
|
|
227
|
+
// Under --json the JSON error replaces Commander's text.
|
|
228
|
+
outputError: (text, write) => {
|
|
229
|
+
if (!isJsonMode(command)) write(text);
|
|
230
|
+
},
|
|
231
|
+
})
|
|
232
|
+
.description(
|
|
233
|
+
"Open the built tile as players, run code or a script, and report what happened",
|
|
234
|
+
)
|
|
235
|
+
.argument("[dir]", "Tile directory (default: the current one)", ".")
|
|
236
|
+
.option(
|
|
237
|
+
"--code <js>",
|
|
238
|
+
"JavaScript calling inspect's actions, inline or @file",
|
|
239
|
+
)
|
|
240
|
+
.option(
|
|
241
|
+
"--script <file>",
|
|
242
|
+
"A script module inside the tile (keep it in .inspect-scripts/)",
|
|
243
|
+
)
|
|
244
|
+
.option("--players <n>", "Admitted players, 1 to 6", "1")
|
|
245
|
+
.option(
|
|
246
|
+
"--viewport <list>",
|
|
247
|
+
"phone, feed-mobile, feed-desktop, or all (comma-separated)",
|
|
248
|
+
"phone",
|
|
249
|
+
)
|
|
250
|
+
.option("--color-scheme <scheme>", "light, dark, or both", "light")
|
|
251
|
+
.option("--time <iso>", "Start every page clock at this moment")
|
|
252
|
+
.option(
|
|
253
|
+
"--ready <json>",
|
|
254
|
+
'A target to wait for after every open and reload, e.g. \'{"testId":"board"}\'',
|
|
255
|
+
)
|
|
256
|
+
.option(
|
|
257
|
+
"--timeout <seconds>",
|
|
258
|
+
"One deadline for the slot, the build, and every variant (max 300)",
|
|
259
|
+
"120",
|
|
260
|
+
)
|
|
261
|
+
.option(
|
|
262
|
+
"--no-build",
|
|
263
|
+
"Never build: use dist/ as it is (warns when it may be stale); fail only when it is missing",
|
|
264
|
+
)
|
|
265
|
+
.addHelpText(
|
|
266
|
+
"after",
|
|
267
|
+
({ command }) => `${HELP}\n${codeApiHelp(dirOperand(command))}`,
|
|
268
|
+
)
|
|
269
|
+
.action(async function (
|
|
270
|
+
this: Command,
|
|
271
|
+
dir: string,
|
|
272
|
+
opts: RawInspectOptions,
|
|
273
|
+
) {
|
|
274
|
+
await inspectAction(dir, opts, isJsonMode(this));
|
|
275
|
+
});
|
|
276
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tiles power` — the 7-day battery and heat report for the caller's own
|
|
3
|
+
* tiles, as the dashboard's battery card shows it.
|
|
4
|
+
*
|
|
5
|
+
* Split from `tiles.ts` for the per-file line budget, the same reason
|
|
6
|
+
* `tiles-visibility-command.ts` exists.
|
|
7
|
+
*
|
|
8
|
+
* Two callers. A developer's shell holds a session: with an argument it reads
|
|
9
|
+
* that one owned tile, without one every tile it owns. A Creator sandbox holds
|
|
10
|
+
* only the bound publish token and no tile id: without an argument the server
|
|
11
|
+
* resolves the session's bound tile, and an argument is resolved through the
|
|
12
|
+
* same lookup `tiles get` uses and then refused by the route unless it names
|
|
13
|
+
* that tile.
|
|
14
|
+
*
|
|
15
|
+
* By default the report measures a tile's newest published versions that
|
|
16
|
+
* together reach the session floor; `--version <n>` reads one published
|
|
17
|
+
* version's own report, and `--all-versions` reads the newest versions' own
|
|
18
|
+
* reports in one run (`tiles-power-versions.ts`), so an agent can answer a
|
|
19
|
+
* creator who asks when something started.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { Command } from "commander";
|
|
23
|
+
import { cliName } from "../cli-name.js";
|
|
24
|
+
import type { SlopPoeClient } from "../client.js";
|
|
25
|
+
import { assertSuccess, CliError } from "../errors.js";
|
|
26
|
+
import { isJsonMode, printJson, printKeyValue, printTable } from "../output.js";
|
|
27
|
+
import type { TilePowerReportBody } from "../power-report-client.js";
|
|
28
|
+
import { getTileWithOwnerMetadata } from "./tiles-get-helpers.js";
|
|
29
|
+
import {
|
|
30
|
+
POWER_SIGNAL_NOTE,
|
|
31
|
+
powerReportHeaderRows,
|
|
32
|
+
powerTileRows,
|
|
33
|
+
} from "./tiles-power-format.js";
|
|
34
|
+
import {
|
|
35
|
+
ALL_VERSIONS_DEFAULT_LIMIT,
|
|
36
|
+
ALL_VERSIONS_MAX_LIMIT,
|
|
37
|
+
POWER_REPORT_READS_PER_MINUTE,
|
|
38
|
+
parseAllVersionsLimit,
|
|
39
|
+
printAllVersionsReport,
|
|
40
|
+
readAllVersionsReport,
|
|
41
|
+
} from "./tiles-power-versions.js";
|
|
42
|
+
|
|
43
|
+
/** Register `tiles power [tileHandleOrId]` on `tiles`. */
|
|
44
|
+
export function addTilePowerCommand(
|
|
45
|
+
tiles: Command,
|
|
46
|
+
client: SlopPoeClient,
|
|
47
|
+
): void {
|
|
48
|
+
tiles
|
|
49
|
+
.command("power")
|
|
50
|
+
.description(
|
|
51
|
+
"Show a tile's 7-day battery and heat report: a verdict (ok, watch, " +
|
|
52
|
+
"hot, insufficient_data, not_computed) with reason and context codes " +
|
|
53
|
+
"and the measurements behind it, battery outcomes compared with the " +
|
|
54
|
+
"typical tile. Owner only. " +
|
|
55
|
+
"Without an argument it reports every tile you own, or, in a Creator " +
|
|
56
|
+
"session, the tile that session publishes. By default a tile is " +
|
|
57
|
+
"measured over its newest published versions that together reach " +
|
|
58
|
+
"30 phone sessions (the Measured row names them); --version reads " +
|
|
59
|
+
"one published version on its own, and --all-versions the newest " +
|
|
60
|
+
"versions, one row each.",
|
|
61
|
+
)
|
|
62
|
+
.argument(
|
|
63
|
+
"[tileHandleOrId]",
|
|
64
|
+
"Tile ID or userHandle/tileHandle; omit it in a Creator session",
|
|
65
|
+
)
|
|
66
|
+
.option(
|
|
67
|
+
"--version <n>",
|
|
68
|
+
"Read one published version's own report instead of the measured set " +
|
|
69
|
+
"(in a Creator session, of the tile that session publishes)",
|
|
70
|
+
)
|
|
71
|
+
.option(
|
|
72
|
+
"--all-versions",
|
|
73
|
+
"Read one tile's newest published versions, each with its own " +
|
|
74
|
+
"report, to see when a finding started",
|
|
75
|
+
)
|
|
76
|
+
.option(
|
|
77
|
+
"--limit <n>",
|
|
78
|
+
`With --all-versions, how many versions to read (default ${ALL_VERSIONS_DEFAULT_LIMIT}, at most ${ALL_VERSIONS_MAX_LIMIT})`,
|
|
79
|
+
)
|
|
80
|
+
.action(async function (
|
|
81
|
+
this: Command,
|
|
82
|
+
tileHandleOrId: string | undefined,
|
|
83
|
+
options: PowerOptions,
|
|
84
|
+
) {
|
|
85
|
+
const versionNumber = parseVersion(options.version);
|
|
86
|
+
const versionLimit = allVersionsLimit(options, {
|
|
87
|
+
versionNumber,
|
|
88
|
+
tileHandleOrId,
|
|
89
|
+
creatorSession: client.powerReport.readsAsCreatorSession(),
|
|
90
|
+
});
|
|
91
|
+
const tileId =
|
|
92
|
+
tileHandleOrId === undefined
|
|
93
|
+
? undefined
|
|
94
|
+
: await resolveTileId(client, tileHandleOrId);
|
|
95
|
+
const read = (version?: number) =>
|
|
96
|
+
readReport(client, { tileId, tileHandleOrId, versionNumber: version });
|
|
97
|
+
const json = isJsonMode(this);
|
|
98
|
+
if (versionLimit !== undefined) {
|
|
99
|
+
const byVersion = await readAllVersionsReport(
|
|
100
|
+
client,
|
|
101
|
+
read,
|
|
102
|
+
versionLimit,
|
|
103
|
+
);
|
|
104
|
+
if (json) printJson(byVersion);
|
|
105
|
+
else printAllVersionsReport(byVersion);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const report = await read(versionNumber);
|
|
109
|
+
if (json) {
|
|
110
|
+
printJson(report);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
printPowerReport(
|
|
114
|
+
report,
|
|
115
|
+
versionNumber === undefined ? "default" : "version",
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface PowerOptions {
|
|
121
|
+
version?: string;
|
|
122
|
+
allVersions?: boolean;
|
|
123
|
+
limit?: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* How many versions `--all-versions` reads, or undefined without the flag.
|
|
128
|
+
* It reads one tile, so it is refused before any request with `--version`,
|
|
129
|
+
* and without a tile outside a Creator session, where no argument means
|
|
130
|
+
* every owned tile.
|
|
131
|
+
*/
|
|
132
|
+
function allVersionsLimit(
|
|
133
|
+
options: PowerOptions,
|
|
134
|
+
request: {
|
|
135
|
+
versionNumber: number | undefined;
|
|
136
|
+
tileHandleOrId: string | undefined;
|
|
137
|
+
creatorSession: boolean;
|
|
138
|
+
},
|
|
139
|
+
): number | undefined {
|
|
140
|
+
if (options.allVersions !== true) {
|
|
141
|
+
if (options.limit === undefined) return undefined;
|
|
142
|
+
throw new CliError("--limit applies only with --all-versions.");
|
|
143
|
+
}
|
|
144
|
+
if (request.versionNumber !== undefined) {
|
|
145
|
+
throw new CliError("Pass --all-versions or --version <n>, not both.");
|
|
146
|
+
}
|
|
147
|
+
if (request.tileHandleOrId === undefined && !request.creatorSession) {
|
|
148
|
+
throw new CliError(
|
|
149
|
+
"--all-versions reads one tile: name it, as in " +
|
|
150
|
+
`\`${cliName()} tiles power myuser/my-tile --all-versions\`.`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return parseAllVersionsLimit(options.limit);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** `--version <n>`: a positive integer, or a CLI error naming the flag. */
|
|
157
|
+
function parseVersion(raw: string | undefined): number | undefined {
|
|
158
|
+
if (raw === undefined) return undefined;
|
|
159
|
+
const versionNumber = Number(raw);
|
|
160
|
+
if (!/^[1-9]\d*$/.test(raw) || !Number.isSafeInteger(versionNumber)) {
|
|
161
|
+
throw new CliError(
|
|
162
|
+
"--version must be a published version number, such as 12.",
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return versionNumber;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function resolveTileId(
|
|
169
|
+
client: SlopPoeClient,
|
|
170
|
+
tileHandleOrId: string,
|
|
171
|
+
): Promise<string> {
|
|
172
|
+
const lookup = await getTileWithOwnerMetadata(client, tileHandleOrId);
|
|
173
|
+
assertSuccess(lookup);
|
|
174
|
+
return lookup.tile.id;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Read the report, explaining the statuses a creator can act on in the CLI's own words. */
|
|
178
|
+
async function readReport(
|
|
179
|
+
client: SlopPoeClient,
|
|
180
|
+
request: {
|
|
181
|
+
tileId: string | undefined;
|
|
182
|
+
tileHandleOrId: string | undefined;
|
|
183
|
+
versionNumber: number | undefined;
|
|
184
|
+
},
|
|
185
|
+
): Promise<TilePowerReportBody> {
|
|
186
|
+
const result = await client.powerReport
|
|
187
|
+
.read(request.tileId, request.versionNumber)
|
|
188
|
+
.catch((error: unknown) => {
|
|
189
|
+
throw explainReportError(error, {
|
|
190
|
+
tileHandleOrId: request.tileHandleOrId,
|
|
191
|
+
creatorSession: client.powerReport.readsAsCreatorSession(),
|
|
192
|
+
versionNumber: request.versionNumber,
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
assertSuccess(result);
|
|
196
|
+
const { success: _success, ...report } = result;
|
|
197
|
+
return report;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* A version report's 404 is the route's own "Version not found" (the tile
|
|
202
|
+
* resolved, so it is never a missing tile), unless it is the bound
|
|
203
|
+
* credential's publish-first refusal, which still names a missing tile.
|
|
204
|
+
*/
|
|
205
|
+
function isMissingVersion(
|
|
206
|
+
error: CliError,
|
|
207
|
+
versionNumber: number | undefined,
|
|
208
|
+
): boolean {
|
|
209
|
+
return (
|
|
210
|
+
versionNumber !== undefined &&
|
|
211
|
+
error.status === 404 &&
|
|
212
|
+
!error.message.includes("Publish a preview first")
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function notYourTileError(
|
|
217
|
+
tileHandleOrId: string,
|
|
218
|
+
creatorSession: boolean,
|
|
219
|
+
): CliError {
|
|
220
|
+
return new CliError(
|
|
221
|
+
`"${tileHandleOrId}" is not one of your tiles.` +
|
|
222
|
+
(creatorSession
|
|
223
|
+
? ` In a Creator session, run \`${cliName()} tiles power\` without an ` +
|
|
224
|
+
"argument to read the tile this session publishes."
|
|
225
|
+
: ""),
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function explainReportError(
|
|
230
|
+
error: unknown,
|
|
231
|
+
caller: {
|
|
232
|
+
tileHandleOrId: string | undefined;
|
|
233
|
+
creatorSession: boolean;
|
|
234
|
+
versionNumber: number | undefined;
|
|
235
|
+
},
|
|
236
|
+
): unknown {
|
|
237
|
+
if (!(error instanceof CliError)) return error;
|
|
238
|
+
const { tileHandleOrId, creatorSession } = caller;
|
|
239
|
+
// The server's own text, never the missing-tile advice.
|
|
240
|
+
if (isMissingVersion(error, caller.versionNumber)) return error;
|
|
241
|
+
// A Creator credential reads only its bound tile: a 404 means the session
|
|
242
|
+
// has none to read, because it has not published or its tile was deleted,
|
|
243
|
+
// whether or not a tile was named. The server folds both into one 404.
|
|
244
|
+
if (creatorSession && error.status === 404) {
|
|
245
|
+
return new CliError(
|
|
246
|
+
"This Creator session has no published tile to report on: it has not " +
|
|
247
|
+
"published yet, or its tile was deleted. Publish a preview first, then " +
|
|
248
|
+
`run \`${cliName()} tiles power\` again.`,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
// A Creator credential naming any tile but its own is a 403; a session
|
|
252
|
+
// naming a tile it does not own is a 404, the same as an unknown tile.
|
|
253
|
+
const notYours = creatorSession ? 403 : 404;
|
|
254
|
+
if (tileHandleOrId !== undefined && error.status === notYours) {
|
|
255
|
+
return notYourTileError(tileHandleOrId, creatorSession);
|
|
256
|
+
}
|
|
257
|
+
// Keeps its status: the by-version read turns a limit part-way into how
|
|
258
|
+
// far it got.
|
|
259
|
+
if (error.status === 429) {
|
|
260
|
+
return new CliError(
|
|
261
|
+
`The battery and heat report allows your account ${POWER_REPORT_READS_PER_MINUTE} ` +
|
|
262
|
+
"reads a minute, and this minute's are spent. Wait a minute, then " +
|
|
263
|
+
"run it again.",
|
|
264
|
+
{ status: 429 },
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
if (error.status === 503) {
|
|
268
|
+
return new CliError(
|
|
269
|
+
"The battery and heat report is not available yet: no hourly report " +
|
|
270
|
+
"has been computed. Try again in an hour.",
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
return error;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function printPowerReport(
|
|
277
|
+
report: TilePowerReportBody,
|
|
278
|
+
reportKind: "default" | "version",
|
|
279
|
+
): void {
|
|
280
|
+
console.log("Battery and heat report");
|
|
281
|
+
printKeyValue(powerReportHeaderRows(report));
|
|
282
|
+
console.log("");
|
|
283
|
+
const [only, ...rest] = report.tiles;
|
|
284
|
+
if (only === undefined) {
|
|
285
|
+
console.log("No tiles to report.");
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (rest.length === 0) {
|
|
289
|
+
printKeyValue(powerTileRows(only, report, reportKind));
|
|
290
|
+
} else {
|
|
291
|
+
printTable({
|
|
292
|
+
headers: ["ID", "Handle", "Verdict", "Reasons", "Sessions"],
|
|
293
|
+
rows: report.tiles.map((tile) => [
|
|
294
|
+
tile.tile_id,
|
|
295
|
+
tile.handle,
|
|
296
|
+
tile.verdict,
|
|
297
|
+
tile.reasons.join(", ") || "-",
|
|
298
|
+
tile.sessions.total,
|
|
299
|
+
]),
|
|
300
|
+
});
|
|
301
|
+
console.log("");
|
|
302
|
+
console.log(
|
|
303
|
+
`Run \`${cliName()} tiles power <ID>\` with an ID above for one tile's measurements.`,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
console.log("");
|
|
307
|
+
console.log(POWER_SIGNAL_NOTE);
|
|
308
|
+
}
|