Skip to content

Add copy, retry and branch actions to chat replies - #423

Open
slorksmo wants to merge 13 commits into
futrx-com:qafrom
slorksmo:feat/copy-code-block
Open

slorksmo wants to merge 13 commits into
futrx-com:qafrom
slorksmo:feat/copy-code-block

Conversation

@slorksmo

@slorksmo slorksmo commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Chat replies get copy, retry and branch actions:

  • Markdown code blocks have a copy button in the top-right corner. It copies the block's raw text and shows a check mark for a moment.
  • Each completed assistant reply has a row of actions under it:
    • Copy copies the reply's text parts as markdown (thinking and tool calls are left out).
    • Retry rewinds to the prompt that started the turn and sends it again.
    • Branch to a new chat opens a new chat with the history up to that reply.

Why

Copying commands from agent replies meant selecting text by hand, and there was no way to retry a reply or continue from an earlier point without losing the rest of the chat. Expanded from the code-block button after review.

Fixes #417

How

  • useCopyToClipboard (new, state/hooks/shared) holds the copy-and-confirm logic. CopyCodeButton and the reply actions both use it.
  • turnActions.ts decides, per assistant block, what the row offers: nothing while the reply streams or for blocks without text, one row per turn (on its last assistant block), the prompt that started the turn, and where a branch cuts the history (the next prompt's timestamp; none for the last turn).
  • Retry reuses runChatRewind. A new optional resend callback changes the dialog text and, after the rewind, queues the prompt instead of putting it back in the composer. The prompt queue already waits until the chat is ready, so a retry while the agent is running stops it, rewinds, then sends. The rewind flow itself is unchanged when resend is not passed.
  • Branch adds chat.Service.ForkBefore(ctx, id, beforeT); Fork now calls it with zero. A partial fork copies only the events before beforeT and starts without provider sessions, the same as after a rewind, because the native session also holds the turns that were left out. The prompt service already sends the visible transcript as context when there is no session. POST /api/chats/{id}/fork accepts an optional {"beforeT": ...}; an empty body still forks the whole chat, so the sidebar fork is unchanged. Branching from the last reply forks the whole chat and keeps native forks.
  • I saw Feat/sqlite conversations #413 adds checkpoint forks (ForkChat with a cut-off and Claude's --resume-session-at). Once that lands, ForkBefore can hand partial forks to it to keep the native session.

Testing

  • npm test: 657 passed. New turnActions.test.ts (7 tests) and 3 retry cases in chatRewindFlow.test.ts.

  • go test ./internal/service/chat/ ./internal/transport/http/handlers/ ./internal/stores/filechat/ on Linux. New fork_before_test.go covers the partial copy dropping sessions, beforeT=0 matching Fork, and a negative timestamp.

  • npm run build succeeds.

  • Ran it on my own instance: copied replies and code blocks, retried the last reply, and branched from a reply in the middle of a chat and continued there.

  • go test ./... passes (backend and catalog): CI

  • npm test passes (frontend)

  • gofmt / go vet clean for the changed packages

  • npm run build succeeds

UI changes

  • Tested in a real project workspace (not just npm run dev)

@Ahmedwaleed22

Copy link
Copy Markdown
Contributor

Hello @slorksmo,

Can we expand this to have all the needed buttons?

Like "Branch to a new chat" and Retry

@slorksmo slorksmo changed the title Add a copy button to chat code blocks Add copy, retry and branch actions to chat replies Nov 23, 2026
@slorksmo

Copy link
Copy Markdown
Contributor Author

Done. Each finished reply now has Copy, Retry and Branch to a new chat under it, and the code-block copy button is still there. Branch needed a small backend change: the fork endpoint takes an optional beforeT, and a partial fork starts a fresh agent session with the copied transcript as context. Details in the description.

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.

Add a copy button to code blocks in chat

2 participants