fix(agent): 修复切换仓库时 Agent 实例不跟随切换的问题#425
Merged
Merged
Conversation
根因: activeIds 使用 cwd 作为唯一 key,不同仓库切换时 key 被覆盖, 导致切回旧仓库时 MainContent 的 activeSessionId 计算找到错误的 session。 修复: - 使用复合 key repoPath::cwd 实现跨仓库隔离 - setActiveId 签名改为 (repoPath, cwd, sessionId) - useActiveSessionId 提供可选 repoPath 参数保持向后兼容 - 更新 AgentPanel/MainContent/useFocusSession/RunningProjectsPopover 调用点
Contributor
|
I'll analyze this and get back to you. |
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.

问题
切换不同仓库时,Agent 实例不会跟随切换。例如当前在 A 项目的 dev 分支打开了一个 agent,切换到 B 项目的 dev 分支打开了一个 agent,再次切换回 A 项目的 dev 分支时,agent 实例显示的还是 B 项目的。
根因
activeIds使用cwd作为唯一 key,不同仓库切换时 key 被覆盖,导致切回旧仓库时MainContent.tsx的activeSessionId计算找到的是错误 repo 的 session。修复
${repoPath}::${cwd}实现跨仓库隔离setActiveId签名改为(repoPath, cwd, sessionId)useActiveSessionId提供可选repoPath参数保持向后兼容AgentPanel/MainContent/useFocusSession/RunningProjectsPopover调用点涉及文件
src/renderer/stores/agentSessions.ts- 核心状态管理src/renderer/components/chat/AgentPanel.tsx- Agent 面板src/renderer/components/layout/MainContent.tsx- 主内容区src/renderer/App/hooks/useFocusSession.ts- Focus Session 钩子src/renderer/components/layout/RunningProjectsPopover.tsx- 运行项目弹窗