The open source coding agent.
TypeScript
chore: rename coder -> primary
adamdottv36e5ae804e4b
diff --git a/README.md b/README.mdindex b3eb37777fb..5db86c74bec 100644--- a/README.md+++ b/README.md@@ -105,7 +105,7 @@ You can configure OpenCode using environment variables:}},"agents": {- "coder": {+ "primary": {"model": "claude-3.7-sonnet","maxTokens": 5000},diff --git a/cmd/root.go b/cmd/root.goindex 1b8c4c574e4..d18c8785425 100644--- a/cmd/root.go+++ b/cmd/root.go@@ -86,7 +86,7 @@ to assist developers in writing, debugging, and understanding code directly fromapp, err := app.New(ctx, conn)if err != nil {- slog.Error("Failed to create app: %v", err)+ slog.Error("Failed to create app", "error", err)return err}@@ -152,11 +152,11 @@ to assist developers in writing, debugging, and understanding code directly fromcleanup()if err != nil {- slog.Error("TUI error: %v", err)+ slog.Error("TUI error", "error", err)return fmt.Errorf("TUI error: %v", err)}- slog.Info("TUI exited with result: %v", result)+ slog.Info("TUI exited", "result", result)return nil},}diff --git a/cmd/schema/README.md b/cmd/schema/README.mdindex 93ebe9f03bd..e448ea0cb21 100644--- a/cmd/schema/README.md+++ b/cmd/schema/README.md@@ -46,7 +46,7 @@ Here's an example configuration that conforms to the schema:}},"agents": {- "coder": {+ "primary": {"model": "claude-3.7-sonnet","maxTokens": 5000,"reasoningEffort": "medium"@@ -61,4 +61,5 @@ Here's an example configuration that conforms to the schema:}}}-```\ No newline at end of file+```+diff --git a/cmd/schema/main.go b/cmd/schema/main.goindex 6340cb32f47..f5786a7c07e 100644--- a/cmd/schema/main.go+++ b/cmd/schema/main.go@@ -274,7 +274,7 @@ func generateSchema() map[string]any {// Add specific agent propertiesagentProperties := map[string]any{}knownAgents := []string{- string(config.AgentCoder),+ string(config.AgentPrimary),string(config.AgentTask),string(config.AgentTitle),}diff --git a/internal/app/app.go b/internal/app/app.goindex 283b311c881..d4110ac7cc8 100644--- a/internal/app/app.go+++ b/internal/app/app.go@@ -29,7 +29,7 @@ type App struct {Permissions permission.ServiceStatus status.Service- CoderAgent agent.Service+ PrimaryAgent agent.ServiceLSPClients map[string]*lsp.Client@@ -88,11 +88,11 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {// Initialize LSP clients in the backgroundgo app.initLSPClients(ctx)- app.CoderAgent, err = agent.NewAgent(- config.AgentCoder,+ app.PrimaryAgent, err = agent.NewAgent(+ config.AgentPrimary,app.Sessions,app.Messages,- agent.CoderAgentTools(+ agent.PrimaryAgentTools(app.Permissions,app.Sessions,app.Messages,@@ -101,7 +101,7 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {),)if err != nil {- slog.Error("Failed to create coder agent", err)+ slog.Error("Failed to create primary agent", "error", err)return nil, err}diff --git a/internal/config/config.go b/internal/config/config.goindex bb9ec447c13..3f80456f6e8 100644--- a/internal/config/config.go+++ b/internal/config/config.go@@ -36,9 +36,9 @@ type MCPServer struct {type AgentName stringconst (- AgentCoder AgentName = "coder"- AgentTask AgentName = "task"- AgentTitle AgentName = "title"+ AgentPrimary AgentName = "primary"+ AgentTask AgentName = "task"+ AgentTitle AgentName = "title")// Agent defines configuration for different LLM models and their token limits.@@ -238,7 +238,7 @@ func setProviderDefaults() {// Anthropic configurationif key := viper.GetString("providers.anthropic.apiKey"); strings.TrimSpace(key) != "" {- viper.SetDefault("agents.coder.model", models.Claude37Sonnet)+ viper.SetDefault("agents.primary.model", models.Claude37Sonnet)viper.SetDefault("agents.task.model", models.Claude37Sonnet)viper.SetDefault("agents.title.model", models.Claude37Sonnet)return@@ -246,7 +246,7 @@ func setProviderDefaults() {// OpenAI configurationif key := viper.GetString("providers.openai.apiKey"); strings.TrimSpace(key) != "" {- viper.SetDefault("agents.coder.model", models.GPT41)+ viper.SetDefault("agents.primary.model", models.GPT41)viper.SetDefault("agents.task.model", models.GPT41Mini)viper.SetDefault("agents.title.model", models.GPT41Mini)return@@ -254,7 +254,7 @@ func setProviderDefaults() {// Google Gemini configurationif key := viper.GetString("providers.gemini.apiKey"); strings.TrimSpace(key) != "" {- viper.SetDefault("agents.coder.model", models.Gemini25)+ viper.SetDefault("agents.primary.model", models.Gemini25)viper.SetDefault("agents.task.model", models.Gemini25Flash)viper.SetDefault("agents.title.model", models.Gemini25Flash)return@@ -262,7 +262,7 @@ func setProviderDefaults() {// Groq configurationif key := viper.GetString("providers.groq.apiKey"); strings.TrimSpace(key) != "" {- viper.SetDefault("agents.coder.model", models.QWENQwq)+ viper.SetDefault("agents.primary.model", models.QWENQwq)viper.SetDefault("agents.task.model", models.QWENQwq)viper.SetDefault("agents.title.model", models.QWENQwq)return@@ -270,7 +270,7 @@ func setProviderDefaults() {// OpenRouter configurationif key := viper.GetString("providers.openrouter.apiKey"); strings.TrimSpace(key) != "" {- viper.SetDefault("agents.coder.model", models.OpenRouterClaude37Sonnet)+ viper.SetDefault("agents.primary.model", models.OpenRouterClaude37Sonnet)viper.SetDefault("agents.task.model", models.OpenRouterClaude37Sonnet)viper.SetDefault("agents.title.model", models.OpenRouterClaude35Haiku)return@@ -278,7 +278,7 @@ func setProviderDefaults() {// XAI configurationif key := viper.GetString("providers.xai.apiKey"); strings.TrimSpace(key) != "" {- viper.SetDefault("agents.coder.model", models.XAIGrok3Beta)+ viper.SetDefault("agents.primary.model", models.XAIGrok3Beta)viper.SetDefault("agents.task.model", models.XAIGrok3Beta)viper.SetDefault("agents.title.model", models.XAiGrok3MiniFastBeta)return@@ -286,7 +286,7 @@ func setProviderDefaults() {// AWS Bedrock configurationif hasAWSCredentials() {- viper.SetDefault("agents.coder.model", models.BedrockClaude37Sonnet)+ viper.SetDefault("agents.primary.model", models.BedrockClaude37Sonnet)viper.SetDefault("agents.task.model", models.BedrockClaude37Sonnet)viper.SetDefault("agents.title.model", models.BedrockClaude37Sonnet)return@@ -294,7 +294,7 @@ func setProviderDefaults() {// Azure OpenAI configurationif os.Getenv("AZURE_OPENAI_ENDPOINT") != "" {- viper.SetDefault("agents.coder.model", models.AzureGPT41)+ viper.SetDefault("agents.primary.model", models.AzureGPT41)viper.SetDefault("agents.task.model", models.AzureGPT41Mini)viper.SetDefault("agents.title.model", models.AzureGPT41Mini)returndiff --git a/internal/llm/agent/agent.go b/internal/llm/agent/agent.goindex 415fce3f092..e45411df747 100644--- a/internal/llm/agent/agent.go+++ b/internal/llm/agent/agent.go@@ -74,7 +74,7 @@ func NewAgent(}var titleProvider provider.Provider// Only generate titles for the coder agent- if agentName == config.AgentCoder {+ if agentName == config.AgentPrimary {titleProvider, err = createAgentProvider(config.AgentTitle)if err != nil {return nil, err@@ -673,7 +673,7 @@ func createAgentProvider(agentName config.AgentName) (provider.Provider, error)provider.WithReasoningEffort(agentConfig.ReasoningEffort),),)- } else if model.Provider == models.ProviderAnthropic && model.CanReason && agentName == config.AgentCoder {+ } else if model.Provider == models.ProviderAnthropic && model.CanReason && agentName == config.AgentPrimary {opts = append(opts,provider.WithAnthropicOptions(diff --git a/internal/llm/agent/tools.go b/internal/llm/agent/tools.goindex b337efb594c..7a23b723b78 100644--- a/internal/llm/agent/tools.go+++ b/internal/llm/agent/tools.go@@ -11,7 +11,7 @@ import ("github.com/opencode-ai/opencode/internal/session")-func CoderAgentTools(+func PrimaryAgentTools(permissions permission.Service,sessions session.Service,messages message.Service,diff --git a/internal/llm/prompt/coder.go b/internal/llm/prompt/primary.gosimilarity index 97%rename from internal/llm/prompt/coder.gorename to internal/llm/prompt/primary.goindex 639679328fb..c67e6d7a3f8 100644--- a/internal/llm/prompt/coder.go+++ b/internal/llm/prompt/primary.go@@ -13,18 +13,18 @@ import ("github.com/opencode-ai/opencode/internal/llm/tools")-func CoderPrompt(provider models.ModelProvider) string {- basePrompt := baseAnthropicCoderPrompt+func PrimaryPrompt(provider models.ModelProvider) string {+ basePrompt := baseAnthropicPrimaryPromptswitch provider {case models.ProviderOpenAI:- basePrompt = baseOpenAICoderPrompt+ basePrompt = baseOpenAIPrimaryPrompt}envInfo := getEnvironmentInfo()return fmt.Sprintf("%s\n\n%s\n%s", basePrompt, envInfo, lspInformation())}-const baseOpenAICoderPrompt = `+const baseOpenAIPrimaryPrompt = `You are operating as and within the OpenCode CLI, a terminal-based agentic coding assistant built by OpenAI. It wraps OpenAI models to enable natural language interaction with a local codebase. You are expected to be precise, safe, and helpful.You can:@@ -71,7 +71,7 @@ You MUST adhere to the following criteria when executing the task:- Remember the user does not see the full output of tools`-const baseAnthropicCoderPrompt = `You are OpenCode, an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.+const baseAnthropicPrimaryPrompt = `You are OpenCode, an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.IMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames directory structure.diff --git a/internal/llm/prompt/prompt.go b/internal/llm/prompt/prompt.goindex 769fd51ab73..66014232003 100644--- a/internal/llm/prompt/prompt.go+++ b/internal/llm/prompt/prompt.go@@ -15,8 +15,8 @@ import (func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) string {basePrompt := ""switch agentName {- case config.AgentCoder:- basePrompt = CoderPrompt(provider)+ case config.AgentPrimary:+ basePrompt = PrimaryPrompt(provider)case config.AgentTitle:basePrompt = TitlePrompt(provider)case config.AgentTask:@@ -25,7 +25,7 @@ func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) sbasePrompt = "You are a helpful assistant"}- if agentName == config.AgentCoder || agentName == config.AgentTask {+ if agentName == config.AgentPrimary || agentName == config.AgentTask {// Add context from project-specific instruction files if they existcontextContent := getContextFromPaths()slog.Debug("Context content", "Context", contextContent)diff --git a/internal/pubsub/broker_test.go b/internal/pubsub/broker_test.goindex 1a82011fc8c..b4caa98f3d1 100644--- a/internal/pubsub/broker_test.go+++ b/internal/pubsub/broker_test.go@@ -51,12 +51,12 @@ func TestBrokerPublish(t *testing.T) {ch := broker.Subscribe(ctx)// Publish a message- broker.Publish("created", "test message")+ broker.Publish(EventTypeCreated, "test message")// Verify message is receivedselect {case event := <-ch:- assert.Equal(t, "created", event.Type)+ assert.Equal(t, EventTypeCreated, event.Type)assert.Equal(t, "test message", event.Payload)case <-time.After(100 * time.Millisecond):t.Fatal("timeout waiting for message")@@ -122,7 +122,7 @@ func TestBrokerConcurrency(t *testing.T) {// Publish messages to all subscribersfor i := range numSubscribers {- broker.Publish("created", i)+ broker.Publish(EventTypeCreated, i)}// Wait for all subscribers to finishdiff --git a/internal/tui/components/chat/editor.go b/internal/tui/components/chat/editor.goindex 99991cdf764..e96e6df3dc1 100644--- a/internal/tui/components/chat/editor.go+++ b/internal/tui/components/chat/editor.go@@ -124,7 +124,7 @@ func (m *editorCmp) Init() tea.Cmd {}func (m *editorCmp) send() tea.Cmd {- if m.app.CoderAgent.IsSessionBusy(m.session.ID) {+ if m.app.PrimaryAgent.IsSessionBusy(m.session.ID) {status.Warn("Agent is working, please wait...")return nil}@@ -189,7 +189,7 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {return m, nil}if key.Matches(msg, editorMaps.OpenEditor) {- if m.app.CoderAgent.IsSessionBusy(m.session.ID) {+ if m.app.PrimaryAgent.IsSessionBusy(m.session.ID) {status.Warn("Agent is working, please wait...")return m, nil}diff --git a/internal/tui/components/chat/list.go b/internal/tui/components/chat/list.goindex bce6f50e16e..bf72e74b5cf 100644--- a/internal/tui/components/chat/list.go+++ b/internal/tui/components/chat/list.go@@ -170,7 +170,7 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {}func (m *messagesCmp) IsAgentWorking() bool {- return m.app.CoderAgent.IsSessionBusy(m.session.ID)+ return m.app.PrimaryAgent.IsSessionBusy(m.session.ID)}func formatTimeDifference(unixTime1, unixTime2 int64) string {@@ -376,7 +376,7 @@ func (m *messagesCmp) help() string {text := ""- if m.app.CoderAgent.IsBusy() {+ if m.app.PrimaryAgent.IsBusy() {text += lipgloss.JoinHorizontal(lipgloss.Left,baseStyle.Foreground(t.TextMuted()).Bold(true).Render("press "),diff --git a/internal/tui/components/core/status.go b/internal/tui/components/core/status.goindex d6612fed4d1..be2f394321e 100644--- a/internal/tui/components/core/status.go+++ b/internal/tui/components/core/status.go@@ -140,7 +140,7 @@ func formatTokensAndCost(tokens int64, contextWindow int64, cost float64) stringfunc (m statusCmp) View() string {t := theme.CurrentTheme()- modelID := config.Get().Agents[config.AgentCoder].Model+ modelID := config.Get().Agents[config.AgentPrimary].Modelmodel := models.SupportedModels[modelID]// Initialize the help widget@@ -283,7 +283,7 @@ func (m statusCmp) model() string {cfg := config.Get()- coder, ok := cfg.Agents[config.AgentCoder]+ coder, ok := cfg.Agents[config.AgentPrimary]if !ok {return "Unknown"}diff --git a/internal/tui/components/dialog/models.go b/internal/tui/components/dialog/models.goindex 9dc2fdffe48..67c4fdfa13c 100644--- a/internal/tui/components/dialog/models.go+++ b/internal/tui/components/dialog/models.go@@ -283,7 +283,7 @@ func (m *modelDialogCmp) setupModels() {func GetSelectedModel(cfg *config.Config) models.Model {- agentCfg := cfg.Agents[config.AgentCoder]+ agentCfg := cfg.Agents[config.AgentPrimary]selectedModelId := agentCfg.Modelreturn models.SupportedModels[selectedModelId]}@@ -325,7 +325,7 @@ func findProviderIndex(providers []models.ModelProvider, provider models.ModelPrfunc (m *modelDialogCmp) setupModelsForProvider(provider models.ModelProvider) {cfg := config.Get()- agentCfg := cfg.Agents[config.AgentCoder]+ agentCfg := cfg.Agents[config.AgentPrimary]selectedModelId := agentCfg.Modelm.provider = providerdiff --git a/internal/tui/page/chat.go b/internal/tui/page/chat.goindex b4984c51102..fe71d6f7ade 100644--- a/internal/tui/page/chat.go+++ b/internal/tui/page/chat.go@@ -67,7 +67,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {}case dialog.CommandRunCustomMsg:// Check if the agent is busy before executing custom commands- if p.app.CoderAgent.IsBusy() {+ if p.app.PrimaryAgent.IsBusy() {status.Warn("Agent is busy, please wait before executing a command...")return p, nil}@@ -92,7 +92,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {// Run compaction in backgroundgo func(sessionID string) {- err := p.app.CoderAgent.CompactSession(context.Background(), sessionID)+ err := p.app.PrimaryAgent.CompactSession(context.Background(), sessionID)if err != nil {status.Error(fmt.Sprintf("Compaction failed: %v", err))} else {@@ -113,7 +113,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {if p.session.ID != "" {// Cancel the current session's generation process// This allows users to interrupt long-running operations- p.app.CoderAgent.Cancel(p.session.ID)+ p.app.PrimaryAgent.Cancel(p.session.ID)return p, nil}case key.Matches(msg, keyMap.ToggleTools):@@ -158,7 +158,7 @@ func (p *chatPage) sendMessage(text string, attachments []message.Attachment) tecmds = append(cmds, util.CmdHandler(chat.SessionSelectedMsg(newSession)))}- _, err := p.app.CoderAgent.Run(context.Background(), p.session.ID, text, attachments...)+ _, err := p.app.PrimaryAgent.Run(context.Background(), p.session.ID, text, attachments...)if err != nil {status.Error(err.Error())return nildiff --git a/internal/tui/tui.go b/internal/tui/tui.goindex 84fbcfdea2e..a0430faf70a 100644--- a/internal/tui/tui.go+++ b/internal/tui/tui.go@@ -266,7 +266,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {case dialog.ModelSelectedMsg:a.showModelDialog = false- model, err := a.app.CoderAgent.Update(config.AgentCoder, msg.Model.ID)+ model, err := a.app.PrimaryAgent.Update(config.AgentPrimary, msg.Model.ID)if err != nil {status.Error(err.Error())return a, nil@@ -460,7 +460,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {a.showHelp = !a.showHelpreturn a, nilcase key.Matches(msg, helpEsc):- if a.app.CoderAgent.IsBusy() {+ if a.app.PrimaryAgent.IsBusy() {if a.showQuit {return a, nil}@@ -574,7 +574,7 @@ func (a *appModel) RegisterCommand(cmd dialog.Command) {func (a *appModel) moveToPage(pageID page.PageID) tea.Cmd {// Allow navigating to logs page even when agent is busy- if a.app.CoderAgent.IsBusy() && pageID != page.LogsPage {+ if a.app.PrimaryAgent.IsBusy() && pageID != page.LogsPage {// Don't move to other pages if the agent is busystatus.Warn("Agent is busy, please wait...")return nil@@ -641,7 +641,7 @@ func (a appModel) View() string {}- if !a.app.CoderAgent.IsBusy() {+ if !a.app.PrimaryAgent.IsBusy() {a.status.SetHelpWidgetMsg("ctrl+? help")} else {a.status.SetHelpWidgetMsg("? help")@@ -658,7 +658,7 @@ func (a appModel) View() string {if a.currentPage == page.LogsPage {bindings = append(bindings, logsKeyReturnKey)}- if !a.app.CoderAgent.IsBusy() {+ if !a.app.PrimaryAgent.IsBusy() {bindings = append(bindings, helpEsc)}a.help.SetBindings(bindings)diff --git a/opencode-schema.json b/opencode-schema.jsonindex e9665eab5e1..d6af65cf09b 100644--- a/opencode-schema.json+++ b/opencode-schema.json@@ -179,7 +179,7 @@},"description": "Agent configurations","properties": {- "coder": {+ "primary": {"$ref": "#/definitions/agent"},"task": {