446
return new RegExp(`^${sanitizedValue}\\b`);
447
}
449
>
// ---- Default rules ----------------------------------------------------------
450
>
//
451
>
// Compatibility fallback for clients that do not forward the VS Code
452
>
// `chat.tools.terminal.autoApprove` setting.
453
>
// TODO: Remove this fallback once all agent-host clients are guaranteed to
454
>
// forward `chat.tools.terminal.autoApprove` before shell approvals run.
455
>
456
>
const DEFAULT_TERMINAL_AUTO_APPROVE_RULES: Readonly<Record<string, AgentHostTerminalAutoApproveRuleValue>> = {
457
>
// Safe readonly commands
458
>
cd: true,
459
>
echo: true,
460
>
ls: true,
461
>
dir: true,
462
>
pwd: true,
463
>
cat: true,
464
>
head: true,
465
>
tail: true,
466
>
findstr: true,
467
>
wc: true,
468
>
tr: true,
469
>
cut: true,
470
>
cmp: true,
471
>
which: true,
472
>
basename: true,
473
>
dirname: true,
474
>
realpath: true,
475
>
readlink: true,
476
>
stat: true,
477
>
file: true,
478
>
od: true,
479
>
du: true,
480
>
df: true,
481
>
sleep: true,
482
>
nl: true,
483
>
484
>
grep: true,
485
>
486
>
// Safe git sub-commands
487
>
'/^git(\\s+(-C\\s+\\S+|--no-pager))*\\s+status\\b/': true,
488
>
'/^git(\\s+(-C\\s+\\S+|--no-pager))*\\s+log\\b/': true,
489
>
'/^git(\\s+(-C\\s+\\S+|--no-pager))*\\s+log\\b.*\\s--output(=|\\s|$)/': false,
490
>
'/^git(\\s+(-C\\s+\\S+|--no-pager))*\\s+show\\b/': true,
491
>
'/^git(\\s+(-C\\s+\\S+|--no-pager))*\\s+diff\\b/': true,
492
>
'/^git(\\s+(-C\\s+\\S+|--no-pager))*\\s+ls-files\\b/': true,
493
>
'/^git(\\s+(-C\\s+\\S+|--no-pager))*\\s+grep\\b/': true,
494
>
'/^git(\\s+(-C\\s+\\S+|--no-pager))*\\s+branch\\b/': true,
495
>
'/^git(\\s+(-C\\s+\\S+|--no-pager))*\\s+branch\\b.*\\s-(d|D|m|M|-delete|-force)\\b/': false,
496
>
497
>
// Docker readonly sub-commands
498
>
'/^docker\\s+(ps|images|info|version|inspect|logs|top|stats|port|diff|search|events)\\b/': true,
499
>
'/^docker\\s+(container|image|network|volume|context|system)\\s+(ls|ps|inspect|history|show|df|info)\\b/': true,
500
>
'/^docker\\s+compose\\s+(ps|ls|top|logs|images|config|version|port|events)\\b/': true,
501
>
502
>
// PowerShell
503
>
'Get-ChildItem': true,
504
>
'Get-Content': true,
505
>
'Get-Date': true,
506
>
'Get-Random': true,
507
>
'Get-Location': true,
508
>
'Set-Location': true,
509
>
'Write-Host': true,
510
>
'Write-Output': true,
511
>
'Out-String': true,
512
>
'Split-Path': true,
513
>
'Join-Path': true,
514
>
'Start-Sleep': true,
515
>
'Where-Object': true,
516
>
'/^Select-[a-z0-9]/i': true,
517
>
'/^Measure-[a-z0-9]/i': true,
518
>
'/^Compare-[a-z0-9]/i': true,
519
>
'/^Format-[a-z0-9]/i': true,
520
>
'/^Sort-[a-z0-9]/i': true,
521
>
522
>
// Package manager read-only commands
523
>
'/^npm\\s+(ls|list|outdated|view|info|show|explain|why|root|prefix|bin|search|doctor|fund|repo|bugs|docs|home|help(-search)?)\\b/': true,
524
>
'/^npm\\s+config\\s+(list|get)\\b/': true,
525
>
'/^npm\\s+pkg\\s+get\\b/': true,
526
>
'/^npm\\s+audit$/': true,
527
>
'/^npm\\s+cache\\s+verify\\b/': true,
528
>
'/^yarn\\s+(list|outdated|info|why|bin|help|versions)\\b/': true,
529
>
'/^yarn\\s+licenses\\b/': true,
530
>
'/^yarn\\s+audit\\b(?!.*\\bfix\\b)/': true,
531
>
'/^yarn\\s+config\\s+(list|get)\\b/': true,
532
>
'/^yarn\\s+cache\\s+dir\\b/': true,
533
>
'/^pnpm\\s+(ls|list|outdated|why|root|bin|doctor)\\b/': true,
534
>
'/^pnpm\\s+licenses\\b/': true,
535
>
'/^pnpm\\s+audit\\b(?!.*\\bfix\\b)/': true,
536
>
'/^pnpm\\s+config\\s+(list|get)\\b/': true,
537
>
538
>
// Safe lockfile-only installs
539
>
'npm ci': true,
540
>
'/^yarn\\s+install\\s+--frozen-lockfile\\b/': true,
541
>
'/^pnpm\\s+install\\s+--frozen-lockfile\\b/': true,
542
>
543
>
// Safe commands with dangerous arg blocking
544
>
column: true,
545
>
'/^column\\b.*\\s-c\\s+[0-9]{4,}/': false,
546
>
date: true,
547
>
'/^date\\b.*\\s(-s|--set)\\b/': false,
548
>
find: true,
549
>
'/^find\\b.*\\s-(delete|exec|execdir|fprint|fprintf|fls|ok|okdir)\\b/': false,
550
>
rg: true,
551
>
'/^rg\\b.*\\s(--pre|--hostname-bin)\\b/': false,
552
>
sed: true,
553
>
'/^sed\\b.*\\s(-[a-zA-Z]*(e|f)[a-zA-Z]*|--expression|--file)\\b/': false,
554
>
'/^sed\\b.*s\\/.*\\/.*\\/[ew]/': false,
555
>
'/^sed\\b.*;W/': false,
556
>
sort: true,
557
>
'/^sort\\b.*\\s-(o|S)\\b/': false,
558
>
tree: true,
559
>
'/^tree\\b.*\\s-o\\b/': false,
560
>
'/^xxd$/': true,
561
>
'/^xxd\\b(\\s+-\\S+)*\\s+[^-\\s]\\S*$/': true,
562
>
563
>
// Dangerous commands
564
>
rm: false,
565
>
rmdir: false,
566
>
del: false,
567
>
'Remove-Item': false,
568
>
ri: false,
569
>
rd: false,
570
>
erase: false,
571
>
dd: false,
572
>
kill: false,
573
>
ps: false,
574
>
top: false,
575
>
'Stop-Process': false,
576
>
spps: false,
577
>
taskkill: false,
578
>
'taskkill.exe': false,
579
>
curl: false,
580
>
wget: false,
581
>
'Invoke-RestMethod': false,
582
>
'Invoke-WebRequest': false,
583
>
irm: false,
584
>
iwr: false,
585
>
chmod: false,
586
>
chown: false,
587
>
'Set-ItemProperty': false,
588
>
sp: false,
589
>
'Set-Acl': false,
590
>
jq: false,
591
>
xargs: false,
592
>
eval: false,
593
>
'Invoke-Expression': false,
594
>
iex: false,
595
>
};