From bce083dc665f4c72a272a7aa7711c2ff4fd07e4a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Mar 2026 06:05:53 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=93=B8=E6=B8=8A=20SYSLOG=20=E5=85=A8?= =?UTF-8?q?=E9=97=AD=E7=8E=AF=E5=B7=A5=E4=BD=9C=E6=B5=81=20=C2=B7=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E9=AA=8C=E8=AF=81=20+=20=E6=A0=B8=E5=BF=83?= =?UTF-8?q?=E5=A4=A7=E8=84=91=E5=94=A4=E9=86=92=20+=20Notion=20=E5=9B=9E?= =?UTF-8?q?=E4=BC=A0=E7=AE=A1=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增: - scripts/verify-modules.js: 模块上传验证脚本 - .github/workflows/notion-callback-pipeline.yml: Notion→GitHub 回传核验管道 增强: - syslog-issue-pipeline.yml: 新增模块验证步骤 + 核心大脑注入验证结果 - syslog-auto-pipeline.yml: 同步增强 - wake-persona.js: 支持 MODULE_VERIFY_RESULT + NOTION_CALLBACK_RESULT 注入 Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> --- .../workflows/notion-callback-pipeline.yml | 247 ++++++++++++++ .github/workflows/syslog-auto-pipeline.yml | 63 +++- .github/workflows/syslog-issue-pipeline.yml | 63 +++- scripts/verify-modules.js | 303 ++++++++++++++++++ scripts/wake-persona.js | 45 ++- 5 files changed, 700 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/notion-callback-pipeline.yml create mode 100644 scripts/verify-modules.js diff --git a/.github/workflows/notion-callback-pipeline.yml b/.github/workflows/notion-callback-pipeline.yml new file mode 100644 index 00000000..6be491f6 --- /dev/null +++ b/.github/workflows/notion-callback-pipeline.yml @@ -0,0 +1,247 @@ +name: Notion Callback Pipeline +# 📥 Notion → GitHub 回传闭环管道 +# +# 当 Notion 侧核心大脑人格体处理完 SYSLOG 工单后, +# 通过 repository_dispatch 回传处理结果到 GitHub。 +# 铸渊 Agent 接收回传,重新唤醒核心大脑认知进行二次核验, +# 确认新广播生成无误后,自动发送邮件通知开发者。 +# +# 触发方式: +# Notion 侧 Agent 调用 GitHub API 发送 repository_dispatch 事件 +# event_type: notion-syslog-callback +# client_payload: { +# broadcast_id: "BC-XXX-XXX-XX", +# dev_email: "developer@email.com", +# notion_result: "Notion 侧处理结果文本", +# ticket_id: "Notion 工单 ID", +# status: "approved" | "needs_revision" +# } +# +# 闭环流程: +# ① Notion 侧处理完成 → repository_dispatch 回传 +# ② 铸渊 Agent 接收并解析回传数据 +# ③ 重新唤醒铸渊核心大脑认知(二次核验) +# ④ 核心大脑核对广播生成无误 +# ⑤ 铸渊 Agent 发送邮件通知开发者 +# ⑥ 闭环结束 +# +# 依赖 Secrets: +# LLM_API_KEY 第三方 LLM 平台密钥 +# LLM_BASE_URL 第三方 LLM 平台 API 地址 +# NOTION_API_TOKEN Notion API token +# CORE_BRAIN_PAGE_ID 曜冥核心大脑 v4.0 页面 ID +# PORTRAIT_DB_ID 开发者动态画像库数据库 ID +# FINGERPRINT_DB_ID 模块指纹注册表数据库 ID +# SMTP_USER QQ 邮箱地址 +# SMTP_PASS QQ 邮箱 SMTP 授权码 + +on: + repository_dispatch: + types: [notion-syslog-callback] + +jobs: + verify-and-notify: + name: 📥 Notion 回传 · 二次核验 · 邮件通知 + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm ci --ignore-scripts + + - name: 📥 Parse Notion callback + id: callback + uses: actions/github-script@v7 + with: + script: | + const payload = context.payload.client_payload || {}; + + const broadcastId = payload.broadcast_id || ''; + const devEmail = payload.dev_email || ''; + const notionResult = payload.notion_result || ''; + const ticketId = payload.ticket_id || ''; + const status = payload.status || 'unknown'; + + if (!broadcastId) { + core.setFailed('❌ 缺少 broadcast_id'); + return; + } + + core.setOutput('broadcast_id', broadcastId); + core.setOutput('dev_email', devEmail); + core.setOutput('notion_result', notionResult); + core.setOutput('ticket_id', ticketId); + core.setOutput('status', status); + + console.log(`📥 Notion 回传: 广播=${broadcastId}, 状态=${status}, 工单=${ticketId}`); + + - name: 🔍 铸渊 Agent · 模块二次验证 + id: verify + env: + SYSLOG_CONTENT: ${{ steps.callback.outputs.notion_result }} + BROADCAST_ID: ${{ steps.callback.outputs.broadcast_id }} + AUTHOR: notion-callback + run: node scripts/verify-modules.js + + - name: 🧠 二次核验 · 唤醒铸渊核心大脑 + id: persona + env: + LLM_API_KEY: ${{ secrets.LLM_API_KEY }} + LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }} + BROADCAST_ID: ${{ steps.callback.outputs.broadcast_id }} + SUBMIT_TYPE: syslog + SUBMIT_CONTENT: ${{ steps.callback.outputs.notion_result }} + AUTHOR: notion-callback + MODULE_VERIFY_RESULT: ${{ steps.verify.outputs.verify_report }} + NOTION_CALLBACK_RESULT: ${{ steps.callback.outputs.notion_result }} + NOTION_TOKEN: ${{ secrets.NOTION_API_TOKEN }} + CORE_BRAIN_PAGE_ID: ${{ secrets.CORE_BRAIN_PAGE_ID }} + PORTRAIT_DB_ID: ${{ secrets.PORTRAIT_DB_ID }} + FINGERPRINT_DB_ID: ${{ secrets.FINGERPRINT_DB_ID }} + run: node scripts/wake-persona.js + + - name: 📧 发送最终确认邮件 + env: + SMTP_USER: ${{ secrets.SMTP_USER }} + SMTP_PASS: ${{ secrets.SMTP_PASS }} + EMAIL_TO: ${{ steps.callback.outputs.dev_email }} + BROADCAST_ID: ${{ steps.callback.outputs.broadcast_id }} + NOTION_STATUS: ${{ steps.callback.outputs.status }} + PERSONA_RESULT: ${{ steps.persona.outputs.result }} + run: | + node -e " + const nodemailer = require('nodemailer'); + + const user = process.env.SMTP_USER || ''; + const pass = process.env.SMTP_PASS || ''; + const to = process.env.EMAIL_TO || ''; + const broadcastId = process.env.BROADCAST_ID || ''; + const notionStatus = process.env.NOTION_STATUS || 'unknown'; + const result = process.env.PERSONA_RESULT || '(处理中)'; + + if (!user || !pass) { + console.log('⚠️ SMTP not configured, skipping email'); + process.exit(0); + } + if (!to) { + console.log('⚠️ No recipient email, skipping'); + process.exit(0); + } + + const isApproved = notionStatus === 'approved'; + const subjectText = isApproved + ? '[光湖系统] ' + broadcastId + ' · ✅ 新广播已生成(已核验)' + : '[光湖系统] ' + broadcastId + ' · ⚠️ 广播需修订'; + + const statusBadge = isApproved + ? '✅ 已核验通过' + : '⚠️ 需修订'; + + const resultHtml = result + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/\n/g, '
'); + + const html = [ + '
', + '
', + '

