From 58b01d5f84ba9ad61f5f897960f89d1754e9b7d9 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 26 Nov 2025 10:47:43 +0100 Subject: [PATCH] Simplify BytesSource Signed-off-by: David Gageot --- cmd/root/run.go | 2 +- pkg/creator/agent.go | 2 +- pkg/server/server.go | 2 +- pkg/teamloader/sources.go | 14 ++++---------- pkg/teamloader/teamloader.go | 5 ++++- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/cmd/root/run.go b/cmd/root/run.go index 65cfc0582..ca3d84886 100644 --- a/cmd/root/run.go +++ b/cmd/root/run.go @@ -103,7 +103,7 @@ func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []s var source teamloader.AgentSource if agentFileName == "default" { - source = teamloader.NewBytesSource(f.runConfig.WorkingDir, defaultAgent) + source = teamloader.NewBytesSource(defaultAgent) } else { source = teamloader.NewFileSource(agentFileName) } diff --git a/pkg/creator/agent.go b/pkg/creator/agent.go index 919f73780..fb0643b0d 100644 --- a/pkg/creator/agent.go +++ b/pkg/creator/agent.go @@ -180,7 +180,7 @@ Can you explain to me what the agent will be used for?`, return teamloader.LoadFrom( ctx, - teamloader.NewBytesSource(runConfig.WorkingDir, configAsJSON), + teamloader.NewBytesSource(configAsJSON), runConfig, teamloader.WithModelOverrides([]string{modelNameOverride}), teamloader.WithToolsetRegistry(registry), diff --git a/pkg/server/server.go b/pkg/server/server.go index 9e9bb4f53..f1348b024 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -1325,7 +1325,7 @@ func (s *Server) loadTeamForSession(ctx context.Context, agentFilename string, s reloaded, err := teamloader.LoadFrom( ctx, - teamloader.NewBytesSource(sess.WorkingDir, []byte(yamlContent)), + teamloader.NewBytesSource([]byte(yamlContent)), rc, teamloader.WithID(agentFilename), ) diff --git a/pkg/teamloader/sources.go b/pkg/teamloader/sources.go index d1e4057d2..0a68ae5bf 100644 --- a/pkg/teamloader/sources.go +++ b/pkg/teamloader/sources.go @@ -49,18 +49,12 @@ func (a fileSource) Read() ([]byte, error) { // bytesSource is used to load an agent configuration from a []byte. type bytesSource struct { - workingDir string - data []byte + data []byte } -func NewBytesSource(workingDir string, data []byte) AgentSource { - // TODO(dga): this is not perfect but ok for now - if workingDir == "" { - workingDir = "." - } +func NewBytesSource(data []byte) AgentSource { return bytesSource{ - workingDir: workingDir, - data: data, + data: data, } } @@ -69,7 +63,7 @@ func (a bytesSource) Name() string { } func (a bytesSource) ParentDir() string { - return a.workingDir + return "" } func (a bytesSource) Read() ([]byte, error) { diff --git a/pkg/teamloader/teamloader.go b/pkg/teamloader/teamloader.go index 93b0c1783..05a8f0f00 100644 --- a/pkg/teamloader/teamloader.go +++ b/pkg/teamloader/teamloader.go @@ -123,8 +123,11 @@ func LoadFrom(ctx context.Context, source AgentSource, runtimeConfig *config.Run } fileName := source.Name() - parentDir := source.ParentDir() env := runtimeConfig.EnvProvider() + parentDir := source.ParentDir() + if parentDir == "" { + parentDir = runtimeConfig.WorkingDir + } // Load the agent's configuration data, err := source.Read()