@hmharness/cli 0.23.41 → 0.23.43

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.
@@ -62,10 +62,16 @@ let PACKAGES = ['cli', 'web', 'agent', 'kernel', 'sandbox', 'evolution',
62
62
  // Known-good pin set (offline fallback when the registry is unreachable).
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
+ // 2026-10-27 fix: this list had only 10 names while PACKAGES had grown to 15 —
66
+ // pins[n] was undefined for cognitive/environments/lsp/browser/extension, so
67
+ // the offline path tried <name>-undefined.tgz → 404 → INSTALL FAILED (directly
68
+ // contradicting the promise above; evidence: cli 0.23.42 declares 14 deps).
65
69
  const FALLBACK_PINS = {
66
- cli: '0.23.41', web: '0.23.41', agent: '0.23.41', kernel: '0.23.41',
67
- sandbox: '0.23.41', evolution: '0.23.41', 'domain-ops': '0.23.41',
68
- evaluation: '0.23.41', observability: '0.23.41', 'domain-harmony': '0.23.41',
70
+ cli: '0.23.43', web: '0.23.43', agent: '0.23.43', kernel: '0.23.43',
71
+ sandbox: '0.23.43', evolution: '0.23.43', 'domain-ops': '0.23.43',
72
+ evaluation: '0.23.43', observability: '0.23.43', 'domain-harmony': '0.23.43',
73
+ cognitive: '0.23.43', environments: '0.23.43', lsp: '0.23.43',
74
+ browser: '0.23.43', extension: '0.23.43',
69
75
  };
70
76
 
71
77
  // ---------- helpers ---------------------------------------------------------
@@ -66,7 +66,11 @@ function runHmh(args, timeoutMs) {
66
66
  }
67
67
  async function cycle() {
68
68
  try {
69
- const evo = await runHmh(['evolve'], 600000);
69
+ // 30min: a HEALTHY evolve cycle does 40+ real judge/model calls and can
70
+ // exceed the old 10min cap — the 401 era finished in seconds (every trap
71
+ // failed fast), so 600s never bit until the fix landed and real work
72
+ // resumed. The cap must cover real work, not the failure mode.
73
+ const evo = await runHmh(['evolve'], 1800000);
70
74
  console.log(stamp(), 'evolve cycle done', evo.err ? ('err ' + String(evo.err).slice(0, 120)) : '');
71
75
  } catch (e) { console.error(stamp(), 'evolve error:', String(e).slice(0, 200)); }
72
76
  // finetune gate after every evolve cycle - the command itself decides
@@ -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;
@@ -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 ? '已停止扩展桥守护\n' : '守护本就未运行\n');
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
- ? `✓ 扩展桥守护已启动(后台) — 浏览器打开后 30 秒内自动连接\n`
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.41",
3
+ "version": "0.23.43",
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.39",
49
- "@hmharness/browser": "0.23.39",
50
- "@hmharness/cognitive": "0.23.39",
51
- "@hmharness/domain-harmony": "0.23.39",
52
- "@hmharness/domain-ops": "0.23.39",
53
- "@hmharness/environments": "0.23.39",
54
- "@hmharness/evaluation": "0.23.39",
55
- "@hmharness/evolution": "0.23.39",
56
- "@hmharness/extension": "0.23.39",
57
- "@hmharness/kernel": "0.23.39",
58
- "@hmharness/observability": "0.23.39",
59
- "@hmharness/sandbox": "0.23.39",
60
- "@hmharness/web": "0.23.39",
48
+ "@hmharness/agent": "0.23.43",
49
+ "@hmharness/browser": "0.23.43",
50
+ "@hmharness/cognitive": "0.23.43",
51
+ "@hmharness/domain-harmony": "0.23.43",
52
+ "@hmharness/domain-ops": "0.23.43",
53
+ "@hmharness/environments": "0.23.43",
54
+ "@hmharness/evaluation": "0.23.43",
55
+ "@hmharness/evolution": "0.23.43",
56
+ "@hmharness/extension": "0.23.43",
57
+ "@hmharness/kernel": "0.23.43",
58
+ "@hmharness/observability": "0.23.43",
59
+ "@hmharness/sandbox": "0.23.43",
60
+ "@hmharness/web": "0.23.43",
61
61
  "qrcode": "^1.5.4",
62
- "@hmharness/lsp": "0.23.39"
62
+ "@hmharness/lsp": "0.23.43"
63
63
  }
64
64
  }
@@ -1,5 +1,15 @@
1
1
  {
2
2
  "notes": [
3
+ {
4
+ "v": "0.23.43",
5
+ "date": "2026-10-27",
6
+ "note": "沙箱隔离诚实化+fail-closed(Docker 兜底谎言根除/TrustLevel 四档/单一证据源)+演化守护 30min+FALLBACK_PINS 15 名;993 测试"
7
+ },
8
+ {
9
+ "v": "0.23.42",
10
+ "date": "2026-10-27",
11
+ "note": "发版管线钉版事故修复(0.23.40/0.23.41 混合版本出厂——44 钉同步 0.23.42+一致性门禁硬检查;两轮根修首次真正到达用户)"
12
+ },
3
13
  {
4
14
  "v": "0.23.41",
5
15
  "date": "2026-10-27",