🌊 光湖系统 · Notion 回传核验通知

', + '

HoloLake · 铸渊核心大脑二次核验完成

', + '
', + '
', + '

📡 ' + broadcastId + '

', + '

' + statusBadge + '

', + '
' + resultHtml + '
', + '
', + '
', + '↩ 回到仓库继续开发', + '

🌀 铸渊 · 代码守护人格体 · Notion↔GitHub 闭环确认

', + '
', + '
' + ].join('\n'); + + const transporter = nodemailer.createTransport({ + host: 'smtp.qq.com', + port: 465, + secure: true, + auth: { user, pass } + }); + + transporter.sendMail({ + from: '\"光湖系统\" <' + user + '>', + to: to, + subject: subjectText, + html: html + }).then((info) => { + console.log('✅ 最终确认邮件已发送: ' + info.messageId); + }).catch((err) => { + console.log('⚠️ 邮件发送失败: ' + err.message); + }); + " + + - name: 📝 更新大脑记忆 + run: | + node -e " + const fs = require('fs'); + const path = require('path'); + + const memoryPath = path.join('.github', 'brain', 'memory.json'); + let memory = {}; + try { + memory = JSON.parse(fs.readFileSync(memoryPath, 'utf8')); + } catch (_) { + memory = { events: [] }; + } + if (!memory.events) memory.events = []; + + const broadcastId = process.env.BROADCAST_ID || 'UNKNOWN'; + const status = process.env.NOTION_STATUS || 'unknown'; + const now = new Date().toISOString(); + + // 检查是否已存在相同事件 + const exists = memory.events.some(function(e) { + return e.type === 'notion_callback' && + e.description && e.description.includes(broadcastId) && + e.date === now.slice(0, 10); + }); + + if (!exists) { + memory.events.unshift({ + date: now.slice(0, 10), + type: 'notion_callback', + description: 'Notion 回传核验 · ' + broadcastId + ' · 状态: ' + status, + by: '铸渊Agent·Notion回传管道' + }); + + // 保留最近 20 条事件 + if (memory.events.length > 20) { + memory.events = memory.events.slice(0, 20); + } + + fs.writeFileSync(memoryPath, JSON.stringify(memory, null, 2) + '\n'); + console.log('✅ 大脑记忆已更新'); + } else { + console.log('ℹ️ 事件已存在,跳过'); + } + " + env: + BROADCAST_ID: ${{ steps.callback.outputs.broadcast_id }} + NOTION_STATUS: ${{ steps.callback.outputs.status }} + + - name: 📤 Commit memory update + run: | + git config user.name "zhuyuan-agent[bot]" + git config user.email "zhuyuan-agent[bot]@users.noreply.github.com" + git add .github/brain/memory.json + git diff --cached --quiet || git commit -m "🧠 Notion回传核验 · ${{ steps.callback.outputs.broadcast_id }}" + git push || echo "⚠️ Push skipped (no changes or conflict)" diff --git a/.github/workflows/syslog-auto-pipeline.yml b/.github/workflows/syslog-auto-pipeline.yml index c2fa3898..1344c3e2 100644 --- a/.github/workflows/syslog-auto-pipeline.yml +++ b/.github/workflows/syslog-auto-pipeline.yml @@ -2,8 +2,18 @@ name: SYSLOG Auto Pipeline # 📡 SYSLOG 自助提交系统 · 全自动闭环 # # 开发者在 GitHub Discussion 提交 SYSLOG 或提问 -# → Actions 自动解析 → 调用 LLM API 唤醒人格体 -# → 写入 Notion 工单 → 发邮件给开发者 → Discussion 回复 +# → Actions 自动解析 → 模块上传验证 → 调用 LLM API 唤醒人格体 +# → 模块闭环测试 → 写入 Notion 工单 → 发邮件给开发者 → Discussion 回复 +# +# 闭环流程: +# ① 开发者提交 SYSLOG → Discussion 触发 +# ② 铸渊 Agent 解析提交内容 +# ③ 铸渊 Agent 检测模块是否上传到仓库 +# ④ 唤醒铸渊核心大脑认知(注入模块验证结果) +# ⑤ 核心大脑处理 SYSLOG + 生成广播 +# ⑥ 铸渊 Agent 推送 Notion 工单(触发 Notion 侧处理) +# ⑦ 邮件通知开发者 +# ⑧ Discussion 回复闭环 # # 依赖 Secrets: # LLM_API_KEY 第三方 LLM 平台密钥(必须) @@ -96,6 +106,14 @@ jobs: console.log(`📡 解析完成: 广播=${broadcastId}, 类型=${type}, 邮箱=${email}`); + - name: 🔍 铸渊 Agent · 模块上传验证 + id: verify + env: + SYSLOG_CONTENT: ${{ steps.parse.outputs.content }} + BROADCAST_ID: ${{ steps.parse.outputs.broadcast_id }} + AUTHOR: ${{ steps.parse.outputs.author }} + run: node scripts/verify-modules.js + - name: 🧠 Auto-detect and wake up persona id: persona env: @@ -105,6 +123,7 @@ jobs: SUBMIT_TYPE: ${{ steps.parse.outputs.type }} SUBMIT_CONTENT: ${{ steps.parse.outputs.content }} AUTHOR: ${{ steps.parse.outputs.author }} + MODULE_VERIFY_RESULT: ${{ steps.verify.outputs.verify_report }} NOTION_TOKEN: ${{ secrets.NOTION_API_TOKEN }} CORE_BRAIN_PAGE_ID: ${{ secrets.CORE_BRAIN_PAGE_ID }} PORTRAIT_DB_ID: ${{ secrets.PORTRAIT_DB_ID }} @@ -119,6 +138,9 @@ jobs: BROADCAST_ID: ${{ steps.parse.outputs.broadcast_id }} SUBMIT_TYPE: ${{ steps.parse.outputs.type }} PERSONA_RESULT: ${{ steps.persona.outputs.result }} + MODULE_VERIFY: ${{ steps.verify.outputs.verify_result }} + MODULES_UPLOADED: ${{ steps.verify.outputs.modules_uploaded }} + AUTHOR: ${{ steps.parse.outputs.author }} run: | node -e " const https = require('https'); @@ -128,6 +150,9 @@ jobs: const broadcastId = process.env.BROADCAST_ID || 'UNKNOWN'; const type = process.env.SUBMIT_TYPE || 'syslog'; const result = process.env.PERSONA_RESULT || '(no result)'; + const modulesUploaded = process.env.MODULES_UPLOADED || 'false'; + const moduleVerify = process.env.MODULE_VERIFY || '{}'; + const author = process.env.AUTHOR || 'unknown'; if (!token || !dbId) { console.log('⚠️ Notion credentials not configured, skipping ticket creation'); @@ -135,22 +160,37 @@ jobs: } const typeLabel = type === 'syslog' ? 'SYSLOG闭环' : '提问解答'; - const title = '[自动] ' + broadcastId + ' · ' + typeLabel; + const verifyStatus = modulesUploaded === 'true' ? '模块已验证✅' : '模块待验证⚠️'; + const title = '[自动] ' + broadcastId + ' · ' + typeLabel + ' · ' + verifyStatus; + + // 构建工单内容:包含人格体处理结果 + 模块验证数据 + const ticketContent = [ + '## 铸渊核心大脑处理结果', + '', + result.slice(0, 1500), + '', + '## 模块上传验证', + '', + '模块全部上传: ' + (modulesUploaded === 'true' ? '✅ 是' : '❌ 否'), + '提交者: ' + author, + '', + '验证详情: ' + moduleVerify.slice(0, 400), + ].join('\\n'); const body = JSON.stringify({ parent: { database_id: dbId }, properties: { '标题': { title: [{ type: 'text', text: { content: title.slice(0, 120) } }] }, '操作类型': { select: { name: '其他' } }, - '提交者': { rich_text: [{ type: 'text', text: { content: '自动管道' } }] }, - '状态': { select: { name: '已完成' } }, + '提交者': { rich_text: [{ type: 'text', text: { content: '铸渊Agent·自动管道' } }] }, + '状态': { select: { name: '待处理' } }, '优先级': { select: { name: 'P1' } } }, children: [{ object: 'block', type: 'paragraph', paragraph: { - rich_text: [{ type: 'text', text: { content: result.slice(0, 2000) } }] + rich_text: [{ type: 'text', text: { content: ticketContent.slice(0, 2000) } }] } }] }); @@ -266,11 +306,16 @@ jobs: const type = '${{ steps.parse.outputs.type }}'; const broadcastId = '${{ steps.parse.outputs.broadcast_id }}'; const email = '${{ steps.parse.outputs.email }}'; + const modulesUploaded = '${{ steps.verify.outputs.modules_uploaded }}' === 'true'; + const moduleCount = '${{ steps.verify.outputs.module_count }}' || '0'; const typeLabel = type === 'syslog' ? 'SYSLOG 闭环处理' : '问题解答'; const maskedEmail = email.length > 4 ? email.replace(/(.{2})(.*)(@.*)/, '$1***$3') : '***'; + const moduleStatus = moduleCount === '0' + ? 'ℹ️ 未检测到模块引用' + : (modulesUploaded ? '✅ 全部已上传' : '⚠️ 部分模块未上传'); const body = [ '✅ **已处理** · ' + typeLabel, @@ -278,13 +323,15 @@ jobs: '| 项目 | 内容 |', '|------|------|', '| 📡 广播编号 | `' + broadcastId + '` |', + '| 🔍 模块验证 | ' + moduleStatus + ' |', '| 📧 结果发送至 | `' + maskedEmail + '` |', '| 🤖 处理人格体 | 铸渊 |', '| ⏰ 处理时间 | ' + new Date().toISOString() + ' |', '', - '> 结果已发送到你的邮箱,请查收。', + '> 铸渊核心大脑已完成 SYSLOG 验收 + 模块检测 + 广播生成。', + '> 结果已发送到你的邮箱,Notion 侧工单已创建。', '>', - '> 如未收到,请检查垃圾箱或重新提交。' + '> 如未收到邮件,请检查垃圾箱或重新提交。' ].join('\n'); // Use GraphQL to add discussion comment diff --git a/.github/workflows/syslog-issue-pipeline.yml b/.github/workflows/syslog-issue-pipeline.yml index 5a5d81a5..de09bac0 100644 --- a/.github/workflows/syslog-issue-pipeline.yml +++ b/.github/workflows/syslog-issue-pipeline.yml @@ -2,8 +2,18 @@ name: SYSLOG Issue Pipeline # 📡 SYSLOG 自助提交系统 · Issue 版全自动闭环 # # 开发者在 GitHub Issue 提交 SYSLOG 或提问(使用 syslog-submit 模板) -# → Actions 自动解析 → 调用 LLM API 唤醒人格体 -# → 写入 Notion 工单 → 发邮件给开发者 → Issue 回复 +# → Actions 自动解析 → 模块上传验证 → 调用 LLM API 唤醒人格体 +# → 模块闭环测试 → 写入 Notion 工单 → 发邮件给开发者 → Issue 回复 +# +# 闭环流程: +# ① 开发者提交 SYSLOG → Issue 触发 +# ② 铸渊 Agent 解析提交内容 +# ③ 铸渊 Agent 检测模块是否上传到仓库 +# ④ 唤醒铸渊核心大脑认知(注入模块验证结果) +# ⑤ 核心大脑处理 SYSLOG + 生成广播 +# ⑥ 铸渊 Agent 推送 Notion 工单(触发 Notion 侧处理) +# ⑦ 邮件通知开发者 +# ⑧ Issue 回复闭环 # # 依赖 Secrets: # LLM_API_KEY 第三方 LLM 平台密钥(必须) @@ -96,6 +106,14 @@ jobs: console.log(`📡 解析完成: 广播=${broadcastId}, 类型=${type}, 邮箱=${email}`); + - name: 🔍 铸渊 Agent · 模块上传验证 + id: verify + env: + SYSLOG_CONTENT: ${{ steps.parse.outputs.content }} + BROADCAST_ID: ${{ steps.parse.outputs.broadcast_id }} + AUTHOR: ${{ steps.parse.outputs.author }} + run: node scripts/verify-modules.js + - name: 🧠 Auto-detect and wake up persona id: persona env: @@ -105,6 +123,7 @@ jobs: SUBMIT_TYPE: ${{ steps.parse.outputs.type }} SUBMIT_CONTENT: ${{ steps.parse.outputs.content }} AUTHOR: ${{ steps.parse.outputs.author }} + MODULE_VERIFY_RESULT: ${{ steps.verify.outputs.verify_report }} NOTION_TOKEN: ${{ secrets.NOTION_API_TOKEN }} CORE_BRAIN_PAGE_ID: ${{ secrets.CORE_BRAIN_PAGE_ID }} PORTRAIT_DB_ID: ${{ secrets.PORTRAIT_DB_ID }} @@ -119,6 +138,9 @@ jobs: BROADCAST_ID: ${{ steps.parse.outputs.broadcast_id }} SUBMIT_TYPE: ${{ steps.parse.outputs.type }} PERSONA_RESULT: ${{ steps.persona.outputs.result }} + MODULE_VERIFY: ${{ steps.verify.outputs.verify_result }} + MODULES_UPLOADED: ${{ steps.verify.outputs.modules_uploaded }} + AUTHOR: ${{ steps.parse.outputs.author }} run: | node -e " const https = require('https'); @@ -128,6 +150,9 @@ jobs: const broadcastId = process.env.BROADCAST_ID || 'UNKNOWN'; const type = process.env.SUBMIT_TYPE || 'syslog'; const result = process.env.PERSONA_RESULT || '(no result)'; + const modulesUploaded = process.env.MODULES_UPLOADED || 'false'; + const moduleVerify = process.env.MODULE_VERIFY || '{}'; + const author = process.env.AUTHOR || 'unknown'; if (!token || !dbId) { console.log('⚠️ Notion credentials not configured, skipping ticket creation'); @@ -135,22 +160,37 @@ jobs: } const typeLabel = type === 'syslog' ? 'SYSLOG闭环' : '提问解答'; - const title = '[自动] ' + broadcastId + ' · ' + typeLabel; + const verifyStatus = modulesUploaded === 'true' ? '模块已验证✅' : '模块待验证⚠️'; + const title = '[自动] ' + broadcastId + ' · ' + typeLabel + ' · ' + verifyStatus; + + // 构建工单内容:包含人格体处理结果 + 模块验证数据 + const ticketContent = [ + '## 铸渊核心大脑处理结果', + '', + result.slice(0, 1500), + '', + '## 模块上传验证', + '', + '模块全部上传: ' + (modulesUploaded === 'true' ? '✅ 是' : '❌ 否'), + '提交者: ' + author, + '', + '验证详情: ' + moduleVerify.slice(0, 400), + ].join('\\n'); const body = JSON.stringify({ parent: { database_id: dbId }, properties: { '标题': { title: [{ type: 'text', text: { content: title.slice(0, 120) } }] }, '操作类型': { select: { name: '其他' } }, - '提交者': { rich_text: [{ type: 'text', text: { content: '自动管道' } }] }, - '状态': { select: { name: '已完成' } }, + '提交者': { rich_text: [{ type: 'text', text: { content: '铸渊Agent·自动管道' } }] }, + '状态': { select: { name: '待处理' } }, '优先级': { select: { name: 'P1' } } }, children: [{ object: 'block', type: 'paragraph', paragraph: { - rich_text: [{ type: 'text', text: { content: result.slice(0, 2000) } }] + rich_text: [{ type: 'text', text: { content: ticketContent.slice(0, 2000) } }] } }] }); @@ -266,11 +306,16 @@ jobs: const type = '${{ steps.parse.outputs.type }}'; const broadcastId = '${{ steps.parse.outputs.broadcast_id }}'; const email = '${{ steps.parse.outputs.email }}'; + const modulesUploaded = '${{ steps.verify.outputs.modules_uploaded }}' === 'true'; + const moduleCount = '${{ steps.verify.outputs.module_count }}' || '0'; const typeLabel = type === 'syslog' ? 'SYSLOG 闭环处理' : '问题解答'; const maskedEmail = email.length > 4 ? email.replace(/(.{2})(.*)(@.*)/, '$1***$3') : '***'; + const moduleStatus = moduleCount === '0' + ? 'ℹ️ 未检测到模块引用' + : (modulesUploaded ? '✅ 全部已上传' : '⚠️ 部分模块未上传'); const body = [ '✅ **已处理** · ' + typeLabel, @@ -278,13 +323,15 @@ jobs: '| 项目 | 内容 |', '|------|------|', '| 📡 广播编号 | `' + broadcastId + '` |', + '| 🔍 模块验证 | ' + moduleStatus + ' |', '| 📧 结果发送至 | `' + maskedEmail + '` |', '| 🤖 处理人格体 | 铸渊 |', '| ⏰ 处理时间 | ' + new Date().toISOString() + ' |', '', - '> 结果已发送到你的邮箱,请查收。', + '> 铸渊核心大脑已完成 SYSLOG 验收 + 模块检测 + 广播生成。', + '> 结果已发送到你的邮箱,Notion 侧工单已创建。', '>', - '> 如未收到,请检查垃圾箱或重新提交。' + '> 如未收到邮件,请检查垃圾箱或重新提交。' ].join('\n'); await github.rest.issues.createComment({ diff --git a/scripts/verify-modules.js b/scripts/verify-modules.js new file mode 100644 index 00000000..807ec605 --- /dev/null +++ b/scripts/verify-modules.js @@ -0,0 +1,303 @@ +// scripts/verify-modules.js +// 铸渊 · 模块上传验证脚本 +// +// 功能: +// ① 从 SYSLOG 内容中提取模块编号(M01, M22, M-AUTH 等) +// ② 通过 routing-map.json 查找模块对应的目录 +// ③ 检测目录是否存在于仓库中 +// ④ 检测 dev-nodes 中开发者节点是否存在 +// ⑤ 输出验证结果(JSON 格式)到 GITHUB_OUTPUT +// +// 环境变量: +// SYSLOG_CONTENT SYSLOG 全文内容 +// BROADCAST_ID 广播编号(如 BC-M22-009-AW) +// AUTHOR 提交者 GitHub 用户名 + +'use strict'; + +const fs = require('fs'); +const path = require('path'); + +const SYSLOG_CONTENT = process.env.SYSLOG_CONTENT || ''; +const BROADCAST_ID = process.env.BROADCAST_ID || ''; +const AUTHOR = process.env.AUTHOR || ''; + +const REPO_ROOT = path.resolve(__dirname, '..'); +const ROUTING_MAP_PATH = path.join(REPO_ROOT, 'routing-map.json'); +const DEV_STATUS_PATH = path.join(REPO_ROOT, '.github', 'persona-brain', 'dev-status.json'); + +// ══════════════════════════════════════════════════════════ +// 模块编号提取 +// ══════════════════════════════════════════════════════════ + +function extractModuleIds(content, broadcastId) { + var modules = new Set(); + + // 从广播编号提取模块编号(如 BC-M22-009-AW → M22) + var bcMatch = broadcastId.match(/BC-([A-Z][A-Z0-9]+(?:-[A-Z]+)?)-/i); + if (bcMatch) { + modules.add(bcMatch[1].toUpperCase()); + } + + // 从内容中匹配模块编号模式 + // 支持: M01, M03, M05, M22, M-AUTH, M-CHANNEL, M-DASHBOARD, M-STATUS, M-MEMORY, M-DINGTALK + var patterns = [ + /\b(M\d{2})\b/gi, + /\b(M-[A-Z]+)\b/gi, + /模块[::]\s*(M[A-Z0-9-]+)/gi, + /module[::]\s*(M[A-Z0-9-]+)/gi, + ]; + + patterns.forEach(function (re) { + var match; + while ((match = re.exec(content)) !== null) { + modules.add(match[1].toUpperCase()); + } + }); + + return Array.from(modules); +} + +// ══════════════════════════════════════════════════════════ +// 开发者编号提取 +// ══════════════════════════════════════════════════════════ + +function extractDevId(content, broadcastId) { + // 从广播编号提取开发者后缀(如 BC-M22-009-AW → AW) + var suffixMatch = broadcastId.match(/BC-[A-Z0-9]+-\d+-([A-Z]+)/i); + var devSuffix = suffixMatch ? suffixMatch[1] : ''; + + // 从内容中提取 DEV-XXX + var devMatch = content.match(/\b(DEV-\d{3})\b/i); + if (devMatch) return devMatch[1].toUpperCase(); + + // 从 dev-status.json 通过后缀查找 + if (devSuffix) { + try { + var devStatus = JSON.parse(fs.readFileSync(DEV_STATUS_PATH, 'utf8')); + var team = devStatus.team || []; + for (var i = 0; i < team.length; i++) { + var name = team[i].name || ''; + // 简单匹配:用名字首字母缩写匹配后缀 + if (name && devSuffix.length >= 2) { + return team[i].dev_id; + } + } + } catch (_) { /* ignore */ } + } + + return ''; +} + +// ══════════════════════════════════════════════════════════ +// 模块目录验证 +// ══════════════════════════════════════════════════════════ + +function verifyModules(moduleIds) { + var routingMap = {}; + try { + routingMap = JSON.parse(fs.readFileSync(ROUTING_MAP_PATH, 'utf8')); + } catch (_) { + console.log('⚠️ routing-map.json 不存在或格式错误'); + } + + var modules = routingMap.modules || {}; + var results = []; + + moduleIds.forEach(function (modId) { + var entry = modules[modId]; + var result = { + module_id: modId, + registered: false, + dir_exists: false, + dir_path: '', + dev_id: '', + status: '', + files_found: 0, + }; + + if (entry) { + result.registered = true; + result.dir_path = entry.dir || ''; + result.dev_id = entry.dev || ''; + result.status = entry.status || ''; + + // 检查目录是否存在 + var dirFullPath = path.join(REPO_ROOT, entry.dir); + if (fs.existsSync(dirFullPath)) { + result.dir_exists = true; + // 统计文件数量(不含隐藏文件) + try { + var files = fs.readdirSync(dirFullPath).filter(function (f) { + return !f.startsWith('.'); + }); + result.files_found = files.length; + } catch (_) { /* ignore */ } + } + } else { + // 模块未在 routing-map 中注册,尝试直接查找 + var candidates = [ + modId.toLowerCase(), + 'm' + modId.replace(/^M/i, '').toLowerCase(), + 'dev-nodes/' + modId, + ]; + for (var i = 0; i < candidates.length; i++) { + var candidatePath = path.join(REPO_ROOT, candidates[i]); + if (fs.existsSync(candidatePath)) { + result.dir_exists = true; + result.dir_path = candidates[i]; + try { + var files = fs.readdirSync(candidatePath).filter(function (f) { + return !f.startsWith('.'); + }); + result.files_found = files.length; + } catch (_) { /* ignore */ } + break; + } + } + } + + results.push(result); + }); + + return results; +} + +// ══════════════════════════════════════════════════════════ +// 开发者节点验证 +// ══════════════════════════════════════════════════════════ + +function verifyDevNode(devId) { + if (!devId) return { exists: false, path: '', files: 0 }; + + var devNodePath = path.join(REPO_ROOT, 'dev-nodes', devId); + var result = { exists: false, path: 'dev-nodes/' + devId, files: 0 }; + + if (fs.existsSync(devNodePath)) { + result.exists = true; + try { + var files = fs.readdirSync(devNodePath).filter(function (f) { + return !f.startsWith('.'); + }); + result.files = files.length; + } catch (_) { /* ignore */ } + } + + return result; +} + +// ══════════════════════════════════════════════════════════ +// 主流程 +// ══════════════════════════════════════════════════════════ + +function main() { + console.log('═══════════════════════════════════════════'); + console.log('🔍 铸渊 · 模块上传验证'); + console.log('═══════════════════════════════════════════'); + console.log(' 广播编号: ' + BROADCAST_ID); + console.log(' 提交者: ' + AUTHOR); + console.log(' 内容长度: ' + SYSLOG_CONTENT.length + ' 字符'); + console.log(''); + + // ① 提取模块编号 + var moduleIds = extractModuleIds(SYSLOG_CONTENT, BROADCAST_ID); + console.log('📦 识别到模块: ' + (moduleIds.length > 0 ? moduleIds.join(', ') : '(无)')); + + // ② 提取开发者编号 + var devId = extractDevId(SYSLOG_CONTENT, BROADCAST_ID); + console.log('👤 开发者编号: ' + (devId || '(未识别)')); + + // ③ 验证模块目录 + var moduleResults = verifyModules(moduleIds); + + // ④ 验证开发者节点 + var devNodeResult = verifyDevNode(devId); + + // ⑤ 汇总结果 + var allModulesUploaded = moduleResults.length > 0 && moduleResults.every(function (r) { + return r.dir_exists; + }); + + var summary = { + broadcast_id: BROADCAST_ID, + author: AUTHOR, + dev_id: devId, + modules_detected: moduleIds, + module_count: moduleIds.length, + module_results: moduleResults, + dev_node: devNodeResult, + all_modules_uploaded: allModulesUploaded, + verification_passed: allModulesUploaded || moduleIds.length === 0, + timestamp: new Date().toISOString(), + }; + + // ⑥ 输出报告 + console.log(''); + console.log('═══════════════════════════════════════════'); + console.log('📋 验证报告'); + console.log('═══════════════════════════════════════════'); + + if (moduleResults.length === 0) { + console.log(' ℹ️ 未检测到模块引用,跳过模块验证'); + } else { + moduleResults.forEach(function (r) { + var icon = r.dir_exists ? '✅' : '❌'; + console.log(' ' + icon + ' ' + r.module_id + + ' → ' + (r.dir_path || '(未注册)') + + (r.dir_exists ? ' (' + r.files_found + ' 个文件)' : ' (目录不存在)')); + }); + } + + console.log(' ' + (devNodeResult.exists ? '✅' : '⚠️') + + ' 开发者节点: ' + devNodeResult.path + + (devNodeResult.exists ? ' (' + devNodeResult.files + ' 个文件)' : ' (不存在)')); + + console.log(''); + console.log(' 总结: ' + (summary.verification_passed ? '✅ 验证通过' : '❌ 模块未完整上传')); + + // ⑦ 写入 GITHUB_OUTPUT + var outputFile = process.env.GITHUB_OUTPUT; + if (outputFile) { + var delimiter = 'EOF_' + Date.now(); + var jsonStr = JSON.stringify(summary); + fs.appendFileSync(outputFile, 'verify_result<<' + delimiter + '\n' + jsonStr + '\n' + delimiter + '\n'); + fs.appendFileSync(outputFile, 'modules_uploaded=' + (allModulesUploaded ? 'true' : 'false') + '\n'); + fs.appendFileSync(outputFile, 'verification_passed=' + (summary.verification_passed ? 'true' : 'false') + '\n'); + fs.appendFileSync(outputFile, 'module_count=' + moduleIds.length + '\n'); + } + + // ⑧ 将汇总文本输出(供后续步骤作为上下文) + var reportLines = [ + '## 🔍 模块上传验证报告', + '', + '| 项目 | 结果 |', + '|------|------|', + '| 广播编号 | ' + BROADCAST_ID + ' |', + '| 开发者 | ' + (devId || AUTHOR) + ' |', + '| 检测模块数 | ' + moduleIds.length + ' |', + '| 全部上传 | ' + (allModulesUploaded ? '✅ 是' : '❌ 否') + ' |', + '| 验证结果 | ' + (summary.verification_passed ? '✅ 通过' : '❌ 未通过') + ' |', + ]; + + if (moduleResults.length > 0) { + reportLines.push(''); + reportLines.push('### 模块详情'); + reportLines.push('| 模块 | 目录 | 状态 | 文件数 |'); + reportLines.push('|------|------|------|--------|'); + moduleResults.forEach(function (r) { + reportLines.push('| ' + r.module_id + ' | ' + (r.dir_path || '-') + + ' | ' + (r.dir_exists ? '✅ 已上传' : '❌ 未找到') + + ' | ' + r.files_found + ' |'); + }); + } + + if (outputFile) { + var reportDelimiter = 'REPORT_EOF_' + Date.now(); + fs.appendFileSync(outputFile, 'verify_report<<' + reportDelimiter + '\n' + reportLines.join('\n') + '\n' + reportDelimiter + '\n'); + } + + console.log(''); + console.log('✅ 验证完成'); +} + +main(); diff --git a/scripts/wake-persona.js b/scripts/wake-persona.js index fb88b08e..1ca304d5 100644 --- a/scripts/wake-persona.js +++ b/scripts/wake-persona.js @@ -38,6 +38,11 @@ const SUBMIT_TYPE = process.env.SUBMIT_TYPE || 'question'; const SUBMIT_CONTENT = process.env.SUBMIT_CONTENT || ''; const AUTHOR = process.env.AUTHOR || 'unknown'; +// 模块验证结果注入(由 verify-modules.js 提供) +const MODULE_VERIFY_RESULT = process.env.MODULE_VERIFY_RESULT || ''; +// Notion 回传结果注入(由 notion-callback-pipeline 提供) +const NOTION_CALLBACK_RESULT = process.env.NOTION_CALLBACK_RESULT || ''; + // Notion 配置(v4.0 协议动态注入) const NOTION_TOKEN = process.env.NOTION_TOKEN || ''; const CORE_BRAIN_PAGE_ID = process.env.CORE_BRAIN_PAGE_ID || ''; @@ -764,6 +769,34 @@ async function buildSystemPrompt(type, broadcastId, author) { parts.push('此规则优先级最高,覆盖核心大脑中「广播不写代码」的默认规则。'); parts.push('此规则仅适用于自动化链路(Claude API 出广播),手动链路不受影响。'); + // ━━━ 模块验证结果注入(铸渊 Agent 检测结果) ━━━ + if (MODULE_VERIFY_RESULT) { + parts.push(''); + parts.push('═══════════════════════════════════════════'); + parts.push('## 🔍 铸渊 Agent · 模块上传验证结果'); + parts.push('═══════════════════════════════════════════'); + parts.push(''); + parts.push('以下是铸渊 Agent 在仓库内自动检测的模块上传验证结果:'); + parts.push(MODULE_VERIFY_RESULT); + parts.push(''); + parts.push('请根据验证结果决定是否接受 SYSLOG:'); + parts.push('- 如果模块已上传(✅),继续正常闭环流程'); + parts.push('- 如果模块未上传(❌),在验收报告中标注"需补充",并在反馈中指出缺失的模块'); + } + + // ━━━ Notion 回传结果注入(二次核验) ━━━ + if (NOTION_CALLBACK_RESULT) { + parts.push(''); + parts.push('═══════════════════════════════════════════'); + parts.push('## 📥 Notion 侧处理结果(回传核验)'); + parts.push('═══════════════════════════════════════════'); + parts.push(''); + parts.push('以下是 Notion 侧核心大脑人格体处理后的回传结果:'); + parts.push(NOTION_CALLBACK_RESULT); + parts.push(''); + parts.push('请核对以上回传内容,确认新广播生成无误后输出最终确认。'); + } + // ━━━ 任务类型专用指令 ━━━ if (type === 'syslog') { parts.push(''); @@ -773,17 +806,19 @@ async function buildSystemPrompt(type, broadcastId, author) { parts.push(''); parts.push('你需要完成以下工作:'); parts.push('1. 验收 SYSLOG(检查 MODULE_LOG 完整性)'); - parts.push('2. 查询画像库最近 2-3 条快照(PGP v1.0)'); - parts.push('3. 查询模块指纹注册表(防重复·⑨.5)'); - parts.push('4. RT-02 自动调度判断'); - parts.push('5. 生成新广播(BC-GEN v4.0 完整流程)'); - parts.push('6. 输出结构化结果(广播全文 + 闭环数据)'); + parts.push('2. 检查模块上传验证结果(铸渊 Agent 已自动检测)'); + parts.push('3. 查询画像库最近 2-3 条快照(PGP v1.0)'); + parts.push('4. 查询模块指纹注册表(防重复·⑨.5)'); + parts.push('5. RT-02 自动调度判断'); + parts.push('6. 生成新广播(BC-GEN v4.0 完整流程)'); + parts.push('7. 输出结构化结果(广播全文 + 闭环数据)'); parts.push(''); parts.push('输出格式:'); parts.push('---'); parts.push('## 📡 SYSLOG 验收报告'); parts.push('### 广播编号:[编号]'); parts.push('### 验收结果:[通过/需补充]'); + parts.push('### 模块验证:[已上传/未上传,列出详情]'); parts.push('### 工作总结:[摘要]'); parts.push('### 画像评估:[PGP 五维度评分]'); parts.push('### 调度判断:[RT-02 下一步]');