Skip to content

Commit b41dca8

Browse files
authored
Merge branch 'feature/agentic-chat' into feature/agentic-chat
2 parents 9757bec + 529da80 commit b41dca8

File tree

5 files changed

+84
-91
lines changed

5 files changed

+84
-91
lines changed

package-lock.json

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@vscode/test-electron": "^2.3.8",
5555
"@vscode/test-web": "^0.0.65",
5656
"@vscode/vsce": "^2.19.0",
57-
"eslint": "^8.56.0",
57+
"eslint": "^8.57.0",
5858
"eslint-config-prettier": "^9.1.0",
5959
"eslint-plugin-aws-toolkits": "file:plugins/eslint-plugin-aws-toolkits",
6060
"eslint-plugin-header": "^3.1.1",

packages/core/src/amazonq/webview/ui/tabs/generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ export class TabDataGenerator {
7878
{
7979
type: 'toggle',
8080
id: 'prompt-type',
81-
value: 'ask',
81+
value: 'pair-programming-on',
82+
tooltip: 'Pair programmar on',
8283
options: [
8384
{
8485
value: 'pair-programming-on',

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

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ import { OutputKind } from '../../tools/toolShared'
9797
import { ToolUtils, Tool, ToolType } from '../../tools/toolUtils'
9898
import { ChatStream } from '../../tools/chatStream'
9999
import { ChatHistoryStorage } from '../../storages/chatHistoryStorage'
100-
import { FsWriteParams } from '../../tools/fsWrite'
101100
import { tempDirPath } from '../../../shared/filesystemUtilities'
102101
import { Database } from '../../../shared/db/chatDb/chatDb'
103102
import { TabBarController } from './tabBarController'
@@ -755,13 +754,6 @@ export class ChatController {
755754
const toolResult: ToolResult = result
756755
toolResults.push(toolResult)
757756
}
758-
759-
if (toolUse.name === ToolType.FsWrite) {
760-
await vscode.commands.executeCommand(
761-
'vscode.open',
762-
vscode.Uri.file((toolUse.input as unknown as FsWriteParams).path)
763-
)
764-
}
765757
}
766758

767759
await this.generateResponse(
@@ -796,11 +788,26 @@ export class ChatController {
796788
})
797789
}
798790

799-
private async closeDiffView() {
800-
// Close the diff view if User reject the generated code changes.
791+
private async closeDiffView(message: CustomFormActionMessage) {
792+
// Close the diff view if User rejected or accepted the generated code changes.
801793
if (vscode.window.tabGroups.activeTabGroup.activeTab?.label.includes(amazonQTabSuffix)) {
802794
await vscode.commands.executeCommand('workbench.action.closeActiveEditor')
803795
}
796+
// clean up temp file
797+
const tabID = message.tabID
798+
const toolUseId = message.action.formItemValues?.toolUseId
799+
if (!tabID || !toolUseId) {
800+
return
801+
}
802+
803+
const session = this.sessionStorage.getSession(tabID)
804+
const { filePath } = session.fsWriteBackups.get(toolUseId) ?? {}
805+
if (filePath) {
806+
const tempFilePath = await this.getTempFilePath(filePath)
807+
if (await fs.existsFile(tempFilePath)) {
808+
await fs.delete(tempFilePath)
809+
}
810+
}
804811
}
805812

806813
private async rejectShellCommand(message: CustomFormActionMessage) {
@@ -834,11 +841,11 @@ export class ChatController {
834841
await this.processToolUseMessage(message)
835842
break
836843
case 'accept-code-diff':
837-
await this.closeDiffView()
844+
await this.closeDiffView(message)
838845
break
839846
case 'reject-code-diff':
840847
await this.restoreBackup(message)
841-
await this.closeDiffView()
848+
await this.closeDiffView(message)
842849
break
843850
case 'reject-shell-command':
844851
await this.rejectShellCommand(message)
@@ -882,6 +889,21 @@ export class ChatController {
882889
}
883890
}
884891

892+
private async getTempFilePath(filePath: string) {
893+
// Create a temporary file path to show the diff view
894+
const pathToArchiveDir = path.join(tempDirPath, 'q-chat')
895+
const archivePathExists = await fs.existsDir(pathToArchiveDir)
896+
if (!archivePathExists) {
897+
await fs.mkdir(pathToArchiveDir)
898+
}
899+
const resultArtifactsDir = path.join(pathToArchiveDir, 'resultArtifacts')
900+
const resultArtifactsDirExists = await fs.existsDir(resultArtifactsDir)
901+
if (!resultArtifactsDirExists) {
902+
await fs.mkdir(resultArtifactsDir)
903+
}
904+
return path.join(resultArtifactsDir, `temp-${path.basename(filePath)}`)
905+
}
906+
885907
private async processFileClickMessage(message: FileClick) {
886908
const session = this.sessionStorage.getSession(message.tabID)
887909
// Check if user clicked on filePath in the contextList or in the fileListTree and perform the functionality accordingly.
@@ -893,18 +915,7 @@ export class ChatController {
893915
}
894916

895917
try {
896-
// Create a temporary file path to show the diff view
897-
// TODO: Use amazonQDiffScheme for temp file
898-
const pathToArchiveDir = path.join(tempDirPath, 'q-chat')
899-
const archivePathExists = await fs.existsDir(pathToArchiveDir)
900-
if (archivePathExists) {
901-
await fs.delete(pathToArchiveDir, { recursive: true })
902-
}
903-
await fs.mkdir(pathToArchiveDir)
904-
const resultArtifactsDir = path.join(pathToArchiveDir, 'resultArtifacts')
905-
await fs.mkdir(resultArtifactsDir)
906-
907-
const tempFilePath = path.join(resultArtifactsDir, `temp-${path.basename(filePath)}`)
918+
const tempFilePath = await this.getTempFilePath(filePath)
908919
await fs.writeFile(tempFilePath, content)
909920

910921
const leftUri = vscode.Uri.file(tempFilePath)

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

Lines changed: 36 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import { split } from 'shlex'
1212

1313
export enum CommandCategory {
1414
ReadOnly,
15-
HighRisk,
15+
Mutate,
1616
Destructive,
1717
}
1818

19-
export const dangerousPatterns = new Set(['<(', '$(', '`'])
2019
export const splitOperators = new Set(['|', '&&', '||', '>'])
2120
export const splitOperatorsArray = Array.from(splitOperators)
2221
export const commandCategories = new Map<string, CommandCategory>([
@@ -47,45 +46,37 @@ export const commandCategories = new Map<string, CommandCategory>([
4746
['netstat', CommandCategory.ReadOnly],
4847
['ss', CommandCategory.ReadOnly],
4948
['dig', CommandCategory.ReadOnly],
50-
['grep', CommandCategory.ReadOnly],
5149
['wc', CommandCategory.ReadOnly],
5250
['sort', CommandCategory.ReadOnly],
5351
['diff', CommandCategory.ReadOnly],
5452
['head', CommandCategory.ReadOnly],
5553
['tail', CommandCategory.ReadOnly],
5654

57-
// HighRisk commands
58-
['chmod', CommandCategory.HighRisk],
59-
['chown', CommandCategory.HighRisk],
60-
['mv', CommandCategory.HighRisk],
61-
['cp', CommandCategory.HighRisk],
62-
['ln', CommandCategory.HighRisk],
63-
['mount', CommandCategory.HighRisk],
64-
['umount', CommandCategory.HighRisk],
65-
['kill', CommandCategory.HighRisk],
66-
['killall', CommandCategory.HighRisk],
67-
['pkill', CommandCategory.HighRisk],
68-
['iptables', CommandCategory.HighRisk],
69-
['route', CommandCategory.HighRisk],
70-
['systemctl', CommandCategory.HighRisk],
71-
['service', CommandCategory.HighRisk],
72-
['crontab', CommandCategory.HighRisk],
73-
['at', CommandCategory.HighRisk],
74-
['tar', CommandCategory.HighRisk],
75-
['awk', CommandCategory.HighRisk],
76-
['sed', CommandCategory.HighRisk],
77-
['wget', CommandCategory.HighRisk],
78-
['curl', CommandCategory.HighRisk],
79-
['nc', CommandCategory.HighRisk],
80-
['ssh', CommandCategory.HighRisk],
81-
['scp', CommandCategory.HighRisk],
82-
['ftp', CommandCategory.HighRisk],
83-
['sftp', CommandCategory.HighRisk],
84-
['rsync', CommandCategory.HighRisk],
85-
['chroot', CommandCategory.HighRisk],
86-
['lsof', CommandCategory.HighRisk],
87-
['strace', CommandCategory.HighRisk],
88-
['gdb', CommandCategory.HighRisk],
55+
// Mutable commands
56+
['chmod', CommandCategory.Mutate],
57+
['curl', CommandCategory.Mutate],
58+
['mount', CommandCategory.Mutate],
59+
['umount', CommandCategory.Mutate],
60+
['systemctl', CommandCategory.Mutate],
61+
['service', CommandCategory.Mutate],
62+
['crontab', CommandCategory.Mutate],
63+
['at', CommandCategory.Mutate],
64+
['nc', CommandCategory.Mutate],
65+
['ssh', CommandCategory.Mutate],
66+
['scp', CommandCategory.Mutate],
67+
['ftp', CommandCategory.Mutate],
68+
['sftp', CommandCategory.Mutate],
69+
['rsync', CommandCategory.Mutate],
70+
['chroot', CommandCategory.Mutate],
71+
['strace', CommandCategory.Mutate],
72+
['gdb', CommandCategory.Mutate],
73+
['apt', CommandCategory.Mutate],
74+
['yum', CommandCategory.Mutate],
75+
['dnf', CommandCategory.Mutate],
76+
['pacman', CommandCategory.Mutate],
77+
['exec', CommandCategory.Mutate],
78+
['eval', CommandCategory.Mutate],
79+
['xargs', CommandCategory.Mutate],
8980

9081
// Destructive commands
9182
['rm', CommandCategory.Destructive],
@@ -104,22 +95,17 @@ export const commandCategories = new Map<string, CommandCategory>([
10495
['insmod', CommandCategory.Destructive],
10596
['rmmod', CommandCategory.Destructive],
10697
['modprobe', CommandCategory.Destructive],
107-
['apt', CommandCategory.Destructive],
108-
['yum', CommandCategory.Destructive],
109-
['dnf', CommandCategory.Destructive],
110-
['pacman', CommandCategory.Destructive],
111-
['perl', CommandCategory.Destructive],
112-
['python', CommandCategory.Destructive],
113-
['bash', CommandCategory.Destructive],
114-
['sh', CommandCategory.Destructive],
115-
['exec', CommandCategory.Destructive],
116-
['eval', CommandCategory.Destructive],
117-
['xargs', CommandCategory.Destructive],
98+
['kill', CommandCategory.Destructive],
99+
['killall', CommandCategory.Destructive],
100+
['pkill', CommandCategory.Destructive],
101+
['iptables', CommandCategory.Destructive],
102+
['route', CommandCategory.Destructive],
103+
['chown', CommandCategory.Destructive],
118104
])
119105
export const maxBashToolResponseSize: number = 1024 * 1024 // 1MB
120106
export const lineCount: number = 1024
121107
export const destructiveCommandWarningMessage = '⚠️ WARNING: Destructive command detected:\n\n'
122-
export const highRiskCommandWarningMessage = '⚠️ WARNING: High risk command detected:\n\n'
108+
export const mutateCommandWarningMessage = 'Mutation command:\n\n'
123109

124110
export interface ExecuteBashParams {
125111
command: string
@@ -197,22 +183,12 @@ export class ExecuteBash {
197183
switch (category) {
198184
case CommandCategory.Destructive:
199185
return { requiresAcceptance: true, warning: destructiveCommandWarningMessage }
200-
case CommandCategory.HighRisk:
201-
return {
202-
requiresAcceptance: true,
203-
warning: highRiskCommandWarningMessage,
204-
}
186+
case CommandCategory.Mutate:
187+
return { requiresAcceptance: true, warning: mutateCommandWarningMessage }
205188
case CommandCategory.ReadOnly:
206-
if (
207-
cmdArgs.some((arg) =>
208-
Array.from(dangerousPatterns).some((pattern) => arg.includes(pattern))
209-
)
210-
) {
211-
return { requiresAcceptance: true, warning: highRiskCommandWarningMessage }
212-
}
213189
continue
214190
default:
215-
return { requiresAcceptance: true, warning: highRiskCommandWarningMessage }
191+
return { requiresAcceptance: true }
216192
}
217193
}
218194
return { requiresAcceptance: false }

0 commit comments

Comments
 (0)