@@ -186,15 +186,22 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
186186 } ) ;
187187 const language = os === OperatingSystem . Windows ? 'pwsh' : 'sh' ;
188188
189+ const instance = context . chatSessionId ? this . _sessionTerminalAssociations . get ( context . chatSessionId ) ?. instance : undefined ;
190+ let toolEditedCommand : string | undefined = await this . _rewriteCommandIfNeeded ( args , instance , shell ) ;
191+ if ( toolEditedCommand === args . command ) {
192+ toolEditedCommand = undefined ;
193+ }
194+
189195 let confirmationMessages : IToolConfirmationMessages | undefined ;
190196 if ( this . _alternativeRecommendation ) {
191197 confirmationMessages = undefined ;
192198 } else {
193- const subCommands = splitCommandLineIntoSubCommands ( args . command , shell , os ) ;
199+ const actualCommand = toolEditedCommand ?? args . command ;
200+ const subCommands = splitCommandLineIntoSubCommands ( actualCommand , shell , os ) ;
194201 const inlineSubCommands = subCommands . map ( e => Array . from ( extractInlineSubCommands ( e , shell , os ) ) ) . flat ( ) ;
195202 const allSubCommands = [ ...subCommands , ...inlineSubCommands ] ;
196203 const subCommandResults = allSubCommands . map ( e => this . _commandLineAutoApprover . isCommandAutoApproved ( e , shell , os ) ) ;
197- const commandLineResult = this . _commandLineAutoApprover . isCommandLineAutoApproved ( args . command ) ;
204+ const commandLineResult = this . _commandLineAutoApprover . isCommandLineAutoApproved ( actualCommand ) ;
198205 const autoApproveReasons : string [ ] = [
199206 ...subCommandResults . map ( e => e . reason ) ,
200207 commandLineResult . reason ,
@@ -233,12 +240,6 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
233240 } ;
234241 }
235242
236- const instance = context . chatSessionId ? this . _sessionTerminalAssociations . get ( context . chatSessionId ) ?. instance : undefined ;
237- let toolEditedCommand : string | undefined = await this . _rewriteCommandIfNeeded ( args , instance , shell ) ;
238- if ( toolEditedCommand === args . command ) {
239- toolEditedCommand = undefined ;
240- }
241-
242243 return {
243244 confirmationMessages,
244245 presentation,
0 commit comments