Skip to content
Closed
Changes from 1 commit
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
87 changes: 36 additions & 51 deletions packages/core/src/codewhispererChat/tools/executeBash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { split } from 'shlex'

export enum CommandCategory {
ReadOnly,
HighRisk,
Mutate,
Destructive,
}

Expand Down Expand Up @@ -47,45 +47,37 @@ export const commandCategories = new Map<string, CommandCategory>([
['netstat', CommandCategory.ReadOnly],
['ss', CommandCategory.ReadOnly],
['dig', CommandCategory.ReadOnly],
['grep', CommandCategory.ReadOnly],
['wc', CommandCategory.ReadOnly],
['sort', CommandCategory.ReadOnly],
['diff', CommandCategory.ReadOnly],
['head', CommandCategory.ReadOnly],
['tail', CommandCategory.ReadOnly],

// HighRisk commands
['chmod', CommandCategory.HighRisk],
['chown', CommandCategory.HighRisk],
['mv', CommandCategory.HighRisk],
['cp', CommandCategory.HighRisk],
['ln', CommandCategory.HighRisk],
['mount', CommandCategory.HighRisk],
['umount', CommandCategory.HighRisk],
['kill', CommandCategory.HighRisk],
['killall', CommandCategory.HighRisk],
['pkill', CommandCategory.HighRisk],
['iptables', CommandCategory.HighRisk],
['route', CommandCategory.HighRisk],
['systemctl', CommandCategory.HighRisk],
['service', CommandCategory.HighRisk],
['crontab', CommandCategory.HighRisk],
['at', CommandCategory.HighRisk],
['tar', CommandCategory.HighRisk],
['awk', CommandCategory.HighRisk],
['sed', CommandCategory.HighRisk],
['wget', CommandCategory.HighRisk],
['curl', CommandCategory.HighRisk],
['nc', CommandCategory.HighRisk],
['ssh', CommandCategory.HighRisk],
['scp', CommandCategory.HighRisk],
['ftp', CommandCategory.HighRisk],
['sftp', CommandCategory.HighRisk],
['rsync', CommandCategory.HighRisk],
['chroot', CommandCategory.HighRisk],
['lsof', CommandCategory.HighRisk],
['strace', CommandCategory.HighRisk],
['gdb', CommandCategory.HighRisk],
// Mutable commands
['chmod', CommandCategory.Mutate],
['curl', CommandCategory.Mutate],
['mount', CommandCategory.Mutate],
['umount', CommandCategory.Mutate],
['systemctl', CommandCategory.Mutate],
['service', CommandCategory.Mutate],
['crontab', CommandCategory.Mutate],
['at', CommandCategory.Mutate],
['nc', CommandCategory.Mutate],
['ssh', CommandCategory.Mutate],
['scp', CommandCategory.Mutate],
['ftp', CommandCategory.Mutate],
['sftp', CommandCategory.Mutate],
['rsync', CommandCategory.Mutate],
['chroot', CommandCategory.Mutate],
['strace', CommandCategory.Mutate],
['gdb', CommandCategory.Mutate],
['apt', CommandCategory.Mutate],
['yum', CommandCategory.Mutate],
['dnf', CommandCategory.Mutate],
['pacman', CommandCategory.Mutate],
['exec', CommandCategory.Mutate],
['eval', CommandCategory.Mutate],
['xargs', CommandCategory.Mutate],

// Destructive commands
['rm', CommandCategory.Destructive],
Expand All @@ -104,22 +96,18 @@ export const commandCategories = new Map<string, CommandCategory>([
['insmod', CommandCategory.Destructive],
['rmmod', CommandCategory.Destructive],
['modprobe', CommandCategory.Destructive],
['apt', CommandCategory.Destructive],
['yum', CommandCategory.Destructive],
['dnf', CommandCategory.Destructive],
['pacman', CommandCategory.Destructive],
['perl', CommandCategory.Destructive],
['python', CommandCategory.Destructive],
['bash', CommandCategory.Destructive],
['sh', CommandCategory.Destructive],
['exec', CommandCategory.Destructive],
['eval', CommandCategory.Destructive],
['xargs', CommandCategory.Destructive],
['kill', CommandCategory.Destructive],
['killall', CommandCategory.Destructive],
['pkill', CommandCategory.Destructive],
['iptables', CommandCategory.Destructive],
['route', CommandCategory.Destructive],
['chown', CommandCategory.Destructive],
])
export const maxBashToolResponseSize: number = 1024 * 1024 // 1MB
export const lineCount: number = 1024
export const destructiveCommandWarningMessage = '⚠️ WARNING: Destructive command detected:\n\n'
export const highRiskCommandWarningMessage = '⚠️ WARNING: High risk command detected:\n\n'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this?

export const mutateCommandWarningMessage = 'Mutation command:\n\n'

export interface ExecuteBashParams {
command: string
Expand Down Expand Up @@ -197,11 +185,8 @@ export class ExecuteBash {
switch (category) {
case CommandCategory.Destructive:
return { requiresAcceptance: true, warning: destructiveCommandWarningMessage }
case CommandCategory.HighRisk:
return {
requiresAcceptance: true,
warning: highRiskCommandWarningMessage,
}
case CommandCategory.Mutate:
return { requiresAcceptance: true, warning: mutateCommandWarningMessage }
case CommandCategory.ReadOnly:
if (
cmdArgs.some((arg) =>
Expand All @@ -212,7 +197,7 @@ export class ExecuteBash {
}
continue
default:
return { requiresAcceptance: true, warning: highRiskCommandWarningMessage }
return { requiresAcceptance: true }
}
}
return { requiresAcceptance: false }
Expand Down