Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions packages/core/src/amazonq/webview/ui/apps/cwChatConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class Connector extends BaseConnector {

if (
!this.onChatAnswerUpdated ||
!['accept-code-diff', 'reject-code-diff', 'confirm-tool-use'].includes(action.id)
!['accept-code-diff', 'reject-code-diff', 'run-shell-command', 'reject-shell-command'].includes(action.id)
) {
return
}
Expand Down Expand Up @@ -363,17 +363,27 @@ export class Connector extends BaseConnector {
answer.body = ' '
}
break
case 'confirm-tool-use':
answer.buttons = [
{
keepCardAfterClick: true,
text: 'Confirmed',
id: 'confirmed-tool-use',
case 'run-shell-command':
answer.header = {
icon: 'code-block' as MynahIconsType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this icon and body. Please follow same approach as accept-code-diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we don't need body and icon? or i missed some UI?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the tyrone StoreItem to get the body and icon

body: 'shell',
status: {
icon: 'ok' as MynahIconsType,
text: 'Accepted',
status: 'success',
position: 'outside',
disabled: true,
},
]
}
break
case 'reject-shell-command':
answer.header = {
icon: 'code-block' as MynahIconsType,
body: 'shell',
status: {
icon: 'cancel' as MynahIconsType,
text: 'Rejected',
status: 'error',
},
}
break
default:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,20 +818,35 @@ export class ChatController {
}
}

private async rejectShellCommand(message: CustomFormActionMessage) {
const triggerId = randomUUID()
this.triggerEventsStorage.addTriggerEvent({
id: triggerId,
tabID: message.tabID,
message: undefined,
type: 'chat_message',
context: undefined,
})
await this.generateStaticTextResponse('reject-shell-command', triggerId)
}

private async processCustomFormAction(message: CustomFormActionMessage) {
switch (message.action.id) {
case 'submit-create-prompt':
await this.handleCreatePrompt(message)
break
case 'accept-code-diff':
case 'confirm-tool-use':
case 'run-shell-command':
case 'generic-tool-execution':
await this.closeDiffView()
await this.processToolUseMessage(message)
break
case 'reject-code-diff':
await this.closeDiffView()
break
case 'reject-shell-command':
await this.rejectShellCommand(message)
break
case 'tool-unavailable':
await this.processUnavailableToolUseMessage(message)
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@
import { Change } from 'diff'
import { FsWriteParams } from '../../../tools/fsWrite'

export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
export type StaticTextResponseType =
| 'quick-action-help'
| 'onboarding-help'
| 'transform'
| 'help'
| 'reject-shell-command'

export type MessengerResponseType = {
$metadata: { requestId?: string; httpStatusCode?: number }
Expand Down Expand Up @@ -269,12 +274,20 @@
}

if (!validation.requiresAcceptance) {
// 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.
this.dispatcher.sendCustomFormActionMessage(
new CustomFormActionMessage(tabID, {
id: 'generic-tool-execution',
})
)
// 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.
if (tool.type === ToolType.ExecuteBash) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const actionId = tool.type === ToolType.ExecuteBash 
    ? 'run-shell-command' 
    : 'generic-tool-execution'

this.dispatcher.sendCustomFormActionMessage(
    new CustomFormActionMessage(tabID, { id: actionId })
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do it in next pr.

this.dispatcher.sendCustomFormActionMessage(
new CustomFormActionMessage(tabID, {
id: 'run-shell-command',
})
)
} else {
this.dispatcher.sendCustomFormActionMessage(
new CustomFormActionMessage(tabID, {
id: 'generic-tool-execution',
})
)
}
}
} else {
// TODO: Handle the error
Expand Down Expand Up @@ -500,12 +513,28 @@
) {
const buttons: ChatItemButton[] = []
let fileList: ChatItemContent['fileList'] = undefined
if (validation.requiresAcceptance && toolUse?.name === ToolType.ExecuteBash) {
buttons.push({
id: 'confirm-tool-use',
text: 'Confirm',
status: 'info',
})
let shellCommandHeader = undefined
if (toolUse?.name === ToolType.ExecuteBash && message.startsWith('```shell')) {
if (validation.requiresAcceptance) {
buttons.push({
id: 'run-shell-command',
text: 'Run',
status: 'main',
icon: 'play' as MynahIconsType,
})
buttons.push({
id: 'reject-shell-command',
text: 'Reject',
status: 'clear',
icon: 'cancel' as MynahIconsType,
})
}

shellCommandHeader = {
icon: 'code-block' as MynahIconsType,
body: 'shell',
buttons: buttons,
}

if (validation.warning) {
message = validation.warning + message
Expand Down Expand Up @@ -564,16 +593,23 @@
codeBlockLanguage: undefined,
contextList: undefined,
canBeVoted: false,
buttons: toolUse?.name === ToolType.FsWrite ? undefined : buttons,
fullWidth: toolUse?.name === ToolType.FsWrite,
padding: !(toolUse?.name === ToolType.FsWrite),
buttons:
Copy link
Contributor

@laileni-aws laileni-aws Apr 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep buttons: undefined. Buttons is used only by fsWrite and ExecuteBash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean the current check is right, but we can simplify it, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if yes, then i can do it in next pr.

toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash
? undefined
: buttons,
fullWidth: toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash,
padding: !(toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash),
header:
toolUse?.name === ToolType.FsWrite
? { icon: 'code-block' as MynahIconsType, buttons: buttons, fileList: fileList }
: undefined,
: toolUse?.name === ToolType.ExecuteBash
? shellCommandHeader
: undefined,
codeBlockActions:
// eslint-disable-next-line unicorn/no-null, prettier/prettier
toolUse?.name === ToolType.FsWrite ? { 'insert-to-cursor': null, copy: null } : undefined,
toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash
? { 'insert-to-cursor': null, copy: null }

Check failure on line 611 in packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Use `undefined` instead of `null`

Check failure on line 611 in packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Use `undefined` instead of `null`
: undefined,
},
tabID
)
Expand Down Expand Up @@ -625,6 +661,10 @@
]
followUpsHeader = 'Try Examples:'
break
case 'reject-shell-command':
// need to update the string later
message = 'The shell command execution rejected. Abort.'
break
}

this.dispatcher.sendChatMessage(
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/codewhispererChat/tools/executeBash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ export class ExecuteBash {
}

public queueDescription(updates: Writable): void {
updates.write(`I will run the following shell command:\n`)
updates.write('```shell\n' + this.command + '\n```')
updates.end()
}
Expand Down
Loading