Skip to content

Commit 1a928c4

Browse files
authored
Merge pull request #194 from dgageot/cagent-exec-prompt
Allow passing a prompt to `cagent exec`
2 parents 6fd3ec1 + dca51a1 commit 1a928c4

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

cmd/root/exec.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ func NewExecCmd() *cobra.Command {
66
cmd := &cobra.Command{
77
Use: "exec <agent-name>",
88
Short: "Execute an agent",
9-
Args: cobra.ExactArgs(1),
10-
RunE: func(cmd *cobra.Command, args []string) error {
11-
return runCommand(cmd, args, true)
12-
},
9+
Args: cobra.RangeArgs(1, 2),
10+
RunE: execCommand,
1311
}
1412

1513
cmd.PersistentFlags().StringVarP(&agentName, "agent", "a", "root", "Name of the agent to run")

cmd/root/run.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ func NewRunCmd() *cobra.Command {
5151
cagent run ./echo.yaml "INSTRUCTIONS"
5252
echo "INSTRUCTIONS" | cagent run ./echo.yaml -`,
5353
Args: cobra.RangeArgs(1, 2),
54-
RunE: func(cmd *cobra.Command, args []string) error {
55-
return runCommand(cmd, args, false)
56-
},
54+
RunE: runCommand,
5755
}
5856

5957
cmd.PersistentFlags().StringVarP(&agentName, "agent", "a", "root", "Name of the agent to run")
@@ -79,12 +77,17 @@ func NewTuiCmd() *cobra.Command {
7977
}
8078
}
8179

82-
func runCommand(_ *cobra.Command, args []string, exec bool) error {
83-
// Track the run command
80+
func runCommand(cmd *cobra.Command, args []string) error {
8481
telemetry.TrackCommand("run", args)
82+
return doRunCommand(cmd.Context(), args, false)
83+
}
8584

86-
ctx := context.Background()
85+
func execCommand(cmd *cobra.Command, args []string) error {
86+
telemetry.TrackCommand("exec", args)
87+
return doRunCommand(cmd.Context(), args, true)
88+
}
8789

90+
func doRunCommand(ctx context.Context, args []string, exec bool) error {
8891
slog.Debug("Starting agent", "agent", agentName, "debug_mode", debugMode)
8992

9093
agentFilename := args[0]
@@ -195,7 +198,13 @@ func runCommand(_ *cobra.Command, args []string, exec bool) error {
195198

196199
// For `cagent exec`
197200
if exec {
198-
return runWithoutTUI(ctx, agentFilename, rt, sess, []string{"exec", "Follow the default instructions"})
201+
execArgs := []string{"exec"}
202+
if len(args) == 2 {
203+
execArgs = append(execArgs, args[1])
204+
} else {
205+
execArgs = append(execArgs, "Follow the default instructions")
206+
}
207+
return runWithoutTUI(ctx, agentFilename, rt, sess, execArgs)
199208
}
200209

201210
// For `cagent run --tui=false`

0 commit comments

Comments
 (0)