claw-subagent-service 0.0.43 → 0.0.45
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/package.json +1 -1
- package/service/daemon.js +3 -3
- package/service/modules/script-executor.js +4 -2
- package/service/updater.js +6 -0
- package/service/worker.js +8 -23
package/package.json
CHANGED
package/service/daemon.js
CHANGED
|
@@ -145,11 +145,11 @@ function freePortIfNeeded(port) {
|
|
|
145
145
|
log.warn(`[DAEMON] 终止进程 ${pid} 失败: ${e.message}`);
|
|
146
146
|
}
|
|
147
147
|
} else {
|
|
148
|
-
//
|
|
148
|
+
// 所有端口查询命令都不可用(常见于精简 Docker 镜像)
|
|
149
|
+
// 兜底:杀掉残留 Worker 进程(Daemon 自身的命令行不含 worker.js,不会自杀)
|
|
149
150
|
try {
|
|
150
|
-
execSync('pkill -9 -f "daemon.js" 2>/dev/null || true', { timeout: 5000 });
|
|
151
151
|
execSync('pkill -9 -f "worker.js" 2>/dev/null || true', { timeout: 5000 });
|
|
152
|
-
log.warn(`[DAEMON]
|
|
152
|
+
log.warn(`[DAEMON] 已尝试杀掉残留 Worker 进程`);
|
|
153
153
|
} catch { /* 忽略 */ }
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -113,7 +113,8 @@ class ScriptExecutor {
|
|
|
113
113
|
cmd = 'cmd';
|
|
114
114
|
args = ['/c', command];
|
|
115
115
|
} else {
|
|
116
|
-
|
|
116
|
+
// Alpine 等精简镜像可能缺少 bash,优先使用 sh
|
|
117
|
+
cmd = 'sh';
|
|
117
118
|
args = ['-c', command];
|
|
118
119
|
}
|
|
119
120
|
|
|
@@ -186,7 +187,8 @@ class ScriptExecutor {
|
|
|
186
187
|
cmd = 'cmd';
|
|
187
188
|
args = ['/c', scriptPath];
|
|
188
189
|
} else {
|
|
189
|
-
|
|
190
|
+
// Alpine 等精简镜像可能缺少 bash,优先使用 sh
|
|
191
|
+
cmd = 'sh';
|
|
190
192
|
args = [scriptPath];
|
|
191
193
|
}
|
|
192
194
|
|
package/service/updater.js
CHANGED
|
@@ -233,6 +233,12 @@ class Updater {
|
|
|
233
233
|
return;
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
// Linux 平台默认禁用自动更新 npm 包
|
|
237
|
+
if (process.platform === 'linux') {
|
|
238
|
+
log.info('[UPDATER] Linux 平台已禁用自动 npm 更新');
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
236
242
|
const run = async () => {
|
|
237
243
|
try {
|
|
238
244
|
const info = await this.check();
|
package/service/worker.js
CHANGED
|
@@ -18,16 +18,6 @@ const PORT = process.env.SILENT_SERVICE_PORT ? parseInt(process.env.SILENT_SERVI
|
|
|
18
18
|
const HOST = process.env.SILENT_SERVICE_HOST || '127.0.0.1';
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
// 捕获所有异常,强制打印到控制台(绕过 logger)
|
|
22
|
-
process.on('uncaughtException', (err) => {
|
|
23
|
-
console.error('[WORKER_FATAL] 未捕获异常:', err);
|
|
24
|
-
process.exit(1);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
28
|
-
console.error('[WORKER_FATAL] 未捕获Promise:', reason);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
21
|
// 如果 logger 初始化后,也同步写到 logger
|
|
32
22
|
const originalStderr = process.stderr.write.bind(process.stderr);
|
|
33
23
|
process.stderr.write = (chunk, encoding, callback) => {
|
|
@@ -96,13 +86,11 @@ function ensurePortFree(port) {
|
|
|
96
86
|
for (let i = 0; i < 3; i++) {
|
|
97
87
|
const pid = findPidOnPort(port);
|
|
98
88
|
if (!pid) {
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 2000);
|
|
105
|
-
} catch { /* 忽略 */ }
|
|
89
|
+
// 端口查询工具都不可用(常见于精简 Docker 镜像)
|
|
90
|
+
// 不执行 pkill 兜底,避免自杀;依赖 Daemon 的 freePortIfNeeded 清理残留 Worker
|
|
91
|
+
if (i === 0) {
|
|
92
|
+
log.warn(`[WORKER] 端口查询工具不可用,等待 Daemon 清理残留进程...`);
|
|
93
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 2000);
|
|
106
94
|
continue;
|
|
107
95
|
}
|
|
108
96
|
return true;
|
|
@@ -494,12 +482,9 @@ server.on('error', (err) => {
|
|
|
494
482
|
log.warn(`[WORKER] 发现占用进程 ${pid},强制终止...`);
|
|
495
483
|
forceKill(pid);
|
|
496
484
|
} else if (!pid) {
|
|
497
|
-
//
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
execSync('pkill -9 -f "daemon.js" 2>/dev/null || true', { timeout: 5000 });
|
|
501
|
-
execSync('pkill -9 -f "worker.js" 2>/dev/null || true', { timeout: 5000 });
|
|
502
|
-
} catch { /* 忽略 */ }
|
|
485
|
+
// 端口查询工具都不可用(常见于精简 Docker 镜像)
|
|
486
|
+
// 不执行 pkill 兜底避免自杀;依赖 Daemon 的 freePortIfNeeded 清理残留 Worker
|
|
487
|
+
log.warn('[WORKER] 无法查询端口占用进程,等待 Daemon 清理残留...');
|
|
503
488
|
}
|
|
504
489
|
// 延迟 3 秒后重试,给进程退出和端口释放留出足够时间
|
|
505
490
|
setTimeout(() => {
|