|
|
@@ -507,6 +507,18 @@ async def rollback_agent(
|
|
|
_WORKSPACE_CONV_TEMPLATES = {"workspace.assistant"}
|
|
|
|
|
|
|
|
|
+def _resolve_session_cwd(inplace_dir: str, workspace_path: str, work_dir: str) -> str:
|
|
|
+ """会话 CWD(Bash/文件工具相对路径基准)必须 == 给模型看的 [工作目录] 提示
|
|
|
+ (= overrides["workspace_path"]),否则相对写入落错目录。见 _execute_agent 注释。
|
|
|
+ 工作区模式 → F;专项 agent → 本 run 的 workspace_path;兜底 → work_dir。"""
|
|
|
+ import os as _os
|
|
|
+ if inplace_dir and _os.path.isdir(inplace_dir):
|
|
|
+ return _os.path.abspath(inplace_dir)
|
|
|
+ if workspace_path and _os.path.isdir(workspace_path):
|
|
|
+ return workspace_path
|
|
|
+ return work_dir if (work_dir and _os.path.isdir(work_dir)) else workspace_path
|
|
|
+
|
|
|
+
|
|
|
def _is_native_workspace(agent, config) -> bool:
|
|
|
"""是否走原生 claude-code 车道:工作区对话型模板 **且** provider=claude-code。
|
|
|
native 车道是 `claude -p`(只认 claude 自己的模型);切到 qwen/ollama/openai 等
|
|
|
@@ -2166,15 +2178,15 @@ def _execute_agent(config: dict, input_text: str, on_step=None,
|
|
|
elif agent_dir:
|
|
|
workspace_path = create_run_workspace(agent_dir, run_id, input_text, config)
|
|
|
|
|
|
- # CRITICAL: align the Bash tool's session CWD.
|
|
|
- # Shell starts in work_dir (where final outputs go) so the agent
|
|
|
- # naturally reads/writes user files there. workspace_path is the
|
|
|
- # log/trace dir — {workspace} variable in prompts points there —
|
|
|
- # but Bash starts in work_dir.
|
|
|
- # When work_dir is absent, fall back to workspace_path (existing behaviour).
|
|
|
- _cwd_to_set = (
|
|
|
- work_dir if (work_dir and os.path.isdir(work_dir)) else workspace_path
|
|
|
- )
|
|
|
+ # CRITICAL: Bash/文件工具的会话 CWD 必须 == 给模型看的 [工作目录] 提示
|
|
|
+ # (compiler step-0 注入的 = overrides["workspace_path"])。否则模型把产物写成
|
|
|
+ # 相对路径时落到 CWD,而提示叫它写到另一个目录 → 产物落错地方、run 查看器空、
|
|
|
+ # 跨 run 互相覆盖(run_bf2405e28547 实锤:literature_map.md 落进 agent 家目录而非
|
|
|
+ # 本 run 工作区)。对齐规则:
|
|
|
+ # · 工作区对话模式(inplace_dir=F):CWD = F(就地读写用户文件夹)。
|
|
|
+ # · 专项 agent:CWD = 本 run 的 workspace_path(per-run 隔离,查看器可见,不覆盖);
|
|
|
+ # 读输入靠 [数据来源目录] 的绝对路径(step-0 提示已明确禁止相对/无参读)。
|
|
|
+ _cwd_to_set = _resolve_session_cwd(inplace_dir, workspace_path, work_dir)
|
|
|
# P1 工作文件夹硬沙箱:工作区模式(inplace_dir 有值)下,把 WriteFile/EditFile
|
|
|
# 的写限定在所选文件夹 F 内,越界写直接拒绝。仅工作区模式启用——专项智能体
|
|
|
# 写各自 run 工作区,root=None 不受影响。finally(下方)清空,防泄漏到下个 run。
|