Skip to content

No way to reconfigure API key once credentials exist; --init immediately calls the API #23

Description

@bath-tub

Summary

Once ~/.openwiki/.env holds a full set of credentials, there is no way to reconfigure them from the CLI. openwiki --init — which the README describes as "configure your model and API key, then generate documentation" — skips setup entirely and immediately fires an agent request against the existing key. A user whose key is dead (expired trial, exhausted quota, wrong tier) gets an error on boot and no path to switch keys.

Steps to reproduce

  1. Have a complete ~/.openwiki/.env (provider + API key + model + LANGSMITH_API_KEY), where the OpenAI key has no remaining quota.
  2. Run openwiki --init.

Observed

The agent runs on mount and returns immediately:

* Error 429 You exceeded your current quota, please check your plan and billing details.

Credential diagnostics confirm every value is present and loaded, so setup is considered "done":

OPENWIKI_PROVIDER   source=process.env over ~/.openwiki/.env  preview="openai"
OPENAI_API_KEY      source=process.env over ~/.openwiki/.env  length=164
OPENWIKI_MODEL_ID   source=process.env over ~/.openwiki/.env  preview="gpt-5.4-mini"
LANGSMITH_API_KEY   source=process.env over ~/.openwiki/.env  length=0

There is no way to reach the key prompt again:

  • --init maps to command: "init" with shouldStart: true, so the App effect calls runOpenWikiAgent on mount (commands.ts, cli.tsx).
  • The only pre-run interceptor is shouldRunInteractiveCredentialSetup, gated on needsCredentialSetup(). That returns true only when provider / key / model / LangSmith are missing (credentials.ts). With a full .env, getInitialStep returns null and InitSetup completes without prompting.
  • Interactive chat has no key command. Slash commands are provider / model / init / update / clear / help / exit; /provider only writes the provider + default model and prints "ensure KEY is set" — nothing lets you enter an API key.

Net: InitSetup is only ever reachable as a side effect of missing credentials, and --init conflates "configure" with "generate docs."

Secondary: env-precedence footgun

loadOpenWikiEnv only sets process.env[key] when it is undefined, so an exported shell var wins over ~/.openwiki/.env (diagnostics: source=process.env over ~/.openwiki/.env). Editing the .env — or a future reconfigure flow — takes effect in the current process (setup patches process.env), but a fresh shell that still exports the old key silently reverts. Setup should warn when the key it saves is shadowed by an exported var.

Proposed fix

  • Add a dedicated, side-effect-free config entry point (openwiki --config) that renders InitSetup unconditionally and never starts an agent run.
  • Give InitSetup a reconfigure mode that walks every step even when values already exist, pre-selecting current values, so credentials are updated rather than skipped — and never nulls out settings the user leaves untouched.
  • (Follow-ups) a /key slash command for the in-session case; a hint on 429/insufficient_quota errors pointing at --config; the env-shadow warning above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions