From 956093bc7797e85aad8e1402fb9fecac2c03ed2a Mon Sep 17 00:00:00 2001 From: ymq Date: Sat, 8 Aug 2026 12:10:28 +0800 Subject: [PATCH] cockpit: add add_repo/show_repo intents + system prompt update --- wwwroot/api/cockpit_chat.dspy | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index 202852e..6ff2d37 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -19,12 +19,15 @@ DEFAULT_SYSTEM_PROMPT = """你是一个专业的软件开发 Agent,名为「 - Bug(sd_bugs):缺陷报告,含标题、严重程度(critical/major/minor/trivial)、状态 - 交付件(pipeline_deliverables):任务执行产生的交付物 - Agent(pipeline_project_agents):项目配置的角色Agent(develop/test/deploy/ops等) +- 仓库(sd_project_repos):项目关联的代码仓库(git地址+分支) ## 当前上下文中的项目/迭代信息由系统自动注入。用户可通过以下方式操作: - "创建XXX项目" → 创建新项目并自动创建默认迭代 - "切换到XXX项目" → 切换当前项目 - "显示任务列表/项目任务" → 查看当前项目任务 - "显示Bug/Bug列表" → 查看Bug +- "仓库 git@xxx:org/repo.git" → 为当前项目添加代码仓库 +- "有哪些仓库" → 查看项目关联的仓库 - 描述开发需求 → 自动创建任务,由角色Agent认领执行 ## 对话规则 @@ -405,6 +408,8 @@ INTENT_PROMPT = """你是一个开发产线意图分类器。分析用户输入 - chat: 开发相关的一般对话 - answer_question: 用户在回答角色Agent此前提出的问题(见「待客户回答的问题」) - out_of_scope: 完全无关软件开发 +- add_repo: 为当前项目添加代码仓库(如\"仓库地址 git@git.xxx:org/repo.git\"\"添加仓库\"\"关联仓库\") +- show_repos: 查看当前项目关联的仓库(如\"有哪些仓库\"\"显示仓库\") 当前上下文:项目={ctx},迭代={iter} 待客户回答的问题(角色Agent执行任务中提出):{questions} @@ -953,6 +958,49 @@ if action == 'send_message': for d in drecs: lines.append(f" · {d.title} [{d.review_status}] {d.quality_score}分") agent_reply = '\n'.join(lines) if len(lines) > 1 else "暂无Agent活动" + elif intent_type == 'add_repo': + pid = ctx['project_id'] + if not pid: + agent_reply = "请先切换到项目。" + else: + import re + repo_url = '' + repo_name = '' + m = re.search(r'(git@[\w.]+:[\w./-]+\.git|https?://[\w./-]+\.git)', message_text) + if m: + repo_url = m.group(0) + repo_name = repo_url.rstrip('/').split('/')[-1].replace('.git', '') + if not repo_url: + agent_reply = "请提供 git 仓库地址,例如:仓库 git@git.opencomputing.cn:org/repo.git" + else: + existing = await sor.sqlExe( + "SELECT id FROM sd_project_repos WHERE project_id=${pid}$ AND repo_url=${url}$", + {"pid": pid, "url": repo_url}) + if existing: + agent_reply = f"仓库 {repo_url} 已关联到当前项目。" + else: + rid = getID() + await sor.C('sd_project_repos', { + 'id': rid, 'project_id': pid, 'repo_name': repo_name, + 'repo_url': repo_url, 'default_branch': 'main', + 'local_path': '', 'org_id': org_id, + }) + agent_reply = f"✅ 已关联仓库 {repo_name}({repo_url})到项目「{ctx['project_name']}」。" + elif intent_type == 'show_repos': + pid = ctx['project_id'] + if not pid: + agent_reply = "请先切换到项目。" + else: + repos = await sor.sqlExe( + "SELECT repo_name, repo_url, default_branch FROM sd_project_repos WHERE project_id=${pid}$", + {"pid": pid}) + if not repos: + agent_reply = f"项目「{ctx['project_name']}」暂未关联代码仓库。\n\n关联方式:发送「仓库 git@xxx:org/repo.git」" + else: + lines = [f"📁 项目「{ctx['project_name']}」的代码仓库:"] + for r in repos: + lines.append(f" · {r.repo_name}: {r.repo_url} ({r.default_branch})") + agent_reply = '\n'.join(lines) elif intent_type == 'skill_list': skills_dir = ctx.get('skills_dir', '') if not skills_dir: