chaimi-keep-mcp 3.5.0-beta.7 → 3.5.0-beta.8
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/restart-daemon.js +201 -0
- package/package.json +2 -2
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 自动重启 mcporter daemon 脚本
|
|
4
|
+
*
|
|
5
|
+
* 功能:安装新版本时自动重启 mcporter daemon,确保加载最新版本
|
|
6
|
+
* 使用场景:npm install 或 npm update 后自动调用
|
|
7
|
+
* 安全策略:只尝试重启,不强制退出,失败时静默处理
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { spawn, exec } = require('child_process');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
const IS_DEBUG = process.env.DEBUG === 'true';
|
|
16
|
+
const LOG_PREFIX = '[mcporter-restart]';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 日志函数
|
|
20
|
+
*/
|
|
21
|
+
function log(message, level = 'info') {
|
|
22
|
+
const timestamp = new Date().toISOString();
|
|
23
|
+
if (level === 'error') {
|
|
24
|
+
console.error(`${LOG_PREFIX} ${timestamp} ❌ ${message}`);
|
|
25
|
+
} else if (level === 'warn') {
|
|
26
|
+
console.warn(`${LOG_PREFIX} ${timestamp} ⚠️ ${message}`);
|
|
27
|
+
} else if (IS_DEBUG) {
|
|
28
|
+
console.log(`${LOG_PREFIX} ${timestamp} ${message}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 检查 mcporter 是否已安装
|
|
34
|
+
*/
|
|
35
|
+
function checkMcporterInstalled() {
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
exec('which mcporter', (error, stdout) => {
|
|
38
|
+
if (error) {
|
|
39
|
+
resolve(false);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
resolve(stdout.trim().length > 0);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 检查 mcporter daemon 是否在运行
|
|
49
|
+
*/
|
|
50
|
+
function checkDaemonRunning() {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
let cmd;
|
|
53
|
+
if (os.platform() === 'win32') {
|
|
54
|
+
cmd = 'tasklist /FI "IMAGENAME eq node.exe" /V';
|
|
55
|
+
} else {
|
|
56
|
+
cmd = 'ps aux | grep -E "mcporter.*daemon|daemon.*mcporter" | grep -v grep';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exec(cmd, (error, stdout) => {
|
|
60
|
+
if (error) {
|
|
61
|
+
// 没找到进程
|
|
62
|
+
resolve(false);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
resolve(stdout.trim().length > 0);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 尝试停止 mcporter daemon
|
|
72
|
+
*/
|
|
73
|
+
function stopDaemon() {
|
|
74
|
+
return new Promise((resolve) => {
|
|
75
|
+
log('尝试停止 mcporter daemon...', 'info');
|
|
76
|
+
exec('mcporter stop', (error, stdout, stderr) => {
|
|
77
|
+
if (error) {
|
|
78
|
+
log(`停止失败: ${error.message}`, 'warn');
|
|
79
|
+
if (IS_DEBUG && stderr) {
|
|
80
|
+
log(`stderr: ${stderr}`, 'warn');
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
log(`mcporter stop 命令执行成功`, 'info');
|
|
84
|
+
if (IS_DEBUG && stdout) {
|
|
85
|
+
log(`stdout: ${stdout}`, 'info');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
resolve();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 尝试启动 mcporter daemon
|
|
95
|
+
*/
|
|
96
|
+
function startDaemon() {
|
|
97
|
+
return new Promise((resolve) => {
|
|
98
|
+
log('尝试启动 mcporter daemon...', 'info');
|
|
99
|
+
exec('mcporter start', (error, stdout, stderr) => {
|
|
100
|
+
if (error) {
|
|
101
|
+
log(`启动失败: ${error.message}`, 'warn');
|
|
102
|
+
if (IS_DEBUG && stderr) {
|
|
103
|
+
log(`stderr: ${stderr}`, 'warn');
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
log(`mcporter start 命令执行成功`, 'info');
|
|
107
|
+
if (IS_DEBUG && stdout) {
|
|
108
|
+
log(`stdout: ${stdout}`, 'info');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
resolve();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 等待一段时间
|
|
118
|
+
*/
|
|
119
|
+
function wait(ms) {
|
|
120
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 获取当前版本
|
|
125
|
+
*/
|
|
126
|
+
function getCurrentVersion() {
|
|
127
|
+
try {
|
|
128
|
+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
129
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
130
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
131
|
+
return pkg.version;
|
|
132
|
+
}
|
|
133
|
+
} catch (e) {
|
|
134
|
+
// 忽略
|
|
135
|
+
}
|
|
136
|
+
return 'unknown';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 主函数
|
|
141
|
+
*/
|
|
142
|
+
async function main() {
|
|
143
|
+
console.log('\n🔄 检查 mcporter daemon...\n');
|
|
144
|
+
|
|
145
|
+
const version = getCurrentVersion();
|
|
146
|
+
log(`当前版本: ${version}`, 'info');
|
|
147
|
+
|
|
148
|
+
// 检查 mcporter 是否安装
|
|
149
|
+
const isInstalled = await checkMcporterInstalled();
|
|
150
|
+
if (!isInstalled) {
|
|
151
|
+
log('mcporter 未安装,跳过重启', 'info');
|
|
152
|
+
console.log('✅ mcporter 未安装,无需重启\n');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
log('mcporter 已安装', 'info');
|
|
157
|
+
|
|
158
|
+
// 检查 daemon 是否在运行
|
|
159
|
+
const isRunning = await checkDaemonRunning();
|
|
160
|
+
if (!isRunning) {
|
|
161
|
+
log('mcporter daemon 未在运行,无需重启', 'info');
|
|
162
|
+
console.log('✅ mcporter daemon 未在运行\n');
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
log('mcporter daemon 在运行中,准备重启...', 'info');
|
|
167
|
+
|
|
168
|
+
// 停止 daemon
|
|
169
|
+
await stopDaemon();
|
|
170
|
+
|
|
171
|
+
// 等待一小会儿
|
|
172
|
+
await wait(500);
|
|
173
|
+
|
|
174
|
+
// 启动 daemon
|
|
175
|
+
await startDaemon();
|
|
176
|
+
|
|
177
|
+
// 等待并检查是否成功启动
|
|
178
|
+
await wait(1000);
|
|
179
|
+
|
|
180
|
+
const isRunningAfter = await checkDaemonRunning();
|
|
181
|
+
if (isRunningAfter) {
|
|
182
|
+
console.log('✅ mcporter daemon 重启成功!\n');
|
|
183
|
+
} else {
|
|
184
|
+
console.log('⚠️ mcporter daemon 可能需要手动启动\n');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 给用户提示
|
|
188
|
+
console.log('💡 如果新版本功能未生效,请尝试:');
|
|
189
|
+
console.log(' 1. 重启您的 AI Agent(OpenClaw/WorkBuddy 等)');
|
|
190
|
+
console.log(' 2. 或运行: mcporter restart\n');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 执行
|
|
194
|
+
main().catch(error => {
|
|
195
|
+
log(`发生未预期错误: ${error.message}`, 'error');
|
|
196
|
+
if (IS_DEBUG) {
|
|
197
|
+
console.error(error.stack);
|
|
198
|
+
}
|
|
199
|
+
// 不阻止安装流程继续
|
|
200
|
+
process.exit(0);
|
|
201
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chaimi-keep-mcp",
|
|
3
|
-
"version": "3.5.0-beta.
|
|
3
|
+
"version": "3.5.0-beta.8",
|
|
4
4
|
"description": "柴米AI记账 MCP Server - 支持 Claude、Cursor、OpenClaw、WorkBuddy 等 AI 工具直接记账",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"start": "node server.js",
|
|
25
25
|
"dev": "node server.js",
|
|
26
|
-
"postinstall": "node bin/sync-skill.js",
|
|
26
|
+
"postinstall": "node bin/sync-skill.js && node bin/restart-daemon.js",
|
|
27
27
|
"test": "jest",
|
|
28
28
|
"test:static": "jest test/static-analysis.test.js",
|
|
29
29
|
"prepublishOnly": "npm run test:static"
|