Skip to content

feat(cli): add session rewind and restore flows#96

Open
BingqingLyu wants to merge 7 commits into
mainfrom
fork-pr-3292-session-history-fork
Open

feat(cli): add session rewind and restore flows#96
BingqingLyu wants to merge 7 commits into
mainfrom
fork-pr-3292-session-history-fork

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 27, 2026

Copy link
Copy Markdown
Owner

TLDR

Add session rewind and restore flows in the CLI.

This change lets users:

  • browse history from the current active session
  • pick a previous prompt from the active branch
  • restore conversation state from that point
  • restore code state when a checkpoint is available
  • summarize from a selected point before continuing

Screenshots / Video Demo

> how are you doing?

  ✦ The user is asking "how are you doing?". This is a general greeting/conversational question.
    According to the "Operational Guidelines" -> "Tone and Style (CLI Interaction)":
     - "Concise & Direct"
     - "Minimal Output"
     - "No Chitchat": Avoid conversational filler, preambles, or postambles.

    However, responding to a simple "how are you doing?" with a very brief, professional answer is appropriate. I should
    not enter into a long conversation but rather maintain the persona of a professional CLI agent.

  ✦ I'm doing well, thank you! How can I help you with your project today?

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
>   Type your message or @path/to/file
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ? for shortcuts


 > create a python file named manual_rewind_test.py, write a small example, and save it in this directory

  ✦ The user wants to create a Python file named manual_rewind_test.py in the current working directory
    (/home/xxx/github/qwen-code) with a small example.

     1. Plan:
         * Create a small Python example.
         * Write it to /home/xxx/github/qwen-code/manual_rewind_test.py using write_file.

     2. Execution:
         * I'll write a simple "Hello World" style script or a basic function to serve as the example.

     3. Path:
         * Root: /home/xxx/github/qwen-code
         * File: manual_rewind_test.py
         * Absolute path: /home/xxx/github/qwen-code/manual_rewind_test.py

  ✦ I'll create a simple Python file named manual_rewind_test.py with a basic example.

    <details>
    <summary>Command explanation</summary>
    I am using write_file to create a new file at /home/xxx/github/qwen-code/manual_rewind_test.py with a small Python
    example that demonstrates a basic function and a loop.
    </details>


  ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
  │ ✓  WriteFile Writing to manual_rewind_test.py                                                                       │
  │                                                                                                                     │
  │    1 def greet(name):                                                                                               │
  │    2     return f"Hello, {name}! Welcome to the manual rewind test."                                                │
  │    3                                                                                                                │
  │    4 if __name__ == "__main__":                                                                                     │
  │    5     names = ["Alice", "Bob", "Charlie"]                                                                        │
  │    6     for name in names:                                                                                         │
  │    7         print(greet(name))                                                                                     │
  │    8     print("\nTest completed successfully.")                                                                    │
  ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

  ✦ The file manual_rewind_test.py has been created successfully in /home/xxx/github/qwen-code/.



$ cat -n manual_rewind_test.py
     1	def greet(name):
     2	    return f"Hello, {name}! Welcome to the manual rewind test."
     3
     4	if __name__ == "__main__":
     5	    names = ["Alice", "Bob", "Charlie"]
     6	    for name in names:
     7	        print(greet(name))
     8	    print("\nTest completed successfully.")

esc,esc: select create python ....
  ✦ The file manual_rewind_test.py has been created successfully in /home/xxx/github/qwen-code/.
  ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
  │ Rewind                                                                                                              │
  │ Restore the code and/or conversation to the point before…                                                           │
  │─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
  │   how are you doing?                                                                                                │
  │   3 minutes ago                                                                                                     │
  │   No code changes                                                                                                   │
  │                                                                                                                     │
  │ › create a python file named manual_rewind_test.py, write a small example, and save it in this directory            │
  │   2 minutes ago                                                                                                     │
  │   manual_rewind_test.py +8 -0                                                                                       │
  │                                                                                                                     │
  │   (current)                                                                                                         │
  │   Current conversation                                                                                              │
  │   No code changes


╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
  │                                                                                                  │
  │ Rewind                                                                                           │
  │                                                                                                  │
  │ Confirm you want to restore to the point before you sent this message:                           │
  │                                                                                                  │
  │  │ create a python file named manual_rewind_test.py, write a small example, and save it in this  │
  │  directory                                                                                       │
  │  │ (3 minutes ago)                                                                               │
  │                                                                                                  │
  │ The conversation will be unchanged.                                                              │
  │ The code will be restored across 2 files (+8 -0).                                                │
  │                                                                                                  │
  │   1. Restore code and conversation                                                               │
  │      Fork the conversation and restore the code snapshot                                         │
  │   2. Restore conversation                                                                        │
  │      Fork from this prompt and keep the current code                                             │
  │ › 3. Restore code                                                                                │
  │      Keep the conversation and restore only the code snapshot                                    │
  │   4. Summarize from here                                                                         │
  │      Summarize messages after this point before continuing                                       │
  │   5. Never mind                                                                                  │
  │      Keep the current conversation and code unchanged                                            │
  │                                                                                                  │
  │ Rewinding does not affect files edited manually or via bash.

  ● The code will be restored across 2 files (+8 -0).

