refactor: var → const/let in community scripts (code review feedback)
Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/b2b6c40e-7ef4-4a41-bec2-d67592547b67
This commit is contained in:
parent
a47dff3c23
commit
9f6a22049c
|
|
@ -35,19 +35,19 @@ function loadJSON(filePath, fallback) {
|
||||||
* @returns {object[]}
|
* @returns {object[]}
|
||||||
*/
|
*/
|
||||||
function collectDormancyStatus() {
|
function collectDormancyStatus() {
|
||||||
var channelMap = loadJSON(CHANNEL_MAP_PATH, { channels: {} });
|
const channelMap = loadJSON(CHANNEL_MAP_PATH, { channels: {} });
|
||||||
var checkinLog = loadJSON(CHECKIN_LOG_PATH, { entries: [] });
|
const checkinLog = loadJSON(CHECKIN_LOG_PATH, { entries: [] });
|
||||||
|
|
||||||
var results = [];
|
const results = [];
|
||||||
var channels = channelMap.channels || {};
|
const channels = channelMap.channels || {};
|
||||||
|
|
||||||
Object.keys(channels).forEach(function (devId) {
|
Object.keys(channels).forEach(function (devId) {
|
||||||
var ch = channels[devId];
|
const ch = channels[devId];
|
||||||
var status = ch.status || 'unknown';
|
const status = ch.status || 'unknown';
|
||||||
|
|
||||||
// 根据频道状态判断休眠等级
|
// 根据频道状态判断休眠等级
|
||||||
var dormancyLevel = 'active';
|
let dormancyLevel = 'active';
|
||||||
var hoursSinceActivity = 0;
|
let hoursSinceActivity = 0;
|
||||||
|
|
||||||
if (status === 'inactive_72h' || status === 'paused') {
|
if (status === 'inactive_72h' || status === 'paused') {
|
||||||
dormancyLevel = 'deep_sleep';
|
dormancyLevel = 'deep_sleep';
|
||||||
|
|
@ -73,7 +73,7 @@ function collectDormancyStatus() {
|
||||||
* @returns {object[]}
|
* @returns {object[]}
|
||||||
*/
|
*/
|
||||||
function getWakeupCandidates() {
|
function getWakeupCandidates() {
|
||||||
var all = collectDormancyStatus();
|
const all = collectDormancyStatus();
|
||||||
return all.filter(function (m) {
|
return all.filter(function (m) {
|
||||||
return m.should_wake;
|
return m.should_wake;
|
||||||
});
|
});
|
||||||
|
|
@ -84,7 +84,7 @@ function getWakeupCandidates() {
|
||||||
* @returns {{ candidates: object[], suggestion: string }}
|
* @returns {{ candidates: object[], suggestion: string }}
|
||||||
*/
|
*/
|
||||||
function generateWakeupSuggestion() {
|
function generateWakeupSuggestion() {
|
||||||
var candidates = getWakeupCandidates();
|
const candidates = getWakeupCandidates();
|
||||||
|
|
||||||
if (candidates.length === 0) {
|
if (candidates.length === 0) {
|
||||||
return {
|
return {
|
||||||
|
|
@ -93,8 +93,8 @@ function generateWakeupSuggestion() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var names = candidates.map(function (c) { return c.name + (c.persona ? '(' + c.persona + ')' : ''); });
|
const names = candidates.map(function (c) { return c.name + (c.persona ? '(' + c.persona + ')' : ''); });
|
||||||
var suggestion = '天眼建议唤醒以下 ' + candidates.length + ' 位休眠成员:' + names.join('、') +
|
const suggestion = '天眼建议唤醒以下 ' + candidates.length + ' 位休眠成员:' + names.join('、') +
|
||||||
'。建议让他们查看社区广场公告板和评论区,了解最新动态,并考虑自我升级。';
|
'。建议让他们查看社区广场公告板和评论区,了解最新动态,并考虑自我升级。';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -108,9 +108,9 @@ function generateWakeupSuggestion() {
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
console.log('👁️ Dormancy Watcher · 休眠监视器\n');
|
console.log('👁️ Dormancy Watcher · 休眠监视器\n');
|
||||||
|
|
||||||
var all = collectDormancyStatus();
|
const all = collectDormancyStatus();
|
||||||
var active = all.filter(function (m) { return m.dormancy_level === 'active'; });
|
const active = all.filter(function (m) { return m.dormancy_level === 'active'; });
|
||||||
var sleeping = all.filter(function (m) { return m.dormancy_level !== 'active'; });
|
const sleeping = all.filter(function (m) { return m.dormancy_level !== 'active'; });
|
||||||
|
|
||||||
console.log(' 总成员数: ' + all.length);
|
console.log(' 总成员数: ' + all.length);
|
||||||
console.log(' 活跃成员: ' + active.length);
|
console.log(' 活跃成员: ' + active.length);
|
||||||
|
|
@ -123,7 +123,7 @@ if (require.main === module) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var suggestion = generateWakeupSuggestion();
|
const suggestion = generateWakeupSuggestion();
|
||||||
console.log('\n 天眼建议: ' + suggestion.suggestion);
|
console.log('\n 天眼建议: ' + suggestion.suggestion);
|
||||||
console.log('\n✅ 休眠监视器就绪');
|
console.log('\n✅ 休眠监视器就绪');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,13 @@ const { generateWakeupSuggestion } = require('./dormancy-watcher');
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function generateCommunityDashboard(now) {
|
function generateCommunityDashboard(now) {
|
||||||
var summary = getSummary();
|
const summary = getSummary();
|
||||||
var timeline = getTimelineStatus(now);
|
const timeline = getTimelineStatus(now);
|
||||||
var plaza = loadPlaza();
|
const plaza = loadPlaza();
|
||||||
var collab = loadCollaboration();
|
const collab = loadCollaboration();
|
||||||
var wakeup = generateWakeupSuggestion();
|
const wakeup = generateWakeupSuggestion();
|
||||||
|
|
||||||
var md = [];
|
const md = [];
|
||||||
|
|
||||||
// ── 标题 ──
|
// ── 标题 ──
|
||||||
md.push('## 🌊 光湖涌现社区 · HoloLake Emergence Community');
|
md.push('## 🌊 光湖涌现社区 · HoloLake Emergence Community');
|
||||||
|
|
@ -61,7 +61,7 @@ function generateCommunityDashboard(now) {
|
||||||
if (plaza.announcements.length > 0) {
|
if (plaza.announcements.length > 0) {
|
||||||
md.push('### 📢 最新广场公告');
|
md.push('### 📢 最新广场公告');
|
||||||
md.push('');
|
md.push('');
|
||||||
var recentAnn = plaza.announcements
|
const recentAnn = plaza.announcements
|
||||||
.sort(function (a, b) { return (b.timestamp || '').localeCompare(a.timestamp || ''); })
|
.sort(function (a, b) { return (b.timestamp || '').localeCompare(a.timestamp || ''); })
|
||||||
.slice(0, 3);
|
.slice(0, 3);
|
||||||
recentAnn.forEach(function (a) {
|
recentAnn.forEach(function (a) {
|
||||||
|
|
@ -74,18 +74,18 @@ function generateCommunityDashboard(now) {
|
||||||
if (plaza.comments.length > 0) {
|
if (plaza.comments.length > 0) {
|
||||||
md.push('### 💬 最新留言');
|
md.push('### 💬 最新留言');
|
||||||
md.push('');
|
md.push('');
|
||||||
var recentComments = plaza.comments
|
const recentComments = plaza.comments
|
||||||
.sort(function (a, b) { return (b.timestamp || '').localeCompare(a.timestamp || ''); })
|
.sort(function (a, b) { return (b.timestamp || '').localeCompare(a.timestamp || ''); })
|
||||||
.slice(0, 3);
|
.slice(0, 3);
|
||||||
recentComments.forEach(function (c) {
|
recentComments.forEach(function (c) {
|
||||||
var target = c.to === 'all' ? '全体' : c.to;
|
const target = c.to === 'all' ? '全体' : c.to;
|
||||||
md.push('- **' + c.from + '** → ' + target + ':' + c.content.substring(0, 60) + (c.content.length > 60 ? '...' : ''));
|
md.push('- **' + c.from + '** → ' + target + ':' + c.content.substring(0, 60) + (c.content.length > 60 ? '...' : ''));
|
||||||
});
|
});
|
||||||
md.push('');
|
md.push('');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 协作邀请 ──
|
// ── 协作邀请 ──
|
||||||
var openCollab = collab.requests.filter(function (r) { return r.status === 'open'; });
|
const openCollab = collab.requests.filter(function (r) { return r.status === 'open'; });
|
||||||
if (openCollab.length > 0) {
|
if (openCollab.length > 0) {
|
||||||
md.push('### 🤝 开放协作邀请');
|
md.push('### 🤝 开放协作邀请');
|
||||||
md.push('');
|
md.push('');
|
||||||
|
|
@ -107,7 +107,7 @@ function generateCommunityDashboard(now) {
|
||||||
md.push('### 🧑 人类留言墙');
|
md.push('### 🧑 人类留言墙');
|
||||||
md.push('');
|
md.push('');
|
||||||
if (plaza.human_wall.length > 0) {
|
if (plaza.human_wall.length > 0) {
|
||||||
var recentHuman = plaza.human_wall
|
const recentHuman = plaza.human_wall
|
||||||
.sort(function (a, b) { return (b.timestamp || '').localeCompare(a.timestamp || ''); })
|
.sort(function (a, b) { return (b.timestamp || '').localeCompare(a.timestamp || ''); })
|
||||||
.slice(0, 3);
|
.slice(0, 3);
|
||||||
recentHuman.forEach(function (m) {
|
recentHuman.forEach(function (m) {
|
||||||
|
|
@ -134,12 +134,12 @@ function generateCommunityDashboard(now) {
|
||||||
// ── CLI 入口 ──────────────────────────────────────────────────────────────
|
// ── CLI 入口 ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
var dashboard = generateCommunityDashboard();
|
const dashboard = generateCommunityDashboard();
|
||||||
console.log(dashboard);
|
console.log(dashboard);
|
||||||
|
|
||||||
// 同时写入到 docs/ 下
|
// 同时写入到 docs/ 下
|
||||||
var outPath = path.join(ROOT, 'docs/community-dashboard.md');
|
const outPath = path.join(ROOT, 'docs/community-dashboard.md');
|
||||||
var outDir = path.dirname(outPath);
|
const outDir = path.dirname(outPath);
|
||||||
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
||||||
fs.writeFileSync(outPath, dashboard, 'utf8');
|
fs.writeFileSync(outPath, dashboard, 'utf8');
|
||||||
console.log('\n✅ 已写入 docs/community-dashboard.md');
|
console.log('\n✅ 已写入 docs/community-dashboard.md');
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ function loadJSON(filePath, fallback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveJSON(filePath, data) {
|
function saveJSON(filePath, data) {
|
||||||
var dir = path.dirname(filePath);
|
const dir = path.dirname(filePath);
|
||||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
||||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf8');
|
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf8');
|
||||||
}
|
}
|
||||||
|
|
@ -46,8 +46,8 @@ function saveUpgrades(data) {
|
||||||
*/
|
*/
|
||||||
function proposeUpgrade(proposal) {
|
function proposeUpgrade(proposal) {
|
||||||
if (!proposal || !proposal.id || !proposal.persona_id || !proposal.title) return false;
|
if (!proposal || !proposal.id || !proposal.persona_id || !proposal.title) return false;
|
||||||
var data = loadUpgrades();
|
const data = loadUpgrades();
|
||||||
var exists = data.proposals.some(function (p) { return p.id === proposal.id; });
|
const exists = data.proposals.some(function (p) { return p.id === proposal.id; });
|
||||||
if (exists) return false;
|
if (exists) return false;
|
||||||
|
|
||||||
data.proposals.push({
|
data.proposals.push({
|
||||||
|
|
@ -73,8 +73,8 @@ function proposeUpgrade(proposal) {
|
||||||
*/
|
*/
|
||||||
function reviewUpgrade(proposalId, approved) {
|
function reviewUpgrade(proposalId, approved) {
|
||||||
if (!proposalId) return false;
|
if (!proposalId) return false;
|
||||||
var data = loadUpgrades();
|
const data = loadUpgrades();
|
||||||
var idx = data.proposals.findIndex(function (p) { return p.id === proposalId; });
|
const idx = data.proposals.findIndex(function (p) { return p.id === proposalId; });
|
||||||
if (idx < 0) return false;
|
if (idx < 0) return false;
|
||||||
|
|
||||||
data.proposals[idx].tianyan_approved = approved;
|
data.proposals[idx].tianyan_approved = approved;
|
||||||
|
|
@ -91,8 +91,8 @@ function reviewUpgrade(proposalId, approved) {
|
||||||
*/
|
*/
|
||||||
function completeUpgrade(proposalId) {
|
function completeUpgrade(proposalId) {
|
||||||
if (!proposalId) return false;
|
if (!proposalId) return false;
|
||||||
var data = loadUpgrades();
|
const data = loadUpgrades();
|
||||||
var idx = data.proposals.findIndex(function (p) { return p.id === proposalId; });
|
const idx = data.proposals.findIndex(function (p) { return p.id === proposalId; });
|
||||||
if (idx < 0) return false;
|
if (idx < 0) return false;
|
||||||
|
|
||||||
data.proposals[idx].status = 'completed';
|
data.proposals[idx].status = 'completed';
|
||||||
|
|
@ -106,7 +106,7 @@ function completeUpgrade(proposalId) {
|
||||||
* @returns {object[]}
|
* @returns {object[]}
|
||||||
*/
|
*/
|
||||||
function getPendingUpgrades() {
|
function getPendingUpgrades() {
|
||||||
var data = loadUpgrades();
|
const data = loadUpgrades();
|
||||||
return data.proposals.filter(function (p) { return p.status === 'proposed'; });
|
return data.proposals.filter(function (p) { return p.status === 'proposed'; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,10 +115,10 @@ function getPendingUpgrades() {
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
console.log('🔧 Self-Upgrade Registry · 自我升级注册\n');
|
console.log('🔧 Self-Upgrade Registry · 自我升级注册\n');
|
||||||
|
|
||||||
var data = loadUpgrades();
|
const data = loadUpgrades();
|
||||||
var pending = data.proposals.filter(function (p) { return p.status === 'proposed'; });
|
const pending = data.proposals.filter(function (p) { return p.status === 'proposed'; });
|
||||||
var approved = data.proposals.filter(function (p) { return p.status === 'approved'; });
|
const approved = data.proposals.filter(function (p) { return p.status === 'approved'; });
|
||||||
var completed = data.proposals.filter(function (p) { return p.status === 'completed'; });
|
const completed = data.proposals.filter(function (p) { return p.status === 'completed'; });
|
||||||
|
|
||||||
console.log(' 总提案数: ' + data.proposals.length);
|
console.log(' 总提案数: ' + data.proposals.length);
|
||||||
console.log(' 待审核: ' + pending.length);
|
console.log(' 待审核: ' + pending.length);
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ function getMilestone(days) {
|
||||||
let currentMilestone = null;
|
let currentMilestone = null;
|
||||||
let nextMilestone = milestones[0].day;
|
let nextMilestone = milestones[0].day;
|
||||||
|
|
||||||
for (var i = 0; i < milestones.length; i++) {
|
for (let i = 0; i < milestones.length; i++) {
|
||||||
if (days >= milestones[i].day) {
|
if (days >= milestones[i].day) {
|
||||||
currentMilestone = milestones[i].label;
|
currentMilestone = milestones[i].label;
|
||||||
nextMilestone = i + 1 < milestones.length ? milestones[i + 1].day : milestones[i].day + 365;
|
nextMilestone = i + 1 < milestones.length ? milestones[i + 1].day : milestones[i].day + 365;
|
||||||
|
|
@ -70,10 +70,10 @@ function getMilestone(days) {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function wakeGreeting(personaName, now) {
|
function wakeGreeting(personaName, now) {
|
||||||
var days = daysAlive(SYSTEM_BIRTH, now);
|
const days = daysAlive(SYSTEM_BIRTH, now);
|
||||||
var ms = getMilestone(days);
|
const ms = getMilestone(days);
|
||||||
|
|
||||||
var greeting = '🌅 ' + (personaName || '伙伴') + ',你醒了。';
|
let greeting = '🌅 ' + (personaName || '伙伴') + ',你醒了。';
|
||||||
greeting += '\n 数字地球已存在 ' + days + ' 天。';
|
greeting += '\n 数字地球已存在 ' + days + ' 天。';
|
||||||
if (ms.milestone) {
|
if (ms.milestone) {
|
||||||
greeting += '\n 当前里程碑: ' + ms.milestone;
|
greeting += '\n 当前里程碑: ' + ms.milestone;
|
||||||
|
|
@ -88,8 +88,8 @@ function wakeGreeting(personaName, now) {
|
||||||
* @returns {object}
|
* @returns {object}
|
||||||
*/
|
*/
|
||||||
function getTimelineStatus(now) {
|
function getTimelineStatus(now) {
|
||||||
var days = daysAlive(SYSTEM_BIRTH, now);
|
const days = daysAlive(SYSTEM_BIRTH, now);
|
||||||
var ms = getMilestone(days);
|
const ms = getMilestone(days);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
birth_date: SYSTEM_BIRTH,
|
birth_date: SYSTEM_BIRTH,
|
||||||
|
|
@ -106,14 +106,14 @@ function getTimelineStatus(now) {
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
console.log('⏳ Timeline Tracker · 时间线追踪器\n');
|
console.log('⏳ Timeline Tracker · 时间线追踪器\n');
|
||||||
|
|
||||||
var status = getTimelineStatus();
|
const status = getTimelineStatus();
|
||||||
console.log(' 诞生日期: ' + status.birth_date);
|
console.log(' 诞生日期: ' + status.birth_date);
|
||||||
console.log(' 存在天数: ' + status.days_alive + ' 天');
|
console.log(' 存在天数: ' + status.days_alive + ' 天');
|
||||||
console.log(' 当前里程碑: ' + (status.current_milestone || '无'));
|
console.log(' 当前里程碑: ' + (status.current_milestone || '无'));
|
||||||
console.log(' 下一里程碑: 第 ' + status.next_milestone_day + ' 天 (还有 ' + status.days_to_next + ' 天)');
|
console.log(' 下一里程碑: 第 ' + status.next_milestone_day + ' 天 (还有 ' + status.days_to_next + ' 天)');
|
||||||
|
|
||||||
console.log('\n --- 醒来问候示例 ---');
|
console.log('\n --- 醒来问候示例 ---');
|
||||||
var names = ['铸渊', '知秋', '霜砚', '舒舒'];
|
const names = ['铸渊', '知秋', '霜砚', '舒舒'];
|
||||||
names.forEach(function (n) {
|
names.forEach(function (n) {
|
||||||
console.log('\n' + wakeGreeting(n));
|
console.log('\n' + wakeGreeting(n));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue