feat(install): let the user pick the environment during install - #230
Conversation
Greptile SummaryThe PR adds an install-time environment picker and threads project-scan context into staging credential resolution.
Confidence Score: 4/5The PR is not yet safe to merge because the key-only-project fallback can still replace the project's existing API key. A consented scan of a key-only project now routes to manual credential entry, but the prompt collects another API key and the configuration writer overwrites the existing project value without ensuring it is preserved or belongs to the same environment. Files Needing Attention: src/lib/resolve-install-credentials.ts, src/lib/run-with-core.ts Important Files Changed
|
…ect-owned keys Two review findings on the picker: - --json on a TTY still counts as prompt-allowed, so ui.select threw PromptUnavailableError instead of completing non-interactively. The picker now also checks isJsonMode(). - A project whose env file already carries WORKOS_API_KEY takes the no-clobber path (key kept, login only). Prompting in that case could persist a picked profile and convert the kept key into an overwrite with a different environment's credentials. The picker now defers to project-owned keys entirely. Addresses PR #230 review.
…ect-owned keys Two review findings on the picker: - --json on a TTY still counts as prompt-allowed, so ui.select threw PromptUnavailableError instead of completing non-interactively. The picker now also checks isJsonMode(). - A project whose env file already carries WORKOS_API_KEY takes the no-clobber path (key kept, login only). Prompting in that case could persist a picked profile and convert the kept key into an overwrite with a different environment's credentials. The picker now defers to project-owned keys entirely. Addresses PR #230 review.
a629031 to
184f4ae
Compare
…dential resolution The picker guard in 0b8fa73 closed the prompt path, but a key-only project (valid WORKOS_API_KEY, no valid WORKOS_CLIENT_ID) still scanned as 'unconfigured' and fell through to the staging-credentials step, which returned the active profile's complete pair -- and configureEnvironment upserted it, silently re-pointing the app at a different environment. resolveStagingCredentials() now owns that step (active profile -> cached staging -> fresh fetch, unchanged priority) and keeps the project's own valid key, adopting only the missing client ID. An invalid project key is treated as absent, matching credential-discovery. The staging cache still records the fetched pair verbatim. Addresses PR #230 review.
… of mixing The previous commit kept the project's WORKOS_API_KEY and adopted the fallback's client ID -- which can combine credentials from two different WorkOS environments. No API maps a secret key back to its environment, so after a consented env scan a key-only project now throws out of staging resolution and lands in the machine's manual prompt, where the user supplies the matching pair. Declined scans keep the fallback pair: declining opted the project's env files out. Addresses PR #230 review.
136d9a9 to
794f2de
Compare
A fresh 'npx workos' silently installs against whatever profile happens to be active — 'staging-3' says nothing about which dashboard environment the project is about to be wired to. When more than one stored profile has an API key (and prompting is allowed), the installer now asks which environment to use, labeled with project-prefixed dashboard names: staging — Nick's Team's Project > test12 Sandbox staging-3 — cli-branding-smoke > Staging (active) Sandbox The choice persists via setActiveEnvironment so the install and every later command agree. Explicit keys (WORKOS_API_KEY / --api-key), non-interactive modes, and single-profile configs never prompt; cancel exits 2 like the installer's other prompts. The picker offers local profiles rather than all team environments: the catalog has no create-key operation, so profiles are the only environments the CLI holds usable credentials for.
…ect-owned keys Two review findings on the picker: - --json on a TTY still counts as prompt-allowed, so ui.select threw PromptUnavailableError instead of completing non-interactively. The picker now also checks isJsonMode(). - A project whose env file already carries WORKOS_API_KEY takes the no-clobber path (key kept, login only). Prompting in that case could persist a picked profile and convert the kept key into an overwrite with a different environment's credentials. The picker now defers to project-owned keys entirely. Addresses PR #230 review.
…dential resolution The picker guard in 0b8fa73 closed the prompt path, but a key-only project (valid WORKOS_API_KEY, no valid WORKOS_CLIENT_ID) still scanned as 'unconfigured' and fell through to the staging-credentials step, which returned the active profile's complete pair -- and configureEnvironment upserted it, silently re-pointing the app at a different environment. resolveStagingCredentials() now owns that step (active profile -> cached staging -> fresh fetch, unchanged priority) and keeps the project's own valid key, adopting only the missing client ID. An invalid project key is treated as absent, matching credential-discovery. The staging cache still records the fetched pair verbatim. Addresses PR #230 review.
… of mixing The previous commit kept the project's WORKOS_API_KEY and adopted the fallback's client ID -- which can combine credentials from two different WorkOS environments. No API maps a secret key back to its environment, so after a consented env scan a key-only project now throws out of staging resolution and lands in the machine's manual prompt, where the user supplies the matching pair. Declined scans keep the fallback pair: declining opted the project's env files out. Addresses PR #230 review.
794f2de to
65123eb
Compare
| throw new Error( | ||
| 'This project already has WORKOS_API_KEY but no valid WORKOS_CLIENT_ID, and the matching client ID cannot be looked up automatically', | ||
| ); |
There was a problem hiding this comment.
When a consented environment scan finds a valid WORKOS_API_KEY without a valid WORKOS_CLIENT_ID, this throw routes the installer to a manual prompt that collects a complete pair. The configuration step then writes the submitted API key over the project's existing key, so entering a key from another environment silently re-points the application despite the no-clobber handling.
Knowledge Base Used:
- Application installation workflows
- Installer orchestration and project mutation
- Configuration and environment management
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/resolve-install-credentials.ts
Line: 95-97
Comment:
**Project key still replaced**
When a consented environment scan finds a valid `WORKOS_API_KEY` without a valid `WORKOS_CLIENT_ID`, this throw routes the installer to a manual prompt that collects a complete pair. The configuration step then writes the submitted API key over the project's existing key, so entering a key from another environment silently re-points the application despite the no-clobber handling.
**Knowledge Base Used:**
- [Application installation workflows](https://app.greptile.com/workos/-/custom-context/knowledge-base/workos/cli/-/docs/application-installation.md)
- [Installer orchestration and project mutation](https://app.greptile.com/workos/-/custom-context/knowledge-base/workos/cli/-/docs/installer-orchestration.md)
- [Configuration and environment management](https://app.greptile.com/workos/-/custom-context/knowledge-base/workos/cli/-/docs/configuration-and-environment-management.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Stacked on #229 (uses its project-prefixed names in the picker labels). Retarget to
mainafter #229 merges.Why
From the Slack thread: a fresh
npx workos@latestrun silently installed againststaging-3— the active profile — with no indication of which dashboard environment that is, and no chance to change it. The installer writes those credentials into the project.What
When more than one stored profile carries an API key and prompting is allowed, install pre-flight asks:
resolveInstallCredentials, the shared pre-flight for all three install entrypoints (workos install, barenpx workos, dashboard path) — before the state machine starts, so no spinner conflictssetActiveEnvironment: the install and every later command agree on the targetWORKOS_API_KEY/--api-key, CI/agent/JSON modes, single-profile configs. Cancel exits 2 like the installer's other promptsVerification
2713 tests passing (6 new covering: prompt + persist, re-choose active is a no-op write, single-profile silence, non-interactive silence, cancel semantics), typecheck clean.