Skip to content

fix(agent): 修复切换仓库时 Agent 实例不跟随切换的问题#425

Merged
J3n5en merged 1 commit into
J3n5en:mainfrom
lwt-sadais:fix/agent-session-repo-switch
Apr 17, 2026
Merged

fix(agent): 修复切换仓库时 Agent 实例不跟随切换的问题#425
J3n5en merged 1 commit into
J3n5en:mainfrom
lwt-sadais:fix/agent-session-repo-switch

Conversation

@lwt-sadais

Copy link
Copy Markdown
Contributor

问题

切换不同仓库时,Agent 实例不会跟随切换。例如当前在 A 项目的 dev 分支打开了一个 agent,切换到 B 项目的 dev 分支打开了一个 agent,再次切换回 A 项目的 dev 分支时,agent 实例显示的还是 B 项目的。

根因

activeIds 使用 cwd 作为唯一 key,不同仓库切换时 key 被覆盖,导致切回旧仓库时 MainContent.tsxactiveSessionId 计算找到的是错误 repo 的 session。

修复

  • 使用复合 key ${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 - 运行项目弹窗

根因: activeIds 使用 cwd 作为唯一 key,不同仓库切换时 key 被覆盖,
导致切回旧仓库时 MainContent 的 activeSessionId 计算找到错误的 session。

修复:
- 使用复合 key repoPath::cwd 实现跨仓库隔离
- setActiveId 签名改为 (repoPath, cwd, sessionId)
- useActiveSessionId 提供可选 repoPath 参数保持向后兼容
- 更新 AgentPanel/MainContent/useFocusSession/RunningProjectsPopover 调用点
@github-actions

Copy link
Copy Markdown
Contributor

Claude Code is working…

I'll analyze this and get back to you.

View job run

@J3n5en J3n5en merged commit 85424b2 into J3n5en:main Apr 17, 2026
1 check failed
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