@@ -58,6 +58,7 @@ import { convertReferenceToVariable } from '../copilotcli/vscode-node/copilotCLI
5858import { clearChangesCacheForAffectedSessions } from './chatSessionRepositoryTracker' ;
5959
6060const REPOSITORY_OPTION_ID = 'repository' ;
61+ const PERMISSION_LEVEL_OPTION_ID = 'permissionLevel' ;
6162
6263const _sessionWorktreeIsolationCache = new Map < string , boolean > ( ) ;
6364const BRANCH_OPTION_ID = 'branch' ;
@@ -578,6 +579,7 @@ export class CopilotCLIChatSessionContentProvider extends Disposable implements
578579 private _currentSessionId : string | undefined ;
579580 private _selectedRepoForBranches : { repoUri : URI ; headBranchName : string | undefined } | undefined ;
580581 private _displayedOptionIds = new Set < string > ( ) ;
582+ private readonly _activeSessionsById = new Map < string , ICopilotCLISession > ( ) ;
581583 /**
582584 * ID of the last used folder in an untitled workspace (for defaulting selection).
583585 */
@@ -1076,7 +1078,10 @@ export class CopilotCLIChatSessionContentProvider extends Disposable implements
10761078 const wasBranchOptionShow = ! ! this . _selectedRepoForBranches ;
10771079 let triggerProviderOptionsChange = false ;
10781080 for ( const update of updates ) {
1079- if ( update . optionId === REPOSITORY_OPTION_ID && typeof update . value === 'string' && this . sessionItemProvider . isNewSession ( sessionId ) ) {
1081+ if ( update . optionId === PERMISSION_LEVEL_OPTION_ID ) {
1082+ const level = typeof update . value === 'string' ? update . value : undefined ;
1083+ this . _getActiveSessionForResourceId ( sessionId ) ?. setPermissionLevel ( level ) ;
1084+ } else if ( update . optionId === REPOSITORY_OPTION_ID && typeof update . value === 'string' && this . sessionItemProvider . isNewSession ( sessionId ) ) {
10801085 const folder = vscode . Uri . file ( update . value ) ;
10811086 if ( isEqual ( folder , this . _selectedRepoForBranches ?. repoUri ) ) {
10821087 continue ;
@@ -1184,6 +1189,29 @@ export class CopilotCLIChatSessionContentProvider extends Disposable implements
11841189 }
11851190 }
11861191
1192+ private _getActiveSessionForResourceId ( sessionId : string ) : ICopilotCLISession | undefined {
1193+ return this . _activeSessionsById . get ( this . sessionItemProvider . untitledSessionIdMapping . get ( sessionId ) ?? sessionId )
1194+ ?? this . _activeSessionsById . get ( sessionId ) ;
1195+ }
1196+
1197+ trackActiveSession ( resourceSessionId : string , session : ICopilotCLISession ) : void {
1198+ this . _activeSessionsById . set ( resourceSessionId , session ) ;
1199+ this . _activeSessionsById . set ( session . sessionId , session ) ;
1200+ }
1201+
1202+ untrackActiveSession ( resourceSessionId : string | undefined , session : ICopilotCLISession | undefined , hasPendingRequests : boolean ) : void {
1203+ if ( ! session || hasPendingRequests ) {
1204+ return ;
1205+ }
1206+
1207+ if ( resourceSessionId && this . _activeSessionsById . get ( resourceSessionId ) === session ) {
1208+ this . _activeSessionsById . delete ( resourceSessionId ) ;
1209+ }
1210+ if ( this . _activeSessionsById . get ( session . sessionId ) === session ) {
1211+ this . _activeSessionsById . delete ( session . sessionId ) ;
1212+ }
1213+ }
1214+
11871215}
11881216
11891217function toRepositoryOptionItem ( repository : RepoContext | Uri , isDefault : boolean = false ) : ChatSessionProviderOptionItem {
@@ -1348,7 +1376,9 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
13481376 const disposables = new DisposableStore ( ) ;
13491377 let sessionId : string | undefined = undefined ;
13501378 let sessionParentId : string | undefined = undefined ;
1379+ let sessionPermissionLevel : string | undefined = undefined ;
13511380 let sdkSessionId : string | undefined = undefined ;
1381+ let activeSession : ICopilotCLISession | undefined ;
13521382 try {
13531383
13541384 const initialOptions = chatSessionContext ?. initialSessionOptions ;
@@ -1365,6 +1395,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
13651395 _sessionBranch . set ( sessionId , value ) ;
13661396 } else if ( opt . optionId === ISOLATION_OPTION_ID && value ) {
13671397 _sessionIsolation . set ( sessionId , value as IsolationMode ) ;
1398+ } else if ( opt . optionId === PERMISSION_LEVEL_OPTION_ID && value ) {
1399+ sessionPermissionLevel = value ;
13681400 } else if ( opt . optionId === PARENT_SESSION_OPTION_ID && value ) {
13691401 sessionParentId = value ;
13701402 }
@@ -1453,7 +1485,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
14531485 } ;
14541486 const newBranch = ( isUntitled && request . prompt && this . branchNameGenerator ) ? this . branchNameGenerator . generateBranchName ( fakeContext , token ) : undefined ;
14551487
1456- const sessionResult = await this . getOrCreateSession ( request , chatSessionContext , stream , { model, agent, newBranch, sessionParentId } , disposables , token ) ;
1488+ const sessionResult = await this . getOrCreateSession ( request , chatSessionContext , stream , { model, agent, newBranch, sessionParentId, permissionLevel : sessionPermissionLevel } , disposables , token ) ;
14571489 const session = sessionResult . session ;
14581490 if ( session ) {
14591491 disposables . add ( session ) ;
@@ -1472,6 +1504,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
14721504 }
14731505
14741506 sdkSessionId = session . object . sessionId ;
1507+ activeSession = session . object ;
1508+ this . contentProvider . trackActiveSession ( sessionId , activeSession ) ;
14751509 const modeInstructions = this . createModeInstructions ( request ) ;
14761510 this . chatSessionMetadataStore . updateRequestDetails ( sessionId , [ { vscodeRequestId : request . id , agentId : agent ?. name ?? '' , modeInstructions } ] ) . catch ( ex => this . logService . error ( ex , 'Failed to update request details' ) ) ;
14771511
@@ -1565,6 +1599,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
15651599 }
15661600 }
15671601 }
1602+ this . contentProvider . untrackActiveSession ( sessionId , activeSession , sdkSessionId ? this . pendingRequestBySession . has ( sdkSessionId ) : false ) ;
15681603 if ( chatSessionContext ?. chatSessionItem . resource ) {
15691604 this . sessionItemProvider . notifySessionsChange ( ) ;
15701605 }
@@ -1831,7 +1866,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
18311866 }
18321867 }
18331868
1834- private async getOrCreateSession ( request : vscode . ChatRequest , chatSessionContext : vscode . ChatSessionContext , stream : vscode . ChatResponseStream , options : { model : { model : string ; reasoningEffort ?: string } | undefined ; agent : SweCustomAgent | undefined ; newBranch ?: Promise < string | undefined > ; sessionParentId ?: string } , disposables : DisposableStore , token : vscode . CancellationToken ) : Promise < { session : IReference < ICopilotCLISession > | undefined ; trusted : boolean } > {
1869+ private async getOrCreateSession ( request : vscode . ChatRequest , chatSessionContext : vscode . ChatSessionContext , stream : vscode . ChatResponseStream , options : { model : { model : string ; reasoningEffort ?: string } | undefined ; agent : SweCustomAgent | undefined ; newBranch ?: Promise < string | undefined > ; sessionParentId ?: string ; permissionLevel ?: string } , disposables : DisposableStore , token : vscode . CancellationToken ) : Promise < { session : IReference < ICopilotCLISession > | undefined ; trusted : boolean } > {
18351870 const { resource } = chatSessionContext . chatSessionItem ;
18361871 const existingSessionId = this . sessionItemProvider . untitledSessionIdMapping . get ( SessionIdForCLI . parse ( resource ) ) ;
18371872 const id = existingSessionId ?? SessionIdForCLI . parse ( resource ) ;
@@ -1872,7 +1907,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
18721907 void this . workspaceFolderService . trackSessionWorkspaceFolder ( session . object . sessionId , sessionWorkingDirectory . fsPath , session . object . workspace . repositoryProperties ) ;
18731908 }
18741909 disposables . add ( session . object . attachStream ( stream ) ) ;
1875- const permissionLevel = request . permissionLevel ;
1910+ const permissionLevel = request . permissionLevel ?? options . permissionLevel ;
18761911 session . object . setPermissionLevel ( permissionLevel ) ;
18771912
18781913 return { session, trusted } ;
0 commit comments