Skip to content

Commit d5570b7

Browse files
committed
Explain auto approve
Part of microsoft#256780
1 parent 6747d36 commit d5570b7

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/commandLineAutoApprover.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,42 @@ export class CommandLineAutoApprover extends Disposable {
3535
this._denyListCommandLineRegexes = denyListCommandLine;
3636
}
3737

38-
isCommandAutoApproved(command: string, shell: string, os: OperatingSystem): boolean {
38+
isCommandAutoApproved(command: string, shell: string, os: OperatingSystem): { isAutoApproved: boolean; reason: string } {
3939
// Check the deny list to see if this command requires explicit approval
4040
for (const regex of this._denyListRegexes) {
4141
if (this._commandMatchesRegex(regex, command, shell, os)) {
42-
return false;
42+
return { isAutoApproved: false, reason: `Command '${command}' is denied by deny list rule: ${regex.source}` };
4343
}
4444
}
4545

4646
// Check the allow list to see if the command is allowed to run without explicit approval
4747
for (const regex of this._allowListRegexes) {
4848
if (this._commandMatchesRegex(regex, command, shell, os)) {
49-
return true;
49+
return { isAutoApproved: true, reason: `Command '${command}' is approved by allow list rule: ${regex.source}` };
5050
}
5151
}
5252

5353
// TODO: LLM-based auto-approval https://github.com/microsoft/vscode/issues/253267
5454

5555
// Fallback is always to require approval
56-
return false;
56+
return { isAutoApproved: false, reason: `Command '${command}' requires explicit approval (no matching allow list rule found)` };
5757
}
5858

59-
isCommandLineAutoApproved(commandLine: string): boolean {
59+
isCommandLineAutoApproved(commandLine: string): { isAutoApproved: boolean; reason: string } {
6060
// Check the deny list first to see if this command line requires explicit approval
6161
for (const regex of this._denyListCommandLineRegexes) {
6262
if (regex.test(commandLine)) {
63-
return false;
63+
return { isAutoApproved: false, reason: `Command line '${commandLine}' is denied by deny list rule: ${regex.source}` };
6464
}
6565
}
6666

6767
// Check if the full command line matches any of the allow list command line regexes
6868
for (const regex of this._allowListCommandLineRegexes) {
6969
if (regex.test(commandLine)) {
70-
return true;
70+
return { isAutoApproved: true, reason: `Command line '${commandLine}' is approved by allow list rule: ${regex.source}` };
7171
}
7272
}
73-
return false;
73+
return { isAutoApproved: false, reason: `Command line '${commandLine}' requires explicit approval (no matching allow list rule found)` };
7474
}
7575

7676
private _commandMatchesRegex(regex: RegExp, command: string, shell: string, os: OperatingSystem): boolean {

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalTool.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,14 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
171171
const subCommands = splitCommandLineIntoSubCommands(args.command, shell, os);
172172
const inlineSubCommands = subCommands.map(e => Array.from(extractInlineSubCommands(e, shell, os))).flat();
173173
const allSubCommands = [...subCommands, ...inlineSubCommands];
174-
if (allSubCommands.every(e => this._commandLineAutoApprover.isCommandAutoApproved(e, shell, os))) {
174+
const subCommandResults = allSubCommands.map(e => this._commandLineAutoApprover.isCommandAutoApproved(e, shell, os));
175+
console.log({ subCommandResults });
176+
if (subCommandResults.every(e => e.isAutoApproved)) {
175177
confirmationMessages = undefined;
176178
} else {
177-
if (this._commandLineAutoApprover.isCommandLineAutoApproved(args.command)) {
179+
const commandLineResults = this._commandLineAutoApprover.isCommandLineAutoApproved(args.command);
180+
console.log({ commandLineResults });
181+
if (commandLineResults) {
178182
confirmationMessages = undefined;
179183
} else {
180184
confirmationMessages = {

0 commit comments

Comments
 (0)