Skip to content

Commit f6686c6

Browse files
authored
Merge pull request #284248 from microsoft/tyriar/282209_sed
Add default auto approve rule for sed
2 parents ae22fa2 + eefd7a2 commit f6686c6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,22 @@ export const terminalChatAgentToolsConfiguration: IStringDictionary<IConfigurati
260260
find: true,
261261
'/^find\\b.*-(delete|exec|execdir|fprint|fprintf|fls|ok|okdir)\\b/': false,
262262

263+
// sed
264+
// - `-e`/`--expression`: Add the commands in script to the set of commands to be run
265+
// while processing the input.
266+
// - `-f`/`--file`: Add the commands contained in the file script-file to the set of
267+
// commands to be run while processing the input.
268+
// - `-i`/`--in-place`: This option specifies that files are to be edited in-place.
269+
// - `w`/`W` commands: Write to files (blocked by `-i` check + agent typically won't use).
270+
// - `s///e` flag: Executes substitution result as shell command
271+
// - `s///w` flag: Write substitution result to file
272+
// - `;W` Write first line of pattern space to file
273+
// - Note that `--sandbox` exists which blocks unsafe commands that could potentially be
274+
// leveraged to auto approve
275+
sed: true,
276+
'/^sed\\b.*(-[a-zA-Z]*(e|i|f)[a-zA-Z]*|--expression|--file|--in-place)\\b/': false,
277+
'/^sed\\b.*(\/e|\/w|;W)/': false,
278+
263279
// sort
264280
// - `-o`: Output redirection can write files (`sort -o /etc/something file`) which are
265281
// blocked currently

src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/runInTerminalTool.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ suite('RunInTerminalTool', () => {
243243
'date +%Y-%m-%d',
244244
'find . -name "*.txt"',
245245
'grep pattern file.txt',
246+
'sed "s/foo/bar/g"',
247+
'sed -n "1,10p" file.txt',
246248
'sort file.txt',
247249
'tree directory'
248250
];
@@ -295,6 +297,16 @@ suite('RunInTerminalTool', () => {
295297
'find . -exec rm {} \\;',
296298
'find . -execdir rm {} \\;',
297299
'find . -fprint output.txt',
300+
'sed -i "s/foo/bar/g" file.txt',
301+
'sed -i.bak "s/foo/bar/" file.txt',
302+
'sed --in-place "s/foo/bar/" file.txt',
303+
'sed -e "s/a/b/" file.txt',
304+
'sed -f script.sed file.txt',
305+
'sed --expression "s/a/b/" file.txt',
306+
'sed --file script.sed file.txt',
307+
'sed "s/foo/bar/e" file.txt',
308+
'sed "s/foo/bar/w output.txt" file.txt',
309+
'sed ";W output.txt" file.txt',
298310
'sort -o /etc/passwd file.txt',
299311
'sort -S 100G file.txt',
300312
'tree -o output.txt',

0 commit comments

Comments
 (0)