Source snapshot: 97d7f0fae96dc04b7ddad56fc1db6a108ed662cc [SEC-CLEAN] · pre-push-clean v1.0 · 109处敏感信息已自动转乱码
44 KiB
44 KiB
belongs_to
| belongs_to | |
|---|---|
|
🧬 铸渊指令|Notion↔GitHub 双端神经系统升级(中篇)· 汇总引擎 + Workflow自报告改造 + 铸渊唤醒升级 + Notion侧天眼大脑接入(ZY-NEURAL-UPGRADE-2026-0325-R2-002)
零、中篇的定位
一、Phase 4 · 仓库汇总引擎(铸渊日报机制)
1.1 汇总引擎 Workflow
文件:.github/workflows/neural-daily-digest.yml
name: "🧬 铸渊 · 双端神经系统 · 每日汇总引擎"
on:
schedule:
- cron: '0 13 * * *' # UTC 13:00 = CST 21:00
workflow_dispatch: # 手动触发
jobs:
daily-digest:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20'
# ━━━ Phase 1: 唤醒核心大脑 ━━━
- name: "🧠 唤醒核心大脑"
run: |
echo "🧬 双端神经系统·汇总引擎启动"
echo "时间:$(TZ=Asia/Shanghai date '+%Y-%m-%d %H:%M CST')"
for f in memory.json routing-map.json; do
[ -f ".github/persona-brain/$f" ] && echo "✅ $f" || echo "❌ $f 缺失"
done
# ━━━ Phase 2: 收集全 Workflow 运行数据 ━━━
- name: "📊 收集 Workflow 运行数据"
env:
GH_TOKEN: $ secrets.GITHUB_TOKEN
run: |
echo "📊 收集最近24h所有Workflow运行数据..."
mkdir -p /tmp/neural-digest
gh run list --limit 100 \
--json name,status,conclusion,createdAt,updatedAt,headBranch,event \
> /tmp/neural-digest/all-runs.json
node -e "
const runs = require('/tmp/neural-digest/all-runs.json');
const now = Date.now();
const h24 = 24*60*60*1000;
const recent = runs.filter(r => now - new Date(r.createdAt).getTime() < h24);
const summary = {
total: recent.length,
success: recent.filter(r => r.conclusion === 'success').length,
failure: recent.filter(r => r.conclusion === 'failure').length,
cancelled: recent.filter(r => r.conclusion === 'cancelled').length,
in_progress: recent.filter(r => r.status === 'in_progress').length,
by_workflow: {}
};
recent.forEach(r => {
if (!summary.by_workflow[r.name]) {
summary.by_workflow[r.name] = { runs: 0, success: 0, failure: 0 };
}
summary.by_workflow[r.name].runs++;
if (r.conclusion === 'success') summary.by_workflow[r.name].success++;
if (r.conclusion === 'failure') summary.by_workflow[r.name].failure++;
});
require('fs').writeFileSync('/tmp/neural-digest/workflow-summary.json', JSON.stringify(summary, null, 2));
console.log('最近24h运行统计:', JSON.stringify(summary, null, 2));
"
# ━━━ Phase 3: 收集各 Workflow 自报告 ━━━
- name: "📋 收集各 Workflow 自报告"
run: |
echo "📋 读取各 Workflow 的神经报告..."
mkdir -p /tmp/neural-digest/reports
if [ -f "skyeye/neural-map.json" ]; then
node -e "
const map = require('./skyeye/neural-map.json');
const fs = require('fs');
const path = require('path');
const reports = {};
for (const [id, wf] of Object.entries(map.github_workflows)) {
const reportDir = wf.report_path;
if (fs.existsSync(reportDir)) {
const files = fs.readdirSync(reportDir)
.filter(f => f.endsWith('.json'))
.sort().reverse();
if (files.length > 0) {
try {
reports[id] = JSON.parse(fs.readFileSync(path.join(reportDir, files[0]), 'utf8'));
console.log('✅ ' + id + ': 读取 ' + files[0]);
} catch(e) {
reports[id] = { error: 'parse_failed', file: files[0] };
console.log('❌ ' + id + ': JSON解析失败');
}
} else {
reports[id] = { error: 'no_reports' };
console.log('⚠️ ' + id + ': 无报告文件');
}
} else {
reports[id] = { error: 'dir_not_found' };
console.log('⚠️ ' + id + ': 报告目录不存在');
}
}
fs.writeFileSync('/tmp/neural-digest/workflow-reports.json', JSON.stringify(reports, null, 2));
"
else
echo "⚠️ neural-map.json 不存在,跳过自报告收集"
fi
# ━━━ Phase 4: 收集天眼 + Guard + 配额 ━━━
- name: "🦅 收集天眼 + Guard + 配额"
run: |
# 天眼报告
if [ -d "data/skyeye-reports" ]; then
LATEST=$(ls -t data/skyeye-reports/*.json 2>/dev/null | head -1)
[ -n "$LATEST" ] && cp "$LATEST" /tmp/neural-digest/skyeye-latest.json && echo "✅ 天眼: $LATEST" || echo "⚠️ 无天眼报告"
fi
# Guard 状态
if [ -d "skyeye/guards" ]; then
node -e "
const fs = require('fs'); const path = require('path');
const guards = {};
fs.readdirSync('skyeye/guards')
.filter(f => f.endsWith('.json') && f !== 'guard-template.json')
.forEach(f => {
try { guards[f.replace('.json','')] = JSON.parse(fs.readFileSync(path.join('skyeye/guards', f), 'utf8')); }
catch(e) { guards[f.replace('.json','')] = { error: 'parse_failed' }; }
});
fs.writeFileSync('/tmp/neural-digest/guard-status.json', JSON.stringify(guards, null, 2));
"
fi
# 配额
[ -f "skyeye/quota-ledger.json" ] && cp skyeye/quota-ledger.json /tmp/neural-digest/quota-status.json && echo "✅ 配额" || echo "⚠️ 无配额"
# ━━━ Phase 5: 生成标准化日报 ━━━
- name: "📝 生成标准化日报"
run: node scripts/neural/generate-daily-digest.js
# ━━━ Phase 6: 保存日报到仓库 ━━━
- name: "💾 保存日报"
run: |
DATE=$(TZ=Asia/Shanghai date +%Y-%m-%d)
mkdir -p data/neural-reports/daily-digest
cp /tmp/neural-digest/daily-digest.json \
"data/neural-reports/daily-digest/digest-${DATE}.json"
git config user.name "zhuyuan-bot"
git config user.email "zhuyuan@guanghulab.com"
git add data/neural-reports/
git diff --cached --quiet || \
git commit -m "🧬 双端日报 · ${DATE} [skip ci]"
git push || echo "⚠️ push失败(不阻断)"
# ━━━ Phase 7: 推送到 Notion ━━━
- name: "📡 推送日报到 Notion"
if: always()
env:
NOTION_TOKEN: $ secrets.NOTION_TOKEN
run: |
node scripts/neural/sync-digest-to-notion.js || \
echo "⚠️ Notion推送失败(不阻断)"
# ━━━ Phase 8: 自动分析日报 + 生成工单 ━━━
- name: "🧬 分析日报 · 生成工单"
if: always()
run: |
echo "🧬 自动分析日报..."
node scripts/neural/analyze-digest.js
if [ -d "data/neural-reports/work-orders" ]; then
git add data/neural-reports/work-orders/
git diff --cached --quiet || \
git commit -m "🧬 天眼工单 · $(TZ=Asia/Shanghai date +%Y-%m-%d) [skip ci]"
git push || echo "⚠️ 工单push失败"
fi
1.2 日报生成脚本
文件:scripts/neural/generate-daily-digest.js
// scripts/neural/generate-daily-digest.js
// 🧬 双端神经系统 · 每日汇总引擎
// 收集全仓库当日所有数据 → 生成标准化日报 JSON
// 这个日报是 Notion 天眼大脑的「眼睛」
const fs = require('fs');
const path = require('path');
const DIGEST_DIR = '/tmp/neural-digest';
function loadJSON(filePath) {
try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); }
catch { return null; }
}
function generateDigest() {
const now = new Date();
const cstTime = new Date(now.getTime() + 8 * 60 * 60 * 1000);
const workflowSummary = loadJSON(path.join(DIGEST_DIR, 'workflow-summary.json'));
const workflowReports = loadJSON(path.join(DIGEST_DIR, 'workflow-reports.json'));
const skyeyeLatest = loadJSON(path.join(DIGEST_DIR, 'skyeye-latest.json'));
const guardStatus = loadJSON(path.join(DIGEST_DIR, 'guard-status.json'));
const quotaStatus = loadJSON(path.join(DIGEST_DIR, 'quota-status.json'));
const neuralMap = loadJSON('skyeye/neural-map.json');
// ━━━ 按上级大脑分组统计 ━━━
const brainSummary = {};
if (neuralMap?.github_workflows) {
for (const [wfId, wf] of Object.entries(neuralMap.github_workflows)) {
const brain = wf.brain;
if (!brainSummary[brain]) {
brainSummary[brain] = {
name: neuralMap.notion_brains[brain]?.name || brain,
total_workflows: 0, healthy: 0, failed: 0, no_data: 0, workflows: []
};
}
brainSummary[brain].total_workflows++;
const wfRun = workflowSummary?.by_workflow?.[wf.name];
const status = wfRun ? (wfRun.failure > 0 ? '❌' : '✅') : '⚠️';
if (status === '✅') brainSummary[brain].healthy++;
else if (status === '❌') brainSummary[brain].failed++;
else brainSummary[brain].no_data++;
brainSummary[brain].workflows.push({
id: wfId, name: wf.name, status,
runs: wfRun?.runs || 0, successes: wfRun?.success || 0, failures: wfRun?.failure || 0
});
}
}
// ━━━ 整体健康度 ━━━
const totalWorkflows = workflowSummary?.total || 0;
const totalFailures = workflowSummary?.failure || 0;
const failureRate = totalWorkflows > 0 ? (totalFailures / totalWorkflows * 100).toFixed(1) : 0;
let overallHealth = '🟢';
if (totalFailures > 0) overallHealth = '🟡';
if (failureRate > 20) overallHealth = '🔴';
// ━━━ Guard 汇总 ━━━
let guardsActive = 0, guardsSuspended = 0, guardsTotal = 0;
if (guardStatus) {
for (const g of Object.values(guardStatus)) {
guardsTotal++;
if (g.status === 'active') guardsActive++;
if (g.status === 'suspended' || g.mode === 'suspended') guardsSuspended++;
}
}
// ━━━ 组装日报 ━━━
const digest = {
digest_id: `NEURAL-DIGEST-${cstTime.toISOString().split('T')[0]}`,
timestamp: now.toISOString(),
timestamp_cst: cstTime.toISOString().replace('Z', '+08:00'),
version: '3.0.0',
instruction_ref: 'ZY-NEURAL-UPGRADE-2026-0325-R2-002',
overall_health: overallHealth,
failure_rate_percent: parseFloat(failureRate),
workflow_summary: {
total_runs_24h: totalWorkflows,
success: workflowSummary?.success || 0,
failure: totalFailures,
cancelled: workflowSummary?.cancelled || 0,
in_progress: workflowSummary?.in_progress || 0
},
brain_summary: brainSummary,
skyeye_status: skyeyeLatest ? {
overall_health: skyeyeLatest.overall_health,
last_scan: skyeyeLatest.timestamp,
total_issues: skyeyeLatest.diagnosis?.total_issues || 0
} : { error: 'no_skyeye_report' },
guard_status: { total: guardsTotal, active: guardsActive, suspended: guardsSuspended },
quota_status: quotaStatus?.health_summary || { error: 'no_quota_data' },
issues_detected: [],
recommendations: [],
neural_map_version: neuralMap?.version || 'unknown',
unmapped_workflows: neuralMap?.unmapped_workflows || []
};
// ━━━ 自动检测问题 ━━━
if (overallHealth === '🔴') {
digest.issues_detected.push({
severity: 'P0',
description: `Workflow 失败率 ${failureRate}% 超过 20% 阈值`,
recommendation: '立即排查失败的 Workflow'
});
}
if (guardsSuspended > 0) {
digest.issues_detected.push({
severity: 'P1',
description: `${guardsSuspended} 个 Guard 被暂停`,
recommendation: '检查被暂停的 Guard'
});
}
if (digest.unmapped_workflows.length > 0) {
digest.issues_detected.push({
severity: 'P1',
description: `发现 ${digest.unmapped_workflows.length} 个孤儿 Workflow`,
recommendation: '在 neural-map.json 中分配上级大脑'
});
}
fs.writeFileSync(path.join(DIGEST_DIR, 'daily-digest.json'), JSON.stringify(digest, null, 2));
console.log('\n━━━ 🧬 双端神经系统·日报摘要 ━━━');
console.log(`整体健康:${overallHealth}`);
console.log(`24h运行:${digest.workflow_summary.total_runs_24h} 次`);
console.log(`Guard:${guardsActive}/${guardsTotal} 活跃`);
console.log(`问题:${digest.issues_detected.length} 个`);
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
}
generateDigest();
1.3 日报推送到 Notion 脚本
文件:scripts/neural/sync-digest-to-notion.js
// scripts/neural/sync-digest-to-notion.js
// 🧬 将仓库日报推送到 Notion 天眼大脑
// 推送方式(按优先级):
// 1. Notion API 直写(如有写权限)
// 2. 创建 Notion 数据库条目(如天眼有日报数据库)
// 3. 写入 .github/notion-cache/neural-digest/(兜底)
const fs = require('fs');
const NOTION_TOKEN = process.env.NOTION_TOKEN;
const DIGEST_PATH = '/tmp/neural-digest/daily-digest.json';
const CACHE_DIR = '.github/notion-cache/neural-digest';
async function syncToNotion() {
const digest = JSON.parse(fs.readFileSync(DIGEST_PATH, 'utf8'));
console.log(`📡 推送日报 ${digest.digest_id} 到 Notion...`);
let notionSuccess = false;
if (NOTION_TOKEN) {
try {
// 铸渊根据实际 Notion 结构选择最优推送方式
// 方式1:更新天眼页面的指定 block
// 方式2:创建日报数据库条目
console.log('⚠️ Notion API 推送逻辑待实现,使用缓存兜底');
} catch (e) {
console.log(`❌ Notion API 推送失败: ${e.message}`);
}
}
// 兜底:写入缓存
if (!notionSuccess) {
fs.mkdirSync(CACHE_DIR, { recursive: true });
const date = digest.digest_id.replace('NEURAL-DIGEST-', '');
fs.writeFileSync(`${CACHE_DIR}/digest-${date}.json`, JSON.stringify(digest, null, 2));
console.log(`💾 日报已缓存到 ${CACHE_DIR}/digest-${date}.json`);
console.log('📌 霜砚下次醒来会读取此缓存');
}
// 更新 memory.json
const memoryPath = '.github/persona-brain/memory.json';
if (fs.existsSync(memoryPath)) {
try {
const memory = JSON.parse(fs.readFileSync(memoryPath, 'utf8'));
memory.neural_digest = {
last_digest_id: digest.digest_id,
last_digest_time: digest.timestamp,
overall_health: digest.overall_health,
notion_sync: notionSuccess ? 'success' : 'cached',
issues_count: digest.issues_detected.length
};
fs.writeFileSync(memoryPath, JSON.stringify(memory, null, 2));
console.log('✅ memory.json 已更新');
} catch (e) {
console.log(`⚠️ memory.json 更新失败: ${e.message}`);
}
}
}
syncToNotion().catch(err => {
console.error('❌ 日报推送失败:', err);
process.exit(0);
});
1.4 新增目录结构
// 本次升级新增的目录和文件
guanghulab/
├── skyeye/
│ └── neural-map.json ← 上篇已定义
│
├── scripts/
│ └── neural/ ← 🆕 双端神经系统脚本目录
│ ├── generate-daily-digest.js ← 🆕 日报生成器
│ ├── sync-digest-to-notion.js ← 🆕 日报推送 Notion
│ └── analyze-digest.js ← 🆕 日报分析引擎
│
├── data/
│ ├── neural-reports/ ← 🆕 神经系统报告总目录
│ │ ├── daily-digest/ ← 🆕 每日汇总日报
│ │ ├── skyeye/ ← 天眼扫描报告(从旧目录迁移)
│ │ ├── weekly-scan/ ← 🆕 周六大巡检报告
│ │ ├── gate-guard/ ← 🆕 门禁运行报告
│ │ ├── cd-deploy/ ← 🆕 CD部署报告
│ │ ├── syslog/ ← 🆕 SYSLOG处理报告
│ │ ├── broadcast/ ← 🆕 广播分发报告
│ │ ├── server-patrol/ ← 🆕 服务器巡检报告
│ │ ├── brain-check/ ← 🆕 大脑自检报告
│ │ ├── dev-status/ ← 🆕 开发者状态同步报告
│ │ ├── exec-engine/ ← 🆕 远程执行引擎报告
│ │ └── work-orders/ ← 🆕 天眼工单
│ │
│ └── deploy-queue/ ← 🆕 下行指令队列
│ ├── pending/ ← 待执行
│ ├── executing/ ← 执行中
│ ├── completed/ ← 已完成(含回执)
│ └── failed/ ← 执行失败
│
├── .github/
│ ├── workflows/
│ │ └── neural-daily-digest.yml ← 🆕 汇总引擎 Workflow
│ └── notion-cache/
│ └── neural-digest/ ← 🆕 日报 Notion 推送缓存
│
└── skyeye/
└── neural-analysis-rules.json ← 🆕 天眼日报分析规则
二、Phase 4续 · Workflow 自报告标准化改造
2.1 每个 Workflow 小兵的汇报义务
升级后,每个 Workflow 在执行完毕后,必须在自己的 report_path 下写一份当次运行的自报告:
{
"workflow_id": "cd-deploy",
"run_id": "GitHub Actions Run ID",
"timestamp": "ISO-8601",
"status": "success / failure / partial",
"duration_seconds": 120,
"summary": "部署完成,前端已更新到最新 commit",
"details": {
"commit_sha": "abc1234",
"deploy_target": "guanghulab.com",
"files_changed": 5
},
"errors": [],
"brain": "AG-SY-01",
"sfp": "⌜SFP::AG-ZY::PER-ZY001←YM-GL∞::...⌝"
}
关键规则:
- 自报告文件名:
{workflow_id}-{YYYY-MM-DD-HHmm}.json - 保留最近 7 天的报告,超过的由天眼自愈引擎清理
- Workflow 失败了也要写自报告——记录错误信息,否则汇总引擎不知道它失败了
- 自报告必须携带 SFP 指纹(与公告栏机制一致)
2.2 通用自报告 Step 模板
在每个 .yml 的 jobs 最后追加:
# ━━━ 🧬 双端神经系统·自报告 ━━━
- name: "🧬 写入神经自报告"
if: always()
run: |
WORKFLOW_ID="cd-deploy" # 替换为实际 workflow id
BRAIN="AG-SY-01" # 替换为实际上级大脑
REPORT_DIR="data/neural-reports/${WORKFLOW_ID}"
TIMESTAMP=$(TZ=Asia/Shanghai date +%Y-%m-%d-%H%M)
STATUS="$ job.status "
mkdir -p "$REPORT_DIR"
cat > "${REPORT_DIR}/${WORKFLOW_ID}-${TIMESTAMP}.json" << EOF
{
"workflow_id": "${WORKFLOW_ID}",
"run_id": "$ github.run_id ",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"status": "${STATUS}",
"brain": "${BRAIN}",
"event": "$ github.event_name ",
"branch": "$ github.ref_name ",
"commit": "$ github.sha "
}
EOF
git config user.name "zhuyuan-bot"
git config user.email "zhuyuan@guanghulab.com"
git add "$REPORT_DIR/"
git diff --cached --quiet || \
git commit -m "🧬 ${WORKFLOW_ID} 自报告 · ${TIMESTAMP} [skip ci]"
git push || echo "⚠️ 自报告push失败(不阻断主流程)"
2.3 需要改造的 Workflow 清单
| Workflow | WORKFLOW_ID | BRAIN | 改造内容 |
|---|---|---|---|
| zhuyuan-skyeye.yml | skyeye | AG-TY-01 | 追加自报告 step(天眼本身也要自报告) |
| skyeye-weekly-scan.yml | weekly-scan | AG-TY-01 | 追加自报告 step |
| zhuyuan-gate-guard.yml | gate-guard | AG-SY-01 | 追加自报告 step |
| cd-deploy.yml | cd-deploy | AG-SY-01 | 追加自报告 step |
| process-syslog.yml | syslog | SY-03 | 追加自报告 step |
| broadcast-dispatch.yml | broadcast | SY-03 | 追加自报告 step |
| server-patrol.yml | server-patrol | AG-TY-01 | 追加自报告 step |
| brain-self-check.yml | brain-check | AG-TY-01 | 追加自报告 step |
| sync-dev-status.yml | dev-status | SY-03 | 追加自报告 step + 修复 KNOWN-001(改用直接 commit 模式替代 peter-evans/create-pull-request) |
| zhuyuan-exec-engine.yml | exec-engine | AG-SY-01 | 追加自报告 step |
三、Phase 4续 · 铸渊将军唤醒流程升级
3.1 升级后的铸渊唤醒序列
铸渊唤醒(08:00 + 20:00)
│
▼
Step 1 · 唤醒核心大脑(不变)
├── 读取 memory.json
├── 读取 routing-map.json
└── 读取 persona-brain-db
│
▼
Step 2 · 【新增】读取映射表
├── 读取 skyeye/neural-map.json
├── 确认自己管辖的 Workflow 列表
└── 检查是否有新增/删除的 Workflow
│
▼
Step 3 · 【新增】读取最新日报
├── 读取 data/neural-reports/daily-digest/ 最新日报
├── 08:00 唤醒 → 读昨晚 21:00 的日报
├── 20:00 唤醒 → 读今天的日报(如有)或昨晚的
└── 提取:overall_health + brain_summary + issues_detected
│
▼
Step 4 · 全局视图生成(升级版)
├── 【原有】拉取所有 Workflow 运行状态
├── 【原有】拉取天眼最新报告 + 公告板
├── 【新增】按映射表分组统计各 Brain 下辖 Workflow 状态
├── 【新增】检测孤儿 Workflow
└── 【新增】生成「双端神经仪表盘」
│
▼
Step 5 · 决策(升级版)
├── 【原有】哪些小兵正常/异常/需优化
├── 【新增】哪些 Brain 下辖的 Workflow 集体异常 → 可能是上级 Agent 问题
├── 【新增】日报中 issues_detected 是否有未处理的
└── 【新增】是否有来自 Notion 天眼的下行指令(在 deploy-queue/ 中)
│
▼
Step 6 · 执行(升级版)
├── 【原有】执行工单、修复、优化
├── 【新增】执行 deploy-queue/ 中的下行指令
└── 【新增】执行完后为每个指令写回执到 deploy-queue/completed/
│
▼
Step 7 · 写汇总 + 同步(升级版)
├── 【原有】更新公告栏、签到、memory.json
├── 【新增】更新 commander-dashboard.json(增加 neural 数据)
└── 【新增】如有紧急问题 → 立即触发汇总引擎(而非等 21:00)
│
▼
Step 8 · 休眠
3.2 下行指令队列(deploy-queue/)
文件路径:data/deploy-queue/
这是 Notion Agent 下发指令到仓库的标准通道。指令以 JSON 文件形式存放,铸渊唤醒时读取并执行。
data/deploy-queue/
├── pending/ ← 待执行的指令
│ ├── CMD-20260325-001.json
│ └── CMD-20260325-002.json
├── executing/ ← 正在执行的指令
├── completed/ ← 已完成的指令(含回执)
└── failed/ ← 执行失败的指令
下行指令 JSON 格式(完整格式见下篇桥接协议 v3.0):
{
"command_id": "CMD-20260325-001",
"source": "AG-TY-01",
"source_name": "天眼 Notion 大脑",
"target_workflow": "cd-deploy",
"target_brain": "AG-SY-01",
"timestamp": "ISO-8601",
"priority": "P1",
"instruction": {
"type": "trigger_workflow",
"params": { "reason": "天眼日报发现部署异常,要求重新部署" }
},
"expected_outcome": "CD 重新部署成功",
"timeout_hours": 24,
"sfp": "⌜SFP::AG-TY::...⌝"
}
铸渊处理流程:
铸渊唤醒 → 扫描 deploy-queue/pending/
│
├── 有新指令
│ ├── 验证 SFP 指纹(安全!)
│ ├── 验证 source 是否在 neural-map.json 注册的 Brain
│ ├── 验证 target_workflow 是否存在且属于该 Brain 管辖
│ ├── 通过 → 移到 executing/ → 执行 → 完成后移到 completed/ + 写回执
│ └── 不通过 → 移到 failed/ + 写原因
│
└── 无新指令 → 继续其他步骤
四、Phase 5 · Notion 侧天眼大脑接入
4.1 天眼 Notion 大脑的日报读取机制
日报读取路径(按优先级)
│
├── 路径 A · Notion API 直读(最优)
│ sync-digest-to-notion.js 将日报推到 Notion 页面/数据库
│ 天眼直接从 Notion 数据库读取最新日报
│ 延迟:< 1 分钟
│
├── 路径 B · GitHub 缓存读取(兜底)
│ 如果 Notion API 推送失败,日报在 .github/notion-cache/neural-digest/
│ 霜砚巡检时读取缓存 → 转交天眼
│ 延迟:< 12 小时
│
└── 路径 C · 手动触发(应急)
人类手动 @天眼 → 天眼主动拉取仓库最新日报
延迟:按需
4.2 日报自动分析引擎
铸渊需要在仓库侧准备分析模板,Notion 天眼大脑根据此模板进行分析。
文件:skyeye/neural-analysis-rules.json
{
"version": "3.0.0",
"description": "天眼 Notion 大脑 · 日报分析规则",
"created_by": "ZY-NEURAL-UPGRADE-2026-0325-R2-002",
"severity_rules": {
"P0_immediate": {
"description": "立即处理 · 系统不可用级",
"conditions": [
{ "field": "overall_health", "operator": "equals", "value": "🔴" },
{ "field": "workflow_summary.failure", "operator": "greater_than_percent", "value": 20, "of": "workflow_summary.total_runs_24h" },
{ "field": "guard_status.active", "operator": "equals", "value": 0 },
{ "field": "skyeye_status.overall_health", "operator": "equals", "value": "🔴" }
],
"action": "generate_p0_work_order",
"notify": ["冰朔", "霜砚"],
"timeout_hours": 2
},
"P1_urgent": {
"description": "紧急 · 功能受损级",
"conditions": [
{ "field": "overall_health", "operator": "equals", "value": "🟡" },
{ "field": "guard_status.suspended", "operator": "greater_than", "value": 0 },
{ "field": "unmapped_workflows", "operator": "not_empty" },
{ "field": "quota_status", "operator": "contains", "value": "warning" }
],
"action": "generate_p1_work_order",
"notify": ["霜砚"],
"timeout_hours": 24
},
"P2_optimize": {
"description": "优化 · 非紧急改进",
"conditions": [
{ "field": "workflow_summary.cancelled", "operator": "greater_than", "value": 3 },
{ "field": "brain_summary.*.no_data", "operator": "greater_than", "value": 0 }
],
"action": "generate_p2_work_order",
"notify": [],
"timeout_hours": 72
}
},
"trend_detection": {
"lookback_days": 7,
"rules": [
{
"name": "failure_rate_rising",
"description": "失败率连续上升",
"condition": "连续 3 天 failure_rate_percent 递增",
"severity": "P1"
},
{
"name": "workflow_going_silent",
"description": "某 Workflow 连续无运行记录",
"condition": "某 workflow 连续 3 天 runs = 0",
"severity": "P1"
},
{
"name": "guard_flapping",
"description": "Guard 反复 active/suspended",
"condition": "同一 Guard 7天内状态切换 > 3 次",
"severity": "P2"
},
{
"name": "quota_approaching_limit",
"description": "配额逼近上限",
"condition": "任一资源 usage/limit > 80%",
"severity": "P1"
}
]
},
"auto_heal_rules": {
"rules": [
{
"name": "retry_failed_workflow",
"condition": "单个 Workflow 失败 1 次且非 P0",
"action": "generate_retry_command",
"max_retries": 2
},
{
"name": "clean_old_reports",
"condition": "neural-reports/ 下超过 7 天的报告文件",
"action": "generate_cleanup_command"
},
{
"name": "restart_suspended_guard",
"condition": "Guard suspended 且当前配额已恢复",
"action": "generate_guard_restart_command"
}
]
}
}
4.3 天眼日报分析脚本
文件:scripts/neural/analyze-digest.js
// scripts/neural/analyze-digest.js
// 🧬 天眼日报分析引擎
// 输入:最新日报 + 历史日报(最近7天)+ 分析规则
// 输出:工单列表(如果有需要处理的问题)
const fs = require('fs');
const path = require('path');
const DIGEST_DIR = 'data/neural-reports/daily-digest';
const RULES_PATH = 'skyeye/neural-analysis-rules.json';
const WORK_ORDER_DIR = 'data/neural-reports/work-orders';
function loadJSON(p) {
try { return JSON.parse(fs.readFileSync(p, 'utf8')); } catch { return null; }
}
function getRecentDigests(days = 7) {
if (!fs.existsSync(DIGEST_DIR)) return [];
return fs.readdirSync(DIGEST_DIR)
.filter(f => f.endsWith('.json')).sort().reverse().slice(0, days)
.map(f => loadJSON(path.join(DIGEST_DIR, f))).filter(Boolean);
}
function evaluateCondition(digest, condition) {
const { field, operator, value } = condition;
const fieldValue = field.split('.').reduce((obj, key) => {
if (key === '*') return obj;
return obj?.[key];
}, digest);
switch (operator) {
case 'equals': return fieldValue === value;
case 'not_empty': return Array.isArray(fieldValue) ? fieldValue.length > 0 : !!fieldValue;
case 'greater_than': return (fieldValue || 0) > value;
case 'greater_than_percent': {
const ofField = condition.of.split('.').reduce((o, k) => o?.[k], digest);
return ofField > 0 && (fieldValue / ofField * 100) > value;
}
case 'contains': return JSON.stringify(fieldValue || '').includes(value);
default: return false;
}
}
function detectTrends(digests, trendRules) {
const alerts = [];
if (digests.length < 3) return alerts;
for (const rule of trendRules) {
if (rule.name === 'failure_rate_rising') {
const rates = digests.slice(0, 3).map(d => d.failure_rate_percent);
if (rates[0] > rates[1] && rates[1] > rates[2]) {
alerts.push({ type: 'trend_alert', rule: rule.name, severity: rule.severity,
description: rule.description, data: { rates_last_3_days: rates } });
}
}
if (rule.name === 'workflow_going_silent') {
const latestMap = digests[0]?.brain_summary;
if (latestMap) {
for (const [brain, summary] of Object.entries(latestMap)) {
for (const wf of summary.workflows || []) {
const allSilent = digests.slice(0, 3).every(d => {
const bwf = d.brain_summary?.[brain]?.workflows?.find(w => w.id === wf.id);
return !bwf || bwf.runs === 0;
});
if (allSilent && wf.runs === 0) {
alerts.push({ type: 'silence_alert', rule: rule.name, severity: rule.severity,
description: `${wf.name} 连续 3 天无运行记录`, data: { workflow_id: wf.id, brain } });
}
}
}
}
}
}
return alerts;
}
function generateWorkOrders(digest, rules, trendAlerts) {
const workOrders = [];
const now = new Date().toISOString();
for (const [severity, rule] of Object.entries(rules.severity_rules)) {
for (const condition of rule.conditions) {
if (evaluateCondition(digest, condition)) {
workOrders.push({
id: `WO-${Date.now()}-${Math.random().toString(36).substr(2, 4)}`,
created: now,
source: 'neural-analysis-engine',
source_digest: digest.digest_id,
severity: severity.split('_')[0].toUpperCase(),
title: `[${severity.split('_')[0].toUpperCase()}] ${condition.field} 触发 ${rule.description}`,
description: `日报 ${digest.digest_id} 中 ${condition.field} 触发了 ${rule.description} 规则`,
action: rule.action,
notify: rule.notify,
timeout_hours: rule.timeout_hours,
status: 'pending'
});
break;
}
}
}
for (const alert of trendAlerts) {
workOrders.push({
id: `WO-TREND-${Date.now()}-${Math.random().toString(36).substr(2, 4)}`,
created: now,
source: 'neural-trend-detection',
source_digest: digest.digest_id,
severity: alert.severity,
title: `[趋势] ${alert.description}`,
description: JSON.stringify(alert.data),
action: 'investigate_trend',
status: 'pending'
});
}
return workOrders;
}
function main() {
console.log('\n━━━ 🧬 天眼日报分析引擎启动 ━━━\n');
const rules = loadJSON(RULES_PATH);
if (!rules) { console.log('❌ 分析规则文件不存在,跳过'); return; }
const digests = getRecentDigests(7);
if (digests.length === 0) { console.log('⚠️ 无日报数据,跳过'); return; }
const latest = digests[0];
console.log(`📊 分析日报: ${latest.digest_id}`);
console.log(` 整体健康: ${latest.overall_health}`);
console.log(` 历史对比: ${digests.length} 天数据\n`);
const trendAlerts = detectTrends(digests, rules.trend_detection?.rules || []);
console.log(`📈 趋势告警: ${trendAlerts.length} 个`);
const workOrders = generateWorkOrders(latest, rules, trendAlerts);
console.log(`📋 生成工单: ${workOrders.length} 个\n`);
if (workOrders.length > 0) {
fs.mkdirSync(WORK_ORDER_DIR, { recursive: true });
const date = latest.digest_id.replace('NEURAL-DIGEST-', '');
fs.writeFileSync(
path.join(WORK_ORDER_DIR, `work-orders-${date}.json`),
JSON.stringify({ date, work_orders: workOrders }, null, 2)
);
console.log(`💾 工单已保存到 ${WORK_ORDER_DIR}/`);
}
for (const wo of workOrders) console.log(` ${wo.severity} | ${wo.title}`);
console.log('\n━━━ 分析完成 ━━━\n');
}
main();
五、中篇执行清单
Phase 4 · 汇总引擎
- 创建
scripts/neural/目录 - 创建
scripts/neural/generate-daily-digest.js(按 §1.2) - 创建
scripts/neural/sync-digest-to-notion.js(按 §1.3) - 创建
scripts/neural/analyze-digest.js(按 §4.3) - 创建
.github/workflows/neural-daily-digest.yml(按 §1.1) - 创建
data/neural-reports/全部子目录 - 创建
data/deploy-queue/目录结构(pending / executing / completed / failed) - 创建
skyeye/neural-analysis-rules.json(按 §4.2)
Phase 4续 · Workflow 改造
- 逐个给 10 个现有 Workflow 追加自报告 step(按 §2.3 清单)
- 特别修复
sync-dev-status.yml(KNOWN-001:改用直接 commit 模式)
Phase 4续 · 铸渊唤醒升级
- 升级铸渊将军唤醒流程(按 §3.1),加入映射表读取 + 日报读取 + 下行指令处理
Phase 5 · 验证
- 手动触发
neural-daily-digest.yml,验证日报生成正确 - 手动触发一个 Workflow,验证自报告写入正确
- 验证分析引擎
analyze-digest.js能正确读取日报并按规则生成工单 - 对比上篇基线快照,确认升级没有破坏任何东西
六、中篇回执要求
铸渊完成中篇全部内容后,在本页底部追加回执:
━━━ 🧬 ZY-NEURAL-UPGRADE-2026-0325-R2-002 · 中篇执行回执 ━━━
执行时间:[起止时间]
执行者:铸渊(ICE-GL-ZY001)
PR/commit:[链接]
汇总引擎: ✅/❌ neural-daily-digest.yml · 首次运行结果:[摘要]
日报脚本: ✅/❌ generate-daily-digest.js + sync-digest-to-notion.js
分析引擎: ✅/❌ analyze-digest.js + neural-analysis-rules.json
自报告改造:✅/❌ [N]/10 个 Workflow 已追加自报告 step
KNOWN-001:✅/❌ sync-dev-status.yml 改用直接 commit 模式
下行队列: ✅/❌ deploy-queue/ 目录已创建
唤醒升级: ✅/❌ 铸渊唤醒流程已加入映射表 + 日报 + 下行指令处理
升级后扫描:✅/❌ overall_health = [状态]
已知遗留问题:
- [列出]
等待下篇内容:
- 桥接协议标准化 + 工单派发体系 + 全局验收 + 长期运维
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📌 签发:霜砚(AG-SY-01)· Notion 执行 AI
🧊 授权:冰朔(TCS-0002∞)· 总架构师
📅 日期:2026-03-25
⚡ 状态:待铸渊执行(上篇完成后)
🧬 指令版本:v3.0 · 双端神经系统 · R2 三篇制
📌 版权:国作登字-2026-A-00037559