@joiner-platform/cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +148 -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 +196 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +308 -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,74 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* The orphan watchdog for a `tiles inspect` variant: a separate small
|
|
4
|
+
* process, so a variant whose event loop a script blocks still ends when the
|
|
5
|
+
* CLI is gone. It reads a pipe whose other end only the CLI holds. The kernel
|
|
6
|
+
* closes that end when the CLI exits, however it exits, before any parent
|
|
7
|
+
* reaps it, so neither a zombie CLI nor a reused pid can hide the exit. It
|
|
8
|
+
* then sends the variant's group SIGTERM (graceful teardown), and SIGKILL
|
|
9
|
+
* after the grace. The variant's own parent check is a second layer.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { spawn } from "node:child_process";
|
|
13
|
+
|
|
14
|
+
/** The watchdog's code; run with `-e` by the CLI's own runtime. */
|
|
15
|
+
export const WATCHDOG_SOURCE = `
|
|
16
|
+
const env = process.env;
|
|
17
|
+
const [group, grace] = [env.INSPECT_WATCH_GROUP, env.INSPECT_WATCH_GRACE_MS].map(Number);
|
|
18
|
+
const send = (signal) => { try { process.kill(-group, signal); } catch {} };
|
|
19
|
+
// The terminal's SIGINT and SIGHUP are the CLI's to handle or die of.
|
|
20
|
+
for (const signal of ["SIGINT", "SIGHUP"]) process.on(signal, () => {});
|
|
21
|
+
// A group that ended on its own needs no watching.
|
|
22
|
+
setInterval(() => { try { process.kill(-group, 0); } catch { process.exit(0); } }, 250);
|
|
23
|
+
(async () => {
|
|
24
|
+
for await (const _ of Bun.stdin.stream()) {}
|
|
25
|
+
send("SIGTERM");
|
|
26
|
+
setTimeout(() => { send("SIGKILL"); process.exit(0); }, grace);
|
|
27
|
+
})();
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
export interface Watchdog {
|
|
31
|
+
/** Ends the watchdog without touching the group. */
|
|
32
|
+
stop(): void;
|
|
33
|
+
/** Why the watchdog did not watch: its spawn failed, or it exited early. */
|
|
34
|
+
failure(): string | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Starts the watchdog for `group`; `runtime` is the Bun that runs it. */
|
|
38
|
+
export function startWatchdog(
|
|
39
|
+
group: number,
|
|
40
|
+
graceMs: number,
|
|
41
|
+
runtime: string = process.execPath,
|
|
42
|
+
): Watchdog {
|
|
43
|
+
const watchdog = spawn(runtime, ["-e", WATCHDOG_SOURCE], {
|
|
44
|
+
detached: true,
|
|
45
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
46
|
+
env: {
|
|
47
|
+
...process.env,
|
|
48
|
+
INSPECT_WATCH_GROUP: String(group),
|
|
49
|
+
INSPECT_WATCH_GRACE_MS: String(graceMs),
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
let failure: string | null = null;
|
|
53
|
+
let stopped = false;
|
|
54
|
+
watchdog.on("error", (error) => {
|
|
55
|
+
failure = error.message;
|
|
56
|
+
});
|
|
57
|
+
// It exits 0 only once the group is gone; any other end while the
|
|
58
|
+
// variant runs leaves the variant unwatched.
|
|
59
|
+
watchdog.on("exit", (code, signal) => {
|
|
60
|
+
if (!stopped && code !== 0)
|
|
61
|
+
failure ??= `it exited early (${code === null ? signal : `exit ${code}`})`;
|
|
62
|
+
});
|
|
63
|
+
watchdog.unref();
|
|
64
|
+
return {
|
|
65
|
+
stop: () => {
|
|
66
|
+
stopped = true;
|
|
67
|
+
// Killed before its pipe closes, so it never reads the close as
|
|
68
|
+
// the CLI's exit.
|
|
69
|
+
watchdog.kill("SIGKILL");
|
|
70
|
+
watchdog.stdin?.destroy();
|
|
71
|
+
},
|
|
72
|
+
failure: () => failure,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import {
|
|
5
|
+
chmodSync,
|
|
6
|
+
linkSync,
|
|
7
|
+
lstatSync,
|
|
8
|
+
mkdtempSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
realpathSync,
|
|
11
|
+
renameSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
statSync,
|
|
14
|
+
writeFileSync,
|
|
15
|
+
} from "node:fs";
|
|
16
|
+
import { isAbsolute, join } from "node:path";
|
|
17
|
+
import { Command } from "commander";
|
|
18
|
+
import { CLI_INVOKED_AS_ENV } from "../cli-name.js";
|
|
19
|
+
import { CliError } from "../errors.js";
|
|
20
|
+
|
|
21
|
+
/** The comment line that marks a launcher this command wrote. */
|
|
22
|
+
export const LAUNCHER_MARKER =
|
|
23
|
+
"# Installed by poe-tiles install-joiner. Keep poe-tiles installed to use this launcher.";
|
|
24
|
+
|
|
25
|
+
export type InstallJoinerOutcome =
|
|
26
|
+
| "created"
|
|
27
|
+
| "unchanged"
|
|
28
|
+
| "updated"
|
|
29
|
+
| "conflict";
|
|
30
|
+
|
|
31
|
+
export interface InstallJoinerResult {
|
|
32
|
+
path: string;
|
|
33
|
+
outcome: InstallJoinerOutcome;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The launcher passes its own name in `JOINER_CLI_INVOKED_AS` (see
|
|
38
|
+
* `cli-name.ts`), because `argv[1]` is the `poe-tiles` path it runs.
|
|
39
|
+
*/
|
|
40
|
+
export function joinerLauncherSource(legacyPath: string): string {
|
|
41
|
+
const quotedLegacyPath = `'${legacyPath.replaceAll("'", "'\\''")}'`;
|
|
42
|
+
return `#!/bin/sh
|
|
43
|
+
${LAUNCHER_MARKER}
|
|
44
|
+
exec env ${CLI_INVOKED_AS_ENV}=joiner ${quotedLegacyPath} "$@"
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The published package must keep only the legacy bin: old updaters call Bun
|
|
50
|
+
* directly, and Bun overwrites unrelated bins without asking. Installing this
|
|
51
|
+
* optional launcher is explicit and exclusive. It must be a regular file:
|
|
52
|
+
* Bun removes even undeclared symlink aliases during `bun remove -g`.
|
|
53
|
+
*
|
|
54
|
+
* A launcher this command wrote earlier (an executable regular file that
|
|
55
|
+
* starts with its marker comment) is rewritten to the current form. Any other
|
|
56
|
+
* existing `joiner` is left as it is: by default that throws; with
|
|
57
|
+
* `onConflict: "report"` the result's outcome is `conflict` instead.
|
|
58
|
+
*/
|
|
59
|
+
export function installJoiner({
|
|
60
|
+
binDir,
|
|
61
|
+
cliSource,
|
|
62
|
+
onConflict = "throw",
|
|
63
|
+
}: {
|
|
64
|
+
binDir: string;
|
|
65
|
+
cliSource: string;
|
|
66
|
+
onConflict?: "throw" | "report";
|
|
67
|
+
}): InstallJoinerResult {
|
|
68
|
+
const legacyPath = join(binDir, "poe-tiles");
|
|
69
|
+
assertGlobalInstall({ binDir, legacyPath, cliSource });
|
|
70
|
+
const joinerPath = join(binDir, "joiner");
|
|
71
|
+
const wrapper = joinerLauncherSource(legacyPath);
|
|
72
|
+
const temporary = mkdtempSync(join(binDir, ".poe-tiles-joiner-"));
|
|
73
|
+
try {
|
|
74
|
+
const stagedPath = join(temporary, "joiner");
|
|
75
|
+
writeFileSync(stagedPath, wrapper, { flag: "wx", mode: 0o755 });
|
|
76
|
+
chmodSync(stagedPath, 0o755);
|
|
77
|
+
try {
|
|
78
|
+
// Publish a complete regular file without replacing an existing path,
|
|
79
|
+
// even when two explicit setup commands run concurrently.
|
|
80
|
+
linkSync(stagedPath, joinerPath);
|
|
81
|
+
return { path: joinerPath, outcome: "created" };
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
84
|
+
}
|
|
85
|
+
const existing = readExistingLauncher(joinerPath);
|
|
86
|
+
if (existing === wrapper) return { path: joinerPath, outcome: "unchanged" };
|
|
87
|
+
if (existing !== null) {
|
|
88
|
+
// An older launcher this command wrote: replace it in one step.
|
|
89
|
+
renameSync(stagedPath, joinerPath);
|
|
90
|
+
return { path: joinerPath, outcome: "updated" };
|
|
91
|
+
}
|
|
92
|
+
if (onConflict === "report")
|
|
93
|
+
return { path: joinerPath, outcome: "conflict" };
|
|
94
|
+
throw new CliError(
|
|
95
|
+
`Refusing to overwrite ${joinerPath}. Keep using poe-tiles, or choose what to do with the existing command before retrying.`,
|
|
96
|
+
);
|
|
97
|
+
} finally {
|
|
98
|
+
rmSync(temporary, { recursive: true, force: true });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The content of an existing launcher this command wrote, or null when the
|
|
104
|
+
* path is anything else (another command, a symlink, a directory, or a
|
|
105
|
+
* launcher whose executable bit was removed).
|
|
106
|
+
*/
|
|
107
|
+
function readExistingLauncher(joinerPath: string): string | null {
|
|
108
|
+
const existing = lstatSync(joinerPath);
|
|
109
|
+
if (!existing.isFile() || (existing.mode & 0o100) === 0) return null;
|
|
110
|
+
const content = readFileSync(joinerPath, "utf8");
|
|
111
|
+
return content.startsWith(`#!/bin/sh\n${LAUNCHER_MARKER}\n`) ? content : null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function assertGlobalInstall({
|
|
115
|
+
binDir,
|
|
116
|
+
legacyPath,
|
|
117
|
+
cliSource,
|
|
118
|
+
}: {
|
|
119
|
+
binDir: string;
|
|
120
|
+
legacyPath: string;
|
|
121
|
+
cliSource: string;
|
|
122
|
+
}): void {
|
|
123
|
+
let matches = false;
|
|
124
|
+
try {
|
|
125
|
+
matches =
|
|
126
|
+
isAbsolute(binDir) &&
|
|
127
|
+
realpathSync(legacyPath) === realpathSync(cliSource);
|
|
128
|
+
} catch {
|
|
129
|
+
// Missing/broken bins are not an installed CLI and must not be repaired here.
|
|
130
|
+
}
|
|
131
|
+
if (!matches) {
|
|
132
|
+
throw new CliError(
|
|
133
|
+
`Run install-joiner using the poe-tiles executable in your Bun global bin directory (${binDir}). This CLI does not match that installation.`,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Installs the launcher next to this CLI's global `poe-tiles` bin. Both the
|
|
140
|
+
* `install-joiner` command and `upgrade` use it. A foreign `joiner` is
|
|
141
|
+
* reported as `conflict`, never replaced.
|
|
142
|
+
*/
|
|
143
|
+
export function installJoinerForThisCli({
|
|
144
|
+
env = process.env,
|
|
145
|
+
}: {
|
|
146
|
+
env?: NodeJS.ProcessEnv;
|
|
147
|
+
} = {}): InstallJoinerResult {
|
|
148
|
+
let binDir: string;
|
|
149
|
+
try {
|
|
150
|
+
binDir = execFileSync(process.execPath, ["pm", "bin", "-g"], {
|
|
151
|
+
encoding: "utf8",
|
|
152
|
+
env,
|
|
153
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
154
|
+
timeout: 10_000,
|
|
155
|
+
}).trim();
|
|
156
|
+
} catch {
|
|
157
|
+
throw new CliError(
|
|
158
|
+
"Could not locate Bun's global bin directory. Install the published poe-tiles CLI globally, then run `poe-tiles install-joiner` using that installation.",
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
// A successful lookup can still point at an empty global directory.
|
|
162
|
+
let installed = false;
|
|
163
|
+
try {
|
|
164
|
+
installed = statSync(join(binDir, "poe-tiles")).isFile();
|
|
165
|
+
} catch {
|
|
166
|
+
// Missing or broken executables require a global installation.
|
|
167
|
+
}
|
|
168
|
+
if (!installed) {
|
|
169
|
+
throw new CliError(
|
|
170
|
+
"poe-tiles is not installed in Bun's global bin directory. Install the published poe-tiles CLI globally, then run `poe-tiles install-joiner` using that installation.",
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return installJoiner({
|
|
174
|
+
binDir,
|
|
175
|
+
cliSource: join(import.meta.dir, "../../cli.ts"),
|
|
176
|
+
onConflict: "report",
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The warning for a `joiner` this CLI did not write. */
|
|
181
|
+
export function joinerConflictWarning(path: string): string {
|
|
182
|
+
return `Warning: ${path} already exists and was not installed by poe-tiles, so it was left unchanged. Keep using poe-tiles, or remove that file and run \`poe-tiles install-joiner\`.\n`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function createInstallJoinerCommand({
|
|
186
|
+
env = process.env,
|
|
187
|
+
stdout = process.stdout,
|
|
188
|
+
stderr = process.stderr,
|
|
189
|
+
}: {
|
|
190
|
+
env?: NodeJS.ProcessEnv;
|
|
191
|
+
stdout?: { write: (text: string) => void };
|
|
192
|
+
stderr?: { write: (text: string) => void };
|
|
193
|
+
} = {}): Command {
|
|
194
|
+
return new Command("install-joiner")
|
|
195
|
+
.description(
|
|
196
|
+
"Opt in to the joiner command for this global installation; never replaces an existing command.",
|
|
197
|
+
)
|
|
198
|
+
.action(() => {
|
|
199
|
+
const result = installJoinerForThisCli({ env });
|
|
200
|
+
if (result.outcome === "conflict") {
|
|
201
|
+
stderr.write(joinerConflictWarning(result.path));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
stdout.write(
|
|
205
|
+
`Installed ${result.path}\nKeep this directory in PATH to use joiner. The poe-tiles command remains available.\n`,
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Top-level browser/device-code login command.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
import { writePoeTilesSessionToken } from "../auth-token.js";
|
|
9
|
+
import { cliName } from "../cli-name.js";
|
|
10
|
+
import type { SlopPoeClient } from "../client.js";
|
|
11
|
+
import { CliError } from "../errors.js";
|
|
12
|
+
import { isJsonMode, printJson, printKeyValue } from "../output.js";
|
|
13
|
+
import type { LoginResponse } from "../types.js";
|
|
14
|
+
|
|
15
|
+
type LoginUser = Extract<LoginResponse, { success: true }>["user"];
|
|
16
|
+
type BrowserOpenChild = {
|
|
17
|
+
on(event: "error", listener: () => void): unknown;
|
|
18
|
+
unref(): void;
|
|
19
|
+
};
|
|
20
|
+
type BrowserOpenSpawn = (
|
|
21
|
+
command: string,
|
|
22
|
+
args: string[],
|
|
23
|
+
options: { detached: true; stdio: "ignore" },
|
|
24
|
+
) => BrowserOpenChild;
|
|
25
|
+
|
|
26
|
+
export interface DeviceLoginClient {
|
|
27
|
+
startDeviceCodeLogin(options?: {
|
|
28
|
+
deviceLabel?: string;
|
|
29
|
+
}): ReturnType<SlopPoeClient["startDeviceCodeLogin"]>;
|
|
30
|
+
pollDeviceCodeLogin(options: {
|
|
31
|
+
deviceCode: string;
|
|
32
|
+
}): ReturnType<SlopPoeClient["pollDeviceCodeLogin"]>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RunLoginOptions {
|
|
36
|
+
client: DeviceLoginClient;
|
|
37
|
+
deviceLabel: string;
|
|
38
|
+
openBrowser: boolean;
|
|
39
|
+
homeDir?: string;
|
|
40
|
+
log: (message: string) => void;
|
|
41
|
+
openUrl?: (url: string) => void | Promise<void>;
|
|
42
|
+
sleep?: (ms: number) => Promise<void>;
|
|
43
|
+
now?: () => number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface RunLoginResult {
|
|
47
|
+
user: LoginUser;
|
|
48
|
+
sessionTokenPath: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface LoginCommandDependencies {
|
|
52
|
+
env?: Record<string, string | undefined>;
|
|
53
|
+
homeDir?: string;
|
|
54
|
+
logError?: (message: string) => void;
|
|
55
|
+
logInfo?: (message: string) => void;
|
|
56
|
+
now?: () => number;
|
|
57
|
+
openUrl?: (url: string) => void | Promise<void>;
|
|
58
|
+
platform?: NodeJS.Platform;
|
|
59
|
+
sleep?: (ms: number) => Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type LoginCommandOptions = {
|
|
63
|
+
deviceLabel: string;
|
|
64
|
+
open?: boolean;
|
|
65
|
+
remote?: boolean;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const DEFAULT_DEVICE_LABEL = "poe-tiles CLI";
|
|
69
|
+
const SLOW_DOWN_INCREMENT_MS = 5_000;
|
|
70
|
+
|
|
71
|
+
export function createLoginCommand(
|
|
72
|
+
client: DeviceLoginClient,
|
|
73
|
+
dependencies: LoginCommandDependencies = {},
|
|
74
|
+
): Command {
|
|
75
|
+
return new Command("login")
|
|
76
|
+
.description("Sign in through Poe and save a local CLI session")
|
|
77
|
+
.option(
|
|
78
|
+
"--device-label <label>",
|
|
79
|
+
"Label shown in Poe",
|
|
80
|
+
DEFAULT_DEVICE_LABEL,
|
|
81
|
+
)
|
|
82
|
+
.option("--open", "Open the Poe approval URL in this machine's browser")
|
|
83
|
+
.option("--no-open", "Print the Poe URL without opening a browser")
|
|
84
|
+
.option("--remote", "Print approval instructions for another machine")
|
|
85
|
+
.action(async function (this: Command) {
|
|
86
|
+
const opts = loginCommandOptions(this);
|
|
87
|
+
const jsonMode = isJsonMode(this);
|
|
88
|
+
const result = await runDeviceCodeLogin({
|
|
89
|
+
client,
|
|
90
|
+
deviceLabel: opts.deviceLabel,
|
|
91
|
+
openBrowser: resolveCommandOpenBrowser(opts, dependencies),
|
|
92
|
+
homeDir: dependencies.homeDir,
|
|
93
|
+
log: loginInstructionLogger(jsonMode, dependencies),
|
|
94
|
+
now: dependencies.now,
|
|
95
|
+
openUrl: dependencies.openUrl ?? openUrlInDefaultBrowser,
|
|
96
|
+
sleep: dependencies.sleep,
|
|
97
|
+
});
|
|
98
|
+
printLoginCommandResult(result, jsonMode);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function loginCommandOptions(command: Command): LoginCommandOptions {
|
|
103
|
+
const opts = command.opts() as LoginCommandOptions;
|
|
104
|
+
if (opts.remote && opts.open === true) {
|
|
105
|
+
throw new CliError("Use either --remote or --open, not both.");
|
|
106
|
+
}
|
|
107
|
+
return opts;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function resolveCommandOpenBrowser(
|
|
111
|
+
opts: LoginCommandOptions,
|
|
112
|
+
dependencies: LoginCommandDependencies,
|
|
113
|
+
): boolean {
|
|
114
|
+
return resolveLoginOpenBrowser({
|
|
115
|
+
env: dependencies.env ?? process.env,
|
|
116
|
+
open: opts.open,
|
|
117
|
+
platform: dependencies.platform ?? process.platform,
|
|
118
|
+
remote: opts.remote === true,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function loginInstructionLogger(
|
|
123
|
+
jsonMode: boolean,
|
|
124
|
+
dependencies: LoginCommandDependencies,
|
|
125
|
+
): (message: string) => void {
|
|
126
|
+
return jsonMode
|
|
127
|
+
? (dependencies.logError ?? console.error)
|
|
128
|
+
: (dependencies.logInfo ?? console.log);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function printLoginCommandResult(
|
|
132
|
+
result: RunLoginResult,
|
|
133
|
+
jsonMode: boolean,
|
|
134
|
+
): void {
|
|
135
|
+
if (jsonMode) {
|
|
136
|
+
printJson({
|
|
137
|
+
user: result.user,
|
|
138
|
+
sessionTokenPath: result.sessionTokenPath,
|
|
139
|
+
});
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
console.log("Logged in successfully.");
|
|
143
|
+
console.log(`Session saved to ${result.sessionTokenPath}.`);
|
|
144
|
+
printKeyValue([
|
|
145
|
+
["User ID", result.user.user_id],
|
|
146
|
+
["Username", result.user.username],
|
|
147
|
+
["Display Name", result.user.display_name],
|
|
148
|
+
]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function runDeviceCodeLogin(
|
|
152
|
+
options: RunLoginOptions,
|
|
153
|
+
): Promise<RunLoginResult> {
|
|
154
|
+
const sleep = options.sleep ?? defaultSleep;
|
|
155
|
+
const now = options.now ?? Date.now;
|
|
156
|
+
const openUrl = options.openUrl ?? openUrlInDefaultBrowser;
|
|
157
|
+
const start = await options.client.startDeviceCodeLogin({
|
|
158
|
+
deviceLabel: options.deviceLabel,
|
|
159
|
+
});
|
|
160
|
+
const approvalUrl = start.verificationUriComplete ?? start.verificationUri;
|
|
161
|
+
printDeviceCodeInstructions(options.log, {
|
|
162
|
+
approvalUrl,
|
|
163
|
+
userCode: start.userCode,
|
|
164
|
+
openBrowser: options.openBrowser,
|
|
165
|
+
});
|
|
166
|
+
if (options.openBrowser) {
|
|
167
|
+
await openUrl(approvalUrl);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const session = await waitForSessionToken({
|
|
171
|
+
client: options.client,
|
|
172
|
+
deviceCode: start.deviceCode,
|
|
173
|
+
deadlineMs: now() + start.expiresIn * 1000,
|
|
174
|
+
intervalMs: start.interval * 1000,
|
|
175
|
+
sleep,
|
|
176
|
+
now,
|
|
177
|
+
});
|
|
178
|
+
const sessionTokenPath = writePoeTilesSessionToken({
|
|
179
|
+
sessionToken: session.sessionToken,
|
|
180
|
+
homeDir: options.homeDir,
|
|
181
|
+
});
|
|
182
|
+
return { user: session.user, sessionTokenPath };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function resolveLoginOpenBrowser(options: {
|
|
186
|
+
env: Record<string, string | undefined>;
|
|
187
|
+
open?: boolean;
|
|
188
|
+
platform: NodeJS.Platform;
|
|
189
|
+
remote: boolean;
|
|
190
|
+
}): boolean {
|
|
191
|
+
if (options.remote) return false;
|
|
192
|
+
if (options.open !== undefined) return options.open;
|
|
193
|
+
return shouldOpenBrowserByDefault({
|
|
194
|
+
env: options.env,
|
|
195
|
+
platform: options.platform,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function shouldOpenBrowserByDefault(options: {
|
|
200
|
+
env: Record<string, string | undefined>;
|
|
201
|
+
platform: NodeJS.Platform;
|
|
202
|
+
}): boolean {
|
|
203
|
+
if (isRemoteShell(options.env)) return false;
|
|
204
|
+
if (options.env["CI"]) return false;
|
|
205
|
+
if (options.platform !== "linux") return true;
|
|
206
|
+
return Boolean(
|
|
207
|
+
options.env["DISPLAY"] ||
|
|
208
|
+
options.env["WAYLAND_DISPLAY"] ||
|
|
209
|
+
options.env["BROWSER"],
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function waitForSessionToken(options: {
|
|
214
|
+
client: DeviceLoginClient;
|
|
215
|
+
deviceCode: string;
|
|
216
|
+
deadlineMs: number;
|
|
217
|
+
intervalMs: number;
|
|
218
|
+
sleep: (ms: number) => Promise<void>;
|
|
219
|
+
now: () => number;
|
|
220
|
+
}): Promise<{ sessionToken: string; user: LoginUser }> {
|
|
221
|
+
let intervalMs = options.intervalMs;
|
|
222
|
+
while (options.now() < options.deadlineMs) {
|
|
223
|
+
// biome-ignore lint/performance/noAwaitInLoops: Device-code polling is intentionally sequential and rate-limited by the server-provided interval.
|
|
224
|
+
const poll = await options.client.pollDeviceCodeLogin({
|
|
225
|
+
deviceCode: options.deviceCode,
|
|
226
|
+
});
|
|
227
|
+
if (poll.status === "authorized") {
|
|
228
|
+
return { sessionToken: poll.sessionToken, user: poll.user };
|
|
229
|
+
}
|
|
230
|
+
throwForTerminalPollStatus(poll.status);
|
|
231
|
+
if (poll.status === "slow_down") {
|
|
232
|
+
intervalMs += SLOW_DOWN_INCREMENT_MS;
|
|
233
|
+
}
|
|
234
|
+
await options.sleep(intervalMs);
|
|
235
|
+
}
|
|
236
|
+
throw new CliError(
|
|
237
|
+
`Poe login code expired. Run \`${cliName()} login\` again.`,
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function throwForTerminalPollStatus(status: string): void {
|
|
242
|
+
if (status === "expired") {
|
|
243
|
+
throw new CliError(
|
|
244
|
+
`Poe login code expired. Run \`${cliName()} login\` again.`,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
if (status === "consumed") {
|
|
248
|
+
throw new CliError(
|
|
249
|
+
`Poe login code was already used. Run \`${cliName()} login\` again.`,
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
if (status === "denied") {
|
|
253
|
+
throw new CliError("Poe login was denied in the browser.");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function printDeviceCodeInstructions(
|
|
258
|
+
log: (message: string) => void,
|
|
259
|
+
options: { approvalUrl: string; userCode: string; openBrowser: boolean },
|
|
260
|
+
): void {
|
|
261
|
+
log(
|
|
262
|
+
options.openBrowser
|
|
263
|
+
? "Opening Poe in your browser:"
|
|
264
|
+
: "Open this Poe URL in any browser:",
|
|
265
|
+
);
|
|
266
|
+
log(options.approvalUrl);
|
|
267
|
+
log(`Enter code: ${options.userCode}`);
|
|
268
|
+
log("Waiting for approval...");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function openUrlInDefaultBrowser(
|
|
272
|
+
url: string,
|
|
273
|
+
dependencies: {
|
|
274
|
+
platform?: NodeJS.Platform;
|
|
275
|
+
spawnFn?: BrowserOpenSpawn;
|
|
276
|
+
} = {},
|
|
277
|
+
): void {
|
|
278
|
+
const { command, args } = browserOpenCommand(url, dependencies.platform);
|
|
279
|
+
const spawnFn = dependencies.spawnFn ?? (spawn as BrowserOpenSpawn);
|
|
280
|
+
const child = spawnFn(command, args, {
|
|
281
|
+
detached: true,
|
|
282
|
+
stdio: "ignore",
|
|
283
|
+
});
|
|
284
|
+
child.on("error", () => undefined);
|
|
285
|
+
child.unref();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function browserOpenCommand(
|
|
289
|
+
url: string,
|
|
290
|
+
platform: NodeJS.Platform = process.platform,
|
|
291
|
+
): { command: string; args: string[] } {
|
|
292
|
+
const platformCommands: Partial<
|
|
293
|
+
Record<NodeJS.Platform, { command: string; args: string[] }>
|
|
294
|
+
> = {
|
|
295
|
+
darwin: { command: "open", args: [url] },
|
|
296
|
+
win32: { command: "cmd", args: ["/c", "start", "", url] },
|
|
297
|
+
};
|
|
298
|
+
return platformCommands[platform] ?? { command: "xdg-open", args: [url] };
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function defaultSleep(ms: number): Promise<void> {
|
|
302
|
+
// biome-ignore lint: CLI login polling needs a real wall-clock delay between Poe poll requests.
|
|
303
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function isRemoteShell(env: Record<string, string | undefined>): boolean {
|
|
307
|
+
return Boolean(env["SSH_CONNECTION"] || env["SSH_CLIENT"] || env["SSH_TTY"]);
|
|
308
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Model commands: list
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
import type { SlopPoeClient } from "../client.js";
|
|
8
|
+
import { assertSuccess } from "../errors.js";
|
|
9
|
+
import { isJsonMode, printJson, printTable } from "../output.js";
|
|
10
|
+
|
|
11
|
+
export function createModelsCommands(client: SlopPoeClient): Command {
|
|
12
|
+
const models = new Command("models").description("Model management");
|
|
13
|
+
|
|
14
|
+
models
|
|
15
|
+
.command("list")
|
|
16
|
+
.description("List available models")
|
|
17
|
+
.action(async function (this: Command) {
|
|
18
|
+
const result = await client.listModels();
|
|
19
|
+
assertSuccess(result);
|
|
20
|
+
if (isJsonMode(this)) {
|
|
21
|
+
printJson(result.models);
|
|
22
|
+
} else {
|
|
23
|
+
if (result.models.length === 0) {
|
|
24
|
+
console.log("No models found.");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
printTable({
|
|
28
|
+
headers: ["ID", "Display Name", "Owner", "Description"],
|
|
29
|
+
rows: result.models.map((m) => [
|
|
30
|
+
m.id,
|
|
31
|
+
m.metadata.display_name,
|
|
32
|
+
m.owned_by,
|
|
33
|
+
m.description,
|
|
34
|
+
]),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return models;
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Shared parsers/validators for CLI option strings.
|
|
4
|
+
*
|
|
5
|
+
* Commander hands every `--flag <value>` to us as a raw string, so numeric flags
|
|
6
|
+
* (`--timeout-ms`, `--limit`, `--after-version`, ...) all need the same
|
|
7
|
+
* validate-and-convert step. These live here — rather than being redeclared per
|
|
8
|
+
* command module — so a fix or message tweak lands once for every command that
|
|
9
|
+
* takes the same shape of flag (see PRINCIPLES.md, "minimize duplicated code").
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { CliError } from "../errors.js";
|
|
13
|
+
|
|
14
|
+
/** Parse a `--flag <n>` that must be an integer > 0, e.g. `--timeout-ms`. */
|
|
15
|
+
export function parsePositiveIntegerOption(
|
|
16
|
+
value: string,
|
|
17
|
+
optionName: string,
|
|
18
|
+
): number {
|
|
19
|
+
const parsed = Number(value);
|
|
20
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
21
|
+
throw new CliError(`${optionName} must be a positive integer.`);
|
|
22
|
+
}
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Parse a `--flag <n>` that must be an integer >= 0, e.g. `--after-version`. */
|
|
27
|
+
export function parseNonNegativeIntegerOption(
|
|
28
|
+
value: string,
|
|
29
|
+
optionName: string,
|
|
30
|
+
): number {
|
|
31
|
+
const parsed = Number(value);
|
|
32
|
+
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
33
|
+
throw new CliError(`${optionName} must be a non-negative integer.`);
|
|
34
|
+
}
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|