@@ -198,49 +198,43 @@ export async function loadPersonaPermissions(
198
198
. filter ( p => p !== globalPath )
199
199
200
200
const globalExists = await workspace . fs . exists ( globalPath ) . catch ( ( ) => false )
201
-
202
- // global first, then workspace
203
- const files = [ ...( globalExists ? [ globalPath ] : [ ] ) , ...wsFiles ]
204
-
205
- const result = new Map < string , MCPServerPermission > ( )
206
-
207
- // if none found, write default global persona and use it
208
- if ( files . length === 0 ) {
201
+ // use workspace files if they exist, otherwise fall back to global
202
+ let selectedFile : string | undefined
203
+ if ( wsFiles . length > 0 ) {
204
+ selectedFile = wsFiles [ 0 ]
205
+ logging . info ( `Using workspace persona file: ${ selectedFile } ` )
206
+ } else if ( globalExists ) {
207
+ selectedFile = globalPath
208
+ logging . info ( `Using global persona file: ${ selectedFile } ` )
209
+ } else {
209
210
await workspace . fs . mkdir ( path . dirname ( globalPath ) , { recursive : true } )
210
211
await workspace . fs
211
212
. writeFile ( globalPath , DEFAULT_PERSONA_RAW )
212
213
. then ( ( ) => logging . info ( `Created default persona file at ${ globalPath } ` ) )
213
214
. catch ( e => {
214
215
logging . error ( `Failed to create default persona file: ${ e . message } ` )
215
216
} )
216
- files . push ( globalPath )
217
- logging . info ( `Created default persona file at ${ globalPath } ` )
217
+ selectedFile = globalPath
218
+ logging . info ( `Using newly created default persona file: ${ selectedFile } ` )
218
219
}
219
220
220
- // merge configs: later files override earlier ones
221
- let wsHasStar = false
222
- const wsEnabled = new Set < string > ( )
221
+ // read all persona files, including global and workspace
222
+ const result = new Map < string , MCPServerPermission > ( )
223
223
224
- for ( const file of files ) {
225
- const isWorkspace = wsFiles . includes ( file )
226
- logging . info ( `Reading persona file ${ file } ` )
224
+ if ( selectedFile ) {
227
225
let cfg : PersonaConfig
228
226
try {
229
- const raw = ( await workspace . fs . readFile ( file ) ) . toString ( ) . trim ( )
227
+ const raw = ( await workspace . fs . readFile ( selectedFile ) ) . toString ( ) . trim ( )
230
228
cfg = raw ? ( JSON . parse ( raw ) as PersonaConfig ) : { mcpServers : [ ] , toolPerms : { } }
231
229
} catch ( err : any ) {
232
- logging . warn ( `Invalid Persona config in ${ file } : ${ err . message } ` )
233
- continue
230
+ logging . warn ( `Invalid Persona config in ${ selectedFile } : ${ err . message } ` )
231
+ return result
234
232
}
235
233
236
234
// enable servers listed under mcpServers
237
235
const enabled = new Set ( cfg [ 'mcpServers' ] ?? [ ] )
238
- if ( wsFiles . includes ( file ) ) {
239
- if ( enabled . has ( '*' ) ) wsHasStar = true
240
- enabled . forEach ( s => wsEnabled . add ( s ) )
241
- }
242
236
for ( const name of enabled ) {
243
- result . set ( name , { enabled : true , toolPerms : { } , __configPath__ : file } )
237
+ result . set ( name , { enabled : true , toolPerms : { } , __configPath__ : selectedFile } )
244
238
}
245
239
246
240
// Check if wildcard is present in mcpServers
@@ -252,27 +246,14 @@ export async function loadPersonaPermissions(
252
246
if ( hasWildcard || enabled . has ( name ) ) {
253
247
// Create entry for this server if it doesn't exist yet
254
248
if ( ! result . has ( name ) ) {
255
- result . set ( name , { enabled : true , toolPerms : { } , __configPath__ : file } )
249
+ result . set ( name , { enabled : true , toolPerms : { } , __configPath__ : selectedFile } )
256
250
}
257
251
258
252
const rec = result . get ( name ) !
259
253
rec . toolPerms = perms as Record < string , McpPermissionType >
260
- } else if ( isWorkspace && result . has ( name ) ) {
261
- // server dropped from workspace mcpServers → remove it entirely
262
- result . delete ( name )
263
254
}
264
255
}
265
256
}
266
-
267
- // workspace overrides global: global has '*' but workspace does not
268
- if ( wsFiles . length > 0 && ! wsHasStar ) {
269
- // remove the global-level wildcard
270
- result . delete ( '*' )
271
- // drop servers that were enabled only by the global '*'
272
- for ( const [ srv ] of result ) {
273
- if ( srv !== '*' && ! wsEnabled . has ( srv ) ) result . delete ( srv )
274
- }
275
- }
276
257
const summary = [ ...result . entries ( ) ]
277
258
. map ( ( [ srv , perm ] ) => {
278
259
const tools = Object . keys ( perm . toolPerms ) . length > 0 ? JSON . stringify ( perm . toolPerms ) : '{}'
0 commit comments