fix(workspace): switch_project后刷新工作目录——根治切项目后list_files仍列旧目录

This commit is contained in:
ymq 2026-08-31 19:31:48 +08:00
parent 947398c9ef
commit 06130bcbef

View File

@ -845,6 +845,7 @@ class AgentExecutor:
r = recs[0]
self.project_id = getattr(r, "id", "")
await self._persist_project(sor, self.project_id)
await self._refresh_workspace_dir(sor)
return f"OK: 已切换到 {getattr(r, 'name', name)}"
# LLM 分类匹配
@ -866,12 +867,28 @@ class AgentExecutor:
r = recs2[0]
self.project_id = getattr(r, "id", "")
await self._persist_project(sor, self.project_id)
await self._refresh_workspace_dir(sor)
return f"OK: 已切换到 {getattr(r, 'name', matched)}"
except Exception:
pass
return f"未找到项目: {name}"
async def _refresh_workspace_dir(self, sor):
"""切换项目后同步刷新工作目录(与上传落盘/初始化同一解析逻辑)。
不刷新则 list_files/read_file 仍停在切换前的目录或无项目时的总根
"""
try:
from .workspace import get_project_dir_by_id
_pdir, _ = await get_project_dir_by_id(sor, self.project_id)
if _pdir:
import os as _os
_os.makedirs(_pdir, exist_ok=True)
self.workspace_dir = _pdir
except Exception:
pass
async def _t_create_project(self, sor, p, pid):
import os
import re