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
46 changes: 46 additions & 0 deletions cmd/root/print.go
Original file line number Diff line number Diff line change
@@ -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 <agent-name>",
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
}
1 change: 1 addition & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func NewRootCmd() *cobra.Command {
cmd.AddCommand(NewFeedbackCmd())
cmd.AddCommand(NewCatalogCmd())
cmd.AddCommand(NewBuildCmd())
cmd.AddCommand(NewPrintCmd())

return cmd
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading