Skip to content

Commit c63f4e9

Browse files
fix(oc): drop unsupported --variant from default opencode launch template
Follow-up to f70a34a (ntm#193). That commit's DefaultOpencodeCommand injected `--variant <effort>` into the OpenCode launch template: opencode{{if .Model}} --model ...{{end}}{{if .ReasoningEffort}} --variant ...{{end}} But `--variant` is NOT a flag on the root `opencode` command — the one an interactive agent pane launches (the TUI). It exists only on the `opencode run` subcommand. Adding it to the root command is the still-open, unmerged feature request anomalyco/opencode#7354 (PR #7358); the tracking issue was auto-closed by a staleness bot after 90 days of inactivity, not by a fix, and as of this writing the PR's `merged` field is false. Concretely, this regressed the exact thing #193 set out to enable: any OpenCode spawn carrying a reasoning effort — e.g. `--oc=2:provider/model:high`, which the agent-spec parser turns into ReasoningEffort="high" and threads through to GenerateAgentCommand — rendered opencode --model 'provider/model' --variant 'high' which the root `opencode` command rejects as an unknown flag, so the pane fails to launch instead of joining cross-agent coordination. Fix: render only `--model` (which the root command genuinely accepts and is the primary #193 goal: makes `--oc=N:provider/model` work and gives Agent Mail a non-empty model). ReasoningEffort is now inert for opencode and leaves no dangling flag — verified by the updated TestDefaultAgentTemplates, which asserts `opencode --model '...'` with model+effort and bare `opencode` with neither. The other #193 pieces are sound and unchanged: GetProfileByName/ AllProfiles return deep copies (confirmed in profiles.go copy()), so effectiveAgentModel overwriting .Model for display does not mutate shared matcher state; the effectiveAgentModel config→static fallback chain is correct for every profile type; and opencodeCommandOrDefault behaves identically at all five call sites. Stale "model/variant-aware" comments updated to "model-aware". go build/vet/gofmt clean; config + cli + agents suites green; robot restart/launch tests green (full robot package only times out under VPS load, unrelated to this change). Co-Authored-By: Claude <[email protected]>
1 parent f70a34a commit c63f4e9

6 files changed

Lines changed: 32 additions & 20 deletions

File tree

‎internal/cli/add.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type AddOptions struct {
4040
}
4141

4242
// opencodeCommandOrDefault returns the configured [agents] oc launch command,
43-
// falling back to config.DefaultOpencodeCommand (a model/variant-aware template)
43+
// falling back to config.DefaultOpencodeCommand (a model-aware template)
4444
// when it is unset. Centralizing this keeps the spawn, add, restart, and
4545
// session-resume dispatch paths in lockstep so a model override is honored and
4646
// Agent Mail registration receives a non-empty model everywhere. See ntm#193.
@@ -71,9 +71,9 @@ func resolveAddAgentCommandTemplate(agentType AgentType, pluginMap map[string]pl
7171
case AgentTypeAider:
7272
return cfg.Agents.Aider, nil, nil
7373
case AgentTypeOpencode:
74-
// Falls back to the model/variant-aware default when [agents] oc is
75-
// unset, so `ntm spawn --oc=N` and `ntm add --oc=N` behave identically
76-
// and a model override is honored. See ntm#193.
74+
// Falls back to the model-aware default when [agents] oc is unset, so
75+
// `ntm spawn --oc=N` and `ntm add --oc=N` behave identically and a
76+
// model override is honored. See ntm#193.
7777
return opencodeCommandOrDefault(cfg.Agents.Opencode), nil, nil
7878
default:
7979
if p, ok := pluginMap[string(agentType)]; ok {

‎internal/cli/controller.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ func buildControllerResponse(opts ControllerInput) (*ControllerResponse, error)
269269
agentCmdTemplate = cfg.Agents.Aider
270270
case "oc":
271271
agentTypeFull = "opencode"
272-
// Mirror the spawn/add dispatch fallback so model/variant injection
273-
// works on restart too. See ntm#193.
272+
// Mirror the spawn/add dispatch fallback so model injection works on
273+
// restart too. See ntm#193.
274274
agentCmdTemplate = opencodeCommandOrDefault(cfg.Agents.Opencode)
275275
case "ollama":
276276
agentTypeFull = "ollama"

‎internal/cli/spawn.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,9 +1917,9 @@ func spawnSessionLogic(opts SpawnOptions) (err error) {
19171917
case AgentTypeAider:
19181918
agentCmdTemplate = cfg.Agents.Aider
19191919
case AgentTypeOpencode:
1920-
// Falls back to the model/variant-aware default when [agents] oc
1921-
// is unset, so `--oc=N:provider/model` works and Agent Mail
1922-
// registration receives a non-empty model. Users can override via
1920+
// Falls back to the model-aware default when [agents] oc is unset,
1921+
// so `--oc=N:provider/model` works and Agent Mail registration
1922+
// receives a non-empty model. Users can override via
19231923
// `[agents] oc = "..."` to point at a wrapper script or pin a
19241924
// specific provider/model. See ntm#193.
19251925
agentCmdTemplate = opencodeCommandOrDefault(cfg.Agents.Opencode)

‎internal/config/templates.go‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,23 @@ func DefaultAgentTemplates() AgentConfig {
242242
Windsurf: `windsurf{{if .Model}} --model {{shellQuote .Model}}{{end}}`,
243243
Aider: `aider{{if .Model}} --model {{shellQuote .Model}}{{end}}`,
244244
// Opencode (oc): the upstream `opencode` binary takes `-m/--model
245-
// provider/model` and `--variant <effort>` for reasoning budget.
246-
// Without the {{.Model}} placeholder a `--oc=N:provider/model` spawn
247-
// is rejected ("agent command has no template syntax") and Agent Mail
248-
// registration fails ("model cannot be empty"). See ntm#116, ntm#193.
245+
// provider/model`. Without the {{.Model}} placeholder a
246+
// `--oc=N:provider/model` spawn is rejected ("agent command has no
247+
// template syntax") and Agent Mail registration fails ("model cannot
248+
// be empty"). NOTE: `--variant` (reasoning effort) is NOT a flag on the
249+
// root `opencode` TUI command an interactive pane launches — it exists
250+
// only on the `opencode run` subcommand (anomalyco/opencode#7354, PR
251+
// #7358 still open/unmerged), so injecting it here would make the pane
252+
// fail to launch whenever an effort is supplied. See ntm#116, ntm#193.
249253
Opencode: DefaultOpencodeCommand,
250254
}
251255
}
252256

253257
// DefaultOpencodeCommand is the launch command used when [agents] oc is not
254258
// configured. It mirrors DefaultAgentTemplates().Opencode so that the spawn,
255259
// add, and restart dispatch paths inject the model the same way a freshly
256-
// generated config does. See ntm#193.
257-
const DefaultOpencodeCommand = `opencode{{if .Model}} --model {{shellQuote .Model}}{{end}}{{if .ReasoningEffort}} --variant {{shellQuote .ReasoningEffort}}{{end}}`
260+
// generated config does. Only `--model` is injected: it is the lone
261+
// model/reasoning flag the root `opencode` TUI command accepts (the
262+
// `--variant` effort flag lives on the `opencode run` subcommand only — see
263+
// the note in DefaultAgentTemplates). See ntm#193.
264+
const DefaultOpencodeCommand = `opencode{{if .Model}} --model {{shellQuote .Model}}{{end}}`

‎internal/config/templates_test.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,17 @@ func TestDefaultAgentTemplates(t *testing.T) {
311311
if !IsTemplateCommand(templates.Opencode) {
312312
t.Error("Opencode template should be recognized as a template command (no {{...}} placeholder)")
313313
}
314-
// With a model + reasoning effort, both --model and --variant render.
314+
// With a model, --model renders. The reasoning-effort hint is deliberately
315+
// NOT emitted as `--variant`: that flag is not accepted by the root
316+
// `opencode` TUI command an interactive pane launches (it exists only on
317+
// `opencode run`; anomalyco/opencode#7354 / PR #7358 still unmerged), so
318+
// emitting it would break the launch. ReasoningEffort is therefore inert
319+
// for opencode and must not leave a dangling flag.
315320
ocFull, err := GenerateAgentCommand(templates.Opencode, AgentTemplateVars{Model: "zai-coding-plan/glm-5.2", ReasoningEffort: "high"})
316321
if err != nil {
317322
t.Fatalf("Opencode template failed: %v", err)
318323
}
319-
if ocFull != "opencode --model 'zai-coding-plan/glm-5.2' --variant 'high'" {
324+
if ocFull != "opencode --model 'zai-coding-plan/glm-5.2'" {
320325
t.Errorf("Opencode model+effort render = %q", ocFull)
321326
}
322327
// With no model, the command degrades to the bare binary (no dangling flags).

‎internal/robot/restart_pane.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ func restartAgentLaunchCommand(cfg *config.Config, agentType string) string {
316316
case "aider":
317317
tmpl = cfg.Agents.Aider
318318
case "oc":
319-
// Fall back to the model/variant-aware default when [agents] oc is
320-
// unset so a respawn launches the real `opencode` binary rather
321-
// than the bare `oc` alias. See ntm#193.
319+
// Fall back to the model-aware default when [agents] oc is unset
320+
// so a respawn launches the real `opencode` binary rather than the
321+
// bare `oc` alias. See ntm#193.
322322
tmpl = cfg.Agents.Opencode
323323
if strings.TrimSpace(tmpl) == "" {
324324
tmpl = config.DefaultOpencodeCommand

0 commit comments

Comments
 (0)