chatccc 0.2.163 → 0.2.164
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/src/orchestrator.ts +40 -11
package/package.json
CHANGED
package/src/orchestrator.ts
CHANGED
|
@@ -180,36 +180,63 @@ function updLog(msg: string): void {
|
|
|
180
180
|
/** 同步更新 npm 全局包并重启(父进程存活等待,避免 systemd KillMode=control-group 杀 watcher) */
|
|
181
181
|
function syncUpdateAndRestart(): void {
|
|
182
182
|
updLog(`sync update start, pid=${process.pid}`);
|
|
183
|
+
appendStartupTrace("updateg: sync update start", { pid: process.pid });
|
|
183
184
|
|
|
184
|
-
// 1. npm update
|
|
185
185
|
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
186
|
+
|
|
187
|
+
// 1. npm update
|
|
188
|
+
updLog(`running: ${npmCmd} update -g chatccc`);
|
|
189
|
+
appendStartupTrace("updateg: npm update begin", { npmCmd });
|
|
190
|
+
const t0 = Date.now();
|
|
186
191
|
try {
|
|
187
|
-
const out = execSync(`${npmCmd} update -g chatccc`, { encoding: "utf8", timeout: 120000, windowsHide: true });
|
|
188
|
-
|
|
192
|
+
const out = execSync(`${npmCmd} update -g chatccc 2>&1`, { encoding: "utf8", timeout: 120000, windowsHide: true });
|
|
193
|
+
const elapsed = Date.now() - t0;
|
|
194
|
+
updLog(`npm update OK (${elapsed}ms): ${out.slice(0, 500)}`);
|
|
195
|
+
appendStartupTrace("updateg: npm update OK", { elapsedMs: elapsed, outputLen: out.length });
|
|
189
196
|
} catch (e) {
|
|
190
|
-
const
|
|
191
|
-
|
|
197
|
+
const elapsed = Date.now() - t0;
|
|
198
|
+
const err = e as Error & { stderr?: string; stdout?: string; status?: number };
|
|
199
|
+
updLog(`npm update failed (${elapsed}ms): message=${err.message}, stderr=${(err.stderr || "").slice(0, 500)}, stdout=${(err.stdout || "").slice(0, 200)}`);
|
|
200
|
+
appendStartupTrace("updateg: npm update failed", { elapsedMs: elapsed, message: err.message, stderrLen: (err.stderr || "").length });
|
|
201
|
+
|
|
202
|
+
// fallback
|
|
203
|
+
updLog(`fallback: ${npmCmd} install -g chatccc@latest`);
|
|
204
|
+
appendStartupTrace("updateg: npm install fallback begin", { npmCmd });
|
|
205
|
+
const t1 = Date.now();
|
|
192
206
|
try {
|
|
193
|
-
const out2 = execSync(`${npmCmd} install -g chatccc@latest`, { encoding: "utf8", timeout: 120000, windowsHide: true });
|
|
194
|
-
|
|
207
|
+
const out2 = execSync(`${npmCmd} install -g chatccc@latest 2>&1`, { encoding: "utf8", timeout: 120000, windowsHide: true });
|
|
208
|
+
const elapsed2 = Date.now() - t1;
|
|
209
|
+
updLog(`npm install fallback OK (${elapsed2}ms): ${out2.slice(0, 500)}`);
|
|
210
|
+
appendStartupTrace("updateg: npm install fallback OK", { elapsedMs: elapsed2, outputLen: out2.length });
|
|
195
211
|
} catch (e2) {
|
|
196
|
-
|
|
212
|
+
const elapsed2 = Date.now() - t1;
|
|
213
|
+
const err2 = e2 as Error & { stderr?: string; stdout?: string };
|
|
214
|
+
updLog(`npm install fallback also failed (${elapsed2}ms): message=${err2.message}, stderr=${(err2.stderr || "").slice(0, 500)}`);
|
|
215
|
+
appendStartupTrace("updateg: npm install fallback failed", { elapsedMs: elapsed2, message: err2.message });
|
|
197
216
|
}
|
|
198
217
|
}
|
|
199
218
|
|
|
200
|
-
// 2.
|
|
219
|
+
// 2. resolve bin path
|
|
201
220
|
const npmPrefix = process.env.NPM_PREFIX || "";
|
|
202
221
|
const binName = process.platform === "win32" ? "chatccc.cmd" : "chatccc";
|
|
203
222
|
const binPath = npmPrefix ? join(npmPrefix, binName) : "chatccc";
|
|
223
|
+
updLog(`bin path: npmPrefix=${npmPrefix || "(empty)"}, binPath=${binPath}`);
|
|
224
|
+
appendStartupTrace("updateg: spawn begin", { npmPrefix: npmPrefix || "(empty)", binPath });
|
|
225
|
+
|
|
226
|
+
// 3. spawn new chatccc
|
|
204
227
|
try {
|
|
205
228
|
const child = spawn(binPath, [], { detached: true, stdio: "ignore", shell: true });
|
|
206
229
|
child.unref();
|
|
207
230
|
updLog(`spawn new chatccc OK, childPid=${child.pid}, bin=${binPath}`);
|
|
231
|
+
appendStartupTrace("updateg: spawn OK", { childPid: child.pid, binPath });
|
|
208
232
|
} catch (e) {
|
|
209
|
-
|
|
233
|
+
const errMsg = (e as Error).message;
|
|
234
|
+
updLog(`spawn new chatccc failed: ${errMsg}`);
|
|
235
|
+
appendStartupTrace("updateg: spawn failed", { error: errMsg });
|
|
210
236
|
}
|
|
211
237
|
|
|
212
238
|
updLog("sync update done, parent exiting in 2s");
|
|
239
|
+
appendStartupTrace("updateg: sync update done, exiting in 2s", { pid: process.pid });
|
|
213
240
|
}
|
|
214
241
|
|
|
215
242
|
// ---------------------------------------------------------------------------
|
|
@@ -267,7 +294,9 @@ export async function handleCommand(
|
|
|
267
294
|
|
|
268
295
|
if (textLower === "/updateg") {
|
|
269
296
|
logTrace(tid, "BRANCH", { cmd: "/updateg" });
|
|
270
|
-
|
|
297
|
+
const isGlobal = isRunningFromGlobalNpm();
|
|
298
|
+
appendStartupTrace("updateg: command received", { isGlobal, chatId });
|
|
299
|
+
if (!isGlobal) {
|
|
271
300
|
await platform.sendText(chatId, "当前进程非 npm 全局安装,无法使用 /updateg 更新。请通过 npm install -g chatccc 安装后使用。").catch(() => {});
|
|
272
301
|
logTrace(tid, "DONE", { outcome: "updateg_not_global" });
|
|
273
302
|
return;
|