diff --git a/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts b/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts index 73be6f860cb..32376ad4945 100644 --- a/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts +++ b/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts @@ -61,7 +61,7 @@ import { TabType } from '../../../../amazonq/webview/ui/storages/tabsStorage' import { ToolType, ToolUtils } from '../../../tools/toolUtils' import { ChatStream } from '../../../tools/chatStream' import path from 'path' -import { CommandValidation } from '../../../tools/executeBash' +import { CommandValidation, ExecuteBashParams } from '../../../tools/executeBash' import { extractErrorInfo } from '../../../../shared/utilities/messageUtil' import { noWriteTools, tools } from '../../../constants' import { Change } from 'diff' @@ -306,12 +306,32 @@ export class Messenger { } const tool = ToolUtils.tryFromToolUse(toolUse) if ('type' in tool) { + let explanation: string | undefined = undefined let changeList: Change[] | undefined = undefined let messageIdToUpdate: string | undefined = undefined const isReadOrList: boolean = [ToolType.FsRead, ToolType.ListDirectory].includes( tool.type ) - if (tool.type === ToolType.FsWrite) { + if (tool.type === ToolType.ExecuteBash) { + const input = toolUse.input as unknown as ExecuteBashParams + if (input.explanation) { + getLogger().debug( + 'Tool explanation: %s for executeBash toolUseId: %s', + input.explanation, + toolUse.toolUseId + ) + explanation = input.explanation + } + } else if (tool.type === ToolType.FsWrite) { + const input = toolUse.input as unknown as FsWriteParams + if (input.explanation) { + getLogger().debug( + 'Tool explanation: %s for fsWrite toolUseId: %s', + input.explanation, + toolUse.toolUseId + ) + explanation = input.explanation + } session.setShowDiffOnFileWrite(true) changeList = await tool.tool.getDiffChanges() } @@ -353,7 +373,8 @@ export class Messenger { true, validation, isReadOrList, - changeList + changeList, + explanation ) await ToolUtils.queueDescription(tool, chatStream) if (session.messageIdToUpdate === undefined && tool.type === ToolType.FsRead) { diff --git a/packages/core/src/codewhispererChat/tools/chatStream.ts b/packages/core/src/codewhispererChat/tools/chatStream.ts index 9c9ecc9a03e..08d8b1fa13b 100644 --- a/packages/core/src/codewhispererChat/tools/chatStream.ts +++ b/packages/core/src/codewhispererChat/tools/chatStream.ts @@ -32,6 +32,7 @@ export class ChatStream extends Writable { private readonly validation: CommandValidation, private readonly isReadorList: boolean, private readonly changeList?: Change[], + private readonly explanation?: string, private readonly logger = getLogger('chatStream') ) { super() @@ -41,7 +42,10 @@ export class ChatStream extends Writable { if (!emitEvent) { return } - if (validation.requiresAcceptance) { + if (this.explanation) { + this.messenger.sendDirectiveMessage(tabID, triggerID, this.explanation) + } + if (validation.requiresAcceptance && this.toolUse?.name === 'executeBash') { this.messenger.sendDirectiveMessage( tabID, triggerID, diff --git a/packages/core/src/codewhispererChat/tools/executeBash.ts b/packages/core/src/codewhispererChat/tools/executeBash.ts index d21c3f2c6eb..77390ebdb7d 100644 --- a/packages/core/src/codewhispererChat/tools/executeBash.ts +++ b/packages/core/src/codewhispererChat/tools/executeBash.ts @@ -113,6 +113,7 @@ export const mutateCommandWarningMessage = 'Mutation command:\n\n' export interface ExecuteBashParams { command: string cwd?: string + explanation?: string } export interface CommandValidation { diff --git a/packages/core/src/codewhispererChat/tools/fsWrite.ts b/packages/core/src/codewhispererChat/tools/fsWrite.ts index dff68d4f425..7bef491e768 100644 --- a/packages/core/src/codewhispererChat/tools/fsWrite.ts +++ b/packages/core/src/codewhispererChat/tools/fsWrite.ts @@ -12,6 +12,7 @@ import { Change, diffLines } from 'diff' interface BaseParams { path: string + explanation?: string } export interface CreateParams extends BaseParams { diff --git a/packages/core/src/codewhispererChat/tools/tool_index.json b/packages/core/src/codewhispererChat/tools/tool_index.json index d1469238da8..b7079795660 100644 --- a/packages/core/src/codewhispererChat/tools/tool_index.json +++ b/packages/core/src/codewhispererChat/tools/tool_index.json @@ -65,6 +65,10 @@ "inputSchema": { "type": "object", "properties": { + "explanation": { + "description": "One sentence explanation as to why this tool is being used, and how it contributes to the goal.", + "type": "string" + }, "command": { "type": "string", "description": "Bash command to execute" @@ -83,10 +87,6 @@ "inputSchema": { "type": "object", "properties": { - "explanation": { - "description": "One sentence explanation as to why this tool is being used, and how it contributes to the goal.", - "type": "string" - }, "path": { "type": "string", "description": "Absolute path to a directory, e.g., `/repo`."