Repository navigation
Edit any message you sent, and switch back to the version it replaced - #193
Open
reynaldichernando wants to merge 3 commits into
Open
reynaldichernando wants to merge 3 commits into
reynaldichernando wants to merge 3 commits into
Conversation
A pencil under the user's latest message opens it for editing in place, for as long as nothing done for that message has changed anything: the AI has only read files, searched, planned or asked a question. The first call that could change something (a write, a worker, a secret, a generated image, a Publish card), a restore or a pull from GitHub takes the pencil away, so an edit never has anything to undo. Opening the editor stops a running build. Send swaps in the new text (files, pasted text and the picked element stay), drops what came after the message and builds again from there. Cancel puts the message back, with the Resume banner if there was one. An edit that can no longer go in moves to the composer instead of being lost. Behind FEATURE_FLAGS.messageEdit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FWCxovs6MrUK18w79a45qj
There was a problem hiding this comment.
🟡 Changes recommended
Several active issues can silently drop in-flight auto-fix or message edits and fail to restore the existing Resume banner text, so the change still risks incorrect user-visible behavior.
4 open issues
What changed in this PR
Adds feature-flagged inline editing for the latest user message, allowing users to revise and rebuild from that point while preserving conversation state and attachments.
Changes:
- Adds the message-edit module with editability checks, inline controls, history rewind, banner coordination, and fallback handling.
- Integrates editing with turn lifecycle, tool execution, publishing, restores, chat loading, analytics, drafts, and persistence.
- Adds styling, mini-DOM support, comprehensive message-edit tests, and updates existing assertions.
| File | Description |
|---|---|
| vite.config.js | Loads the message-edit module in the required script order. |
| src/js/versions.js | Refreshes or removes message editability after version restores and external updates. |
| src/js/ui.js | Integrates publishing behavior with message editability refreshes. |
| src/js/tools.js | Refreshes the edit affordance before potentially mutating tool calls run. |
| src/js/message-edit.js | Implements editability rules, the inline editor, history rewind, and fallback behavior. |
| src/js/helpers.js | Adds the messageEdit feature flag. |
| src/js/app.js | Integrates edited sends with turn lifecycle, history, analytics, banners, persistence, and chat loading. |
| src/css/styles.css | Styles the edit button, inline editor, controls, mobile layout, and dark theme. |
| scripts/test-paste-as-attachment.mjs | Updates assertions for edited-message paste handling. |
| scripts/test-message-queue.mjs | Updates queue assertions to account for edited sends. |
| scripts/test-message-edit.mjs | Adds functional, interaction, wiring, and tool-list coverage for message editing. |
| scripts/test-composer-drafts.mjs | Updates draft and attachment assertions for edited sends. |
| scripts/lib/mini-dom.mjs | Adds prepend support required by the message editor test harness. |
| package.json | Includes the message-edit test in the npm test suite. |
Review effort: Lite
Copy and Edit sit under every message the user sent. They show on hover or keyboard focus, and always on touch screens. Edit opens the message in place, as before, and stops a running build. Each message now keeps the version of the project's files it was sent with. When anything after the message changed the files, Send puts them back to that version first, with no dialog and no note in the chat, and brings back the files the message itself was sent with. Editing a project's first message starts from an empty project. A message sent before this has no version on record, so its files stay as they are, the box says so, and the AI gets a note saying so. Nothing is lost. The conversation from the message on stays as another version of it, with the files it had got to, and arrows under the message switch between versions, files included. The versions not showing are saved with the chat (chat.branches), so they survive a reload. A copied project starts without them. An edit or a switch puts a new conversation array in place of the old one, and saves of the old one are skipped, so a stopped build still unwinding can't write it back. An edit waits for that build's last step before it restores files. versions.js gains projectVersionNow, restoreProjectVersion (quiet, returns the version the files were at), restoring to an empty project, and copyFilesFromVersion. loadChat's drawing moved into renderChatHistory, which a switch reuses. Tests: test-message-edit rewritten for the new flow, and test-message-versions runs the versions.js side for real. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.


What
You can edit any message you sent, and the version it replaces is kept so you can go back.
It sits behind
FEATURE_FLAGS.messageEdit.Try it
Preview: https://builder-claude-serene-hamilton-uf7f7t-3yb5.puter.site
Puter app: https://puter.com/app/builder-claude-serene-hamilton-uf7f7t-3yb5
How
sendChatMessageasksprojectVersionNow(versions.js) at turn start, before attachments are saved, and keeps the answer on the message asbaseVersion. It answers once the snapshots queued so far have landed, using the chat's mutation count, so a slow end-of-turn snapshot from the previous message is still counted. A project with no files is'empty'.restoreProjectVersionisrestoreVersionwith no confirm, no note in the chat, andexact(it goes ahead when the target is current but the files changed since). It now resolves{ ok, from }, wherefromis the version the files were at before (its restore point if they had changed). Restoring'empty'removes everything but.puter.copyFilesFromVersionbrings the message's own attachments back fromfrom.chat.branchesis{ [group]: { active, variants: [{ tail, head, interrupted } | null] } }.groupis the first version's message id, each version of the message carries it asbranchGroup, and the active version's entry is null because it is the live conversation.saveCurrentChatwrites them for the open chat and keeps what the file has for any other. Neither field reaches the AI, and a duplicated project drops both.whenTurnsUnwound), then swaps in the new conversation, saves it as interrupted, restores the files, and starts the turn. A switch also swaps the conversation before restoring. If the restore fails, the conversation goes back to the version the files still match.chatHistory. The old array is marked left, and saves, end-of-turn snapshots and checkpoints of it are skipped.renderChatHistoryunchanged, and a switch reuses it.Build Startedgetsedited: trueandreverted.Build Abandonedgetshow: 'edited', as before.Tests
scripts/test-message-edit.mjsis rewritten. It runs the real module on the mini DOM and covers the buttons, Copy, open and cancel, Send with and without a revert, older messages, a failed restore, called-off sends, switching versions and a failed switch. It also checks the wiring in app.js, versions.js and helpers.js.scripts/test-message-versions.mjsruns versions.js for real against a mock file system. It coversprojectVersionNow, quiet and exact restores, restoring to empty, and copying a message's files back.npm testpasses (155 scripts) andvite buildsucceeds.🤖 Generated with Claude Code