Skip to content

Add /undo and /redo commands like OpenCode - #944

Open
KazenDev wants to merge 1 commit into
CodebuffAI:mainfrom
KazenDev:feat/undo-command
Open

Add /undo and /redo commands like OpenCode#944
KazenDev wants to merge 1 commit into
CodebuffAI:mainfrom
KazenDev:feat/undo-command

Conversation

@KazenDev

@KazenDev KazenDev commented Aug 5, 2026

Copy link
Copy Markdown

Closes #907

Adds snapshot-based /undo and /redo commands modeled after OpenCode's snapshot service, with a native full-screen picker.

What

  • cli/src/utils/undo-snapshot.ts — isolated per-project git snapshot repo (track / restore / revert / diff) that never touches the real .git
  • cli/src/state/undo-store.ts — per-chat undo journal with jump-back semantics: undoing a turn reverts that turn plus everything newer
  • /undo and /redo open a /history-style picker: searchable, keyboard and mouse, with a live files panel (modified / created / deleted)
  • Colored, detailed confirmations with the diff stat (git-style colors)

Why

Users currently have no way to revert the agent's changes without manual git surgery. This is the safety net that makes it safe to let the agent edit code freely.

Notes

  • Snapshots reuse the source repo's object database (alternates) for speed
  • Best-effort: failures disable undo for that turn rather than breaking the chat
  • The user's real git history is never touched

@KazenDev

KazenDev commented Aug 5, 2026

Copy link
Copy Markdown
Author

Thanks for taking a look! Since this mirror doesn't run public CI, here's how the change was validated and how to try it.

Automated tests (2 new files, ~264 lines):

bun test cli/src/state/__tests__/undo-store.test.ts cli/src/utils/__tests__/undo-snapshot.test.ts
# or the full CLI suite: cd cli && bun run test

Also validated locally with bun run typecheck (cli + sdk).

Manual walkthrough:

  1. Start the CLI on a scratch project (from cli/: bun run dev).
  2. Ask the agent to modify, create, and delete files in a single turn.
  3. Run /undo — a /history-style picker opens: arrow keys or mouse to select, type to search, Enter to undo, Esc to cancel. Each entry shows the user message and the files it touched.
  4. The selected turn and every newer one are reverted. The colored confirmation shows the git-style diff stat: files restored (↺) or removed (🗑).
  5. Run /redo — it offers the captured states; redo restores them. Jumping back past a redo entry invalidates the newer redo entries.
  6. Quit and reopen the CLI on the same project — /undo still lists the history (persisted per chat in undo.json, max 20 entries).

Notes:

  • Snapshots live in an isolated git repo (--git-dir / --work-tree); the user's real .git is never touched.
  • Snapshots reuse the source repo's object database via objects/info/alternates, so snapshots are fast.
  • Best-effort by design: if a snapshot fails for a turn, undo is disabled for that turn instead of breaking the chat.
  • Granularity is per turn (one agent message), matching the semantics requested in add /undo action #907.

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.

add /undo action

1 participant