feat: 建立执行层状态同步系统

新增模块:
- core/execution-sync: 执行层状态采集与同步
- docs/execution-layer-map.md: 执行层结构地图
- docs/execution-status.md: 执行层状态报告(自动生成)
- .github/workflows/execution-sync.yml: 每日状态同步工作流

更新:
- connectors/notion-sync: 新增 syncExecutionStatus 方法
- core/system-check: 新增 execution-sync 模块检查
- brain/master-brain.md: 新增执行同步模块入口
- brain/system-health.json: 新增 execution_sync 状态
- package.json: 新增 core:sync 脚本

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-14 06:38:13 +00:00
parent 54805c2bd6
commit 70f678506e
9 changed files with 537 additions and 2 deletions

53
.github/workflows/execution-sync.yml vendored Normal file
View File

@ -0,0 +1,53 @@
name: "📡 铸渊 · 执行层状态同步"
on:
schedule:
- cron: '0 3 * * *' # 每日 UTC 03:00 (北京时间 11:00)
workflow_dispatch:
permissions:
contents: write
jobs:
execution-sync:
name: 执行层状态采集与同步
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# ── Step 1: 运行系统自检 ──
- name: 运行系统自检
run: node core/system-check
# ── Step 2: 生成执行状态报告 ──
- name: 生成执行状态报告
run: node core/execution-sync report
# ── Step 3: 同步到 Notion ──
- name: 同步执行状态到 Notion
if: ${{ secrets.NOTION_TOKEN != '' }}
env:
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
EXECUTION_LOG_DB_ID: ${{ secrets.EXECUTION_LOG_DB_ID }}
run: node core/execution-sync sync
# ── Step 4: 提交状态报告 ──
- name: 提交状态报告
run: |
git config user.name "铸渊 Execution Sync"
git config user.email "actions@guanghulab.com"
git add docs/execution-status.md
if git diff --cached --quiet; then
echo "📌 无变更需要提交"
else
git commit -m "📡 Execution Sync: 更新执行状态报告 [skip ci]"
git push
echo "✅ 已提交执行状态报告"
fi

View File

@ -67,10 +67,13 @@
| 广播监听 | `core/broadcast-listener/index.js` | 广播监听与任务解析 |
| 任务队列 | `core/task-queue/index.js` | 任务调度与执行 |
| 系统自检 | `core/system-check/index.js` | 仓库自检系统 |
| 执行同步 | `core/execution-sync/index.js` | 执行层状态同步 |
| Notion 同步 | `connectors/notion-sync/index.js` | 双向数据同步 |
| 模型路由 | `connectors/model-router/index.js` | 模型调用路由 |
| 结构地图 | `docs/repo-structure-map.md` | 仓库结构文档 |
| 桥接地图 | `docs/notion-bridge-map.md` | Notion 桥接文档 |
| 执行层地图 | `docs/execution-layer-map.md` | 执行层结构文档 |
| 执行状态 | `docs/execution-status.md` | 执行层状态报告(自动生成) |
---

View File

@ -7,6 +7,7 @@
"system_health": "normal",
"execution_layer_status": "stable",
"notion_bridge": "active",
"execution_sync": "enabled",
"task_queue": "running",
"brain_integrity": {
"complete": true,
@ -17,7 +18,8 @@
"core_modules": {
"broadcast_listener": "enabled",
"task_queue": "enabled",
"system_check": "enabled"
"system_check": "enabled",
"execution_sync": "enabled"
},
"connectors": {
"notion_sync": "enabled",

View File

@ -165,6 +165,61 @@ function writeLocalLog(logEntry) {
console.log('📝 日志已写入本地');
}
/**
* 同步执行层状态到 Notion
*/
async function syncExecutionStatus(statusData) {
const dbId = process.env.EXECUTION_LOG_DB_ID;
if (!dbId) {
console.log('⚠️ EXECUTION_LOG_DB_ID 未设置,执行状态仅写入本地');
writeLocalLog({
task_id: `execution-status-${new Date().toISOString().slice(0, 10)}`,
status: statusData.execution_layer_status || 'stable',
type: 'execution_status',
data: statusData
});
return;
}
console.log('📡 同步执行层状态到 Notion...');
const summary = [
`version: v${statusData.version || 'unknown'}`,
`modules: ${(statusData.core_modules || []).filter(m => m.status === 'enabled').length}/${(statusData.core_modules || []).length}`,
`connectors: ${(statusData.connectors || []).filter(c => c.status === 'enabled').length}/${(statusData.connectors || []).length}`,
`workflows: ${statusData.workflows?.count || 0}`,
`queue: ${statusData.task_queue?.total || 0} total / ${statusData.task_queue?.pending || 0} pending`
].join(' | ');
try {
await notionRequest('POST', 'pages', {
parent: { database_id: dbId },
properties: {
Name: { title: [{ text: { content: `Execution Status · ${new Date().toISOString().slice(0, 10)}` } }] },
Status: { select: { name: statusData.execution_layer_status || 'stable' } },
Executor: { rich_text: [{ text: { content: 'zhuyuan' } }] },
Timestamp: { rich_text: [{ text: { content: statusData.timestamp || new Date().toISOString() } }] }
},
children: [{
object: 'block',
type: 'paragraph',
paragraph: {
rich_text: [{ text: { content: summary } }]
}
}]
});
console.log('✅ 执行层状态已同步到 Notion');
} catch (err) {
console.error(`⚠️ Notion 同步失败,回退本地: ${err.message}`);
writeLocalLog({
task_id: `execution-status-${new Date().toISOString().slice(0, 10)}`,
status: statusData.execution_layer_status || 'stable',
type: 'execution_status',
data: statusData
});
}
}
/**
* 检查 Notion 连接状态
*/
@ -206,4 +261,4 @@ if (require.main === module) {
})();
}
module.exports = { pullBroadcasts, pushExecutionLog, writeLocalLog, checkStatus, notionRequest };
module.exports = { pullBroadcasts, pushExecutionLog, syncExecutionStatus, writeLocalLog, checkStatus, notionRequest };

View File

