@@ -51,9 +51,7 @@ func NewRunCmd() *cobra.Command {
51
51
cagent run ./echo.yaml "INSTRUCTIONS"
52
52
echo "INSTRUCTIONS" | cagent run ./echo.yaml -` ,
53
53
Args : cobra .RangeArgs (1 , 2 ),
54
- RunE : func (cmd * cobra.Command , args []string ) error {
55
- return runCommand (cmd , args , false )
56
- },
54
+ RunE : runCommand ,
57
55
}
58
56
59
57
cmd .PersistentFlags ().StringVarP (& agentName , "agent" , "a" , "root" , "Name of the agent to run" )
@@ -79,12 +77,17 @@ func NewTuiCmd() *cobra.Command {
79
77
}
80
78
}
81
79
82
- func runCommand (_ * cobra.Command , args []string , exec bool ) error {
83
- // Track the run command
80
+ func runCommand (cmd * cobra.Command , args []string ) error {
84
81
telemetry .TrackCommand ("run" , args )
82
+ return doRunCommand (cmd .Context (), args , false )
83
+ }
85
84
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
+ }
87
89
90
+ func doRunCommand (ctx context.Context , args []string , exec bool ) error {
88
91
slog .Debug ("Starting agent" , "agent" , agentName , "debug_mode" , debugMode )
89
92
90
93
agentFilename := args [0 ]
@@ -195,7 +198,13 @@ func runCommand(_ *cobra.Command, args []string, exec bool) error {
195
198
196
199
// For `cagent exec`
197
200
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 )
199
208
}
200
209
201
210
// For `cagent run --tui=false`
0 commit comments