Skip to content

feat(install): let the user pick the environment during install - #230

Merged
nicknisi merged 5 commits into
mainfrom
nicknisi/install-env-picker
Aug 26, 2026
Merged

feat(install): let the user pick the environment during install#230
nicknisi merged 5 commits into
mainfrom
nicknisi/install-env-picker

Conversation

@nicknisi

Copy link
Copy Markdown
Member

Stacked on #229 (uses its project-prefixed names in the picker labels). Retarget to main after #229 merges.

Why

From the Slack thread: a fresh npx workos@latest run silently installed against staging-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:

? Which WorkOS environment should this install use?
❯ staging — Nick's Team's Project > test12            Sandbox
  staging-3 — cli-branding-smoke > Staging (active)   Sandbox
  • Lives in resolveInstallCredentials, the shared pre-flight for all three install entrypoints (workos install, bare npx workos, dashboard path) — before the state machine starts, so no spinner conflicts
  • Choice persists via setActiveEnvironment: the install and every later command agree on the target
  • Never prompts: explicit WORKOS_API_KEY/--api-key, CI/agent/JSON modes, single-profile configs. Cancel exits 2 like the installer's other prompts
  • Offers local profiles, not all team environments: the dashboard catalog has no create-key operation, so profiles are the only environments the CLI holds usable credentials for

Verification

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.

@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds an install-time environment picker and threads project-scan context into staging credential resolution.

  • Prompts interactive users to select among locally keyed profiles and persists the selection.
  • Suppresses selection for explicit/project-owned credentials and non-interactive output modes.
  • Routes consented key-only projects through manual credential entry, but that fallback can still replace the existing project key.

Confidence Score: 4/5

The 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

Filename Overview
src/lib/resolve-install-credentials.ts Adds profile selection and key-only-project handling, but the manual fallback does not preserve the existing project API key.
src/lib/installer-core.ts Passes install-directory and scan-consent state into staging resolution and routes failures to manual credential entry.
src/lib/run-with-core.ts Delegates staging resolution to the new helper; the existing configuration writer applies the manually submitted API key over project state.
src/lib/resolve-install-credentials.spec.ts Covers selection and staging branches but does not verify that manual fallback preserves a key-only project's API key.
src/lib/installer-core.spec.ts Updates the staging actor input type to match the new state-machine contract.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Consent to project env scan] --> B{Valid client ID found?}
  B -->|Yes| C[Configure with discovered credentials]
  B -->|No, valid project API key exists| D[resolveStagingCredentials throws]
  D --> E[Manual credential prompt]
  E --> F[Submit client ID and API key]
  F --> G[configureEnvironment]
  G --> H[Existing project API key is replaced]
Loading
Prompt To Fix All With AI
### Issue 1
src/lib/resolve-install-credentials.ts:95-97
**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.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (7): Last reviewed commit: "chore: formatting" | Re-trigger Greptile

Comment thread src/lib/resolve-install-credentials.ts
Comment thread src/lib/resolve-install-credentials.ts Outdated
nicknisi added a commit that referenced this pull request Aug 26, 2026
…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.
Comment thread src/lib/resolve-install-credentials.ts
Comment thread src/lib/resolve-install-credentials.ts Outdated
nicknisi added a commit that referenced this pull request Aug 26, 2026
…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.
@nicknisi
nicknisi force-pushed the nicknisi/project-prefixed-env-names branch from a629031 to 184f4ae Compare August 26, 2026 19:18
nicknisi added a commit that referenced this pull request Aug 26, 2026
…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.
nicknisi added a commit that referenced this pull request Aug 26, 2026
… 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.
@nicknisi
nicknisi force-pushed the nicknisi/install-env-picker branch from 136d9a9 to 794f2de Compare August 26, 2026 19:18
Base automatically changed from nicknisi/project-prefixed-env-names to main August 26, 2026 19:37
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.
@nicknisi
nicknisi force-pushed the nicknisi/install-env-picker branch from 794f2de to 65123eb Compare August 26, 2026 19:37
@nicknisi
nicknisi merged commit 8eb9408 into main Aug 26, 2026
5 checks passed
@nicknisi
nicknisi deleted the nicknisi/install-env-picker branch August 26, 2026 19:37
Comment on lines +95 to +97
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',
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant