Skip to content

Commit 03feece

Browse files
authored
Clarify usage of prompt file specifications in Copilot CLI (#4705)
* Copikot CLI: Clarify usage of prompt file specifications * Update tests
1 parent 82bd5cb commit 03feece

3 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/extension/chatSessions/vscode-node/copilotCLIChatSessions.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,10 +1536,9 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
15361536

15371537
/**
15381538
* Gets the agent to be used.
1539-
* If creating a new session, then uses the agent configured in settings.
1540-
* If opening an existing session, then uses the agent associated with that session.
1541-
* If creating a new session with a prompt file that specifies an agent, then uses that agent.
1539+
* If the request has a prompt file (modeInstructions2) that specifies an agent, uses that agent.
15421540
* If the prompt file specifies tools, those tools override the agent's default tools.
1541+
* Otherwise returns undefined (no agent).
15431542
*/
15441543
private async getAgent(sessionId: string | undefined, request: vscode.ChatRequest | undefined, token: vscode.CancellationToken): Promise<SweCustomAgent | undefined> {
15451544
// If we have a prompt file that specifies an agent or tools, use that.
@@ -1553,8 +1552,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
15531552
return customAgent;
15541553
}
15551554
}
1556-
const sessionAgent = sessionId ? await this.chatSessionMetadataStore.getSessionAgent(sessionId) : undefined;
1557-
return sessionAgent ? await this.copilotCLIAgents.resolveAgent(sessionAgent) : undefined;
1555+
// If not found, don't use any agent, default to empty agent.
1556+
return undefined;
15581557
}
15591558

15601559
private async getPromptInfoFromRequest(request: vscode.ChatRequest, token: vscode.CancellationToken): Promise<ParsedPromptFile | undefined> {

src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { IFileSystemService } from '../../../platform/filesystem/common/fileSyst
1515
import { IGitExtensionService } from '../../../platform/git/common/gitExtensionService';
1616
import { getGitHubRepoInfoFromContext, IGitService, RepoContext } from '../../../platform/git/common/gitService';
1717
import { toGitUri } from '../../../platform/git/common/utils';
18-
import { IOctoKitService } from '../../../platform/github/common/githubService';
1918
import { derivePullRequestState } from '../../../platform/github/common/githubAPI';
19+
import { IOctoKitService } from '../../../platform/github/common/githubService';
2020
import { ILogService } from '../../../platform/log/common/logService';
2121
import { IPromptsService, ParsedPromptFile } from '../../../platform/promptFiles/common/promptsService';
2222
import { ITelemetryService } from '../../../platform/telemetry/common/telemetry';
@@ -1660,10 +1660,9 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
16601660

16611661
/**
16621662
* Gets the agent to be used.
1663-
* If creating a new session, then uses the agent configured in settings.
1664-
* If opening an existing session, then uses the agent associated with that session.
1665-
* If creating a new session with a prompt file that specifies an agent, then uses that agent.
1663+
* If the request has a prompt file (modeInstructions2) that specifies an agent, uses that agent.
16661664
* If the prompt file specifies tools, those tools override the agent's default tools.
1665+
* Otherwise returns undefined (no agent).
16671666
*/
16681667
private async getAgent(sessionId: string | undefined, request: vscode.ChatRequest | undefined, token: vscode.CancellationToken): Promise<SweCustomAgent | undefined> {
16691668
// If we have a prompt file that specifies an agent or tools, use that.
@@ -1677,8 +1676,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
16771676
return customAgent;
16781677
}
16791678
}
1680-
const sessionAgent = sessionId ? await this.chatSessionMetadataStore.getSessionAgent(sessionId) : undefined;
1681-
return sessionAgent ? await this.copilotCLIAgents.resolveAgent(sessionAgent) : undefined;
1679+
// If not found, don't use any agent, default to empty agent.
1680+
return undefined;
16821681
}
16831682

16841683
private async getPromptInfoFromRequest(request: vscode.ChatRequest, token: vscode.CancellationToken): Promise<ParsedPromptFile | undefined> {

src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,23 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
19611961
const { agent } = createSessionSpy.mock.calls[0][0];
19621962
expect(agent?.tools).toBeNull();
19631963
});
1964+
1965+
it('does not use session agent when no modeInstructions2 is provided', async () => {
1966+
const agentParticipant = makeParticipantWithAgents(new MockCopilotCLIAgentsWithCustomAgent(['tool-a']));
1967+
const createSessionSpy = vi.spyOn(sessionService, 'createSession');
1968+
1969+
const request = new TestChatRequest('Do something');
1970+
// No modeInstructions2 set — agent should be undefined regardless of session state
1971+
const context = createChatContext('temp-new', true);
1972+
const stream = new MockChatResponseStream();
1973+
const token = disposables.add(new CancellationTokenSource()).token;
1974+
1975+
await agentParticipant.createHandler()(request, context, stream, token);
1976+
1977+
expect(createSessionSpy).toHaveBeenCalled();
1978+
const { agent } = createSessionSpy.mock.calls[0][0];
1979+
expect(agent).toBeUndefined();
1980+
});
19641981
});
19651982

19661983
describe('PR detection with retry', () => {

0 commit comments

Comments
 (0)