yongle-dadian 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/install.js +7 -0
- package/commands/status.md +8 -0
- package/package.json +1 -1
- package/scripts/yongle-auto-archive-hook.js +7 -0
- package/scripts/yongle-auto-search-hook.js +22 -0
- package/scripts/yongle-bg-archiver.js +15 -1
- package/scripts/yongle-dreamer.js +11 -0
- package/scripts/yongle-logger.js +104 -0
- package/scripts/yongle-status.js +122 -0
- package/skills/yongle-status/SKILL.md +17 -0
package/bin/install.js
CHANGED
|
@@ -41,6 +41,12 @@ const hasGlobal = args.includes('--global') || args.includes('-g');
|
|
|
41
41
|
const hasLocal = args.includes('--local') || args.includes('-l');
|
|
42
42
|
const hasUninstall = args.includes('--uninstall') || args.includes('-u');
|
|
43
43
|
const hasHelp = args.includes('--help') || args.includes('-h');
|
|
44
|
+
const hasStatus = args.includes('--status') || args.includes('-s');
|
|
45
|
+
|
|
46
|
+
if (hasStatus) {
|
|
47
|
+
require('../scripts/yongle-status.js');
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
44
50
|
|
|
45
51
|
// Runtime flags
|
|
46
52
|
const runtimeFlags = {
|
|
@@ -87,6 +93,7 @@ if (hasHelp) {
|
|
|
87
93
|
console.log(` ${cyan}--qoder${reset} Target Qoder runtime`);
|
|
88
94
|
console.log(` ${cyan}--all${reset} Install for all supported runtimes`);
|
|
89
95
|
console.log(` ${cyan}-u, --uninstall${reset} Remove yongle files from target`);
|
|
96
|
+
console.log(` ${cyan}-s, --status${reset} Show auto-features health dashboard`);
|
|
90
97
|
console.log(` ${cyan}-h, --help${reset} Show this help\n`);
|
|
91
98
|
console.log(` ${yellow}Examples:${reset}`);
|
|
92
99
|
console.log(` ${dim}# Install for Antigravity globally${reset}`);
|
package/package.json
CHANGED
|
@@ -23,6 +23,13 @@ process.stdin.on('end', () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
child.unref(); // 让当前 Hook 脚本可以立刻退出
|
|
26
|
+
|
|
27
|
+
const { logAutoFeature } = require('./yongle-logger');
|
|
28
|
+
logAutoFeature({
|
|
29
|
+
feature: 'auto-archive',
|
|
30
|
+
status: 'RUNNING',
|
|
31
|
+
details: '已触发脱机后台归档进程'
|
|
32
|
+
});
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
// Stop 钩子一般不需要返回任何操作(直接输出空或原样放行)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const { spawnSync } = require('child_process');
|
|
3
|
+
const { logAutoFeature } = require('./yongle-logger');
|
|
3
4
|
|
|
4
5
|
let inputData = '';
|
|
5
6
|
process.stdin.on('data', chunk => {
|
|
@@ -14,6 +15,7 @@ process.stdin.on('end', () => {
|
|
|
14
15
|
console.log(JSON.stringify({}));
|
|
15
16
|
process.exit(0);
|
|
16
17
|
}
|
|
18
|
+
const startTime = Date.now();
|
|
17
19
|
|
|
18
20
|
// 读取 transcript
|
|
19
21
|
const transcript = fs.readFileSync(payload.transcriptPath, 'utf8');
|
|
@@ -76,6 +78,13 @@ process.stdin.on('end', () => {
|
|
|
76
78
|
|
|
77
79
|
// 如果找到了结果(通过判定是否包含结果专属的 emoji 前缀)
|
|
78
80
|
if (cleanOutput && (cleanOutput.includes('🧠') || cleanOutput.includes('🔍')) && !cleanOutput.includes('Semantic Error')) {
|
|
81
|
+
const durationMs = Date.now() - startTime;
|
|
82
|
+
logAutoFeature({
|
|
83
|
+
feature: 'auto-search',
|
|
84
|
+
status: 'HIT',
|
|
85
|
+
durationMs,
|
|
86
|
+
details: `匹配到关联经验 (${queryContext})`
|
|
87
|
+
});
|
|
79
88
|
console.log(JSON.stringify({
|
|
80
89
|
injectSteps: [
|
|
81
90
|
{
|
|
@@ -86,9 +95,22 @@ process.stdin.on('end', () => {
|
|
|
86
95
|
process.exit(0);
|
|
87
96
|
}
|
|
88
97
|
|
|
98
|
+
logAutoFeature({
|
|
99
|
+
feature: 'auto-search',
|
|
100
|
+
status: 'MISS',
|
|
101
|
+
durationMs: Date.now() - startTime,
|
|
102
|
+
details: `未匹配到明显相关排错经验 (${queryContext || 'NoQuery'})`
|
|
103
|
+
});
|
|
104
|
+
|
|
89
105
|
console.log(JSON.stringify({}));
|
|
90
106
|
process.exit(0);
|
|
91
107
|
} catch (err) {
|
|
108
|
+
logAutoFeature({
|
|
109
|
+
feature: 'auto-search',
|
|
110
|
+
status: 'ERROR',
|
|
111
|
+
durationMs: 0,
|
|
112
|
+
error: err.message
|
|
113
|
+
});
|
|
92
114
|
console.log(JSON.stringify({}));
|
|
93
115
|
process.exit(0);
|
|
94
116
|
}
|
|
@@ -3,6 +3,7 @@ const path = require('path');
|
|
|
3
3
|
const { execSync } = require('child_process');
|
|
4
4
|
const { getAgentCompletion } = require('./yongle-agent-api.js');
|
|
5
5
|
const { loadMergedConfig } = require('./yongle-config.js');
|
|
6
|
+
const { logAutoFeature } = require('./yongle-logger.js');
|
|
6
7
|
const os = require('os');
|
|
7
8
|
|
|
8
9
|
// 获取日志路径
|
|
@@ -15,6 +16,7 @@ if (!transcriptPath || !fs.existsSync(transcriptPath)) {
|
|
|
15
16
|
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
16
17
|
|
|
17
18
|
async function main() {
|
|
19
|
+
const startTime = Date.now();
|
|
18
20
|
try {
|
|
19
21
|
// 1. 读取并提取上下文 (最近 40 条记录)
|
|
20
22
|
const lines = fs.readFileSync(transcriptPath, 'utf8').trim().split('\n').slice(-40);
|
|
@@ -143,10 +145,22 @@ ${data.solution}
|
|
|
143
145
|
execSync(`node "${embedScript}"`);
|
|
144
146
|
}
|
|
145
147
|
} catch (e) {}
|
|
148
|
+
|
|
149
|
+
logAutoFeature({
|
|
150
|
+
feature: 'auto-archive',
|
|
151
|
+
status: 'SUCCESS',
|
|
152
|
+
durationMs: Date.now() - startTime,
|
|
153
|
+
details: `归档生成经验: "${data.title}" (${usedAgentApi ? 'Native AgentAPI' : 'External LLM API'})`
|
|
154
|
+
});
|
|
146
155
|
}
|
|
147
156
|
|
|
148
157
|
} catch (error) {
|
|
149
|
-
|
|
158
|
+
logAutoFeature({
|
|
159
|
+
feature: 'auto-archive',
|
|
160
|
+
status: 'ERROR',
|
|
161
|
+
durationMs: Date.now() - startTime,
|
|
162
|
+
error: error.message
|
|
163
|
+
});
|
|
150
164
|
}
|
|
151
165
|
}
|
|
152
166
|
|
|
@@ -8,6 +8,7 @@ const path = require('path');
|
|
|
8
8
|
const { execSync } = require('child_process');
|
|
9
9
|
const { getAgentCompletion } = require('./yongle-agent-api.js');
|
|
10
10
|
const { loadMergedConfig } = require('./yongle-config');
|
|
11
|
+
const { logAutoFeature } = require('./yongle-logger');
|
|
11
12
|
|
|
12
13
|
// 配置 (可从 config.json 读取,此处为默认值)
|
|
13
14
|
const CONFIG = {
|
|
@@ -161,6 +162,11 @@ ${summary.trim()}
|
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
console.log(`[${timestamp}] ✅ ${type === 'quick' ? '梦境片段已缓存' : '梦境合并已排期'}`);
|
|
165
|
+
logAutoFeature({
|
|
166
|
+
feature: 'dreamer',
|
|
167
|
+
status: 'SUCCESS',
|
|
168
|
+
details: `完成 ${type === 'quick' ? '快速梦' : '长梦'} 整理沉淀`
|
|
169
|
+
});
|
|
164
170
|
}
|
|
165
171
|
|
|
166
172
|
const STATE_FILE = '.planning/yongle/dream_state.json';
|
|
@@ -210,6 +216,11 @@ async function runOnce() {
|
|
|
210
216
|
const minToQuick = Math.max(0, Math.ceil((CONFIG.QUICK_IDLE_MS - fileSilence) / (60 * 1000)));
|
|
211
217
|
const minToLong = Math.max(0, Math.ceil((CONFIG.LONG_IDLE_MS - fileSilence) / (60 * 1000)));
|
|
212
218
|
console.log(`当前项目静默时长: ${Math.round(fileSilence / 1000)}s。暂未达到梦境触发阈值(距离快速梦还需 ${minToQuick}m,距离长梦还需 ${minToLong}m)。`);
|
|
219
|
+
logAutoFeature({
|
|
220
|
+
feature: 'dreamer',
|
|
221
|
+
status: 'MISS',
|
|
222
|
+
details: `守护检查:未达阈值(静默 ${Math.round(fileSilence / 1000)}s)`
|
|
223
|
+
});
|
|
213
224
|
}
|
|
214
225
|
}
|
|
215
226
|
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
const homedir = os.homedir();
|
|
6
|
+
const logDir = path.join(homedir, '.yongle_knowledge', 'logs');
|
|
7
|
+
const archiveDir = path.join(logDir, 'archives');
|
|
8
|
+
const logFilePath = path.join(logDir, 'auto-features.jsonl');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 确保日志与归档目录存在
|
|
12
|
+
*/
|
|
13
|
+
function ensureLogDirs() {
|
|
14
|
+
if (!fs.existsSync(logDir)) {
|
|
15
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
if (!fs.existsSync(archiveDir)) {
|
|
18
|
+
fs.mkdirSync(archiveDir, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 记录一条自动化功能状态日志,并执行超限转储归档
|
|
24
|
+
* @param {Object} params
|
|
25
|
+
* @param {'auto-search'|'auto-archive'|'dreamer'} params.feature
|
|
26
|
+
* @param {'HIT'|'MISS'|'RUNNING'|'SUCCESS'|'ERROR'} params.status
|
|
27
|
+
* @param {number} [params.durationMs]
|
|
28
|
+
* @param {string} [params.details]
|
|
29
|
+
* @param {string} [params.error]
|
|
30
|
+
*/
|
|
31
|
+
function logAutoFeature({ feature, status, durationMs = 0, details = '', error = '' }) {
|
|
32
|
+
try {
|
|
33
|
+
ensureLogDirs();
|
|
34
|
+
|
|
35
|
+
const entry = {
|
|
36
|
+
timestamp: new Date().toISOString(),
|
|
37
|
+
feature,
|
|
38
|
+
status,
|
|
39
|
+
duration_ms: Math.round(durationMs),
|
|
40
|
+
details: details || '',
|
|
41
|
+
error: error || ''
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const line = JSON.stringify(entry) + '\n';
|
|
45
|
+
|
|
46
|
+
// 如果日志文件存在,检查行数
|
|
47
|
+
let lines = [];
|
|
48
|
+
if (fs.existsSync(logFilePath)) {
|
|
49
|
+
const content = fs.readFileSync(logFilePath, 'utf8').trim();
|
|
50
|
+
if (content) {
|
|
51
|
+
lines = content.split('\n');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
lines.push(JSON.stringify(entry));
|
|
56
|
+
|
|
57
|
+
// 超限切割归档:若总行数达到/超过 1000 条,切割前 850 条转储,保留最新的 150 条
|
|
58
|
+
if (lines.length >= 1000) {
|
|
59
|
+
const archiveLines = lines.slice(0, 850);
|
|
60
|
+
const keepLines = lines.slice(850);
|
|
61
|
+
|
|
62
|
+
const timestampSlug = new Date().toISOString().replace(/[:.]/g, '-');
|
|
63
|
+
const archiveFilePath = path.join(archiveDir, `auto-features-${timestampSlug}.jsonl`);
|
|
64
|
+
|
|
65
|
+
fs.writeFileSync(archiveFilePath, archiveLines.join('\n') + '\n', 'utf8');
|
|
66
|
+
fs.writeFileSync(logFilePath, keepLines.join('\n') + '\n', 'utf8');
|
|
67
|
+
} else {
|
|
68
|
+
fs.appendFileSync(logFilePath, line, 'utf8');
|
|
69
|
+
}
|
|
70
|
+
} catch (err) {
|
|
71
|
+
// 日志写入静默安全捕获,切勿阻塞主执行流
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 读取最近的自动化功能日志
|
|
77
|
+
* @param {number} [limit=50]
|
|
78
|
+
* @returns {Array<Object>}
|
|
79
|
+
*/
|
|
80
|
+
function getRecentLogs(limit = 50) {
|
|
81
|
+
try {
|
|
82
|
+
if (!fs.existsSync(logFilePath)) return [];
|
|
83
|
+
const content = fs.readFileSync(logFilePath, 'utf8').trim();
|
|
84
|
+
if (!content) return [];
|
|
85
|
+
const lines = content.split('\n');
|
|
86
|
+
const recent = lines.slice(-limit);
|
|
87
|
+
return recent.map(line => {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(line);
|
|
90
|
+
} catch (e) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}).filter(Boolean);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = {
|
|
100
|
+
logAutoFeature,
|
|
101
|
+
getRecentLogs,
|
|
102
|
+
logFilePath,
|
|
103
|
+
archiveDir
|
|
104
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 永乐大典 (Yongle Dadian) — 自动化功能运行状态与健康看板
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { getRecentLogs } = require('./yongle-logger.js');
|
|
8
|
+
|
|
9
|
+
// ─── ANSI 颜色常量 ─────────────────────────────────────────
|
|
10
|
+
const cyan = '\x1b[36m';
|
|
11
|
+
const green = '\x1b[32m';
|
|
12
|
+
const yellow = '\x1b[33m';
|
|
13
|
+
const red = '\x1b[31m';
|
|
14
|
+
const bold = '\x1b[1m';
|
|
15
|
+
const dim = '\x1b[2m';
|
|
16
|
+
const reset = '\x1b[0m';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 将时间戳转换为人性化的相对时间描述(如 "12秒前")
|
|
20
|
+
* @param {string} isoString
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
function formatTimeAgo(isoString) {
|
|
24
|
+
if (!isoString) return '未曾触发';
|
|
25
|
+
const diffMs = Date.now() - new Date(isoString).getTime();
|
|
26
|
+
if (isNaN(diffMs) || diffMs < 0) return '刚才';
|
|
27
|
+
|
|
28
|
+
const seconds = Math.floor(diffMs / 1000);
|
|
29
|
+
if (seconds < 60) return `${seconds}秒前`;
|
|
30
|
+
const minutes = Math.floor(seconds / 60);
|
|
31
|
+
if (minutes < 60) return `${minutes}分钟前`;
|
|
32
|
+
const hours = Math.floor(minutes / 60);
|
|
33
|
+
if (hours < 24) return `${hours}小时前`;
|
|
34
|
+
const days = Math.floor(hours / 24);
|
|
35
|
+
return `${days}天前`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 格式化状态标签色彩
|
|
40
|
+
* @param {string} status
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
function formatStatus(status) {
|
|
44
|
+
switch (status) {
|
|
45
|
+
case 'HIT':
|
|
46
|
+
return `${green}${bold}🎯 匹配命中${reset}`;
|
|
47
|
+
case 'SUCCESS':
|
|
48
|
+
return `${green}${bold}✓ 成功完成${reset}`;
|
|
49
|
+
case 'RUNNING':
|
|
50
|
+
return `${cyan}${bold}🔄 后台运行中${reset}`;
|
|
51
|
+
case 'MISS':
|
|
52
|
+
return `${dim}💬 未触发/放行${reset}`;
|
|
53
|
+
case 'ERROR':
|
|
54
|
+
return `${red}${bold}✗ 执行报错${reset}`;
|
|
55
|
+
default:
|
|
56
|
+
return `${dim}⚪ 未开启/未知${reset}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 主绘制函数
|
|
62
|
+
*/
|
|
63
|
+
function main() {
|
|
64
|
+
const logs = getRecentLogs(200);
|
|
65
|
+
|
|
66
|
+
// 找三大功能的最新日志
|
|
67
|
+
const latestMap = {
|
|
68
|
+
'auto-search': null,
|
|
69
|
+
'auto-archive': null,
|
|
70
|
+
'dreamer': null
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
for (let i = logs.length - 1; i >= 0; i--) {
|
|
74
|
+
const entry = logs[i];
|
|
75
|
+
if (entry && entry.feature && !latestMap[entry.feature]) {
|
|
76
|
+
latestMap[entry.feature] = entry;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const features = [
|
|
81
|
+
{
|
|
82
|
+
id: 'auto-search',
|
|
83
|
+
name: '1. 前置静默搜索 (Auto-Search)',
|
|
84
|
+
data: latestMap['auto-search']
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: 'auto-archive',
|
|
88
|
+
name: '2. 会话停止自动归档 (Auto-Archive)',
|
|
89
|
+
data: latestMap['auto-archive']
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: 'dreamer',
|
|
93
|
+
name: '4. 梦境守护与整理 (Dreamer)',
|
|
94
|
+
data: latestMap['dreamer']
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
console.log('\n' +
|
|
99
|
+
cyan + ' ╔════════════════════════════════════════════════════════════════════════╗\n' +
|
|
100
|
+
' ║ 永 乐 大 典 · 自 动 化 功能 运行 状 态 看 板 ║\n' +
|
|
101
|
+
' ╚════════════════════════════════════════════════════════════════════════╝' + reset + '\n'
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
features.forEach((item, index) => {
|
|
105
|
+
const d = item.data;
|
|
106
|
+
const timeAgo = d ? formatTimeAgo(d.timestamp) : `${dim}未曾触发${reset}`;
|
|
107
|
+
const statusText = d ? formatStatus(d.status) : `${dim}无纪录${reset}`;
|
|
108
|
+
const durationText = d && d.duration_ms ? `${d.duration_ms}ms` : '-';
|
|
109
|
+
const detailText = d ? (d.error ? `${red}${d.error}${reset}` : d.details) : `${dim}系统运行正常,等待事件触发${reset}`;
|
|
110
|
+
|
|
111
|
+
console.log(` ${bold}${item.name}${reset}`);
|
|
112
|
+
console.log(` ▸ 状态/结果 : ${statusText}`);
|
|
113
|
+
console.log(` ▸ 上次触发 : ${dim}${timeAgo}${reset} ${d ? `(${new Date(d.timestamp).toLocaleString()})` : ''}`);
|
|
114
|
+
console.log(` ▸ 执行耗时 : ${dim}${durationText}${reset}`);
|
|
115
|
+
console.log(` ▸ 最新详情 : ${detailText}`);
|
|
116
|
+
if (index < features.length - 1) console.log(' ────────────────────────────────────────────────────────────────────────');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
console.log('\n' + dim + ' 提示: 日志保存在 ~/.yongle_knowledge/logs/auto-features.jsonl (满1000条自动归档850条前历史纪录)。' + reset + '\n');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
main();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: yongle-status
|
|
3
|
+
description: 查看永乐大典后台自动化功能的运行状态与健康看板
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<objective>
|
|
7
|
+
查看永乐大典后台三大自动化功能(1.前置自动搜索、2.会话停止自动归档、4.梦境守护整理)的当前状态、上次触发时间、耗时及运行结果/报错日志。
|
|
8
|
+
</objective>
|
|
9
|
+
|
|
10
|
+
<process>
|
|
11
|
+
运行永乐大典内置的状态看板脚本。
|
|
12
|
+
|
|
13
|
+
执行以下命令:
|
|
14
|
+
```bash
|
|
15
|
+
node {{YONGLE_INSTALL_DIR}}/scripts/yongle-status.js
|
|
16
|
+
```
|
|
17
|
+
</process>
|