- Remove acp.ts and schema.ts in favor of SDK types
- Refactor acpAgent.ts to leverage SDK client
- Update session management types and implementations
- Adjust all test cases for new SDK-based architecture
- Update integration tests and export utilities
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
- Extract isUtf8CompatibleEncoding to iconvHelper.ts, removing duplicate
definitions in fileUtils.ts and fileSystemService.ts
- Add readFileWithEncodingInfo() returning content + encoding + bom in a
single I/O pass; update edit.ts and write-file.ts to use it instead of
separate readTextFile/detectFileEncoding/detectFileBOM calls
- Add readTextFileWithInfo() to FileSystemService interface; implement in
StandardFileSystemService and AcpFileSystemService (delegates to fallback)
- Fix FileReadResult.bom to be true for all Unicode BOM variants (UTF-8/
16/32), not just UTF-8; add getBOMBytesForEncoding() and update
writeTextFile to re-prepend the correct BOM bytes on write-back so
UTF-16/32 BOM files are no longer silently corrupted
- Add tests for readFileWithEncodingInfo, readTextFileWithInfo, and
UTF-16LE BOM write-back preservation
Fixes#2069
- Add iconv-lite dependency for non-UTF-8 encoding support
- Add iconvHelper.ts as a CJS/ESM compatibility wrapper
- Update readFileWithEncoding() to detect and handle GBK/Big5/Shift_JIS
using BOM detection -> UTF-8 validation -> chardet -> iconv-lite fallback
- Add detectFileEncoding() to identify file encoding before writes
- Update writeTextFile() to accept encoding option and encode with iconv-lite
- Update WriteFileTool and EditTool to detect and preserve original encoding
- Add tests for GBK read/write, detectFileEncoding, and encoding option
Improve the detectFileBOM method to handle edge cases better:
1. Add length check before accessing first character
- Prevents potential issues with empty strings
- Makes the intent explicit and defensive
2. Use codePointAt() instead of charCodeAt()
- Better Unicode support for characters beyond BMP
- More modern API for Unicode code point handling
This change maintains the same functionality while being more
robust and explicit about edge case handling.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Edit tool now respects defaultFileEncoding for new files
- Edit tool preserves BOM character for existing files without re-adding
- AcpFileSystemService detects BOM through ACP client with fallback
- Use line: null, limit: 1 for efficient BOM detection
- Add unit tests for AcpFileSystemService.detectFileBOM
- Add unit tests for EditTool BOM handling
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>