Skip to content

feat(cli): Edit key creation wizard#1085

Merged
brian-lou merged 5 commits intomainfrom
b/cli/wizard/creds
Mar 7, 2026
Merged

feat(cli): Edit key creation wizard#1085
brian-lou merged 5 commits intomainfrom
b/cli/wizard/creds

Conversation

@brian-lou
Copy link
Contributor

@brian-lou brian-lou commented Mar 7, 2026

Greptile Summary

This PR upgrades the auth / init wizard in the CLI to let users explicitly choose which type of API key to generate (development, production, or all/both), replacing the previous automatic detection heuristic. It also introduces a centralized apiRequest utility (fetch.ts) that standardises URL construction and shared headers (including a new gt-api-version header) across all credential-related requests.

Key changes:

  • New fetch.ts helper: Wraps all CLI→API calls with shared headers (Content-Type, gt-api-version) and a default POST method. Contains an unused generic type parameter T that should be removed.
  • credentials.ts refactor: Credentials now carries an ApiKey[] array instead of a single apiKey string, allowing multiple keys to be returned and written in one session. setCredentials no longer requires a type argument; key type is read from each ApiKey object. areCredentialsSet() now accepts either GT_API_KEY or GT_DEV_API_KEY.
  • base.ts wizard flow: Auto-detection logic removed; an interactive promptSelect is shown instead. The 'all' option generates both keys in one browser session. The success message uses incorrect plural wording for single-key selections.
  • Version bump: 2.6.302.7.0.

The logic changes are well-scoped and internally consistent. Main items to address: remove the unused generic type parameter, and fix the grammar in the success message.

Confidence Score: 4/5

  • This PR is safe to merge with minor polish — an unused generic type and a grammar issue in user-facing text.
  • The logic changes are well-scoped, internally consistent, and the new apiRequest helper is straightforward. The credential flow properly supports multiple keys. Two issues remain: an unused TypeScript generic that will generate a compilation warning, and a minor user-facing grammar error in the success message that should be corrected before merge.
  • packages/cli/src/utils/fetch.ts (remove unused generic T) and packages/cli/src/cli/base.ts (fix plural/singular in success message)

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI (base.ts)
    participant credentials.ts
    participant fetch.ts (apiRequest)
    participant GT API

    User->>CLI (base.ts): gt auth (or init wizard)
    CLI (base.ts)->>User: promptSelect — key type?
    User-->>CLI (base.ts): development | production | all
    CLI (base.ts)->>credentials.ts: retrieveCredentials(settings, keyType)
    credentials.ts->>fetch.ts (apiRequest): POST /cli/wizard/session {keyType}
    fetch.ts (apiRequest)->>GT API: POST /cli/wizard/session
    GT API-->>fetch.ts (apiRequest): { sessionId }
    fetch.ts (apiRequest)-->>credentials.ts: Response
    credentials.ts->>User: Open browser → dashboard/cli/wizard/:sessionId
    loop Poll every 2 s
        credentials.ts->>fetch.ts (apiRequest): GET /cli/wizard/:sessionId
        fetch.ts (apiRequest)->>GT API: GET /cli/wizard/:sessionId
        GT API-->>fetch.ts (apiRequest): 200 { apiKeys: ApiKey[], projectId }
        fetch.ts (apiRequest)-->>credentials.ts: Response
    end
    credentials.ts->>fetch.ts (apiRequest): DELETE /cli/wizard/:sessionId
    credentials.ts-->>CLI (base.ts): Credentials { apiKeys[], projectId }
    CLI (base.ts)->>credentials.ts: setCredentials(credentials, framework)
    credentials.ts->>credentials.ts: Write GT_PROJECT_ID + GT_DEV_API_KEY / GT_API_KEY to .env.local
Loading

Last reviewed commit: 4f413db

Greptile also left 2 inline comments on this PR.

