feat: Fork 会话分支功能 — 真正独立的图片分支#3
Merged
Merged
Conversation
新增 Fork 功能设计 spec,将当前"同一 session 内 fork_from 标记" 改造为"真正创建新 session + 物理拷贝图片"的独立分支机制。 核心决策:点击即 Fork、数据库级拷贝保留完整历史、 物理拷贝文件保证独立性、保留 response_id 链。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
8 个 Task:后端 Storage/SessionManager/Fork API/清理旧逻辑, 前端 api.ts/types/generationStore/DetailPanel+InputArea/i18n。 TDD 流程,逐步提交。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
在 ImageStore 中添加 copy_session_images 方法,支持将指定图片文件 从源 session 目录物理拷贝到目标 session 目录,用于 Fork 分支功能。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- SessionManager.fork: 数据库级拷贝目标图片及之前所有记录 - 物理拷贝图片文件到新 session 目录 - 命名规则: 原名 (Fork #N),编号自动递增 - 保留 response_id 链和 step 顺序 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
接受 image_id 参数,调用 SessionManager.fork 创建独立分支 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Fork 功能已由独立的 POST /fork 端点替代,生成流程不再需要 fork_from 参数 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Fork 不再通过生成流程触发,改为独立的 API 调用 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- DetailPanel: 点击 Fork 立即创建新 session 并自动切换 - InputArea: 移除旧的 fork 提示条 UI - 新增 toast.sessionForked 翻译 - Fork 按钮增加 loading 防重复点击 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 提取 _extract_filename 辅助函数消除重复的 file_path 解析 - fork() 中 fork_count 查询改用 COUNT(*) 替代 fetchall - 合并两次 db commit 为一次(session 创建 + 图片拷贝) - copy_session_images 改用 try/except 消除 TOCTOU - DetailPanel 提取 doFork 消除 handleFork/handleForkLast 重复 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
避免 fork 后数据库记录指向不存在的文件导致数据不一致。 如果源文件缺失,整个 fork 操作将失败并回滚。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Owner
Author
|
/review -i |
Incremental PR Reviewer Guide 🔍⏮️ Review for commits since previous PR-Agent review Starting from commit a650362. Here are some key observations to aid the review process:
|
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.
Summary
将 Fork 机制从"同一 session 内标记重新生成"改造为"创建新 session + 物理拷贝图片"的独立分支,类似 git branch 的语义。
POST /api/sessions/{id}/fork端点,一次调用完成:创建新 session、数据库级拷贝图片记录、物理拷贝图片文件原名 (Fork #N)fork_from/pendingForkFrom逻辑Changes
后端
storage.py: 新增copy_session_images方法(物理文件拷贝)session.py: 新增fork方法(数据库拷贝 + 命名 + 文件编排),含_extract_filename辅助sessions.py: 新增 Fork API 路由generate.py: 移除fork_from字段和_resolve_previous的 fork 分支前端
api.ts: 新增forkSession函数generationStore.ts: 移除pendingForkFrom状态DetailPanel.tsx: Fork 按钮→直接 API 调用 + 自动切换 + ToastInputArea.tsx: 移除 fork 提示条 UItypes/index.ts: 移除fork_fromtoast.sessionForked翻译Test plan
🤖 Generated with Claude Code