Skip to content

AtomCode v5.2.3 新子系统深度分析 — Code Rewind 代码回退(opt-in 重新启用)+ 会话快照迁移 ​

基于 strings 结构体元数据 + 状态机字符串 + 模块路径的还原分析 2026-10-14 前置报告:06-version-diff-v5.0.9-to-v5.2.3.md 姊妹报告:DEEP_ANALYSIS_54(会话事件化)、DEEP_ANALYSIS_58(后台会话与团队)


1. Code Rewind 概述(v5.1.0 起 opt-in) ​

版本行为
v5.0.9Rewind 会话回退存在(/rewind),但代码回滚能力受限
v5.1.0Code Rewind 以 opt-in 开关重新启用:`ATOMCODE_CODE_REWIND=1
v5.2.2/rewind 默认就能连代码一起回退(ATOMCODE_CODE_REWIND=0 可关闭)

2. 核心结构体 ​

struct RewindPoint with 6 elements
  fields: prompt_number / prompt_preview / before_tree / after_tree / ...
struct RewindLedger with 2 elements
  fields: previous_points / retained_points
struct RewindTransactionJournal with 7 elements
  fields: recovery_tree / target_snapshot / committed / retained / ...
struct FileChangeSummary with 4 elements
  fields: additions / deletions / ...

2.1 RewindPoint(回退点) ​

prompt_number / prompt_preview / before_tree / after_tree

→ 每个回退点记录:提示词序号、提示词预览、回退前文件树(before_tree)、回退后文件树(after_tree)。

2.2 RewindLedger(账本) ​

previous_points / retained_points

→ 账本跟踪"已保留的回退点"与"之前的所有回退点"。

2.3 RewindTransactionJournal(事务日志) ​

recovery_tree / target_snapshot / committed / retained

→ 事务日志带恢复树 + 目标快照 + 提交/保留状态。


3. 存储与预算机制 ​

3.1 磁盘与容量保护(双重熔断) ​

2 GiB      ← 磁盘下限(≥2 GiB 可用空间)
500 MiB    ← 快照总预算

→ 捕获受磁盘下限(≥2 GiB 可用空间)与快照总预算(500 MiB)双重熔断保护; 自动跳过大文件与构建/依赖目录。

3.2 存储去重(Git alternates) ​

alternates

→ 通过 Git alternates 共享真实仓库对象,不再全量复制。

3.3 清理 ​

/rewind purge 与容量报告
/rewind purge 需显式 opt-in 确认
超预算时自动跳过并告警

4. 状态机字符串 ​

code rewind requires a Git worktree
retained rewind points are not a prefix of previous points
restored files require a recovery tree
rewind point has no code snapshot
code rewind compensation lost its checkpoint
code rewind is unavailable
rewind compensation lost its workspace checkpoint
code rewind lost its workspace checkpoint
rewind transaction requires an active session lease
conversation rewind must have an undo plan

→ 前置条件:必须位于 Git worktree 中(code rewind requires a Git worktree)。 回退事务需要活动的会话租约(rewind transaction requires an active session lease)。 不变量:retained rewind points are not a prefix of previous points(保留点是前缀不变量)。


5. 与事件化会话的关系 ​

struct variant SessionEvent::Rewound with 3 elements

→ 代码回退 = 在会话事件流中追加一条 Rewound 事件,不改写历史。

5.1 会话快照不变量 ​

session snapshot changed while preparing undo
session snapshot changed while preparing compaction
canonical snapshot changed before undo commits
canonical snapshot changed before undo rollback
native undo rollback lost its session binding
session mutation conflicts
snapshot message count exceeds native metadata
turn count exceeds native metadata

→ 撤销/回退基于规范快照(canonical snapshot) + CAS 并发控制;快照变更时中止操作。


6. 用户可见语义 ​

The person rewound this conversation to before one of their earlier messages; the turns
after it are gone from the conversation. Changes those turns made to files were NOT
reverted and are still on disk.

→ 明确告知:会话回退不回滚文件改动(文件改动仍在磁盘上),仅在对话层面回退。

6.1 交互入口 ​

double Esc opens the rewind panel
/rewind opens the checkpoint picker
/rewind purge
/rewind 需显式 opt-in 确认
ATOMCODE_CODE_REWIND=0 可关闭

7. 配置与环境变量 ​

ATOMCODE_CODE_REWIND = 1|true|on|yes(启用)/ 0(关闭)
RewindPointSource / RewindPointUnavailable / CodeRewindUnavailable / Stale / current
DoneWithNote / SessionChanged / SessionPreview / Undo / restored_files

8. 结论 ​

  1. Code Rewind 受控重新启用:opt-in 开关 + 双重熔断(磁盘 ≥2 GiB / 预算 500 MiB)
  2. 存储去重:Git alternates 共享对象
  3. 回退点结构:prompt_number / prompt_preview / before_tree / after_tree
  4. 与事件化会话集成:Rewound 事件追加,不改写历史;规范快照 CAS 保护
  5. 语义清晰:会话回退不回滚文件改动

基于 VitePress 构建 · AtomCode v5.2.3 逆向工程分析文档