Skip to content

Commit 367e4e5

Browse files
authored
Merge pull request microsoft#262895 from microsoft/tyriar/refine_telemetry
Refine sub-command telemetry, trust it and shell/prompt types
2 parents 8fc809f + 19a3958 commit 367e4e5

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

src/vs/workbench/contrib/terminal/browser/terminalTelemetry.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Event } from '../../../../base/common/event.js';
1010
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
1111
import { basename } from '../../../../base/common/path.js';
1212
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';
13+
import { TelemetryTrustedValue } from '../../../../platform/telemetry/common/telemetryUtils.js';
1314
import { TerminalCapability } from '../../../../platform/terminal/common/capabilities/capabilities.js';
1415
import { TerminalLocation, type IShellLaunchConfig, type ShellIntegrationInjectionFailureReason } from '../../../../platform/terminal/common/terminal.js';
1516
import type { IWorkbenchContribution } from '../../../common/contributions.js';
@@ -66,8 +67,8 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
6667
type TerminalCreationTelemetryData = {
6768
location: string;
6869

69-
shellType: string;
70-
promptType: string | undefined;
70+
shellType: TelemetryTrustedValue<string>;
71+
promptType: TelemetryTrustedValue<string | undefined>;
7172

7273
isCustomPtyImplementation: boolean;
7374
isExtensionOwnedTerminal: boolean;
@@ -107,8 +108,8 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
107108
? (isInAuxWindow ? 'editor-auxwindow' : 'editor')
108109
: 'unknown'),
109110

110-
shellType: getSanitizedShellType(slc),
111-
promptType: commandDetection?.promptType,
111+
shellType: new TelemetryTrustedValue(getSanitizedShellType(slc)),
112+
promptType: new TelemetryTrustedValue(commandDetection?.promptType),
112113

113114
isCustomPtyImplementation: !!slc.customPtyImplementation,
114115
isExtensionOwnedTerminal: !!slc.isExtensionOwnedTerminal,

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js';
7+
import { TelemetryTrustedValue } from '../../../../../platform/telemetry/common/telemetryUtils.js';
78
import type { ITerminalInstance } from '../../../terminal/browser/terminal.js';
89
import { ShellIntegrationQuality } from './toolTerminalCreator.js';
910

@@ -21,41 +22,42 @@ export class RunInTerminalToolTelemetry {
2122
autoApproveDefault: boolean | undefined;
2223
}) {
2324
const subCommandsSanitized = state.subCommands.map(e => {
24-
let commandName = e.split(' ')[0].toLowerCase();
25-
if (!commandAllowList.has(commandName)) {
26-
if (/[\\\/]/.test(commandName)) {
27-
commandName = '(unknown:path)';
28-
} else if (/^(?:[A-Z][a-z0-9]+)+(?:-(?:[A-Z][a-z0-9]+))*$/.test(commandName)) {
29-
commandName = '(unknown:pwsh)';
30-
} else if (/^[a-z0-9_-]+$/i.test(commandName)) {
25+
const commandName = e.split(' ')[0];
26+
let sanitizedCommandName = commandName.toLowerCase();
27+
if (!commandAllowList.has(sanitizedCommandName)) {
28+
if (/^(?:[A-Z][a-z0-9]+)+(?:-(?:[A-Z][a-z0-9]+))*$/.test(commandName)) {
29+
sanitizedCommandName = '(unknown:pwsh)';
30+
} else if (/^[a-z0-9_\-\.\\\/:;]+$/i.test(commandName)) {
3131
const properties: string[] = [];
3232
if (/[a-z]/.test(commandName)) {
33-
properties.push('alpha_lowercase');
33+
properties.push('ascii_lower');
3434
}
3535
if (/[A-Z]/.test(commandName)) {
36-
properties.push('alpha_uppercase');
36+
properties.push('ascii_upper');
3737
}
3838
if (/[0-9]/.test(commandName)) {
3939
properties.push('numeric');
4040
}
41-
if (commandName.includes('-')) {
42-
properties.push('hyphen');
41+
const chars: string[] = [];
42+
for (const c of ['.', '-', '_', '/', '\\', ':', ';']) {
43+
if (commandName.includes(c)) {
44+
chars.push(c);
45+
}
4346
}
44-
if (commandName.includes('_')) {
45-
properties.push('underscore');
46-
}
47-
commandName = `(unknown:${properties.join(',')})`;
47+
sanitizedCommandName = `(unknown:${properties.join(',')}:${chars.join('')})`;
48+
} else if (/[^\x00-\x7F]/.test(commandName)) {
49+
sanitizedCommandName = '(unknown:unicode)';
4850
} else {
49-
commandName = '(unknown)';
51+
sanitizedCommandName = '(unknown)';
5052
}
5153
}
52-
return commandName;
54+
return sanitizedCommandName;
5355
});
5456

5557
type TelemetryEvent = {
5658
terminalToolSessionId: string | undefined;
5759

58-
subCommands: string;
60+
subCommands: TelemetryTrustedValue<string>;
5961
autoApproveResult: string;
6062
autoApproveReason: string | undefined;
6163
autoApproveDefault: boolean | undefined;
@@ -74,7 +76,7 @@ export class RunInTerminalToolTelemetry {
7476

7577
this._telemetryService.publicLog2<TelemetryEvent, TelemetryClassification>('toolUse.runInTerminal.prepare', {
7678
terminalToolSessionId: state.terminalToolSessionId,
77-
subCommands: JSON.stringify(subCommandsSanitized),
79+
subCommands: new TelemetryTrustedValue(JSON.stringify(subCommandsSanitized)),
7880
autoApproveResult: state.autoApproveResult,
7981
autoApproveReason: state.autoApproveReason,
8082
autoApproveDefault: state.autoApproveDefault,

0 commit comments

Comments
 (0)