44 *--------------------------------------------------------------------------------------------*/
55
66import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js' ;
7+ import { TelemetryTrustedValue } from '../../../../../platform/telemetry/common/telemetryUtils.js' ;
78import type { ITerminalInstance } from '../../../terminal/browser/terminal.js' ;
89import { 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 - z 0 - 9 ] + ) + (?: - (?: [ A - Z ] [ a - z 0 - 9 ] + ) ) * $ / . test ( commandName ) ) {
29- commandName = '(unknown:pwsh)' ;
30- } else if ( / ^ [ a - z 0 - 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 - z 0 - 9 ] + ) + (?: - (?: [ A - Z ] [ a - z 0 - 9 ] + ) ) * $ / . test ( commandName ) ) {
29+ sanitizedCommandName = '(unknown:pwsh)' ;
30+ } else if ( / ^ [ a - z 0 - 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