Skip to content

Commit 02b411e

Browse files
authored
Merge pull request #260739 from microsoft/tyriar/260573_3
Make link tooltips more user friendly
2 parents 7ca850c + e6ac857 commit 02b411e

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ConfigurationTarget, IConfigurationService, type IConfigurationValue }
1212
import { TerminalChatAgentToolsSettingId } from '../common/terminalChatAgentToolsConfiguration.js';
1313
import { isPowerShell } from './runInTerminalHelpers.js';
1414

15-
interface IAutoApproveRule {
15+
export interface IAutoApproveRule {
1616
regex: RegExp;
1717
regexCaseInsensitive: RegExp;
1818
sourceText: string;

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type { XtermTerminal } from '../../../../terminal/browser/xterm/xtermTerm
2828
import { ITerminalProfileResolverService } from '../../../../terminal/common/terminal.js';
2929
import { getRecommendedToolsOverRunInTerminal } from '../alternativeRecommendation.js';
3030
import { getOutput } from '../bufferOutputPolling.js';
31-
import { CommandLineAutoApprover, type ICommandApprovalResultWithReason } from '../commandLineAutoApprover.js';
31+
import { CommandLineAutoApprover, type IAutoApproveRule, type ICommandApprovalResult, type ICommandApprovalResultWithReason } from '../commandLineAutoApprover.js';
3232
import { BasicExecuteStrategy } from '../executeStrategy/basicExecuteStrategy.js';
3333
import type { ITerminalExecuteStrategy } from '../executeStrategy/executeStrategy.js';
3434
import { NoneExecuteStrategy } from '../executeStrategy/noneExecuteStrategy.js';
@@ -39,6 +39,8 @@ import { ShellIntegrationQuality, ToolTerminalCreator, type IToolTerminal } from
3939
import { Codicon } from '../../../../../../base/common/codicons.js';
4040
import { OutputMonitor } from '../outputMonitor.js';
4141
import type { TerminalNewAutoApproveButtonData } from '../../../../chat/browser/chatContentParts/toolInvocationParts/chatTerminalToolSubPart.js';
42+
import type { SingleOrMany } from '../../../../../../base/common/types.js';
43+
import { asArray } from '../../../../../../base/common/arrays.js';
4244

4345
const TERMINAL_SESSION_STORAGE_KEY = 'chat.terminalSessions';
4446

@@ -253,20 +255,25 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
253255
}
254256
}
255257

258+
function formatRuleLinks(result: SingleOrMany<{ result: ICommandApprovalResult; rule?: IAutoApproveRule; reason: string }>): string {
259+
return asArray(result).map(e => {
260+
return `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget} "${localize('ruleTooltip', 'View rule in settings')}")`;
261+
}).join(', ');
262+
}
256263
if (isAutoApproved) {
257264
switch (autoApproveReason) {
258265
case 'commandLine': {
259266
if (commandLineResult.rule) {
260-
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', `[\`${commandLineResult.rule.sourceText}\`](settings_${commandLineResult.rule.sourceTarget})`)}_`);
267+
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', formatRuleLinks(commandLineResult))}_`);
261268
}
262269
break;
263270
}
264271
case 'subCommand': {
265-
const uniqueRules = Array.from(new Set(subCommandResults.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`)));
272+
const uniqueRules = Array.from(new Set(subCommandResults));
266273
if (uniqueRules.length === 1) {
267-
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', uniqueRules[0])}_`);
274+
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', formatRuleLinks(uniqueRules))}_`);
268275
} else if (uniqueRules.length > 1) {
269-
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rules', 'Auto approved by rules {0}', uniqueRules.join(', '))}_`);
276+
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rules', 'Auto approved by rules {0}', formatRuleLinks(uniqueRules))}_`);
270277
}
271278
break;
272279
}
@@ -275,24 +282,24 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
275282
switch (autoApproveReason) {
276283
case 'commandLine': {
277284
if (commandLineResult.rule) {
278-
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', `[\`${commandLineResult.rule.sourceText}\`](settings_${commandLineResult.rule.sourceTarget})`)}_`);
285+
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', formatRuleLinks(commandLineResult))}_`);
279286
}
280287
break;
281288
}
282289
case 'subCommand': {
283290
const deniedRules = subCommandResults.filter(e => e.result === 'denied');
284-
const uniqueRules = Array.from(new Set(deniedRules.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`)));
291+
const uniqueRules = Array.from(new Set(deniedRules));
285292
if (uniqueRules.length === 1) {
286-
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', uniqueRules[0])}_`);
293+
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', formatRuleLinks(uniqueRules))}_`);
287294
} else if (uniqueRules.length > 1) {
288-
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rules', 'Auto approval denied by rules {0}', uniqueRules.join(', '))}_`);
295+
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rules', 'Auto approval denied by rules {0}', formatRuleLinks(uniqueRules))}_`);
289296
}
290297
break;
291298
}
292299
}
293300
}
294301

295-
// TODO: Surface reason on tool part https://github.com/microsoft/vscode/issues/256780
302+
// Log detailed auto approval reasoning
296303
for (const reason of autoApproveReasons) {
297304
this._logService.info(`- ${reason}`);
298305
}

0 commit comments

Comments
 (0)