@@ -15,6 +15,7 @@ limitations under the License.
1515package cmd
1616
1717import (
18+ "context"
1819 "fmt"
1920 "os"
2021
@@ -32,12 +33,24 @@ var (
3233 date = "unknown"
3334)
3435
36+ var (
37+ instructions string
38+ outputPath string
39+ )
40+
3541// rootCmd represents the base command when called without any subcommands
3642var rootCmd = & cobra.Command {
3743 Use : "arlocode" ,
3844 Short : "ArloCode a Coding Agent focused on long running tasks and local models" ,
39- Long : `AlroCode is an AI coding agent designed to assist developers with complex coding tasks.` ,
45+ Long : `ArloCode is an AI coding agent designed to assist developers with complex coding tasks.` ,
4046 Run : func (cmd * cobra.Command , args []string ) {
47+ if instructions != "" {
48+ if err := runHeadless (instructions , outputPath ); err != nil {
49+ os .Exit (1 )
50+ }
51+ return
52+ }
53+
4154 codingAgent := coding_agent .Agent
4255 agentBridge := bridge .NewDirectBridge (codingAgent )
4356
@@ -87,7 +100,45 @@ func init() {
87100 // Cobra supports persistent flags, which, if defined here,
88101 // will be global for your application.
89102
103+ rootCmd .Flags ().StringVarP (& instructions , "instructions" , "i" , "" , "Run in headless mode with the provided instruction text" )
104+ rootCmd .Flags ().StringVarP (& outputPath , "output" , "o" , "" , "Path to write the ATIF trajectory JSON" )
105+
90106 // Set version template for --version flag
91107 rootCmd .Version = version
92108 rootCmd .SetVersionTemplate (fmt .Sprintf ("arlocode %s (commit: %s, built: %s)\n " , version , commit , date ))
93109}
110+
111+ func runHeadless (prompt string , path string ) error {
112+ codingAgent := coding_agent .Agent .WithMaxIterations (500 )
113+ agentBridge := bridge .NewDirectBridge (codingAgent )
114+ defer agentBridge .Close ()
115+
116+ if err := agentBridge .Run (context .Background (), prompt ); err != nil {
117+ return err
118+ }
119+
120+ var runErr error
121+ for {
122+ event , ok := <- agentBridge .Events ()
123+ if ! ok {
124+ break
125+ }
126+ switch e := event .(type ) {
127+ case bridge.ErrorEvent :
128+ if e .Err != nil {
129+ runErr = e .Err
130+ }
131+ case bridge.TurnCompleteEvent :
132+ _ , err := agentBridge .ExportATIF (path )
133+ if err != nil {
134+ return err
135+ }
136+ if runErr != nil {
137+ return runErr
138+ }
139+ return nil
140+ }
141+ }
142+
143+ return runErr
144+ }
0 commit comments