MyClaw - 跨平台一致运行版
约 1192 字大约 4 分钟
2026-03-07
跨平台一致运行版 - 使用 Go 语言实现,专门解决 Windows 环境下的兼容性问题,提供跨平台一致的运行体验。
核心特性
跨平台兼容
- Windows/Linux/macOS 统一体验
- 自动适配系统差异
- 路径分隔符自动转换
- 命令行工具兼容层
Windows 优化
- PowerShell 原生支持
- CMD 命令兼容
- Windows 路径处理
- 文件权限适配
统一接口
- 跨平台 API 抽象
- 系统调用封装
- 环境变量统一管理
- 配置文件兼容
简单部署
- 单文件可执行
- 无需运行时依赖
- 静态编译
- 开箱即用
快速开始
下载安装
# Windows
# 从 GitHub Releases 下载 myclaw-windows-amd64.exe
# 或使用 Scoop
scoop install myclaw
# macOS
brew install myclaw
# Linux
wget https://github.com/myclaw/myclaw/releases/latest/download/myclaw-linux-amd64
chmod +x myclaw-linux-amd64
sudo mv myclaw-linux-amd64 /usr/local/bin/myclaw配置
创建 config.yaml:
# 跨平台配置
platform:
auto_detect: true
shell: auto # auto, powershell, cmd, bash, zsh
# API 配置
api:
provider: anthropic
model: claude-3-5-sonnet-20241022
api_key: ${ANTHROPIC_API_KEY}
# 路径配置
paths:
workspace: ./workspace
logs: ./logs
cache: ./cache启动
# Windows PowerShell
myclaw.exe start
# Windows CMD
myclaw.exe start
# Linux/macOS
./myclaw start
# 交互模式
myclaw chat技术架构
跨平台抽象层
package platform
import (
"runtime"
"path/filepath"
)
type Platform interface {
GetShell() string
ExecuteCommand(cmd string) (string, error)
NormalizePath(path string) string
}
type WindowsPlatform struct{}
func (p *WindowsPlatform) GetShell() string {
return "powershell.exe"
}
func (p *WindowsPlatform) ExecuteCommand(cmd string) (string, error) {
// 使用 PowerShell 执行
return exec.Command("powershell", "-Command", cmd).Output()
}
func (p *WindowsPlatform) NormalizePath(path string) string {
// 转换为 Windows 路径格式
return filepath.FromSlash(path)
}命令适配器
type CommandAdapter struct {
platform Platform
}
func (a *CommandAdapter) Adapt(cmd string) string {
switch a.platform.GetOS() {
case "windows":
return a.adaptForWindows(cmd)
case "linux", "darwin":
return a.adaptForUnix(cmd)
default:
return cmd
}
}
func (a *CommandAdapter) adaptForWindows(cmd string) string {
// ls -> Get-ChildItem
cmd = strings.Replace(cmd, "ls", "Get-ChildItem", -1)
// cat -> Get-Content
cmd = strings.Replace(cmd, "cat", "Get-Content", -1)
// grep -> Select-String
cmd = strings.Replace(cmd, "grep", "Select-String", -1)
return cmd
}路径处理
type PathManager struct {
separator string
}
func NewPathManager() *PathManager {
return &PathManager{
separator: string(filepath.Separator),
}
}
func (pm *PathManager) Join(parts ...string) string {
return filepath.Join(parts...)
}
func (pm *PathManager) Normalize(path string) string {
// 统一使用正斜杠
normalized := filepath.ToSlash(path)
// 展开环境变量
normalized = os.ExpandEnv(normalized)
return normalized
}功能特性
自动平台检测
func DetectPlatform() Platform {
switch runtime.GOOS {
case "windows":
return &WindowsPlatform{}
case "linux":
return &LinuxPlatform{}
case "darwin":
return &MacOSPlatform{}
default:
return &GenericPlatform{}
}
}Shell 命令转换
// Unix 命令转 Windows
var unixToWindows = map[string]string{
"ls": "dir",
"cat": "type",
"rm": "del",
"cp": "copy",
"mv": "move",
"pwd": "cd",
"clear": "cls",
"which": "where",
}
func ConvertCommand(cmd string, targetOS string) string {
if targetOS == "windows" {
for unix, win := range unixToWindows {
cmd = strings.Replace(cmd, unix, win, 1)
}
}
return cmd
}环境变量管理
type EnvManager struct {
vars map[string]string
}
func (em *EnvManager) Get(key string) string {
// 尝试多种格式
formats := []string{
key, // VARIABLE
strings.ToUpper(key), // VARIABLE
strings.ToLower(key), // variable
}
for _, format := range formats {
if val := os.Getenv(format); val != "" {
return val
}
}
return ""
}Windows 特性
PowerShell 集成
func ExecutePowerShell(script string) (string, error) {
cmd := exec.Command("powershell",
"-NoProfile",
"-NonInteractive",
"-Command",
script)
output, err := cmd.CombinedOutput()
return string(output), err
}文件权限处理
func SetExecutable(path string) error {
if runtime.GOOS == "windows" {
// Windows 不需要设置执行权限
return nil
}
return os.Chmod(path, 0755)
}路径长度限制
func HandleLongPath(path string) string {
if runtime.GOOS == "windows" {
// 使用 \\?\ 前缀支持长路径
if len(path) > 260 && !strings.HasPrefix(path, `\\?\`) {
absPath, _ := filepath.Abs(path)
return `\\?\` + absPath
}
}
return path
}适用场景
Windows 用户
- 官方版在 Windows 上问题多
- 需要原生 Windows 体验
- PowerShell 用户
企业环境
- 混合操作系统环境
- 需要统一部署方案
- IT 管理简化
开发团队
- 跨平台协作
- 统一开发体验
- CI/CD 集成
性能指标
| 指标 | Windows | Linux | macOS |
|---|---|---|---|
| 启动时间 | < 500ms | < 300ms | < 400ms |
| 内存占用 | ~80MB | ~60MB | ~70MB |
| 文件大小 | 15MB | 12MB | 13MB |
与其他版本对比
vs 官方版
- 官方版 Windows 兼容性差,MyClaw 专门优化
- 官方版需要 Node.js,MyClaw 单文件
- MyClaw 是官方版的跨平台增强
vs PicoClaw
- PicoClaw 专注 Serverless,MyClaw 专注跨平台
- 两者都是 Go 实现
- MyClaw 有更多 Windows 优化
vs ZeroClaw
- ZeroClaw 使用 Rust,MyClaw 使用 Go
- ZeroClaw 追求性能,MyClaw 追求兼容性
- 应用场景不同
常见问题
Windows Defender 误报
# 添加排除项
Add-MpPreference -ExclusionPath "C:\path\to\myclaw.exe"PowerShell 执行策略
# 设置执行策略
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser中文路径支持
// MyClaw 自动处理中文路径
// 无需额外配置相关链接
- GitHub: myclaw/myclaw
- 文档: 使用文档
- Windows 指南: Windows 用户指南
- 问题反馈: Issues
贡献
欢迎跨平台开发经验的贡献!
# 克隆仓库
git clone https://github.com/myclaw/myclaw.git
# 构建
go build -o myclaw
# 运行测试
go test ./...
# 跨平台编译
GOOS=windows GOARCH=amd64 go build -o myclaw.exe
GOOS=linux GOARCH=amd64 go build -o myclaw-linux
GOOS=darwin GOARCH=amd64 go build -o myclaw-macos许可证
MIT License - 详见 LICENSE