zhclaw 0.4.0 → 0.5.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.
|
@@ -34,6 +34,7 @@ var DOCTOR_HOME = APP_HOME;
|
|
|
34
34
|
var CONFIG_PATH = join2(APP_HOME, "config.json");
|
|
35
35
|
var DOCTOR_LOG_DIR = join2(APP_HOME, "logs");
|
|
36
36
|
var PID_FILE = join2(APP_HOME, "daemon.pid");
|
|
37
|
+
var STOP_FLAG_FILE = join2(APP_HOME, "gateway.stopped");
|
|
37
38
|
var defaults = {
|
|
38
39
|
checkInterval: 30,
|
|
39
40
|
failThreshold: 5,
|
|
@@ -234,11 +235,12 @@ function getRestartCommand(info) {
|
|
|
234
235
|
}
|
|
235
236
|
function getStopCommand(info) {
|
|
236
237
|
const uid = process.getuid?.() ?? 501;
|
|
237
|
-
return `launchctl kill SIGTERM gui/${uid}/${info.launchdLabel}`;
|
|
238
|
+
return `launchctl bootout gui/${uid}/${info.launchdLabel} 2>/dev/null || launchctl kill SIGTERM gui/${uid}/${info.launchdLabel} 2>/dev/null || true`;
|
|
238
239
|
}
|
|
239
240
|
function getStartCommand(info) {
|
|
240
241
|
const uid = process.getuid?.() ?? 501;
|
|
241
|
-
|
|
242
|
+
const plistDir = `${process.env.HOME}/Library/LaunchAgents`;
|
|
243
|
+
return `(launchctl bootstrap gui/${uid} ${plistDir}/${info.launchdLabel}.plist 2>/dev/null || true) && launchctl kickstart gui/${uid}/${info.launchdLabel}`;
|
|
242
244
|
}
|
|
243
245
|
|
|
244
246
|
// src/core/logger.ts
|
|
@@ -514,7 +516,7 @@ function scanCosts(agents) {
|
|
|
514
516
|
}
|
|
515
517
|
|
|
516
518
|
// src/dashboard/server.ts
|
|
517
|
-
var _PKG_VER = true ? "0.
|
|
519
|
+
var _PKG_VER = true ? "0.5.0" : "0.2.1";
|
|
518
520
|
var pkgVersion = _PKG_VER;
|
|
519
521
|
function readDoctorLogs(maxLines = 50) {
|
|
520
522
|
if (!existsSync6(DOCTOR_LOG_DIR)) return [];
|
|
@@ -1134,6 +1136,7 @@ export {
|
|
|
1134
1136
|
DISPLAY_NAME,
|
|
1135
1137
|
DOCTOR_LOG_DIR,
|
|
1136
1138
|
PID_FILE,
|
|
1139
|
+
STOP_FLAG_FILE,
|
|
1137
1140
|
ensureDoctorHome,
|
|
1138
1141
|
loadConfig,
|
|
1139
1142
|
initLogger,
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
DOCTOR_LOG_DIR,
|
|
7
7
|
PID_FILE,
|
|
8
8
|
RestartThrottle,
|
|
9
|
+
STOP_FLAG_FILE,
|
|
9
10
|
__require,
|
|
10
11
|
checkHealth,
|
|
11
12
|
detectOpenClaw,
|
|
@@ -18,7 +19,7 @@ import {
|
|
|
18
19
|
startDashboard,
|
|
19
20
|
startGateway,
|
|
20
21
|
stopGateway
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-XSRH4RHR.js";
|
|
22
23
|
|
|
23
24
|
// src/index.ts
|
|
24
25
|
import { spawnSync } from "child_process";
|
|
@@ -174,7 +175,7 @@ async function watchDaemon(options) {
|
|
|
174
175
|
log("info", `Check interval: ${config.checkInterval}s`);
|
|
175
176
|
log("info", `PID: ${process.pid}`);
|
|
176
177
|
if (options.dashboard) {
|
|
177
|
-
const { startDashboard: startDashboard2 } = await import("./server-
|
|
178
|
+
const { startDashboard: startDashboard2 } = await import("./server-3JMOADVR.js");
|
|
178
179
|
startDashboard2({ config: options.config });
|
|
179
180
|
}
|
|
180
181
|
const throttle = new RestartThrottle(config.maxRestartsPerHour);
|
|
@@ -182,6 +183,10 @@ async function watchDaemon(options) {
|
|
|
182
183
|
let isRestarting = false;
|
|
183
184
|
async function tick() {
|
|
184
185
|
if (isRestarting) return;
|
|
186
|
+
if (existsSync2(STOP_FLAG_FILE)) {
|
|
187
|
+
log("info", "Gateway is manually stopped \u2014 skipping auto-restart");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
185
190
|
const result = await checkHealth(info);
|
|
186
191
|
if (result.healthy) {
|
|
187
192
|
consecutiveFailures = 0;
|
|
@@ -204,7 +209,7 @@ async function watchDaemon(options) {
|
|
|
204
209
|
consecutiveFailures = 0;
|
|
205
210
|
throttle.record();
|
|
206
211
|
await restartGateway(info);
|
|
207
|
-
log("info", "Waiting
|
|
212
|
+
log("info", "Waiting 60s for gateway to start...");
|
|
208
213
|
await new Promise((r) => setTimeout(r, 6e4));
|
|
209
214
|
isRestarting = false;
|
|
210
215
|
}
|
|
@@ -556,14 +561,20 @@ function showDoctorLogs(maxLines) {
|
|
|
556
561
|
|
|
557
562
|
// src/commands/gateway.ts
|
|
558
563
|
import chalk5 from "chalk";
|
|
559
|
-
|
|
564
|
+
import { writeFileSync as writeFileSync4, unlinkSync as unlinkSync2 } from "fs";
|
|
565
|
+
var _VER = true ? "0.5.0" : void 0;
|
|
560
566
|
async function gatewayStart(options) {
|
|
561
567
|
const config = loadConfig(options.config);
|
|
562
568
|
initLogger();
|
|
569
|
+
ensureDoctorHome();
|
|
563
570
|
const info = detectOpenClaw(options.profile ?? config.openclawProfile);
|
|
571
|
+
try {
|
|
572
|
+
unlinkSync2(STOP_FLAG_FILE);
|
|
573
|
+
} catch {
|
|
574
|
+
}
|
|
564
575
|
const result = await startGateway(info);
|
|
565
576
|
if (result.success) {
|
|
566
|
-
console.log(chalk5.green("Gateway started"));
|
|
577
|
+
console.log(chalk5.green("Gateway started (auto-restart resumed)"));
|
|
567
578
|
trackCommand("gateway start", true, _VER).catch(() => {
|
|
568
579
|
});
|
|
569
580
|
} else {
|
|
@@ -576,10 +587,13 @@ async function gatewayStart(options) {
|
|
|
576
587
|
async function gatewayStop(options) {
|
|
577
588
|
const config = loadConfig(options.config);
|
|
578
589
|
initLogger();
|
|
590
|
+
ensureDoctorHome();
|
|
579
591
|
const info = detectOpenClaw(options.profile ?? config.openclawProfile);
|
|
580
592
|
const result = await stopGateway(info);
|
|
581
593
|
if (result.success) {
|
|
582
|
-
|
|
594
|
+
writeFileSync4(STOP_FLAG_FILE, (/* @__PURE__ */ new Date()).toISOString());
|
|
595
|
+
console.log(chalk5.green("Gateway stopped (auto-restart paused)"));
|
|
596
|
+
console.log(chalk5.gray(" Run `gateway start` to resume."));
|
|
583
597
|
trackCommand("gateway stop", true, _VER).catch(() => {
|
|
584
598
|
});
|
|
585
599
|
} else {
|
|
@@ -592,10 +606,15 @@ async function gatewayStop(options) {
|
|
|
592
606
|
async function gatewayRestart(options) {
|
|
593
607
|
const config = loadConfig(options.config);
|
|
594
608
|
initLogger();
|
|
609
|
+
ensureDoctorHome();
|
|
595
610
|
const info = detectOpenClaw(options.profile ?? config.openclawProfile);
|
|
611
|
+
try {
|
|
612
|
+
unlinkSync2(STOP_FLAG_FILE);
|
|
613
|
+
} catch {
|
|
614
|
+
}
|
|
596
615
|
const result = await restartGateway(info);
|
|
597
616
|
if (result.success) {
|
|
598
|
-
console.log(chalk5.green("Gateway restarted"));
|
|
617
|
+
console.log(chalk5.green("Gateway restarted (auto-restart resumed)"));
|
|
599
618
|
trackCommand("gateway restart", true, _VER).catch(() => {
|
|
600
619
|
});
|
|
601
620
|
} else {
|
|
@@ -608,7 +627,7 @@ async function gatewayRestart(options) {
|
|
|
608
627
|
|
|
609
628
|
// src/commands/memory.ts
|
|
610
629
|
import chalk6 from "chalk";
|
|
611
|
-
import { existsSync as
|
|
630
|
+
import { existsSync as existsSync6, statSync } from "fs";
|
|
612
631
|
import { join as join3 } from "path";
|
|
613
632
|
import { homedir } from "os";
|
|
614
633
|
function expandHome(p) {
|
|
@@ -623,7 +642,7 @@ async function memoryStatus(options) {
|
|
|
623
642
|
if (!ws) continue;
|
|
624
643
|
const wsPath = expandHome(ws);
|
|
625
644
|
const memPath = join3(wsPath, "MEMORY.md");
|
|
626
|
-
const exists =
|
|
645
|
+
const exists = existsSync6(memPath);
|
|
627
646
|
const sizeKB = exists ? Math.round(statSync(memPath).size / 1024) : 0;
|
|
628
647
|
const warn = sizeKB > 50;
|
|
629
648
|
const indicator = warn ? chalk6.yellow("\u26A0") : chalk6.green("\u2713");
|
|
@@ -683,7 +702,7 @@ function telemetryStatus() {
|
|
|
683
702
|
}
|
|
684
703
|
|
|
685
704
|
// src/index.ts
|
|
686
|
-
var _PKG_VER = true ? "0.
|
|
705
|
+
var _PKG_VER = true ? "0.5.0" : "0.2.1";
|
|
687
706
|
var version = _PKG_VER;
|
|
688
707
|
printFirstRunNotice();
|
|
689
708
|
var program = new Command();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zhclaw",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "OpenClaw CLI for Zhihu/Zhipu AI users. Alias of openclaw-cli.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"zhclaw": "./dist/index.js"
|
|
@@ -15,11 +15,9 @@
|
|
|
15
15
|
"keywords": [
|
|
16
16
|
"openclaw",
|
|
17
17
|
"openclaw-cli",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"gateway"
|
|
21
|
-
"watchdog",
|
|
22
|
-
"health-check"
|
|
18
|
+
"zhipu",
|
|
19
|
+
"chatglm",
|
|
20
|
+
"ai-gateway"
|
|
23
21
|
],
|
|
24
22
|
"license": "MIT",
|
|
25
23
|
"repository": {
|