@brian-lou brian-lou requested a review from a team as a code owner March 7, 2026 03:48
@brian-lou brian-lou enabled auto-merge (squash) March 7, 2026 03:50
*
* Encapsulates URL construction, headers, and JSON parsing.
*/
export default async function apiRequest<T>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused generic type parameter

The generic type parameter T is declared on the function signature but is never used — the return type is Promise<Response>, not Promise<T>. TypeScript will flag this as an unused type parameter. Either remove it or update the return type to use it:

Suggested change
export default async function apiRequest<T>(
export default async function apiRequest(
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cli/src/utils/fetch.ts
Line: 10

Comment:
Unused generic type parameter

The generic type parameter `T` is declared on the function signature but is never used — the return type is `Promise<Response>`, not `Promise<T>`. TypeScript will flag this as an unused type parameter. Either remove it or update the return type to use it:

```suggestion
export default async function apiRequest(
```

How can I resolve this? If you propose a fix, please make it concise.

await this.handleLoginCommand(options);
logger.endCommand(
`Done! A ${options.keyType} key has been generated and saved to your .env.local file.`
`Done! ${options.keyType} keys have been generated and saved to your .env.local file.`
Copy link
Contributor

Choose a reason for hiding this comment

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

Incorrect plural in success message for single key type

When options.keyType is 'development' or 'production', the message reads e.g. "Done! development keys have been generated..." — but only one key was produced. The phrasing should vary based on whether one or two keys were requested:

Suggested change
`Done! ${options.keyType} keys have been generated and saved to your .env.local file.`
`Done! ${options.keyType === 'all' ? 'Development and production keys have' : `A ${options.keyType} key has`} been generated and saved to your .env.local file.`
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cli/src/cli/base.ts
Line: 354

Comment:
Incorrect plural in success message for single key type

When `options.keyType` is `'development'` or `'production'`, the message reads e.g. _"Done! development keys have been generated..."_ — but only one key was produced. The phrasing should vary based on whether one or two keys were requested:

```suggestion
          `Done! ${options.keyType === 'all' ? 'Development and production keys have' : `A ${options.keyType} key has`} been generated and saved to your .env.local file.`
```

How can I resolve this? If you propose a fix, please make it concise.

@brian-lou brian-lou merged commit dad7824 into main Mar 7, 2026
26 checks passed
@brian-lou brian-lou deleted the b/cli/wizard/creds branch March 7, 2026 05:22
@github-actions github-actions bot mentioned this pull request Mar 7, 2026
brian-lou pushed a commit that referenced this pull request Mar 7, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## gt@2.7.1

### Patch Changes

- [#1085](#1085)
[`dad7824`](dad7824)
Thanks [@brian-lou](https://github.com/brian-lou)! - feat: Auth wizard
supports both types of key creation

- [#1082](#1082)
[`3cb3bbd`](3cb3bbd)
Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Bumping
CLI timeouts

- [#1076](#1076)
[`19ae4eb`](19ae4eb)
Thanks [@moss-bryophyta](https://github.com/moss-bryophyta)! - Apply
style guide to error messages and warnings: remove "Please", simplify
verbose phrasing, fix `in-line` → `inline`.

- Updated dependencies
\[[`dad7824`](dad7824)]:
    -   generaltranslation@8.1.14

## @generaltranslation/compiler@1.1.25

### Patch Changes

- [#1076](#1076)
[`19ae4eb`](19ae4eb)
Thanks [@moss-bryophyta](https://github.com/moss-bryophyta)! - Apply
style guide to error messages and warnings: remove "Please", simplify
verbose phrasing, fix `in-line` → `inline`.

- Updated dependencies
\[[`dad7824`](dad7824)]:
    -   generaltranslation@8.1.14

## generaltranslation@8.1.14

### Patch Changes

- [#1085](#1085)
[`dad7824`](dad7824)
Thanks [@brian-lou](https://github.com/brian-lou)! - feat: Auth wizard
supports both types of key creation

## gtx-cli@2.7.1

### Patch Changes

- Updated dependencies
\[[`dad7824`](dad7824),
[`3cb3bbd`](3cb3bbd),
[`19ae4eb`](19ae4eb)]:
    -   gt@2.7.1

## gt-i18n@0.4.2

### Patch Changes

- Updated dependencies
\[[`dad7824`](dad7824)]:
    -   generaltranslation@8.1.14
    -   @generaltranslation/supported-locales@2.0.47

## locadex@1.0.111

### Patch Changes

- [#1076](#1076)
[`19ae4eb`](19ae4eb)
Thanks [@moss-bryophyta](https://github.com/moss-bryophyta)! - Apply
style guide to error messages and warnings: remove "Please", simplify
verbose phrasing, fix `in-line` → `inline`.

- Updated dependencies
\[[`dad7824`](dad7824),
[`3cb3bbd`](3cb3bbd),
[`19ae4eb`](19ae4eb)]:
    -   gt@2.7.1

## gt-next@6.13.5

### Patch Changes

- [#1076](#1076)
[`19ae4eb`](19ae4eb)
Thanks [@moss-bryophyta](https://github.com/moss-bryophyta)! - Apply
style guide to error messages and warnings: remove "Please", simplify
verbose phrasing, fix `in-line` → `inline`.

- Updated dependencies
\[[`dad7824`](dad7824),
[`19ae4eb`](19ae4eb)]:
    -   generaltranslation@8.1.14
    -   @generaltranslation/compiler@1.1.25
    -   gt-i18n@0.4.2
    -   gt-react@10.11.4
    -   @generaltranslation/supported-locales@2.0.47

## @generaltranslation/gt-next-lint@11.0.5

### Patch Changes

- Updated dependencies
\[[`19ae4eb`](19ae4eb)]:
    -   gt-next@6.13.5

## gt-node@0.2.8

### Patch Changes

- Updated dependencies
\[[`dad7824`](dad7824)]:
    -   generaltranslation@8.1.14
    -   gt-i18n@0.4.2

## gt-react@10.11.4

### Patch Changes

- Updated dependencies
\[[`dad7824`](dad7824),
[`19ae4eb`](19ae4eb)]:
    -   generaltranslation@8.1.14
    -   @generaltranslation/react-core@1.5.4
    -   @generaltranslation/supported-locales@2.0.47

## @generaltranslation/react-core@1.5.4

### Patch Changes

- [#1076](#1076)
[`19ae4eb`](19ae4eb)
Thanks [@moss-bryophyta](https://github.com/moss-bryophyta)! - Apply
style guide to error messages and warnings: remove "Please", simplify
verbose phrasing, fix `in-line` → `inline`.

- Updated dependencies
\[[`dad7824`](dad7824)]:
    -   generaltranslation@8.1.14
    -   gt-i18n@0.4.2
    -   @generaltranslation/supported-locales@2.0.47

## gt-sanity@1.1.21

### Patch Changes

- [#1076](#1076)
[`19ae4eb`](19ae4eb)
Thanks [@moss-bryophyta](https://github.com/moss-bryophyta)! - Apply
style guide to error messages and warnings: remove "Please", simplify
verbose phrasing, fix `in-line` → `inline`.

- Updated dependencies
\[[`dad7824`](dad7824)]:
    -   generaltranslation@8.1.14

## @generaltranslation/supported-locales@2.0.47

### Patch Changes

- Updated dependencies
\[[`dad7824`](dad7824)]:
    -   generaltranslation@8.1.14

## gt-tanstack-start@0.1.11

### Patch Changes

- Updated dependencies
\[[`dad7824`](dad7824),
[`19ae4eb`](19ae4eb)]:
    -   generaltranslation@8.1.14
    -   @generaltranslation/react-core@1.5.4
    -   gt-i18n@0.4.2
    -   gt-react@10.11.4

## gt-next-middleware-e2e@0.1.5

### Patch Changes

- Updated dependencies
\[[`19ae4eb`](19ae4eb)]:
    -   gt-next@6.13.5

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants