MoonshotAI / MoonshotAI/kimi-cli
有关shell硬编码问题;已由kimi自身实现,代码奉上,希望可以采纳; || Regarding the issue of shell hard coding; it has been implemented by kimi itself, and the code is provided. I hope it can be adopted;
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.4k
- Forks
- 1.3k
- Avg merge
- 9h 47m
- Merged PRs (30d)
- 2
Description
What feature would you like to see?
kimi-cli Feature Request: 支持 PowerShell 7 (pwsh) 作为 Windows 默认 Shell
问题描述
在 Windows 环境下,kimi-cli 的 Shell 工具硬编码使用 Windows 自带的 PowerShell 5.1 (C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe),完全忽略用户可能已安装的 PowerShell 7 (pwsh)。
这导致即使用户终端默认使用 PowerShell 7.6.1,kimi-cli 的 Shell 工具仍然调用 5.1 执行命令。
复现步骤
- 在 Windows 上安装 PowerShell 7 (
pwsh) - 确保
pwsh在 PATH 中可用 - 启动
kimi并执行任意 Shell 命令 - 观察实际执行环境:
$PSVersionTable.PSVersion # 返回 5.1.x,而非 7.x
预期行为
kimi-cli 在 Windows 上应该优先检测 pwsh.exe(PowerShell 7),如果存在则使用它;仅在没有 pwsh 的情况下 fallback 到 PowerShell 5.1。
实际行为
kimi-cli 直接硬编码指向 PowerShell 5.1 的路径,完全不检查 pwsh:
# kimi_cli/utils/environment.py (原始代码)
if os_kind == "Windows":
shell_name = "Windows PowerShell"
system_root = os.environ.get("SYSTEMROOT", r"C:\Windows")
possible_paths = [
KaosPath(
os.path.join(
system_root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"
)
),
]
影响
- PowerShell 7 用户无法利用 PS7 的新特性(如
ForEach-Object -Parallel、改进的 UTF-8 默认处理、跨平台模块等) - 用户终端环境和
kimi-cli执行环境不一致,导致行为差异 - 配置文件 (
config.toml) 中没有任何选项可以自定义 shell 路径或名称
建议方案
方案 A:自动检测 pwsh(推荐)
修改 kimi_cli/utils/environment.py,在 Windows 分支中优先通过 shutil.which("pwsh") 检测 PowerShell 7:
import os
import platform
+ import shutil
from dataclasses import dataclass
from typing import Literal
@dataclass(slots=True, frozen=True, kw_only=True)
class Environment:
os_kind: Literal["Windows", "Linux", "macOS"] | str
os_arch: str
os_version: str
- shell_name: Literal["bash", "sh", "Windows PowerShell"]
+ shell_name: Literal["bash", "sh", "Windows PowerShell", "pwsh"]
shell_path: KaosPath
@staticmethod
async def detect() -> Environment:
# ... 平台检测逻辑 ...
if os_kind == "Windows":
- shell_name = "Windows PowerShell"
- system_root = os.environ.get("SYSTEMROOT", r"C:\Windows")
- possible_paths = [
- KaosPath(
- os.path.join(
- system_root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"
- )
- ),
- ]
- fallback_path = KaosPath("powershell.exe")
- for path in possible_paths:
- if await path.is_file():
- shell_path = path
- break
- else:
- shell_path = fallback_path
+ # 优先检测 PowerShell 7 (pwsh)
+ pwsh_exe = shutil.which("pwsh")
+ if pwsh_exe:
+ shell_name = "pwsh"
+ shell_path = KaosPath(pwsh_exe)
+ else:
+ shell_name = "Windows PowerShell"
+ system_root = os.environ.get("SYSTEMROOT", r"C:\Windows")
+ possible_paths = [
+ KaosPath(
+ os.path.join(
+ system_root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"
+ )
+ ),
+ ]
+ fallback_path = KaosPath("powershell.exe")
+ for path in possible_paths:
+ if await path.is_file():
+ shell_path = path
+ break
+ else:
+ shell_path = fallback_path
同时修改 kimi_cli/tools/shell/__init__.py,让 pwsh 也被识别为 PowerShell:
def __init__(self, approval: Approval, environment: Environment, runtime: Runtime):
- is_powershell = environment.shell_name == "Windows PowerShell"
+ is_powershell = environment.shell_name in ("Windows PowerShell", "pwsh")
super().__init__(...)
方案 B:配置文件支持(更灵活)
在 config.toml 中增加 shell 配置项:
[shell]
name = "pwsh" # 或 "bash", "zsh", "Windows PowerShell"
path = "D:\\forsoft\\PowerShell7\\pwsh.exe" # 可选,留空则自动检测
这样所有平台用户都可以自定义 shell,不仅限于 Windows PowerShell 7 用户。
环境信息
- OS: Windows 11
- kimi-cli version: 1.38.0 (通过 uv 安装)
- PowerShell 7 安装路径:
D:\forsoft\PowerShell7\pwsh.exe pwsh已在 PATH 中可用
备注
目前 config.toml 的配置结构 (kimi_cli/config.py 中的 Config 类) 没有任何与 shell 相关的字段,说明 shell 选择从未被设计为可配置项。希望官方能考虑支持,这对 Windows 开发者体验很重要。
Additional information
No response
What feature would you like to see?
kimi-cli Feature Request: Support PowerShell 7 (pwsh) as Windows default shell
Problem description
In a Windows environment, the Shell tool of kimi-cli is hard-coded to use the PowerShell 5.1 that comes with Windows (C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe), completely ignoring the PowerShell 7 (pwsh) that the user may have installed.
This causes the kimi-cli Shell tool to still call 5.1 to execute commands even if the user terminal uses PowerShell 7.6.1 by default.
Reproduction steps
- Install PowerShell 7 (
pwsh) on Windows - Make sure
pwshis available in PATH - Start
kimiand execute any shell command - Observe the actual execution environment:
$PSVersionTable.PSVersion # returns 5.1.x, not 7.x
expected behavior
kimi-cli on Windows should preferentially detect pwsh.exe** (PowerShell 7) and use it if present; only fallback to PowerShell 5.1 if pwsh is not available.
Actual behavior
kimi-cli directly hardcodes the path to PowerShell 5.1, without checking pwsh at all:
# kimi_cli/utils/environment.py (original code)
if os_kind == "Windows":
shell_name = "Windows PowerShell"
system_root = os.environ.get("SYSTEMROOT", r"C:\Windows")
possible_paths = [
KaosPath(
os.path.join(
system_root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"
)
),
]
Impact
- PowerShell 7 users cannot take advantage of new PS7 features (such as
ForEach-Object -Parallel, improved UTF-8 default handling, cross-platform modules, etc.) - The user terminal environment and the
kimi-cliexecution environment are inconsistent, resulting in behavioral differences - There is no option in the configuration file (
config.toml) to customize the shell path or name
Suggestions
Solution A: Automatically detect pwsh (recommended)
Modify kimi_cli/utils/environment.py to preferentially detect PowerShell 7 through shutil.which("pwsh") in the Windows branch:
import os
import platform
+ import shutil
from dataclasses import dataclass
from typing import Literal
@dataclass(slots=True, frozen=True, kw_only=True)
classEnvironment:
os_kind: Literal["Windows", "Linux", "macOS"] | str
os_arch: str
os_version: str
- shell_name: Literal["bash", "sh", "Windows PowerShell"]
+ shell_name: Literal["bash", "sh", "Windows PowerShell", "pwsh"]
shell_path: KaosPath
@staticmethod
async def detect() -> Environment:
#...Platform detection logic...
if os_kind == "Windows":
- shell_name = "Windows PowerShell"
- system_root = os.environ.get("SYSTEMROOT", r"C:\Windows")
- possible_paths = [
-KaosPath(
- os.path.join(
- system_root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"
- )
- ),
- ]
- fallback_path = KaosPath("powershell.exe")
- for path in possible_paths:
- if await path.is_file():
- shell_path = path
- break
-else:
- shell_path = fallback_path
+ # Prioritize detection of PowerShell 7 (pwsh)
+ pwsh_exe = shutil.which("pwsh")
+ if pwsh_exe:
+ shell_name = "pwsh"
+ shell_path = KaosPath(pwsh_exe)
+ else:
+ shell_name = "Windows PowerShell"
+ system_root = os.environ.get("SYSTEMROOT", r"C:\Windows")
+ possible_paths = [
+ KaosPath(
+ os.path.join(
+ system_root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"
+ )
+ ),
+ ]
+ fallback_path = KaosPath("powershell.exe")
+ for path in possible_paths:
+ if await path.is_file():
+ shell_path = path
+ break
+ else:
+ shell_path = fallback_path
Also modify kimi_cli/tools/shell/__init__.py so that pwsh is also recognized as PowerShell:
def __init__(self, approval: Approval, environment: Environment, runtime: Runtime):
- is_powershell = environment.shell_name == "Windows PowerShell"
+ is_powershell = environment.shell_name in ("Windows PowerShell", "pwsh")
super().__init__(...)
Option B: Configuration file support (more flexible)
Add the shell configuration item in config.toml:
[shell]
name = "pwsh" # or "bash", "zsh", "Windows PowerShell"
path = "D:\\forsoft\\PowerShell7\\pwsh.exe" # Optional, leave blank to automatically detect
This allows users on all platforms to customize their shells, not just Windows PowerShell 7 users.
Environment information
- OS: Windows 11
- kimi-cli version: 1.38.0 (installed via uv)
- PowerShell 7 installation path:
D:\forsoft\PowerShell7\pwsh.exe pwshis already available in PATH
Remarks
The current configuration structure of config.toml (the Config class in kimi_cli/config.py) does not have any shell related fields, indicating that the shell selection was never designed to be configurable. I hope the official can consider supporting it, which is very important for the Windows developer experience.
Additional information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with kimi_cli/utils/environment.py and trace Environment.detect() through the Windows shell selection, then inspect kimi_cli/tools/shell/init.py for PowerShell-specific handling. Verify the recommended pwsh-first behavior when pwsh is on PATH and the existing Windows PowerShell fallback when it is absent; the issue does not name a test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, python
- Domain
- cli, developer-experience
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100