From 46239bccc7648fa8b02ad5d097e62225d5ef84cf Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 6 Aug 2026 14:18:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20devops=E5=A4=84=E7=90=86=E5=99=A8?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E6=8F=90=E5=8F=96git=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E2=80=94=E2=80=94=E4=BB=8E=E4=B8=AD=E6=96=87=E8=87=AA=E7=84=B6?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E4=B8=AD=E8=AF=86=E5=88=ABgit=20URL=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=A1=A5=E5=85=A8git=20clone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/cockpit_chat.dspy | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index dc14090..48086f4 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -876,10 +876,24 @@ if action == 'send_message': else: agent_reply = f"❌ 导入失败:{msg}" elif intent_type == 'devops': - # LLM 分类器的 description 可能是自然语言,直接用用户原始消息作为命令 + # 从自然语言中提取实际命令:剥前缀 + 识别 git URL 自动构造 git clone cmd = message_text.strip() import re - cmd = re.sub(r'^(执行命令[::]|运行[::]|帮我\s*)', '', cmd).strip() + cmd = re.sub(r'^(执行命令[::]|运行[::]|帮我\s*|克隆仓库\s*|从.*克隆\s*)', '', cmd).strip() + # 如果包含 git@ 或 https://...git 但没有 git clone 前缀,自动补全 + if re.search(r'(git@[\w.]+:[\w./-]+\.git|https?://[\w./-]+\.git)', cmd): + if not cmd.startswith('git '): + # 提取 URL 和可选目标路径 + m = re.search(r'(git@[\w.]+:[\w./-]+\.git|https?://[\w./-]+\.git)', cmd) + repo_url = m.group(0) + rest = cmd[m.end():].strip() + target = rest.split()[0] if rest else '' + if target and not target.startswith('-'): + cmd = f'git clone {repo_url} {target}' + else: + cmd = f'git clone {repo_url}' + # 特殊处理:包含"到本地""到工作区"→只保留 git clone url + cmd = re.sub(r'(\s+(到本地|到工作区|到workspace).*)', '', cmd).strip() workdir = ctx.get('workspace_dir', '') or '/d/pipeline/workspaces' result = await shell_exec(cmd, workdir=workdir) if result['rc'] == 0: