chatExternalPathConfirmation.ts ×9

Frontier kind: Code frontier

unlabeled · c_de85b003058a

13 tests · 16833 LOC · 92 files · introduces 0 tests · 72 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
9 ranges72 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2184 ranges16833 lines · 92 files · Browse complete extent
All tests (intent)
13 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 72 introduced LOC across 9 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/common/tools/builtinTools/chatExternalPathConfirmation.ts 72 introduced LOC · 9 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- chatExternalPathConfirmation.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { IDisposable } from '../../../../../../base/common/lifecycle.js';
7 > import { ResourceMap, ResourceSet } from '../../../../../../base/common/map.js';
8 > import { dirname, extUriBiasedIgnorePathCase } from '../../../../../../base/common/resources.js';
9 > import { URI } from '../../../../../../base/common/uri.js';
10 > import { localize } from '../../../../../../nls.js';
11 > import { ILabelService } from '../../../../../../platform/label/common/label.js';
12 > import { ObservableMemento, observableMemento } from '../../../../../../platform/observable/common/observableMemento.js';
13 > import { IStorageService, StorageScope, StorageTarget } from '../../../../../../platform/storage/common/storage.js';
14 > import { ConfirmedReason, ToolConfirmKind } from '../../chatService/chatService.js';
15 > import {
16 > ILanguageModelToolConfirmationActions,
17 > ILanguageModelToolConfirmationContribution,
18 > ILanguageModelToolConfirmationContributionQuickTreeItem,
19 > ILanguageModelToolConfirmationRef
20 > } from '../languageModelToolsConfirmationService.js';
21 >
22 > const workspaceAllowlistMemento = observableMemento<readonly string[]>({
23 > key: 'chat.externalPath.workspaceAllowlist',
24 > defaultValue: [],
25 > toStorage: value => JSON.stringify(value),
26 > fromStorage: value => {
27 const parsed = JSON.parse(value);
28 return Array.isArray(parsed) ? parsed : [];
29 },
31 >
32 > export interface IExternalPathInfo {
33 > path: string;
34 > isDirectory: boolean;
35 > }
36 >
37 > /**
38 > * Confirmation contribution for read_file and list_dir tools that allows users to approve
39 > * accessing paths outside the workspace, with an option to allow all access
40 > * from a containing folder for the current chat session.
41 > */
42 > export class ChatExternalPathConfirmationContribution implements ILanguageModelToolConfirmationContribution, IDisposable {
43 > readonly canUseDefaultApprovals = false;
44 >
45 > private readonly _sessionFolderAllowlist = new ResourceMap<ResourceSet>();
46 > /** Cache of path URI -> resolved git root URI (or null if not in a repo) */
47 > private readonly _gitRootCache = new ResourceMap<URI | null>();
48 > private readonly _workspaceAllowlist?: ObservableMemento<readonly string[]>;
49 >
50 > constructor(
51 > private readonly _getPathInfo: (ref: ILanguageModelToolConfirmationRef) => IExternalPathInfo | undefined,
52 > private readonly _labelService: ILabelService,
53 > private readonly _findGitRoot?: (pathUri: URI) => Promise<URI | undefined>,
54 > storageService?: IStorageService,
55 > private readonly _pickFolder?: () => Promise<URI | undefined>,
56 > ) {
57 > if (storageService) {
58 this._workspaceAllowlist = workspaceAllowlistMemento(StorageScope.WORKSPACE, StorageTarget.MACHINE, storageService);
59 }
61 >
62 > dispose(): void {
63 > this._workspaceAllowlist?.dispose();
64 > }
65 >
66 > private _getWorkspaceFolders(): ResourceSet {
67 if (!this._workspaceAllowlist) {
68 return new ResourceSet();
78 return set;
79 }
81 > private _setWorkspaceFolders(folders: ResourceSet): void {
82 if (!this._workspaceAllowlist) {
83 return;
89 this._workspaceAllowlist.set(uriStrings, undefined);
90 }
92 > getPreConfirmAction(ref: ILanguageModelToolConfirmationRef): ConfirmedReason | undefined {
93 const pathInfo = this._getPathInfo(ref);
94 if (!pathInfo) {
134 return undefined;
135 }
137 > getPreConfirmActions(ref: ILanguageModelToolConfirmationRef): ILanguageModelToolConfirmationActions[] {
138 const pathInfo = this._getPathInfo(ref);
139 if (!pathInfo || !ref.chatSessionResource) {
217 return actions;
218 }
220 > getManageActions(): ILanguageModelToolConfirmationContributionQuickTreeItem[] {
221 const items: ILanguageModelToolConfirmationContributionQuickTreeItem[] = [];
222
287 return items;
288 }
290 > reset(): void {
291 this._sessionFolderAllowlist.clear();
292 this._gitRootCache.clear();