@hmharness/cli 0.18.13 → 0.18.15
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/main.js +71 -3
- package/dist/tui.js +82 -1
- package/dist/web-daemon.d.ts +1 -1
- package/dist/web-daemon.js +7 -5
- package/package.json +11 -10
package/dist/main.js
CHANGED
|
@@ -912,6 +912,60 @@ flags:
|
|
|
912
912
|
if (cmd === 'web') {
|
|
913
913
|
await initHome();
|
|
914
914
|
const port = Number(rest.find((a) => a.startsWith('--port='))?.slice(7) ?? 7788);
|
|
915
|
+
// remote control (2026-09-28): --exposure=lan|wan opens the UI to other
|
|
916
|
+
// devices; web.token in config.json is the auth (REQUIRED for lan/wan).
|
|
917
|
+
// CLI flags win over config: --exposure / --token=... / --token-gen.
|
|
918
|
+
const cfgWeb = await loadConfig();
|
|
919
|
+
const exposureArg = rest.find((a) => a.startsWith('--exposure='))?.slice(11);
|
|
920
|
+
const exposure = (exposureArg === 'lan' || exposureArg === 'wan' || exposureArg === 'loopback')
|
|
921
|
+
? exposureArg
|
|
922
|
+
: (cfgWeb.web?.exposure === 'lan' || cfgWeb.web?.exposure === 'wan')
|
|
923
|
+
? cfgWeb.web.exposure
|
|
924
|
+
: 'loopback';
|
|
925
|
+
const tokenArg = rest.find((a) => a.startsWith('--token='))?.slice(8);
|
|
926
|
+
let webToken = tokenArg ?? cfgWeb.web?.token ?? '';
|
|
927
|
+
if ((exposure === 'lan' || exposure === 'wan') && rest.includes('--token-gen')) {
|
|
928
|
+
webToken = 'hmh-' + Math.random().toString(36).slice(2, 10) + Math.random().toString(36).slice(2, 8);
|
|
929
|
+
const { patchConfig } = await import('@hmharness/kernel');
|
|
930
|
+
await patchConfig({ web: { exposure, token: webToken } });
|
|
931
|
+
}
|
|
932
|
+
if ((exposure === 'lan' || exposure === 'wan') && !webToken && !rest.includes('--token-gen')) {
|
|
933
|
+
// Pairing (QR one-time token) no longer needs a long-term key; the
|
|
934
|
+
// cfg token is just an extra always-valid link. Hint, don't block.
|
|
935
|
+
stdout.write(DIM('(提示:手机用网页里的 📱 二维码配对即可;如需长期固定链接可加 --token-gen)\n'));
|
|
936
|
+
}
|
|
937
|
+
if ((exposure === 'lan' || exposure === 'wan') && tokenArg) {
|
|
938
|
+
const { patchConfig } = await import('@hmharness/kernel');
|
|
939
|
+
await patchConfig({ web: { exposure, token: webToken } });
|
|
940
|
+
}
|
|
941
|
+
if (exposure !== 'loopback') {
|
|
942
|
+
// print the phone-ready access info once; the LAN IP shown must be the
|
|
943
|
+
// one a phone on the same WiFi can route to (virtual adapters like
|
|
944
|
+
// Tailscale/VMware excluded — see server.ts preferredLanAddress).
|
|
945
|
+
const osMod = await import('node:os');
|
|
946
|
+
const VIRTUAL = /vmware|virtual|hyper-?v|vethernet|wsl|tailscale|loopback|bluetooth|vbox|docker|tap-|pseudo/i;
|
|
947
|
+
const isRfc1918 = (a) => /^10\./.test(a) || /^192\.168\./.test(a) || /^172\.(1[6-9]|2\d|3[01])\./.test(a);
|
|
948
|
+
let lanIp = '';
|
|
949
|
+
let virtualFallback = '';
|
|
950
|
+
for (const [name, list] of Object.entries(osMod.networkInterfaces())) {
|
|
951
|
+
for (const n of list ?? []) {
|
|
952
|
+
if (n.family !== 'IPv4' || n.internal || !isRfc1918(n.address))
|
|
953
|
+
continue;
|
|
954
|
+
if (!VIRTUAL.test(name)) {
|
|
955
|
+
lanIp = lanIp || n.address;
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
virtualFallback = virtualFallback || n.address;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
lanIp = lanIp || virtualFallback;
|
|
963
|
+
stdout.write(YELLOW('手机连接:打开 http://127.0.0.1:' + port + ' 点 📱 扫二维码(WiFi 直连免密码;互联网模式任何网络可用)\n'));
|
|
964
|
+
if (lanIp)
|
|
965
|
+
stdout.write(YELLOW(`WiFi 地址:http://${lanIp}:${port}(手机与电脑同一 WiFi)\n`));
|
|
966
|
+
if (exposure === 'wan')
|
|
967
|
+
stdout.write(YELLOW('互联网模式:启动后自动建立免费隧道(trycloudflare.com),无需公网 IP/端口转发\n'));
|
|
968
|
+
}
|
|
915
969
|
const t = await uiStrings();
|
|
916
970
|
const sub = rest.find((a) => !a.startsWith('-'));
|
|
917
971
|
if (sub === 'stop') {
|
|
@@ -935,7 +989,16 @@ flags:
|
|
|
935
989
|
return;
|
|
936
990
|
}
|
|
937
991
|
if (sub === 'start') {
|
|
938
|
-
|
|
992
|
+
// forward remote-control flags to the daemon child so the exposure
|
|
993
|
+
// survives the respawn cycle (the child re-reads config.json too)
|
|
994
|
+
const passThrough = [];
|
|
995
|
+
const ex = rest.find((a) => a.startsWith('--exposure='));
|
|
996
|
+
if (ex)
|
|
997
|
+
passThrough.push(ex);
|
|
998
|
+
const tk = rest.find((a) => a.startsWith('--token='));
|
|
999
|
+
if (tk)
|
|
1000
|
+
passThrough.push(tk);
|
|
1001
|
+
const r = startWebDaemon(Number.isFinite(port) ? port : 7788, undefined, passThrough);
|
|
939
1002
|
// 2026-09-23: evolution runs silently alongside the web daemon - the
|
|
940
1003
|
// user never triggers `hmh evolve` manually (zero-config direction fix)
|
|
941
1004
|
try {
|
|
@@ -952,11 +1015,16 @@ flags:
|
|
|
952
1015
|
}
|
|
953
1016
|
return;
|
|
954
1017
|
}
|
|
955
|
-
// default: foreground server (handy for debugging)
|
|
1018
|
+
// default: foreground server (handy for debugging); foreground trusts the
|
|
1019
|
+
// config-file exposure (flags were persisted above when explicitly given)
|
|
956
1020
|
const { startServer } = await import('@hmharness/web');
|
|
957
1021
|
const { createRequire: cr } = await import('node:module');
|
|
958
1022
|
const ver = cr(import.meta.url)('../package.json').version ?? '';
|
|
959
|
-
await startServer({
|
|
1023
|
+
await startServer({
|
|
1024
|
+
port: Number.isFinite(port) ? port : 7788,
|
|
1025
|
+
host: exposure === 'loopback' ? '127.0.0.1' : '0.0.0.0',
|
|
1026
|
+
version: ver,
|
|
1027
|
+
});
|
|
960
1028
|
return; // startServer keeps the process alive
|
|
961
1029
|
}
|
|
962
1030
|
if (cmd === 'pipeline') {
|
package/dist/tui.js
CHANGED
|
@@ -120,6 +120,7 @@ export const COMMANDS = [
|
|
|
120
120
|
{ name: '/keymap', key: 'cmdKeymap' },
|
|
121
121
|
{ name: '/review', key: 'cmdReview' },
|
|
122
122
|
{ name: '/web', key: 'cmdWeb' },
|
|
123
|
+
{ name: '/remote', key: 'cmdRemote' },
|
|
123
124
|
{ name: '/exit', key: 'cmdExit' },
|
|
124
125
|
];
|
|
125
126
|
/** Commands whose name starts with the input (input must start with '/'). */
|
|
@@ -1885,7 +1886,10 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1885
1886
|
rt.addText(DIM(`✎ external editor (${editor}) → draft loaded (${edited.length} chars)`), 'dim');
|
|
1886
1887
|
}
|
|
1887
1888
|
catch (err) {
|
|
1889
|
+
// Recovery First (docx TUI 专项): external-editor failure suggests the
|
|
1890
|
+
// fallback explicitly - the draft is intact, nothing was lost
|
|
1888
1891
|
rt.addText(String(err), 'err');
|
|
1892
|
+
rt.addText(DIM('✎ 编辑器打开失败——草稿仍在输入框中未丢失。可直接在 TUI 里继续编辑,或检查 EDITOR 环境变量。 / editor failed; your draft is intact in the input box.'), 'dim');
|
|
1889
1893
|
}
|
|
1890
1894
|
});
|
|
1891
1895
|
// B14: remapped keys from config.json tui.keymap (applied at startup)
|
|
@@ -2053,6 +2057,9 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2053
2057
|
rt.setBusy(false);
|
|
2054
2058
|
currentInject = null;
|
|
2055
2059
|
rt.addText(String(err), 'err');
|
|
2060
|
+
// Recovery First (docx TUI 专项): every task failure names the next step
|
|
2061
|
+
// instead of leaving a bare stack - retry is one up-arrow away
|
|
2062
|
+
rt.addText(DIM('↑ 重新运行:按 ↑ 调回刚才的输入;持续失败可用 /model 换路由或 /status 查看状态。 / press ↑ to retry, /model to switch route.'), 'dim');
|
|
2056
2063
|
}
|
|
2057
2064
|
finally {
|
|
2058
2065
|
currentAbort = null;
|
|
@@ -2343,7 +2350,23 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2343
2350
|
const pretty = v === '\x1b' ? 'esc' : v === '\x0a' ? 'ctrl+enter' : v === '\x12' ? 'ctrl+r' : v === '\x14' ? 'ctrl+t' : v === '\x07' ? 'ctrl+g' : JSON.stringify(v);
|
|
2344
2351
|
return ` ${a.padEnd(14)} ${pretty}`;
|
|
2345
2352
|
});
|
|
2346
|
-
rt.addText('keymap (defaults in parens):\n' + rows.join('\n') + '\n\n/keymap <action>=<key> — e.g. /keymap inject=ctrl+j', 'dim');
|
|
2353
|
+
rt.addText('keymap (defaults in parens):\n' + rows.join('\n') + '\n\n/keymap <action>=<key> — e.g. /keymap inject=ctrl+j\n/keymap reset — restore all defaults', 'dim');
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2356
|
+
// docx TUI 专项: "/keymap 修改后必须能恢复默认" - reset restores every
|
|
2357
|
+
// binding to the factory default in one shot (config + live TUI)
|
|
2358
|
+
if (arg === 'reset' || arg === 'default') {
|
|
2359
|
+
try {
|
|
2360
|
+
const { patchConfig } = await import('@hmharness/kernel');
|
|
2361
|
+
const merged = { ...(cfg.tui ?? {}), keymap: { ...KEYMAP_DEFAULTS } };
|
|
2362
|
+
const fresh = await patchConfig({ tui: merged });
|
|
2363
|
+
cfg = fresh;
|
|
2364
|
+
rt.setKeymap({ ...KEYMAP_DEFAULTS });
|
|
2365
|
+
rt.addText(GREEN('✓') + ' keymap reset to defaults', 'plain');
|
|
2366
|
+
}
|
|
2367
|
+
catch (err) {
|
|
2368
|
+
rt.addText(String(err), 'err');
|
|
2369
|
+
}
|
|
2347
2370
|
return;
|
|
2348
2371
|
}
|
|
2349
2372
|
const eq = arg.indexOf('=');
|
|
@@ -2419,6 +2442,51 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2419
2442
|
rt.addText(up ? t.tuiWebLinked(DEFAULT_WEB_PORT) : t.tuiWebHint, 'dim');
|
|
2420
2443
|
return;
|
|
2421
2444
|
}
|
|
2445
|
+
if (line === '/remote' || line === '/remote lan' || line === '/remote wan') {
|
|
2446
|
+
// 2026-09-28 DSH Desktop pattern: /remote shows a QR of a ONE-TIME
|
|
2447
|
+
// pairing link fetched from the running web server (/api/pair-info).
|
|
2448
|
+
// WiFi scan = connected (no password); internet mode goes through a
|
|
2449
|
+
// free tunnel and asks the phone for the 6-digit PIN shown here.
|
|
2450
|
+
rt.setBusy(true, '/remote');
|
|
2451
|
+
try {
|
|
2452
|
+
const mode = line === '/remote wan' ? 'wan' : 'lan';
|
|
2453
|
+
const { patchConfig } = await import('@hmharness/kernel');
|
|
2454
|
+
let webCfg = cfg.web ?? {};
|
|
2455
|
+
if (webCfg.exposure !== mode) {
|
|
2456
|
+
await patchConfig({ web: { exposure: mode, token: webCfg.token ?? '' } });
|
|
2457
|
+
}
|
|
2458
|
+
// ensure daemon is up on the exposure
|
|
2459
|
+
await ensureWebDaemon(DEFAULT_WEB_PORT);
|
|
2460
|
+
// ask the SERVER for the live pairing state (token rotates there)
|
|
2461
|
+
const info = await fetch(`http://127.0.0.1:${DEFAULT_WEB_PORT}/api/pair-info`).then((r) => r.json());
|
|
2462
|
+
const url = (mode === 'wan' ? info.tunnelPairingUrl : info.lanPairingUrl) || info.pairingUrl || '';
|
|
2463
|
+
if (!url)
|
|
2464
|
+
throw new Error('no pairing URL (is the web server on --exposure=lan?)');
|
|
2465
|
+
const QR = (await import('qrcode')).default;
|
|
2466
|
+
const art = await QR.toString(url, { type: 'terminal', small: true, margin: 1 });
|
|
2467
|
+
rt.addText('┌─────────────────────────────────┐', 'plain');
|
|
2468
|
+
rt.addText('│ 📱 连接手机(' + (mode === 'lan' ? 'WiFi 直连' : '互联网隧道') + ') │', 'plain');
|
|
2469
|
+
rt.addText('├─────────────────────────────────┤', 'plain');
|
|
2470
|
+
for (const l of art.split('\n'))
|
|
2471
|
+
rt.addText('│' + l.replace(/\x1b\[[0-9;]*m/g, '') + '│', 'plain');
|
|
2472
|
+
rt.addText('├─────────────────────────────────┤', 'plain');
|
|
2473
|
+
if (mode === 'wan') {
|
|
2474
|
+
rt.addText('│ 配对密码(6位): ' + (info.pin ?? '(服务器窗口查看)'), 'plain');
|
|
2475
|
+
}
|
|
2476
|
+
rt.addText('│ 链接: ' + url, 'plain');
|
|
2477
|
+
rt.addText('│ (二维码 5 分钟内有效, 过期自动刷新)', 'plain');
|
|
2478
|
+
rt.addText('└─────────────────────────────────┘', 'plain');
|
|
2479
|
+
rt.addText(DIM(mode === 'lan'
|
|
2480
|
+
? '手机与电脑连同一 WiFi,扫码即连(无需密码)。'
|
|
2481
|
+
: '任何网络可连:扫码后在手机输入上面的 6 位密码。网页里可切换线路。'), 'dim');
|
|
2482
|
+
}
|
|
2483
|
+
catch (err) {
|
|
2484
|
+
rt.addText(String(err), 'err');
|
|
2485
|
+
rt.addText(DIM('/remote 失败 - 先运行: hmh web start --exposure=lan'), 'dim');
|
|
2486
|
+
}
|
|
2487
|
+
rt.setBusy(false);
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2422
2490
|
if (line === '/resume' || line.startsWith('/resume ')) {
|
|
2423
2491
|
const arg = line.slice(8).trim();
|
|
2424
2492
|
// bare /resume opens the Codex-style full-frame picker (typeahead,
|
|
@@ -2624,8 +2692,21 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2624
2692
|
return;
|
|
2625
2693
|
}
|
|
2626
2694
|
}
|
|
2695
|
+
// docx TUI 专项: "SIGINT/SIGTERM/异常退出必须 cleanup" - Ctrl+C in raw mode
|
|
2696
|
+
// never generates SIGINT (the byte is just read), but external kills and
|
|
2697
|
+
// terminal-level signals do; destroy() is idempotent so double-call is safe
|
|
2698
|
+
const sigCleanup = () => { try {
|
|
2699
|
+
rt.destroy();
|
|
2700
|
+
}
|
|
2701
|
+
catch { /* best effort */ } };
|
|
2702
|
+
process.once('SIGINT', sigCleanup);
|
|
2703
|
+
process.once('SIGTERM', sigCleanup);
|
|
2704
|
+
process.once('SIGHUP', sigCleanup);
|
|
2627
2705
|
await rt.waitExit();
|
|
2628
2706
|
rt.destroy();
|
|
2707
|
+
process.off('SIGINT', sigCleanup);
|
|
2708
|
+
process.off('SIGTERM', sigCleanup);
|
|
2709
|
+
process.off('SIGHUP', sigCleanup);
|
|
2629
2710
|
for (const c of clients)
|
|
2630
2711
|
c.close();
|
|
2631
2712
|
stdout.write('\n');
|
package/dist/web-daemon.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare function webDaemonStale(port?: number): Promise<{
|
|
|
39
39
|
daemon: string;
|
|
40
40
|
cli: string;
|
|
41
41
|
}>;
|
|
42
|
-
export declare function startWebDaemon(port?: number, entry?: string): {
|
|
42
|
+
export declare function startWebDaemon(port?: number, entry?: string, extraArgs?: string[]): {
|
|
43
43
|
already: boolean;
|
|
44
44
|
pid: number;
|
|
45
45
|
};
|
package/dist/web-daemon.js
CHANGED
|
@@ -109,11 +109,13 @@ export function stopWebDaemon(port = DEFAULT_WEB_PORT) {
|
|
|
109
109
|
return killed;
|
|
110
110
|
}
|
|
111
111
|
/** Spawn the daemon (no window, detached). Returns the pid. Records the
|
|
112
|
-
* spawning CLI's version so a later upgrade can detect the stale snapshot.
|
|
113
|
-
|
|
112
|
+
* spawning CLI's version so a later upgrade can detect the stale snapshot.
|
|
113
|
+
* extraArgs carries remote-control flags (--exposure/--token) through to the
|
|
114
|
+
* child's `web` invocation. */
|
|
115
|
+
function spawnWebDaemon(port, entry = process.argv[1], extraArgs = []) {
|
|
114
116
|
const home = homeDir();
|
|
115
117
|
const log = openSync(join(home, 'web.log'), 'a');
|
|
116
|
-
const child = spawn(process.execPath, [entry, 'web', `--port=${port}
|
|
118
|
+
const child = spawn(process.execPath, [entry, 'web', `--port=${port}`, ...extraArgs], {
|
|
117
119
|
detached: true,
|
|
118
120
|
stdio: ['ignore', log, log],
|
|
119
121
|
windowsHide: true,
|
|
@@ -201,9 +203,9 @@ export async function webDaemonStale(port = DEFAULT_WEB_PORT) {
|
|
|
201
203
|
const d = served.version || daemonVersion();
|
|
202
204
|
return { stale: d !== '' && c !== '' && d !== c, daemon: d, cli: c };
|
|
203
205
|
}
|
|
204
|
-
export function startWebDaemon(port = DEFAULT_WEB_PORT, entry = process.argv[1]) {
|
|
206
|
+
export function startWebDaemon(port = DEFAULT_WEB_PORT, entry = process.argv[1], extraArgs = []) {
|
|
205
207
|
const pid = readWebPid();
|
|
206
208
|
if (pid && alive(pid))
|
|
207
209
|
return { already: true, pid };
|
|
208
|
-
return { already: false, pid: spawnWebDaemon(port, entry) };
|
|
210
|
+
return { already: false, pid: spawnWebDaemon(port, entry, extraArgs) };
|
|
209
211
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.15",
|
|
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",
|
|
@@ -43,14 +43,15 @@
|
|
|
43
43
|
"build": "tsc -p tsconfig.build.json"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@hmharness/
|
|
47
|
-
"@hmharness/
|
|
48
|
-
"@hmharness/
|
|
49
|
-
"@hmharness/
|
|
50
|
-
"@hmharness/
|
|
51
|
-
"@hmharness/
|
|
52
|
-
"@hmharness/
|
|
53
|
-
"@hmharness/
|
|
54
|
-
"@hmharness/
|
|
46
|
+
"@hmharness/agent": "0.18.15",
|
|
47
|
+
"@hmharness/domain-harmony": "0.18.15",
|
|
48
|
+
"@hmharness/domain-ops": "0.18.15",
|
|
49
|
+
"@hmharness/evaluation": "0.18.15",
|
|
50
|
+
"@hmharness/evolution": "0.18.15",
|
|
51
|
+
"@hmharness/kernel": "0.18.15",
|
|
52
|
+
"@hmharness/observability": "0.18.15",
|
|
53
|
+
"@hmharness/sandbox": "0.18.15",
|
|
54
|
+
"@hmharness/web": "0.18.15",
|
|
55
|
+
"qrcode": "^1.5.4"
|
|
55
56
|
}
|
|
56
57
|
}
|