Skip to content

Commit 6baf872

Browse files
authored
Merge branch 'feature/agentic-chat' into feature/agentic-chat-working-stop
2 parents b43f2a0 + 1667c94 commit 6baf872

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
@@ -314,7 +314,7 @@ export class Connector extends BaseConnector {
314314

315315
if (
316316
!this.onChatAnswerUpdated ||
317-
!['accept-code-diff', 'reject-code-diff', 'confirm-tool-use'].includes(action.id)
317+
!['accept-code-diff', 'reject-code-diff', 'run-shell-command', 'reject-shell-command'].includes(action.id)
318318
) {
319319
return
320320
}
@@ -352,17 +352,27 @@ export class Connector extends BaseConnector {
352352
answer.body = ' '
353353
}
354354
break
355-
case 'confirm-tool-use':
356-
answer.buttons = [
357-
{
358-
keepCardAfterClick: true,
359-
text: 'Confirmed',
360-
id: 'confirmed-tool-use',
355+
case 'run-shell-command':
356+
answer.header = {
357+
icon: 'code-block' as MynahIconsType,
358+
body: 'shell',
359+
status: {
360+
icon: 'ok' as MynahIconsType,
361+
text: 'Accepted',
361362
status: 'success',
362-
position: 'outside',
363-
disabled: true,
364363
},
365-
]
364+
}
365+
break
366+
case 'reject-shell-command':
367+
answer.header = {
368+
icon: 'code-block' as MynahIconsType,
369+
body: 'shell',
370+
status: {
371+
icon: 'cancel' as MynahIconsType,
372+
text: 'Rejected',
373+
status: 'error',
374+
},
375+
}
366376
break
367377
default:
368378
break

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,20 +813,35 @@ export class ChatController {
813813
}
814814
}
815815

816+
private async rejectShellCommand(message: CustomFormActionMessage) {
817+
const triggerId = randomUUID()
818+
this.triggerEventsStorage.addTriggerEvent({
819+
id: triggerId,
820+
tabID: message.tabID,
821+
message: undefined,
822+
type: 'chat_message',
823+
context: undefined,
824+
})
825+
await this.generateStaticTextResponse('reject-shell-command', triggerId)
826+
}
827+
816828
private async processCustomFormAction(message: CustomFormActionMessage) {
817829
switch (message.action.id) {
818830
case 'submit-create-prompt':
819831
await this.handleCreatePrompt(message)
820832
break
821833
case 'accept-code-diff':
822-
case 'confirm-tool-use':
834+
case 'run-shell-command':
823835
case 'generic-tool-execution':
824836
await this.closeDiffView()
825837
await this.processToolUseMessage(message)
826838
break
827839
case 'reject-code-diff':
828840
await this.closeDiffView()
829841
break
842+
case 'reject-shell-command':
843+
await this.rejectShellCommand(message)
844+
break
830845
case 'tool-unavailable':
831846
await this.processUnavailableToolUseMessage(message)
832847
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 { Change } from 'diff'
5050
import { FsWriteParams } from '../../../tools/fsWrite'
5151
import { 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

5560
export 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(

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)