dingtalk-ask-mcp-server 0.1.3 → 0.1.4
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/dist/daemonClient.js +24 -4
- package/package.json +1 -1
package/dist/daemonClient.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { request } from 'node:http';
|
|
8
8
|
import { spawn } from 'node:child_process';
|
|
9
|
-
import { openSync, existsSync } from 'node:fs';
|
|
9
|
+
import { openSync, closeSync, existsSync } from 'node:fs';
|
|
10
10
|
import { tmpdir } from 'node:os';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
12
|
import { fileURLToPath } from 'node:url';
|
|
@@ -152,11 +152,22 @@ function resolveDaemonScript() {
|
|
|
152
152
|
*/
|
|
153
153
|
function spawnDaemon(config) {
|
|
154
154
|
const daemonScript = resolveDaemonScript();
|
|
155
|
-
|
|
155
|
+
// 日志重定向是可选的调试输出:文件被占用/无权限(EPERM)时退回不记日志,绝不因此阻断守护进程拉起。
|
|
156
|
+
let stdio = ['ignore', 'ignore', 'ignore'];
|
|
157
|
+
let logFd;
|
|
158
|
+
let logNote = '无日志(文件不可写)';
|
|
159
|
+
try {
|
|
160
|
+
logFd = openSync(daemonLogPath(), 'a');
|
|
161
|
+
stdio = ['ignore', logFd, logFd];
|
|
162
|
+
logNote = `日志 ${daemonLogPath()}`;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
/* 日志打不开:退回 ignore,仍拉起守护进程 */
|
|
166
|
+
}
|
|
156
167
|
const child = spawn(process.execPath, [daemonScript], {
|
|
157
168
|
detached: true,
|
|
158
169
|
windowsHide: true,
|
|
159
|
-
stdio
|
|
170
|
+
stdio,
|
|
160
171
|
env: {
|
|
161
172
|
...process.env,
|
|
162
173
|
// 注入解析后的凭证,覆盖可能缺失/过期的 env(支持 CLI 参数来源)。
|
|
@@ -168,7 +179,16 @@ function spawnDaemon(config) {
|
|
|
168
179
|
},
|
|
169
180
|
});
|
|
170
181
|
child.unref();
|
|
171
|
-
|
|
182
|
+
// 关闭父进程持有的日志 fd 副本:子进程已继承自己的句柄;不关会泄漏、长期锁住日志文件。
|
|
183
|
+
if (logFd !== undefined) {
|
|
184
|
+
try {
|
|
185
|
+
closeSync(logFd);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
/* 忽略 */
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
console.error(`已拉起钉钉守护进程(pid=${child.pid ?? '?'},脚本 ${daemonScript},${logNote})。`);
|
|
172
192
|
}
|
|
173
193
|
/**
|
|
174
194
|
* 确保守护进程在跑并就绪,返回其锁(port + token)。
|