fix: workspace fallback 统一到 WORKSPACE_BASE(/d/pipeline/workspaces),修复通用助手(无项目)仍用旧 /tmp/pipeline_ws 的问题
This commit is contained in:
parent
bb29d6d634
commit
42bf89c0c1
@ -19,6 +19,8 @@ import logging
|
|||||||
|
|
||||||
logger = logging.getLogger("pipeline.agent_loop")
|
logger = logging.getLogger("pipeline.agent_loop")
|
||||||
|
|
||||||
|
from .workspace import WORKSPACE_BASE
|
||||||
|
|
||||||
ROLE_ALIASES = {
|
ROLE_ALIASES = {
|
||||||
'developer': 'agent.develop', 'dev': 'agent.develop', 'development': 'agent.develop', 'coding': 'agent.develop',
|
'developer': 'agent.develop', 'dev': 'agent.develop', 'development': 'agent.develop', 'coding': 'agent.develop',
|
||||||
'requirement': 'agent.requirement', 'requirements': 'agent.requirement', 'requirement_analysis': 'agent.requirement',
|
'requirement': 'agent.requirement', 'requirements': 'agent.requirement', 'requirement_analysis': 'agent.requirement',
|
||||||
@ -156,14 +158,14 @@ def _get_db():
|
|||||||
|
|
||||||
def _resolve_workspace(workspace_dir):
|
def _resolve_workspace(workspace_dir):
|
||||||
if not workspace_dir:
|
if not workspace_dir:
|
||||||
workspace_dir = os.path.expanduser('~/pipeline_ws/default')
|
workspace_dir = os.path.join(WORKSPACE_BASE, 'default')
|
||||||
try:
|
try:
|
||||||
parent = os.path.dirname(workspace_dir)
|
parent = os.path.dirname(workspace_dir)
|
||||||
if parent and not os.access(parent, os.W_OK):
|
if parent and not os.access(parent, os.W_OK):
|
||||||
proj_name = os.path.basename(workspace_dir)
|
proj_name = os.path.basename(workspace_dir)
|
||||||
workspace_dir = os.path.expanduser(f'~/pipeline_ws/{proj_name}')
|
workspace_dir = os.path.join(WORKSPACE_BASE, proj_name)
|
||||||
except Exception:
|
except Exception:
|
||||||
workspace_dir = os.path.expanduser(f'~/pipeline_ws/{os.path.basename(workspace_dir) or "default"}')
|
workspace_dir = os.path.join(WORKSPACE_BASE, os.path.basename(workspace_dir) or "default")
|
||||||
os.makedirs(workspace_dir, exist_ok=True)
|
os.makedirs(workspace_dir, exist_ok=True)
|
||||||
return workspace_dir
|
return workspace_dir
|
||||||
|
|
||||||
@ -219,7 +221,7 @@ async def _is_safe_workdir_async(workdir):
|
|||||||
|
|
||||||
async def _run_shell(command, workdir, timeout=120):
|
async def _run_shell(command, workdir, timeout=120):
|
||||||
"""安全执行 shell 命令。返回 {"rc": int, "stdout": str, "stderr": str}"""
|
"""安全执行 shell 命令。返回 {"rc": int, "stdout": str, "stderr": str}"""
|
||||||
cwd = os.path.abspath(workdir) if workdir else os.path.expanduser('~/pipeline_ws')
|
cwd = os.path.abspath(workdir) if workdir else WORKSPACE_BASE
|
||||||
if not await _is_safe_workdir_async(cwd):
|
if not await _is_safe_workdir_async(cwd):
|
||||||
return {"rc": -1, "stdout": "", "stderr": f"安全限制:目录 {cwd} 不在允许范围"}
|
return {"rc": -1, "stdout": "", "stderr": f"安全限制:目录 {cwd} 不在允许范围"}
|
||||||
if not os.path.isdir(cwd):
|
if not os.path.isdir(cwd):
|
||||||
|
|||||||
@ -26,6 +26,8 @@ from typing import AsyncGenerator, Dict, List, Optional
|
|||||||
|
|
||||||
logger = logging.getLogger("pipeline.agent_executor")
|
logger = logging.getLogger("pipeline.agent_executor")
|
||||||
|
|
||||||
|
from .workspace import WORKSPACE_BASE
|
||||||
|
|
||||||
|
|
||||||
# ── 默认工具定义(在 pipeline-core 未加载时使用)──
|
# ── 默认工具定义(在 pipeline-core 未加载时使用)──
|
||||||
|
|
||||||
@ -67,7 +69,7 @@ class AgentExecutor:
|
|||||||
self.org_id = "" # loaded from project context
|
self.org_id = "" # loaded from project context
|
||||||
self.pipeline_id = "" # loaded from project context(产线能力包 key)
|
self.pipeline_id = "" # loaded from project context(产线能力包 key)
|
||||||
self.role = role # 产线内角色(技能/工具/prompt 按角色加载)
|
self.role = role # 产线内角色(技能/工具/prompt 按角色加载)
|
||||||
self.workspace_dir = workspace_dir or "/tmp/pipeline_ws"
|
self.workspace_dir = workspace_dir or WORKSPACE_BASE
|
||||||
self.model_name = model_name or config.model_name
|
self.model_name = model_name or config.model_name
|
||||||
|
|
||||||
# 运行状态
|
# 运行状态
|
||||||
@ -800,7 +802,7 @@ class AgentExecutor:
|
|||||||
org_id = getattr(_u[0], "orgid", "0") or "0"
|
org_id = getattr(_u[0], "orgid", "0") or "0"
|
||||||
|
|
||||||
# 项目专属工作空间目录(workspace_base 从 appbase params 表读,可动态配置)
|
# 项目专属工作空间目录(workspace_base 从 appbase params 表读,可动态配置)
|
||||||
# 不设置 workspace_dir 会导致 _resolve_workspace 回退到 ~/pipeline_ws/default,
|
# 不设置 workspace_dir 会导致 _resolve_workspace 回退到 WORKSPACE_BASE/default,
|
||||||
# 所有项目共用同一目录,设计文档/代码互相覆盖。
|
# 所有项目共用同一目录,设计文档/代码互相覆盖。
|
||||||
from .workspace import get_workspace_base
|
from .workspace import get_workspace_base
|
||||||
workspace_base = await get_workspace_base(sor)
|
workspace_base = await get_workspace_base(sor)
|
||||||
@ -837,7 +839,7 @@ class AgentExecutor:
|
|||||||
def _resolve_ws_path(self, path: str) -> str:
|
def _resolve_ws_path(self, path: str) -> str:
|
||||||
"""解析相对路径为工作空间内绝对路径(越界返回 '')。"""
|
"""解析相对路径为工作空间内绝对路径(越界返回 '')。"""
|
||||||
import os
|
import os
|
||||||
ws = self.workspace_dir or "/tmp/pipeline_ws"
|
ws = self.workspace_dir or WORKSPACE_BASE
|
||||||
full = os.path.abspath(os.path.join(ws, path or "."))
|
full = os.path.abspath(os.path.join(ws, path or "."))
|
||||||
# 限制在 workspace 内
|
# 限制在 workspace 内
|
||||||
if full != ws and not full.startswith(ws.rstrip("/") + "/"):
|
if full != ws and not full.startswith(ws.rstrip("/") + "/"):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user