@@ -61,6 +61,7 @@ const REPOSITORY_OPTION_ID = 'repository';
6161const _sessionWorktreeIsolationCache = new Map < string , boolean > ( ) ;
6262const BRANCH_OPTION_ID = 'branch' ;
6363const ISOLATION_OPTION_ID = 'isolation' ;
64+ const PARENT_SESSION_OPTION_ID = 'parentSessionId' ;
6465const LAST_USED_ISOLATION_OPTION_KEY = 'github.copilot.cli.lastUsedIsolationOption' ;
6566const OPEN_REPOSITORY_COMMAND_ID = 'github.copilot.cli.sessions.openRepository' ;
6667const OPEN_IN_COPILOT_CLI_COMMAND_ID = 'github.copilot.cli.openInCopilotCLI' ;
@@ -308,9 +309,12 @@ export class CopilotCLIChatSessionItemProvider extends Disposable implements vsc
308309 // repository state which we are passing along through the metadata
309310 worktreeProperties = await this . worktreeManager . getWorktreeProperties ( session . id ) ;
310311
312+ const sessionParentId = await this . chatSessionMetadataStore . getSessionParentId ( session . id ) ;
313+
311314 if ( worktreeProperties ) {
312315 // Worktree
313316 metadata = {
317+ sessionParentId,
314318 autoCommit : worktreeProperties . autoCommit !== false ,
315319 baseCommit : worktreeProperties ?. baseCommit ,
316320 baseBranchName : worktreeProperties . version === 2
@@ -373,6 +377,7 @@ export class CopilotCLIChatSessionItemProvider extends Disposable implements vsc
373377 : undefined ;
374378
375379 metadata = {
380+ sessionParentId,
376381 isolationMode : IsolationMode . Workspace ,
377382 repositoryPath : repositoryProperties ?. repositoryPath ,
378383 branchName : repositoryProperties ?. branchName ,
@@ -1267,6 +1272,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
12671272 let { chatSessionContext } = context ;
12681273 const disposables = new DisposableStore ( ) ;
12691274 let sessionId : string | undefined = undefined ;
1275+ let sessionParentId : string | undefined = undefined ;
12701276 let sdkSessionId : string | undefined = undefined ;
12711277 try {
12721278
@@ -1284,6 +1290,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
12841290 _sessionBranch . set ( sessionId , value ) ;
12851291 } else if ( opt . optionId === ISOLATION_OPTION_ID && value ) {
12861292 _sessionIsolation . set ( sessionId , value as IsolationMode ) ;
1293+ } else if ( opt . optionId === PARENT_SESSION_OPTION_ID && value ) {
1294+ sessionParentId = value ;
12871295 }
12881296 }
12891297 }
@@ -1369,7 +1377,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
13691377 } ;
13701378 const newBranch = ( isUntitled && request . prompt && this . branchNameGenerator ) ? this . branchNameGenerator . generateBranchName ( fakeContext , token ) : undefined ;
13711379
1372- const sessionResult = await this . getOrCreateSession ( request , chatSessionContext , stream , { model, agent, newBranch } , disposables , token ) ;
1380+ const sessionResult = await this . getOrCreateSession ( request , chatSessionContext , stream , { model, agent, newBranch, sessionParentId } , disposables , token ) ;
13731381 const session = sessionResult . session ;
13741382 if ( session ) {
13751383 disposables . add ( session ) ;
@@ -1729,7 +1737,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
17291737 }
17301738 }
17311739
1732- 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 > } , disposables : DisposableStore , token : vscode . CancellationToken ) : Promise < { session : IReference < ICopilotCLISession > | undefined ; trusted : boolean } > {
1740+ 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 } > {
17331741 const { resource } = chatSessionContext . chatSessionItem ;
17341742 const existingSessionId = this . sessionItemProvider . untitledSessionIdMapping . get ( SessionIdForCLI . parse ( resource ) ) ;
17351743 const id = existingSessionId ?? SessionIdForCLI . parse ( resource ) ;
@@ -1747,7 +1755,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
17471755 const debugTargetSessionIds = extractDebugTargetSessionIds ( request . references ) ;
17481756 const mcpServerMappings = buildMcpServerMappings ( request . tools ) ;
17491757 const session = isNewSession ?
1750- await this . sessionService . createSession ( { model : model ?. model , reasoningEffort : model ?. reasoningEffort , workspace : workspaceInfo , agent, debugTargetSessionIds, mcpServerMappings } , token ) :
1758+ await this . sessionService . createSession ( { model : model ?. model , reasoningEffort : model ?. reasoningEffort , workspace : workspaceInfo , agent, debugTargetSessionIds, mcpServerMappings, sessionParentId : options . sessionParentId } , token ) :
17511759 await this . sessionService . getSession ( { sessionId : id , model : model ?. model , reasoningEffort : model ?. reasoningEffort , workspace : workspaceInfo , agent, debugTargetSessionIds, mcpServerMappings } , token ) ;
17521760 this . sessionItemProvider . notifySessionsChange ( ) ;
17531761 // TODO @DonJayamanne We need to refresh to add this new session, but we need a label.
0 commit comments