fix: devops处理器智能提取git命令——从中文自然语言中识别git URL自动补全git clone
This commit is contained in:
parent
255863aa66
commit
46239bccc7
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user