Skip to content

About

Forkable agent session checkpoints. Snapshot every tool call, fork any step, compare branches. One Python file, one dependency.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Forkable Agent Checkpoints

Wraps an agent loop so every tool call commits the working tree to a hidden git ref, then forks any step with an edited instruction and compares both branches' outcomes side by side. One Python file, one dependency.

This repo is meant to be used as a GitHub template. Once it's pushed, click "Use this template" on GitHub (or gh repo create --template <org>/forkable-agent-checkpoints my-copy) to get your own copy with a clean git history, then start editing scripted_agent() to call your real model.

Hosted / full version

This repo is the free core. The packaged kit is on Gumroad: Forkable checkpoints for agent loops: a git snapshot per tool call (Python kit) ($19). Try it in the browser on the Hugging Face Space.

Quickstart

uv run main.py --selfcheck   # proves the mechanism on the bundled demo
uv run main.py                # runs the demo and prints the compare JSON

What it does

  • main.py runs an agent loop over a small seed repo (fixture/, or any directory via run --seed). After every tool call (write_file, run_tests) it snapshots the worktree as a real git commit in a bare store (runs/<root>/store.git) under refs/checkpoints/<session>/<step>, chaining each commit to the previous one. Git objects are written with dulwich, a pure-Python git implementation — no git CLI required.
  • fork <source> <step> <new-session> "<instruction>" restores that step's snapshot into a fresh worktree, re-points the new session's refs at the shared history, and re-runs the agent from step+1. An out-of-range or negative step is rejected with a clear error (exit 1), not a crash.
  • compare a b writes compare.json and a static side-by-side timeline.html. Inherited steps are shown greyed out. No server, no port.
  • With no arguments it runs the demo: main implements add() with '-' and fails its tests; fork1 forks at step 2 with the instruction changed to '+' and passes.

CLI:

uv run main.py --root runs/x run s1 "implement add using '*'"
uv run main.py --root runs/x fork s1 2 s2 "implement add using '+'"
uv run main.py --root runs/x compare s1 s2

Verification (--selfcheck re-reads every artifact from disk)

Run live on this copy, 2026-10-10:

$ uv run main.py --selfcheck
selfcheck OK: main='FAIL: FAILED (failures=1)' fork1='PASS: OK' (fork-step validation + path containment checked)

It asserts, independently of anything held in memory during the run:

  • every step has a hidden ref that resolves to the commit recorded in the timeline JSON, and each commit's parent is the previous step's commit;
  • restoring every snapshot from the object store reproduces the exact file digests recorded at that step;
  • the fork shares main's first 3 commit ids, and its step 3 is a new commit whose parent is main's step 2;
  • main ends FAIL (a - b), the fork ends PASS (a + b);
  • forking a step that doesn't exist on the source session (negative, or past its last step) raises a clear error instead of crashing or silently no-op'ing;
  • write_file rejects a path that would resolve outside the worktree.

Bringing your own model

scripted_agent(instruction) in main.py is the only function a real integration replaces. Today it returns a fixed plan derived with a regex over the instruction text — a deterministic stand-in, not a model call. Swap it for a function that calls your model with the instruction and the current worktree state, and returns the same [{"tool": ..., "args": ...}] shape; everything else (snapshotting, forking, comparing) is unchanged.

Limits, stated plainly

  • The agent is a scripted stand-in (see above) — plugging in a real model is on you, this template doesn't ship one.
  • Two tools (write_file, run_tests), two branches in the compare view, a static HTML page — no live/clickable UI.
  • The checkpoint store is a separate bare repo (runs/<root>/store.git), not the target repo's own .git. Writing refs/checkpoints/* directly into your repo is a natural next step, not shipped here.
  • Correctness-critical checks in run_session and selfcheck use bare assert, which python -O strips. Don't run this optimized.

Licensing

Two tiers — see LICENSE and COMMERCIAL-LICENSE.md for full terms (not legal advice; have counsel review before relying on either for a real sale):

Free tier Commercial — $2,000/year
Personal / educational / 90-day eval use Yes Yes
Noncommercial research Yes Yes
Use inside or on behalf of a for-profit entity No Yes
Site-wide seats, one company — Unlimited
Email support — Best-effort, 3 business days
Updates during the license year — Included

Commercial use without a license, or publishing a fork without attribution back to this repository, ends the free-tier grant (LICENSE §3).

Relationship to the $19 Gumroad kit

A simpler, license-free, one-time-download version of this same mechanism (1.0.0, no fork-step validation or timeout handling) is sold separately on Gumroad: https://vedovino.gumroad.com/l/forkable-agent-checkpoints — good for a single personal project. This template is for a team that wants a licensed, forkable source base to build on. See CHANGELOG.md for the exact code differences between the two.

Requirements

Python 3.11+ and uv. No git install, no network after uv run fetches dulwich once, no API key.

About

Forkable agent session checkpoints. Snapshot every tool call, fork any step, compare branches. One Python file, one dependency.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages