Repository navigation
fix(console): 默认 UTF-8 并兼容 Windows GBK 输出 - #2223
Merged
Merged
Conversation
xiaoyumuxi
marked this pull request as ready for review
November 20, 2026 05:12
18 of 23 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
程序向管道写 GBK 时,原来的 Go→Core JSON 文本会先把非法 UTF-8 替换成 U+FFFD,Core 无法再恢复中文。一次运行/构建/测试可能交替收到 UTF-8 和 GBK 行,本 PR 保留进程原始字节,由 Core 逐行决定编码。
默认规则是 UTF-8,仅 Windows 在某一行不合法时尝试 GBK,不依赖系统语言或 ANSI 代码页。macOS/Linux 默认只有 UTF-8;用户固定编码和插件显式声明仍可覆盖默认。
改动 / Changes
core.DecodeOutputStyle改为传[]byte和编码策略,以 base64 穿过 JSON 边界;读取 Core 独立返回的open预览,不再从不透明 state 猜当前行。新增ResolveOutputEncoding类型化桥接。RunStart、RunEvent和BuildLaunch传递 Core 校验后的outputEncoding;运行在输出前附上声明,构建提供者在启动进程前声明。宿主不添加 Java/Maven/JVM 参数,也不改变终端代码页。consoleEncoding,通过原子快照供后台观察器读取;不读写工具原生配置。文件/控制台编码共用显示名,避免两份表;后台读取失败接入已有事件。604699f0df9a7c5ec1b245d3f2526d158f5a8eed(Core win端-检查更新 #128)。已无本地覆盖构建验证,远端 pin 可获取。不在本 PR 范围内 / Out of scope
Java/Maven 插件专属 JVM 参数、终端代码页切换未做。同一行内部混用编码或 GBK 恰好也是合法 UTF-8 时无法可靠自动识别,可用固定编码或声明;自动规则不承诺任意编码识别。完整应用窗口的 Run、Build、Tests、复制和链接操作未逐项验收。
类型专属:fix
复现与根因
B9 B9 BD A8(GBK“构建”),原DecodeOutputStyle(text string)把字符串作为 JSON 文本发送;JSON 会先替换非法 UTF-8。期望是控制台出现“构建”且保留颜色、复制/搜索文本,修复后字节原样交给 Core。desktop/internal/core/output_style.go原 text-only JSON 边界;output_style.go原字符补齐只处理 UTF-8。沿用路径可追到dacbce692(fix(desktop): 日志接入审计修复:操作串联、引擎日志转发、被拒事件可见和插件日志接线 #1945)及9f4d5fb05(feat(run): 运行控制台加自动换行开关,沿用 Git 控制台的换行与省略号 #2138)的控制台实现,未把其中某条误称为首次引入 GBK 缺陷。检查项
.agents/notes/implemented/bug-fix/2026-11-20-console-output-encoding.md记录行为、取舍及性能。范围检查 / Scope checks
功能矩阵 / Feature matrix
console-output-encoding.json:两端 implemented;完整窗口验证未完成,verification 均 pending。verify-platform-feature-matrix.sh及相对0119f4107的 change gate 通过。.artifacts/的生成矩阵视图。插件归属 / Plugin ownership
UI 验证 / UI evidence
TestVisualConsoleEncoding的页面/下拉、明/暗、中文/英文,两端共 16 张实际 PNG,1800×1400;无头测试已退出。新页面无旧版对应页,没有伪造 before。docs/assets/console-output-encoding,采集基线和命令见其中 README。windows:true策略以覆盖较长候选,不代表 macOS 默认 GBK;实际 macOS 默认仅 UTF-8。统一日志系统 / Structured logging
reportOutputStyleFailure/后台失败事件,每个控制台只记录首次降级;catalog 失败走backgroundFailed。未新增事件 ID 或逐行 INFO。界面文案 / i18n
shared/i18n/features/console-encoding.json,中英完整,通过生成器更新字典;界面使用 Shared/SharedFormat。逻辑归属 / Logic placement
性能与内存 / Performance and memory
windows:true策略的主机桥接,不是 Windows/GPU 性能。纯 UTF-8 桥接耗时约 +15%,累计分配约多 0.65 MiB/批,主要额外成本来自 base64/JSON。采用它是为了先保住原始字节、避免 JSON 不可逆替换,并让共享规则集中到 Core。旧 text 对照保留在同一个 Core 二进制,不是独立旧版可执行文件;混合结果处于测量波动内,不能声称更快/零开销。B/op 不是 RSS,不含 Rust 分配、UI/GPU 或整个应用原生长输出基线;后者未验证。
复现:
scripts/desktop/desktop-go.sh test ./internal/core -run '^$' -bench '^BenchmarkOutputEncodingBridge$' -benchmem -benchtime=500ms -count=5 -timeout=180s,设置LITHE_DESKTOP_CORE_PROFILE=release。设置 / Settings
插件契约 / Plugin contract
PINNED_CORE_REVISION=604699f0df9a7c5ec1b245d3f2526d158f5a8eed,已通过 validate-pins,且不使用本地覆盖执行桥接 fixture 测试通过。verify-docs.mjs、sdk-e2e.mjs通过,四官方 SDK 共 12 项通过。run/startprocess.outputEncoding到运行解码器lithe/build/prepareRunoutputEncodingoutputStyle.decode(内部 Core 命令)outputEncoding.resolve(内部 Core 命令)发行包与资源 / Bundle and resources
verify-runtime-bundle-immutability.sh在 macOS 检查两端生产源码通过。没有新增运行时可写目录或缓存。无用代码与重构 / Dead code and refactoring
验证 / Verification
desktop-go.sh test ./internal/core ./internal/workbench ./internal/pluginservice ./internal/buildprocess ./internal/settingswindow -count=1test-stability-macos.sh,筛选 Console/编码/声明test-stability-windows.ps1 -Scope DesktopGo,五包相同筛选desktop-go.sh test -race ./internal/workbench ./internal/settingswindow -run '^TestConsole'TestVisualConsoleEncodingdesktop-go.sh test ./internal/core -run 'Test(DecodeOutputStyle|ResolveOutputEncoding|DecodeRunStart|BuildDecodeRun)'node scripts/desktop/validate-pins.mjs未能执行的检查和原因: 未运行全仓 Go 测试,其余交给 CI;Windows 最新 main/Viva 未重新原生运行,已有原生结果针对同一任务实现的之前基线。完整窗口工作流、GPU/RSS 和原生长输出整机基线未验收;日志旧门禁等价检查未恢复。Windows 用 Bash 调用 zsh 的只读脚本曾失败,未计为 Windows 通过;macOS 已正确执行该脚本且检查两端源码。
提交前确认 / Final checks
0119f4107,目标 main。.artifacts/target产物;docs/assets 仅脱敏截图证据。