-
Notifications
You must be signed in to change notification settings - Fork 80
Fix install prompt on headless Windows environments #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughImplements lazy, environment-aware PromptSession creation with error caching and a fallback to input() in headless contexts, adds a module logger, updates typings for prompt-related globals, broadens exception handling in prompt_with_default, and retains the core install flow while adjusting prompt acquisition and logging. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant InstallCommand as InstallCommand
participant PromptFactory as _get_prompt_session
participant PromptSession as PromptSession
participant Stdin as input()
User->>InstallCommand: Run install
InstallCommand->>PromptFactory: Request PromptSession
alt Console available
PromptFactory-->>InstallCommand: PromptSession instance
InstallCommand->>PromptSession: prompt_with_default(...)
PromptSession-->>InstallCommand: user input
else No console / init error
PromptFactory-->>InstallCommand: None (error cached)
InstallCommand->>Stdin: input(prompt)
Stdin-->>InstallCommand: user input
end
InstallCommand-->>User: Continue install with value
rect rgba(240,250,255,0.6)
note over InstallCommand: KeyboardInterrupt/EOFError are caught and abort gracefully
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/mcpm/commands/install.py (2)
32-35
: Module-level state: tiny typing nitOptional: widen
_prompt_session_error
toOptional[BaseException]
to future‑proof if you ever decide to cache non-Exception errors.
127-133
: Harden fallback input: hide secrets and strip HTML tags in plain modeWhen no console is available,
input()
will echo secrets and the HTML tags show literally. Use getpass for hidden input and strip tags for readability.Apply this diff:
- # Basic fallback for environments without an interactive console (e.g., headless Windows) - prompt_parts = [prompt_text] + # Basic fallback for environments without an interactive console (e.g., headless Windows) + # Strip prompt_toolkit HTML tags for plain input + plain_text = re.sub(r"<[^>]+>", "", prompt_text) + prompt_parts = [plain_text] if default: prompt_parts.append(f"[{default}]") prompt_display = " ".join(prompt_parts) + " > " - result = input(prompt_display) # noqa: PLW1513 - suppressed by KeyboardInterrupt handling + if hide_input: + import getpass # local import to avoid global dependency when unused + result = getpass.getpass(prompt_display) # noqa: PLW1513 + else: + result = input(prompt_display) # noqa: PLW1513
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/mcpm/commands/install.py
(4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Always format Python code with
ruff
.
Files:
src/mcpm/commands/install.py
🧬 Code graph analysis (1)
src/mcpm/commands/install.py (3)
src/mcpm/utils/repository.py (1)
RepositoryManager
(25-163)src/mcpm/profile/profile_config.py (1)
ProfileConfigManager
(13-207)src/mcpm/global_config.py (1)
GlobalConfigManager
(23-381)
🔇 Additional comments (4)
src/mcpm/commands/install.py (4)
1-1
: LGTM: docstring and logging setupDocstring reads well; logger initialization is appropriate.
Also applies to: 4-4, 27-27
115-126
: Session gating in prompt_with_default: goodUsing the lazy getter and preserving styling when a session exists is correct.
148-149
: EOFError handling: nice catchCatching EOFError avoids crashes in truly non-interactive contexts.
37-56
: Approve: lazy PromptSession + error caching; verify other interactive promptsLazy PromptSession init and error caching are good and approved. Found other interactive prompt callsites that can still fail in headless/non‑TTY runs — ensure each has a safe fallback or is guarded.
- src/mcpm/commands/install.py — Confirm.ask(...) and click.prompt(...) (installation confirmation & method selection).
- src/mcpm/commands/uninstall.py — Confirm.ask("Proceed with removal?").
- src/mcpm/commands/profile/remove.py — Confirm.ask(...).
- src/mcpm/commands/inspect.py — click.confirm("Launch raw MCP Inspector").
- src/mcpm/commands/edit.py — multiple inquirer.* prompts (text/select/confirm).
- src/mcpm/commands/client.py — many inquirer.* calls (checkbox/confirm/text); some helpers already catch OSError (errno 22) — ensure consistent handling.
- src/mcpm/commands/profile/interactive.py — inquirer.* prompts.
- tests/test_add.py — tests patch PromptSession.prompt; verify tests still valid if prompt behavior changes.
User description
Summary
Testing
PR Type
Bug fix
Description
Fix install prompt crashes on headless Windows environments
Add lazy PromptSession instantiation with fallback to basic input
Include debug logging for fallback scenarios
Handle EOFError exceptions in prompt handling
Diagram Walkthrough
File Walkthrough
install.py
Fix headless Windows prompt handling
src/mcpm/commands/install.py
input()
for headless environmentsSummary by CodeRabbit