Files
Netcatty/domain/commandBlocklist.ts
T
JasonWen 5c5fa4f27e fix(ai): make the command blocklist shell-aware
Select default command-safety rules from the live session shell so legal
PowerShell subexpressions are allowed and PowerShell-native dangerous
commands are blocked. Untouched pre-shell-aware lists gain the new
defaults on read.

Closes #3256
2026-09-03 15:21:45 +08:00

24 lines
804 B
TypeScript

import commandBlocklistTable from '../lib/commandBlocklist.json';
const LEGACY_DEFAULT_PATTERNS = [
...commandBlocklistTable.common,
...commandBlocklistTable.posixNative,
...commandBlocklistTable.posix,
];
/**
* Add PowerShell defaults only to a complete pre-shell-aware list.
* If any PowerShell default is already present, the list has been upgraded or
* customized and is left as saved.
*/
export function migrateLegacyCommandBlocklist(blocklist: string[]): string[] {
const configured = new Set(blocklist);
if (!LEGACY_DEFAULT_PATTERNS.every((pattern) => configured.has(pattern))) {
return blocklist;
}
if (commandBlocklistTable.powershell.some((pattern) => configured.has(pattern))) {
return blocklist;
}
return [...blocklist, ...commandBlocklistTable.powershell];
}