support for chat customizations in parent repo folders#300916
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends chat customization discovery (prompts, instructions, agents, etc.) to optionally search parent repository folders (walking up to a .git root) and gates that behavior behind the chat.searchRootRepositoryCustomizations setting and workspace trust checks.
Changes:
- Add parent-repo root discovery logic to
PromptFilesLocator, including trust-gating and updated watcher refresh behavior. - Refactor prompt discovery to use resolved locations with
{ parent, filePattern }metadata, and update the resolved-source-folder shape accordingly. - Update and expand tests to cover parent-repo discovery and trust behavior across prompt discovery and automatic instructions.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/test/common/workbenchTestServices.ts | Enhances the test workspace trust service with trusted URI support used by parent-repo discovery. |
| src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.ts | Implements parent repo folder walking to .git, trust checks, and refactors location resolution to include parent/filePattern. |
| src/vs/workbench/contrib/chat/common/promptSyntax/config/promptFileLocations.ts | Extends IResolvedPromptSourceFolder with parent and filePattern metadata. |
| src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.ts | Passes a logger into getWorkspaceFolderRoots for discovery logging. |
| src/vs/workbench/contrib/chat/test/common/promptSyntax/utils/promptFilesLocator.test.ts | Refactors tests to use mockFiles and adds coverage for getWorkspaceFolderRoots behavior. |
| src/vs/workbench/contrib/chat/test/common/promptSyntax/service/promptsService.test.ts | Adds integration tests asserting parent-repo discovery and “untrusted parent repo” exclusion. |
| src/vs/workbench/contrib/chat/test/common/promptSyntax/computeAutomaticInstructions.test.ts | Adds trust + .git fixtures to verify parent-repo discovery for automatic instructions. |
You can also share your feedback on Copilot code review. Take the survey.
| getUriTrustInfo(uri: URI): Promise<IWorkspaceTrustUriInfo> { | ||
| throw new Error('Method not implemented.'); | ||
| return Promise.resolve({ trusted: this.trustedUris.has(uri), uri }); | ||
| } | ||
|
|
||
| async setTrustedUris(folders: URI[]): Promise<void> { | ||
| throw new Error('Method not implemented.'); | ||
| this.trustedUris = new ResourceSet(folders); | ||
| } |
There was a problem hiding this comment.
TestWorkspaceTrustManagementService.getUriTrustInfo currently reports trust only when the URI is an exact member of trustedUris, which is inconsistent with isWorkspaceTrusted() (defaults to true) and doesn’t match typical trust semantics (trust applying to descendants via isEqualOrParent). Also, setTrustedUris updates state without firing onDidChangeTrustedFolders, so components listening for trust changes won’t react in tests. Consider (1) making getUriTrustInfo incorporate this.trusted and treat URIs under any trusted root as trusted, and (2) firing _onDidChangeTrustedFolders from setTrustedUris (and possibly also when trust state changes).
See below for a potential fix:
// If the workspace is trusted, all URIs are trusted
if (this.trusted) {
return Promise.resolve({ trusted: true, uri });
}
// Otherwise, trust applies to any URI that is equal to or a parent of a trusted root
let trusted = false;
for (const trustedUri of this.trustedUris) {
if (isEqualOrParent(uri, trustedUri, !isLinux)) {
trusted = true;
break;
}
}
return Promise.resolve({ trusted, uri });
}
async setTrustedUris(folders: URI[]): Promise<void> {
this.trustedUris = new ResourceSet(folders);
this._onDidChangeTrustedFolders.fire();
Fixes #293277
Support for finding chat customizations (instructions/prompts/agents/skills/..) in parent repositories.
This was requested by users of monorepos where users only open subfolders in VS Code.
chat.useCustomizationsInParentRepositories, default false (for now).gitfolder), walk up until we find repository folder. If found, and the folder is trusted, use chat customizations of that folder and all folders in between.