Skip to content

Commit e358157

Browse files
committed
Add header for execute shell command
1 parent 69de65c commit e358157

File tree

4 files changed

+94
-30
lines changed

4 files changed

+94
-30
lines changed

packages/core/src/amazonq/webview/ui/apps/cwChatConnector.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class Connector extends BaseConnector {
325325

326326
if (
327327
!this.onChatAnswerUpdated ||
328-
!['accept-code-diff', 'reject-code-diff', 'confirm-tool-use'].includes(action.id)
328+
!['accept-code-diff', 'reject-code-diff', 'run-shell-command', 'reject-shell-command'].includes(action.id)
329329
) {
330330
return
331331
}
@@ -363,17 +363,27 @@ export class Connector extends BaseConnector {
363363
answer.body = ' '
364364
}
365365
break
366-
case 'confirm-tool-use':
367-
answer.buttons = [
368-
{
369-
keepCardAfterClick: true,
370-
text: 'Confirmed',
371-
id: 'confirmed-tool-use',
366+
case 'run-shell-command':
367+
answer.header = {
368+
icon: 'code-block' as MynahIconsType,
369+
body: 'shell',
370+
status: {
371+
icon: 'ok' as MynahIconsType,
372+
text: 'Accepted',
372373
status: 'success',
373-
position: 'outside',
374-
disabled: true,
375374
},
376-
]
375+
}
376+
break
377+
case 'reject-shell-command':
378+
answer.header = {
379+
icon: 'code-block' as MynahIconsType,
380+
body: 'shell',
381+
status: {
382+
icon: 'cancel' as MynahIconsType,
383+
text: 'Rejected',
384+
status: 'error',
385+
},
386+
}
377387
break
378388
default:
379389
break

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,20 +818,35 @@ export class ChatController {
818818
}
819819
}
820820

821+
private async rejectShellCommand(message: CustomFormActionMessage) {
822+
const triggerId = randomUUID()
823+
this.triggerEventsStorage.addTriggerEvent({
824+
id: triggerId,
825+
tabID: message.tabID,
826+
message: undefined,
827+
type: 'chat_message',
828+
context: undefined,
829+
})
830+
await this.generateStaticTextResponse('reject-shell-command', triggerId)
831+
}
832+
821833
private async processCustomFormAction(message: CustomFormActionMessage) {
822834
switch (message.action.id) {
823835
case 'submit-create-prompt':
824836
await this.handleCreatePrompt(message)
825837
break
826838
case 'accept-code-diff':
827-
case 'confirm-tool-use':
839+
case 'run-shell-command':
828840
case 'generic-tool-execution':
829841
await this.closeDiffView()
830842
await this.processToolUseMessage(message)
831843
break
832844
case 'reject-code-diff':
833845
await this.closeDiffView()
834846
break
847+
case 'reject-shell-command':
848+
await this.rejectShellCommand(message)
849+
break
835850
case 'tool-unavailable':
836851
await this.processUnavailableToolUseMessage(message)
837852
break

packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ import { noWriteTools, tools } from '../../../constants'
5050
import { Change } from 'diff'
5151
import { FsWriteParams } from '../../../tools/fsWrite'
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

5560
export type MessengerResponseType = {
5661
$metadata: { requestId?: string; httpStatusCode?: number }
@@ -269,12 +274,20 @@ export class Messenger {
269274
}
270275

271276
if (!validation.requiresAcceptance) {
272-
// 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.
273-
this.dispatcher.sendCustomFormActionMessage(
274-
new CustomFormActionMessage(tabID, {
275-
id: 'generic-tool-execution',
276-
})
277-
)
277+
// 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.
278+
if (tool.type === ToolType.ExecuteBash) {
279+
this.dispatcher.sendCustomFormActionMessage(
280+
new CustomFormActionMessage(tabID, {
281+
id: 'run-shell-command',
282+
})
283+
)
284+
} else {
285+
this.dispatcher.sendCustomFormActionMessage(
286+
new CustomFormActionMessage(tabID, {
287+
id: 'generic-tool-execution',
288+
})
289+
)
290+
}
278291
}
279292
} else {
280293
// TODO: Handle the error
@@ -500,12 +513,28 @@ export class Messenger {
500513
) {
501514
const buttons: ChatItemButton[] = []
502515
let fileList: ChatItemContent['fileList'] = undefined
503-
if (validation.requiresAcceptance && toolUse?.name === ToolType.ExecuteBash) {
504-
buttons.push({
505-
id: 'confirm-tool-use',
506-
text: 'Confirm',
507-
status: 'info',
508-
})
516+
let shellCommandHeader = undefined
517+
if (toolUse?.name === ToolType.ExecuteBash && message.startsWith('```shell')) {
518+
if (validation.requiresAcceptance) {
519+
buttons.push({
520+
id: 'run-shell-command',
521+
text: 'Run',
522+
status: 'main',
523+
icon: 'play' as MynahIconsType,
524+
})
525+
buttons.push({
526+
id: 'reject-shell-command',
527+
text: 'Reject',
528+
status: 'clear',
529+
icon: 'cancel' as MynahIconsType,
530+
})
531+
}
532+
533+
shellCommandHeader = {
534+
icon: 'code-block' as MynahIconsType,
535+
body: 'shell',
536+
buttons: buttons,
537+
}
509538

510539
if (validation.warning) {
511540
message = validation.warning + message
@@ -564,16 +593,23 @@ export class Messenger {
564593
codeBlockLanguage: undefined,
565594
contextList: undefined,
566595
canBeVoted: false,
567-
buttons: toolUse?.name === ToolType.FsWrite ? undefined : buttons,
568-
fullWidth: toolUse?.name === ToolType.FsWrite,
569-
padding: !(toolUse?.name === ToolType.FsWrite),
596+
buttons:
597+
toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash
598+
? undefined
599+
: buttons,
600+
fullWidth: toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash,
601+
padding: !(toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash),
570602
header:
571603
toolUse?.name === ToolType.FsWrite
572604
? { icon: 'code-block' as MynahIconsType, buttons: buttons, fileList: fileList }
573-
: undefined,
605+
: toolUse?.name === ToolType.ExecuteBash
606+
? shellCommandHeader
607+
: undefined,
574608
codeBlockActions:
575609
// eslint-disable-next-line unicorn/no-null, prettier/prettier
576-
toolUse?.name === ToolType.FsWrite ? { 'insert-to-cursor': null, copy: null } : undefined,
610+
toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash
611+
? { 'insert-to-cursor': null, copy: null }
612+
: undefined,
577613
},
578614
tabID
579615
)
@@ -625,6 +661,10 @@ export class Messenger {
625661
]
626662
followUpsHeader = 'Try Examples:'
627663
break
664+
case 'reject-shell-command':
665+
// need to update the string later
666+
message = 'The shell command execution rejected. Abort.'
667+
break
628668
}
629669

630670
this.dispatcher.sendChatMessage(

packages/core/src/codewhispererChat/tools/executeBash.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ export class ExecuteBash {
327327
}
328328

329329
public queueDescription(updates: Writable): void {
330-
updates.write(`I will run the following shell command:\n`)
331330
updates.write('```shell\n' + this.command + '\n```')
332331
updates.end()
333332
}

0 commit comments

Comments
 (0)