Skip to content

feat: 工具层编码支持 + 文件浏览编码选择 + 回滚修复#3108

Open
expfukck wants to merge 5 commits into
esengine:main-v2from
expfukck:feat/encoding-support-and-rewind-fix
Open

feat: 工具层编码支持 + 文件浏览编码选择 + 回滚修复#3108
expfukck wants to merge 5 commits into
esengine:main-v2from
expfukck:feat/encoding-support-and-rewind-fix

Conversation

@expfukck
Copy link
Copy Markdown

@expfukck expfukck commented Jun 4, 2026

Summary / 概要

为文件操作工具增加编码参数支持,桌面文件浏览器增加编码选择器,并修复回滚功能无法还原文件的 bug。

Changes / 改动

1. 工具层编码支持 (read_file / write_file / edit_file / multi_edit)

  • 四个工具全部新增可选的 \encoding\ 参数,支持 \UTF-8, \GB18030(兼容 GBK/GB2312), \UTF-16 LE/BE\ 等 8 种编码
  • write_file 编码保持:覆写已有文件时自动保留原文件编码(之前总是写 UTF-8,导致 GBK/UTF-16 文件编码丢失)
  • edit_file / multi_edit:支持编码覆盖参数,读取和写回都使用指定编码
  • read_file:支持编码覆盖参数,跳过自动检测直接按指定编码解码
  • Preview 方法(审批预览)同步支持 encoding 参数

2. 桌面文件浏览器编码选择器

  • 文件预览 meta 栏新增编码下拉菜单,可手动选择编码重新读取文件
  • 切换文件时自动重置为 Auto 模式
  • FilePreview 接口增加 encoding 字段回显检测到的编码

3. 回滚 Bug 修复

  • 根因:回滚后旧检查点(checkpoint)未清理,新的 turn 编号与旧快照冲突,导致 \RestoreCode\ 取到错误的(更旧的)快照
  • 修复:新增 \checkpoint.Store.Prune(fromTurn)\ 方法,回滚时清理 \Turn >= fromTurn\ 的所有检查点(内存 + 磁盘 JSON)
  • 前端:Rewind / Fork / Summarize 错误不再静默吞掉,通过 \local_notice\ 显示给用户

4. 共享编码 API

  • \ ileenc.Name(Kind)\ / \ ileenc.ParseName(string)\ 统一编码名称映射

  • eadFileEncodedWith()\ / \writeFileEncodedWith()\ 支持编码覆盖

Files Changed / 改动文件 (18 files)

Area Files
Encoding package \internal/fileutil/encoding/encoding.go\
Tool implementations \
eadfile.go, \writefile.go, \editfile.go, \multiedit.go, \preview.go, \encoding_helpers.go\
Checkpoint / Rewind \internal/checkpoint/checkpoint.go, \internal/control/controller.go\
Desktop frontend \WorkspacePanel.tsx, \�ridge.ts, \ ypes.ts, \useController.ts, \styles.css\
Desktop backend \�pp.go\
i18n \en.ts, \zh.ts\

Testing / 测试

  • ✅ \go vet ./...\
  • ✅ \go test ./internal/checkpoint/... ./internal/tool/builtin/... ./internal/fileutil/encoding/...\
  • ✅ TypeScript \ sc --noEmit\
  • ✅ Vite production build
  • ✅ \wails build\ 完整桌面版编译

@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 4, 2026
expfukck added 2 commits June 4, 2026 19:41
Add an encoding override dropdown to the workspace file preview panel,
allowing users to manually select file encoding when auto-detection
produces incorrect results.

Backend (desktop/app.go):
- Add Encoding field to FilePreview struct
- Extend ReadFile(rel, enc) with optional encoding override parameter
- Add encodingName() and parseEncoding() helper functions
- Support: UTF-8, UTF-8 BOM, GB18030, UTF-16 LE/BE (with/without BOM)

Frontend (WorkspacePanel.tsx):
- Add ENCODING_OPTIONS list and encodingOverride state
- Add encoding selector dropdown in preview meta bar
- Auto-reset encoding override when switching files or workspaces
- Re-read file with selected encoding on change

Also updated: types.ts, bridge.ts, styles.css, en.ts, zh.ts
- Add optional 'encoding' parameter to read_file, write_file, edit_file,
  and multi_edit tools (supports UTF-8, GB18030/GBK, UTF-16 LE/BE, etc.)
- write_file now preserves existing file encoding instead of always
  writing UTF-8, preventing silent charset corruption
- Add fileenc.Name() and fileenc.ParseName() shared API in the encoding
  package, replacing duplicated logic in desktop/app.go
- Add encoding_helpers.readFileEncodedWith() and writeFileEncodedWith()
  for encoding override support
- Preview methods (editFile, multiEdit) now respect the encoding parameter

- Fix rewind not restoring files: add checkpoint.Store.Prune() to clean
  up stale checkpoints after rewind, preventing turn-number collisions
  that caused RestoreCode to pick wrong (older) snapshots
- Fix frontend silently swallowing Rewind/Fork/Summarize errors — now
  surfaces failures via local_notice in the UI
@expfukck expfukck force-pushed the feat/encoding-support-and-rewind-fix branch from c4d0e2d to 9864c14 Compare June 4, 2026 11:42
expfukck added 3 commits June 4, 2026 20:21
- Add 'file_encoding' field to Config struct (reasonix.toml)
- All tools (read_file, write_file, edit_file, multi_edit) now use
  the project encoding as default when no per-call override is given
- write_file preserves existing file encoding instead of always UTF-8
- WorkspacePanel encoding selector now controls the project-level
  setting, persists to config, affects all file operations globally
- New file creation uses the project encoding
- Settings panel exposes FileEncoding in SettingsView
- SetFileEncoding bridge method to change encoding from UI
- Pass fileEncoding through boot → Workspace → tool structs chain
- ConfineWriters accepts optional fileEncoding parameter
RenderTOML is a manual field-by-field renderer — adding FileEncoding to
the Config struct alone was not enough. The field was silently dropped
on save, so the UI encoding change never reached the tools.

Now file_encoding renders as an active TOML line when set, or as a
commented example when empty (matching the existing pattern for language,
planner_model, etc.).
The encoding setting is project-level, not per-file. Moved the dropdown
from the file preview meta bar (only visible when a file is open) to the
file browser's top toolbar next to Files/Changed tabs, so it's always
accessible without needing to open a file first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant