From e78a6cc086dae3d13e538a8c7e5742889dfd5ca5 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 26 Sep 2025 15:07:39 +0200 Subject: [PATCH] Print canonical configuration Let's hide it for now until it's finished. Signed-off-by: David Gageot --- cmd/root/print.go | 46 +++++++++++++++++++++++++++++++++++++ cmd/root/root.go | 1 + pkg/runtime/runtime_test.go | 3 ++- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 cmd/root/print.go diff --git a/cmd/root/print.go b/cmd/root/print.go new file mode 100644 index 000000000..e4efd2175 --- /dev/null +++ b/cmd/root/print.go @@ -0,0 +1,46 @@ +package root + +import ( + "fmt" + "path/filepath" + "strings" + + "github.com/goccy/go-yaml" + "github.com/spf13/cobra" + + "github.com/docker/cagent/pkg/config" + "github.com/docker/cagent/pkg/telemetry" +) + +func NewPrintCmd() *cobra.Command { + return &cobra.Command{ + Use: "print ", + Short: "Print the canonical configuration of an agent", + Args: cobra.ExactArgs(1), + RunE: printCommand, + Hidden: true, + } +} + +func printCommand(cmd *cobra.Command, args []string) error { + telemetry.TrackCommand("print", args) + + agentFilename := args[0] + + ext := strings.ToLower(filepath.Ext(agentFilename)) + if ext == ".yaml" || ext == ".yml" || strings.HasPrefix(agentFilename, "/dev/fd/") { + cfg, err := config.LoadConfigSecure(filepath.Base(agentFilename), filepath.Dir(agentFilename)) + if err != nil { + return err + } + + buf, err := yaml.Marshal(cfg) + if err != nil { + return err + } + + fmt.Println(string(buf)) + } + + return nil +} diff --git a/cmd/root/root.go b/cmd/root/root.go index b0b1c4c17..c2e169380 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -107,6 +107,7 @@ func NewRootCmd() *cobra.Command { cmd.AddCommand(NewFeedbackCmd()) cmd.AddCommand(NewCatalogCmd()) cmd.AddCommand(NewBuildCmd()) + cmd.AddCommand(NewPrintCmd()) return cmd } diff --git a/pkg/runtime/runtime_test.go b/pkg/runtime/runtime_test.go index d447cda14..999e196ad 100644 --- a/pkg/runtime/runtime_test.go +++ b/pkg/runtime/runtime_test.go @@ -7,13 +7,14 @@ import ( "reflect" "testing" + "github.com/stretchr/testify/require" + "github.com/docker/cagent/pkg/agent" "github.com/docker/cagent/pkg/chat" "github.com/docker/cagent/pkg/modelsdev" "github.com/docker/cagent/pkg/session" "github.com/docker/cagent/pkg/team" "github.com/docker/cagent/pkg/tools" - "github.com/stretchr/testify/require" ) type mockStream struct {