@ -0,0 +1,267 @@
/**
* core/execution-sync 执行层状态同步模块
*
* 职责
* - 扫描仓库结构采集执行层状态
* - 生成执行层状态报告docs/execution-status.md
* - 同步执行状态到 Notion 主脑
*
* 执行逻辑
* 扫描仓库 生成状态报告 同步到 Notion
*
* 调用方式
* node core/execution-sync [report|sync|status]
*/
const fs = require('fs');
const path = require('path');
const ROOT = path.resolve(__dirname, '../..');
/**
* 采集核心模块状态
*/
function collectCoreModules() {
const modules = [
{ name: 'broadcast-listener', path: 'core/broadcast-listener/index.js' },
{ name: 'task-queue', path: 'core/task-queue/index.js' },
{ name: 'system-check', path: 'core/system-check/index.js' },
{ name: 'execution-sync', path: 'core/execution-sync/index.js' }
];
return modules.map(m => ({
...m,
status: fs.existsSync(path.join(ROOT, m.path)) ? 'enabled' : 'missing'
}));
}
/**
* 采集连接器状态
*/
function collectConnectors() {
const connectors = [
{ name: 'notion-sync', path: 'connectors/notion-sync/index.js' },
{ name: 'model-router', path: 'connectors/model-router/index.js' }
];
return connectors.map(c => ({
...c,
status: fs.existsSync(path.join(ROOT, c.path)) ? 'enabled' : 'missing'
}));
}
/**
* 采集自动化工作流状态
*/
function collectWorkflows() {
const workflowDir = path.join(ROOT, '.github/workflows');
if (!fs.existsSync(workflowDir)) return { count: 0, files: [] };
const files = fs.readdirSync(workflowDir).filter(
f => f.endsWith('.yml') || f.endsWith('.yaml')
);
return { count: files.length, files };
}
/**
* 采集任务队列状态
*/
function collectQueueStatus() {
const queuePath = path.join(ROOT, 'core/task-queue/queue.json');
if (!fs.existsSync(queuePath)) {
return { total: 0, pending: 0, running: 0, completed: 0, failed: 0 };
}
try {
const queue = JSON.parse(fs.readFileSync(queuePath, 'utf-8'));
const tasks = queue.tasks || [];
return {
total: tasks.length,
pending: tasks.filter(t => t.status === 'pending').length,
running: tasks.filter(t => t.status === 'running').length,
completed: tasks.filter(t => t.status === 'completed').length,
failed: tasks.filter(t => t.status === 'failed').length
};
} catch {
return { total: 0, pending: 0, running: 0, completed: 0, failed: 0 };
}
}
/**
* 读取系统版本
*/
function getSystemVersion() {
const healthPath = path.join(ROOT, 'brain/system-health.json');
if (!fs.existsSync(healthPath)) return 'unknown';
try {
const health = JSON.parse(fs.readFileSync(healthPath, 'utf-8'));
return health.version || 'unknown';
} catch {
return 'unknown';
}
}
/**
* 生成完整的执行层状态快照
*/
function collectStatus() {
const now = new Date();
const beijingTime = new Date(now.getTime() + 8 * 60 * 60 * 1000)
.toISOString().replace('T', ' ').slice(0, 19) + '+08:00';
return {
timestamp: beijingTime,
version: getSystemVersion(),
core_modules: collectCoreModules(),
connectors: collectConnectors(),
workflows: collectWorkflows(),
task_queue: collectQueueStatus(),
execution_layer_status: 'stable',
notion_bridge: 'active',
execution_sync: 'enabled'
};
}
/**
* 生成 Markdown 状态报告
*/
function generateReport(statusData) {
const s = statusData || collectStatus();
const coreTable = s.core_modules.map(m =>
`| ${m.name} | \`${m.path}\` | ${m.status === 'enabled' ? '✅ Enabled' : '❌ Missing'} |`
).join('\n');
const connTable = s.connectors.map(c =>
`| ${c.name} | \`${c.path}\` | ${c.status === 'enabled' ? '✅ Enabled' : '❌ Missing'} |`
).join('\n');
const q = s.task_queue;
const md = `# 执行层状态报告 — execution-status.md
> 铸渊执行层自动生成 · TCS-0002
> 更新时间${s.timestamp}
---
## 系统概览
| 指标 | 状态 |
|------|------|
| 系统版本 | v${s.version} |
| 执行层状态 | ${s.execution_layer_status === 'stable' ? '✅ Stable' : '⚠️ ' + s.execution_layer_status} |
| Notion 桥接 | ${s.notion_bridge === 'active' ? '✅ Active' : '❌ Inactive'} |
| 执行同步 | ${s.execution_sync === 'enabled' ? '✅ Enabled' : '❌ Disabled'} |
| 工作流数量 | ${s.workflows.count} |
---
## 核心模块状态
| 模块 | 路径 | 状态 |
|------|------|------|
${coreTable}
---
## 连接器状态
| 连接器 | 路径 | 状态 |
|--------|------|------|
${connTable}
---
## 任务队列状态
| 指标 | 数量 |
|------|------|
| 总计 | ${q.total} |
| 待处理 | ${q.pending} |
| 执行中 | ${q.running} |
| 已完成 | ${q.completed} |
| 失败 | ${q.failed} |
---
## 执行闭环
\`\`\`
Notion 广播 broadcast-listener task-queue 执行
execution-sync notion-sync Notion 主脑更新
\`\`\`
`;
return md;
}
/**
* 写入状态报告文件
*/
function writeReport() {
const statusData = collectStatus();
const md = generateReport(statusData);
const reportPath = path.join(ROOT, 'docs/execution-status.md');
fs.writeFileSync(reportPath, md, 'utf-8');
console.log(`📝 执行状态报告已生成: docs/execution-status.md`);
return statusData;
}
/**
* 同步执行状态到 Notion
*/
async function syncToNotion(statusData) {
let notionSync;
try {
notionSync = require('../../connectors/notion-sync');
} catch {
console.log('⚠️ connectors/notion-sync 模块未找到,跳过 Notion 同步');
return;
}
console.log('📡 同步执行状态到 Notion...');
await notionSync.pushExecutionLog({
task_id: `execution-sync-${new Date().toISOString().slice(0, 10)}`,
status: statusData.execution_layer_status,
message: `v${statusData.version} | modules: ${statusData.core_modules.length} | workflows: ${statusData.workflows.count} | queue: ${statusData.task_queue.total}`
});
}
// CLI 入口
if (require.main === module) {
const cmd = process.argv[2] || 'report';
switch (cmd) {
case 'report': {
writeReport();
break;
}
case 'sync': {
const statusData = writeReport();
syncToNotion(statusData).catch(err => {
console.error(`❌ Notion 同步失败: ${err.message}`);
});
break;
}
case 'status': {
const s = collectStatus();
console.log('📊 执行层状态:');
console.log(` 版本: v${s.version}`);
console.log(` 执行层: ${s.execution_layer_status}`);
console.log(` Notion 桥接: ${s.notion_bridge}`);
console.log(` 执行同步: ${s.execution_sync}`);
console.log(` 核心模块: ${s.core_modules.filter(m => m.status === 'enabled').length}/${s.core_modules.length}`);
console.log(` 连接器: ${s.connectors.filter(c => c.status === 'enabled').length}/${s.connectors.length}`);
console.log(` 工作流: ${s.workflows.count}`);
console.log(` 任务队列: ${s.task_queue.total} 总 / ${s.task_queue.pending} 待处理`);
break;
}
default:
console.log('用法: node core/execution-sync [report|sync|status]');
}
}
module.exports = { collectStatus, generateReport, writeReport, syncToNotion };

View File

@ -28,6 +28,7 @@ const REQUIRED_DIRS = [
'core/broadcast-listener',
'core/task-queue',
'core/system-check',
'core/execution-sync',
'connectors/notion-sync',
'connectors/model-router',
'.github/workflows',
@ -112,6 +113,7 @@ function checkCoreModules() {
{ name: 'broadcast-listener', path: 'core/broadcast-listener/index.js' },
{ name: 'task-queue', path: 'core/task-queue/index.js' },
{ name: 'system-check', path: 'core/system-check/index.js' },
{ name: 'execution-sync', path: 'core/execution-sync/index.js' },
{ name: 'notion-sync', path: 'connectors/notion-sync/index.js' },
{ name: 'model-router', path: 'connectors/model-router/index.js' }
];

View File

@ -0,0 +1,94 @@
# 执行层结构地图 — execution-layer-map.md
> 铸渊执行层状态同步系统产物 · TCS-0002∞
> 生成时间2026-03-14
---
## 执行层系统结构
```
零点原核(语言观察层)
数字地球主控台Notion 主脑 / 曜冥)
系统广播
仓库执行层(铸渊)
自动化执行系统
执行层状态同步
Notion 主脑更新
```
---
## 核心执行模块
| 模块 | 路径 | 职责 |
|------|------|------|
| 广播监听 | `core/broadcast-listener/index.js` | 监听并解析 Notion 广播为可执行任务 |
| 任务队列 | `core/task-queue/index.js` | 任务入队、调度、优先级管理 |
| 系统自检 | `core/system-check/index.js` | 仓库结构完整性检查 |
| 执行同步 | `core/execution-sync/index.js` | 生成执行状态报告并同步到 Notion |
---
## 自动化模块
| 工作流 | 触发方式 | 职责 |
|--------|----------|------|
| `daily-maintenance.yml` | cron `0 2 * * *` | 每日巡检与 system-health 更新 |
| `zhuyuan-daily-selfcheck.yml` | cron `0 0 * * *` | 铸渊每日自检 |
| `execution-sync.yml` | cron `0 3 * * *` | 执行层状态同步到 Notion |
| `notion-heartbeat.yml` | cron `*/5 * * * *` | 工单心跳监控 |
| `brain-sync.yml` | workflow_dispatch | 大脑数据同步 |
---
## Notion 连接模块
| 模块 | 路径 | 方向 | 职责 |
|------|------|------|------|
| Notion 同步 | `connectors/notion-sync/index.js` | 双向 | 广播拉取 / 日志写回 / 状态同步 |
| 模型路由 | `connectors/model-router/index.js` | 出站 | 统一模型调用入口 |
| Notion 桥接 | `scripts/notion-bridge.js` | 上行 | SYSLOG 上报 / 变更同步 |
| 信号桥 | `scripts/notion-signal-bridge.js` | 下行 | 工单轮询 / 信号执行 |
| 心跳监控 | `scripts/notion-heartbeat.js` | 双向 | 超时检测 / 自动重试 |
---
## 任务执行模块
| 脚本 | 职责 |
|------|------|
| `scripts/process-broadcasts.js` | 处理广播JSON 规则 + MD 成长日志) |
| `scripts/daily-check.js` | 文件完整性 / HLI 覆盖率 / Schema 验证 |
| `scripts/zhuyuan-daily-selfcheck.js` | 大脑文件验证 / FAQ 去重 / 记忆修剪 |
| `scripts/distribute-broadcasts.js` | 广播分发 |
| `scripts/generate-repo-map.js` | 仓库结构索引生成 |
| `scripts/generate-system-health.js` | 系统健康报告生成 |
---
## 执行闭环
```
Notion 广播(主脑下发)
broadcast-listener广播监听
task-queue任务排队
执行器运行
execution-sync状态采集
connectors/notion-sync状态回写
Notion 主脑更新
生成下一任务
```

