Skip to content

Commit dc7af6e

Browse files
committed
use customize
1 parent b409f2b commit dc7af6e

4 files changed

Lines changed: 55 additions & 16 deletions

File tree

‎extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSessionService.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,16 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
891891
]);
892892
const customAgents = agentInfos.map(i => i.agent);
893893
const variablesContext = this._promptVariablesService.buildTemplateVariablesContext(options.sessionId, options.debugTargetSessionIds);
894-
const systemMessageContent = variablesContext
895-
? `${variablesContext}\n\n${COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE}`
896-
: COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE;
897-
const systemMessage = { mode: 'append' as const, content: systemMessageContent };
894+
const systemMessage = {
895+
mode: 'customize' as const,
896+
sections: {
897+
identity: {
898+
action: 'replace' as const,
899+
content: COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE,
900+
},
901+
},
902+
...(variablesContext ? { content: variablesContext } : undefined),
903+
};
898904

899905
const allOptions: SessionOptions = {
900906
clientName: 'vscode',

‎extensions/copilot/src/extension/chatSessions/copilotcli/node/test/copilotCliSessionService.spec.ts‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,35 @@ describe('CopilotCLISessionService', () => {
256256

257257
const callArgs = createSessionSpy.mock.calls[0][0];
258258
expect(callArgs.systemMessage).toEqual({
259-
mode: 'append',
260-
content: COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE,
259+
mode: 'customize',
260+
sections: {
261+
identity: {
262+
action: 'replace',
263+
content: COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE,
264+
},
265+
},
261266
});
262267
});
263268

264-
it('preserves prompt variable context before the VS Code Copilot CLI identity system message', async () => {
269+
it('preserves prompt variable context separately from the VS Code Copilot CLI identity system message', async () => {
265270
const variableContext = 'Resolved template variables are available here.';
266271
vi.spyOn(NullPromptVariablesService.prototype, 'buildTemplateVariablesContext').mockReturnValue(variableContext);
267272
const createSessionSpy = vi.spyOn(manager, 'createSession');
268273
await service.createSession({ model: 'gpt-test', ...sessionOptionsFor(URI.file('/tmp')) }, CancellationToken.None);
269274

270-
const content = createSessionSpy.mock.calls[0][0].systemMessage?.content;
271-
expect(content).toContain(variableContext);
272-
expect(content).toContain(COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE);
273-
expect(content!.indexOf(variableContext)).toBeLessThan(content!.indexOf(COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE));
275+
const systemMessage = createSessionSpy.mock.calls[0][0].systemMessage;
276+
expect(systemMessage?.mode).toBe('customize');
277+
if (systemMessage?.mode !== 'customize') {
278+
throw new Error('Expected customize-mode system message');
279+
}
280+
const identity = systemMessage.sections?.identity;
281+
expect(identity?.action).toBe('replace');
282+
if (identity?.action !== 'replace') {
283+
throw new Error('Expected replace identity section override');
284+
}
285+
expect(systemMessage.content).toBe(variableContext);
286+
expect(identity.content).toBe(COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE);
287+
expect(identity.content).not.toContain(variableContext);
274288
});
275289

276290
it('passes reasoningEffort to session manager when provided', async () => {
@@ -314,8 +328,13 @@ describe('CopilotCLISessionService', () => {
314328

315329
expect(getSessionSpy).toHaveBeenCalledWith(expect.objectContaining({
316330
systemMessage: {
317-
mode: 'append',
318-
content: COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE,
331+
mode: 'customize',
332+
sections: {
333+
identity: {
334+
action: 'replace',
335+
content: COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE,
336+
},
337+
},
319338
},
320339
}), true);
321340
});

‎src/vs/platform/agentHost/node/copilot/copilotAgent.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ const ReasoningEfforts = ['low', 'medium', 'high', 'xhigh'] as const;
8585
type ReasoningEffort = NonNullable<SessionConfig['reasoningEffort']>;
8686

8787
export const COPILOT_AGENT_HOST_SYSTEM_MESSAGE = {
88-
mode: 'append',
89-
content: 'You are an AI assistant using Copilot CLI runtime in VS Code. When referring to yourself or this integration, do not describe yourself as a terminal assistant. When asked about your identity, you must state that you are an AI assistant using Copilot CLI runtime in VS Code.',
88+
mode: 'customize',
89+
sections: {
90+
identity: {
91+
action: 'replace',
92+
content: 'You are an AI assistant using Copilot CLI runtime in VS Code. When referring to yourself or this integration, do not describe yourself as a terminal assistant. When asked about your identity, you must state that you are an AI assistant using Copilot CLI runtime in VS Code.',
93+
},
94+
},
9095
} satisfies NonNullable<ResumeSessionConfig['systemMessage']>;
9196

9297
interface ISerializedModelSelection {

‎src/vs/platform/agentHost/test/node/copilotAgent.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,16 @@ suite('CopilotAgent', () => {
699699
await agent.sendMessage(result.session, 'hello');
700700

701701
assert.ok(capturedConfig, 'SDK createSession should be called during provisional materialization');
702-
assert.deepStrictEqual(capturedConfig.systemMessage, COPILOT_AGENT_HOST_SYSTEM_MESSAGE);
702+
const systemMessage = capturedConfig.systemMessage;
703+
assert.deepStrictEqual(systemMessage, COPILOT_AGENT_HOST_SYSTEM_MESSAGE);
704+
if (!systemMessage || systemMessage.mode !== 'customize') {
705+
assert.fail('Expected customize-mode system message');
706+
}
707+
assert.strictEqual(systemMessage.sections?.identity?.action, 'replace');
708+
assert.strictEqual(
709+
systemMessage.sections?.identity?.content,
710+
'You are an AI assistant using Copilot CLI runtime in VS Code. When referring to yourself or this integration, do not describe yourself as a terminal assistant. When asked about your identity, you must state that you are an AI assistant using Copilot CLI runtime in VS Code.'
711+
);
703712
} finally {
704713
await disposeAgent(agent);
705714
}

0 commit comments

Comments
 (0)