src/vs/workbench/contrib/chat/common/chatPermissionWarnings.ts

193 LOC · 108 covered · 85 uncovered · 16 ranges · 13 concepts · 8 introducers · 6 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/workbench/contrib/chat/common/chatPermissionStorageKeys.ts · 10 LOCcommon/chatPermissionSto…chatPermissionWarnings.test|title=chatPermissionWarnings confirming Autopilot suppresses the equal-reach Bypass warning|occurrence=1 · 0 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings confirming Allow All suppresses the lower-reach Approve When Safe warning|occurrence=1 · 0 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings confirming Approve When Safe does not suppress the Allow All warning|occurrence=1 · 0 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings confirming Bypass suppresses the equal-reach Autopilot warning|occurrence=1 · 0 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.ts ×1 · 2 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings an unconfirmed elevated level has not been warned|occurrence=1 · 0 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.ts ×1 · 2 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.ts ×1 · 2 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.ts ×1 · 3 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.ts ×1 · 2 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.ts ×6 · 13 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.ts ×1 · 2 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.ts ×4 · 92 introduced LOCchatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings an unconfirmed elevated level has not been warned|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/chat/test/common/chatPermissionWarnings.test|title=chatPermissionWarnings an unconfirmed elevated level has not been warned|occurrence=1chatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings confirming Allow All suppresses the lower-reach Approve When Safe warning|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/chat/test/common/chatPermissionWarnings.test|title=chatPermissionWarnings confirming Allow All suppresses the lower-reach Approve When Safe warning|occurrence=1chatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings confirming Approve When Safe does not suppress the Allow All warning|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/chat/test/common/chatPermissionWarnings.test|title=chatPermissionWarnings confirming Approve When Safe does not suppress the Allow All warning|occurrence=1chatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings confirming Autopilot suppresses the equal-reach Bypass warning|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/chat/test/common/chatPermissionWarnings.test|title=chatPermissionWarnings confirming Autopilot suppresses the equal-reach Bypass warning|occurrence=1chatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings confirming Bypass suppresses the equal-reach Autopilot warning|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/chat/test/common/chatPermissionWarnings.test|title=chatPermissionWarnings confirming Bypass suppresses the equal-reach Autopilot warning|occurrence=1chatPermissionWarnings.t…chatPermissionWarnings.test|title=chatPermissionWarnings non-elevated Default is never considered "warned"|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/chat/test/common/chatPermissionWarnings.test|title=chatPermissionWarnings non-elevated Default is never considered "warned"|occurrence=1chatPermissionWarnings.t…Focused file · src/vs/workbench/contrib/chat/common/chatPermissionWarnings.ts · 193 LOCcommon/chatPermissionWar…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- chatPermissionWarnings.ts ×4
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 { Codicon } from '../../../../base/common/codicons.js';
7 > import { MarkdownString } from '../../../../base/common/htmlContent.js';
8 > import Severity from '../../../../base/common/severity.js';
9 > import { ThemeIcon } from '../../../../base/common/themables.js';
10 > import { localize } from '../../../../nls.js';
11 > import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
12 > import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
13 > import { ASSISTED_APPROVAL_DONT_SHOW_AGAIN_KEY, AUTO_APPROVE_DONT_SHOW_AGAIN_KEY, AUTOPILOT_DONT_SHOW_AGAIN_KEY } from './chatPermissionStorageKeys.js';
14 > import { ChatConfiguration, ChatPermissionLevel } from './constants.js';
15 >
16 > /**
17 > * In-memory record of warnings already accepted in this VS Code session.
18 > * Checked alongside the persisted "Don't show again" storage value so that the
19 > * warning isn't repeated within a session even when the user didn't tick the
20 > * checkbox.
21 > *
22 > * Per-renderer; the `StorageScope.PROFILE` storage entry is what synchronizes
23 > * the dismissed state across windows (workbench and Agents).
24 > */
25 > const shownWarnings = new Set<ChatPermissionLevel>();
26 >
27 > function dontShowAgainKey(level: ChatPermissionLevel): string | undefined { chatPermissionWarnings.ts ×6
28 > if (level === ChatPermissionLevel.Autopilot) {
29 > return AUTOPILOT_DONT_SHOW_AGAIN_KEY; chatPermissionWarnings.ts ×1
30 > }
31 > if (level === ChatPermissionLevel.AutoApprove) { chatPermissionWarnings.ts ×6
32 > return AUTO_APPROVE_DONT_SHOW_AGAIN_KEY;
33 > }
34 > if (level === ChatPermissionLevel.Assisted) { chatPermissionWarnings.ts ×1
35 > return ASSISTED_APPROVAL_DONT_SHOW_AGAIN_KEY;
36 > }
37 return undefined;
38 }
40 > /**
41 > * Clears the in-process suppression set so that previously accepted (but not
42 > * persistently dismissed) warnings will be shown again within this session.
43 > * Call this alongside removing the persisted storage keys when implementing a
44 > * "reset" developer action.
45 > */
46 > export function resetShownWarnings(): void {
47 > shownWarnings.clear();
48 > }
49 >
50 > /**
51 > * Relative "auto-approval reach" of each elevated level, used to suppress
52 > * lower-level warnings once a stronger one has been accepted. Bypass Approvals
53 > * and Autopilot both auto-approve *every* tool call, so confirming either in
54 > * this session (or persistently) implies acceptance of the other — the user is
55 > * not warned again when stepping between them (e.g. Autopilot → Bypass).
56 > */
57 > const ELEVATION_RANK: ReadonlyMap<ChatPermissionLevel, number> = new Map([
58 > [ChatPermissionLevel.Assisted, 1],
59 > [ChatPermissionLevel.AutoApprove, 2],
60 > [ChatPermissionLevel.Autopilot, 2],
61 > ]);
62 >
63 > export function hasShownElevatedWarning(level: ChatPermissionLevel, storageService: IStorageService): boolean {
64 > const rank = ELEVATION_RANK.get(level);
65 > if (rank === undefined) {
66 > return false; chatPermissionWarnings.ts ×1
67 > }
68 > // Accepting any elevated level whose reach is >= this one (in this session chatPermissionWarnings.ts ×6
69 > // or persistently) suppresses the warning.
70 > for (const [candidate, candidateRank] of ELEVATION_RANK) {
71 > if (candidateRank < rank) {
73 > }
74 > if (shownWarnings.has(candidate)) { chatPermissionWarnings.ts ×6
75 return true;
76 }
77 > const key = dontShowAgainKey(candidate); chatPermissionWarnings.ts ×6
78 > if (key && storageService.getBoolean(key, StorageScope.PROFILE, false)) {
79 > return true; chatPermissionWarnings.ts ×1
80 > }
82 > return false; chatPermissionWarnings.ts ×1
83 > }
85 > interface IElevatedWarningCopy {
86 > readonly title: string;
87 > readonly confirm: string;
88 > readonly icon: ThemeIcon;
89 > readonly detail: string;
90 > }
91 >
92 function getElevatedWarningCopy(level: ChatPermissionLevel, defaultSettingKey: string, levelLabel?: string): IElevatedWarningCopy | undefined {
93 switch (level) {
94 case ChatPermissionLevel.Assisted:
95 levelLabel ??= localize('permissions.assisted', "Auto Approvals");
96 return {
97 title: localize('permissions.assisted.warning.title', "Enable {0}?", levelLabel),
98 confirm: localize('permissions.assisted.warning.confirm', "Enable"),
99 icon: Codicon.sparkle,
100 detail: localize('permissions.assisted.warning.detail', "{0} uses model recommendations to approve tool calls. Copilot will still ask when the model requires approval, excludes the request from automatic approval, or cannot make a recommendation.\n\nTo make this the starting permission level for new sessions, change the [{1}](command:workbench.action.openSettings?%5B%22{1}%22%5D) setting.", levelLabel, defaultSettingKey),
101 };
102 case ChatPermissionLevel.Autopilot:
103 return {
104 title: localize('permissions.autopilot.warning.title', "Enable Autopilot?"),
105 confirm: localize('permissions.autopilot.warning.confirm', "Enable"),
106 icon: Codicon.rocket,
107 detail: localize('permissions.autopilot.warning.detail', "Autopilot will auto-approve all tool calls and continue working autonomously until the task is complete. This includes terminal commands, file edits, and external tool calls. The agent will make decisions on your behalf without asking for confirmation.\n\nYou can stop the agent at any time by clicking the stop button. This applies to the current session only.\n\nTo make this the starting permission level for new sessions, change the [{0}](command:workbench.action.openSettings?%5B%22{0}%22%5D) setting.", defaultSettingKey),
108 };
109 case ChatPermissionLevel.AutoApprove:
110 levelLabel ??= localize('permissions.autoApprove', "Bypass Approvals");
111 return {
112 title: localize('permissions.autoApprove.warning.title', "Enable {0}?", levelLabel),
113 confirm: localize('permissions.autoApprove.warning.confirm', "Enable"),
114 icon: Codicon.warning,
115 detail: localize('permissions.autoApprove.warning.detail', "{0} will auto-approve all tool calls without asking for confirmation. This includes file edits, terminal commands, and external tool calls.\n\nTo make this the starting permission level for new sessions, change the [{1}](command:workbench.action.openSettings?%5B%22{1}%22%5D) setting.", levelLabel, defaultSettingKey),
116 };
117 default:
118 return undefined;
119 }
120 }
122 > /**
123 > * If `level` is an elevated permission level (Bypass Approvals or Autopilot)
124 > * that hasn't already been confirmed in this session or persistently
125 > * dismissed, show the corresponding warning dialog. Returns:
126 > *
127 > * - `true` if the level is not elevated, has already been confirmed, or the
128 > * user accepts the dialog. In these cases the caller should proceed to apply
129 > * the level.
130 > * - `false` if the user cancels the dialog. The caller should abort the
131 > * permission change.
132 > *
133 > * When the user ticks "Don't show again", the choice is persisted in
134 > * `StorageScope.PROFILE`, which is shared across the workbench and Agents
135 > * windows so a dismissal in one applies to the other.
136 > *
137 > * `options.defaultSettingKey` controls which "make this the default" setting
138 > * the dialog links to — local chat uses `chat.permissions.default` (the
139 > * default), while agent-host sessions pass
140 > * `chat.defaultConfiguration`.
141 > */
142 export async function maybeConfirmElevatedPermissionLevel(
143 level: ChatPermissionLevel,
144 dialogService: IDialogService,
145 storageService: IStorageService,
146 options?: { readonly defaultSettingKey?: string; readonly levelLabel?: string },
147 ): Promise<boolean> {
148 const key = dontShowAgainKey(level);
149 if (!key || hasShownElevatedWarning(level, storageService)) {
150 return true;
151 }
152
153 const copy = getElevatedWarningCopy(level, options?.defaultSettingKey ?? ChatConfiguration.DefaultPermissionLevel, options?.levelLabel);
154 if (!copy) {
155 return true;
156 }
157
158 const result = await dialogService.prompt({
159 type: Severity.Warning,
160 message: copy.title,
161 buttons: [
162 {
163 label: copy.confirm,
164 run: () => true,
165 },
166 {
167 label: localize('permissions.warning.cancel', "Cancel"),
168 run: () => false,
169 },
170 ],
171 checkbox: {
172 label: localize('permissions.warning.dontShowAgain', "Don't show again"),
173 checked: false,
174 },
175 custom: {
176 icon: copy.icon,
177 markdownDetails: [{
178 markdown: new MarkdownString(
179 copy.detail,
180 { isTrusted: { enabledCommands: ['workbench.action.openSettings'] } },
181 ),
182 }],
183 },
184 });
185 if (result.result !== true) {
186 return false;
187 }
188 if (result.checkboxChecked) {
189 storageService.store(key, true, StorageScope.PROFILE, StorageTarget.USER);
190 }
191 shownWarnings.add(level);
192 return true;
193 }