Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(daemon): add Google Gemini CLI backend

Sanjay Ramaduguf99f50eb0c1b
diff --git a/server/internal/daemon/config.go b/server/internal/daemon/config.go
index fc0fcad7bd..1c8727c5e0 100644
--- a/server/internal/daemon/config.go
+++ b/server/internal/daemon/config.go
@@ -30,7 +30,7 @@ type Config struct {
RuntimeName string
CLIVersion string // multica CLI version (e.g. "0.1.13")
Profile string // profile name (empty = default)
- Agents map[string]AgentEntry // "claude" -> entry, "codex" -> entry, "opencode" -> entry, "openclaw" -> entry, "hermes" -> entry
+ Agents map[string]AgentEntry // keyed by provider: claude, codex, opencode, openclaw, hermes, gemini
WorkspacesRoot string // base path for execution envs (default: ~/multica_workspaces)
KeepEnvAfterTask bool // preserve env after task for debugging
HealthPort int // local HTTP port for health checks (default: 19514)
@@ -106,8 +106,15 @@ func LoadConfig(overrides Overrides) (Config, error) {
Model: strings.TrimSpace(os.Getenv("MULTICA_HERMES_MODEL")),
}
}
+ geminiPath := envOrDefault("MULTICA_GEMINI_PATH", "gemini")
+ if _, err := exec.LookPath(geminiPath); err == nil {
+ agents["gemini"] = AgentEntry{
+ Path: geminiPath,
+ Model: strings.TrimSpace(os.Getenv("MULTICA_GEMINI_MODEL")),
+ }
+ }
if len(agents) == 0 {
- return Config{}, fmt.Errorf("no agent CLI found: install claude, codex, opencode, openclaw, or hermes and ensure it is on PATH")
+ return Config{}, fmt.Errorf("no agent CLI found: install claude, codex, opencode, openclaw, hermes, or gemini and ensure it is on PATH")
}
// Host info
diff --git a/server/internal/daemon/execenv/execenv_test.go b/server/internal/daemon/execenv/execenv_test.go
index b12e681875..1093b6edf9 100644
--- a/server/internal/daemon/execenv/execenv_test.go
+++ b/server/internal/daemon/execenv/execenv_test.go
@@ -390,6 +390,44 @@ func TestInjectRuntimeConfigClaude(t *testing.T) {
}
}
+func TestInjectRuntimeConfigGemini(t *testing.T) {
+ t.Parallel()
+ dir := t.TempDir()
+
+ ctx := TaskContextForEnv{
+ IssueID: "test-issue-id",
+ AgentSkills: []SkillContextForEnv{{Name: "Writing", Content: "Write clearly."}},
+ }
+
+ if err := InjectRuntimeConfig(dir, "gemini", ctx); err != nil {
+ t.Fatalf("InjectRuntimeConfig failed: %v", err)
+ }
+
+ content, err := os.ReadFile(filepath.Join(dir, "GEMINI.md"))
+ if err != nil {
+ t.Fatalf("failed to read GEMINI.md: %v", err)
+ }
+
+ s := string(content)
+ for _, want := range []string{
+ "Multica Agent Runtime",
+ "multica issue get",
+ "Writing",
+ } {
+ if !strings.Contains(s, want) {
+ t.Errorf("GEMINI.md missing %q", want)
+ }
+ }
+
+ // Should not write CLAUDE.md or AGENTS.md for gemini provider.
+ if _, err := os.Stat(filepath.Join(dir, "CLAUDE.md")); !os.IsNotExist(err) {
+ t.Error("gemini provider should not create CLAUDE.md")
+ }
+ if _, err := os.Stat(filepath.Join(dir, "AGENTS.md")); !os.IsNotExist(err) {
+ t.Error("gemini provider should not create AGENTS.md")
+ }
+}
+
func TestInjectRuntimeConfigCodex(t *testing.T) {
t.Parallel()
dir := t.TempDir()
diff --git a/server/internal/daemon/execenv/runtime_config.go b/server/internal/daemon/execenv/runtime_config.go
index dd9a264d56..13be8c1f8d 100644
--- a/server/internal/daemon/execenv/runtime_config.go
+++ b/server/internal/daemon/execenv/runtime_config.go
@@ -14,6 +14,7 @@ import (
// For Codex: writes {workDir}/AGENTS.md (skills discovered natively via CODEX_HOME)
// For OpenCode: writes {workDir}/AGENTS.md (skills discovered natively from .config/opencode/skills/)
// For OpenClaw: writes {workDir}/AGENTS.md (skills discovered natively from .openclaw/skills/)
+// For Gemini: writes {workDir}/GEMINI.md (discovered natively by the Gemini CLI)
func InjectRuntimeConfig(workDir, provider string, ctx TaskContextForEnv) error {
content := buildMetaSkillContent(provider, ctx)
@@ -22,6 +23,8 @@ func InjectRuntimeConfig(workDir, provider string, ctx TaskContextForEnv) error
return os.WriteFile(filepath.Join(workDir, "CLAUDE.md"), []byte(content), 0o644)
case "codex", "opencode", "openclaw":
return os.WriteFile(filepath.Join(workDir, "AGENTS.md"), []byte(content), 0o644)
+ case "gemini":
+ return os.WriteFile(filepath.Join(workDir, "GEMINI.md"), []byte(content), 0o644)
default:
// Unknown provider — skip config injection, prompt-only mode.
return nil
@@ -125,6 +128,9 @@ func buildMetaSkillContent(provider string, ctx TaskContextForEnv) string {
case "codex", "opencode", "openclaw":
// Codex, OpenCode, and OpenClaw discover skills natively from their respective paths — just list names.
b.WriteString("You have the following skills installed (discovered automatically):\n\n")
+ case "gemini":
+ // Gemini reads GEMINI.md directly; point it at the fallback skills dir.
+ b.WriteString("Detailed skill instructions are in `.agent_context/skills/`. Each subdirectory contains a `SKILL.md`.\n\n")
default:
b.WriteString("Detailed skill instructions are in `.agent_context/skills/`. Each subdirectory contains a `SKILL.md`.\n\n")
}
diff --git a/server/pkg/agent/agent.go b/server/pkg/agent/agent.go
index 2d7c347c50..aa3f50928e 100644
--- a/server/pkg/agent/agent.go
+++ b/server/pkg/agent/agent.go
@@ -82,13 +82,13 @@ type Result struct {
// Config configures a Backend instance.
type Config struct {
- ExecutablePath string // path to CLI binary (claude, codex, opencode, openclaw, or hermes)
+ ExecutablePath string // path to CLI binary (claude, codex, opencode, openclaw, hermes, or gemini)
Env map[string]string // extra environment variables
Logger *slog.Logger
}
// New creates a Backend for the given agent type.
-// Supported types: "claude", "codex", "opencode", "openclaw", "hermes".
+// Supported types: "claude", "codex", "opencode", "openclaw", "hermes", "gemini".
func New(agentType string, cfg Config) (Backend, error) {
if cfg.Logger == nil {
cfg.Logger = slog.Default()
@@ -105,8 +105,10 @@ func New(agentType string, cfg Config) (Backend, error) {
return &openclawBackend{cfg: cfg}, nil
case "hermes":
return &hermesBackend{cfg: cfg}, nil
+ case "gemini":
+ return &geminiBackend{cfg: cfg}, nil
default:
- return nil, fmt.Errorf("unknown agent type: %q (supported: claude, codex, opencode, openclaw, hermes)", agentType)
+ return nil, fmt.Errorf("unknown agent type: %q (supported: claude, codex, opencode, openclaw, hermes, gemini)", agentType)
}
}
diff --git a/server/pkg/agent/gemini.go b/server/pkg/agent/gemini.go
new file mode 100644
index 0000000000..cfc52f3ac8
--- /dev/null
+++ b/server/pkg/agent/gemini.go
@@ -0,0 +1,135 @@
+package agent
+
+import (
+ "bufio"
+ "context"
+ "fmt"
+ "io"
+ "os/exec"
+ "strings"
+ "time"
+)
+
+// geminiBackend implements Backend by spawning the Google Gemini CLI
+// (`gemini -p <prompt> --yolo -o text`) and collecting its stdout.
+//
+// This is a minimal v1 implementation — it captures the final text
+// response but does not stream tool calls in real time. Follow-ups
+// can move to `-o stream-json` and parse Gemini's event schema once
+// we have a reliable reproduction of its output format.
+type geminiBackend struct {
+ cfg Config
+}
+
+func (b *geminiBackend) Execute(ctx context.Context, prompt string, opts ExecOptions) (*Session, error) {
+ execPath := b.cfg.ExecutablePath
+ if execPath == "" {
+ execPath = "gemini"
+ }
+ if _, err := exec.LookPath(execPath); err != nil {
+ return nil, fmt.Errorf("gemini executable not found at %q: %w", execPath, err)
+ }
+
+ timeout := opts.Timeout
+ if timeout == 0 {
+ timeout = 20 * time.Minute
+ }
+ runCtx, cancel := context.WithTimeout(ctx, timeout)
+
+ args := buildGeminiArgs(prompt, opts)
+
+ cmd := exec.CommandContext(runCtx, execPath, args...)
+ if opts.Cwd != "" {
+ cmd.Dir = opts.Cwd
+ }
+ cmd.Env = buildEnv(b.cfg.Env)
+
+ stdout, err := cmd.StdoutPipe()
+ if err != nil {
+ cancel()
+ return nil, fmt.Errorf("gemini stdout pipe: %w", err)
+ }
+ cmd.Stderr = newLogWriter(b.cfg.Logger, "[gemini:stderr] ")
+
+ if err := cmd.Start(); err != nil {
+ cancel()
+ return nil, fmt.Errorf("start gemini: %w", err)
+ }
+
+ b.cfg.Logger.Info("gemini started", "pid", cmd.Process.Pid, "cwd", opts.Cwd, "model", opts.Model)
+
+ msgCh := make(chan Message, 16)
+ resCh := make(chan Result, 1)
+
+ go func() {
+ defer cancel()
+ defer close(msgCh)
+ defer close(resCh)
+
+ startTime := time.Now()
+ output, readErr := io.ReadAll(bufio.NewReader(stdout))
+
+ // Forward the full response as a single text message so the daemon
+ // can persist it verbatim. Tool streaming is intentionally omitted
+ // in v1; see the file-level comment.
+ text := strings.TrimRight(string(output), "\n")
+ if text != "" {
+ trySend(msgCh, Message{Type: MessageText, Content: text})
+ }
+
+ waitErr := cmd.Wait()
+ durationMs := time.Since(startTime).Milliseconds()
+
+ result := Result{
+ Status: "completed",
+ Output: text,
+ DurationMs: durationMs,
+ }
+
+ if readErr != nil {
+ result.Status = "failed"
+ result.Error = fmt.Sprintf("read stdout: %s", readErr.Error())
+ } else if waitErr != nil {
+ // Distinguish context cancellation (timeout) from exit errors.
+ if runCtx.Err() == context.DeadlineExceeded {
+ result.Status = "timeout"
+ result.Error = fmt.Sprintf("gemini timed out after %s", timeout)
+ } else {
+ result.Status = "failed"
+ result.Error = waitErr.Error()
+ }
+ }
+
+ resCh <- result
+ }()
+
+ return &Session{Messages: msgCh, Result: resCh}, nil
+}
+
+// buildGeminiArgs assembles the argv for a one-shot gemini invocation.
+//
+// Flags:
+//
+// -p / --prompt non-interactive prompt (the user's task)
+// --yolo auto-approve all tool executions (equivalent to
+// claude's --permission-mode bypassPermissions)
+// -o text plain text output (stream-json is a follow-up)
+// -m <model> optional model override (from MULTICA_GEMINI_MODEL)
+// -r <session> resume a previous session (if provided)
+//
+// Note: gemini reads stdin and appends it to -p when both are present.
+// The daemon does not pipe stdin, so the prompt comes exclusively from -p.
+func buildGeminiArgs(prompt string, opts ExecOptions) []string {
+ args := []string{
+ "-p", prompt,
+ "--yolo",
+ "-o", "text",
+ }
+ if opts.Model != "" {
+ args = append(args, "-m", opts.Model)
+ }
+ if opts.ResumeSessionID != "" {
+ args = append(args, "-r", opts.ResumeSessionID)
+ }
+ return args
+}
diff --git a/server/pkg/agent/gemini_test.go b/server/pkg/agent/gemini_test.go
new file mode 100644
index 0000000000..8fc4e63399
--- /dev/null
+++ b/server/pkg/agent/gemini_test.go
@@ -0,0 +1,79 @@
+package agent
+
+import (
+ "testing"
+)
+
+func TestBuildGeminiArgsBaseline(t *testing.T) {
+ t.Parallel()
+
+ args := buildGeminiArgs("write a haiku", ExecOptions{})
+ expected := []string{
+ "-p", "write a haiku",
+ "--yolo",
+ "-o", "text",
+ }
+
+ if len(args) != len(expected) {
+ t.Fatalf("expected %d args, got %d: %v", len(expected), len(args), args)
+ }
+ for i, want := range expected {
+ if args[i] != want {
+ t.Fatalf("expected args[%d] = %q, got %q", i, want, args[i])
+ }
+ }
+}
+
+func TestBuildGeminiArgsWithModel(t *testing.T) {
+ t.Parallel()
+
+ args := buildGeminiArgs("hi", ExecOptions{Model: "gemini-2.5-pro"})
+
+ var foundModel bool
+ for i, a := range args {
+ if a == "-m" {
+ if i+1 >= len(args) || args[i+1] != "gemini-2.5-pro" {
+ t.Fatalf("expected -m followed by gemini-2.5-pro, got %v", args)
+ }
+ foundModel = true
+ break
+ }
+ }
+ if !foundModel {
+ t.Fatalf("expected -m flag when Model is set, got args=%v", args)
+ }
+}
+
+func TestBuildGeminiArgsWithResume(t *testing.T) {
+ t.Parallel()
+
+ args := buildGeminiArgs("hi", ExecOptions{ResumeSessionID: "3"})
+
+ var foundResume bool
+ for i, a := range args {
+ if a == "-r" {
+ if i+1 >= len(args) || args[i+1] != "3" {
+ t.Fatalf("expected -r followed by session id, got %v", args)
+ }
+ foundResume = true
+ break
+ }
+ }
+ if !foundResume {
+ t.Fatalf("expected -r flag when ResumeSessionID is set, got args=%v", args)
+ }
+}
+
+func TestBuildGeminiArgsOmitsModelWhenEmpty(t *testing.T) {
+ t.Parallel()
+
+ args := buildGeminiArgs("hi", ExecOptions{})
+ for _, a := range args {
+ if a == "-m" {
+ t.Fatalf("expected no -m flag when Model is empty, got args=%v", args)
+ }
+ if a == "-r" {
+ t.Fatalf("expected no -r flag when ResumeSessionID is empty, got args=%v", args)
+ }
+ }
+}