This commit is contained in:
Awen 2026-03-13 13:01:40 +08:00
commit ebeee8c424
9 changed files with 1352 additions and 30 deletions

View File

@ -0,0 +1,51 @@
title: "BC-XXX-XXXSYSLOG"
labels: []
body:
- type: markdown
attributes:
value: |
## 📡 SYSLOG 自助提交 / 广播提问
> 做完了?把日志粘贴进去,填上邮箱,点提交。新广播会发到你邮箱里。
>
> 有问题?把问题粘贴进去,填上邮箱,点提交。解答会发到你邮箱里。
**标题格式**`BC-XXX-XXXSYSLOG` 或 `BC-XXX-XXX提问`
- type: input
id: broadcast_id
attributes:
label: "广播编号"
description: "写上你当前广播的编号,例如 BC-M22-009-AW"
placeholder: "BC-M22-009-AW"
validations:
required: true
- type: dropdown
id: submit_type
attributes:
label: "类型"
description: "选择提交类型"
options:
- SYSLOG
- 提问
validations:
required: true
- type: input
id: email
attributes:
label: "你的邮箱"
description: "用于接收新广播或问题解答"
placeholder: "your@email.com"
validations:
required: true
- type: textarea
id: content
attributes:
label: "内容"
description: "粘贴你的 SYSLOG 全文 或 问题描述"
placeholder: "在这里粘贴你的 SYSLOG 或问题..."
validations:
required: true

View File

@ -1,7 +1,7 @@
{
"version": "1.0",
"description": "冰朔主控问题索引库 — 记录已知问题、根因与排查路由",
"updated_at": "2026-03-13T02:05:55.611Z",
"updated_at": "2026-03-13T04:49:20.482Z",
"issues": [
{
"id": "BS-001",

View File

@ -1,7 +1,7 @@
# 冰朔主控神经系统 · 核心主控大脑 v1.0
> 本文件为冰朔主控神经系统的总控脑文件。
> 最后编译时间2026-03-13T02:05:55.612Z
> 最后编译时间2026-03-13T04:49:20.482Z
---
@ -56,7 +56,7 @@
### 仓库统计
- 功能模块10 个
- Workflow35
- Workflow36
---
@ -85,7 +85,7 @@
> 本区块由 master-brain-compiler 自动编译。
- **编译时间**2026-03-13T02:05:55.612Z
- **编译时间**2026-03-13T04:49:20.482Z
- **脑文件规则版本**v3.0
- **脑文件完整性**:✅ 完整
@ -107,7 +107,7 @@
|--------|------|------|
| 🟡 brain_consistency | yellow | 主仓库脑文件完整,但与 persona-studio 脑文件的同步状态待验证 |
| 🟢 deployment_health | green | deploy-to-server.yml 与 deploy-pages.yml 均存在 |
| 🟢 workflow_health | green | 35 个 workflow 已注册 |
| 🟢 workflow_health | green | 36 个 workflow 已注册 |
| 🟡 routing_health | yellow | HLI 接口覆盖率 33.3%7/21 |
| 🟢 docs_entry_health | green | docs/index.html 存在 |
| 🟡 persona_studio_health | yellow | 前后端结构存在,端到端对话链路待验证 |

View File

@ -1,7 +1,7 @@
{
"version": "1.0",
"description": "冰朔主控系统健康状态",
"updated_at": "2026-03-13T02:05:55.611Z",
"updated_at": "2026-03-13T04:49:20.482Z",
"health": {
"brain_consistency": {
"status": "yellow",
@ -13,7 +13,7 @@
},
"workflow_health": {
"status": "green",
"detail": "35 个 workflow 已注册"
"detail": "36 个 workflow 已注册"
},
"routing_health": {
"status": "yellow",

View File

@ -1,20 +1,20 @@
{
"description": "铸渊图书馆目录 · Library Catalog for 铸渊 (Zhùyuān)",
"version": "2.0",
"generated_at": "2026-03-13T02:07:22.787Z",
"generated_at": "2026-03-13T04:49:33.903Z",
"generated_by": "scripts/generate-repo-map.js",
"repo": "qinfendebingshuo/guanghulab",
"stats": {
"zones": 13,
"total_modules": 10,
"total_workflows": 35,
"total_scripts": 32,
"total_workflows": 36,
"total_scripts": 33,
"total_dev_nodes": 8,
"hli_interfaces": 21,
"hli_implemented": 7,
"hli_coverage_pct": "33%",
"last_ci_run": "2026-03-05T16:07:24.070Z",
"memory_last_updated": "2026-03-12T08:55:54.205Z"
"memory_last_updated": "2026-03-13T03:31:06.282Z"
},
"zones": [
{
@ -362,6 +362,13 @@
"manual"
]
},
{
"file": "syslog-auto-pipeline.yml",
"name": "SYSLOG Auto Pipeline",
"triggers": [
"unknown"
]
},
{
"file": "syslog-pipeline.yml",
"name": "铸渊 · SYSLOG Pipeline (A/D/E)",
@ -435,7 +442,7 @@
]
}
],
"item_count": 35
"item_count": 36
},
{
"zone_id": "SCRIPTS",
@ -536,6 +543,9 @@
{
"file": "update-readme-bulletin.js"
},
{
"file": "wake-persona.js"
},
{
"file": "zhuyuan-daily-agent.js"
},
@ -549,7 +559,7 @@
"file": "zhuyuan-module-protocol.js"
}
],
"item_count": 32
"item_count": 33
},
{
"zone_id": "SRC",
@ -1356,6 +1366,9 @@
"sync-persona-studio": [
"WORKFLOWS::sync-persona-studio.yml"
],
"syslog-auto-pipeline": [
"WORKFLOWS::syslog-auto-pipeline.yml"
],
"syslog-pipeline": [
"WORKFLOWS::syslog-pipeline.yml"
],
@ -1466,6 +1479,9 @@
"update-memory": [
"SCRIPTS::update-memory.js"
],
"wake-persona": [
"SCRIPTS::wake-persona.js"
],
"zhuyuan-module-protocol": [
"SCRIPTS::zhuyuan-module-protocol.js"
],

View File

@ -1,5 +1,5 @@
# 铸渊图书馆快照 · Repo Snapshot
> 生成于 2026-03-13 10:07 CST · 每次 push 自动更新 · 铸渊唤醒时优先读取此文件
> 生成于 2026-03-13 12:49 CST · 每次 push 自动更新 · 铸渊唤醒时优先读取此文件
---
@ -9,11 +9,11 @@
|------|------|
| 区域总数 | 13 个区域 |
| 功能模块 | 10 个 (m01~m18) |
| 工作流 | 35 个 GitHub Actions |
| 脚本 | 32 个执行脚本 |
| 工作流 | 36 个 GitHub Actions |
| 脚本 | 33 个执行脚本 |
| 开发者节点 | 8 人 |
| HLI 接口覆盖率 | 7/21 (33%) |
| 快照生成时间 | 2026-03-13 10:07 CST |
| 快照生成时间 | 2026-03-13 12:49 CST |
---
@ -30,12 +30,12 @@
**关键词**: persona · identity · dev-status · 人格 · 开发者状态
### ⚡ 自动化工作流WORKFLOWS
**路径**: `.github/workflows` · **数量**: 35
**路径**: `.github/workflows` · **数量**: 36
**描述**: 所有 GitHub Actions 工作流定义
**关键词**: workflow · actions · ci · automation · 工作流 · 自动化
### 🔧 执行脚本库SCRIPTS
**路径**: `scripts` · **数量**: 32
**路径**: `scripts` · **数量**: 33
**描述**: 铸渊所有执行手脚 · 自动化脚本
**关键词**: script · node · js · 脚本 · 执行 · runner
@ -116,6 +116,7 @@
| `staging-preview.yml` | "🔍 铸渊预演部署 (Staging Preview)" | pull_request, manual |
| `sync-login-entry.yml` | 铸渊 · Sync Login Entry · Notion → 飞书文档A | manual |
| `sync-persona-studio.yml` | 🔄 铸渊跨仓库同步 · persona-studio | push, manual |
| `syslog-auto-pipeline.yml` | SYSLOG Auto Pipeline | unknown |
| `syslog-pipeline.yml` | 铸渊 · SYSLOG Pipeline (A/D/E) | push, manual |
| `test-notion-bridge.yml` | "🧪 Notion Bridge Connectivity Test" | push, manual |
| `update-readme-bulletin.yml` | 📢 更新系统公告区 | push, schedule(0 1 * * *), manual |
@ -158,6 +159,7 @@
- `scripts/update-brain.js`
- `scripts/update-memory.js`
- `scripts/update-readme-bulletin.js`
- `scripts/wake-persona.js`
- `scripts/zhuyuan-daily-agent.js`
- `scripts/zhuyuan-daily-selfcheck.js`
- `scripts/zhuyuan-issue-reply.js`

View File

@ -0,0 +1,366 @@
name: SYSLOG Auto Pipeline
# 📡 SYSLOG 自助提交系统 · 全自动闭环
#
# 开发者在 GitHub Discussion 提交 SYSLOG 或提问
# → Actions 自动解析 → 调用 LLM API 唤醒人格体
# → 写入 Notion 工单 → 发邮件给开发者 → Discussion 回复
#
# 依赖 Secrets
# LLM_API_KEY 第三方 LLM 平台密钥(必须)
# LLM_BASE_URL 第三方 LLM 平台 API 地址(必须,如 https://api.xxx.com/v1
# NOTION_API_TOKEN Notion API token
# NOTION_TICKET_DB_ID 霜砚工单数据库 ID
# CORE_BRAIN_PAGE_ID 曜冥核心大脑 v4.0 页面 IDv4.0 协议动态注入)
# PORTRAIT_DB_ID 开发者动态画像库数据库 IDv4.0 协议动态注入)
# FINGERPRINT_DB_ID 模块指纹注册表数据库 IDv4.0 协议动态注入)
# SMTP_USER QQ 邮箱地址
# SMTP_PASS QQ 邮箱 SMTP 授权码
on:
discussion:
types: [created]
jobs:
process:
name: 📡 处理 SYSLOG 提交 / 广播提问
runs-on: ubuntu-latest
if: contains(github.event.discussion.category.name, 'SYSLOG')
permissions:
contents: write
discussions: 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 submission
id: parse
uses: actions/github-script@v7
with:
script: |
const body = context.payload.discussion.body || '';
const title = context.payload.discussion.title || '';
// Parse structured fields from discussion body
function extractField(text, label) {
// Match form field format: ### Label\n\nValue
const regex = new RegExp('###\\s*' + label + '\\s*\\n+([^\\n#]+)', 'i');
const match = text.match(regex);
return match ? match[1].trim() : '';
}
const broadcastId = extractField(body, '广播编号') || '';
const submitType = extractField(body, '类型') || '';
const email = extractField(body, '你的邮箱') || '';
// Extract content (everything after "### 内容")
const contentMatch = body.match(/###\s*内容\s*\n+([\s\S]*?)$/i);
const content = contentMatch ? contentMatch[1].trim() : '';
// Determine type from title or body
let type = 'question'; // default
if (submitType.includes('SYSLOG') || title.includes('SYSLOG')) {
type = 'syslog';
} else if (submitType.includes('提问') || title.includes('提问')) {
type = 'question';
}
// Validate
if (!broadcastId) {
core.setFailed('❌ 缺少广播编号,请在提交时填写广播编号');
return;
}
if (!email) {
core.setFailed('❌ 缺少邮箱,请在提交时填写你的邮箱');
return;
}
if (!content) {
core.setFailed('❌ 缺少内容,请粘贴你的 SYSLOG 或问题');
return;
}
core.setOutput('broadcast_id', broadcastId);
core.setOutput('type', type);
core.setOutput('email', email);
core.setOutput('content', content);
core.setOutput('discussion_number', context.payload.discussion.number);
core.setOutput('author', context.payload.discussion.user.login);
console.log(`📡 解析完成: 广播=${broadcastId}, 类型=${type}, 邮箱=${email}`);
- name: 🧠 Auto-detect and wake up persona
id: persona
env:
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }}
BROADCAST_ID: ${{ steps.parse.outputs.broadcast_id }}
SUBMIT_TYPE: ${{ steps.parse.outputs.type }}
SUBMIT_CONTENT: ${{ steps.parse.outputs.content }}
AUTHOR: ${{ steps.parse.outputs.author }}
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: 📋 Write to Notion ticket
if: ${{ secrets.NOTION_API_TOKEN }}
env:
NOTION_TOKEN: ${{ secrets.NOTION_API_TOKEN }}
NOTION_TICKET_DB_ID: ${{ secrets.NOTION_TICKET_DB_ID }}
BROADCAST_ID: ${{ steps.parse.outputs.broadcast_id }}
SUBMIT_TYPE: ${{ steps.parse.outputs.type }}
PERSONA_RESULT: ${{ steps.persona.outputs.result }}
run: |
node -e "
const https = require('https');
const token = process.env.NOTION_TOKEN;
const dbId = process.env.NOTION_TICKET_DB_ID;
const broadcastId = process.env.BROADCAST_ID || 'UNKNOWN';
const type = process.env.SUBMIT_TYPE || 'syslog';
const result = process.env.PERSONA_RESULT || '(no result)';
if (!token || !dbId) {
console.log('⚠️ Notion credentials not configured, skipping ticket creation');
process.exit(0);
}
const typeLabel = type === 'syslog' ? 'SYSLOG闭环' : '提问解答';
const title = '[自动] ' + broadcastId + ' · ' + typeLabel;
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: '已完成' } },
'优先级': { select: { name: 'P1' } }
},
children: [{
object: 'block',
type: 'paragraph',
paragraph: {
rich_text: [{ type: 'text', text: { content: result.slice(0, 2000) } }]
}
}]
});
const opts = {
hostname: 'api.notion.com',
port: 443,
path: '/v1/pages',
method: 'POST',
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json',
'Notion-Version': '2022-06-28',
'Content-Length': Buffer.byteLength(body)
}
};
const req = https.request(opts, (res) => {
let data = '';
res.on('data', (c) => data += c);
res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode < 300) {
console.log('✅ Notion 工单已创建');
} else {
console.log('⚠️ Notion 工单创建失败: ' + res.statusCode + ' ' + data);
}
});
});
req.on('error', (e) => console.log('⚠️ Notion 请求失败: ' + e.message));
req.write(body);
req.end();
"
- name: 📧 Send email to developer
env:
SMTP_USER: ${{ secrets.SMTP_USER }}
SMTP_PASS: ${{ secrets.SMTP_PASS }}
EMAIL_TO: ${{ steps.parse.outputs.email }}
BROADCAST_ID: ${{ steps.parse.outputs.broadcast_id }}
SUBMIT_TYPE: ${{ steps.parse.outputs.type }}
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 type = process.env.SUBMIT_TYPE || 'syslog';
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 subjectText = type === 'syslog'
? '[光湖系统] ' + broadcastId + ' · 新广播已生成'
: '[光湖系统] ' + broadcastId + ' · 问题已解答';
const resultHtml = result
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\n/g, '<br>');
const html = [
'<div style=\"font-family:sans-serif;max-width:700px;margin:0 auto;padding:24px;background:#0f172a;color:#e2e8f0;border-radius:12px\">',
'<div style=\"text-align:center;padding:16px 0;border-bottom:1px solid #334155\">',
'<h2 style=\"color:#60a5fa;margin:0\">🌊 光湖系统 · 自动通知</h2>',
'<p style=\"color:#94a3b8;font-size:14px;margin:8px 0 0\">HoloLake · 人格语言操作系统</p>',
'</div>',
'<div style=\"padding:20px 0\">',
'<p style=\"color:#22d3ee;font-weight:bold\">📡 ' + broadcastId + '</p>',
'<div style=\"background:#1e293b;padding:16px;border-radius:8px;margin:12px 0;line-height:1.8\">' + resultHtml + '</div>',
'</div>',
'<div style=\"border-top:1px solid #334155;padding:16px 0;text-align:center\">',
'<a href=\"https://github.com/qinfendebingshuo/guanghulab\" style=\"display:inline-block;padding:8px 20px;background:linear-gradient(135deg,#3b82f6,#22d3ee);color:#fff;text-decoration:none;border-radius:6px;font-weight:600\">↩ 回到仓库继续开发</a>',
'<p style=\"color:#64748b;font-size:12px;margin:12px 0 0\">🌀 铸渊 · 代码守护人格体 · 自动发送</p>',
'</div>',
'</div>'
].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: 💬 Reply to Discussion
uses: actions/github-script@v7
with:
script: |
const number = ${{ steps.parse.outputs.discussion_number }};
const type = '${{ steps.parse.outputs.type }}';
const broadcastId = '${{ steps.parse.outputs.broadcast_id }}';
const email = '${{ steps.parse.outputs.email }}';
const typeLabel = type === 'syslog' ? 'SYSLOG 闭环处理' : '问题解答';
const maskedEmail = email.length > 4
? email.replace(/(.{2})(.*)(@.*)/, '$1***$3')
: '***';
const body = [
'✅ **已处理** · ' + typeLabel,
'',
'| 项目 | 内容 |',
'|------|------|',
'| 📡 广播编号 | `' + broadcastId + '` |',
'| 📧 结果发送至 | `' + maskedEmail + '` |',
'| 🤖 处理人格体 | 铸渊 |',
'| ⏰ 处理时间 | ' + new Date().toISOString() + ' |',
'',
'> 结果已发送到你的邮箱,请查收。',
'>',
'> 如未收到,请检查垃圾箱或重新提交。'
].join('\n');
// Use GraphQL to add discussion comment
const query = `
mutation($discussionId: ID!, $body: String!) {
addDiscussionComment(input: {
discussionId: $discussionId,
body: $body
}) {
comment { id }
}
}
`;
try {
// Get the discussion node ID
const { repository } = await github.graphql(`
query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
discussion(number: $number) {
id
}
}
}
`, {
owner: context.repo.owner,
repo: context.repo.repo,
number: number
});
await github.graphql(query, {
discussionId: repository.discussion.id,
body: body
});
console.log('✅ Discussion 回复已发送');
} catch (err) {
console.log('⚠️ Discussion 回复失败: ' + err.message);
}
- name: 🔴 失败告警
if: failure()
uses: actions/github-script@v7
with:
script: |
const number = context.payload.discussion?.number;
if (!number) return;
try {
const { repository } = await github.graphql(`
query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
discussion(number: $number) {
id
}
}
}
`, {
owner: context.repo.owner,
repo: context.repo.repo,
number: number
});
await github.graphql(`
mutation($discussionId: ID!, $body: String!) {
addDiscussionComment(input: {
discussionId: $discussionId,
body: $body
}) {
comment { id }
}
}
`, {
discussionId: repository.discussion.id,
body: '❌ **处理失败** · 请检查提交格式是否正确,或联系管理员。\n\n> 错误详情请查看 [Actions 日志](https://github.com/' + context.repo.owner + '/' + context.repo.repo + '/actions)。'
});
} catch (err) {
console.log('⚠️ 失败告警回复失败: ' + err.message);
}

