Skip to content

Commit a3db51a

Browse files
authored
Merge pull request #2 from JochenYang/main
feat: Add Windows support with PowerShell integration
2 parents c4362ab + bc3fcd7 commit a3db51a

4 files changed

Lines changed: 312 additions & 18 deletions

File tree

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ Both usage modes require uv. If you don't have it installed:
6464
# macOS/Linux/WSL
6565
curl -LsSf https://astral.sh/uv/install.sh | sh
6666

67+
# Windows (PowerShell)
68+
python -m pip install --user pipx
69+
python -m pipx ensurepath
70+
# Restart PowerShell after installation
71+
6772
# After installation, restart your terminal or run:
68-
source ~/.bashrc # or ~/.zshrc
73+
source ~/.bashrc # or ~/.zshrc (macOS/Linux)
6974
```
7075

7176
We offer two usage modes - choose based on your needs:
@@ -81,7 +86,12 @@ Perfect for users who want to quickly try Mini Agent without cloning the reposit
8186
uv tool install git+https://github.com/MiniMax-AI/Mini-Agent.git
8287

8388
# 2. Run setup script (automatically creates config files)
89+
# macOS/Linux:
8490
curl -fsSL https://raw.githubusercontent.com/MiniMax-AI/Mini-Agent/main/scripts/setup-config.sh | bash
91+
92+
# Windows (PowerShell):
93+
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/MiniMax-AI/Mini-Agent/main/scripts/setup-config.ps1" -OutFile "$env:TEMP\setup-config.ps1"
94+
powershell -ExecutionPolicy Bypass -File "$env:TEMP\setup-config.ps1"
8595
```
8696

8797
> 💡 **Tip**: If you want to develop locally or modify code, use "Development Mode" below
@@ -129,16 +139,34 @@ git clone https://github.com/MiniMax-AI/Mini-Agent.git
129139
cd Mini-Agent
130140

131141
# 2. Install uv (if you haven't)
142+
# macOS/Linux:
132143
curl -LsSf https://astral.sh/uv/install.sh | sh
144+
# Windows (PowerShell):
145+
irm https://astral.sh/uv/install.ps1 | iex
146+
# Restart terminal after installation
133147

134148
# 3. Sync dependencies
135149
uv sync
136150

151+
# Alternative: Install dependencies manually (if not using uv)
152+
# pip install -r requirements.txt
153+
# Or install required packages:
154+
# pip install tiktoken pyyaml httpx pydantic requests prompt-toolkit mcp
155+
137156
# 4. Initialize Claude Skills (Optional)
138157
git submodule update --init --recursive
139158

140159
# 5. Copy config template
160+
```
161+
162+
**macOS/Linux:**
163+
```bash
141164
cp mini_agent/config/config-example.yaml mini_agent/config/config.yaml
165+
```
166+
167+
**Windows:**
168+
```powershell
169+
Copy-Item mini_agent\config\config-example.yaml mini_agent\config\config.yaml
142170
143171
# 6. Edit config file
144172
vim mini_agent/config/config.yaml # Or use your preferred editor
@@ -220,6 +248,34 @@ pytest tests/test_agent.py tests/test_note_tool.py -v
220248
-**External Services** - Git MCP Server loading
221249

222250

251+
## Troubleshooting
252+
253+
### SSL Certificate Error
254+
255+
If you encounter `[SSL: CERTIFICATE_VERIFY_FAILED]` error:
256+
257+
**Quick fix for testing** (modify `mini_agent/llm.py`):
258+
```python
259+
# Line 50: Add verify=False to AsyncClient
260+
async with httpx.AsyncClient(timeout=120.0, verify=False) as client:
261+
```
262+
263+
**Production solution**:
264+
```bash
265+
# Update certificates
266+
pip install --upgrade certifi
267+
268+
# Or configure system proxy/certificates
269+
```
270+
271+
### Module Not Found Error
272+
273+
Make sure you're running from the project directory:
274+
```bash
275+
cd Mini-Agent
276+
python -m mini_agent.cli
277+
```
278+
223279
## Related Documentation
224280

225281
- [Development Guide](docs/DEVELOPMENT_GUIDE.md) - Detailed development and configuration guidance

README_CN.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ MiniMax 提供国内和海外两个平台,请根据您的网络环境选择:
6464
# macOS/Linux/WSL
6565
curl -LsSf https://astral.sh/uv/install.sh | sh
6666

67+
# Windows (PowerShell)
68+
python -m pip install --user pipx
69+
python -m pipx ensurepath
70+
# 安装后需要重启 PowerShell
71+
6772
# 安装完成后,重启终端或运行:
68-
source ~/.bashrc # 或 ~/.zshrc
73+
source ~/.bashrc # 或 ~/.zshrc (macOS/Linux)
6974
```
7075

7176
我们提供两种使用模式,请根据您的需求选择:
@@ -81,7 +86,12 @@ source ~/.bashrc # 或 ~/.zshrc
8186
uv tool install git+https://github.com/MiniMax-AI/Mini-Agent.git
8287

8388
# 2. 运行配置脚本(自动创建配置文件)
89+
# macOS/Linux:
8490
curl -fsSL https://raw.githubusercontent.com/MiniMax-AI/Mini-Agent/main/scripts/setup-config.sh | bash
91+
92+
# Windows (PowerShell):
93+
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/MiniMax-AI/Mini-Agent/main/scripts/setup-config.ps1" -OutFile "$env:TEMP\setup-config.ps1"
94+
powershell -ExecutionPolicy Bypass -File "$env:TEMP\setup-config.ps1"
8595
```
8696

8797
> 💡 **提示**:如果您希望在本地进行开发或修改代码,请使用下方的"开发模式"。
@@ -129,16 +139,34 @@ git clone https://github.com/MiniMax-AI/Mini-Agent.git
129139
cd Mini-Agent
130140

131141
# 2. 安装 uv(如果尚未安装)
142+
# macOS/Linux:
132143
curl -LsSf https://astral.sh/uv/install.sh | sh
144+
# Windows (PowerShell):
145+
irm https://astral.sh/uv/install.ps1 | iex
146+
# 安装后需要重启终端
133147

134148
# 3. 同步依赖
135149
uv sync
136150

151+
# 替代方案: 手动安装依赖(如果不使用 uv)
152+
# pip install -r requirements.txt
153+
# 或者安装必需的包:
154+
# pip install tiktoken pyyaml httpx pydantic requests prompt-toolkit mcp
155+
137156
# 4. 初始化 Claude Skills(可选)
138157
git submodule update --init --recursive
139158

140159
# 5. 复制配置模板
160+
```
161+
162+
**macOS/Linux:**
163+
```bash
141164
cp mini_agent/config/config-example.yaml mini_agent/config/config.yaml
165+
```
166+
167+
**Windows:**
168+
```powershell
169+
Copy-Item mini_agent\config\config-example.yaml mini_agent\config\config.yaml
142170
143171
# 6. 编辑配置文件
144172
vim mini_agent/config/config.yaml # 或使用您偏好的编辑器
@@ -221,6 +249,34 @@ pytest tests/test_agent.py tests/test_note_tool.py -v
221249
-**外部服务** - Git MCP 服务器加载
222250

223251

252+
## 常见问题
253+
254+
### SSL 证书错误
255+
256+
如果遇到 `[SSL: CERTIFICATE_VERIFY_FAILED]` 错误:
257+
258+
**测试环境快速修复** (修改 `mini_agent/llm.py`):
259+
```python
260+
# 第 50 行: 给 AsyncClient 添加 verify=False
261+
async with httpx.AsyncClient(timeout=120.0, verify=False) as client:
262+
```
263+
264+
**生产环境解决方案**:
265+
```bash
266+
# 更新证书
267+
pip install --upgrade certifi
268+
269+
# 或配置系统代理/证书
270+
```
271+
272+
### 模块未找到错误
273+
274+
确保从项目目录运行:
275+
```bash
276+
cd Mini-Agent
277+
python -m mini_agent.cli
278+
```
279+
224280
## 相关文档
225281

226282
- [开发指南](docs/DEVELOPMENT_GUIDE_CN.md) - 详细的开发和配置指引

mini_agent/tools/bash_tool.py

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
"""Bash command execution tool with background process management."""
1+
"""Shell command execution tool with background process management.
2+
3+
Supports both bash (Unix/Linux/macOS) and PowerShell (Windows).
4+
"""
25

36
import asyncio
7+
import platform
48
import re
59
import time
610
import uuid
@@ -211,15 +215,45 @@ async def terminate(cls, bash_id: str) -> BackgroundShell:
211215

212216

213217
class BashTool(Tool):
214-
"""Execute bash commands in foreground or background."""
218+
"""Execute shell commands in foreground or background.
219+
220+
Automatically detects OS and uses appropriate shell:
221+
- Windows: PowerShell
222+
- Unix/Linux/macOS: bash
223+
"""
224+
225+
def __init__(self):
226+
"""Initialize BashTool with OS-specific shell detection."""
227+
self.is_windows = platform.system() == "Windows"
228+
self.shell_name = "PowerShell" if self.is_windows else "bash"
215229

216230
@property
217231
def name(self) -> str:
218232
return "bash"
219233

