Skip to content

feat: configurable auto-pruning, cross-session rewind, and settings command#3

Open
cullendotdev wants to merge 2 commits into
arpagon:mainfrom
cullendotdev:main
Open

feat: configurable auto-pruning, cross-session rewind, and settings command#3
cullendotdev wants to merge 2 commits into
arpagon:mainfrom
cullendotdev:main

Conversation

@cullendotdev

Copy link
Copy Markdown

I built these changes for my own workflow, I wanted checkpoints to survive restarts and give me more control over retention. Opening a PR in case you're interested or want to take things in a similar direction. Happy to adjust or close if it's not a fit. No expectations either way.

Summary

Adds three user-facing features to pi-rewind while preserving full backward compatibility:

  1. Configurable auto-pruning — users can opt out of the rolling 50-checkpoint window and keep old sessions
  2. Cross-session checkpoint picker — when old sessions are kept, /rewind shows a two-step picker (session → checkpoint)
  3. /rewind-settings — interactive menu to change config live, auto-saves to ~/.pi/agent/config/rewind.json

Problem

The original extension hard-coded a 50-checkpoint rolling window per session and unconditionally pruned all checkpoints from previous sessions on startup. There was no way to:

  • Keep checkpoints across pi restarts for long-running projects
  • Change the retention limit without editing source code

Solution

A RewindConfig file at ~/.pi/agent/config/rewind.json with three knobs, all defaulting to the original behavior:

{
  "maxCheckpoints": 50,          // 0 = unlimited, never prune
  "keepOldSessions": false,      // true = survive restarts, show cross-session picker
  "cleanupHintThreshold": 200    // show cleanup hint in footer when exceeded
}

Two new commands give users direct control:

Command What it does
/rewind-settings Interactive menu to change any config value — auto-saves immediately, no restart needed
/rewind-cleanup Shows stats grouped by session, offers to prune old sessions or trim current to max

When keepOldSessions is enabled, the /rewind picker becomes a two-step flow: pick a session (grouped by date), then pick a checkpoint within it. The Esc+Esc shortcut shows current session + the most recent old session for quick access. Footer status shows a warning hint when checkpoints exceed the cleanup threshold.

Four new core functions (getCheckpointStats, pruneAllOldSessions, deleteCheckpointsBulk, diffCheckpoints) support the new commands and keep the two-layer architecture intact — all pure git, no pi dependency.

What changed

New files

  • src/config.tsRewindConfig interface, load from rewind.json, env var overrides (PI_REWIND_*)
  • CHANGELOG.md

Behavioral changes

  • /rewind picker becomes two-step when keepOldSessions is enabled
  • Footer status shows cleanup hint at threshold (◆ N checkpoints (consider /rewind-cleanup))
  • Toggling keepOldSessions off in /rewind-settings prunes old refs immediately
  • Esc+Esc shortcut is cross-session aware (shows current + 1 most recent old session)

Testing

npx tsx tests/core.test.ts
# 26 tests, 0 failures (was 20)

New coverage: cross-session pruning (with UUID-in-ref-name parsing), bulk delete, checkpoint stats, diff output.

Notes

  • pruneOldSessions / pruneAllOldSessions extract session IDs from ref names via UUID pattern matching. They only operate on checkpoints created through the standard flow (resume-{uuid}-{ts}, turn-{uuid}-{turn}-{ts}). Hand-crafted checkpoint IDs without embedded UUIDs will be skipped.
  • Pi resolves /rewind before subcommands, so cleanup and settings are registered as standalone commands (rewind-cleanup, rewind-settings) rather than subcommands.

…ommand

- RewindConfig at ~/.pi/agent/config/rewind.json with PI_REWIND_* env overrides
- Cross-session checkpoint persistence (keepOldSessions) with two-step picker
- /rewind-settings for live config changes, /rewind-cleanup for stats + prune
- getCheckpointStats, pruneAllOldSessions, deleteCheckpointsBulk, diffCheckpoints
- Prune old session refs immediately when keepOldSessions toggled off
- Cleanup hint in footer status when checkpoints exceed threshold
- 6 new unit tests (26 total), updated README, CHANGELOG.md
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