$ cat -n manual_rewind_test.py
cat: manual_rewind_test.py: No such file or directory


restore conversation:
  │ Rewind                                                                                           │
  │                                                                                                  │
  │ Confirm you want to restore to the point before you sent this message:                           │
  │                                                                                                  │
  │  │ create a python file named manual_rewind_test.py, write a small example, and save it in this  │
  │  directory                                                                                       │
  │  │ (3 minutes ago)                                                                               │
  │                                                                                                  │
  │ The conversation will be forked.                                                                 │
  │ The code will be unchanged.                                                                      │
  │                                                                                                  │
  │   1. Restore code and conversation                                                               │
  │      Fork the conversation and restore the code snapshot                                         │
  │ › 2. Restore conversation                                                                        │
  │      Fork from this prompt and keep the current code                                             │
  │   3. Restore code                                                                                │
  │      Keep the conversation and restore only the code snapshot                                    │
  │   4. Summarize from here                                                                         │
  │      Summarize messages after this point before continuing                                       │
  │   5. Never mind                                                                                  │
  │      Keep the current conversation and code unchanged                                            │
  │                                                                                                  │
  │ Rewinding does not affect files edited manually or via bash.


  ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
  │ Rewind                                                                                                              │
  │ Restore the code and/or conversation to the point before…                                                           │
  │─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
  │   how are you doing?                                                                                                │
  │   4 minutes ago                                                                                                     │
  │   No code changes                                                                                                   │
  │                                                                                                                     │
  │ › (current)                                                                                                         │
  │   Current conversation                                                                                              │
  │   No code changes                                                                                                   │
  │                                                                                                                     │
  │

Dive Deeper

Reviewer Test Plan

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman -
Seatbelt -

Linked issues / bugs

Closes QwenLM#3186

  Add session rewind and restore flows in the CLI.

  Users can browse history from the active session, restore conversation
  state from a selected prompt, restore code when checkpoints are
  available, and summarize from a selected point before continuing.

  This also updates session history, checkpoint handling, and summarize
  feedback so rewind stays aligned with the active branch and latest
  persisted state after restores.
  Wait for the highlighted history entry to render before submitting Enter in
  the selection test. This avoids selecting the previous item when UI updates lag
  on slower runners.
…pshot.

  Avoid deleting untracked manual files when restoring a snapshot, and summarize only messages after the selected rewind point to prevent
  duplicate prompt context.
  Address rewind review feedback by making checkpoint creation run before edit tools execute, including fast approval paths.

  Improve restore reliability, error handling, branch validation, cleanup behavior, and picker stability. Add focused coverage for checkpoint
  ordering, rewind entries, restore actions, and picker interactions.
  Make snapshot restore handling explicit for tracked and untracked files.

  Use a preserve policy for /restore and a delete-listed policy for /rewind so callers state their intended behavior clearly. Update rewind
  confirmation copy to describe when later edits can be overwritten or removed. Wire rewind dialogs into the global close path so Ctrl+C
  closes them consistently.
  Fix invalid stream test events and use a complete scheduled tool call fixture.

  Prevent swarm workers from recursively invoking orchestration tools by default. Clean up unused webview provider state and use bracket
  notation for index-signature access.
@BingqingLyu

BingqingLyu commented May 7, 2026

Copy link
Copy Markdown
Owner Author

Conflict Group 1

This PR shares modified functions with 21 other PR(s): #100, #106, #107, #109, #112, #113, #114, #117, #24, #28, #52, #55, #57, #6, #68, #83, #86, #87, #88, #9, #91.

These PRs should be reviewed as a batch — merging one may affect the others.

Function File Also modified by
createInvocation coreToolScheduler.test.ts #86
createTestCommand slashCommandProcessor.test.ts #107
dispose WebViewProvider.ts #114
executeSingleToolCall coreToolScheduler.ts #91
isInsightCommand WebViewProvider.ts #114, #57
isToolExecuting AppContainer.tsx #100, #107, #109, #113, #114, #117, #52, #88
loadCommands BuiltinCommandLoader.ts #107, #86, #87, #9
partitionToolCalls coreToolScheduler.ts #68
restoreAction restoreCommand.ts #83
serializeHistoryItemForRecording slashCommandProcessor.ts #107, #28
showCitations useGeminiStream.ts #106, #55, #6, #9
toParts coreToolScheduler.ts #24
useDreamRunning Footer.tsx #112, #113, #114, #117, #86, #88

Posted by codegraph-ai conflict detection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicting-group-1 Conflicting PR group 1 — review as a batch conflicting-pr Shares at least one cross-PR dependency with other PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

功能建议:会话历史回退功能

2 participants