58
docs/execution-status.md Normal file
View File

@ -0,0 +1,58 @@
# 执行层状态报告 — execution-status.md
> 铸渊执行层自动生成 · TCS-0002∞
> 更新时间2026-03-14 14:37:53+08:00
---
## 系统概览
| 指标 | 状态 |
|------|------|
| 系统版本 | v5.0 |
| 执行层状态 | ✅ Stable |
| Notion 桥接 | ✅ Active |
| 执行同步 | ✅ Enabled |
| 工作流数量 | 43 |
---
## 核心模块状态
| 模块 | 路径 | 状态 |
|------|------|------|
| broadcast-listener | `core/broadcast-listener/index.js` | ✅ Enabled |
| task-queue | `core/task-queue/index.js` | ✅ Enabled |
| system-check | `core/system-check/index.js` | ✅ Enabled |
| execution-sync | `core/execution-sync/index.js` | ✅ Enabled |
---
## 连接器状态
| 连接器 | 路径 | 状态 |
|--------|------|------|
| notion-sync | `connectors/notion-sync/index.js` | ✅ Enabled |
| model-router | `connectors/model-router/index.js` | ✅ Enabled |
---
## 任务队列状态
| 指标 | 数量 |
|------|------|
| 总计 | 0 |
| 待处理 | 0 |
| 执行中 | 0 |
| 已完成 | 0 |
| 失败 | 0 |
---
## 执行闭环
```
Notion 广播 → broadcast-listener → task-queue → 执行
execution-sync → notion-sync → Notion 主脑更新
```

View File

@ -34,6 +34,7 @@
"core:listen": "node core/broadcast-listener",
"core:queue": "node core/task-queue status",
"core:check": "node core/system-check",
"core:sync": "node core/execution-sync report",
"connector:notion": "node connectors/notion-sync status",
"connector:model": "node connectors/model-router"
},