feat(core): auto-detect UTF-8 BOM for PowerShell scripts on Windows

- Add needsUtf8Bom() to detect when UTF-8 BOM is needed based on file
  extension and system code page
- PowerShell 5.1 on non-UTF-8 Windows systems (e.g. GBK) requires BOM
  to read scripts correctly
- Remove default UTF8 encoding; undefined now triggers auto-detection
- Add tests for needsUtf8Bom() covering Windows/non-Windows scenarios

This ensures PowerShell scripts are written with UTF-8 BOM on systems
that need it, fixing character encoding issues for non-ASCII content.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
tanzhenxin 2026-03-16 22:44:53 +08:00
parent 82e0064871
commit 17939baa66
6 changed files with 142 additions and 13 deletions

View file

@ -10,7 +10,6 @@ import {
Config,
DEFAULT_QWEN_EMBEDDING_MODEL,
FileDiscoveryService,
FileEncoding,
getAllGeminiMdFilenames,
loadServerHierarchicalMemory,
setGeminiMdFilename as setServerGeminiMdFilename,
@ -1041,8 +1040,7 @@ export async function loadCliConfig(
// always be true and the settings file can never disable recording.
chatRecording:
argv.chatRecording ?? settings.general?.chatRecording ?? true,
defaultFileEncoding:
settings.general?.defaultFileEncoding ?? FileEncoding.UTF8,
defaultFileEncoding: settings.general?.defaultFileEncoding,
lsp: {
enabled: lspEnabled,
},