Add Edit and Retry to `clai2` web UI prompts, rewinding like the TUI's rewind
Merged
MP
1mo ago+642+642+012345678901234567890123456789-130-130-012345678901234567890123456789
Fixes #12199
Each prompt in a live web session now shows Edit and Retry on hover or keyboard focus, the browser's counterpart of the terminal's Esc Esc rewind.
- Edit turns the bubble into an editor prefilled with the prompt's text, with its images shown. Send (or Enter) rewinds the conversation to just before that prompt and sends the edited text with the same images. Esc or Cancel leaves everything unchanged.
- Retry does the same with the text unchanged.
- Both buttons are disabled while a turn runs. The server also refuses with 409 while the session is
busy: a turn, a command such as/compact, the terminal's own rewind picker, or queued input. - Later turns are dropped from the live history, as the TUI rewind drops them. The editor and the button tooltips say so: "Later messages are removed; files are not restored."
How it works
build_rewind_menu's point selection moves into the UI-freeruntime/rewind.pyasrewind_points(messages)(eachRewindPointgets areason). The TUI picker and the web route share it, so both use the same rules: run boundaries only, no steering, no prompts that predate compaction, and no unsupported attachments.- New public surface: the read-only
LiveSession.busyproperty (documented in PLUGINS.md), backed bySessionRuntime.handling. The terminal's Esc Esc picker now counts as handling input, so a web rewind can't race it. - Transcript
Itemgetsrun_id: the run a user prompt started.history_itemssets it only on eligible rewind points. A live prompt gets it fromctx.run_idinObserver.wrap_run. Keying by run ID instead of a list position is stable across truncation and compaction. It also never matches a steering message or a tool's enqueued note, both of which appear in the saved history but not in the live view. - New route
POST /api/[sessions/{id}/]rewind/{run_id}with{text}callsSessionChannel.rewind. That method validates the new text before touching history (no/command, bareclear, or!line, and blank only when images go with it). It then callsconversation.commit_messages(messages[:index]), the same durable replacement the TUI uses, pushes a fresh snapshot so every watching browser starts over from the rewound history, and sends the prompt throughsend_input. Ifsend_inputrefuses the prompt (for example, the image budget is full), the original history is restored.
Choices and alternatives
- Drop vs. fork. The issue allows either "dropped, or kept recoverable via an automatic fork". I chose drop to match the existing TUI rewind contract and keep the change narrow. Users who want the old branch can still
/forkor fork the session from the sidebar before editing. An automatic fork could be added later as an option. - Images on Edit are kept as they were. The editor changes only the text. Removing or adding images while editing was left out to keep the UI small.
- Prompts with no run ID, such as those in histories imported from Claude Code or Codex, show no Edit or Retry. The TUI rewind still covers them.
Tests
tests/clai2/test_web_rewind.py(server, in-process). Send A with an image, then B. Edit A to A′: the transcript is A′ with its answer and the image, and B is gone. Retry works too, and refusals (command,!line, unknown run, running turn) keep the history. Steering and enqueued notes carry norun_id. This test fails onmain(AttributeError: 'Item' object has no attribute 'run_id', and the route does not exist).tests/clai2/browser/test_web_rewind_browser.py(Playwright, the issue's browser repro). Hover A, click Edit, change it to A′, press Enter: the transcript shows only A′ and "Echo A′". Then Retry.- The existing
test_rewind.py,test_web*.py, and the fulltests/clai2/browsersuite (35) pass locally.tsc --noEmit, ruff, and pyright on the changed files are clean. The rebuilt bundle is not committed, perweb-ui/README.md.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.