From eba90e934347d65238f0fba450f69adcaf4818af Mon Sep 17 00:00:00 2001 From: zhayujie Date: Wed, 11 Mar 2026 23:35:42 +0800 Subject: [PATCH] fix: workspace bootstrap --- agent/prompt/workspace.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/agent/prompt/workspace.py b/agent/prompt/workspace.py index 1b7b48c..6cd44c5 100644 --- a/agent/prompt/workspace.py +++ b/agent/prompt/workspace.py @@ -42,14 +42,16 @@ def ensure_workspace(workspace_dir: str, create_templates: bool = True) -> Works Returns: WorkspaceFiles对象,包含所有文件路径 """ - # Check if this is a brand new workspace (before creating the directory) - is_new_workspace = not os.path.exists(workspace_dir) + # Check if this is a brand new workspace (AGENT.md not yet created). + # Cannot rely on directory existence because other modules (e.g. ConversationStore) + # may create the workspace directory before ensure_workspace is called. + agent_path = os.path.join(workspace_dir, DEFAULT_AGENT_FILENAME) + is_new_workspace = not os.path.exists(agent_path) # 确保目录存在 os.makedirs(workspace_dir, exist_ok=True) # 定义文件路径 - agent_path = os.path.join(workspace_dir, DEFAULT_AGENT_FILENAME) user_path = os.path.join(workspace_dir, DEFAULT_USER_FILENAME) rule_path = os.path.join(workspace_dir, DEFAULT_RULE_FILENAME) memory_path = os.path.join(workspace_dir, DEFAULT_MEMORY_FILENAME) # MEMORY.md 在根目录