@@ -86,9 +86,9 @@ function saveAppRegistry(environment: string, registry: AppRegistry): void {
8686}
8787
8888/**
89- * Resolve app ID or name to app ID
89+ * Resolve app ID or name to app ID (for CLI use)
9090 */
91- function resolveAppID ( environment : string , appIDOrName : string ) : string | null {
91+ export function resolveAppIDFromRegistry ( environment : string , appIDOrName : string ) : string | null {
9292 // First check if it's already a valid hex address
9393 if ( / ^ 0 x [ a - f A - F 0 - 9 ] { 40 } $ / . test ( appIDOrName ) ) {
9494 return appIDOrName ;
@@ -117,7 +117,7 @@ export async function setAppName(
117117 const registry = loadAppRegistry ( environment ) ;
118118
119119 // Resolve the target app ID
120- let targetAppID : string | null = resolveAppID ( environment , appIDOrName ) ;
120+ let targetAppID : string | null = resolveAppIDFromRegistry ( environment , appIDOrName ) ;
121121 if ( ! targetAppID ) {
122122 // If can't resolve, check if it's a valid app ID
123123 if ( / ^ 0 x [ a - f A - F 0 - 9 ] { 40 } $ / . test ( appIDOrName ) ) {
@@ -187,3 +187,34 @@ export function listApps(environment: string): Record<string, string> {
187187
188188 return result ;
189189}
190+
191+ /**
192+ * Check if an app name is available in the given environment
193+ */
194+ export function isAppNameAvailable ( environment : string , name : string ) : boolean {
195+ const apps = listApps ( environment ) ;
196+ return ! apps [ name ] ;
197+ }
198+
199+ /**
200+ * Find an available app name by appending numbers if needed
201+ */
202+ export function findAvailableName ( environment : string , baseName : string ) : string {
203+ const apps = listApps ( environment ) ;
204+
205+ // Check if base name is available
206+ if ( ! apps [ baseName ] ) {
207+ return baseName ;
208+ }
209+
210+ // Try with incrementing numbers
211+ for ( let i = 2 ; i <= 100 ; i ++ ) {
212+ const candidate = `${ baseName } -${ i } ` ;
213+ if ( ! apps [ candidate ] ) {
214+ return candidate ;
215+ }
216+ }
217+
218+ // Fallback to timestamp if somehow we have 100+ duplicates
219+ return `${ baseName } -${ Date . now ( ) } ` ;
220+ }
0 commit comments