Skip to content

fix(setup): offer Keep/Replace/Clear when API key already exists#20162

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-9af03b10
May 5, 2026
Merged

fix(setup): offer Keep/Replace/Clear when API key already exists#20162
teknium1 merged 1 commit into
mainfrom
hermes/hermes-9af03b10

Conversation

@teknium1

@teknium1 teknium1 commented May 5, 2026

Copy link
Copy Markdown
Contributor

hermes setup / hermes model used to silently skip the key prompt when any value was present in .env — even a malformed paste — leaving users with a stuck and no way to recover without hand-editing ~/.hermes/.env.

Changes

  • hermes_cli/main.py (+88/−66): new _prompt_api_key(pconfig, existing_key, provider_id) helper. All three API-key provider flows (Kimi, Stepfun, generic) now call it instead of inlining ~30 lines of branching each.
  • tests/hermes_cli/test_prompt_api_key.py (+11 tests): coverage for every branch incl. lmstudio placeholder semantics.

UX

  DeepSeek API key: sk-junkj... ✓
  [K]eep / [R]eplace / [C]lear (default K): _
  • K / Enter / Ctrl-C / unknown input → keep (never destroys the key)
  • Rgetpass for new key; empty input cancels and preserves existing
  • C → clears the env var, tells user to rerun hermes setup, aborts the flow

LM Studio's no-auth-placeholder substitution stays on first-time entry only; on Replace, empty input means 'cancel', not 'overwrite with dummy key'.

Validation

Before After
Malformed key in .env Silent , stuck K/R/C menu, can update in-flow
Replace cancelled (empty) n/a Existing key preserved
Clear n/a Env var wiped, siblings intact
Tests 0 11, all passing

Fixes #16394
Reshapes #18355 — original PR pasted the menu inline at 3 sites with no tests; this consolidates to one helper and adds coverage. Credit to @Feranmi10 for identifying the bug and the K/R/C UX; authorship preserved via Co-authored-by.

hermes setup / hermes model used to silently skip the key prompt when
any value was present in .env — even a malformed paste — leaving users
with a stuck '✓' and no way to recover without hand-editing .env.

Replace the silent acknowledgement at all three API-key provider flows
(Kimi, Stepfun, generic) with a single [K]eep / [R]eplace / [C]lear
menu via a shared `_prompt_api_key` helper.

- K / Enter / Ctrl-C / unknown input → keep (never destroys the key)
- R → getpass for new key; empty input cancels and preserves existing
- C → clears the env var, tells user to rerun hermes setup, aborts flow

LM Studio's no-auth-placeholder substitution stays on first-time entry
only; on Replace an empty input means 'cancel', not 'overwrite with
dummy key'.

11 unit tests cover all branches incl. garbage-input-keeps-key, Ctrl-C
at the choice prompt, Replace-cancel preserving the old key, Clear
wiping only the target env var, and lmstudio placeholder semantics.

Fixes #16394
Reshapes #18355 — original PR pasted the menu inline at 3 sites with
no tests; this consolidates to one helper (+88/-66) with coverage.

Co-authored-by: Feranmi10 <89228157+Feranmi10@users.noreply.github.com>
@teknium1 teknium1 merged commit 91ce8fc into main May 5, 2026
9 of 10 checks passed
@teknium1 teknium1 deleted the hermes/hermes-9af03b10 branch May 5, 2026 11:08
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard area/config Config system, migrations, profiles P2 Medium — degraded but workaround exists labels May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: hermes setup should allow replacing an existing API key instead of silently skipping the prompt

2 participants