Skip to content

Commit a89b1fc

Browse files
Avoidincluding customizations variables into CLI prompt as context (#4392)
* Avoidincluding customizations variables into CLI prompt as context * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent bce996f commit a89b1fc

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

src/extension/chatSessions/copilotcli/node/copilotcliPromptResolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { extUriBiasedIgnorePathCase, relativePath } from '../../../../util/vs/ba
1818
import { URI } from '../../../../util/vs/base/common/uri';
1919
import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';
2020
import { ChatReferenceBinaryData, ChatReferenceDiagnostic, FileType, Location } from '../../../../vscodeTypes';
21-
import { ChatVariablesCollection, isPromptInstruction, isInstructionFile, PromptVariable } from '../../../prompt/common/chatVariablesCollection';
21+
import { ChatVariablesCollection, isCustomizationsIndex, isInstructionFile, isPromptInstruction, PromptVariable } from '../../../prompt/common/chatVariablesCollection';
2222
import { generateUserPrompt } from '../../../prompts/node/agent/copilotCLIPrompt';
2323
import { getWorkingDirectory, isIsolationEnabled, IWorkspaceInfo } from '../../common/workspaceInfo';
2424
import { ICopilotCLIImageSupport, isImageMimeType } from './copilotCLIImageSupport';
@@ -76,8 +76,8 @@ export class CopilotCLIPromptResolver {
7676
const folderToWorktreeMap = this.buildFolderToWorktreeMap(workspaceInfo, additionalWorkspaces);
7777
const hasAnyWorkingDirectory = getWorkingDirectory(workspaceInfo) || additionalWorkspaces.some(ws => getWorkingDirectory(ws));
7878
await Promise.all(Array.from(variables).map(async variable => {
79-
// Unsupported references.
80-
if (isPromptInstruction(variable) || isInstructionFile(variable)) {
79+
// Unsupported references: prompt instructions, instruction files, and the customizations index.
80+
if (isPromptInstruction(variable) || isInstructionFile(variable) || isCustomizationsIndex(variable)) {
8181
return;
8282
}
8383
// If isolation is enabled, and we have workspace repo information, skip it.

src/extension/prompt/common/chatVariablesCollection.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,12 @@ export function isInstructionFile(variable: PromptVariable): variable is PromptV
134134
}
135135

136136
export const InstructionFileIdPrefix = 'vscode.instructions.file';
137+
138+
/**
139+
* Check if provided variable is the workspace "customizations index" file.
140+
*/
141+
export function isCustomizationsIndex(variable: PromptVariable): variable is PromptVariable & { value: vscode.Uri } {
142+
return variable.reference.id === CustomizationsIndexId;
143+
}
144+
145+
export const CustomizationsIndexId = 'vscode.customizations.index';

src/extension/prompts/node/agent/test/parseAttachments.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,38 @@ suite('CopilotCLI Generate & parse prompts', () => {
465465
expect(instructionAttachment).toBeUndefined();
466466
});
467467

468+
test('excludes customizations index from references and attachments', async () => {
469+
const customizationsIndex = {
470+
id: 'vscode.customizations.index',
471+
name: 'customizations',
472+
value: URI.file('/workspace/.github/copilot-instructions.md')
473+
};
474+
const regularFileRef = {
475+
id: 'regular-file',
476+
name: 'regular.ts',
477+
value: URI.file('/workspace/regular.ts')
478+
};
479+
createMockFile(customizationsIndex.value, `# Customizations\nSome instructions.`);
480+
createMockFile(regularFileRef.value, `const x = 1;`);
481+
482+
const req = new TestChatRequest('Process these files', [
483+
customizationsIndex,
484+
regularFileRef
485+
]);
486+
487+
const resolved = await resolver.resolvePrompt(req, undefined, [], workspaceInfo, [], CancellationToken.None);
488+
489+
// Customizations index should be excluded from references and attachments
490+
const customizationsRef = resolved.references.find(r => URI.isUri(r.value) && (r.value as URI).fsPath.includes('copilot-instructions.md'));
491+
expect(customizationsRef).toBeUndefined();
492+
// Regular file reference should still be included
493+
const regularRef = resolved.references.find(r => URI.isUri(r.value) && (r.value as URI).fsPath.includes('regular.ts'));
494+
expect(regularRef).toBeDefined();
495+
// Attachment for customizations index should not be present
496+
const customizationsAttachment = resolved.attachments.find(a => a.type === 'file' && a.path.includes('copilot-instructions.md'));
497+
expect(customizationsAttachment).toBeUndefined();
498+
});
499+
468500
test('extract GitHub PR/Issues', async () => {
469501
const result = extractChatPromptReferences(getPromptTextWithGithubIssuePR());
470502
expect(result).toMatchSnapshot();

0 commit comments

Comments
 (0)