220234
@property
221235
def description(self) -> str:
222-
return """Execute bash commands in foreground or background.
236+
shell_examples = {
237+
"Windows": """Execute PowerShell commands in foreground or background.
238+
239+
For terminal operations like git, npm, docker, etc. DO NOT use for file operations - use specialized tools.
240+
241+
Parameters:
242+
- command (required): PowerShell command to execute
243+
- timeout (optional): Timeout in seconds (default: 120, max: 600) for foreground commands
244+
- run_in_background (optional): Set true for long-running commands (servers, etc.)
245+
246+
Tips:
247+
- Quote file paths with spaces: cd "My Documents"
248+
- Chain dependent commands with semicolon: git add . ; git commit -m "msg"
249+
- Use absolute paths instead of cd when possible
250+
- For background commands, monitor with bash_output and terminate with bash_kill
251+
252+
Examples:
253+
- git status
254+
- npm test
255+
- python -m http.server 8080 (with run_in_background=true)""",
256+
"Unix": """Execute bash commands in foreground or background.
223257
224258
For terminal operations like git, npm, docker, etc. DO NOT use for file operations - use specialized tools.
225259
@@ -238,15 +272,18 @@ def description(self) -> str:
238272
- git status
239273
- npm test
240274
- python3 -m http.server 8080 (with run_in_background=true)"""
275+
}
276+
return shell_examples["Windows"] if self.is_windows else shell_examples["Unix"]
241277

242278
@property
243279
def parameters(self) -> dict[str, Any]:
280+
cmd_desc = f"The {self.shell_name} command to execute. Quote file paths with spaces using double quotes."
244281
return {
245282
"type": "object",
246283
"properties": {
247284
"command": {
248285
"type": "string",
249-
"description": "The bash command to execute. Quote file paths with spaces using double quotes.",
286+
"description": cmd_desc,
250287
},
251288
"timeout": {
252289
"type": "integer",
@@ -268,10 +305,10 @@ async def execute(
268305
timeout: int = 120,
269306
run_in_background: bool = False,
270307
) -> ToolResult:
271-
"""Execute bash command with optional background execution.
308+
"""Execute shell command with optional background execution.
272309
273310
Args:
274-
command: The bash command to execute
311+
command: The shell command to execute
275312
timeout: Timeout in seconds (default: 120, max: 600)
276313
run_in_background: Set true to run command in background
277314
@@ -286,16 +323,31 @@ async def execute(
286323
elif timeout < 1:
287324
timeout = 120
288325

326+
# Prepare shell-specific command execution
327+
if self.is_windows:
328+
# Windows: Use PowerShell with appropriate encoding
329+
shell_cmd = ["powershell.exe", "-NoProfile", "-Command", command]
330+
else:
331+
# Unix/Linux/macOS: Use bash
332+
shell_cmd = command
333+
289334
if run_in_background:
290335
# Background execution: Create isolated process
291336
bash_id = str(uuid.uuid4())[:8]
292337

293338
# Start background process with combined stdout/stderr
294-
process = await asyncio.create_subprocess_shell(
295-
command,
296-
stdout=asyncio.subprocess.PIPE,
297-
stderr=asyncio.subprocess.STDOUT, # Redirect stderr to stdout
298-
)
339+
if self.is_windows:
340+
process = await asyncio.create_subprocess_exec(
341+
*shell_cmd,
342+
stdout=asyncio.subprocess.PIPE,
343+
stderr=asyncio.subprocess.STDOUT,
344+
)
345+
else:
346+
process = await asyncio.create_subprocess_shell(
347+
shell_cmd,
348+
stdout=asyncio.subprocess.PIPE,
349+
stderr=asyncio.subprocess.STDOUT,
350+
)
299351

300352
# Create background shell and add to manager
301353
bg_shell = BackgroundShell(bash_id=bash_id, command=command, process=process, start_time=time.time())
@@ -319,11 +371,18 @@ async def execute(
319371

320372
else:
321373
# Foreground execution: Create isolated process
322-
process = await asyncio.create_subprocess_shell(
323-
command,
324-
stdout=asyncio.subprocess.PIPE,
325-
stderr=asyncio.subprocess.PIPE,
326-
)
374+
if self.is_windows:
375+
process = await asyncio.create_subprocess_exec(
376+
*shell_cmd,
377+
stdout=asyncio.subprocess.PIPE,
378+
stderr=asyncio.subprocess.PIPE,
379+
)
380+
else:
381+
process = await asyncio.create_subprocess_shell(
382+
shell_cmd,
383+
stdout=asyncio.subprocess.PIPE,
384+
stderr=asyncio.subprocess.PIPE,
385+
)
327386

328387
try:
329388
stdout, stderr = await asyncio.wait_for(process.communicate(), timeout=timeout)

0 commit comments

Comments
 (0)