Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix: change coding memory to {agent_workspace_dir}/coding_memory/{project name}

ldstyle899f17ccd0af0
diff --git a/jiuwenclaw/agents/harness/common/memory/manager.py b/jiuwenclaw/agents/harness/common/memory/manager.py
index 675679387e..f56503779e 100644
--- a/jiuwenclaw/agents/harness/common/memory/manager.py
+++ b/jiuwenclaw/agents/harness/common/memory/manager.py
@@ -20,7 +20,7 @@ from .internal import (
hash_text, build_fts_query, bm25_rank_to_score, is_memory_path
)
from .embeddings import EmbeddingProvider, create_embedding_provider
-from .config import MemorySettings
+from .config import MemorySettings, create_memory_settings
logger = logging.getLogger(__name__)
@@ -1220,5 +1220,5 @@ async def get_memory_manager(
settings: Optional[MemorySettings] = None
) -> Optional[MemoryIndexManager]:
"""Get or create memory manager."""
- settings = settings or MemorySettings()
+ settings = settings or create_memory_settings(workspace_dir=workspace_dir)
return await MemoryIndexManager.get(agent_id, workspace_dir, settings)
diff --git a/jiuwenclaw/agents/harness/common/memory_rpc.py b/jiuwenclaw/agents/harness/common/memory_rpc.py
index c43d14bab7..0faf976257 100644
--- a/jiuwenclaw/agents/harness/common/memory_rpc.py
+++ b/jiuwenclaw/agents/harness/common/memory_rpc.py
@@ -31,10 +31,15 @@ def _is_forbidden_enabled(config: dict[str, Any] | None) -> bool:
return bool(forbidden.get("enabled", False))
+def _get_coding_memory_dir(workspace: str, project_dir: str | None = None) -> str:
+ _project_name = os.path.basename(project_dir) if project_dir else "default"
+ return os.path.join(workspace, "coding_memory", _project_name)
+
+
def _get_allowed_dirs(workspace: str, project_dir: str | None = None) -> list[str]:
allowed_dirs = [
os.path.join(workspace, "memory"),
- os.path.join(workspace, "coding_memory"),
+ _get_coding_memory_dir(workspace, project_dir),
os.path.join(workspace, ".jiuwen"),
os.path.expanduser("~/.jiuwen"),
]
@@ -191,7 +196,7 @@ async def handle_memory_list(
files.append(item)
seen_paths.add(item["path"])
- coding_dir = os.path.join(workspace, "coding_memory")
+ coding_dir = _get_coding_memory_dir(workspace, project_dir)
for item in _scan_md_files(coding_dir, "coding", workspace, project_dir):
if item["path"] not in seen_paths:
files.append(item)
@@ -296,7 +301,7 @@ async def handle_memory_status(
if project_dir:
result["project_memory"]["project_dir"] = project_dir
- coding_dir = os.path.join(workspace, "coding_memory")
+ coding_dir = _get_coding_memory_dir(workspace, project_dir)
coding_files = _scan_md_files(coding_dir, "coding", workspace)
coding_total_chars = 0
for cf in coding_files:
@@ -415,7 +420,7 @@ async def handle_memory_open(
}
if project_dir:
result["project_dir"] = project_dir
- coding_dir = os.path.join(workspace, "coding_memory")
+ coding_dir = _get_coding_memory_dir(workspace, project_dir)
if os.path.isdir(coding_dir):
result["coding_memory_dir"] = coding_dir
return result
diff --git a/jiuwenclaw/agents/harness/common/tools/memory_tools.py b/jiuwenclaw/agents/harness/common/tools/memory_tools.py
index ce4e7fda2d..5c47f0c0c0 100644
--- a/jiuwenclaw/agents/harness/common/tools/memory_tools.py
+++ b/jiuwenclaw/agents/harness/common/tools/memory_tools.py
@@ -15,6 +15,7 @@ from ..memory import (
MemorySettings,
create_memory_settings,
is_memory_enabled,
+ DEFAULT_WORKSPACE_DIR,
)
logger = logging.getLogger(__name__)
@@ -150,7 +151,8 @@ async def _ensure_global_manager() -> bool:
return True
try:
- _global_settings = _global_settings or MemorySettings()
+ workspace_dir = _global_workspace_dir or DEFAULT_WORKSPACE_DIR
+ _global_settings = _global_settings or create_memory_settings(workspace_dir=workspace_dir)
_global_manager = await MemoryIndexManager.get(
agent_id=_global_agent_id,
workspace_dir=_global_workspace_dir,
diff --git a/jiuwenclaw/server/runtime/agent_adapter/interface_code.py b/jiuwenclaw/server/runtime/agent_adapter/interface_code.py
index 1f783e7ca5..711a5ea587 100644
--- a/jiuwenclaw/server/runtime/agent_adapter/interface_code.py
+++ b/jiuwenclaw/server/runtime/agent_adapter/interface_code.py
@@ -155,6 +155,8 @@ class JiuwenClawCodeAdapter(JiuWenClawDeepAdapter):
or config.get("workspace_dir")
or str(get_agent_workspace_dir())
)
+ # Coding memory 使用固定的 agent workspace 目录,不受 project_dir 影响
+ self._agent_workspace_dir = str(get_agent_workspace_dir())
model = self._create_model(config_base)
agent_card = AgentCard(name=self._agent_name, id='jiuwenclaw')
@@ -201,6 +203,24 @@ class JiuwenClawCodeAdapter(JiuWenClawDeepAdapter):
auto_create_workspace=False
)
+ _project_name = os.path.basename(self._project_dir) if self._project_dir else "default"
+ coding_memory_abs_path = os.path.join(self._agent_workspace_dir, "coding_memory", _project_name)
+ self._instance.deep_config.workspace.set_directory({
+ "name": "coding_memory",
+ "description": "Coding Agent 记忆模块",
+ "path": coding_memory_abs_path,
+ "children": [
+ {
+ "name": "MEMORY.md",
+ "description": "Coding 记忆索引",
+ "path": "MEMORY.md",
+ "children": [],
+ "is_file": True,
+ "default_content": "",
+ },
+ ],
+ })
+
# code 模式不传: vision_model_config, audio_model_config,
# context_engine_config, completion_timeout
@@ -397,7 +417,8 @@ class JiuwenClawCodeAdapter(JiuWenClawDeepAdapter):
return None
language = config.get("preferred_language", "zh")
- coding_memory_dir = os.path.join(self._workspace_dir, "coding_memory")
+ _project_name = os.path.basename(self._project_dir) if self._project_dir else "default"
+ coding_memory_dir = os.path.join(self._agent_workspace_dir, "coding_memory", _project_name)
os.makedirs(coding_memory_dir, exist_ok=True)
coding_memory_rail = CodingMemoryRail(