Skip to content

feat: add workspace rewind checkpoints - #2785

Closed
Coiggahou2002 wants to merge 1 commit into
MoonshotAI:mainfrom
Coiggahou2002:feat/rewind-files
Closed

feat: add workspace rewind checkpoints#2785
Coiggahou2002 wants to merge 1 commit into
MoonshotAI:mainfrom
Coiggahou2002:feat/rewind-files

Conversation

@Coiggahou2002

Copy link
Copy Markdown

Related Issue

Resolve #108

Problem

/undo restores conversation context, but files written by tool calls remain changed. Users therefore cannot safely rewind a turn as a unit, especially when the workspace is not a Git repository or already contains unrelated uncommitted work.

What changed

  • Add /rewind [count], which previews and restores both conversation history and workspace files to their state before the selected prompt.
  • Capture bounded, content-addressed checkpoints for the primary working directory and additional directories without depending on Git.
  • Detect file conflicts after preview and abort before changing context; make filesystem restoration transactional and roll back a partial restore on failure.
  • Keep /undo context-only while discarding the corresponding filesystem checkpoints so the two histories cannot become misaligned.
  • Exclude ignored paths, symlinks, VCS metadata, dependencies, and checkpoint contents from session/debug exports.
  • Document the command in English and Chinese and add a minor changeset.

The checkpoint store retains at most 20 turns and enforces limits of 50,000 files, 512 MiB per checkpoint, and 64 MiB per file. A failed checkpoint capture does not block the prompt, but it invalidates rewind alignment so stale state cannot be applied.

Verification

  • Workspace checkpoint unit tests: 11 passed.
  • Command registry/resolution tests: 32 passed.
  • Targeted TUI rewind integration test passed; existing undo tests: 10 passed.
  • Agent Core v1 export tests: 9 passed.
  • Agent Core v2 export tests: 23 passed.
  • Full monorepo typecheck passed.
  • CLI and documentation builds passed.
  • pnpm sherif passed.
  • Lint completed with no errors (repository baseline warnings remain).

The full TUI message-flow suite otherwise reported six existing feedback attachment/media failures; the same failure was reproduced from an independent clean worktree without this change.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 90f2c2d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 90f2c2d890

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +34 to +36
const availability = await resolveUndoAvailability(host);
const checkpointCount = await store.availableCount();
const maxCount = Math.min(availability.maxCount, checkpointCount);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep rewind checkpoints aligned with mid-turn steers

This assumes the newest workspace checkpoints line up one-for-one with the newest undo anchors, but the streaming steerMessage() path still appends user transcript entries and calls session.steer directly without capturing a checkpoint. In a session with prompt A checkpointed and then a mid-turn steer B, /rewind 1 can offer B while prepareRewind(1) applies A's before-image and undoHistory(1) only removes B, restoring files too far back. Capture or invalidate checkpoints for the streaming steer path before using checkpointCount as an alignment guarantee.

Useful? React with 👍 / 👎.

@liruifengv

Copy link
Copy Markdown
Collaborator

Thank you for your interest in contributing to Kimi Code.

For new features, please discuss first. We are not currently accepting pull requests for new features.

@liruifengv liruifengv closed this Aug 11, 2026
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.

/rewind 功能相关

2 participants