Skip to content

Commit b03bb7a

Browse files
CopilotTyriar
andcommitted
Add safe readonly commands to terminal auto approve defaults
Co-authored-by: Tyriar <[email protected]>
1 parent 6e80cb1 commit b03bb7a

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalChatAgentToolsConfiguration.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,32 @@ export const terminalChatAgentToolsConfiguration: IStringDictionary<IConfigurati
8787
]
8888
},
8989
default: {
90+
// Safe and common readonly commands (automatically approved)
91+
echo: true,
92+
ls: true,
93+
pwd: true,
94+
cat: true,
95+
head: true,
96+
tail: true,
97+
grep: true,
98+
find: true,
99+
which: true,
100+
whoami: true,
101+
date: true,
102+
hostname: true,
103+
ps: true,
104+
wc: true,
105+
sort: true,
106+
uniq: true,
107+
// PowerShell equivalents
108+
'/^Get-ChildItem\\b/i': true,
109+
'/^Get-Content\\b/i': true,
110+
'/^Get-Location\\b/i': true,
111+
'/^Get-Date\\b/i': true,
112+
'/^Get-Host\\b/i': true,
113+
'/^Get-Process\\b/i': true,
114+
'/^Get-Service\\b/i': true,
115+
// Dangerous commands (require explicit approval)
90116
rm: false,
91117
rmdir: false,
92118
del: false,

src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/commandLineAutoApprover.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,4 +618,78 @@ suite('CommandLineAutoApprover', () => {
618618
});
619619
});
620620
});
621+
622+
suite('default configuration', () => {
623+
test('should auto-approve safe readonly commands by default', () => {
624+
// Don't set any configuration - use defaults
625+
setAutoApprove({});
626+
627+
// Unix/Linux safe commands should be auto-approved by default
628+
ok(isAutoApproved('echo hello'));
629+
ok(isAutoApproved('ls -la'));
630+
ok(isAutoApproved('pwd'));
631+
ok(isAutoApproved('cat file.txt'));
632+
ok(isAutoApproved('head -10 file.txt'));
633+
ok(isAutoApproved('tail -f log.txt'));
634+
ok(isAutoApproved('grep pattern file.txt'));
635+
ok(isAutoApproved('find . -name "*.txt"'));
636+
ok(isAutoApproved('which node'));
637+
ok(isAutoApproved('whoami'));
638+
ok(isAutoApproved('date'));
639+
ok(isAutoApproved('hostname'));
640+
ok(isAutoApproved('ps aux'));
641+
ok(isAutoApproved('wc -l file.txt'));
642+
ok(isAutoApproved('sort file.txt'));
643+
ok(isAutoApproved('uniq file.txt'));
644+
645+
// Dangerous commands should be denied by default
646+
ok(!isAutoApproved('rm file.txt'));
647+
ok(!isAutoApproved('rmdir directory'));
648+
ok(!isAutoApproved('del file.txt'));
649+
ok(!isAutoApproved('kill 1234'));
650+
ok(!isAutoApproved('curl -X POST http://example.com'));
651+
ok(!isAutoApproved('wget http://example.com/script.sh'));
652+
ok(!isAutoApproved('eval "dangerous code"'));
653+
ok(!isAutoApproved('chmod 777 file.txt'));
654+
ok(!isAutoApproved('chown user file.txt'));
655+
});
656+
657+
test('should auto-approve PowerShell safe commands by default', () => {
658+
// Don't set any configuration - use defaults
659+
setAutoApprove({});
660+
661+
// PowerShell safe commands should be auto-approved by default
662+
ok(isAutoApproved('Get-ChildItem'));
663+
ok(isAutoApproved('Get-ChildItem C:\\'));
664+
ok(isAutoApproved('get-childitem')); // case insensitive
665+
ok(isAutoApproved('Get-Content file.txt'));
666+
ok(isAutoApproved('GET-CONTENT file.txt')); // case insensitive
667+
ok(isAutoApproved('Get-Location'));
668+
ok(isAutoApproved('Get-Date'));
669+
ok(isAutoApproved('Get-Host'));
670+
ok(isAutoApproved('Get-Process'));
671+
ok(isAutoApproved('Get-Service'));
672+
673+
// PowerShell dangerous commands should be denied by default
674+
ok(!isAutoApproved('Remove-Item file.txt'));
675+
ok(!isAutoApproved('REMOVE-ITEM file.txt')); // case insensitive
676+
});
677+
678+
test('should allow overriding defaults with explicit configuration', () => {
679+
// Override defaults with explicit configuration
680+
setAutoApprove({
681+
echo: false, // Deny a usually safe command
682+
rm: true // Allow a usually dangerous command
683+
});
684+
685+
// Overridden commands should follow explicit config
686+
ok(!isAutoApproved('echo hello')); // Now denied
687+
ok(isAutoApproved('rm file.txt')); // Now allowed
688+
689+
// Non-overridden defaults should still work
690+
ok(isAutoApproved('ls -la'));
691+
ok(isAutoApproved('pwd'));
692+
ok(!isAutoApproved('kill 1234'));
693+
});
694+
});
621695
});

0 commit comments

Comments
 (0)