@@ -35,39 +35,39 @@ func runInit(cmd *cobra.Command, args []string) error {
3535 fmt .Println ("=====================================" )
3636 fmt .Println ()
3737
38- // Project name
3938 var projectName string
4039 if len (args ) > 0 {
4140 projectName = args [0 ]
4241 } else {
4342 projectName = promptString (scanner , "Project name" , "my-agent" )
4443 }
4544
46- // Create project directory
4745 projectDir := filepath .Join ("." , projectName )
4846 if err := os .MkdirAll (projectDir , 0755 ); err != nil {
4947 return fmt .Errorf ("failed to create project directory: %w" , err )
5048 }
5149
52- // Collect information interactively
5350 adl := collectADLInfo (scanner , projectName )
5451
55- // Write ADL file
5652 adlFile := filepath .Join (projectDir , "agent.yaml" )
5753 if err := writeADLFile (adl , adlFile ); err != nil {
5854 return fmt .Errorf ("failed to write ADL file: %w" , err )
5955 }
6056
6157 fmt .Printf ("\n ✅ ADL file created: %s\n " , adlFile )
6258
63- // Generate project
6459 fmt .Println ("🔨 Generating project structure..." )
65-
66- // Use the generate command to create the project
67- generateCmd .Flags ().Set ("file" , adlFile )
68- generateCmd .Flags ().Set ("output" , projectDir )
69- generateCmd .Flags ().Set ("template" , adl .getTemplate ())
70-
60+
61+ if err := generateCmd .Flags ().Set ("file" , adlFile ); err != nil {
62+ return fmt .Errorf ("failed to set file flag: %w" , err )
63+ }
64+ if err := generateCmd .Flags ().Set ("output" , projectDir ); err != nil {
65+ return fmt .Errorf ("failed to set output flag: %w" , err )
66+ }
67+ if err := generateCmd .Flags ().Set ("template" , adl .getTemplate ()); err != nil {
68+ return fmt .Errorf ("failed to set template flag: %w" , err )
69+ }
70+
7171 if err := runGenerate (generateCmd , []string {}); err != nil {
7272 return fmt .Errorf ("failed to generate project: %w" , err )
7373 }
@@ -95,9 +95,9 @@ type adlData struct {
9595 } `yaml:"metadata"`
9696 Spec struct {
9797 Capabilities * struct {
98- Streaming bool `yaml:"streaming"`
99- PushNotifications bool `yaml:"pushNotifications"`
100- StateTransitionHistory bool `yaml:"stateTransitionHistory"`
98+ Streaming bool `yaml:"streaming"`
99+ PushNotifications bool `yaml:"pushNotifications"`
100+ StateTransitionHistory bool `yaml:"stateTransitionHistory"`
101101 } `yaml:"capabilities,omitempty"`
102102 Agent * struct {
103103 Provider string `yaml:"provider"`
@@ -112,13 +112,15 @@ type adlData struct {
112112 Schema map [string ]interface {} `yaml:"schema"`
113113 } `yaml:"tools,omitempty"`
114114 Server struct {
115- Port int `yaml:"port"`
115+ Port int `yaml:"port"`
116116 Debug bool `yaml:"debug"`
117117 } `yaml:"server"`
118- Go struct {
119- Module string `yaml:"module"`
120- GoVersion string `yaml:"goVersion"`
121- } `yaml:"go"`
118+ Language * struct {
119+ Go * struct {
120+ Module string `yaml:"module"`
121+ Version string `yaml:"version"`
122+ } `yaml:"go,omitempty"`
123+ } `yaml:"language,omitempty"`
122124 } `yaml:"spec"`
123125}
124126
@@ -142,16 +144,14 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
142144 adl .Metadata .Description = promptString (scanner , "Agent description" , "A helpful AI agent" )
143145 adl .Metadata .Version = promptString (scanner , "Version" , "1.0.0" )
144146
145- // Agent type
146147 fmt .Println ("\n 🤖 Agent Type" )
147148 fmt .Println ("--------------" )
148149 agentType := promptChoice (scanner , "Agent type" , []string {"ai-powered" , "minimal" }, "ai-powered" )
149150
150151 if agentType == "ai-powered" {
151- // AI configuration
152152 fmt .Println ("\n 🧠 AI Configuration" )
153153 fmt .Println ("-------------------" )
154-
154+
155155 adl .Spec .Agent = & struct {
156156 Provider string `yaml:"provider"`
157157 Model string `yaml:"model"`
@@ -176,39 +176,45 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
176176 }
177177
178178 adl .Spec .Agent .Model = promptString (scanner , "Model" , defaultModel )
179- adl .Spec .Agent .SystemPrompt = promptString (scanner , "System prompt (optional)" , "" )
180-
179+
180+ for {
181+ systemPrompt := promptString (scanner , "System prompt" , "You are a helpful AI assistant." )
182+ if systemPrompt != "" {
183+ adl .Spec .Agent .SystemPrompt = systemPrompt
184+ break
185+ }
186+ fmt .Println ("⚠️ System prompt is required for AI-powered agents. Please provide a system prompt." )
187+ }
188+
181189 if maxTokensStr := promptString (scanner , "Max tokens (optional, press enter to skip)" , "" ); maxTokensStr != "" {
182190 if maxTokens , err := strconv .Atoi (maxTokensStr ); err == nil {
183191 adl .Spec .Agent .MaxTokens = maxTokens
184192 }
185193 }
186-
194+
187195 if tempStr := promptString (scanner , "Temperature (0.0-2.0, optional)" , "" ); tempStr != "" {
188196 if temp , err := strconv .ParseFloat (tempStr , 64 ); err == nil {
189197 adl .Spec .Agent .Temperature = temp
190198 }
191199 }
192200 }
193201
194- // Capabilities
195202 fmt .Println ("\n ⚡ Capabilities" )
196203 fmt .Println ("---------------" )
197204 adl .Spec .Capabilities = & struct {
198- Streaming bool `yaml:"streaming"`
199- PushNotifications bool `yaml:"pushNotifications"`
200- StateTransitionHistory bool `yaml:"stateTransitionHistory"`
205+ Streaming bool `yaml:"streaming"`
206+ PushNotifications bool `yaml:"pushNotifications"`
207+ StateTransitionHistory bool `yaml:"stateTransitionHistory"`
201208 }{}
202209
203210 adl .Spec .Capabilities .Streaming = promptBool (scanner , "Enable streaming" , true )
204211 adl .Spec .Capabilities .PushNotifications = promptBool (scanner , "Enable push notifications" , false )
205212 adl .Spec .Capabilities .StateTransitionHistory = promptBool (scanner , "Enable state transition history" , false )
206213
207- // Tools
208214 fmt .Println ("\n 🔧 Tools" )
209215 fmt .Println ("--------" )
210- addTools := promptBool (scanner , "Add tools to your agent" , true )
211-
216+ addTools := promptBool (scanner , "Add tools to your agent" , false )
217+
212218 if addTools {
213219 for {
214220 tool := struct {
@@ -221,10 +227,9 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
221227 if tool .Name == "" {
222228 break
223229 }
224-
230+
225231 tool .Description = promptString (scanner , "Tool description" , "" )
226-
227- // Simple schema for now
232+
228233 tool .Schema = map [string ]interface {}{
229234 "type" : "object" ,
230235 "properties" : map [string ]interface {}{
@@ -244,7 +249,6 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
244249 }
245250 }
246251
247- // Server configuration
248252 fmt .Println ("\n 🌐 Server Configuration" )
249253 fmt .Println ("-----------------------" )
250254 portStr := promptString (scanner , "Server port" , "8080" )
@@ -255,11 +259,23 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
255259 }
256260 adl .Spec .Server .Debug = promptBool (scanner , "Enable debug mode" , false )
257261
258- // Go configuration
259262 fmt .Println ("\n 🐹 Go Configuration" )
260263 fmt .Println ("-------------------" )
261- adl .Spec .Go .Module = promptString (scanner , "Go module" , fmt .Sprintf ("github.com/example/%s" , adl .Metadata .Name ))
262- adl .Spec .Go .GoVersion = promptString (scanner , "Go version" , "1.21" )
264+
265+ adl .Spec .Language = & struct {
266+ Go * struct {
267+ Module string `yaml:"module"`
268+ Version string `yaml:"version"`
269+ } `yaml:"go,omitempty"`
270+ }{}
271+
272+ adl .Spec .Language .Go = & struct {
273+ Module string `yaml:"module"`
274+ Version string `yaml:"version"`
275+ }{}
276+
277+ adl .Spec .Language .Go .Module = promptString (scanner , "Go module" , fmt .Sprintf ("github.com/example/%s" , adl .Metadata .Name ))
278+ adl .Spec .Language .Go .Version = promptString (scanner , "Go version" , "1.24" )
263279
264280 return adl
265281}
@@ -270,10 +286,10 @@ func promptString(scanner *bufio.Scanner, prompt, defaultValue string) string {
270286 } else {
271287 fmt .Printf ("%s: " , prompt )
272288 }
273-
289+
274290 scanner .Scan ()
275291 input := strings .TrimSpace (scanner .Text ())
276-
292+
277293 if input == "" {
278294 return defaultValue
279295 }
@@ -285,42 +301,49 @@ func promptBool(scanner *bufio.Scanner, prompt string, defaultValue bool) bool {
285301 if defaultValue {
286302 defaultStr = "y"
287303 }
288-
289- fmt .Printf ("%s [%s /n]: " , prompt , defaultStr )
304+
305+ fmt .Printf ("%s [y /n] (default: %s) : " , prompt , defaultStr )
290306 scanner .Scan ()
291307 input := strings .ToLower (strings .TrimSpace (scanner .Text ()))
292-
308+
293309 if input == "" {
294310 return defaultValue
295311 }
296-
312+
297313 return input == "y" || input == "yes"
298314}
299315
300316func promptChoice (scanner * bufio.Scanner , prompt string , choices []string , defaultValue string ) string {
301317 fmt .Printf ("%s (%s) [%s]: " , prompt , strings .Join (choices , "/" ), defaultValue )
302318 scanner .Scan ()
303319 input := strings .TrimSpace (scanner .Text ())
304-
320+
305321 if input == "" {
306322 return defaultValue
307323 }
308-
309- // Validate choice
324+
310325 for _ , choice := range choices {
311326 if input == choice {
312327 return input
313328 }
314329 }
315-
330+
316331 return defaultValue
317332}
318333
319334func writeADLFile (adl * adlData , filePath string ) error {
320- data , err := yaml .Marshal (adl )
321- if err != nil {
335+ var buf strings.Builder
336+ encoder := yaml .NewEncoder (& buf )
337+ encoder .SetIndent (2 )
338+
339+ if err := encoder .Encode (adl ); err != nil {
340+ _ = encoder .Close ()
322341 return err
323342 }
324-
325- return os .WriteFile (filePath , data , 0644 )
343+
344+ if err := encoder .Close (); err != nil {
345+ return err
346+ }
347+
348+ return os .WriteFile (filePath , []byte (buf .String ()), 0644 )
326349}
0 commit comments