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(team): resolve project workspace prompt in code.team

openJiuwen-botbc56fd2f9d1d
diff --git a/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py b/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py
index 35c30cb094..fd698ca596 100644
--- a/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py
+++ b/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py
@@ -67,6 +67,7 @@ class RuntimePromptRail(DeepAgentRail):
self.system_prompt_builder.remove_section("language_output")
self.system_prompt_builder.remove_section("env")
self.system_prompt_builder.remove_section("browser_tool_policy")
+ self.system_prompt_builder.remove_section("tui_current_project_policy")
self.system_prompt_builder = None
self.attachment_manager = None
@@ -139,7 +140,8 @@ class RuntimePromptRail(DeepAgentRail):
"runtime.model_answer_policy",
"language_output",
"env",
- "browser_tool_policy"):
+ "browser_tool_policy",
+ "tui_current_project_policy"):
self.system_prompt_builder.remove_section(name)
# ── time ──
@@ -401,6 +403,15 @@ class RuntimePromptRail(DeepAgentRail):
cn_dirs_display = ", ".join(other_dirs) if other_dirs else "无"
en_dirs_display = ", ".join(other_dirs) if other_dirs else "none"
if not self._force_english and self._language == "cn":
+ current_project_policy = (
+ "# 当前项目工作空间\n\n"
+ f"- 当前项目目录:{project_dir}\n"
+ f"- 系统目录:{workspace_dir}\n\n"
+ "- 当用户询问“当前工作空间”“当前工作目录”“当前项目目录”“项目空间”或 workspace,"
+ "且没有明确限定 team workspace、系统目录或其他目录时,直接回答当前项目目录。\n"
+ "- 不要为了回答这类问题调用 `pwd`、`ls` 或读取内部 Team Leader workspace;"
+ "也不要把系统目录、team-workspace 或 Team Leader workspace 称为当前工作空间。\n"
+ )
trusted_dirs_content = (
"# 工作目录策略\n\n"
f"- 系统目录(不要在其中查找或运行项目文件):{workspace_dir}\n"
@@ -417,6 +428,19 @@ class RuntimePromptRail(DeepAgentRail):
"- 确认时需明确告知:操作的完整路径、操作类型(读取/编辑/执行)、潜在风险\n"
)
else:
+ current_project_policy = (
+ "# Current Project Workspace\n\n"
+ f"- Current project directory: {project_dir}\n"
+ f"- System directory: {workspace_dir}\n\n"
+ "- When the user asks for the current workspace, current working directory, "
+ "current project directory, project space, or workspace without explicitly "
+ "saying team workspace, "
+ "system directory, or another directory, answer directly with the current "
+ "project directory.\n"
+ "- Do not call `pwd`, `ls`, or inspect the internal Team Leader workspace "
+ "to answer this question, and do not call the system directory, "
+ "team-workspace, or Team Leader workspace the current workspace.\n"
+ )
trusted_dirs_content = (
"# Working Directory Policy\n\n"
f"- System directory (never search or run project files here): {workspace_dir}\n"
@@ -440,6 +464,11 @@ class RuntimePromptRail(DeepAgentRail):
"- When confirming, clearly state: the full path, operation type (read/edit/execute), "
"potential risks\n"
)
+ self.system_prompt_builder.add_section(PromptSection(
+ name="tui_current_project_policy",
+ content={"cn": current_project_policy, "en": current_project_policy},
+ priority=99,
+ ))
await self._upsert_prompt_attachment(
ctx,
section="trusted_dirs_policy",
diff --git a/jiuwenswarm/agents/swarm/providers/code_rails.py b/jiuwenswarm/agents/swarm/providers/code_rails.py
index cb98bd22e6..80dafe29c3 100644
--- a/jiuwenswarm/agents/swarm/providers/code_rails.py
+++ b/jiuwenswarm/agents/swarm/providers/code_rails.py
@@ -116,6 +116,10 @@ class CodeRuntimePromptInput(ConstructionInput):
channel: str = context_field(
attr="channel", default="default", description="Resolved channel key."
)
+ project_dir: str | None = context_field(
+ attr="project_dir",
+ description="Resolved user project directory.",
+ )
@harness_element(
@@ -133,7 +137,9 @@ def build_code_runtime_prompt(params: dict[str, Any], ctx: SwarmBuildContext) ->
try:
inp = CodeRuntimePromptInput.resolve(params, ctx)
- return RuntimePromptRail(language=inp.language, channel=inp.channel)
+ rail = RuntimePromptRail(language=inp.language, channel=inp.channel)
+ rail.set_runtime_paths(cwd=inp.project_dir, project_dir=inp.project_dir)
+ return rail
except Exception as exc:
logger.warning("[swarm.code_runtime_prompt] create failed: %s", exc)
return None
diff --git a/tests/agents/swarm/test_swarm_assembly.py b/tests/agents/swarm/test_swarm_assembly.py
index 478ba65239..76014c5bdb 100644
--- a/tests/agents/swarm/test_swarm_assembly.py
+++ b/tests/agents/swarm/test_swarm_assembly.py
@@ -24,6 +24,7 @@ import logging
import types
from pathlib import Path
from types import SimpleNamespace
+from typing import Any
import pytest
@@ -67,9 +68,6 @@ 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,
@@ -1181,6 +1179,27 @@ def test_code_runtime_language_by_mode_and_role() -> None:
assert code_rails.code_runtime_language(code_team) == "en"
+def test_code_runtime_prompt_provider_carries_project_dir(tmp_path: Path) -> None:
+ """code.team runtime prompts keep the user's project scope visible."""
+ register_swarm_providers()
+ project_dir = tmp_path / "project"
+ project_dir.mkdir()
+ ctx = SwarmBuildContext(
+ mode="code.team",
+ role="leader",
+ channel="tui",
+ project_dir=str(project_dir),
+ )
+
+ rail = RailSpec(type=registry.CODE_RUNTIME_PROMPT).build(
+ language="cn",
+ context=ctx,
+ )
+
+ assert getattr(rail, "_project_dir") == str(project_dir)
+ assert getattr(rail, "_cwd") == str(project_dir)
+
+
def test_team_plan_approval_provider_builds_only_for_leader() -> None:
"""The code.plan-style approval rail is scoped to the team.plan leader."""
register_swarm_providers()
diff --git a/tests/unit_tests/agentserver/test_system_prompt_restructure.py b/tests/unit_tests/agentserver/test_system_prompt_restructure.py
index 8d904550d5..432571d143 100644
--- a/tests/unit_tests/agentserver/test_system_prompt_restructure.py
+++ b/tests/unit_tests/agentserver/test_system_prompt_restructure.py
@@ -323,7 +323,9 @@ async def test_runtime_prompt_uses_runtime_cwd_over_stale_trusted_dir(tmp_path):
await runtime_rail.before_model_call(ctx)
prompt = builder.build()
- assert "Current project directory" not in prompt
+ assert "# Current Project Workspace" in prompt
+ assert "Current project directory" in prompt
+ assert "Do not call `pwd`, `ls`" in prompt
rendered = agent.prompt_attachment_manager.render(
await agent.prompt_attachment_manager.list_by_filter(session_id="sess1")
)