Skip to content

Commit a9c4b92

Browse files
authored
Merge pull request #260609 from microsoft/tyriar/dupe_rules
Prevent duplicate rules showing in message
2 parents 57352f3 + a3a1491 commit a9c4b92

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,11 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
262262
break;
263263
}
264264
case 'subCommand': {
265-
if (subCommandResults.length === 1) {
266-
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', subCommandResults.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`).join(', '))}_`);
267-
} else if (subCommandResults.length > 1) {
268-
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rules', 'Auto approved by rules {0}', subCommandResults.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`).join(', '))}_`);
265+
const uniqueRules = Array.from(new Set(subCommandResults.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`)));
266+
if (uniqueRules.length === 1) {
267+
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', uniqueRules[0])}_`);
268+
} else if (uniqueRules.length > 1) {
269+
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rules', 'Auto approved by rules {0}', uniqueRules.join(', '))}_`);
269270
}
270271
break;
271272
}
@@ -280,10 +281,11 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
280281
}
281282
case 'subCommand': {
282283
const deniedRules = subCommandResults.filter(e => e.result === 'denied');
283-
if (deniedRules.length === 1) {
284-
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', deniedRules.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`).join(', '))}_`);
285-
} else if (deniedRules.length > 1) {
286-
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rules', 'Auto approval denied by rules {0}', deniedRules.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`).join(', '))}_`);
284+
const uniqueRules = Array.from(new Set(deniedRules.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`)));
285+
if (uniqueRules.length === 1) {
286+
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', uniqueRules[0])}_`);
287+
} else if (uniqueRules.length > 1) {
288+
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rules', 'Auto approval denied by rules {0}', uniqueRules.join(', '))}_`);
287289
}
288290
break;
289291
}
@@ -879,7 +881,7 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
879881
const canCreateAutoApproval = autoApproveResult.subCommandResults.some(e => e.result !== 'denied') || autoApproveResult.commandLineResult.result === 'denied';
880882
if (canCreateAutoApproval) {
881883
// Allow all sub-commands
882-
const subCommandsFirstWordOnly = subCommands.map(command => command.split(' ')[0]);
884+
const subCommandsFirstWordOnly = Array.from(new Set(subCommands.map(command => command.split(' ')[0])));
883885
let subCommandLabel: string;
884886
let subCommandTooltip: string;
885887
if (subCommandsFirstWordOnly.length === 1) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ suite('RunInTerminalTool', () => {
367367
const customActions = result!.confirmationMessages!.terminalCustomActions!;
368368
strictEqual(customActions.length, 3, 'Expected 3 custom actions');
369369

370-
strictEqual(customActions[0].label, 'Always Allow Commands: npm, npm');
370+
strictEqual(customActions[0].label, 'Always Allow Command: npm');
371371
strictEqual(customActions[0].data.type, 'newRule');
372372

373373
strictEqual(customActions[1].label, 'Always Allow Full Command Line: npm install &&& npm run build');

0 commit comments

Comments
 (0)