Skip to content

fix: /login shows provider menu and supports Ctrl+C cancellation - #55

Merged
assapir merged 6 commits into
mainfrom
fix/login-provider-choice-and-ctrl-c
Mar 2, 2026
Merged

assapir merged 6 commits into
mainfrom
fix/login-provider-choice-and-ctrl-c

Conversation

@assapir

@assapir assapir commented Mar 2, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #54 — /login now lets you choose a provider and can be cancelled with Ctrl+C.

Changes

1. Provider selection menu (src/commands/login.rs)

/login now presents a numbered menu of all available providers (like /model does for models), instead of always logging into the current provider:

  Choose a provider:

  1. Anthropic (Claude Pro/Max) ← current
  2. Google (Gemini)

  Select provider: 

The current provider is marked. Auth status is only updated in the REPL when logging into the current provider.

2. Async stdin for Anthropic login (src/provider.rs)

Switched from blocking io::stdin().read_line() to async tokio::io::stdin().lines() so the "Paste the authorization code" prompt is cancellable by the tokio runtime.

3. Ctrl+C support for all commands (src/main.rs)

Wrapped commands.dispatch() in tokio::select! with tokio::signal::ctrl_c(), so any interactive command (not just task execution) can be interrupted. This covers:

  • The provider selection prompt
  • Anthropic's code-paste wait
  • Google's OAuth callback wait

4. New all_login_providers() helper (src/provider.rs)

Returns all providers that support login, used by the /login menu.

Testing

All 214 tests pass. Zero clippy warnings. cargo fmt clean.

assapir added 2 commits March 2, 2026 14:15
- /login now presents a numbered provider menu instead of
  always using the current provider (like /model does)
- Anthropic login switched from sync stdin to async tokio stdin
  so it's cancellable
- REPL wraps command dispatch in tokio::select! with ctrl_c()
  so /login (and all commands) can be interrupted with Ctrl+C

Closes #54
assapir added 2 commits March 2, 2026 14:20
Instead of a hardcoded list, use Provider::value_variants() from
clap's ValueEnum and filter to those with a ProviderConfig. New
providers added to the enum automatically appear in /login.
- Non-empty, excludes human, includes anthropic and google
- Display names and env vars are non-empty, IDs are unique
- Matches Provider enum variants (catches missing providers)
- provider_config_by_id round-trips and rejects unknown IDs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the REPL login experience by adding an interactive provider-selection menu to /login and making interactive command flows cancellable via Ctrl+C, aligning /login with existing menu-driven UX patterns in the REPL.

Changes:

  • Add a provider selection menu to /login, with current provider marking and conditional auth-status updates.
  • Make Anthropic’s “paste authorization code” prompt async to support cancellation.
  • Wrap command dispatch in tokio::select! with tokio::signal::ctrl_c() to allow interrupting interactive commands.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/provider.rs Switch Anthropic login code entry to async stdin and add all_login_providers() helper.
src/main.rs Add Ctrl+C handling around command dispatch to interrupt interactive commands.
src/commands/login.rs Implement provider selection menu and async stdin input for /login.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/commands/login.rs
Comment thread src/main.rs
Comment thread src/provider.rs
Comment thread src/commands/login.rs Outdated
assapir added 2 commits March 2, 2026 14:25
New tests/login_test.rs covering:
- build_provider detects OAuth, API key, and env var auth
- build_provider model resolution: CLI override, config DB, precedence
- logout clears credentials for all login providers
- logout one provider preserves others
- /login command handles stdin EOF gracefully
- Convert /model to async stdin (was blocking, prevented Ctrl+C)
- Extract parse_menu_choice() helper with unit tests (5 tests)
- Both /login and /model now use the shared helper
- Make provider_config_by_id() dynamic from Provider::value_variants()
  instead of a hardcoded match (reduces provider registry duplication)
@assapir
assapir merged commit f72abd1 into main Mar 2, 2026
4 checks passed
@assapir
assapir deleted the fix/login-provider-choice-and-ctrl-c branch March 2, 2026 12:38
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.

BUG: /login doesn't allow you to choose a provider nor to cancel with CTRL+C while waiting

2 participants