Skip to content

Commit 592a0a3

Browse files
committed
change warning category and default present logic for uncategory command
1 parent 56c4819 commit 592a0a3

File tree

1 file changed

+36
-51
lines changed

1 file changed

+36
-51
lines changed

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

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

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

@@ -47,45 +47,37 @@ export const commandCategories = new Map<string, CommandCategory>([
4747
['netstat', CommandCategory.ReadOnly],
4848
['ss', CommandCategory.ReadOnly],
4949
['dig', CommandCategory.ReadOnly],
50-
['grep', CommandCategory.ReadOnly],
5150
['wc', CommandCategory.ReadOnly],
5251
['sort', CommandCategory.ReadOnly],
5352
['diff', CommandCategory.ReadOnly],
5453
['head', CommandCategory.ReadOnly],
5554
['tail', CommandCategory.ReadOnly],
5655

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],
56+
// Mutable commands
57+
['chmod', CommandCategory.Mutate],
58+
['curl', CommandCategory.Mutate],
59+
['mount', CommandCategory.Mutate],
60+
['umount', CommandCategory.Mutate],
61+
['systemctl', CommandCategory.Mutate],
62+
['service', CommandCategory.Mutate],
63+
['crontab', CommandCategory.Mutate],
64+
['at', CommandCategory.Mutate],
65+
['nc', CommandCategory.Mutate],
66+
['ssh', CommandCategory.Mutate],
67+
['scp', CommandCategory.Mutate],
68+
['ftp', CommandCategory.Mutate],
69+
['sftp', CommandCategory.Mutate],
70+
['rsync', CommandCategory.Mutate],
71+
['chroot', CommandCategory.Mutate],
72+
['strace', CommandCategory.Mutate],
73+
['gdb', CommandCategory.Mutate],
74+
['apt', CommandCategory.Mutate],
75+
['yum', CommandCategory.Mutate],
76+
['dnf', CommandCategory.Mutate],
77+
['pacman', CommandCategory.Mutate],
78+
['exec', CommandCategory.Mutate],
79+
['eval', CommandCategory.Mutate],
80+
['xargs', CommandCategory.Mutate],
8981

9082
// Destructive commands
9183
['rm', CommandCategory.Destructive],
@@ -104,22 +96,18 @@ export const commandCategories = new Map<string, CommandCategory>([
10496
['insmod', CommandCategory.Destructive],
10597
['rmmod', CommandCategory.Destructive],
10698
['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],
99+
['kill', CommandCategory.Destructive],
100+
['killall', CommandCategory.Destructive],
101+
['pkill', CommandCategory.Destructive],
102+
['iptables', CommandCategory.Destructive],
103+
['route', CommandCategory.Destructive],
104+
['chown', CommandCategory.Destructive],
118105
])
119106
export const maxBashToolResponseSize: number = 1024 * 1024 // 1MB
120107
export const lineCount: number = 1024
121108
export const destructiveCommandWarningMessage = '⚠️ WARNING: Destructive command detected:\n\n'
122109
export const highRiskCommandWarningMessage = '⚠️ WARNING: High risk command detected:\n\n'
110+
export const mutateCommandWarningMessage = 'Mutation command:\n\n'
123111

124112
export interface ExecuteBashParams {
125113
command: string
@@ -197,11 +185,8 @@ export class ExecuteBash {
197185
switch (category) {
198186
case CommandCategory.Destructive:
199187
return { requiresAcceptance: true, warning: destructiveCommandWarningMessage }
200-
case CommandCategory.HighRisk:
201-
return {
202-
requiresAcceptance: true,
203-
warning: highRiskCommandWarningMessage,
204-
}
188+
case CommandCategory.Mutate:
189+
return { requiresAcceptance: true, warning: mutateCommandWarningMessage }
205190
case CommandCategory.ReadOnly:
206191
if (
207192
cmdArgs.some((arg) =>
@@ -212,7 +197,7 @@ export class ExecuteBash {
212197
}
213198
continue
214199
default:
215-
return { requiresAcceptance: true, warning: highRiskCommandWarningMessage }
200+
return { requiresAcceptance: true }
216201
}
217202
}
218203
return { requiresAcceptance: false }

0 commit comments

Comments
 (0)