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
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/codewhispererChat/tools/chatStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/codewhispererChat/tools/executeBash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const mutateCommandWarningMessage = 'Mutation command:\n\n'
export interface ExecuteBashParams {
command: string
cwd?: string
explanation?: string
}

export interface CommandValidation {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/codewhispererChat/tools/fsWrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Change, diffLines } from 'diff'

interface BaseParams {
path: string
explanation?: string
}

export interface CreateParams extends BaseParams {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/codewhispererChat/tools/tool_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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`."
Expand Down
Loading