Skip to content

Commit 95626e5

Browse files
committed
making updates optional for executeBash tool
1 parent 29bc7d4 commit 95626e5

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ import { ChatSession } from '../../clients/chat/v0/chat'
9090
import { ChatHistoryManager } from '../../storages/chatHistory'
9191
import { amazonQTabSuffix } from '../../../shared/constants'
9292
import { OutputKind } from '../../tools/toolShared'
93-
import { ToolUtils, Tool } from '../../tools/toolUtils'
93+
import { ToolUtils, Tool, ToolType } from '../../tools/toolUtils'
9494
import { ChatStream } from '../../tools/chatStream'
95-
import { FsWriteParams } from '../../tools/fsWrite'
95+
import { FsWrite, FsWriteParams } from '../../tools/fsWrite'
9696
import { tempDirPath } from '../../../shared/filesystemUtilities'
9797

9898
export interface ChatControllerMessagePublishers {
@@ -661,10 +661,6 @@ export class ChatController {
661661
toolUseId: toolUse.toolUseId,
662662
status: ToolResultStatus.SUCCESS,
663663
})
664-
// Close the diff view if User accept the generated code changes.
665-
if (vscode.window.tabGroups.activeTabGroup.activeTab?.label.includes(amazonQTabSuffix)) {
666-
await vscode.commands.executeCommand('workbench.action.closeActiveEditor')
667-
}
668664
} catch (e: any) {
669665
toolResults.push({
670666
content: [{ text: e.message }],
@@ -677,6 +673,13 @@ export class ChatController {
677673
toolResults.push(toolResult)
678674
}
679675

676+
if (toolUse.name === ToolType.FsWrite) {
677+
await vscode.commands.executeCommand(
678+
'vscode.open',
679+
vscode.Uri.file((toolUse.input as unknown as FsWriteParams).path)
680+
)
681+
}
682+
680683
await this.generateResponse(
681684
{
682685
message: '',
@@ -710,6 +713,13 @@ export class ChatController {
710713
})
711714
}
712715

716+
private async closeDiffView() {
717+
// Close the diff view if User reject the generated code changes.
718+
if (vscode.window.tabGroups.activeTabGroup.activeTab?.label.includes(amazonQTabSuffix)) {
719+
await vscode.commands.executeCommand('workbench.action.closeActiveEditor')
720+
}
721+
}
722+
713723
private async processCustomFormAction(message: CustomFormActionMessage) {
714724
switch (message.action.id) {
715725
case 'submit-create-prompt':
@@ -718,15 +728,11 @@ export class ChatController {
718728
case 'accept-code-diff':
719729
case 'confirm-tool-use':
720730
case 'generic-tool-execution':
731+
await this.closeDiffView()
721732
await this.processToolUseMessage(message)
722733
break
723734
case 'reject-code-diff':
724-
// Close the diff view if User reject the generated code changes.
725-
if (vscode.window.tabGroups.activeTabGroup.activeTab?.label.includes(amazonQTabSuffix)) {
726-
await vscode.commands.executeCommand('workbench.action.closeActiveEditor')
727-
}
728-
// TODO: Do session cleanUp.
729-
getLogger().info('Generated response is rejected')
735+
await this.closeDiffView()
730736
break
731737
default:
732738
getLogger().warn(`Unhandled action: ${message.action.id}`)
@@ -771,13 +777,9 @@ export class ChatController {
771777
}
772778
const input = clonedToolUse.input as unknown as FsWriteParams
773779
input.path = tempFilePath
774-
const result = ToolUtils.tryFromToolUse(clonedToolUse)
775-
if (!('type' in result)) {
776-
return
777-
}
778-
const tool: Tool = result
779-
await ToolUtils.validate(tool)
780-
await ToolUtils.invoke(tool)
780+
781+
const fsWrite = new FsWrite(input)
782+
await fsWrite.invoke()
781783

782784
// Check if fileExists=false, If yes, return instead of showing broken diff experience.
783785
if (!tempFilePath) {

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ export class ExecuteBash {
6767

6868
public async invoke(updates?: Writable): Promise<InvokeOutput> {
6969
this.logger.info(`Invoking bash command: "${this.command}" in cwd: "${this.workingDirectory}"`)
70-
if (!updates) {
71-
// updates passed as undefined only in the code diff is clicked to avoid showing Q Streaming spinner component to the user.
72-
return new Promise(async (resolve) => {
73-
resolve({
74-
output: {
75-
kind: OutputKind.Json,
76-
content: '',
77-
},
78-
})
79-
})
80-
}
8170

8271
return new Promise(async (resolve, reject) => {
8372
this.logger.debug(`Spawning process with command: bash -c "${this.command}" (cwd=${this.workingDirectory})`)
@@ -137,9 +126,9 @@ export class ExecuteBash {
137126
})
138127
}
139128

140-
private static handleChunk(chunk: string, buffer: string[], updates: Writable) {
129+
private static handleChunk(chunk: string, buffer: string[], updates?: Writable) {
141130
try {
142-
updates.write(chunk)
131+
updates?.write(chunk)
143132
const lines = chunk.split(/\r?\n/)
144133
for (const line of lines) {
145134
buffer.push(line)

0 commit comments

Comments
 (0)