Skip to content

Edit any message you sent, and switch back to the version it replaced - #193

Open
reynaldichernando wants to merge 3 commits into
mainfrom
claude/serene-hamilton-uf7f7t
Open

reynaldichernando wants to merge 3 commits into
mainfrom
claude/serene-hamilton-uf7f7t

Conversation

@reynaldichernando

@reynaldichernando reynaldichernando commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

What

You can edit any message you sent, and the version it replaces is kept so you can go back.

  • Copy and Edit sit under every message you sent. They show on hover or keyboard focus, and always on touch screens.
  • Edit opens the message in place. Opening it stops a running build. Enter sends, Shift+Enter adds a line, Esc cancels.
  • Send puts the app's files back to how they were when the message was first sent, if anything after it changed them, then builds again from there. It works like a restore from the Versions panel, without the dialog or a note in the chat. Files attached to the message come back. Editing a project's first message starts from an empty project.
  • Nothing is lost. The conversation from that message on stays as another version of it, along with the files it had got to. Arrows under the message ("‹ 2 / 2 ›") switch between versions, and each switch puts that version's files back too. Versions are saved with the chat, so they survive a reload.
  • The edit box says what Send will do, for example "Your app goes back to how it was before this message. The current version stays, and you can switch back to it."
  • Older messages. A message sent before this change has no version on record. Editing it still keeps the old conversation as a version, but the files stay as they are. The box says so, and the AI gets a note that the files may include later changes. Messages sent from now on, in old projects too, can be fully reverted.

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

  1. Ask for a small page, for example "a page that says Hello in big blue letters".
  2. Hover your message and click Edit. Change blue to red and send. The page rebuilds from scratch in red, and the message shows "2 / 2".
  3. Click ‹ to get the blue page and its conversation back, and › to go forward again. Reload and check that both versions are still there.

How

  • The version each message was sent with. sendChatMessage asks projectVersionNow (versions.js) at turn start, before attachments are saved, and keeps the answer on the message as baseVersion. 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'.
  • Restoring. restoreProjectVersion is restoreVersion with no confirm, no note in the chat, and exact (it goes ahead when the target is current but the files changed since). It now resolves { ok, from }, where from is the version the files were at before (its restore point if they had changed). Restoring 'empty' removes everything but .puter. copyFilesFromVersion brings the message's own attachments back from from.
  • Branches. chat.branches is { [group]: { active, variants: [{ tail, head, interrupted } | null] } }. group is the first version's message id, each version of the message carries it as branchGroup, and the active version's entry is null because it is the live conversation. saveCurrentChat writes 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.
  • Ordering. An edit waits for a stopped build to finish unwinding (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.
  • No stale writes. An edit or a switch puts a new array in place of chatHistory. The old array is marked left, and saves, end-of-turn snapshots and checkpoints of it are skipped.
  • Redrawing. loadChat's drawing moved into renderChatHistory unchanged, and a switch reuses it.
  • While an edit is going in. Composer sends and automatic fixes wait, and so does a stopped build's Resume banner. If the edit's turn is called off, the Resume banner builds from the edited message.
  • Analytics. Build Started gets edited: true and reverted. Build Abandoned gets how: 'edited', as before.

Tests

  • scripts/test-message-edit.mjs is 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.
  • New scripts/test-message-versions.mjs runs versions.js for real against a mock file system. It covers projectVersionNow, quiet and exact restores, restoring to empty, and copying a message's files back.
  • npm test passes (155 scripts) and vite build succeeds.
  • I tried it on the preview in Chrome with steps 1 to 3 above, including the reload. Not tried live: attachments coming back, editing a message from before this change, and phone layout.

🤖 Generated with Claude Code

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread src/js/app.js Resolved
Comment thread src/js/app.js Resolved
Comment thread src/js/message-edit.js Resolved
Comment thread src/js/ui.js Resolved
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>
@reynaldichernando reynaldichernando changed the title Edit your latest message before Puter changes anything Edit any message you sent, and switch back to the version it replaced Nov 23, 2026
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.

3 participants