@@ -9,6 +9,17 @@ import type {
99} from '../../../schema' ;
1010import { LIFECYCLE_TIMEOUT_MAX , LIFECYCLE_TIMEOUT_MIN } from '../../../schema' ;
1111import { getErrorMessage } from '../../errors' ;
12+ import { runCliCommand } from '../../telemetry/cli-command-run.js' ;
13+ import {
14+ Build ,
15+ Framework ,
16+ Language ,
17+ Memory ,
18+ ModelProvider as ModelProviderEnum ,
19+ NetworkMode as NetworkModeEnum ,
20+ Protocol ,
21+ standardize ,
22+ } from '../../telemetry/schemas/common-shapes.js' ;
1223import { COMMAND_DESCRIPTIONS } from '../../tui/copy' ;
1324import { requireTTY } from '../../tui/guards' ;
1425import { CreateScreen } from '../../tui/screens/create' ;
@@ -79,18 +90,17 @@ async function handleCreateCLI(options: CreateOptions): Promise<void> {
7990 const name = options . name ?? options . projectName ;
8091 const projectName = options . projectName ?? name ;
8192
82- const validation = validateCreateOptions ( options , cwd ) ;
83- if ( ! validation . valid ) {
84- if ( options . json ) {
85- console . log ( JSON . stringify ( { success : false , error : validation . error } ) ) ;
86- } else {
87- console . error ( validation . error ) ;
88- }
89- process . exit ( 1 ) ;
90- }
91-
92- // Handle dry-run mode
93+ // Handle dry-run mode (no telemetry for dry-run)
9394 if ( options . dryRun ) {
95+ const validation = validateCreateOptions ( options , cwd ) ;
96+ if ( ! validation . valid ) {
97+ if ( options . json ) {
98+ console . log ( JSON . stringify ( { success : false , error : validation . error } ) ) ;
99+ } else {
100+ console . error ( validation . error ) ;
101+ }
102+ process . exit ( 1 ) ;
103+ }
94104 const result = getDryRunInfo ( { name : name ! , projectName, cwd, language : options . language } ) ;
95105 if ( options . json ) {
96106 console . log ( JSON . stringify ( result ) ) ;
@@ -103,74 +113,92 @@ async function handleCreateCLI(options: CreateOptions): Promise<void> {
103113 process . exit ( 0 ) ;
104114 }
105115
106- const green = '\x1b[32m' ;
107- const reset = '\x1b[0m' ;
116+ await runCliCommand ( 'create' , ! ! options . json , async ( ) => {
117+ const validation = validateCreateOptions ( options , cwd ) ;
118+ if ( ! validation . valid ) {
119+ throw new Error ( validation . error ) ;
120+ }
121+ const green = '\x1b[32m' ;
122+ const reset = '\x1b[0m' ;
108123
109- // Progress callback for real-time output
110- const onProgress : ProgressCallback | undefined = options . json
111- ? undefined
112- : ( step , status ) => {
113- if ( status === 'done' ) {
114- console . log ( `${ green } [done]${ reset } ${ step } ` ) ;
115- } else if ( status === 'error' ) {
116- console . log ( `\x1b[31m[error]${ reset } ${ step } ` ) ;
117- }
118- // 'start' is silent - we only show when done
119- } ;
124+ // Progress callback for real-time output
125+ const onProgress : ProgressCallback | undefined = options . json
126+ ? undefined
127+ : ( step , status ) => {
128+ if ( status === 'done' ) {
129+ console . log ( `${ green } [done]${ reset } ${ step } ` ) ;
130+ } else if ( status === 'error' ) {
131+ console . log ( `\x1b[31m[error]${ reset } ${ step } ` ) ;
132+ }
133+ // 'start' is silent - we only show when done
134+ } ;
120135
121- // Commander.js --no-agent sets agent=false, not noAgent=true
122- const skipAgent = options . agent === false ;
136+ // Commander.js --no-agent sets agent=false, not noAgent=true
137+ const skipAgent = options . agent === false ;
123138
124- const result = skipAgent
125- ? await createProject ( {
126- name : projectName ! ,
127- cwd,
128- skipGit : options . skipGit ,
129- skipInstall : options . skipInstall ,
130- onProgress,
131- } )
132- : await createProjectWithAgent ( {
133- name : name ! ,
134- projectName,
135- cwd,
136- type : options . type as 'create' | 'import' | undefined ,
137- buildType : ( options . build as BuildType ) ?? 'CodeZip' ,
138- language : ( options . language as TargetLanguage ) ?? ( options . type === 'import' ? 'Python' : undefined ) ,
139- framework : options . framework as SDKFramework | undefined ,
140- modelProvider : options . modelProvider as ModelProvider | undefined ,
141- apiKey : options . apiKey ,
142- memory : ( options . memory as 'none' | 'shortTerm' | 'longAndShortTerm' ) ?? 'none' ,
143- protocol : options . protocol as ProtocolMode | undefined ,
144- agentId : options . agentId ,
145- agentAliasId : options . agentAliasId ,
146- region : options . region ,
147- networkMode : options . networkMode as NetworkMode | undefined ,
148- subnets : parseCommaSeparatedList ( options . subnets ) ,
149- securityGroups : parseCommaSeparatedList ( options . securityGroups ) ,
150- idleTimeout : options . idleTimeout ? Number ( options . idleTimeout ) : undefined ,
151- maxLifetime : options . maxLifetime ? Number ( options . maxLifetime ) : undefined ,
152- sessionStorageMountPath : options . sessionStorageMountPath ,
153- withConfigBundle : options . withConfigBundle ,
154- skipGit : options . skipGit ,
155- skipInstall : options . skipInstall ,
156- skipPythonSetup : options . skipPythonSetup ,
157- onProgress,
158- } ) ;
139+ const result = skipAgent
140+ ? await createProject ( {
141+ name : projectName ! ,
142+ cwd,
143+ skipGit : options . skipGit ,
144+ skipInstall : options . skipInstall ,
145+ onProgress,
146+ } )
147+ : await createProjectWithAgent ( {
148+ name : name ! ,
149+ projectName,
150+ cwd,
151+ type : options . type as 'create' | 'import' | undefined ,
152+ buildType : ( options . build as BuildType ) ?? 'CodeZip' ,
153+ language : ( options . language as TargetLanguage ) ?? ( options . type === 'import' ? 'Python' : undefined ) ,
154+ framework : options . framework as SDKFramework | undefined ,
155+ modelProvider : options . modelProvider as ModelProvider | undefined ,
156+ apiKey : options . apiKey ,
157+ memory : ( options . memory as 'none' | 'shortTerm' | 'longAndShortTerm' ) ?? 'none' ,
158+ protocol : options . protocol as ProtocolMode | undefined ,
159+ agentId : options . agentId ,
160+ agentAliasId : options . agentAliasId ,
161+ region : options . region ,
162+ networkMode : options . networkMode as NetworkMode | undefined ,
163+ subnets : parseCommaSeparatedList ( options . subnets ) ,
164+ securityGroups : parseCommaSeparatedList ( options . securityGroups ) ,
165+ idleTimeout : options . idleTimeout ? Number ( options . idleTimeout ) : undefined ,
166+ maxLifetime : options . maxLifetime ? Number ( options . maxLifetime ) : undefined ,
167+ sessionStorageMountPath : options . sessionStorageMountPath ,
168+ withConfigBundle : options . withConfigBundle ,
169+ skipGit : options . skipGit ,
170+ skipInstall : options . skipInstall ,
171+ skipPythonSetup : options . skipPythonSetup ,
172+ onProgress,
173+ } ) ;
159174
160- if ( options . json ) {
161- console . log ( JSON . stringify ( result ) ) ;
162- } else if ( result . success ) {
163- printCreateSummary ( projectName ! , result . agentName , options . language , options . framework ) ;
164- if ( options . skipInstall ) {
165- console . log (
166- "\nDependency installation was skipped. Run 'npm install' in agentcore/cdk/ and 'uv sync' in your agent directory manually."
167- ) ;
175+ if ( ! result . success ) {
176+ throw new Error ( result . error ) ;
177+ }
178+
179+ if ( options . json ) {
180+ console . log ( JSON . stringify ( result ) ) ;
181+ } else {
182+ printCreateSummary ( projectName ! , result . agentName , options . language , options . framework ) ;
183+ if ( options . skipInstall ) {
184+ console . log (
185+ "\nDependency installation was skipped. Run 'npm install' in agentcore/cdk/ and 'uv sync' in your agent directory manually."
186+ ) ;
187+ }
168188 }
169- } else {
170- console . error ( result . error ) ;
171- }
172189
173- process . exit ( result . success ? 0 : 1 ) ;
190+ return {
191+ language : standardize ( Language , options . language ) ,
192+ framework : standardize ( Framework , options . framework ) ,
193+ model_provider : standardize ( ModelProviderEnum , options . modelProvider ) ,
194+ memory : standardize ( Memory , options . memory ?? 'none' ) ,
195+ protocol : standardize ( Protocol , options . protocol ?? 'http' ) ,
196+ build : standardize ( Build , options . build ?? 'codezip' ) ,
197+ agent_type : ( options . type ?. toLowerCase ( ) ?? 'create' ) as 'create' | 'import' ,
198+ network_mode : standardize ( NetworkModeEnum , options . networkMode ?? 'public' ) ,
199+ has_agent : options . agent !== false ,
200+ } ;
201+ } ) ;
174202}
175203
176204export const registerCreate = ( program : Command ) => {
0 commit comments