diff --git a/README.md b/README.md index c08b8556a..edd2e58db 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # CoreCoder -**The nanoGPT of coding agents. A 1.4k-line engine inside 3,307 readable lines of pure Python: understand how a coding agent actually works, then fork your own.** +**The nanoGPT of coding agents. A 1.5k-line engine inside 3,343 readable lines of pure Python: understand how a coding agent actually works, then fork your own.** *learn from it · fork it · ship something better* @@ -12,7 +12,7 @@ [![Python](https://img.shields.io/badge/python-3.10+-blue)](https://python.org) [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE) [![Tests](https://github.com/he-yufeng/CoreCoder/actions/workflows/ci.yml/badge.svg)](https://github.com/he-yufeng/CoreCoder/actions) -[![engine](https://img.shields.io/badge/engine-1511_LoC-blue)](article/00-index_EN.md) +[![engine](https://img.shields.io/badge/engine-1515_LoC-blue)](article/00-index_EN.md) [![essays](https://img.shields.io/badge/source--reading-8_bilingual-orange)](article/00-index_EN.md) @@ -25,7 +25,7 @@ | | CoreCoder | Claude Code | aider | nanoGPT | |---|---|---|---|---| -| Lines of code | ~1,511 engine / 3,307 total | hundreds of thousands (closed) | tens of thousands of Python | ~600 (two files) | +| Lines of code | ~1,515 engine / 3,343 total | hundreds of thousands (closed) | tens of thousands of Python | ~600 (two files) | | Time to read it all | one afternoon | can't (closed) | a few days of slogging | one afternoon | | Breakpoint, change, rerun? | yes, every line | no | yes, but there's a lot | yes | | What it's for | understand one, then fork your own | production coding assistant | terminal pair-programming | minimal GPT for teaching | @@ -36,9 +36,9 @@ The nanoGPT column is there as a reference point: minimal, readable, but it teac I've always felt coding agents get talked about as if they were arcane. Strip a tool like Claude Code or Cursor all the way down and the core is a `while` loop wrapped around a large model, plus seven or eight tools that let it actually do things. The hard part was never the loop; it's everything the loop has to cope with once it meets the real world. CoreCoder is the minimal version that writes that core out honestly. -The engine (loop, model interface, context, tools, sessions) is 1,511 lines once you drop blank lines and comments. Counting the outer CLI, config and packaging too, the whole package is 26 files: 3,307 physical lines, 2,731 net, every one short enough to read in a single sitting. The growth since the original 1,161-line snapshot went into visible features: plan mode, hooks and checkpoints, each documented below. +The engine (loop, model interface, context, tools, sessions) is 1,515 lines once you drop blank lines and comments. Counting the outer CLI, config and packaging too, the whole package is 26 files: 3,343 physical lines, 2,762 net, every one short enough to read in a single sitting. The growth since the original 1,161-line snapshot went into visible features: plan mode, hooks and checkpoints, each documented below. -And it really runs: reads and writes files, executes shell, spawns sub-agents, compacts context in three tiers, and tells you the tokens and dollars a run burned whenever you ask. Anything that would mutate your disk or run a command stops for your consent first. The suite has 356 offline tests and an opt-in live smoke test. But the point of it running isn't to become your daily driver. It runs so the walkthrough can't lie: a reference that shows how an agent works has to actually work. +And it really runs: reads and writes files, executes shell, spawns sub-agents, compacts context in three tiers, and tells you the tokens and dollars a run burned whenever you ask. Anything that would mutate your disk or run a command stops for your consent first. The suite has 360 offline tests and an opt-in live smoke test. But the point of it running isn't to become your daily driver. It runs so the walkthrough can't lie: a reference that shows how an agent works has to actually work. The code came out of a public teardown: open analyses have already exposed a lot of the load-bearing architecture inside production agents like Claude Code. I took the most essential layer and rewrote it honestly, in as little code as I could. So reading CoreCoder is roughly like reading a runnable, annotated take on how that kind of agent works, except it's only a minimal reimplementation, sitting right there on your machine for you to take apart and change. @@ -101,15 +101,15 @@ corecoder/ ├── prompt.py system prompt 41 lines ├── cli.py REPL + slash commands + one-shot 393 lines ├── config.py env-var config 55 lines -├── checkpoints.py /undo snapshot and restore 93 lines +├── checkpoints.py /undo snapshot and restore 125 lines ├── demo.py offline end-to-end demo 101 lines └── tools/ ├── bash.py shell + dangerous-command gate + cd 203 lines - ├── edit.py unique-match search/replace + diff 99 lines + ├── edit.py unique-match search/replace + diff 101 lines ├── grep.py content search 93 lines ├── glob_tool.py filename matching 52 lines ├── read.py file read 56 lines - ├── write.py file write 46 lines + ├── write.py file write 48 lines ├── todo.py agent-maintained task checklist 79 lines ├── agent.py sub-agent teams + isolation 224 lines └── base.py tool base class 32 lines @@ -229,7 +229,7 @@ Inside the REPL, `/help` lists everything; these are the ones you'll reach for: quit / exit exit (Ctrl+C cancels the current round) ``` -Session IDs are sanitized to safe characters before they become filenames, every archive lands under `~/.corecoder/sessions`, and a malicious session name can't traverse out. Undo history persists the same way: checkpoints land in `~/.corecoder/checkpoints.json`, so `/undo` still reaches back after a restart. The cost estimate behind `/tokens` reads a built-in price table, and `~/.corecoder/pricing.json` overrides any entry in it, so a new model or a moved price lands without waiting for a release. +Session IDs are sanitized to safe characters before they become filenames, every archive lands under `~/.corecoder/sessions`, and a malicious session name can't traverse out. Undo history persists the same way: checkpoints land in `~/.corecoder/checkpoints.json`, so `/undo` still reaches back after a restart. Each checkpoint also records the bytes the edit produced; if the file changed again by hand or through bash, `/undo` keeps the newer work and the checkpoint instead of overwriting it. The cost estimate behind `/tokens` reads a built-in price table, and `~/.corecoder/pricing.json` overrides any entry in it, so a new model or a moved price lands without waiting for a release. ## Permissions diff --git a/README_CN.md b/README_CN.md index 29115e506..3dd538a7c 100644 --- a/README_CN.md +++ b/README_CN.md @@ -2,7 +2,7 @@ # CoreCoder -**编程 agent 里的 nanoGPT。1.4k 行引擎、整包 3307 行纯 Python 全部一口气可读,读懂一个 coding agent 到底怎么运作,再 fork 出你自己的。** +**编程 agent 里的 nanoGPT。1.5k 行引擎、整包 3343 行纯 Python 全部一口气可读,读懂一个 coding agent 到底怎么运作,再 fork 出你自己的。** *learn from it · fork it · ship something better* @@ -12,7 +12,7 @@ [![Python](https://img.shields.io/badge/python-3.10+-blue)](https://python.org) [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE) [![Tests](https://github.com/he-yufeng/CoreCoder/actions/workflows/ci.yml/badge.svg)](https://github.com/he-yufeng/CoreCoder/actions) -[![engine](https://img.shields.io/badge/engine-1511_LoC-blue)](article/) +[![engine](https://img.shields.io/badge/engine-1515_LoC-blue)](article/) [![源码导读](https://img.shields.io/badge/源码导读-8篇双语-orange)](article/) @@ -25,7 +25,7 @@ | | CoreCoder | Claude Code | aider | nanoGPT | |---|---|---|---|---| -| 代码量 | 引擎约 1511 行 / 整包 3307 行 | 几十万行(闭源) | 数万行 Python | 约 600 行(两个文件) | +| 代码量 | 引擎约 1515 行 / 整包 3343 行 | 几十万行(闭源) | 数万行 Python | 约 600 行(两个文件) | | 读完要多久 | 一个下午 | 读不了(闭源) | 得啃几天 | 一个下午 | | 能不能下断点改了再跑 | 能,每一行 | 不能 | 能,但量大 | 能 | | 定位 | 读懂并 fork 出你自己的 agent | 生产级编程助手 | 终端结对编程 | 教学用最小 GPT | @@ -36,9 +36,9 @@ nanoGPT 那一列是拿来对照的:它最小、可读,但教的是训一个 我一直觉得 coding agent 被讲得太玄了。把 Claude Code、Cursor 这类工具扒到底,核心是一个 while 循环套着一个大模型,外加七八个让它能真正动手的工具。难的从来不是这个循环,而是循环跑进真实世界以后要兜的那些底。CoreCoder 就是把这个核心老老实实写出来的最小版本。 -引擎部分(循环、模型接口、上下文、工具、会话)去掉空行和注释是 1511 行。连最外层的 CLI、配置、打包一起算,整个包 26 个文件、物理 3307 行、净 2731 行,每个文件都短到能一口气读完。自 1161 行快照之后的增长都花在了看得见的功能上:plan mode、hooks、checkpoints,下文各有交代。 +引擎部分(循环、模型接口、上下文、工具、会话)去掉空行和注释是 1515 行。连最外层的 CLI、配置、打包一起算,整个包 26 个文件、物理 3343 行、净 2762 行,每个文件都短到能一口气读完。自 1161 行快照之后的增长都花在了看得见的功能上:plan mode、hooks、checkpoints,下文各有交代。 -它真能跑:读写文件、执行 shell、派子 agent、分三层压上下文,还能随时把这趟烧掉的 token 和美元数报给你。任何要动你磁盘、要跑命令的调用,都会先停下来等你点头。现在有 356 个离线测试,另有按需开启的真实 API 冒烟。但能跑不是为了劝你拿去日用,而是为了让这份「注释」不撒谎:一个解释 agent 怎么运作的范例,自己得真能运作。 +它真能跑:读写文件、执行 shell、派子 agent、分三层压上下文,还能随时把这趟烧掉的 token 和美元数报给你。任何要动你磁盘、要跑命令的调用,都会先停下来等你点头。现在有 360 个离线测试,另有按需开启的真实 API 冒烟。但能跑不是为了劝你拿去日用,而是为了让这份「注释」不撒谎:一个解释 agent 怎么运作的范例,自己得真能运作。 代码来自一次公开拆解。公开的源码分析里,Claude Code 这类生产级 agent 暴露出不少关键架构,我挑出最核心的一层,用尽量少的代码诚实地复写了一遍。所以读 CoreCoder,约等于读一份基于公开源码分析的「可运行注释版」:讲的是这类 agent 的核心思路,而它本身只是最小复写,就摆在你机器上,随你拆、随你改。 @@ -101,15 +101,15 @@ corecoder/ ├── prompt.py 系统提示词 41 行 ├── cli.py REPL + 斜杠命令 + 一次性模式 393 行 ├── config.py 环境变量配置 55 行 -├── checkpoints.py /undo 快照与回滚 93 行 +├── checkpoints.py /undo 快照与回滚 125 行 ├── demo.py 离线端到端演示 101 行 └── tools/ ├── bash.py shell + 危险命令闸 + cd 追踪 203 行 - ├── edit.py 唯一匹配搜索替换 + diff 99 行 + ├── edit.py 唯一匹配搜索替换 + diff 101 行 ├── grep.py 内容搜索 93 行 ├── glob_tool.py 文件名匹配 52 行 ├── read.py 文件读取 56 行 - ├── write.py 文件写入 46 行 + ├── write.py 文件写入 48 行 ├── todo.py agent 自维护的任务清单 79 行 ├── agent.py 子 agent 团队与隔离 224 行 └── base.py 工具基类 32 行 @@ -229,7 +229,7 @@ README 只给方向,每条的代码细节第七篇接着讲。挑一个动手 quit / exit 退出(Ctrl+C 取消当前回合) ``` -会话 ID 会先清洗成安全字符再拿去当文件名,存档统统落在 `~/.corecoder/sessions` 里,恶意会话名穿越不出去。undo 历史也一样落盘:快照写在 `~/.corecoder/checkpoints.json`,重启之后 `/undo` 照样能往回撤。`/tokens` 的费用估算读的是内置价目表,在 `~/.corecoder/pricing.json` 里写自己的价格就会盖掉对应条目,新模型、调价都不用等发版。 +会话 ID 会先清洗成安全字符再拿去当文件名,存档统统落在 `~/.corecoder/sessions` 里,恶意会话名穿越不出去。undo 历史也一样落盘:快照写在 `~/.corecoder/checkpoints.json`,重启之后 `/undo` 照样能往回撤。每份快照还会记下这次编辑实际写出的字节;如果文件后来又被手工或 bash 改过,`/undo` 会保留后来的改动和快照,不会直接覆盖。`/tokens` 的费用估算读的是内置价目表,在 `~/.corecoder/pricing.json` 里写自己的价格就会盖掉对应条目,新模型、调价都不用等发版。 ## 权限 diff --git a/article/00-index.md b/article/00-index.md index 84b13814c..b2714ed99 100644 --- a/article/00-index.md +++ b/article/00-index.md @@ -8,7 +8,7 @@ 因为 Claude Code 本体太大了。它的代码量在几十万行的量级,光一个负责跑 shell 命令的 BashTool 就上千行,真要逐行读完,多数人会在第三个文件就关掉编辑器。可 agent 的核心其实没那么复杂,复杂的是工程化之后那些为真实世界兜底的边角:模型半路被打断怎么办、上下文塞满了怎么办、十个工具调用同时回来怎么办、provider 偶尔抽风返回 500 又怎么办。这些东西摊在几十万行里,你很难一眼看到骨架。 -CoreCoder 做的事,是把这套骨架压到一千四百行出头的纯 Python。准确说,agent 引擎(循环、模型接口、上下文、工具、会话)去掉空行和注释是 1511 行;连最外层的 CLI 终端、配置和打包都算上,整个包去掉空行和注释 2731 行,物理代码 3307 行。每个文件都短到能一口气读完,跑起来又确实是个能改代码、能跑命令、能自己开子任务、能压缩上下文、能算钱的 agent。它不是玩具。它是把生产级 agent 的每个设计决策,拣出最核心的那版,用最少的代码诚实地写一遍。 +CoreCoder 做的事,是把这套骨架压到一千四百行出头的纯 Python。准确说,agent 引擎(循环、模型接口、上下文、工具、会话)去掉空行和注释是 1515 行;连最外层的 CLI 终端、配置和打包都算上,整个包去掉空行和注释 2762 行,物理代码 3343 行。每个文件都短到能一口气读完,跑起来又确实是个能改代码、能跑命令、能自己开子任务、能压缩上下文、能算钱的 agent。它不是玩具。它是把生产级 agent 的每个设计决策,拣出最核心的那版,用最少的代码诚实地写一遍。 读它,约等于读一份 Claude Code 的「可运行注释版」。区别在于,CoreCoder 的每一行你都能在自己机器上断点、改、跑、看它出什么效果。本系列里我引用的每一个行数、每一段代码,都是从仓库里现读现核的,不是凭印象。这点我后面会反复较真,因为编码 agent 这个领域,太多文章在凭感觉编数字。 diff --git a/article/00-index_EN.md b/article/00-index_EN.md index 0313acd8b..77fa3545c 100644 --- a/article/00-index_EN.md +++ b/article/00-index_EN.md @@ -8,7 +8,7 @@ First, use CoreCoder, an open source project whose core runs to just over fourte Because Claude Code itself is too big. Its codebase runs into the hundreds of thousands of lines, and the BashTool alone, the part that runs shell commands, is over a thousand. Read it line by line and most people close the editor by the third file. Yet the core of an agent isn't really that complicated. What's complicated is everything engineered around it to survive the real world: what to do when the model gets interrupted mid-stream, when the context window fills up, when ten tool calls come back at once, when a provider hiccups and returns a 500. Spread across hundreds of thousands of lines, that skeleton is hard to see. -What CoreCoder does is squeeze the skeleton down to just over fourteen hundred lines of pure Python. To be precise, the agent engine (the loop, model interface, context, tools, session) is 1,511 lines once you drop blank lines and comments; add the outermost CLI terminal, config, and packaging and the whole package is 2,731 lines without blanks and comments, 3,307 physical. Every file is short enough to read in one sitting, and what runs is genuinely an agent: it edits code, runs commands, spins up its own subtasks, compresses context, tracks cost. It is not a toy. It takes every design decision a production agent makes, picks the most essential version of each, and writes it out honestly in the least code it can. +What CoreCoder does is squeeze the skeleton down to just over fourteen hundred lines of pure Python. To be precise, the agent engine (the loop, model interface, context, tools, session) is 1,515 lines once you drop blank lines and comments; add the outermost CLI terminal, config, and packaging and the whole package is 2,762 lines without blanks and comments, 3,343 physical. Every file is short enough to read in one sitting, and what runs is genuinely an agent: it edits code, runs commands, spins up its own subtasks, compresses context, tracks cost. It is not a toy. It takes every design decision a production agent makes, picks the most essential version of each, and writes it out honestly in the least code it can. Reading it is close to reading a runnable, annotated edition of Claude Code. The difference is that every line of CoreCoder is something you can breakpoint, change, run, and watch on your own machine. Every line count and every snippet I quote in this series is read straight out of the repository, not recalled from memory. I'll keep being pedantic about that, because in the coding-agent space far too many write-ups just make the numbers up. diff --git a/corecoder/checkpoints.py b/corecoder/checkpoints.py index 0519a0ce9..3f4d661a6 100644 --- a/corecoder/checkpoints.py +++ b/corecoder/checkpoints.py @@ -9,15 +9,26 @@ import base64 import json +from dataclasses import dataclass from pathlib import Path CHECKPOINTS_FILE = Path.home() / ".corecoder" / "checkpoints.json" -# (path, prior bytes or None if the file did not exist) -_stack: list[tuple[str, bytes | None]] = [] +@dataclass +class _Checkpoint: + path: str + prior: bytes | None + after: bytes | None = None + + +_stack: list[_Checkpoint] = [] _loaded = False +def _encode(data: bytes | None) -> str | None: + return base64.b64encode(data).decode("ascii") if data is not None else None + + def _ensure_loaded() -> None: global _loaded if _loaded: @@ -27,7 +38,12 @@ def _ensure_loaded() -> None: entries = json.loads(CHECKPOINTS_FILE.read_text(encoding="utf-8")) for e in entries: prior = e["prior"] - _stack.append((e["path"], base64.b64decode(prior) if prior is not None else None)) + after = e.get("after") + _stack.append(_Checkpoint( + e["path"], + base64.b64decode(prior) if prior is not None else None, + base64.b64decode(after) if after is not None else None, + )) except (OSError, ValueError, KeyError, TypeError): # a missing or corrupt stack just means nothing to undo pass @@ -35,8 +51,8 @@ def _ensure_loaded() -> None: def _save() -> None: entries = [ - {"path": path, "prior": base64.b64encode(prior).decode("ascii") if prior is not None else None} - for path, prior in _stack + {"path": c.path, "prior": _encode(c.prior), "after": _encode(c.after)} + for c in _stack ] try: CHECKPOINTS_FILE.parent.mkdir(parents=True, exist_ok=True) @@ -51,17 +67,33 @@ def _save() -> None: def record(path: Path) -> None: """Capture the pre-mutation state of path. Call right before writing.""" _ensure_loaded() - _stack.append((str(path), path.read_bytes() if path.exists() else None)) + _stack.append(_Checkpoint(str(path), path.read_bytes() if path.exists() else None)) _save() +def wrote(path: Path, content: bytes) -> None: + """Record the bytes produced by the mutation that followed record().""" + _ensure_loaded() + if _stack and _stack[-1].path == str(path) and _stack[-1].after is None: + _stack[-1].after = content + _save() + + def undo() -> str: """Restore the most recent checkpoint.""" _ensure_loaded() if not _stack: return "Nothing to undo." - path_str, prior = _stack.pop() + checkpoint = _stack[-1] + path_str, prior = checkpoint.path, checkpoint.prior p = Path(path_str) + current = p.read_bytes() if p.exists() else None + if checkpoint.after is not None and p.exists() and current != checkpoint.after: + return ( + f"Skipped {path_str}: the file changed after the edit. " + "The checkpoint was kept; review the file before undoing it." + ) + _stack.pop() if prior is None: p.unlink(missing_ok=True) msg = f"Removed {path_str} (created this session)." diff --git a/corecoder/tools/edit.py b/corecoder/tools/edit.py index e10798fd8..a623575e0 100644 --- a/corecoder/tools/edit.py +++ b/corecoder/tools/edit.py @@ -11,6 +11,7 @@ from typing import ClassVar from ..checkpoints import record as _record_checkpoint +from ..checkpoints import wrote as _record_write from .base import Tool # track files changed this session for /diff @@ -73,6 +74,7 @@ def execute(self, file_path: str, old_string: str, new_string: str) -> str: new_content = content.replace(old_string, new_string, 1) _record_checkpoint(p) p.write_text(new_content, encoding="utf-8") + _record_write(p, p.read_bytes()) _changed_files.add(str(p)) # generate a unified diff so the user/LLM can see exactly what changed diff --git a/corecoder/tools/write.py b/corecoder/tools/write.py index 1a8000342..b4c13e16c 100644 --- a/corecoder/tools/write.py +++ b/corecoder/tools/write.py @@ -4,6 +4,7 @@ from typing import ClassVar from ..checkpoints import record as _record_checkpoint +from ..checkpoints import wrote as _record_write from .base import Tool from .edit import _changed_files @@ -38,6 +39,7 @@ def execute(self, file_path: str, content: str) -> str: p.parent.mkdir(parents=True, exist_ok=True) _record_checkpoint(p) p.write_text(content, encoding="utf-8") + _record_write(p, p.read_bytes()) _changed_files.add(str(p)) n_lines = content.count("\n") + (1 if content and not content.endswith("\n") else 0) return f"Wrote {n_lines} lines to {file_path}" diff --git a/pyproject.toml b/pyproject.toml index 6dc09e7bf..e504d040c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "corecoder" version = "0.12.0" -description = "Minimal AI coding agent (3,276 lines of Python) inspired by Claude Code. Works with any LLM. (formerly NanoCoder)" +description = "Minimal AI coding agent (3,343 lines of Python) inspired by Claude Code. Works with any LLM. (formerly NanoCoder)" readme = "README.md" license = "MIT" requires-python = ">=3.10" diff --git a/tests/test_checkpoints.py b/tests/test_checkpoints.py index 492531793..7cd45eade 100644 --- a/tests/test_checkpoints.py +++ b/tests/test_checkpoints.py @@ -2,6 +2,9 @@ from __future__ import annotations +import base64 +import json + from corecoder import checkpoints from corecoder.tools.edit import EditFileTool from corecoder.tools.write import WriteFileTool @@ -103,3 +106,59 @@ def test_corrupt_stack_file_means_nothing_to_undo(tmp_path): _simulate_restart() assert checkpoints.pending() == 0 assert checkpoints.undo() == "Nothing to undo." + + +def test_undo_keeps_later_manual_edits(tmp_path): + f = tmp_path / "a.py" + f.write_text("v1\n", encoding="utf-8") + EditFileTool().execute(str(f), "v1", "v2") + f.write_text("keep my manual work\n", encoding="utf-8") + + result = checkpoints.undo() + + assert "changed after the edit" in result + assert f.read_text() == "keep my manual work\n" + assert checkpoints.pending() == 1 + + +def test_undo_keeps_a_file_replaced_after_creation(tmp_path): + f = tmp_path / "new.py" + WriteFileTool().execute(str(f), "agent\n") + f.write_text("manual\n", encoding="utf-8") + + result = checkpoints.undo() + + assert "changed after the edit" in result + assert f.read_text() == "manual\n" + assert checkpoints.pending() == 1 + + +def test_conflicted_undo_keeps_the_checkpoint_until_resolved(tmp_path): + first = tmp_path / "first.py" + latest = tmp_path / "latest.py" + first.write_text("old\n", encoding="utf-8") + EditFileTool().execute(str(first), "old", "agent") + WriteFileTool().execute(str(latest), "agent\n") + latest.write_text("manual\n", encoding="utf-8") + + assert "changed after the edit" in checkpoints.undo() + assert checkpoints.pending() == 2 + latest.unlink() + assert checkpoints.undo() == f"Removed {latest} (created this session)." + assert checkpoints.undo() == f"Restored {first}." + assert first.read_text() == "old\n" + assert checkpoints.pending() == 0 + + +def test_legacy_checkpoint_still_restores(tmp_path): + f = tmp_path / "a.py" + f.write_text("v1\n", encoding="utf-8") + checkpoints.CHECKPOINTS_FILE.write_text( + json.dumps([{"path": str(f), "prior": base64.b64encode(b"v1\n").decode()}]), + encoding="utf-8", + ) + f.write_text("v2\n", encoding="utf-8") + + _simulate_restart() + assert checkpoints.undo() == f"Restored {f}." + assert f.read_text() == "v1\n"