11import os , sys
22from typing import Optional
33from pathlib import Path
4+ import inquirer
5+ from textwrap import shorten
46
57from agentstack import conf , log
68from agentstack .exceptions import EnvironmentError
79from agentstack .utils import is_snake_case
810from agentstack import packaging
911from agentstack import frameworks
1012from agentstack import generation
11- from agentstack .proj_templates import TemplateConfig
13+ from agentstack .proj_templates import get_all_templates , TemplateConfig
1214
1315from agentstack .cli import welcome_message
1416from agentstack .cli .wizard import run_wizard
1517from agentstack .cli .templates import insert_template
1618
17- DEFAULT_TEMPLATE_NAME : str = "hello_alex"
18-
1919
2020def require_uv ():
2121 try :
2222 uv_bin = packaging .get_uv_bin ()
2323 assert os .path .exists (uv_bin )
2424 except (AssertionError , ImportError ):
25- message = "Error: uv is not installed.\n "
26- message += "Full installation instructions at: https://docs.astral.sh/uv/getting-started/installation\n "
25+ message = (
26+ "Error: uv is not installed.\n "
27+ "Full installation instructions at: "
28+ "https://docs.astral.sh/uv/getting-started/installation\n "
29+ )
2730 match sys .platform :
2831 case 'linux' | 'darwin' :
2932 message += "Hint: run `curl -LsSf https://astral.sh/uv/install.sh | sh`\n "
@@ -32,6 +35,28 @@ def require_uv():
3235 raise EnvironmentError (message )
3336
3437
38+ def select_template (slug_name : str , framework : Optional [str ] = None ) -> TemplateConfig :
39+ """Let the user select a template from the ones available."""
40+ templates : list [TemplateConfig ] = get_all_templates ()
41+ template_names = [shorten (f"⚡️ { t .name } - { t .description } " , 80 ) for t in templates ]
42+
43+ empty_msg = "🆕 Empty Project"
44+ template_choice = inquirer .list_input (
45+ message = "Do you want to start with a template?" ,
46+ choices = [empty_msg ] + template_names ,
47+ )
48+ template_name = template_choice .split ("⚡️ " )[1 ].split (" - " )[0 ]
49+
50+ if template_name == empty_msg :
51+ return TemplateConfig (
52+ name = slug_name ,
53+ description = "" ,
54+ framework = framework or frameworks .DEFAULT_FRAMEWORK ,
55+ )
56+
57+ return TemplateConfig .from_template_name (template_name )
58+
59+
3560def init_project (
3661 slug_name : Optional [str ] = None ,
3762 template : Optional [str ] = None ,
@@ -61,18 +86,19 @@ def init_project(
6186
6287 if template and use_wizard :
6388 raise Exception ("Template and wizard flags cannot be used together" )
64-
89+
90+ welcome_message ()
91+
6592 if use_wizard :
6693 log .debug ("Initializing new project with wizard." )
6794 template_data = run_wizard (slug_name )
6895 elif template :
6996 log .debug (f"Initializing new project with template: { template } " )
7097 template_data = TemplateConfig .from_user_input (template )
7198 else :
72- log .debug (f "Initializing new project with default template: { DEFAULT_TEMPLATE_NAME } " )
73- template_data = TemplateConfig . from_template_name ( DEFAULT_TEMPLATE_NAME )
99+ log .debug ("Initializing new project with template selection. " )
100+ template_data = select_template ( slug_name , framework )
74101
75- welcome_message ()
76102 log .notify ("🦾 Creating a new AgentStack project..." )
77103 log .info (f"Using project directory: { conf .PATH .absolute ()} " )
78104
@@ -81,15 +107,15 @@ def init_project(
81107 if not framework in frameworks .SUPPORTED_FRAMEWORKS :
82108 raise Exception (f"Framework '{ framework } ' is not supported." )
83109 log .info (f"Using framework: { framework } " )
84-
110+
85111 # copy the project skeleton, create a virtual environment, and install dependencies
86112 # project template is populated before the venv is created so we have a working directory
87113 insert_template (name = slug_name , template = template_data , framework = framework )
88114 log .info ("Creating virtual environment..." )
89115 packaging .create_venv ()
90116 log .info ("Installing dependencies..." )
91117 packaging .install_project ()
92-
118+
93119 # now we can interact with the project and add Agents, Tasks, and Tools
94120 # we allow dependencies to be installed along with these, so the project must
95121 # be fully initialized first.
0 commit comments