diff --git a/internal/config/config.go b/internal/config/config.go index 0dc07196f08ffffeffd96c532a7bded73409a35f..f2880f12c1dd267741b6167d1c4af9d2b98954d4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -526,33 +526,6 @@ func filterSlice(data []string, mask []string, include bool) []string { return filtered } -func (c *Config) SetupAgents() { - allowedTools := resolveAllowedTools(allToolNames(), c.Options.DisabledTools) - - agents := map[string]Agent{ - AgentCoder: { - ID: AgentCoder, - Name: "Coder", - Description: "An agent that helps with executing coding tasks.", - Model: SelectedModelTypeLarge, - ContextPaths: c.Options.ContextPaths, - AllowedTools: allowedTools, - }, - - AgentTask: { - ID: AgentCoder, - Name: "Task", - Description: "An agent that helps with searching for context and finding implementation details.", - Model: SelectedModelTypeLarge, - ContextPaths: c.Options.ContextPaths, - AllowedTools: resolveReadOnlyTools(allowedTools), - // NO MCPs or LSPs by default - AllowedMCP: map[string][]string{}, - }, - } - c.Agents = agents -} - func (c *Config) Resolver() VariableResolver { return c.resolver } diff --git a/internal/config/load.go b/internal/config/load.go index 96b4e06ce97a3ae0ee0d2bcac92d3152792a51da..044d9a5f7596ac21f7280936e44517f431195073 100644 --- a/internal/config/load.go +++ b/internal/config/load.go @@ -101,7 +101,7 @@ func Load(workingDir, dataDir string, debug bool) (*Service, error) { if err := svc.configureSelectedModels(svc.knownProviders); err != nil { return nil, fmt.Errorf("failed to configure selected models: %w", err) } - cfg.SetupAgents() + svc.SetupAgents() return svc, nil } diff --git a/internal/config/load_test.go b/internal/config/load_test.go index 71b94ca5af1a09d98583099c503b9555dab5e462..bde345e27ded5445ee026884b943c0a1e8ee9b1b 100644 --- a/internal/config/load_test.go +++ b/internal/config/load_test.go @@ -465,7 +465,7 @@ func TestConfig_setupAgentsWithNoDisabledTools(t *testing.T) { }, } - cfg.SetupAgents() + serviceFor(cfg).SetupAgents() coderAgent, ok := cfg.Agents[AgentCoder] require.True(t, ok) assert.Equal(t, allToolNames(), coderAgent.AllowedTools) @@ -486,7 +486,7 @@ func TestConfig_setupAgentsWithDisabledTools(t *testing.T) { }, } - cfg.SetupAgents() + serviceFor(cfg).SetupAgents() coderAgent, ok := cfg.Agents[AgentCoder] require.True(t, ok) @@ -510,7 +510,7 @@ func TestConfig_setupAgentsWithEveryReadOnlyToolDisabled(t *testing.T) { }, } - cfg.SetupAgents() + serviceFor(cfg).SetupAgents() coderAgent, ok := cfg.Agents[AgentCoder] require.True(t, ok) assert.Equal(t, []string{"agent", "bash", "job_output", "job_kill", "download", "edit", "multiedit", "lsp_diagnostics", "lsp_references", "lsp_restart", "fetch", "agentic_fetch", "todos", "write"}, coderAgent.AllowedTools) diff --git a/internal/config/service.go b/internal/config/service.go index 5a7aa0c03362a0ca4cb6a1b196b68a4ce31e0152..b85b54d5f8f8bcaeb065a2176ccb2622fedaafc6 100644 --- a/internal/config/service.go +++ b/internal/config/service.go @@ -25,6 +25,7 @@ type Service struct { resolver VariableResolver workingDir string knownProviders []catwalk.Provider + agents map[string]Agent } // Config returns the underlying Config struct. This is a temporary @@ -90,6 +91,39 @@ func (s *Service) Resolver() VariableResolver { return s.resolver } +// SetupAgents builds the agent configurations from the current config +// options. +func (s *Service) SetupAgents() { + allowedTools := resolveAllowedTools(allToolNames(), s.cfg.Options.DisabledTools) + + s.agents = map[string]Agent{ + AgentCoder: { + ID: AgentCoder, + Name: "Coder", + Description: "An agent that helps with executing coding tasks.", + Model: SelectedModelTypeLarge, + ContextPaths: s.cfg.Options.ContextPaths, + AllowedTools: allowedTools, + }, + + AgentTask: { + ID: AgentCoder, + Name: "Task", + Description: "An agent that helps with searching for context and finding implementation details.", + Model: SelectedModelTypeLarge, + ContextPaths: s.cfg.Options.ContextPaths, + AllowedTools: resolveReadOnlyTools(allowedTools), + AllowedMCP: map[string][]string{}, + }, + } + s.cfg.Agents = s.agents +} + +// Agents returns the agent configuration map. +func (s *Service) Agents() map[string]Agent { + return s.agents +} + // HasConfigField returns true if the given dotted key path exists in // the persisted config data. func (s *Service) HasConfigField(key string) bool { diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index 7526c4897403c2fb3b05e97f1f6783c6d6470fa4..3ab0caee90ea78990469deda4852bdac7d1e5c05 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -1286,7 +1286,7 @@ func (m *UI) handleDialogMsg(msg tea.Msg) tea.Cmd { if isOnboarding { m.setState(uiLanding, uiFocusEditor) - m.com.Config().SetupAgents() + m.com.ConfigService().SetupAgents() if err := m.com.App.InitCoderAgent(context.TODO()); err != nil { cmds = append(cmds, util.ReportError(err)) }