@@ -45,6 +45,27 @@ const body_suffix = vscode.l10n.t('Created from VS Code via the [GitHub Pull Req
4545
4646const PREFERRED_GITHUB_CODING_AGENT_REMOTE_WORKSPACE_KEY = 'PREFERRED_GITHUB_CODING_AGENT_REMOTE' ;
4747
48+
49+ export namespace SessionIdForPr {
50+
51+ const prefix = 'pull-session-by-index' ;
52+
53+ export function getId ( prNumber : number , sessionIndex : number ) : string {
54+ return `${ prefix } -${ prNumber } -${ sessionIndex } ` ;
55+ }
56+
57+ export function parse ( id : string ) : { prNumber : number ; sessionIndex : number } | undefined {
58+ const match = id . match ( new RegExp ( `^${ prefix } -(\\d+)-(\\d+)$` ) ) ;
59+ if ( match ) {
60+ return {
61+ prNumber : parseInt ( match [ 1 ] , 10 ) ,
62+ sessionIndex : parseInt ( match [ 2 ] , 10 )
63+ } ;
64+ }
65+ return undefined ;
66+ }
67+ }
68+
4869export class CopilotRemoteAgentManager extends Disposable {
4970 public static ID = 'CopilotRemoteAgentManager' ;
5071
@@ -1024,10 +1045,21 @@ export class CopilotRemoteAgentManager extends Disposable {
10241045 return await this . newSessionFlowFromPrompt ( id ) ;
10251046 }
10261047
1027- const pullRequestNumber = parseInt ( id ) ;
1028- if ( isNaN ( pullRequestNumber ) ) {
1029- Logger . error ( `Invalid pull request number: ${ id } ` , CopilotRemoteAgentManager . ID ) ;
1030- return this . createEmptySession ( ) ;
1048+ let pullRequestNumber : number | undefined ;
1049+ let sessionIndex : number | undefined ;
1050+
1051+ const indexedSessionId = SessionIdForPr . parse ( id ) ;
1052+ if ( indexedSessionId ) {
1053+ pullRequestNumber = indexedSessionId . prNumber ;
1054+ sessionIndex = indexedSessionId . sessionIndex ;
1055+ }
1056+
1057+ if ( typeof pullRequestNumber === 'undefined' ) {
1058+ pullRequestNumber = parseInt ( id ) ;
1059+ if ( isNaN ( pullRequestNumber ) ) {
1060+ Logger . error ( `Invalid pull request number: ${ id } ` , CopilotRemoteAgentManager . ID ) ;
1061+ return this . createEmptySession ( ) ;
1062+ }
10311063 }
10321064
10331065 const pullRequest = await this . findPullRequestById ( pullRequestNumber , true ) ;
@@ -1039,7 +1071,7 @@ export class CopilotRemoteAgentManager extends Disposable {
10391071 // Parallelize independent operations
10401072 const timelineEvents = pullRequest . getTimelineEvents ( ) ;
10411073 const changeModels = this . getChangeModels ( pullRequest ) ;
1042- const sessions = await capi . getAllSessions ( pullRequest . id ) ;
1074+ let sessions = await capi . getAllSessions ( pullRequest . id ) ;
10431075
10441076 if ( ! sessions || sessions . length === 0 ) {
10451077 Logger . warn ( `No sessions found for pull request ${ pullRequestNumber } ` , CopilotRemoteAgentManager . ID ) ;
@@ -1051,6 +1083,16 @@ export class CopilotRemoteAgentManager extends Disposable {
10511083 return this . createEmptySession ( ) ;
10521084 }
10531085
1086+ if ( typeof sessionIndex === 'number' ) {
1087+ const target = sessions . at ( sessionIndex ) ;
1088+ if ( ! target ) {
1089+ Logger . error ( `Session not found: ${ sessionIndex } ` , CopilotRemoteAgentManager . ID ) ;
1090+ return this . createEmptySession ( ) ;
1091+ }
1092+
1093+ sessions = [ target ] ;
1094+ }
1095+
10541096 // Create content builder with pre-fetched change models
10551097 const contentBuilder = new ChatSessionContentBuilder ( CopilotRemoteAgentManager . ID , COPILOT , changeModels ) ;
10561098
0 commit comments