@@ -50,7 +50,12 @@ import { Change } from 'diff'
5050import { FsWriteParams } from '../../../tools/fsWrite'
5151import { AsyncEventProgressMessage } from '../../../../amazonq/commons/connector/connectorMessages'
5252
53- export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
53+ export type StaticTextResponseType =
54+ | 'quick-action-help'
55+ | 'onboarding-help'
56+ | 'transform'
57+ | 'help'
58+ | 'reject-shell-command'
5459
5560export type MessengerResponseType = {
5661 $metadata : { requestId ?: string ; httpStatusCode ?: number }
@@ -243,12 +248,20 @@ export class Messenger {
243248 await ToolUtils . queueDescription ( tool , chatStream )
244249
245250 if ( ! validation . requiresAcceptance ) {
246- // Need separate id for read tool and safe bash command execution as 'confirm-tool-use' id is required to change button status from `Confirm` to `Confirmed` state in cwChatConnector.ts which will impact generic tool execution.
247- this . dispatcher . sendCustomFormActionMessage (
248- new CustomFormActionMessage ( tabID , {
249- id : 'generic-tool-execution' ,
250- } )
251- )
251+ // Need separate id for read tool and safe bash command execution as 'run-shell-command' id is required to state in cwChatConnector.ts which will impact generic tool execution.
252+ if ( tool . type === ToolType . ExecuteBash ) {
253+ this . dispatcher . sendCustomFormActionMessage (
254+ new CustomFormActionMessage ( tabID , {
255+ id : 'run-shell-command' ,
256+ } )
257+ )
258+ } else {
259+ this . dispatcher . sendCustomFormActionMessage (
260+ new CustomFormActionMessage ( tabID , {
261+ id : 'generic-tool-execution' ,
262+ } )
263+ )
264+ }
252265 }
253266 } else {
254267 // TODO: Handle the error
@@ -453,12 +466,28 @@ export class Messenger {
453466 ) {
454467 const buttons : ChatItemButton [ ] = [ ]
455468 let fileList : ChatItemContent [ 'fileList' ] = undefined
456- if ( validation . requiresAcceptance && toolUse ?. name === ToolType . ExecuteBash ) {
457- buttons . push ( {
458- id : 'confirm-tool-use' ,
459- text : 'Confirm' ,
460- status : 'info' ,
461- } )
469+ let shellCommandHeader = undefined
470+ if ( toolUse ?. name === ToolType . ExecuteBash && message . startsWith ( '```shell' ) ) {
471+ if ( validation . requiresAcceptance ) {
472+ buttons . push ( {
473+ id : 'run-shell-command' ,
474+ text : 'Run' ,
475+ status : 'main' ,
476+ icon : 'play' as MynahIconsType ,
477+ } )
478+ buttons . push ( {
479+ id : 'reject-shell-command' ,
480+ text : 'Reject' ,
481+ status : 'clear' ,
482+ icon : 'cancel' as MynahIconsType ,
483+ } )
484+ }
485+
486+ shellCommandHeader = {
487+ icon : 'code-block' as MynahIconsType ,
488+ body : 'shell' ,
489+ buttons : buttons ,
490+ }
462491
463492 if ( validation . warning ) {
464493 message = validation . warning + message
@@ -517,16 +546,23 @@ export class Messenger {
517546 codeBlockLanguage : undefined ,
518547 contextList : undefined ,
519548 canBeVoted : false ,
520- buttons : toolUse ?. name === ToolType . FsWrite ? undefined : buttons ,
521- fullWidth : toolUse ?. name === ToolType . FsWrite ,
522- padding : ! ( toolUse ?. name === ToolType . FsWrite ) ,
549+ buttons :
550+ toolUse ?. name === ToolType . FsWrite || toolUse ?. name === ToolType . ExecuteBash
551+ ? undefined
552+ : buttons ,
553+ fullWidth : toolUse ?. name === ToolType . FsWrite || toolUse ?. name === ToolType . ExecuteBash ,
554+ padding : ! ( toolUse ?. name === ToolType . FsWrite || toolUse ?. name === ToolType . ExecuteBash ) ,
523555 header :
524556 toolUse ?. name === ToolType . FsWrite
525557 ? { icon : 'code-block' as MynahIconsType , buttons : buttons , fileList : fileList }
526- : undefined ,
558+ : toolUse ?. name === ToolType . ExecuteBash
559+ ? shellCommandHeader
560+ : undefined ,
527561 codeBlockActions :
528562 // eslint-disable-next-line unicorn/no-null, prettier/prettier
529- toolUse ?. name === ToolType . FsWrite ? { 'insert-to-cursor' : null , copy : null } : undefined ,
563+ toolUse ?. name === ToolType . FsWrite || toolUse ?. name === ToolType . ExecuteBash
564+ ? { 'insert-to-cursor' : null , copy : null }
565+ : undefined ,
530566 } ,
531567 tabID
532568 )
@@ -578,6 +614,10 @@ export class Messenger {
578614 ]
579615 followUpsHeader = 'Try Examples:'
580616 break
617+ case 'reject-shell-command' :
618+ // need to update the string later
619+ message = 'The shell command execution rejected. Abort.'
620+ break
581621 }
582622
583623 this . dispatcher . sendChatMessage (
0 commit comments