Files
myclaude/codeagent-wrapper/backend.go
swe-agent[bot] 90478d2049 fix(codeagent-wrapper): 修复权限标志逻辑和版本号测试
修复 GitHub Action CI 失败的两个问题:

1. backend.go - 修正 Claude 后端权限标志逻辑,将 `if !cfg.SkipPermissions` 改为 `if cfg.SkipPermissions`,确保只在显式请求时才添加 --dangerously-skip-permissions
2. main_test.go - 更新版本测试用例期望值从 5.1.0 到 5.2.0,匹配当前版本常量

所有测试通过 ✓

🤖 Generated with [SWE Agent Bot](https://swe-agent.ai)

Co-Authored-By: SWE-Agent-Bot <noreply@swe-agent.ai>
2025-12-11 16:16:23 +08:00

86 lines
1.9 KiB
Go

package main
// Backend defines the contract for invoking different AI CLI backends.
// Each backend is responsible for supplying the executable command and
// building the argument list based on the wrapper config.
type Backend interface {
Name() string
BuildArgs(cfg *Config, targetArg string) []string
Command() string
}
type CodexBackend struct{}
func (CodexBackend) Name() string { return "codex" }
func (CodexBackend) Command() string {
return "codex"
}
func (CodexBackend) BuildArgs(cfg *Config, targetArg string) []string {
return buildCodexArgs(cfg, targetArg)
}
type ClaudeBackend struct{}
func (ClaudeBackend) Name() string { return "claude" }
func (ClaudeBackend) Command() string {
return "claude"
}
func (ClaudeBackend) BuildArgs(cfg *Config, targetArg string) []string {
if cfg == nil {
return nil
}
args := []string{"-p"}
// Only skip permissions when explicitly requested
if cfg.SkipPermissions {
args = append(args, "--dangerously-skip-permissions")
}
workdir := cfg.WorkDir
if workdir == "" {
workdir = defaultWorkdir
}
if cfg.Mode == "resume" {
if cfg.SessionID != "" {
args = append(args, "--session-id", cfg.SessionID)
}
} else {
args = append(args, "-C", workdir)
}
args = append(args, "--output-format", "stream-json", "--verbose", targetArg)
return args
}
type GeminiBackend struct{}
func (GeminiBackend) Name() string { return "gemini" }
func (GeminiBackend) Command() string {
return "gemini"
}
func (GeminiBackend) BuildArgs(cfg *Config, targetArg string) []string {
if cfg == nil {
return nil
}
args := []string{"-o", "stream-json", "-y"}
workdir := cfg.WorkDir
if workdir == "" {
workdir = defaultWorkdir
}
if cfg.Mode == "resume" {
if cfg.SessionID != "" {
args = append(args, "--session-id", cfg.SessionID)
}
} else {
args = append(args, "-C", workdir)
}
args = append(args, "-p", targetArg)
return args
}