Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ export class ChatTerminalToolConfirmationSubPart extends BaseChatToolInvocationS
const optedIn = await this._showAutoApproveWarning();

This comment was marked as off-topic.

if (optedIn) {
this.storageService.store(TerminalToolConfirmationStorageKeys.TerminalAutoApproveWarningAccepted, true, StorageScope.APPLICATION, StorageTarget.USER);
// This is good to auto approve immediately
if (!terminalCustomActions) {
// If this command would have been auto-approved, approve immediately
if (terminalData.autoApproveInfo) {
toolConfirmKind = ToolConfirmKind.UserAction;
}
// If this would not have been auto approved, enable the options and
// do not complete
else {
else if (terminalCustomActions) {
for (const action of terminalCustomActions) {
if (!(action instanceof Separator)) {
action.disabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,8 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
shellType = 'pwsh';
}

const isFinalAutoApproved = (
// Is the setting enabled and the user has opted-in
isAutoApproveAllowed &&
// Check if the command would be auto-approved based on rules (ignoring warning state)
const wouldBeAutoApproved = (
// Does at least one analyzer auto approve
commandLineAnalyzerResults.some(e => e.isAutoApproved) &&
// No analyzer denies auto approval
Expand All @@ -470,7 +469,16 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
analyzersIsAutoApproveAllowed
);

if (isFinalAutoApproved) {
const isFinalAutoApproved = (
// Is the setting enabled and the user has opted-in
isAutoApproveAllowed &&
// Would be auto-approved based on rules
wouldBeAutoApproved
);

// Pass autoApproveInfo if command would be auto-approved (even if warning not yet accepted)
// This allows the confirmation widget to auto-approve after user accepts the warning
if (isFinalAutoApproved || (isAutoApproveEnabled && wouldBeAutoApproved)) {
Comment thread
Tyriar marked this conversation as resolved.
toolSpecificData.autoApproveInfo = commandLineAnalyzerResults.find(e => e.autoApproveInfo)?.autoApproveInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,23 @@ suite('RunInTerminalTool', () => {
assertConfirmationRequired(await executeToolTest({ command: 'echo hello world' }), 'Run `bash` command?');
});

test('should include autoApproveInfo when command would be auto-approved but warning not accepted', async () => {
setConfig(TerminalChatAgentToolsSettingId.EnableAutoApprove, true);
setAutoApprove({
echo: true
});

clearAutoApproveWarningAcceptedState();

const result = await executeToolTest({ command: 'echo hello world' });
assertConfirmationRequired(result, 'Run `bash` command?');

// autoApproveInfo should be set so the confirmation widget knows to auto-approve
// after the user accepts the warning modal
const terminalData = result!.toolSpecificData as IChatTerminalToolInvocationData;
ok(terminalData.autoApproveInfo, 'autoApproveInfo should be set for commands that would be auto-approved');
});

test('should auto-approve commands when both auto-approve enabled and warning accepted', async () => {
setConfig(TerminalChatAgentToolsSettingId.EnableAutoApprove, true);
setAutoApprove({
Expand Down
Loading