Skip to content

feat: prompt for API key interactively when missing#35

Merged
oren153 merged 1 commit intomainfrom
feat/interactive-api-key-prompt
Mar 9, 2026
Merged

feat: prompt for API key interactively when missing#35
oren153 merged 1 commit intomainfrom
feat/interactive-api-key-prompt

Conversation

@oren153
Copy link
Member

@oren153 oren153 commented Mar 9, 2026

Summary

  • When no API key is found (no env var, no config), the CLI now prompts the user to enter it interactively instead of immediately erroring
  • Only prompts when running in a TTY (interactive terminal) — MCP and piped contexts still throw the error
  • Uses Node's built-in readline — no new dependencies

Test plan

  • All 293 tests pass
  • Type-check passes
  • Manual test: run npx agent-triage demo customer-support without API key set — should prompt
  • Manual test: pipe input (non-TTY) — should still throw error

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Users are now prompted to interactively enter their API key when it's not available in environment variables.
  • Tests

    • Updated test suite to verify asynchronous API key resolution behavior.

Instead of immediately erroring when no API key is found, the CLI now
prompts the user to enter their key interactively (when running in a
TTY). MCP callers are unaffected — they still get the error thrown.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@oren153 oren153 merged commit db7f13b into main Mar 9, 2026
3 checks passed
@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: aec7e7f5-32ee-4eaa-9229-75dd620e8a9c

📥 Commits

Reviewing files that changed from the base of the PR and between a66e7e4 and 2680052.

📒 Files selected for processing (8)
  • src/cli/analyze.ts
  • src/cli/check.ts
  • src/cli/explain.ts
  • src/cli/init.ts
  • src/config/loader.ts
  • src/mcp/helpers.ts
  • src/mcp/tools-eval.ts
  • test/config/loader.test.ts

📝 Walkthrough

Walkthrough

The PR converts API key resolution from synchronous to asynchronous across the codebase. The resolveApiKey function in src/config/loader.ts is refactored to return a Promise, gains interactive prompting capability via readline, and all call sites are updated to await the result.

Changes

Cohort / File(s) Summary
Core API Key Resolution
src/config/loader.ts
Made resolveApiKey asynchronous with signature change from (config: Config): string to (config: Config, options?: { interactive?: boolean }): Promise<string>. Added promptForKey helper using readline to support interactive API key prompting when the environment variable is not set.
CLI Commands
src/cli/analyze.ts, src/cli/check.ts, src/cli/explain.ts, src/cli/init.ts
Updated all command handlers to await the now-asynchronous resolveApiKey calls. Commands in explain.ts and init.ts pass { interactive: true } to enable interactive prompting during initialization.
MCP Helpers
src/mcp/helpers.ts, src/mcp/tools-eval.ts
Updated async LLM resolution functions to await resolveApiKey in helper function and three triage paths (init, analyze, demo).
Tests
test/config/loader.test.ts
Updated all resolveApiKey tests to be async and use await. Error case updated to use rejects.toThrow() pattern for async exceptions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~20 minutes

Poem

🐰 The API keys now dance through promises bright,
Interactive prompts guide the configuration night,
Async and await weave through the CLI,
Changing sync to async—oh my, oh my!
CodeRabbit hops forward with refactored delight! 🥕


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@oren153 oren153 deleted the feat/interactive-api-key-prompt branch March 10, 2026 02:56
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.

1 participant