@@ -14,7 +14,7 @@ import { CODING_AGENT, CODING_AGENT_AUTO_COMMIT_AND_PUSH, CODING_AGENT_ENABLED }
1414import { ITelemetry } from '../common/telemetry' ;
1515import { toOpenPullRequestWebviewUri } from '../common/uri' ;
1616import { OctokitCommon } from './common' ;
17- import { ChatSessionWithPR , CopilotApi , getCopilotApi , RemoteAgentJobPayload , SessionInfo } from './copilotApi' ;
17+ import { ChatSessionWithPR , CopilotApi , getCopilotApi , RemoteAgentJobPayload , SessionInfo , SessionSetupStep } from './copilotApi' ;
1818import { CopilotPRWatcher , CopilotStateModel } from './copilotPrWatcher' ;
1919import { CredentialStore } from './credentials' ;
2020import { FolderRepositoryManager } from './folderRepositoryManager' ;
@@ -29,6 +29,7 @@ type RemoteAgentResult = RemoteAgentSuccessResult | RemoteAgentErrorResult;
2929export interface IAPISessionLogs {
3030 readonly info : SessionInfo ;
3131 readonly logs : string ;
32+ readonly setupSteps : SessionSetupStep [ ] | undefined ;
3233}
3334
3435export interface ICopilotRemoteAgentCommandArgs {
@@ -604,13 +605,39 @@ export class CopilotRemoteAgentManager extends Disposable {
604605 return await capi . getLogsFromZipUrl ( lastRun . logs_url ) ;
605606 }
606607
608+ async getWorkflowStepsFromAction ( pullRequest : PullRequestModel ) : Promise < SessionSetupStep [ ] > {
609+ const lastRun = await this . getLatestCodingAgentFromAction ( pullRequest , 0 , false ) ;
610+ if ( ! lastRun ) {
611+ return [ ] ;
612+ }
613+
614+ try {
615+ const jobs = await pullRequest . githubRepository . getWorkflowJobs ( lastRun . id ) ;
616+ const steps : SessionSetupStep [ ] = [ ] ;
617+
618+ for ( const job of jobs ) {
619+ if ( job . steps ) {
620+ for ( const step of job . steps ) {
621+ steps . push ( { name : step . name , status : step . status } ) ;
622+ }
623+ }
624+ }
625+
626+ return steps ;
627+ } catch ( error ) {
628+ Logger . error ( `Failed to get workflow steps: ${ error } ` , CopilotRemoteAgentManager . ID ) ;
629+ return [ ] ;
630+ }
631+ }
632+
607633 async getLatestCodingAgentFromAction ( pullRequest : PullRequestModel , sessionIndex = 0 , completedOnly = true ) : Promise < OctokitCommon . WorkflowRun | undefined > {
608634 const capi = await this . copilotApi ;
609635 if ( ! capi ) {
610636 return ;
611637 }
612638 const runs = await pullRequest . githubRepository . getWorkflowRunsFromAction ( pullRequest . createdAt ) ;
613- const padawanRuns = runs
639+ const workflowRuns = runs . flatMap ( run => run . workflow_runs ) ;
640+ const padawanRuns = workflowRuns
614641 . filter ( run => run . path && run . path . startsWith ( 'dynamic/copilot-swe-agent' ) )
615642 . filter ( run => run . pull_requests ?. some ( pr => pr . id === pullRequest . id ) ) ;
616643
@@ -622,20 +649,33 @@ export class CopilotRemoteAgentManager extends Disposable {
622649 return this . getLatestRun ( padawanRuns ) ;
623650 }
624651
625- async getSessionLogFromPullRequest ( pullRequestId : number , sessionIndex = 0 , completedOnly = true ) : Promise < IAPISessionLogs | undefined > {
652+ async getSessionLogFromPullRequest ( pullRequest : PullRequestModel , sessionIndex = 0 , completedOnly = true ) : Promise < IAPISessionLogs | undefined > {
626653 const capi = await this . copilotApi ;
627654 if ( ! capi ) {
628655 return undefined ;
629656 }
630657
631- const sessions = await capi . getAllSessions ( pullRequestId ) ;
658+ const sessions = await capi . getAllSessions ( pullRequest . id ) ;
632659 const session = sessions . filter ( s => ! completedOnly || s . state === 'completed' ) . at ( sessionIndex ) ;
633660 if ( ! session ) {
634661 return undefined ;
635662 }
636663
637664 const logs = await capi . getLogsFromSession ( session . id ) ;
638- return { info : session , logs } ;
665+
666+ // If session is in progress, try to fetch workflow steps to show setup progress
667+ let setupSteps : SessionSetupStep [ ] | undefined ;
668+ if ( session . state === 'in_progress' || logs . trim ( ) . length === 0 || true ) {
669+ try {
670+ // Get workflow steps instead of logs
671+ setupSteps = await this . getWorkflowStepsFromAction ( pullRequest ) ;
672+ } catch ( error ) {
673+ // If we can't fetch workflow steps, don't fail the entire request
674+ Logger . warn ( `Failed to fetch workflow steps for session ${ session . id } : ${ error } ` , CopilotRemoteAgentManager . ID ) ;
675+ }
676+ }
677+
678+ return { info : session , logs, setupSteps } ;
639679 }
640680
641681 async getSessionUrlFromPullRequest ( pullRequest : PullRequestModel ) : Promise < string | undefined > {
0 commit comments