Skip to content

Commit 5cfbd2e

Browse files
Add opencode_cmd config override for custom executable path (#524)
## Summary Add `opencode_cmd` config key so users can override the OpenCode executable path, matching the existing pattern for `codex_cmd`, `claude_code_cmd`, `cursor_cmd`, and `pi_cmd`. This is the simplest unblocking approach (option 3) from #355, enabling users to point roborev at a wrapper script that passes `--agent` or other flags to opencode. ## Changes - **`internal/config/config.go`** — Add `OpenCodeCmd` field to `Config` struct with `toml:"opencode_cmd"` tag; set default `"opencode"` in `DefaultConfig()` - **`internal/agent/acp.go`** — Add `case *OpenCodeAgent:` branch in `applyCommandOverrides` to apply the config override - **`internal/agent/acp_test.go`** — Add `TestGetAvailableWithConfigOpenCodeCmd` following the established test pattern ## How to test ```bash go test ./internal/config/... ./internal/agent/... ``` The new test creates a fake binary, sets `opencode_cmd` in config, and verifies `GetAvailableWithConfig` resolves to the overridden path. ## Notes - No changes needed in `keyval.go` or `config_cmd.go` — config keys are auto-discovered via reflection on `toml` struct tags - No docs changes — existing `*_cmd` keys are not documented in-repo (README defers to roborev.io/configuration) Closes #355 (option 3) Co-authored-by: Sergey Trofimovsky <sergey.trofimovsky@trulioo.com>
1 parent 0b8f2f1 commit 5cfbd2e

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

internal/agent/acp.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,12 @@ func applyCommandOverrides(a Agent, cfg *config.Config) Agent {
15361536
clone.Command = cfg.PiCmd
15371537
return &clone
15381538
}
1539+
case *OpenCodeAgent:
1540+
if cfg.OpenCodeCmd != "" {
1541+
clone := *agent
1542+
clone.Command = cfg.OpenCodeCmd
1543+
return &clone
1544+
}
15391545
}
15401546
return a
15411547
}

internal/agent/acp_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,38 @@ func TestGetAvailableWithConfigPiCmd(t *testing.T) {
11491149
assert.Equal(t, filepath.Join(fakeBin, wrapper), ca.CommandName())
11501150
}
11511151

1152+
func TestGetAvailableWithConfigOpenCodeCmd(t *testing.T) {
1153+
fakeBin := t.TempDir()
1154+
wrapper := "custom-opencode"
1155+
if runtime.GOOS == "windows" {
1156+
wrapper += ".exe"
1157+
}
1158+
err := os.WriteFile(
1159+
filepath.Join(fakeBin, wrapper),
1160+
[]byte("#!/bin/sh\nexit 0\n"), 0o755,
1161+
)
1162+
require.NoError(t, err)
1163+
t.Setenv("PATH", fakeBin)
1164+
1165+
originalRegistry := registry
1166+
registry = map[string]Agent{
1167+
"opencode": NewOpenCodeAgent(""),
1168+
}
1169+
t.Cleanup(func() { registry = originalRegistry })
1170+
1171+
cfg := &config.Config{
1172+
OpenCodeCmd: filepath.Join(fakeBin, wrapper),
1173+
}
1174+
1175+
resolved, err := GetAvailableWithConfig("opencode", cfg)
1176+
require.NoError(t, err)
1177+
assert.Equal(t, "opencode", resolved.Name())
1178+
1179+
ca, ok := resolved.(CommandAgent)
1180+
require.True(t, ok)
1181+
assert.Equal(t, filepath.Join(fakeBin, wrapper), ca.CommandName())
1182+
}
1183+
11521184
func TestGetAvailableWithConfigACPFallbackBackupUsesConfigCmd(t *testing.T) {
11531185
// Configured ACP alias is requested but ACP command is
11541186
// unavailable. The backup agent's default command is also

internal/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ type Config struct {
145145
ClaudeCodeCmd string `toml:"claude_code_cmd"`
146146
CursorCmd string `toml:"cursor_cmd"`
147147
PiCmd string `toml:"pi_cmd"`
148+
OpenCodeCmd string `toml:"opencode_cmd"`
148149

149150
// API keys (optional - agents use subscription auth by default)
150151
AnthropicAPIKey string `toml:"anthropic_api_key" sensitive:"true"`
@@ -691,6 +692,7 @@ func DefaultConfig() *Config {
691692
ClaudeCodeCmd: "claude",
692693
CursorCmd: "agent",
693694
PiCmd: "pi",
695+
OpenCodeCmd: "opencode",
694696
MouseEnabled: true,
695697
}
696698
cfg.CI.ThrottleBypassUsers = []string{

0 commit comments

Comments
 (0)