Skip to content

feat(cli): /rewind N undoes multiple turns with safer truncation#213

Merged
emal-avala merged 1 commit intomainfrom
feat/rewind-count-arg
Apr 23, 2026
Merged

feat(cli): /rewind N undoes multiple turns with safer truncation#213
emal-avala merged 1 commit intomainfrom
feat/rewind-count-arg

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

  • /rewind (alias /undo) now accepts an optional turn count. /rewind still undoes one turn; /rewind 3 undoes up to three.
  • Replaces the ad-hoc pop loop with a per-turn truncation algorithm that defines a turn as the most recent real user prompt + everything after it.
  • Tool results (is_meta) and compact summaries are no longer treated as prompt boundaries, so a session whose tail is a tool result can't be mis-truncated and a compacted session can't be rewound past its summary.
  • Multi-turn rewinds stop early with a readable message when no earlier prompt exists.

Test plan

  • cargo clippy -p agent-code --tests --no-deps -- -D warnings — clean
  • cargo test -p agent-code --bin agent commands::tests:: — 80 pass (72 prior + 8 new)
  • 8 new unit tests cover:
    • default / whitespace / numeric arg parsing
    • zero and garbage rejected with a usage hint
    • single-turn rewind removes prompt + all replies
    • multi-turn session peels only the last turn
    • compact-summary boundary is not a valid rewind target
    • tool-result tail with no prompt behind it returns 0 (no truncation)
    • empty history returns 0

Extends /rewind (and its /undo alias) to accept an optional turn count, so
/rewind 3 undoes three turns in one go. The existing version only ever
unwound the last assistant reply and did so with an ad-hoc loop that
would happily chew through the entire history if the tail wasn't a
plain assistant message.

The new implementation defines a turn as "the most recent real user
prompt plus everything that came after it" and truncates in one pass
per turn. Tool results (is_meta) and compact summaries are explicitly
excluded from being treated as prompt boundaries, so:

- a session whose tail is a tool result never gets mis-truncated
- a compacted session can't be rewound past its summary
- multi-turn rewinds stop early with a readable message when there's
  no earlier prompt left

8 new unit tests cover argument parsing (default, numeric, zero/garbage)
and the per-turn truncation algorithm (happy path, multi-turn peel,
tool-result tail, compact-summary boundary, empty history).
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@emal-avala emal-avala merged commit 39182fc into main Apr 23, 2026
14 checks passed
@emal-avala emal-avala deleted the feat/rewind-count-arg branch April 23, 2026 18:29
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