Skip to content

Commit 791666f

Browse files
CopilotHeDaas-Code
andcommitted
Fix AgentMode initialization - auto-init when prerequisites met
Root cause: AgentMode only initialized in settings dialog, not on repo open Fix: 1. Added _ensure_agent_mode_initialized() method 2. Call in toggleCopilotPanel when panel shown 3. Call in showCopilotSettings after config reload 4. Connected repoChanged signal to auto-initialization 5. Prerequisites: gitManager + copilotManager.client both required 6. Info logging when auto-initialized Now AgentMode initializes automatically when both API key and Git repo are available, regardless of order or when settings were last saved. Co-authored-by: HeDaas-Code <208586641+HeDaas-Code@users.noreply.github.com>
1 parent 6553b0a commit 791666f

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

src/views/main_window.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,9 @@ def connectSignals(self):
832832
# 同时也通知Git面板更新最近仓库列表
833833
self.configManager.recentRepositoriesChanged.connect(self.gitPanel.updateRecentRepositories)
834834

835+
# 仓库变化时尝试初始化AgentMode
836+
self.repoChanged.connect(lambda: self._ensure_agent_mode_initialized())
837+
835838
def updatePreview(self):
836839
""" 更新Markdown预览 """
837840
content = self.editor.toPlainText()
@@ -1455,14 +1458,8 @@ def showCopilotSettings(self):
14551458
# 重新加载copilot配置
14561459
self.copilotManager.reload_config()
14571460

1458-
# 初始化agent mode if git manager available
1459-
if self.gitManager and self.copilotManager.client:
1460-
from src.copilot.agent_mode import AgentMode
1461-
self.agentMode = AgentMode(
1462-
self.copilotManager.client,
1463-
self.gitManager
1464-
)
1465-
info("Agent mode initialized")
1461+
# 确保AgentMode初始化
1462+
self._ensure_agent_mode_initialized()
14661463

14671464
InfoBar.success(
14681465
title="设置已保存",

0 commit comments

Comments
 (0)