Repository navigation
fix(cli): rewind resets to before the turn and refills its prompt - #700
Merged
Merged
Conversation
Interrupting the latest turn left its aborted turn_state as the last message, and listRewindTargets excluded the "head" turn — so the turn the user just interrupted, the one they wanted to redo, was dropped from the rewind list. They could only rewind to the turn before it. Switch rewind to the semantics the gesture implies: rewinding to a turn now resets to the state just *before* it (discarding it and everything after) and refills the editor with its prompt for an edit-and-resend, matching how rewind works elsewhere. With that, every prompted turn — including the latest/interrupted one — is a valid target, and the head-exclusion (and the bug) goes away. - runtime: add branchBeforeTurn, the exclusive dual of branchFromTurn (kept unchanged; desktop still uses it). Both share createBranchSession. copyMessagesBeforeTurn slices by turn membership, not array position, because the read model does not guarantee a turn's messages are contiguous or that a user prompt precedes its turn_state. An empty copy (first turn) is a valid branch into empty context. - cli: listRewindTargets lists all prompted turns newest-first; rewindToTurn branches before the turn and returns its full prompt; the runner refills the editor via editor.setText and updates the notice/picker copy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rewind (double-Esc /
/rewind) now resets the conversation to just before the chosen turn and refills the editor with that turn's prompt for an edit-and-resend, instead of branching through the turn. Every prompted turn — including the latest one — is a valid target.Why
Refs: interrupting the latest turn left its aborted
turn_stateas the last message, andlistRewindTargetsexcluded the "head" turn. So the very turn the user had just interrupted (the one they wanted to redo) was dropped from the rewind list — they could only rewind to the turn before it.Rather than patch the head-exclusion, switch rewind to the semantics the gesture already implies (matching rewind elsewhere): reset to before the turn + refill its prompt. With that, the head concept — and the bug — disappears.
Scope
Changed:
packages/runtime/src/session-manager.ts— addbranchBeforeTurn, the exclusive dual ofbranchFromTurn(unchanged; desktop still uses it). Both share a new privatecreateBranchSession.copyMessagesBeforeTurnslices by turn membership, not array position.packages/cli/src/session-driver.ts—listRewindTargetslists every prompted turn newest-first;rewindToTurnbranches before the turn and returns its full prompt (MakaSessionRewindResult).packages/cli/src/pi-tui-runner.ts— refill the editor viaeditor.setText, update notice/picker copy.Not included:
branchBeforeTurn(CLI-only bug; the runtime primitive is there if desktop wants it later).branchFromTurnsemantics untouched.Verification
npm run -w @maka/runtime test→ 1126 pass, 0 fail (2 skipped)npm run -w maka-agent test→ 187 pass, 0 failnpm run typecheck→ clean across all workspacesUser-facing impact
Behavior change (intended): rewinding to a turn now discards that turn and refills its prompt, so a single-turn session becomes rewindable (empty branch + refilled prompt), and the picker/notice copy changed to say so. Non-destructive as before — the original session, including the discarded turn, is preserved.
Reviewer notes
The one subtle bit is
copyMessagesBeforeTurn:getSessionViewdoes not return messages in strict chronological order (a user prompt can sort after its turn'sturn_state), so a positional "slice before first occurrence" would drop an earlier turn's prompt. It slices by turn membership instead. There's a runtime test that locks this exact case.