Checkpoint
checkpoint
Targeted path snapshot and rollback for atomic batch edits.
Before applying a batch, :func:create_checkpoint captures — for every
path the batch will touch — whether it existed and its original bytes.
:func:rollback then restores exactly those paths and nothing else:
modified files are rewritten with their original bytes, files that did not
exist before are removed, and files that were deleted are recreated.
No git is involved: the snapshot is independent of the repository (it works
in a non-git directory and never runs git checkout/clean/stash).
The snapshot is serialized to a JSON string so it can ride on the existing
BatchResult.checkpoint field and cross the MCP boundary unchanged.
create_checkpoint(root, operations)
Snapshot every path operations will touch, before they are applied.
For each operation's target path the snapshot records whether the file
currently exists and, if so, its original bytes. The result is a JSON
string keyed by resolved relative path, suitable for storage on
BatchResult.checkpoint and for passing back to :func:rollback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Project root directory (all paths are relative to this). |
required |
operations
|
Sequence[Operation]
|
The batch about to be applied — replace, create and
delete operations whose |
required |
Returns:
| Type | Description |
|---|---|
str
|
A JSON snapshot string. Always returned (never |
str
|
there are operations, in git and non-git directories alike. |
Source code in packages/axm-edit/src/axm_edit/core/checkpoint.py
rollback(root, checkpoint)
Restore exactly the paths captured by checkpoint to their prior state.
Rollback is a strict inverse of the batch and best-effort: for each snapshotted path a file that existed is rewritten with its original bytes, a file that did not exist before is removed, and only the directories the batch itself created (recorded in the snapshot) are pruned — a pre-existing directory is never removed. Every captured path is attempted even if an earlier one fails, so a partial rollback is fully reported. No git command is run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Project root directory. |
required |
checkpoint
|
str
|
The JSON snapshot returned by :func: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
RollbackResult
|
class: |
RollbackResult
|
paths restored and those that could not be restored. |
|
RollbackResult
|
is |
|
RollbackResult
|
a malformed snapshot yields |
Source code in packages/axm-edit/src/axm_edit/core/checkpoint.py
snapshot_paths(checkpoint)
Return the relative paths captured by checkpoint (best-effort).
Read-only and side-effect free: a malformed snapshot yields an empty list so informational callers degrade gracefully.