|
| 1 | +package root |
| 2 | + |
| 3 | +import ( |
| 4 | + "log/slog" |
| 5 | + "os" |
| 6 | + |
| 7 | + acpsdk "github.com/coder/acp-go-sdk" |
| 8 | + "github.com/spf13/cobra" |
| 9 | + |
| 10 | + "github.com/docker/cagent/pkg/acp" |
| 11 | + "github.com/docker/cagent/pkg/telemetry" |
| 12 | +) |
| 13 | + |
| 14 | +// NewACPCmd creates a new acp command |
| 15 | +func NewACPCmd() *cobra.Command { |
| 16 | + cmd := &cobra.Command{ |
| 17 | + Use: "acp <agent-file>", |
| 18 | + Short: "Start an ACP (Agent Client Protocol) server", |
| 19 | + Long: `Start an ACP server that exposes the agent via the Agent Client Protocol`, |
| 20 | + Args: cobra.ExactArgs(1), |
| 21 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 22 | + telemetry.TrackCommand("acp", args) |
| 23 | + return runACP(cmd, args) |
| 24 | + }, |
| 25 | + } |
| 26 | + |
| 27 | + addGatewayFlags(cmd) |
| 28 | + addRuntimeConfigFlags(cmd) |
| 29 | + |
| 30 | + return cmd |
| 31 | +} |
| 32 | + |
| 33 | +func runACP(cmd *cobra.Command, args []string) error { |
| 34 | + ctx := cmd.Context() |
| 35 | + agentFilename := args[0] |
| 36 | + |
| 37 | + slog.Debug("Starting ACP server", "agent_file", agentFilename, "debug_mode", debugMode) |
| 38 | + |
| 39 | + acpAgent := acp.NewAgent(agentFilename, runConfig) |
| 40 | + conn := acpsdk.NewAgentSideConnection(acpAgent, os.Stdout, os.Stdin) |
| 41 | + conn.SetLogger(slog.Default()) |
| 42 | + acpAgent.SetAgentConnection(conn) |
| 43 | + defer acpAgent.Stop(ctx) |
| 44 | + |
| 45 | + slog.Debug("acp started, waiting for conn") |
| 46 | + |
| 47 | + <-conn.Done() |
| 48 | + |
| 49 | + return nil |
| 50 | +} |
0 commit comments