-
Notifications
You must be signed in to change notification settings - Fork 947
fix(environment): improve bash shell detection using shutil.which #1134
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -388,19 +388,27 @@ def _emit_fatal_error(message: str) -> None: | |
| case "okabe": | ||
| agent_file = OKABE_AGENT_FILE | ||
|
|
||
| # Track if -c/--command was explicitly used (vs --prompt/-p) | ||
| # to auto-enable print mode for command-style usage | ||
| command_mode = False | ||
| for arg in sys.argv[1:]: | ||
| if arg in ("-c", "--command"): | ||
| command_mode = True | ||
| break | ||
|
|
||
| if prompt is not None: | ||
| prompt = prompt.strip() | ||
| if not prompt: | ||
| raise typer.BadParameter("Prompt cannot be empty", param_hint="--prompt") | ||
|
|
||
| ui: UIMode = "shell" | ||
| if print_mode: | ||
| if print_mode or command_mode: | ||
| ui = "print" | ||
|
Comment on lines
+391
to
406
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 When a user runs Root CauseThe conflict_option_sets = [
{
"--print": print_mode, # only checks print_mode, not command_mode
"--acp": acp_mode,
"--wire": wire_mode,
},
...
]So when the user passes if print_mode or command_mode: # command_mode is True
ui = "print" # overrides --acp / --wire
elif acp_mode:
ui = "acp" # never reachedFurther, at line 497, Impact: The user's explicitly requested Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| elif acp_mode: | ||
| ui = "acp" | ||
| elif wire_mode: | ||
| ui = "wire" | ||
|
|
||
| if prompt is not None: | ||
| prompt = prompt.strip() | ||
| if not prompt: | ||
| raise typer.BadParameter("Prompt cannot be empty", param_hint="--prompt") | ||
|
|
||
| if input_format is not None and ui != "print": | ||
| raise typer.BadParameter( | ||
| "Input format is only supported for print UI", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import platform | ||
| import shutil | ||
| from dataclasses import dataclass | ||
| from typing import Literal | ||
|
|
||
|
|
@@ -34,20 +35,27 @@ async def detect() -> Environment: | |
| shell_name = "Windows PowerShell" | ||
| shell_path = KaosPath("powershell.exe") | ||
| else: | ||
| possible_paths = [ | ||
| KaosPath("/bin/bash"), | ||
| KaosPath("/usr/bin/bash"), | ||
| KaosPath("/usr/local/bin/bash"), | ||
| ] | ||
| fallback_path = KaosPath("/bin/sh") | ||
| for path in possible_paths: | ||
| if await path.is_file(): | ||
| shell_name = "bash" | ||
| shell_path = path | ||
| break | ||
| # Use shutil.which first (works on NixOS and other non-FHS systems) | ||
| bash_in_path = shutil.which("bash") | ||
| if bash_in_path: | ||
| shell_name = "bash" | ||
| shell_path = KaosPath(bash_in_path) | ||
|
Comment on lines
+39
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| else: | ||
| shell_name = "sh" | ||
| shell_path = fallback_path | ||
| # Fallback to hardcoded paths for traditional systems | ||
| possible_paths = [ | ||
| KaosPath("/bin/bash"), | ||
| KaosPath("/usr/bin/bash"), | ||
| KaosPath("/usr/local/bin/bash"), | ||
| ] | ||
| fallback_path = KaosPath("/bin/sh") | ||
| for path in possible_paths: | ||
| if await path.is_file(): | ||
| shell_name = "bash" | ||
| shell_path = path | ||
| break | ||
| else: | ||
| shell_name = "sh" | ||
| shell_path = fallback_path | ||
|
|
||
| return Environment( | ||
| os_kind=os_kind, | ||
|
|
||
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.
🟡 Raw
sys.argvscan for-ccan match option values, causing falsecommand_modeactivationThe
sys.argvscan at lines 394-397 iterates over all argv entries without understanding option-value pairing, so-cappearing as a value to another option (e.g.,kimi --session -c) is incorrectly detected ascommand_mode = True.Detailed Explanation
The code scans
sys.argv[1:]linearly:Consider
kimi --session -c -p "hello". Typer parses--sessionas expecting a string value, so it consumes-cas the session ID (i.e.,session_id = "-c"). Thepromptparameter gets its value from-p "hello". However, the rawsys.argvscan finds-cat index 2 and setscommand_mode = True, causingui = "print"and implicitly enabling yolo atsrc/kimi_cli/cli/__init__.py:497. The user intended shell mode with session "-c" but instead gets print mode with auto-approval.Impact: Unexpected UI mode and implicit yolo activation when
-chappens to appear as a value to another option.Was this helpful? React with 👍 or 👎 to provide feedback.