Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
!./**/*.css
!./**/*.go
!./**/*.txt
!/pkg/config/default-agent.yaml
!/pkg/config/coder-agent.yaml
!/pkg/config/builtin-agents/*.yaml
!/pkg/tui/styles/themes/*.yaml
5 changes: 3 additions & 2 deletions cmd/root/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/docker/cagent/pkg/teamloader"
"github.com/docker/cagent/pkg/telemetry"
"github.com/docker/cagent/pkg/tui/styles"
"github.com/docker/cagent/pkg/userconfig"
)

type runExecFlags struct {
Expand Down Expand Up @@ -160,7 +161,7 @@ func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []s

// Apply global user settings first (lowest priority)
// User settings only apply if the flag wasn't explicitly set by the user
userSettings := config.GetUserSettings()
userSettings := userconfig.Get()
if userSettings.HideToolResults && !f.hideToolResults {
f.hideToolResults = true
slog.Debug("Applying user settings", "hide_tool_results", true)
Expand Down Expand Up @@ -493,7 +494,7 @@ func (f *runExecFlags) handleRunMode(ctx context.Context, rt runtime.Runtime, se
func applyTheme() {
// Resolve theme from user config > built-in default
themeRef := styles.DefaultThemeRef
if userSettings := config.GetUserSettings(); userSettings.Theme != "" {
if userSettings := userconfig.Get(); userSettings.Theme != "" {
themeRef = userSettings.Theme
}

Expand Down
File renamed without changes.
16 changes: 4 additions & 12 deletions pkg/config/commands_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package config

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestV2Commands_AllForms(t *testing.T) {
cfg, err := Load(t.Context(), testfileSource("testdata/commands_v2.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/commands_v2.yaml"))
require.NoError(t, err)

// Test simple map format
Expand Down Expand Up @@ -40,7 +38,7 @@ func TestV2Commands_AllForms(t *testing.T) {
}

func TestV2Commands_DisplayText(t *testing.T) {
cfg, err := Load(t.Context(), testfileSource("testdata/commands_v2.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/commands_v2.yaml"))
require.NoError(t, err)

// Simple format: DisplayText returns the instruction
Expand All @@ -53,7 +51,7 @@ func TestV2Commands_DisplayText(t *testing.T) {
}

func TestMigrate_v1_Commands_AllForms(t *testing.T) {
cfg, err := Load(t.Context(), testfileSource("testdata/commands_v1.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/commands_v1.yaml"))
require.NoError(t, err)

require.Equal(t, "root", cfg.Agents[0].Name)
Expand All @@ -71,7 +69,7 @@ func TestMigrate_v1_Commands_AllForms(t *testing.T) {
}

func TestMigrate_v0_Commands_AllForms(t *testing.T) {
cfg, err := Load(t.Context(), testfileSource("testdata/commands_v0.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/commands_v0.yaml"))
require.NoError(t, err)

require.Equal(t, "root", cfg.Agents[0].Name)
Expand All @@ -87,9 +85,3 @@ func TestMigrate_v0_Commands_AllForms(t *testing.T) {
require.Equal(t, "yet_another_agent", cfg.Agents[2].Name)
require.Empty(t, cfg.Agents[2].Commands)
}

type testfileSource string

func (s testfileSource) Read(context.Context) ([]byte, error) {
return os.ReadFile(string(s))
}
6 changes: 1 addition & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ import (
"github.com/docker/cagent/pkg/environment"
)

type Reader interface {
Read(ctx context.Context) ([]byte, error)
}

func Load(ctx context.Context, source Reader) (*latest.Config, error) {
func Load(ctx context.Context, source Source) (*latest.Config, error) {
data, err := source.Read(ctx)
if err != nil {
return nil, err
Expand Down
34 changes: 17 additions & 17 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestAutoRegisterModels(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/autoregister.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/autoregister.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Models, 2)
Expand All @@ -28,7 +28,7 @@ func TestAutoRegisterModels(t *testing.T) {
func TestAutoRegisterAlloy(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/autoregister_alloy.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/autoregister_alloy.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Models, 2)
Expand All @@ -41,7 +41,7 @@ func TestAutoRegisterAlloy(t *testing.T) {
func TestAlloyModelComposition(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/alloy_model_composition.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/alloy_model_composition.yaml"))
require.NoError(t, err)

// The alloy model should be expanded to its constituent models
Expand All @@ -57,7 +57,7 @@ func TestAlloyModelComposition(t *testing.T) {
func TestAlloyModelNestedComposition(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/alloy_model_nested.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/alloy_model_nested.yaml"))
require.NoError(t, err)

// The nested alloy should be fully expanded to all constituent models
Expand All @@ -72,7 +72,7 @@ func TestAlloyModelNestedComposition(t *testing.T) {
func TestMigrate_v0_v1_provider(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/provider_v0.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/provider_v0.yaml"))
require.NoError(t, err)

assert.Equal(t, "openai", cfg.Models["gpt"].Provider)
Expand All @@ -81,7 +81,7 @@ func TestMigrate_v0_v1_provider(t *testing.T) {
func TestMigrate_v1_provider(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/provider_v1.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/provider_v1.yaml"))
require.NoError(t, err)

assert.Equal(t, "openai", cfg.Models["gpt"].Provider)
Expand All @@ -90,7 +90,7 @@ func TestMigrate_v1_provider(t *testing.T) {
func TestMigrate_v0_v1_todo(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/todo_v0.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/todo_v0.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Agents.First().Toolsets, 2)
Expand All @@ -102,7 +102,7 @@ func TestMigrate_v0_v1_todo(t *testing.T) {
func TestMigrate_v1_todo(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/todo_v1.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/todo_v1.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Agents.First().Toolsets, 2)
Expand All @@ -114,7 +114,7 @@ func TestMigrate_v1_todo(t *testing.T) {
func TestMigrate_v0_v1_shared_todo(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/shared_todo_v0.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/shared_todo_v0.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Agents.First().Toolsets, 2)
Expand All @@ -126,7 +126,7 @@ func TestMigrate_v0_v1_shared_todo(t *testing.T) {
func TestMigrate_v1_shared_todo(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/shared_todo_v1.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/shared_todo_v1.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Agents.First().Toolsets, 2)
Expand All @@ -138,7 +138,7 @@ func TestMigrate_v1_shared_todo(t *testing.T) {
func TestMigrate_v0_v1_think(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/think_v0.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/think_v0.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Agents.First().Toolsets, 2)
Expand All @@ -149,7 +149,7 @@ func TestMigrate_v0_v1_think(t *testing.T) {
func TestMigrate_v1_think(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/think_v1.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/think_v1.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Agents.First().Toolsets, 2)
Expand All @@ -160,7 +160,7 @@ func TestMigrate_v1_think(t *testing.T) {
func TestMigrate_v0_v1_memory(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/memory_v0.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/memory_v0.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Agents.First().Toolsets, 2)
Expand All @@ -172,7 +172,7 @@ func TestMigrate_v0_v1_memory(t *testing.T) {
func TestMigrate_v1_memory(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/memory_v1.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/memory_v1.yaml"))
require.NoError(t, err)

assert.Len(t, cfg.Agents.First().Toolsets, 2)
Expand All @@ -184,7 +184,7 @@ func TestMigrate_v1_memory(t *testing.T) {
func TestMigrate_v1(t *testing.T) {
t.Parallel()

_, err := Load(t.Context(), testfileSource("testdata/v1.yaml"))
_, err := Load(t.Context(), NewFileSource("testdata/v1.yaml"))
require.NoError(t, err)
}

Expand Down Expand Up @@ -262,7 +262,7 @@ func TestCheckRequiredEnvVars(t *testing.T) {
t.Run(test.yaml, func(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/env/"+test.yaml))
cfg, err := Load(t.Context(), NewFileSource("testdata/env/"+test.yaml))
require.NoError(t, err)

err = CheckRequiredEnvVars(t.Context(), cfg, "", &noEnvProvider{})
Expand All @@ -282,7 +282,7 @@ func TestCheckRequiredEnvVars(t *testing.T) {
func TestCheckRequiredEnvVarsWithModelGateway(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource("testdata/env/all.yaml"))
cfg, err := Load(t.Context(), NewFileSource("testdata/env/all.yaml"))
require.NoError(t, err)

err = CheckRequiredEnvVars(t.Context(), cfg, "gateway:8080", &noEnvProvider{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestParseExamples(t *testing.T) {
t.Run(file, func(t *testing.T) {
t.Parallel()

cfg, err := Load(t.Context(), testfileSource(file))
cfg, err := Load(t.Context(), NewFileSource(file))

require.NoError(t, err)
require.Equal(t, latest.Version, cfg.Version, "Version should be %d in %s", latest.Version, file)
Expand Down
Loading