mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-07-03 12:28:10 +08:00
fix(opencode): pass --agent flag when agent config option is set (#1210)
Adds optional 'agent' config option under [projects.agent.options] for opencode. When set, the value is passed as --agent to every 'opencode run' invocation, enabling plugin-defined agents (e.g. oh-my-openagent's 'Sisyphus - Ultraworker') to work correctly without falling back to the default agent. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -33,6 +33,7 @@ type Agent struct {
|
||||
model string
|
||||
mode string
|
||||
cmd string // CLI binary name, default "opencode"
|
||||
agentName string // passed as --agent to opencode (for plugin-defined agents)
|
||||
providers []core.ProviderConfig
|
||||
activeIdx int
|
||||
sessionEnv []string
|
||||
@@ -69,6 +70,7 @@ func New(opts map[string]any) (core.Agent, error) {
|
||||
if cmd == "" {
|
||||
cmd = "opencode"
|
||||
}
|
||||
agentName, _ := opts["agent"].(string) // --agent flag for plugin-defined agents (#1210)
|
||||
ccDataDir, _ := opts["cc_data_dir"].(string)
|
||||
ccProject, _ := opts["cc_project"].(string)
|
||||
modelCachePath := opencodeProjectModelCachePath(ccDataDir, ccProject)
|
||||
@@ -86,6 +88,7 @@ func New(opts map[string]any) (core.Agent, error) {
|
||||
model: model,
|
||||
mode: mode,
|
||||
cmd: cmd,
|
||||
agentName: agentName,
|
||||
activeIdx: -1,
|
||||
modelCachePath: modelCachePath,
|
||||
persistentModelCache: persistentModelCache,
|
||||
@@ -459,6 +462,7 @@ func (a *Agent) StartSession(ctx context.Context, sessionID string) (core.AgentS
|
||||
mode := a.mode
|
||||
cmd := a.cmd
|
||||
workDir := a.workDir
|
||||
agentName := a.agentName
|
||||
extraEnv := a.providerEnvLocked()
|
||||
extraEnv = append(extraEnv, a.sessionEnv...)
|
||||
if a.activeIdx >= 0 && a.activeIdx < len(a.providers) {
|
||||
@@ -468,7 +472,7 @@ func (a *Agent) StartSession(ctx context.Context, sessionID string) (core.AgentS
|
||||
}
|
||||
a.mu.Unlock()
|
||||
|
||||
return newOpencodeSession(ctx, cmd, workDir, model, mode, sessionID, extraEnv)
|
||||
return newOpencodeSession(ctx, cmd, workDir, model, mode, agentName, sessionID, extraEnv)
|
||||
}
|
||||
|
||||
// ListSessions runs `opencode session list` and parses the JSON output.
|
||||
|
||||
@@ -28,6 +28,7 @@ type opencodeSession struct {
|
||||
workDir string
|
||||
model string
|
||||
mode string
|
||||
agentName string
|
||||
extraEnv []string
|
||||
events chan core.Event
|
||||
chatID atomic.Value // stores string — OpenCode session ID
|
||||
@@ -39,18 +40,19 @@ type opencodeSession struct {
|
||||
resultSent atomic.Bool // true when EventResult has been sent for this turn
|
||||
}
|
||||
|
||||
func newOpencodeSession(ctx context.Context, cmd, workDir, model, mode, resumeID string, extraEnv []string) (*opencodeSession, error) {
|
||||
func newOpencodeSession(ctx context.Context, cmd, workDir, model, mode, agentName, resumeID string, extraEnv []string) (*opencodeSession, error) {
|
||||
sessionCtx, cancel := context.WithCancel(ctx)
|
||||
|
||||
s := &opencodeSession{
|
||||
cmd: cmd,
|
||||
workDir: workDir,
|
||||
model: model,
|
||||
mode: mode,
|
||||
extraEnv: extraEnv,
|
||||
events: make(chan core.Event, 64),
|
||||
ctx: sessionCtx,
|
||||
cancel: cancel,
|
||||
cmd: cmd,
|
||||
workDir: workDir,
|
||||
model: model,
|
||||
mode: mode,
|
||||
agentName: agentName,
|
||||
extraEnv: extraEnv,
|
||||
events: make(chan core.Event, 64),
|
||||
ctx: sessionCtx,
|
||||
cancel: cancel,
|
||||
}
|
||||
s.alive.Store(true)
|
||||
|
||||
@@ -158,6 +160,9 @@ func (s *opencodeSession) buildRunArgs(prompt string, imagePaths []string, chatI
|
||||
if chatID != "" {
|
||||
args = append(args, "--session", chatID)
|
||||
}
|
||||
if s.agentName != "" {
|
||||
args = append(args, "--agent", s.agentName)
|
||||
}
|
||||
if s.model != "" {
|
||||
args = append(args, "--model", s.model)
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestOpencodeSessionEntry_Unmarshal(t *testing.T) {
|
||||
// the ContinueSession sentinel (__continue__) is not passed as a literal
|
||||
// session ID to the CLI. This was fixed in PR #249.
|
||||
func TestNewOpencodeSession_ContinueSessionTreatedAsFresh(t *testing.T) {
|
||||
s, err := newOpencodeSession(context.Background(), "echo", "/tmp", "", "default", core.ContinueSession, nil)
|
||||
s, err := newOpencodeSession(context.Background(), "echo", "/tmp", "", "default", "", core.ContinueSession, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("newOpencodeSession: %v", err)
|
||||
}
|
||||
|
||||
@@ -1558,6 +1558,9 @@ app_secret = "your-feishu-app-secret"
|
||||
# - "default": Standard mode / 标准模式
|
||||
# - "yolo": Auto-approve all tool calls / 自动批准所有工具调用
|
||||
#
|
||||
# Optional: pass --agent to opencode (for plugin-defined agents) / 可选:传递 --agent 给 opencode(适用于插件定义的 agent)
|
||||
# agent = "Sisyphus - Ultraworker"
|
||||
#
|
||||
# Optional: specify a model (provider/model format) / 可选:指定模型
|
||||
# model = "anthropic/claude-sonnet-4-20250514"
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user