Skip to content

feat: restore recent files after compaction and measure summary requests - #61

Merged
kylinmac merged 1 commit into
mainfrom
feat/compaction-file-restore
Oct 30, 2026
Merged

kylinmac merged 1 commit into
mainfrom
feat/compaction-file-restore

Conversation

@kylinmac

Copy link
Copy Markdown
Owner

改动

实现 R21.2(压缩后附回文件片段,V61)和 R21.3 的测量部分(V62)。

  • 不弹审批的读取:tools.execute 新增内部参数 nonInteractive。自动判断无法放行时,直接返回 APPROVAL_REQUIRED,不创建审批请求;显式允许和拒绝的行为不变。只有 runtime 内部会设置它,模型参数设置不了。
  • 选文件:从被总结的消息里,取成功的 Read / Edit / Write,按最近一次操作倒序。Read 保留原来的行范围,只写过的文件整份读取;近期原文里已经有最新读取结果的文件跳过。
  • 读取:在安装检查点前执行,走同一条 tools.execute 路径,所以远程路由和路径校验照旧生效。并发 2,总时限 10 秒;Stop 或超时会中止未完成的读取。
  • 预算:最多 5 个文件,单个 5K、合计 8K tokens,都只是上限。装入后必须低于下一次自动压缩线并留出余量,而且比压缩前更小;做不到就恢复 0 个。不会为了放文件去删摘要或近期原文。
  • 保存与重建:快照存在检查点 details.restoredFiles 里,和摘要分开存;落盘沿用"先落盘、后安装"的既有顺序。重建只用已存的快照,不重新读文件。
  • 发送:摘要和快照放在同一条 user 消息的两个文本块里,避免出现相邻的 user 消息。快照会注明是压缩时读到的内容,编辑前应重新读取。
  • 测量(R21.3):每次摘要请求结束后,记录耗时、结束原因,以及输入、输出、缓存读写的计数,写到本机日志 session.compaction.summary。服务商没返回用量时标为未知,不当作 0。文件恢复的结果写到 session.compaction.restore。两类日志都不含正文和路径。

更新说明(用户可见)

刻意未改

  • R21.3 的缓存复用试验没有做。按计划要先有基线数据,而基线只能来自安装版的真实会话;发版后看日志再决定。
  • 不新增读取权限,不改数据库结构,不把附回的文件当成一次新的工具调用展示。

验证

  • host-core:全量 1162 项通过、1 忽略,含新增的非交互读取用例(工作区外的文件返回 APPROVAL_REQUIRED,且不产生审批事件)。cargo fmt --check 通过,Clippy 对新代码没有报告警。
  • agent-runtime:全量 1552 项通过,新增 12 项,覆盖:选文件、并发、截断、时限、Stop、预算、详情解析、格式、不弹审批且随摘要发送、没空间时不读取、重建时不重读、测量。
  • 类型检查、pnpm lint、桌面 mcp-control 测试、文档检查都通过。

还没验证的:远程工作区下的慢读;真实会话里附回文件的实际收益;各适配器对"同一条消息里两个文本块"的处理(离线只验证了转换出的结构)。

🤖 Generated with Claude Code

R21.2: after a compaction the model lost the file contents it had just
read and either re-read them or edited from memory. A summary checkpoint
now carries up to five re-read file snapshots (5K tokens each, 8K total)
when they fit below the next compaction threshold and still shrink the
context. Reads go through the normal tools.execute path with a new
internal nonInteractive flag, so a read that would need approval is
skipped instead of prompting. Snapshots are stored next to the summary
in the checkpoint details, sent in the same user message, and never
re-read on rebuild. Zero files is a normal outcome.

R21.3: before deciding whether a cache-sharing summary request is worth
building, record duration, stop reason and input/output/cache counts for
every summary attempt in the local log. The cache trial itself waits for
that baseline from installed builds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kylinmac
kylinmac merged commit d1b88fa into main Oct 30, 2026
9 checks passed
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.

1 participant