Skip to content

Refactor session ID generation in copilotRemoteAgent.ts to avoid duplication #7428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/github/copilotRemoteAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ export class CopilotRemoteAgentManager extends Disposable {
}
return {
id: `${session.number}`,
label: session.title || `Session ${session.number}`,
label: session.title || this.generateSessionIdentifier(session.number),
iconPath: this.getIconForSession(status),
pullRequest: session
};
Expand Down Expand Up @@ -903,7 +903,7 @@ export class CopilotRemoteAgentManager extends Disposable {
timelineEvents: readonly TimelineEvent[],
capi: CopilotApi
): Promise<string> {
let sessionPrompt = session.name || `Session ${sessionIndex + 1} (ID: ${session.id})`;
let sessionPrompt = session.name || this.generateSessionIdentifier(sessionIndex + 1, session.id);

if (sessionIndex === 0) {
sessionPrompt = await this.getInitialSessionPrompt(session, pullRequest, capi, sessionPrompt);
Expand Down Expand Up @@ -988,6 +988,19 @@ export class CopilotRemoteAgentManager extends Disposable {
return 0;
}

/**
* Generates a session identifier string in various formats
* @param sessionNumber The session number (1-based)
* @param sessionId Optional session ID to include in the identifier
* @returns Formatted session identifier string
*/
private generateSessionIdentifier(sessionNumber: number, sessionId?: string): string {
if (sessionId) {
return `Session ${sessionNumber} (ID: ${sessionId})`;
}
return `Session ${sessionNumber}`;
}

private findRelevantTimelineEvents(
timelineEvents: readonly TimelineEvent[],
previousSessionEndTime: number,
Expand Down