Skip to content

Commit 4cc64fc

Browse files
authored
feat(chat): Add explanation for tool invocation for fsWrite and executeBash (aws#7037)
## Problem - Multiple invocations of ExecuteBash and FsWrite can be confusing to the user ## Solution - Add explanation for tool invocation for fsWrite and executeBash [ <img width="374" alt="Screenshot 2025-04-14 at 1 57 11 PM" src="https://github.com/user-attachments/assets/fb0c2873-f2fe-4554-b448-be2c41f2ddea" /> ](url) --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 76b5607 commit 4cc64fc

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import { TabType } from '../../../../amazonq/webview/ui/storages/tabsStorage'
6161
import { ToolType, ToolUtils } from '../../../tools/toolUtils'
6262
import { ChatStream } from '../../../tools/chatStream'
6363
import path from 'path'
64-
import { CommandValidation } from '../../../tools/executeBash'
64+
import { CommandValidation, ExecuteBashParams } from '../../../tools/executeBash'
6565
import { extractErrorInfo } from '../../../../shared/utilities/messageUtil'
6666
import { noWriteTools, tools } from '../../../constants'
6767
import { Change } from 'diff'
@@ -306,12 +306,32 @@ export class Messenger {
306306
}
307307
const tool = ToolUtils.tryFromToolUse(toolUse)
308308
if ('type' in tool) {
309+
let explanation: string | undefined = undefined
309310
let changeList: Change[] | undefined = undefined
310311
let messageIdToUpdate: string | undefined = undefined
311312
const isReadOrList: boolean = [ToolType.FsRead, ToolType.ListDirectory].includes(
312313
tool.type
313314
)
314-
if (tool.type === ToolType.FsWrite) {
315+
if (tool.type === ToolType.ExecuteBash) {
316+
const input = toolUse.input as unknown as ExecuteBashParams
317+
if (input.explanation) {
318+
getLogger().debug(
319+
'Tool explanation: %s for executeBash toolUseId: %s',
320+
input.explanation,
321+
toolUse.toolUseId
322+
)
323+
explanation = input.explanation
324+
}
325+
} else if (tool.type === ToolType.FsWrite) {
326+
const input = toolUse.input as unknown as FsWriteParams
327+
if (input.explanation) {
328+
getLogger().debug(
329+
'Tool explanation: %s for fsWrite toolUseId: %s',
330+
input.explanation,
331+
toolUse.toolUseId
332+
)
333+
explanation = input.explanation
334+
}
315335
session.setShowDiffOnFileWrite(true)
316336
changeList = await tool.tool.getDiffChanges()
317337
}
@@ -353,7 +373,8 @@ export class Messenger {
353373
true,
354374
validation,
355375
isReadOrList,
356-
changeList
376+
changeList,
377+
explanation
357378
)
358379
await ToolUtils.queueDescription(tool, chatStream)
359380
if (session.messageIdToUpdate === undefined && tool.type === ToolType.FsRead) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class ChatStream extends Writable {
3232
private readonly validation: CommandValidation,
3333
private readonly isReadorList: boolean,
3434
private readonly changeList?: Change[],
35+
private readonly explanation?: string,
3536
private readonly logger = getLogger('chatStream')
3637
) {
3738
super()
@@ -41,7 +42,10 @@ export class ChatStream extends Writable {
4142
if (!emitEvent) {
4243
return
4344
}
44-
if (validation.requiresAcceptance) {
45+
if (this.explanation) {
46+
this.messenger.sendDirectiveMessage(tabID, triggerID, this.explanation)
47+
}
48+
if (validation.requiresAcceptance && this.toolUse?.name === 'executeBash') {
4549
this.messenger.sendDirectiveMessage(
4650
tabID,
4751
triggerID,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export const mutateCommandWarningMessage = 'Mutation command:\n\n'
113113
export interface ExecuteBashParams {
114114
command: string
115115
cwd?: string
116+
explanation?: string
116117
}
117118

118119
export interface CommandValidation {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Change, diffLines } from 'diff'
1212

1313
interface BaseParams {
1414
path: string
15+
explanation?: string
1516
}
1617

1718
export interface CreateParams extends BaseParams {

packages/core/src/codewhispererChat/tools/tool_index.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
"inputSchema": {
6666
"type": "object",
6767
"properties": {
68+
"explanation": {
69+
"description": "One sentence explanation as to why this tool is being used, and how it contributes to the goal.",
70+
"type": "string"
71+
},
6872
"command": {
6973
"type": "string",
7074
"description": "Bash command to execute"
@@ -83,10 +87,6 @@
8387
"inputSchema": {
8488
"type": "object",
8589
"properties": {
86-
"explanation": {
87-
"description": "One sentence explanation as to why this tool is being used, and how it contributes to the goal.",
88-
"type": "string"
89-
},
9090
"path": {
9191
"type": "string",
9292
"description": "Absolute path to a directory, e.g., `/repo`."

0 commit comments

Comments
 (0)