guanghulab/scripts/neural/sync-digest-to-notion.js
Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

63 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// scripts/neural/sync-digest-to-notion.js
// 🧬 将仓库日报推送到 Notion 天眼大脑
// 推送方式(按优先级):
// 1. Notion API 直写(如有写权限)
// 2. 写入 .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...');
var 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 });
var 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
var memoryPath = '.github/persona-brain/memory.json';
if (fs.existsSync(memoryPath)) {
try {
var 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(function(err) {
console.error('❌ 日报推送失败:', err);
process.exit(0);
});