Skip to content

feat(tools): append_file 工具输出支持 diff 预览 - #85

Merged
h3c-hexin merged 3 commits into
mainfrom
feat/append-file-diff-preview
Jul 30, 2026
Merged

feat(tools): append_file 工具输出支持 diff 预览#85
h3c-hexin merged 3 commits into
mainfrom
feat/append-file-diff-preview

Conversation

@asto18089

@asto18089 asto18089 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

概述

append_filewrite_file / edit_file 一样展示带行号、着色和可展开的 inline unified diff,同时兼容旧 session 的纯字节摘要。

变更

  • CodeWhale fork:append_file 输出 inline unified diff 和尾部字节摘要;旧文件超过 512KB 或非 UTF-8 时安全回退。
  • 前端:新版输出进入 DiffView;旧格式继续显示字节摘要;[diff omitted] 保留完整原因。
  • fork 合规:CodeWhale PR chore(deps): bump react-router and react-router-dom in /pinvou3-app/src-tauri/resources/common/web-template #2 已合并为 cb93e0f4466d,发布稳定标签 pinvou-v0.9.0-r2;父仓 gitlink、固定标签、守护指纹及中英文 fork 文档已同步。
  • 测试:补齐 append diff、旧格式和省略 diff 三类真实渲染断言,以及 CodeWhale forkguard 行为回归。

实际验证

  • cargo fmt --all -- --check
  • cargo test -p codewhale-tui --lib tools::file --no-fail-fast:77 passed
  • CodeWhale CI:workspace/all-targets、forkguard、DCO、Gitleaks、贡献门禁全部通过
  • ./scripts/verify-public-submodule.sh
  • ./scripts/fork-guard.sh --fast
  • python3 scripts/architecture-guard.py
  • node pinvou3-app/tests/unified_diff_parser.test.js:24 passed
  • node pinvou3-app/tests/diff_viewer_ui_smoke.mjs
  • npm --prefix pinvou3-app run lint:ui

风险

inline diff 仅在旧文件不超过 512KB 时生成;超限和非 UTF-8 文件不会读取并比较完整内容,避免大文件内存放大。

@asto18089

Copy link
Copy Markdown
Collaborator Author

审阅后已推送两处修复:

本仓 commit e2ce2be(前端):

  • [diff omitted] 回退输出(旧文件 >512KB)不再走 appendBytes 字节摘要兜底——之前 omit 说明行会被吞掉,用户看不到 diff 被省略的原因;现在与 write_file 一样落到 OutputPre 展示完整原文
  • diff_viewer_ui_smoke 补该场景 fixture 与断言(真实 Chrome 渲染 ok,unified_diff_parser 24 passed,eslint 0 errors)

fork 侧 commit a1728d651(Pinvou/CodeWhale#2,已推到 asto18089/DeepSeek-TUIfeat/append-file-inline-diff):

  • 修鲁棒性隐患:追加前快照旧内容的 read_to_string 原本在 512KB 上限判断之前执行,向超大文件(如数 GB 日志)追加会把整个文件读进内存。改为先用 metadata 的 before_len 门控,超限直接走 [diff omitted] 不再读取;prior.len() 检查保留作兜底
  • 补非 UTF-8 旧文件回退纯字节摘要的 forkguard 回归
  • cargo test -p codewhale-tui --lib tools::file:77 passed

待办(转正前):fork PR 合并并在合并 commit 上打 pinvou-v0.9.0-r2 后,本 PR 需 bump CodeWhale gitlink + 更新 verify-public-submodule.shPINVOU_CODEWHALE_TAG(当前 fast-gate 指纹层因 gitlink 仍为 r1 而失败,属预期时序);Signed-off commits 检查失败也需处理(历史 commit 缺 sign-off)。

asto18089 and others added 3 commits July 30, 2026 13:43
底座 append_file 输出 inline unified diff 后(Pinvou/CodeWhale#2),前端工具卡片
与 write_file 一样走 DiffView 渲染带行号、着色的 diff 预览;旧 session 落盘的
纯文本输出保留 appendBytes 字节摘要兜底。fork-guard 指纹与 fork-modifications.md
按同 PR 要求随 fork patch 登记。gitlink 与稳定 tag 待 fork PR 合并后本 PR 内更新。

Signed-off-by: hexin <372726039@qq.com>
审阅发现:旧文件超 512KB 时后端输出 "摘要 + [diff omitted] 说明",
前端 appendBytes 正则兜底会吞掉 omit 说明行,用户看不到 diff 被省略的
原因。含 [diff omitted] 时不再走字节摘要兜底,与 write_file 一样落到
OutputPre 展示完整原文;diff_viewer_ui_smoke 补该场景 fixture 与断言。

Signed-off-by: asto <asto18089@126.com>
Signed-off-by: hexin <372726039@qq.com>
Signed-off-by: hexin <372726039@qq.com>
@h3c-hexin
h3c-hexin force-pushed the feat/append-file-diff-preview branch from e2ce2be to 9c57ea0 Compare July 30, 2026 06:02
@h3c-hexin
h3c-hexin marked this pull request as ready for review July 30, 2026 06:03
@h3c-hexin
h3c-hexin added this pull request to the merge queue Jul 30, 2026
Merged via the queue into main with commit 15cf05c Jul 30, 2026
22 checks passed
@h3c-hexin
h3c-hexin deleted the feat/append-file-diff-preview branch July 30, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants