Skip to content

Commit d7fe9b5

Browse files
committed
Add header for shell command
1 parent cc41a7f commit d7fe9b5

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ChatItemButton,
99
ChatItemFormItem,
1010
ChatItemType,
11+
MynahIcons,
1112
MynahIconsType,
1213
MynahUIDataModel,
1314
QuickActionCommand,
@@ -291,7 +292,7 @@ export class Connector extends BaseConnector {
291292

292293
if (
293294
!this.onChatAnswerUpdated ||
294-
!['accept-code-diff', 'reject-code-diff', 'confirm-tool-use'].includes(action.id)
295+
!['accept-code-diff', 'reject-code-diff', 'confirm-tool-use', 'run-shell-command'].includes(action.id)
295296
) {
296297
return
297298
}
@@ -341,6 +342,17 @@ export class Connector extends BaseConnector {
341342
},
342343
]
343344
break
345+
case 'run-shell-command':
346+
answer.header = {
347+
body: 'shell',
348+
icon: 'code-block' as MynahIconsType,
349+
status: {
350+
icon: MynahIcons.OK,
351+
text: 'Accepted',
352+
status: 'success',
353+
},
354+
}
355+
break
344356
default:
345357
break
346358
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ export class ChatController {
743743
break
744744
case 'accept-code-diff':
745745
case 'confirm-tool-use':
746+
case 'run-shell-command':
746747
case 'generic-tool-execution':
747748
await this.closeDiffView()
748749
await this.processToolUseMessage(message)

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,21 @@ export class Messenger {
438438
) {
439439
const buttons: ChatItemButton[] = []
440440
let fileList: ChatItemContent['fileList'] = undefined
441-
if (validation.requiresAcceptance && toolUse?.name === ToolType.ExecuteBash) {
442-
buttons.push({
443-
id: 'confirm-tool-use',
444-
text: 'Confirm',
445-
status: 'info',
446-
})
441+
let shellCommandHeader = undefined
442+
if (toolUse?.name === ToolType.ExecuteBash && message.startsWith('```shell')) {
443+
if (validation.requiresAcceptance) {
444+
buttons.push({
445+
id: 'run-shell-command',
446+
text: 'Run',
447+
icon: 'play' as MynahIconsType,
448+
})
449+
}
450+
451+
shellCommandHeader = {
452+
body: 'shell',
453+
icon: 'code-block' as MynahIconsType,
454+
buttons: buttons,
455+
}
447456

448457
if (validation.warning) {
449458
message = validation.warning + message
@@ -497,16 +506,23 @@ export class Messenger {
497506
codeBlockLanguage: undefined,
498507
contextList: undefined,
499508
canBeVoted: false,
500-
buttons: toolUse?.name === ToolType.FsWrite ? undefined : buttons,
501-
fullWidth: toolUse?.name === ToolType.FsWrite,
509+
buttons:
510+
toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash
511+
? undefined
512+
: buttons,
513+
fullWidth: toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash,
502514
padding: !(toolUse?.name === ToolType.FsWrite),
503515
header:
504516
toolUse?.name === ToolType.FsWrite
505517
? { icon: 'code-block' as MynahIconsType, buttons: buttons, fileList: fileList }
506-
: undefined,
518+
: toolUse?.name === ToolType.ExecuteBash
519+
? shellCommandHeader
520+
: undefined,
507521
codeBlockActions:
508522
// eslint-disable-next-line unicorn/no-null, prettier/prettier
509-
toolUse?.name === ToolType.FsWrite ? { 'insert-to-cursor': null, copy: null } : undefined,
523+
toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash
524+
? { 'insert-to-cursor': null, copy: null }
525+
: undefined,
510526
},
511527
tabID
512528
)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ export class ExecuteBash {
327327
}
328328

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

0 commit comments

Comments
 (0)