mirror of
https://github.com/cexll/myclaude.git
synced 2025-12-24 13:47:58 +08:00
Gemini CLI uses -r <session_id> for session resume, not --session-id. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
87 lines
1.9 KiB
Go
87 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 != "" {
|
|
// Claude CLI uses -r <session_id> for resume.
|
|
args = append(args, "-r", 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, "-r", cfg.SessionID)
|
|
}
|
|
} else {
|
|
args = append(args, "-C", workdir)
|
|
}
|
|
|
|
args = append(args, "-p", targetArg)
|
|
|
|
return args
|
|
}
|