@@ -68,10 +68,16 @@ export class GdbWorld extends World {
6868 }
6969 }
7070
71- /** Write a config file in the temp config dir */
71+ /** Write a config file in the temp config dir (auto-wraps v1 flat configs into v2 format) */
7272 writeConfig ( config : Record < string , unknown > ) : void {
7373 mkdirSync ( this . configDir , { recursive : true } ) ;
74- writeFileSync ( join ( this . configDir , "config.json" ) , JSON . stringify ( config , null , 2 ) + "\n" ) ;
74+ // Ensure v2 format so the CLI doesn't need to auto-migrate (avoids extra file I/O)
75+ const toWrite = config . version === 2 ? config : {
76+ version : 2 ,
77+ currentProfile : "default" ,
78+ profiles : { default : config } ,
79+ } ;
80+ writeFileSync ( join ( this . configDir , "config.json" ) , JSON . stringify ( toWrite , null , 2 ) + "\n" ) ;
7581 }
7682
7783 /** Read the current config file (raw JSON) */
@@ -133,9 +139,13 @@ export async function performLogin(world: GdbWorld): Promise<Record<string, unkn
133139 continue ;
134140 }
135141
136- const config : Record < string , unknown > = { url : world . serverUrl , token } ;
137- if ( data . refreshToken ) config . refreshToken = data . refreshToken ;
138- world . writeConfig ( config ) ;
142+ const profile : Record < string , unknown > = { url : world . serverUrl , token } ;
143+ if ( data . refreshToken ) profile . refreshToken = data . refreshToken ;
144+ world . writeConfig ( {
145+ version : 2 ,
146+ currentProfile : "default" ,
147+ profiles : { default : profile } ,
148+ } ) ;
139149 return world . readProfileConfig ( ) ;
140150 } catch ( err ) {
141151 lastError = err instanceof Error ? err : new Error ( String ( err ) ) ;
0 commit comments