Skip to content

feat(fork): append_file 输出 inline unified diff - #2

Merged
h3c-hexin merged 3 commits into
Pinvou:pinvou3-cleanfrom
asto18089:feat/append-file-inline-diff
Jul 30, 2026
Merged

feat(fork): append_file 输出 inline unified diff#2
h3c-hexin merged 3 commits into
Pinvou:pinvou3-cleanfrom
asto18089:feat/append-file-inline-diff

Conversation

@asto18089

Copy link
Copy Markdown

概述

append_file 工具结果与 write_file / edit_file 一样在头部输出 inline unified diff(尾部 context + 追加行),字节摘要保留在末尾;pinvou3 前端工具卡片据此渲染与 write_file 一致的 diff 预览。

背景

pinvou3 前端对 write_file / edit_file 已基于 unified diff 渲染带行号、着色的 diff 预览(DiffView);而 append_file 只返回 Appended N bytes (X -> Y bytes) 纯文本,只能显示一行字节摘要。append_file 是大产物分块写入的主路径(skeleton + ≤16KB chunks),恰恰是最需要预览写入内容的场景。

变更

  • AppendFileTool::execute 追加前快照旧内容(已存文件非 UTF-8 时跳过,无可信 diff 基底),经新增 append_file_result_body() 输出 unified diff;原 {action} N bytes (X -> Y bytes) 字节摘要原样保留在末尾,兼容旧格式解析。
  • 新增 APPEND_FILE_INLINE_DIFF_LIMIT_BYTES = 512KB:已存文件超过该值回退 [diff omitted] 提示。取 512KB 而非 write_file 的 32KB,是因为 append 是分块写大文件的路径,旧内容两次 16KB chunk 即超过 32KB;similar 会裁剪公共前缀,diff 输出始终保持很小。
  • 工具 description 同步更正(原文称 "Returns a compact byte-count summary, not a full diff")。
  • 新增 forkguard_append_file_emits_inline_diffforkguard_append_file_omits_inline_diff_for_huge_prior_contents 两条结果式回归。

验证

  • cargo test -p codewhale-tui --lib tools::file:76 passed(含 2 条新 forkguard 测试)
  • pinvou3 父仓配套验证:./scripts/fork-guard.sh --fast 指纹层全过;前端 diff_viewer_ui_smoke.mjs(真实 Chrome 渲染)通过

备注

  • 归属 T2(工具面、文件写入与执行安全)主题;父仓配套 PR 会同 PR 带 fork-guard.sh 指纹与 docs/fork-modifications.md 更新。
  • 合并后请在合并 commit 上打稳定 tag pinvou-v0.9.0-r2:父仓 scripts/verify-public-submodule.sh 要求 gitlink 与固定 tag 解引用一致,父仓 PR 需要该 tag 才能通过 required-gate。

append_file 此前只返回字节摘要,前端无法像 write_file 一样渲染 diff 预览。
追加前快照旧内容,输出 unified diff(尾部 context + 追加行),字节摘要保留在末尾;
已存文件超过 512KB(APPEND_FILE_INLINE_DIFF_LIMIT_BYTES)或非 UTF-8 时回退
[diff omitted] / 纯字节摘要。归属 T2 工具面主题,附 forkguard 结果式回归。
@github-actions

Copy link
Copy Markdown

Thanks @asto18089 for taking the time to contribute.

This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant recurring PR access by commenting /lgtm on a pull request.

审阅发现:追加前快照旧内容的 read_to_string 在 512KB 上限判断之前执行,
向超大文件(如数 GB 日志)追加会把整个文件读入内存。改为先用 metadata
的 before_len 门控,超限直接走 [diff omitted] 说明,不再读取;prior.len()
检查保留作为 metadata 与读取之间文件增长的兜底。

同时补齐非 UTF-8 旧文件回退纯字节摘要的 forkguard 回归测试。

Signed-off-by: asto <asto18089@126.com>
@asto18089

Copy link
Copy Markdown
Author

审阅后推送修复 commit a1728d6:

  • 鲁棒性修复:追加前快照旧内容的 read_to_string 原本在 512KB 上限判断之前执行,向超大文件追加会无差别整读旧文件进内存。改为先用 metadata 的 before_len 门控(超限 → None[diff omitted] 说明,不再读取);append_file_result_body 增加 old_len 参数,prior.len() 检查保留作为 metadata 与读取之间文件增长的兜底。
  • 补测试:新增 forkguard_append_file_falls_back_to_summary_for_non_utf8_prior,覆盖非 UTF-8 旧文件回退纯字节摘要的分支。

验证:cargo test -p codewhale-tui --lib tools::file 77 passed(含 3 条 append_file inline diff 相关 forkguard)。

Signed-off-by: hexin <372726039@qq.com>
@h3c-hexin h3c-hexin closed this Jul 30, 2026
@h3c-hexin h3c-hexin reopened this Jul 30, 2026
@h3c-hexin
h3c-hexin merged commit cb93e0f into Pinvou:pinvou3-clean Jul 30, 2026
7 checks passed
h3c-hexin pushed a commit to Pinvou/pinvou-agent that referenced this pull request Jul 30, 2026
底座 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>
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