@hmharness/cli 0.23.41 → 0.23.42
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/board/install-kaihongos.cjs +3 -3
- package/dist/extension-daemon.d.ts +14 -0
- package/dist/extension-daemon.js +84 -0
- package/dist/main.js +10 -4
- package/package.json +15 -15
- package/release-notes.json +5 -0
|
@@ -63,9 +63,9 @@ let PACKAGES = ['cli', 'web', 'agent', 'kernel', 'sandbox', 'evolution',
|
|
|
63
63
|
// The release bot keeps versions synced; the NAMES must cover the full
|
|
64
64
|
// first-party set so the offline path cannot produce an incomplete tree.
|
|
65
65
|
const FALLBACK_PINS = {
|
|
66
|
-
cli: '0.23.
|
|
67
|
-
sandbox: '0.23.
|
|
68
|
-
evaluation: '0.23.
|
|
66
|
+
cli: '0.23.42', web: '0.23.42', agent: '0.23.42', kernel: '0.23.42',
|
|
67
|
+
sandbox: '0.23.42', evolution: '0.23.42', 'domain-ops': '0.23.42',
|
|
68
|
+
evaluation: '0.23.42', observability: '0.23.42', 'domain-harmony': '0.23.42',
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
// ---------- helpers ---------------------------------------------------------
|
|
@@ -21,3 +21,17 @@ export declare function startExtensionDaemon(port?: number, entry?: string): {
|
|
|
21
21
|
already: boolean;
|
|
22
22
|
pid: number;
|
|
23
23
|
};
|
|
24
|
+
/** Path of the watchdog pid file under HMH_HOME. */
|
|
25
|
+
export declare function watchdogPidPath(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Watchdog body (runs INSIDE the detached watchdog process): probe the
|
|
28
|
+
* bridge every 60s; dead or stale → respawn it. Idempotent by design —
|
|
29
|
+
* a second watchdog exits when the pid file already names a live process.
|
|
30
|
+
* The bridge dying must never be a state the user can observe (round 54:
|
|
31
|
+
* "插件又不能用了" = the daemon had silently died and nothing revived it).
|
|
32
|
+
*/
|
|
33
|
+
export declare function runWatchdogLoop(port: number, entry: string): Promise<never>;
|
|
34
|
+
/** Spawn the watchdog detached (no window). Safe to call repeatedly. */
|
|
35
|
+
export declare function startWatchdog(port?: number, entry?: string): number;
|
|
36
|
+
/** Stop the watchdog (used by `extension stop` — it must not resurrect). */
|
|
37
|
+
export declare function stopWatchdog(): boolean;
|
package/dist/extension-daemon.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { spawn, execSync } from 'node:child_process';
|
|
12
12
|
import { createRequire } from 'node:module';
|
|
13
|
+
import { pathToFileURL } from 'node:url';
|
|
13
14
|
import { openSync, readFileSync, unlinkSync, writeFileSync, closeSync } from 'node:fs';
|
|
14
15
|
import { join } from 'node:path';
|
|
15
16
|
import { homeDir } from '@hmharness/kernel';
|
|
@@ -172,3 +173,86 @@ export function startExtensionDaemon(port = DEFAULT_EXTENSION_PORT, entry = proc
|
|
|
172
173
|
return { already: true, pid };
|
|
173
174
|
return { already: false, pid: spawnExtensionDaemon(entry, port) };
|
|
174
175
|
}
|
|
176
|
+
// --------------------------------------------------------------- watchdog
|
|
177
|
+
/** Path of the watchdog pid file under HMH_HOME. */
|
|
178
|
+
export function watchdogPidPath() {
|
|
179
|
+
return join(homeDir(), 'extension-watchdog.pid');
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Watchdog body (runs INSIDE the detached watchdog process): probe the
|
|
183
|
+
* bridge every 60s; dead or stale → respawn it. Idempotent by design —
|
|
184
|
+
* a second watchdog exits when the pid file already names a live process.
|
|
185
|
+
* The bridge dying must never be a state the user can observe (round 54:
|
|
186
|
+
* "插件又不能用了" = the daemon had silently died and nothing revived it).
|
|
187
|
+
*/
|
|
188
|
+
export async function runWatchdogLoop(port, entry) {
|
|
189
|
+
const wp = watchdogPidPath();
|
|
190
|
+
try {
|
|
191
|
+
const existing = Number(readFileSync(wp, 'utf8').trim());
|
|
192
|
+
if (Number.isFinite(existing) && existing > 0 && existing !== process.pid && alive(existing)) {
|
|
193
|
+
process.exit(0); // another watchdog is on duty
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch { /* no pid file yet */ }
|
|
197
|
+
writeFileSync(wp, String(process.pid));
|
|
198
|
+
for (;;) {
|
|
199
|
+
try {
|
|
200
|
+
const served = await probeExtensionDaemon(port);
|
|
201
|
+
const pid = readExtensionPid();
|
|
202
|
+
const stale = pid > 0 && alive(pid) && recordedVersion() !== cliVersion();
|
|
203
|
+
if (!served.up || stale) {
|
|
204
|
+
if (stale)
|
|
205
|
+
stopExtensionDaemon(port);
|
|
206
|
+
await waitExtensionPortFree(port, 3000);
|
|
207
|
+
spawnExtensionDaemon(entry, port);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch { /* a watchdog that throws is a watchdog that dies — never */ }
|
|
211
|
+
await new Promise((r) => setTimeout(r, 60_000));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** Spawn the watchdog detached (no window). Safe to call repeatedly. */
|
|
215
|
+
export function startWatchdog(port = DEFAULT_EXTENSION_PORT, entry = process.argv[1]) {
|
|
216
|
+
try {
|
|
217
|
+
const wp = watchdogPidPath();
|
|
218
|
+
const existing = Number(readFileSync(wp, 'utf8').trim());
|
|
219
|
+
if (Number.isFinite(existing) && existing > 0 && alive(existing))
|
|
220
|
+
return existing;
|
|
221
|
+
}
|
|
222
|
+
catch { /* none yet */ }
|
|
223
|
+
const log = openSync(join(homeDir(), 'extension-watchdog.log'), 'a');
|
|
224
|
+
const child = spawn(process.execPath, [
|
|
225
|
+
'-e',
|
|
226
|
+
`import('${pathToFileURL(entry).href.replace(/main\.js$/, 'extension-daemon.js')}').then(m => m.runWatchdogLoop(${port}, ${JSON.stringify(entry)}))`,
|
|
227
|
+
], { detached: true, stdio: ['ignore', log, log], windowsHide: true });
|
|
228
|
+
child.unref();
|
|
229
|
+
try {
|
|
230
|
+
closeSync(log);
|
|
231
|
+
}
|
|
232
|
+
catch { /* gone */ }
|
|
233
|
+
return child.pid ?? 0;
|
|
234
|
+
}
|
|
235
|
+
/** Stop the watchdog (used by `extension stop` — it must not resurrect). */
|
|
236
|
+
export function stopWatchdog() {
|
|
237
|
+
try {
|
|
238
|
+
const wp = watchdogPidPath();
|
|
239
|
+
const pid = Number(readFileSync(wp, 'utf8').trim());
|
|
240
|
+
if (Number.isFinite(pid) && pid > 0 && alive(pid)) {
|
|
241
|
+
if (process.platform === 'win32')
|
|
242
|
+
spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { windowsHide: true });
|
|
243
|
+
else
|
|
244
|
+
process.kill(pid);
|
|
245
|
+
try {
|
|
246
|
+
unlinkSync(wp);
|
|
247
|
+
}
|
|
248
|
+
catch { /* absent */ }
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
unlinkSync(wp);
|
|
253
|
+
}
|
|
254
|
+
catch { /* absent */ }
|
|
255
|
+
}
|
|
256
|
+
catch { /* none */ }
|
|
257
|
+
return false;
|
|
258
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -1181,11 +1181,12 @@ flags:
|
|
|
1181
1181
|
const port = pArg ? Number(pArg.slice(7)) : undefined;
|
|
1182
1182
|
const ed = await import("./extension-daemon.js");
|
|
1183
1183
|
if (sub === 'stop') {
|
|
1184
|
+
const w = ed.stopWatchdog();
|
|
1184
1185
|
const killed = ed.stopExtensionDaemon(port);
|
|
1185
|
-
stdout.write(killed ? '
|
|
1186
|
+
stdout.write(w || killed ? '已停止扩展桥守护(含看门狗)\n' : '守护本就未运行\n');
|
|
1186
1187
|
return;
|
|
1187
1188
|
}
|
|
1188
|
-
const { probeExtensionDaemon, ensureExtensionDaemon, DEFAULT_EXTENSION_PORT } = ed;
|
|
1189
|
+
const { probeExtensionDaemon, ensureExtensionDaemon, startWatchdog, DEFAULT_EXTENSION_PORT } = ed;
|
|
1189
1190
|
const p = port ?? DEFAULT_EXTENSION_PORT;
|
|
1190
1191
|
const already = await probeExtensionDaemon(p);
|
|
1191
1192
|
if (already.up) {
|
|
@@ -1197,7 +1198,10 @@ flags:
|
|
|
1197
1198
|
stdout.write(`✗ 守护启动失败(详见 ${homeDir()}/extension.log)\n`);
|
|
1198
1199
|
return;
|
|
1199
1200
|
}
|
|
1201
|
+
const wpid = startWatchdog(p);
|
|
1200
1202
|
stdout.write(`✓ 扩展桥守护已启动(后台,PID 文件 ${homeDir()}/extension.pid)\n`);
|
|
1203
|
+
if (wpid)
|
|
1204
|
+
stdout.write(`✓ 看门狗已就位(每 60s 自检,桥意外死亡自动复活)\n`);
|
|
1201
1205
|
stdout.write(r.connected ? ' 浏览器扩展已连接 — 智能体 extension_* 工具可用\n' : ' 装有扩展的浏览器 30 秒内自动连接(浏览器先开也行)\n');
|
|
1202
1206
|
stdout.write(DIM(' 停止: hmh extension stop;前台调试: hmh extension serve;状态: hmh extension status\n'));
|
|
1203
1207
|
return;
|
|
@@ -1250,10 +1254,12 @@ flags:
|
|
|
1250
1254
|
stdout.write(DIM(' 生效时机: 浏览器重启后常驻;撤销: hmh extension uninstall\n'));
|
|
1251
1255
|
// 装完即用:终端侧零操作 —— 直接把桥守护拉起(幂等,已在跑则跳过)
|
|
1252
1256
|
try {
|
|
1253
|
-
const { ensureExtensionDaemon } = await import("./extension-daemon.js");
|
|
1257
|
+
const { ensureExtensionDaemon, startWatchdog } = await import("./extension-daemon.js");
|
|
1254
1258
|
const p = await ensureExtensionDaemon(pArg ? Number(pArg.slice(7)) : undefined);
|
|
1259
|
+
if (p.up)
|
|
1260
|
+
startWatchdog(pArg ? Number(pArg.slice(7)) : undefined);
|
|
1255
1261
|
stdout.write(p.up
|
|
1256
|
-
? `✓ 扩展桥守护已启动(
|
|
1262
|
+
? `✓ 扩展桥守护已启动(后台+看门狗) — 浏览器打开后 30 秒内自动连接\n`
|
|
1257
1263
|
: DIM(' · 桥守护未能启动 — 手动: hmh extension start\n'));
|
|
1258
1264
|
}
|
|
1259
1265
|
catch { /* 守护是锦上添花,不阻塞安装报告 */ }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.42",
|
|
4
4
|
"description": "hmharness command line: one-shot tasks, an interactive REPL, a fullscreen TUI, the web frontend, and direct tool invocation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -45,20 +45,20 @@
|
|
|
45
45
|
"build": "tsc -p tsconfig.build.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@hmharness/agent": "0.23.
|
|
49
|
-
"@hmharness/browser": "0.23.
|
|
50
|
-
"@hmharness/cognitive": "0.23.
|
|
51
|
-
"@hmharness/domain-harmony": "0.23.
|
|
52
|
-
"@hmharness/domain-ops": "0.23.
|
|
53
|
-
"@hmharness/environments": "0.23.
|
|
54
|
-
"@hmharness/evaluation": "0.23.
|
|
55
|
-
"@hmharness/evolution": "0.23.
|
|
56
|
-
"@hmharness/extension": "0.23.
|
|
57
|
-
"@hmharness/kernel": "0.23.
|
|
58
|
-
"@hmharness/observability": "0.23.
|
|
59
|
-
"@hmharness/sandbox": "0.23.
|
|
60
|
-
"@hmharness/web": "0.23.
|
|
48
|
+
"@hmharness/agent": "0.23.42",
|
|
49
|
+
"@hmharness/browser": "0.23.42",
|
|
50
|
+
"@hmharness/cognitive": "0.23.42",
|
|
51
|
+
"@hmharness/domain-harmony": "0.23.42",
|
|
52
|
+
"@hmharness/domain-ops": "0.23.42",
|
|
53
|
+
"@hmharness/environments": "0.23.42",
|
|
54
|
+
"@hmharness/evaluation": "0.23.42",
|
|
55
|
+
"@hmharness/evolution": "0.23.42",
|
|
56
|
+
"@hmharness/extension": "0.23.42",
|
|
57
|
+
"@hmharness/kernel": "0.23.42",
|
|
58
|
+
"@hmharness/observability": "0.23.42",
|
|
59
|
+
"@hmharness/sandbox": "0.23.42",
|
|
60
|
+
"@hmharness/web": "0.23.42",
|
|
61
61
|
"qrcode": "^1.5.4",
|
|
62
|
-
"@hmharness/lsp": "0.23.
|
|
62
|
+
"@hmharness/lsp": "0.23.42"
|
|
63
63
|
}
|
|
64
64
|
}
|