Skip to content

feat(web): add history fork for conversations#281

Open
zhengdaqi wants to merge 1 commit into
mainfrom
feat/history-fork-0625
Open

feat(web): add history fork for conversations#281
zhengdaqi wants to merge 1 commit into
mainfrom
feat/history-fork-0625

Conversation

@zhengdaqi

@zhengdaqi zhengdaqi commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • 为对话新增 History Fork(历史分叉):可从任意一条历史用户消息分叉出新会话,新会话携带分叉点之前的完整历史,并把被分叉的那条消息预填进输入框供编辑后重新发送。
  • 网关层新增 fork_session RPC(protocol 类型 / InProcess + Remote 客户端 / ws dispatch / 本地网关实现)。
  • 服务端 forkSession 在分叉 turn 处截断源 transcript,写入带分叉谱系 metadata 的新会话 jsonl,复制 tool-results/file-history 辅助目录,并返回预填文本与携带消息数。
  • 会话持久化 parentSessionId/forkedFromTurnId,侧栏据此渲染分叉谱系树。
  • 前端:用户消息 hover 出现 Fork 按钮;分叉后自动进入新会话、预填并聚焦输入框、滚动到底;分叉标题以 ⑂ <分叉点消息> 命名增强区分度;对无携带历史的分支提供友好空态。

Changes

  • gateway: protocol/types.ts, protocol/frames.ts, client/InProcessGateway.ts, client/RemoteGateway.ts, server/GatewayWsConnection.ts, cli/createLocalGateway.ts, cli/pilotdeck.ts
  • server: web/server/forkSession.ts(新增), web/server/readSessionMessages.ts, web/client/protocol.ts, web/client/webMessage.ts
  • session lineage: session/transcript/TranscriptEntry.ts, session/storage/SessionList.ts
  • ui-server: ui/server/routes/messages.jsPOST /api/sessions/:id/fork), ui/server/projects.js
  • ui: ChatInterfaceV2.tsx, MessageRowV2.tsx, MessagesPaneV2.tsx, SidebarV2.tsx, useChatMessages.ts, types.ts, useSessionStore.ts, api.js
  • tests: tests/web/forkSession.test.ts, ui/e2e/history-fork.spec.mjs

Test plan

  • 单元测试 tests/web/forkSession.test.ts 通过
  • API 端到端:从多轮会话第二个 turn 分叉,返回 newSessionIdprefillTextcarriedMessageCount;新 transcript 携带完整历史、谱系 metadata 正确、标题为 ⑂ <消息>
  • 浏览器实测(vite):点击 Fork → 自动进入新会话、输入框预填并聚焦、携带历史渲染并滚动到底、侧栏出现带 的分叉条目、无 "Fork did not return a new session id" 报错
  • reviewer 复核

Made with Cursor

Let users branch a conversation from any prior user message into a new
session that carries the history up to the fork point and pre-fills the
forked prompt into the composer for editing and re-sending.

- gateway: new fork_session RPC wired through protocol types, in-process
  and remote gateway clients, ws dispatch, and local gateway impl
- server: forkSession truncates the source transcript at the fork turn,
  writes a new session jsonl with fork lineage metadata, copies aux dirs,
  and returns the prefill text + carried message count
- session: persist parentSessionId/forkedFromTurnId so the sidebar can
  render the fork lineage tree
- ui: hover Fork button on user messages, auto-navigate to the new
  session, prefill + focus the composer, scroll to bottom, distinctive
  fork titles, and a friendly empty state for branches with no carried
  history
- tests: forkSession unit test + history-fork e2e spec

Co-authored-by: Cursor <cursoragent@cursor.com>
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