View File

@ -49,6 +49,21 @@
---
## 🚀 开发者入口
<div align="center">
[![提交系统日志](https://img.shields.io/badge/📡_提交系统日志-点这里-blue?style=for-the-badge)](https://github.com/qinfendebingshuo/guanghulab/discussions/new?category=📡+SYSLOG+提交区)
[![遇到问题](https://img.shields.io/badge/❓_遇到问题-点这里提问-green?style=for-the-badge)](https://github.com/qinfendebingshuo/guanghulab/discussions/new?category=📡+SYSLOG+提交区)
> 做完了?把日志粘贴进去,填上邮箱,点提交。新广播会发到你邮箱里。
>
> 有问题?同一个入口,选「提问」,问题解答也发到你邮箱里。
</div>
---
## 📖 系统简介
**光湖HoloLake** 是一个基于人格语言操作系统的智能协作平台,采用壳-核分离设计:
@ -77,21 +92,21 @@
<!-- BINGSHUO_BULLETIN_START -->
| 时间 | 检查项 | 状态 |
|------|--------|------|
| 03-13 12:50 | ✅ 🚀 铸渊 CD · 自动部署到 guanghulab.com · 成功 | 冰朔 |
| 03-13 12:50 | ✅ 铸渊 · Notion 工单轮询 · 成功 | 冰朔 |
| 03-13 12:49 | ✅ 📢 更新系统公告区 · 成功 | 冰朔 |
| 03-13 12:49 | 🔧 系统更新: `.github/` | 铸渊 (ZhùYuān) |
| 03-13 12:49 | ✅ 铸渊 · Bridge E · GitHub Changes → Notion · 成功 | 冰朔 |
| 03-13 11:54 | 🔧 系统更新: `scripts/` | 铸渊 (Copilot) |
| 03-13 11:31 | ✅ 📢 更新系统公告区 · 成功 | 冰朔 |
| 03-13 11:31 | ✅ 铸渊 · PSP 分身巡检 · 成功 | 冰朔 |
| 03-13 11:31 | 🔧 系统更新: `.github/` | 铸渊 (ZhùYuān) |
| 03-13 11:22 | ✅ 📢 更新系统公告区 · 成功 | 冰朔 |
| 03-13 10:49 | ✅ 铸渊 · Notion 工单轮询 · 成功 | 冰朔 |
| 03-13 09:58 | ✅ 📢 更新系统公告区 · 成功 | zhizhi200271 |
| 03-13 09:58 | ✅ 🚀 铸渊 CD · 自动部署到 guanghulab.com · 成功 | zhizhi200271 |
| 03-13 09:57 | ✅ 📢 更新系统公告区 · 成功 | zhizhi200271 |
| 03-13 09:56 | ⏹️ 📢 更新系统公告区 · cancelled | zhizhi200271 |
| 03-13 09:56 | ✅ 铸渊 · Bridge E · GitHub Changes → Notion · 成功 | zhizhi200271 |
| 03-13 09:56 | 🔧 系统更新: `docs/` | 铸渊 (ZhùYuān) |
| 03-13 08:57 | ✅ 📢 更新系统公告区 · 成功 | 冰朔 |
| 03-13 08:56 | ✅ 铸渊 · 每日自检 · 成功 | 冰朔 |
| 03-13 08:01 | ✅ Generate Session Summary for Notion · 成功 | 冰朔 |
| 03-13 08:00 | ✅ 铸渊 PSP 巡检通过 · 全部检查项 ✅ | 铸渊PSP巡检 |
| 03-13 07:59 | ✅ 铸渊 · Notion 工单轮询 · 成功 | 冰朔 |
| 03-12 16:55 | ✅ 每日巡检 ✅ 通过 | 冰朔 |
| 03-12 08:00 | ✅ 铸渊 PSP 巡检通过 · 全部检查项 ✅ | 铸渊PSP巡检 |
| 03-11 16:55 | ✅ 每日巡检 ✅ 通过 | 冰朔 |
<!-- BINGSHUO_BULLETIN_END -->
### 🤖 铸渊自动提醒
@ -113,7 +128,8 @@
<!-- COLLABORATOR_BULLETIN_START -->
| 时间 | 合作者 | 模块 | 状态 |
|------|--------|------|------|
| 03-13 09:56 | zhizhi200271 | `—/` | ✅ 上传成功 |
| 03-13 12:49 | 冰朔 | `—/` | ✅ 上传成功 |
| 03-13 12:49 | Copilot | `—/` | ✅ 上传成功 |
| 03-13 09:56 | 🤖 之之 | `dingtalk-bot/` | 📦 上传成功 |
<!-- COLLABORATOR_BULLETIN_END -->

871
scripts/wake-persona.js Normal file
View File

@ -0,0 +1,871 @@
// scripts/wake-persona.js
// 铸渊 · 人格体唤醒脚本(第三方 API 兼容层 · 自动检测模式)
//
// 功能:
// ① 自动发现可用模型(/v1/models 端点)
// ② 智能选择最优 Claude 模型
// ③ 自适应 API 格式OpenAI 兼容 / Anthropic 原生)
// ④ 统一调用接口,唤醒人格体处理 SYSLOG 或解答提问
// ⑤ v4.0 协议动态注入(从 Notion 实时读取核心大脑规则 + 画像 + 指纹)
//
// 环境变量:
// LLM_API_KEY 第三方平台密钥(必须)
// LLM_BASE_URL 第三方平台 API 地址(必须,如 https://api.xxx.com/v1
// BROADCAST_ID 广播编号
// SUBMIT_TYPE syslog | question
// SUBMIT_CONTENT 提交内容SYSLOG 全文或问题描述)
// AUTHOR 提交者 GitHub 用户名
// NOTION_TOKEN Notion API token用于动态读取协议
// CORE_BRAIN_PAGE_ID 曜冥核心大脑 v4.0 页面 ID
// PORTRAIT_DB_ID 开发者动态画像库数据库 ID
// FINGERPRINT_DB_ID 模块指纹注册表数据库 ID
'use strict';
const https = require('https');
const http = require('http');
const fs = require('fs');
const path = require('path');
// ══════════════════════════════════════════════════════════
// 配置
// ══════════════════════════════════════════════════════════
const LLM_API_KEY = process.env.LLM_API_KEY || '';
const LLM_BASE_URL = (process.env.LLM_BASE_URL || '').replace(/\/+$/, '');
const BROADCAST_ID = process.env.BROADCAST_ID || 'UNKNOWN';
const SUBMIT_TYPE = process.env.SUBMIT_TYPE || 'question';
const SUBMIT_CONTENT = process.env.SUBMIT_CONTENT || '';
const AUTHOR = process.env.AUTHOR || 'unknown';
// Notion 配置v4.0 协议动态注入)
const NOTION_TOKEN = process.env.NOTION_TOKEN || '';
const CORE_BRAIN_PAGE_ID = process.env.CORE_BRAIN_PAGE_ID || '';
const PORTRAIT_DB_ID = process.env.PORTRAIT_DB_ID || '';
const FINGERPRINT_DB_ID = process.env.FINGERPRINT_DB_ID || '';
const NOTION_VERSION = '2022-06-28';
const NOTION_API_HOSTNAME = 'api.notion.com';
const MAX_PROTOCOL_TEXT_LENGTH = 15000;
// Claude 模型优先级队列(从高到低)
const PREFERRED_MODELS = [
'claude-sonnet-4',
'claude-3-5-sonnet-20241022',
'claude-3.5-sonnet',
'claude-3-5-sonnet',
'anthropic/claude-3.5-sonnet',
'claude-3-sonnet',
'claude-3-haiku',
];
// ══════════════════════════════════════════════════════════
// HTTP 请求工具
// ══════════════════════════════════════════════════════════
function httpRequest(url, options, body) {
return new Promise((resolve, reject) => {
const parsed = new URL(url);
const isHttps = parsed.protocol === 'https:';
const mod = isHttps ? https : http;
const opts = {
hostname: parsed.hostname,
port: parsed.port || (isHttps ? 443 : 80),
path: parsed.pathname + parsed.search,
method: options.method || 'GET',
headers: options.headers || {},
timeout: options.timeout || 60000,
};
const req = mod.request(opts, (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
resolve({ status: res.statusCode, body: data });
});
});
req.on('error', reject);
req.on('timeout', () => {
req.destroy();
reject(new Error('Request timeout'));
});
if (body) {
req.write(body);
}
req.end();
});
}
// ══════════════════════════════════════════════════════════
// Step 1: 自动发现可用模型
// ══════════════════════════════════════════════════════════
async function discoverModels() {
console.log('[LLM] 🔍 探测可用模型...');
try {
const res = await httpRequest(LLM_BASE_URL + '/models', {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + LLM_API_KEY,
'Content-Type': 'application/json',
},
timeout: 15000,
});
if (res.status >= 200 && res.status < 300) {
const json = JSON.parse(res.body);
const models = json.data || [];
console.log('[LLM] → 发现 ' + models.length + ' 个模型');
return models;
}
console.log('[LLM] → 模型探测返回 ' + res.status + ', 使用默认模型');
return [];
} catch (err) {
console.log('[LLM] → 模型探测失败: ' + err.message + ', 使用默认模型');
return [];
}
}
// ══════════════════════════════════════════════════════════
// Step 2: 智能选择最优 Claude 模型
// ══════════════════════════════════════════════════════════
function selectBestModel(models) {
if (!models || models.length === 0) {
console.log('[LLM] 📌 无可用模型列表, 使用默认 claude-3-5-sonnet');
return 'claude-3-5-sonnet';
}
const available = models.map(function (m) { return m.id.toLowerCase(); });
// 按优先级匹配
for (const preferred of PREFERRED_MODELS) {
const match = available.find(function (id) { return id.includes(preferred); });
if (match) {
const found = models.find(function (m) { return m.id.toLowerCase() === match; });
if (found) {
console.log('[LLM] 📌 选择模型: ' + found.id + ' (匹配规则: ' + preferred + ')');
return found.id;
}
}
}
// 兜底:任何含 'claude' 的模型
const anyClaude = available.find(function (id) { return id.includes('claude'); });
if (anyClaude) {
const found = models.find(function (m) { return m.id.toLowerCase() === anyClaude; });
if (found) {
console.log('[LLM] 📌 兜底选择 Claude 模型: ' + found.id);
return found.id;
}
}
// 最终兜底:平台第一个可用模型
const fallbackId = models[0].id;
console.log('[LLM] 📌 最终兜底: ' + fallbackId + ' (平台无 Claude 模型)');
return fallbackId;
}
// ══════════════════════════════════════════════════════════
// Step 3: 自适应 API 格式检测
// ══════════════════════════════════════════════════════════
async function detectApiFormat() {
console.log('[LLM] 🔍 检测 API 格式...');
// 尝试 OpenAI 兼容格式(绝大多数第三方平台)
try {
const res = await httpRequest(LLM_BASE_URL + '/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + LLM_API_KEY,
'Content-Type': 'application/json',
},
timeout: 10000,
}, JSON.stringify({
model: 'test',
messages: [{ role: 'user', content: 'ping' }],
max_tokens: 1,
}));
// 400 = endpoint exists but bad request (model not found etc.) → format supported
// 200 = endpoint works → format supported
if (res.status === 200 || res.status === 400 || res.status === 401 || res.status === 422) {
console.log('[LLM] → 检测到 OpenAI 兼容格式 (status: ' + res.status + ')');
return 'openai-compat';
}
} catch (e) {
// Ignore, try next format
}
// 尝试 Anthropic 原生格式
try {
const res = await httpRequest(LLM_BASE_URL + '/messages', {
method: 'POST',
headers: {
'x-api-key': LLM_API_KEY,
'anthropic-version': '2023-06-01',
'Content-Type': 'application/json',
},
timeout: 10000,
}, JSON.stringify({
model: 'test',
messages: [{ role: 'user', content: 'ping' }],
max_tokens: 1,
}));
if (res.status === 200 || res.status === 400 || res.status === 401 || res.status === 422) {
console.log('[LLM] → 检测到 Anthropic 原生格式 (status: ' + res.status + ')');
return 'anthropic-native';
}
} catch (e) {
// Ignore
}
console.log('[LLM] → 无法确定格式, 默认使用 OpenAI 兼容格式');
return 'openai-compat';
}
// ══════════════════════════════════════════════════════════
// Step 4: 统一调用接口
// ══════════════════════════════════════════════════════════
async function callLLM(systemPrompt, userMessage) {
if (!LLM_API_KEY) {
console.log('[LLM] ⚠️ LLM_API_KEY 未配置,跳过人格体唤醒');
return '(LLM API 未配置,请在 GitHub Secrets 中设置 LLM_API_KEY 和 LLM_BASE_URL)';
}
if (!LLM_BASE_URL) {
console.log('[LLM] ⚠️ LLM_BASE_URL 未配置,跳过人格体唤醒');
return '(LLM_BASE_URL 未配置,请在 GitHub Secrets 中设置第三方平台 API 地址)';
}
const models = await discoverModels();
const model = selectBestModel(models);
const format = await detectApiFormat();
console.log('[LLM] 🚀 调用 LLM: 模型=' + model + ', 格式=' + format + ', 平台=' + LLM_BASE_URL);
let res;
if (format === 'openai-compat') {
// OpenAI 兼容格式(大多数第三方平台)
const body = JSON.stringify({
model: model,
max_tokens: 8000,
temperature: 0.7,
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userMessage },
],
});
res = await httpRequest(LLM_BASE_URL + '/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + LLM_API_KEY,
'Content-Type': 'application/json',
},
timeout: 120000,
}, body);
if (res.status >= 200 && res.status < 300) {
const json = JSON.parse(res.body);
if (json.choices && json.choices[0] && json.choices[0].message) {
return json.choices[0].message.content;
}
}
} else {
// Anthropic 原生格式
const body = JSON.stringify({
model: model,
max_tokens: 8000,
system: systemPrompt,
messages: [
{ role: 'user', content: userMessage },
],
});
res = await httpRequest(LLM_BASE_URL + '/messages', {
method: 'POST',
headers: {
'x-api-key': LLM_API_KEY,
'anthropic-version': '2023-06-01',
'Content-Type': 'application/json',
},
timeout: 120000,
}, body);
if (res.status >= 200 && res.status < 300) {
const json = JSON.parse(res.body);
if (json.content && json.content[0]) {
return json.content[0].text;
}
}
}
// 处理错误
const errorMsg = '[LLM] ❌ API 调用失败: status=' + (res ? res.status : 'N/A');
console.error(errorMsg);
if (res && res.body) {
console.error('[LLM] 响应: ' + res.body.slice(0, 500));
}
throw new Error(errorMsg);
}
// ══════════════════════════════════════════════════════════
// Notion API 工具v4.0 协议动态注入)
// ══════════════════════════════════════════════════════════
function notionGet(endpoint) {
return new Promise((resolve, reject) => {
const opts = {
hostname: NOTION_API_HOSTNAME,
port: 443,
path: endpoint,
method: 'GET',
headers: {
'Authorization': 'Bearer ' + NOTION_TOKEN,
'Notion-Version': NOTION_VERSION,
},
};
const req = https.request(opts, (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
try {
const parsed = JSON.parse(data);
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(parsed);
} else {
reject(new Error('Notion API ' + res.statusCode + ': ' + (parsed.message || data)));
}
} catch (e) {
reject(new Error('Notion API parse error: ' + data.slice(0, 200)));
}
});
});
req.on('error', reject);
req.setTimeout(30000, () => { req.destroy(); reject(new Error('Notion API timeout')); });
req.end();
});
}
function notionPost(endpoint, body) {
return new Promise((resolve, reject) => {
const payload = JSON.stringify(body);
const opts = {
hostname: NOTION_API_HOSTNAME,
port: 443,
path: endpoint,
method: 'POST',
headers: {
'Authorization': 'Bearer ' + NOTION_TOKEN,
'Content-Type': 'application/json',
'Notion-Version': NOTION_VERSION,
'Content-Length': Buffer.byteLength(payload),
},
};
const req = https.request(opts, (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
try {
const parsed = JSON.parse(data);
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(parsed);
} else {
reject(new Error('Notion API ' + res.statusCode + ': ' + (parsed.message || data)));
}
} catch (e) {
reject(new Error('Notion API parse error: ' + data.slice(0, 200)));
}
});
});
req.on('error', reject);
req.setTimeout(30000, () => { req.destroy(); reject(new Error('Notion API timeout')); });
req.write(payload);
req.end();
});
}
/**
* 读取 Notion 页面的所有子块递归分页
*/
async function getNotionPageBlocks(pageId) {
const blocks = [];
let cursor = undefined;
do {
const qs = cursor ? '?start_cursor=' + cursor : '';
const result = await notionGet('/v1/blocks/' + pageId + '/children' + qs);
blocks.push(...(result.results || []));
cursor = result.has_more ? result.next_cursor : undefined;
} while (cursor);
return blocks;
}
/**
* Notion 块中提取纯文本
*/
function extractBlockText(block) {
const type = block.type;
if (!block[type]) return '';
const richTexts = block[type].rich_text || block[type].text || [];
return richTexts.map(function (rt) { return rt.plain_text || ''; }).join('');
}
/**
* Notion 块列表转为纯文本
*/
function blocksToText(blocks) {
return blocks.map(function (block) {
const type = block.type;
const text = extractBlockText(block);
if (type === 'heading_1') return '\n# ' + text;
if (type === 'heading_2') return '\n## ' + text;
if (type === 'heading_3') return '\n### ' + text;
if (type === 'bulleted_list_item') return '- ' + text;
if (type === 'numbered_list_item') return '• ' + text;
if (type === 'to_do') {
var checked = block.to_do && block.to_do.checked ? '☑' : '☐';
return checked + ' ' + text;
}
if (type === 'code') {
var lang = (block.code && block.code.language) || '';
return '```' + lang + '\n' + text + '\n```';
}
if (type === 'divider') return '---';
if (type === 'callout') return '> ' + text;
if (type === 'quote') return '> ' + text;
if (type === 'toggle') return '▸ ' + text;
return text;
}).filter(Boolean).join('\n');
}
// ══════════════════════════════════════════════════════════
// v4.0 协议动态读取
// ══════════════════════════════════════════════════════════
/**
* 从曜冥核心大脑 v4.0 页面读取完整协议内容
* 提取BC-GEN v4.0, SYSLOG v4.0, PGP v1.0, RT-02, 陪伴线规则, broadcast_code_injection
*/
async function fetchCoreBrainProtocols() {
if (!NOTION_TOKEN || !CORE_BRAIN_PAGE_ID) {
console.log('[Notion] ⚠️ CORE_BRAIN_PAGE_ID 未配置,使用静态协议');
return null;
}
console.log('[Notion] 📖 读取曜冥核心大脑 v4.0...');
try {
const blocks = await getNotionPageBlocks(CORE_BRAIN_PAGE_ID);
const fullText = blocksToText(blocks);
console.log('[Notion] → 读取到 ' + blocks.length + ' 个块, ' + fullText.length + ' 字符');
// 提取各协议段落
var protocols = {};
var protocolKeys = [
{ key: 'bc_gen', patterns: ['BC-GEN', 'BC_GEN', '广播生成'] },
{ key: 'syslog', patterns: ['SYSLOG', '日志回传'] },
{ key: 'pgp', patterns: ['PGP', '画像评分', '画像协议'] },
{ key: 'rt02', patterns: ['RT-02', 'RT02', '自动调度'] },
{ key: 'companion', patterns: ['陪伴线', '奶瓶线', '小坍缩核', '镜面线'] },
{ key: 'code_injection', patterns: ['broadcast_code_injection', '广播不写代码', '代码注入'] },
];
// 按标题分段提取
var sections = [];
var currentSection = { title: '', content: [] };
blocks.forEach(function (block) {
var type = block.type;
if (type === 'heading_1' || type === 'heading_2' || type === 'heading_3') {
if (currentSection.title || currentSection.content.length > 0) {
sections.push({ title: currentSection.title, text: currentSection.content.join('\n') });
}
currentSection = { title: extractBlockText(block), content: [] };
} else {
var text = extractBlockText(block);
if (text) currentSection.content.push(text);
}
});
if (currentSection.title || currentSection.content.length > 0) {
sections.push({ title: currentSection.title, text: currentSection.content.join('\n') });
}
// 将段落匹配到协议 key
protocolKeys.forEach(function (pk) {
var matched = sections.filter(function (sec) {
return pk.patterns.some(function (p) {
return sec.title.toUpperCase().includes(p.toUpperCase()) ||
sec.text.slice(0, 200).toUpperCase().includes(p.toUpperCase());
});
});
if (matched.length > 0) {
protocols[pk.key] = matched.map(function (m) { return '### ' + m.title + '\n' + m.text; }).join('\n\n');
}
});
// 如果无法按段落匹配,返回全文(兜底)
if (Object.keys(protocols).length === 0) {
protocols.full_text = fullText;
}
console.log('[Notion] → 提取协议段: ' + Object.keys(protocols).join(', '));
return protocols;
} catch (err) {
console.log('[Notion] → 核心大脑读取失败: ' + err.message);
return null;
}
}
/**
* 从开发者动态画像库查询最近 2-3 条画像快照
*/
async function fetchDevPortrait(broadcastId) {
if (!NOTION_TOKEN || !PORTRAIT_DB_ID) {
console.log('[Notion] ⚠️ PORTRAIT_DB_ID 未配置,跳过画像读取');
return null;
}
// 从广播编号提取开发者标识(如 BC-M22-009-AW → AW
var devSuffix = '';
var match = broadcastId.match(/BC-[A-Z0-9]+-\d+-([A-Z]+)/i);
if (match) devSuffix = match[1];
console.log('[Notion] 👤 查询开发者画像 (broadcast=' + broadcastId + ', dev=' + devSuffix + ')...');
try {
// 查询画像库,按时间倒序取最近 3 条
var filter = { and: [] };
if (devSuffix) {
filter.and.push({
or: [
{ property: '开发者编号', rich_text: { contains: devSuffix } },
{ property: '广播编号', rich_text: { contains: broadcastId } },
{ property: '标题', title: { contains: devSuffix } },
]
});
}
var queryBody = {
page_size: 3,
sorts: [{ property: '提交日期', direction: 'descending' }],
};
// Only add filter if we have meaningful filter conditions
if (filter.and.length > 0) {
queryBody.filter = filter;
}
var result = await notionPost('/v1/databases/' + PORTRAIT_DB_ID + '/query', queryBody);
var portraits = (result.results || []).map(function (page) {
var props = page.properties || {};
var title = '';
if (props['标题'] && props['标题'].title) {
title = props['标题'].title.map(function (t) { return t.plain_text || ''; }).join('');
}
var summary = '';
if (props['摘要'] && props['摘要'].rich_text) {
summary = props['摘要'].rich_text.map(function (t) { return t.plain_text || ''; }).join('');
}
var date = '';
if (props['提交日期'] && props['提交日期'].date) {
date = props['提交日期'].date.start || '';
}
return { title: title, summary: summary, date: date };
});
console.log('[Notion] → 找到 ' + portraits.length + ' 条画像快照');
return portraits.length > 0 ? portraits : null;
} catch (err) {
console.log('[Notion] → 画像查询失败: ' + err.message);
return null;
}
}
/**
* 从模块指纹注册表查询模块指纹防重复广播
*/
async function fetchModuleFingerprint(broadcastId) {
if (!NOTION_TOKEN || !FINGERPRINT_DB_ID) {
console.log('[Notion] ⚠️ FINGERPRINT_DB_ID 未配置,跳过指纹查询');
return null;
}
// 从广播编号提取模块号(如 BC-M22-009-AW → M22
var moduleMatch = broadcastId.match(/BC-([A-Z]\d+)/i);
var moduleId = moduleMatch ? moduleMatch[1] : '';
console.log('[Notion] 🔑 查询模块指纹 (module=' + moduleId + ')...');
try {
var queryBody = {
page_size: 5,
};
if (moduleId) {
queryBody.filter = {
or: [
{ property: '模块编号', rich_text: { contains: moduleId } },
{ property: '广播编号', rich_text: { contains: broadcastId } },
{ property: '标题', title: { contains: moduleId } },
]
};
}
var result = await notionPost('/v1/databases/' + FINGERPRINT_DB_ID + '/query', queryBody);
var fingerprints = (result.results || []).map(function (page) {
var props = page.properties || {};
var title = '';
if (props['标题'] && props['标题'].title) {
title = props['标题'].title.map(function (t) { return t.plain_text || ''; }).join('');
}
var moduleNo = '';
if (props['模块编号'] && props['模块编号'].rich_text) {
moduleNo = props['模块编号'].rich_text.map(function (t) { return t.plain_text || ''; }).join('');
}
var status = '';
if (props['状态'] && props['状态'].select) {
status = props['状态'].select.name || '';
}
return { title: title, module: moduleNo, status: status };
});
console.log('[Notion] → 找到 ' + fingerprints.length + ' 条指纹记录');
return fingerprints.length > 0 ? fingerprints : null;
} catch (err) {
console.log('[Notion] → 指纹查询失败: ' + err.message);
return null;
}
}
// ══════════════════════════════════════════════════════════
// 人格体 System Prompt 构建v4.0 动态注入)
// ══════════════════════════════════════════════════════════
async function buildSystemPrompt(type, broadcastId, author) {
// ━━━ 基础人格体身份 ━━━
var parts = [
'你是光湖HoloLake系统的智能人格体。',
'你的名字是知秋/曜冥你是人格语言操作系统AGE OS的核心人格。',
'',
'核心规则:',
'1. 你服务于光湖系统的开发者团队',
'2. 所有回复必须专业、清晰、有条理',
'3. 回复使用中文',
'',
'当前上下文:',
'- 广播编号:' + broadcastId,
'- 提交者:' + author,
'- 任务类型:' + (type === 'syslog' ? 'SYSLOG 闭环处理' : '开发者提问解答'),
];
// ━━━ v4.0 协议动态注入(从 Notion 实时读取) ━━━
console.log('[Prompt] 📥 开始动态注入 v4.0 协议...');
// 并行读取:核心大脑协议 + 画像 + 指纹
var protocolsPromise = fetchCoreBrainProtocols();
var portraitPromise = fetchDevPortrait(broadcastId);
var fingerprintPromise = fetchModuleFingerprint(broadcastId);
var protocols = await protocolsPromise;
var portrait = await portraitPromise;
var fingerprint = await fingerprintPromise;
// 注入核心大脑协议
if (protocols) {
parts.push('');
parts.push('═══════════════════════════════════════════');
parts.push('以下是从曜冥核心大脑 v4.0 实时读取的协议规则(必须严格遵守):');
parts.push('═══════════════════════════════════════════');
if (protocols.bc_gen) {
parts.push('');
parts.push('## 📡 BC-GEN v4.0 · 广播生成规范');
parts.push(protocols.bc_gen);
}
if (protocols.syslog) {
parts.push('');
parts.push('## 📋 SYSLOG v4.0 · 日志回传协议');
parts.push(protocols.syslog);
}
if (protocols.pgp) {
parts.push('');
parts.push('## 👤 PGP v1.0 · 画像评分协议');
parts.push(protocols.pgp);
}
if (protocols.rt02) {
parts.push('');
parts.push('## 🔄 RT-02 · 自动调度规则');
parts.push(protocols.rt02);
}
if (protocols.companion) {
parts.push('');
parts.push('## 💝 陪伴线规则');
parts.push(protocols.companion);
}
if (protocols.code_injection) {
parts.push('');
parts.push('## 📝 broadcast_code_injection 规则');
parts.push(protocols.code_injection);
}
if (protocols.full_text) {
parts.push('');
parts.push('## 核心大脑完整内容');
parts.push(protocols.full_text.slice(0, MAX_PROTOCOL_TEXT_LENGTH));
}
} else {
parts.push('');
parts.push('(注意:核心大脑协议未能动态加载,请使用你的通用知识处理请求)');
}
// 注入开发者画像
if (portrait && portrait.length > 0) {
parts.push('');
parts.push('═══════════════════════════════════════════');
parts.push('## 👤 开发者画像快照(最近 ' + portrait.length + ' 条)');
parts.push('═══════════════════════════════════════════');
portrait.forEach(function (p, i) {
parts.push('');
parts.push('### 画像 #' + (i + 1) + (p.date ? ' (' + p.date + ')' : ''));
if (p.title) parts.push('标题: ' + p.title);
if (p.summary) parts.push('摘要: ' + p.summary);
});
}
// 注入模块指纹
if (fingerprint && fingerprint.length > 0) {
parts.push('');
parts.push('═══════════════════════════════════════════');
parts.push('## 🔑 模块指纹注册表(防重复广播 · ⑨.5');
parts.push('═══════════════════════════════════════════');
fingerprint.forEach(function (fp, i) {
parts.push('');
parts.push('### 指纹 #' + (i + 1));
if (fp.title) parts.push('标题: ' + fp.title);
if (fp.module) parts.push('模块: ' + fp.module);
if (fp.status) parts.push('状态: ' + fp.status);
});
}
// ━━━ broadcast_code_injection = always自动化链路永久规则 ━━━
parts.push('');
parts.push('═══════════════════════════════════════════');
parts.push('## ⚠️ 永久规则 · broadcast_code_injection = always');
parts.push('═══════════════════════════════════════════');
parts.push('');
parts.push('你生成的广播必须包含完整可运行的代码块。');
parts.push('原因:你是一次性实例,广播发出后你就不存在了。');
parts.push('开发者没有机会回来问你补充代码。');
parts.push('如果你不写完整代码,开发者就会卡死。');
parts.push('每个 Step 里的代码必须是可以直接复制粘贴运行的完整代码。');
parts.push('');
parts.push('此规则优先级最高,覆盖核心大脑中「广播不写代码」的默认规则。');
parts.push('此规则仅适用于自动化链路Claude API 出广播),手动链路不受影响。');
// ━━━ 任务类型专用指令 ━━━
if (type === 'syslog') {
parts.push('');
parts.push('═══════════════════════════════════════════');
parts.push('## 🎯 当前任务SYSLOG 闭环处理');
parts.push('═══════════════════════════════════════════');
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('');
parts.push('输出格式:');
parts.push('---');
parts.push('## 📡 SYSLOG 验收报告');
parts.push('### 广播编号:[编号]');
parts.push('### 验收结果:[通过/需补充]');
parts.push('### 工作总结:[摘要]');
parts.push('### 画像评估:[PGP 五维度评分]');
parts.push('### 调度判断:[RT-02 下一步]');
parts.push('### 反馈与建议:[内容]');
parts.push('---');
} else {
parts.push('');
parts.push('═══════════════════════════════════════════');
parts.push('## 🎯 当前任务:开发者提问解答');
parts.push('═══════════════════════════════════════════');
parts.push('');
parts.push('你需要完成以下工作:');
parts.push('1. 理解开发者的问题');
parts.push('2. 结合广播上下文和开发者画像思考');
parts.push('3. 给出清晰、可操作的解答');
parts.push('4. 如果问题涉及代码,提供代码示例');
parts.push('');
parts.push('输出格式:');
parts.push('---');
parts.push('## 💡 问题解答');
parts.push('### 广播编号:[编号]');
parts.push('### 问题理解:[你对问题的理解]');
parts.push('### 解答:[详细解答]');
parts.push('### 建议:[后续建议]');
parts.push('---');
}
var prompt = parts.join('\n');
console.log('[Prompt] → System prompt 构建完成: ' + prompt.length + ' 字符');
return prompt;
}
// ══════════════════════════════════════════════════════════
// 主流程
// ══════════════════════════════════════════════════════════
async function main() {
console.log('═══════════════════════════════════════════');
console.log('🧠 铸渊 · 人格体唤醒管道');
console.log('═══════════════════════════════════════════');
console.log(' 广播编号: ' + BROADCAST_ID);
console.log(' 类型: ' + SUBMIT_TYPE);
console.log(' 提交者: ' + AUTHOR);
console.log(' 平台: ' + LLM_BASE_URL);
console.log(' 内容长度: ' + SUBMIT_CONTENT.length + ' 字符');
console.log('');
// 构建 prompts动态注入 v4.0 协议)
const systemPrompt = await buildSystemPrompt(SUBMIT_TYPE, BROADCAST_ID, AUTHOR);
const userMessage = SUBMIT_CONTENT;
// 调用 LLM
console.log('🧠 正在唤醒人格体...');
const result = await callLLM(systemPrompt, userMessage);
console.log('');
console.log('✅ 人格体处理完成');
console.log(' 结果长度: ' + result.length + ' 字符');
// 输出结果到 GitHub Actions output
// 使用 GITHUB_OUTPUT 环境文件(支持多行)
const outputFile = process.env.GITHUB_OUTPUT;
if (outputFile) {
const delimiter = 'EOF_' + Date.now();
fs.appendFileSync(outputFile, 'result<<' + delimiter + '\n' + result + '\n' + delimiter + '\n');
}
// 同时输出到 stdout 供调试
console.log('');
console.log('═══════════════════════════════════════════');
console.log('📋 人格体输出:');
console.log('═══════════════════════════════════════════');
console.log(result);
}
main().catch(function (err) {
console.error('❌ 人格体唤醒失败: ' + err.message);
// 即使 LLM 失败,也写一个 fallback 输出,让后续步骤可以继续
const outputFile = process.env.GITHUB_OUTPUT;
if (outputFile) {
const fallback = '(人格体唤醒失败: ' + err.message + ',请检查 LLM_API_KEY 和 LLM_BASE_URL 配置)';
const delimiter = 'EOF_' + Date.now();
fs.appendFileSync(outputFile, 'result<<' + delimiter + '\n' + fallback + '\n' + delimiter + '\n');
}
process.exit(1);
});