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(team): Default write position for coding_memory_write has been changed
weichenhaoddd444084458
diff --git a/jiuwenswarm/agents/swarm/providers/code_rails.py b/jiuwenswarm/agents/swarm/providers/code_rails.pyindex 68407c579d..5d7ef237e2 100644--- a/jiuwenswarm/agents/swarm/providers/code_rails.py+++ b/jiuwenswarm/agents/swarm/providers/code_rails.py@@ -234,12 +234,19 @@ def build_code_coding_memory(params: dict[str, Any], ctx: SwarmBuildContext) ->try:from jiuwenswarm.server.runtime.agent_adapter.interface_code import (create_coding_memory_rail,+ _set_workspace_coding_memory_directory,)inp = CodeCodingMemoryInput.resolve(params, ctx)+ workspace_root = str(inp.workspace_root or "./")+ _set_workspace_coding_memory_directory(+ ctx.workspace,+ project_dir=inp.project_dir,+ agent_workspace_dir=workspace_root,+ )rail = create_coding_memory_rail(project_dir=inp.project_dir,- agent_workspace_dir=str(inp.workspace_root or "./"),+ agent_workspace_dir=workspace_root,config={"embed": inp.embed_config},)# Share the instance with the code_agent sub-agent via the build context.diff --git a/jiuwenswarm/common/coding_memory_paths.py b/jiuwenswarm/common/coding_memory_paths.pyindex 9c8cc38427..e881bad909 100644--- a/jiuwenswarm/common/coding_memory_paths.py+++ b/jiuwenswarm/common/coding_memory_paths.py@@ -38,3 +38,14 @@ def resolve_project_coding_memory_dir("coding_memory",resolve_coding_memory_project_name(project_dir),)+++def resolve_project_coding_memory_workspace_path(+ *,+ project_dir: str | PathLike[str] | None,+) -> str:+ """Resolve the workspace-relative ``coding_memory/<project_name>`` path."""+ return os.path.join(+ "coding_memory",+ resolve_coding_memory_project_name(project_dir),+ )diff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_code.py b/jiuwenswarm/server/runtime/agent_adapter/interface_code.pyindex a7ddb663a1..73fcea0dbb 100644--- a/jiuwenswarm/server/runtime/agent_adapter/interface_code.py+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_code.py@@ -67,7 +67,10 @@ from jiuwenswarm.agents.harness.common.tools import ()from jiuwenswarm.agents.harness.common.tools.acp_chat import acp_chatfrom jiuwenswarm.common.config import get_config-from jiuwenswarm.common.coding_memory_paths import resolve_project_coding_memory_dir+from jiuwenswarm.common.coding_memory_paths import (+ resolve_project_coding_memory_dir,+ resolve_project_coding_memory_workspace_path,+)from jiuwenswarm.server.runtime.agent_adapter.code_agent_rail import CodeAgentRailfrom jiuwenswarm.common.hooks_config import load_hooks_configfrom jiuwenswarm.server.hooks.user_hook_rail import UserHookRail@@ -231,14 +234,14 @@ def _resolve_coding_memory_dir(def _build_coding_memory_directory_node(- coding_memory_dir: str,+ coding_memory_path: str,*,description: str,) -> dict[str, Any]:return {"name": "coding_memory","description": description,- "path": coding_memory_dir,+ "path": coding_memory_path,"children": [{"name": "MEMORY.md",@@ -263,13 +266,12 @@ def _set_workspace_coding_memory_directory(if not callable(set_directory):return- coding_memory_dir = _resolve_coding_memory_dir(+ coding_memory_path = resolve_project_coding_memory_workspace_path(project_dir=project_dir,- agent_workspace_dir=agent_workspace_dir,)set_directory(_build_coding_memory_directory_node(- coding_memory_dir,+ coding_memory_path,description=description,))diff --git a/tests/agents/swarm/test_swarm_assembly.py b/tests/agents/swarm/test_swarm_assembly.pyindex d08cce2514..49499d839e 100644--- a/tests/agents/swarm/test_swarm_assembly.py+++ b/tests/agents/swarm/test_swarm_assembly.py@@ -61,6 +61,13 @@ from jiuwenswarm.agents.swarm.providers import (runtime_tools,tools,)+from jiuwenswarm.agents.harness.team.team_runtime_inheritance import (+ resolve_model_config,+)+from jiuwenswarm.common.coding_memory_paths import (+ resolve_project_coding_memory_dir,+ resolve_project_coding_memory_workspace_path,+)from jiuwenswarm.common.config import get_configlogger = logging.getLogger(__name__)@@ -1140,6 +1147,86 @@ def test_code_extra_tools_gated_by_config() -> None:assert isinstance(tools.build_code_extra_tools({}, enabled), list)+def test_code_coding_memory_provider_mounts_workspace_node(+ tmp_path: Path,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The declarative coding-memory provider must also mount the workspace node."""+ register_swarm_providers()++ import jiuwenswarm.server.runtime.agent_adapter.interface_code as interface_code++ project_dir = tmp_path / "project"+ workspace_root = tmp_path / "member-workspace"+ project_dir.mkdir()+ workspace_root.mkdir()++ created: dict[str, Any] = {}+ rail = object()++ def _fake_create_coding_memory_rail(+ *,+ project_dir: str | None,+ agent_workspace_dir: str,+ config: dict[str, Any] | None,+ ) -> object:+ created["project_dir"] = project_dir+ created["agent_workspace_dir"] = agent_workspace_dir+ created["config"] = config+ return rail++ monkeypatch.setattr(+ interface_code,+ "create_coding_memory_rail",+ _fake_create_coding_memory_rail,+ )++ class Workspace:+ def __init__(self, root_path: Path) -> None:+ self.root_path = str(root_path)+ self.directories: list[dict[str, Any]] = []++ def set_directory(self, directory: dict[str, Any]) -> None:+ self.directories.append(directory)++ workspace = Workspace(workspace_root)+ ctx = SwarmBuildContext(+ mode="code.team",+ project_dir=str(project_dir),+ workspace=workspace,+ config={},+ )++ built = code_rails.build_code_coding_memory({"embed_config": {}}, ctx)++ assert built is rail+ assert ctx.extras[code_rails.CODING_MEMORY_EXTRAS_KEY] is rail+ assert created == {+ "project_dir": str(project_dir),+ "agent_workspace_dir": str(workspace_root),+ "config": {"embed": {}},+ }+ assert workspace.directories == [+ {+ "name": "coding_memory",+ "description": "Coding Agent memory",+ "path": resolve_project_coding_memory_workspace_path(+ project_dir=str(project_dir),+ ),+ "children": [+ {+ "name": "MEMORY.md",+ "description": "Coding 记忆索引",+ "path": "MEMORY.md",+ "children": [],+ "is_file": True,+ "default_content": "",+ }+ ],+ }+ ]++def test_code_member_builds_declaratively_without_post_processing(tmp_path,monkeypatch: pytest.MonkeyPatch,@@ -1211,6 +1298,31 @@ def test_code_member_builds_declaratively_without_post_processing(assert agent.deep_config.system_prompt# CodingMemoryRail is published for the code_agent sub-agent to reuse.assert ctx.extras.get(code_rails.CODING_MEMORY_EXTRAS_KEY) is not None+ coding_memory_dir = resolve_project_coding_memory_dir(+ agent_workspace_dir=str(tmp_path),+ project_dir=str(tmp_path),+ )+ coding_memory_workspace_path = resolve_project_coding_memory_workspace_path(+ project_dir=str(tmp_path),+ )+ coding_memory_node = next(+ node+ for node in agent.deep_config.workspace.directories+ if node.get("name") == "coding_memory"+ )+ assert coding_memory_node["path"] == coding_memory_workspace_path+ assert Path(coding_memory_node["path"]).is_absolute() is False+ assert Path(coding_memory_dir).is_dir()+ assert coding_memory_node["children"] == [+ {+ "name": "MEMORY.md",+ "description": "Coding 记忆索引",+ "path": "MEMORY.md",+ "children": [],+ "is_file": True,+ "default_content": "",+ }+ ]logger.info("code member declarative build rail types: %s", sorted(rail_types))diff --git a/tests/unit_tests/agentserver/test_team_manager_skill_state.py b/tests/unit_tests/agentserver/test_team_manager_skill_state.pyindex 957fffad1b..cc8524e6a2 100644--- a/tests/unit_tests/agentserver/test_team_manager_skill_state.py+++ b/tests/unit_tests/agentserver/test_team_manager_skill_state.py@@ -5,6 +5,10 @@from pathlib import Pathfrom types import SimpleNamespace+from jiuwenswarm.common.coding_memory_paths import (+ resolve_project_coding_memory_dir,+ resolve_project_coding_memory_workspace_path,+)@@ -100,6 +104,16 @@ def test_configure_code_team_member_uses_agent_workspace_coding_memory_path(monk)coding_memory_path = Path(workspace.directories[0]["path"])- assert coding_memory_path.is_absolute()- assert coding_memory_path == global_workspace / "coding_memory" / "project"- assert coding_memory_path != member_workspace / "coding_memory"+ assert coding_memory_path.is_absolute() is False+ assert workspace.directories[0]["path"] == resolve_project_coding_memory_workspace_path(+ project_dir=str(parent_project),+ )++ coding_memory_storage_path = Path(+ resolve_project_coding_memory_dir(+ agent_workspace_dir=str(global_workspace),+ project_dir=str(parent_project),+ )+ )+ assert coding_memory_storage_path == global_workspace / "coding_memory" / "project"+ assert coding_memory_storage_path != member_workspace / "coding_memory"