@hmharness/cli 0.18.12 → 0.18.14

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 CHANGED
@@ -912,6 +912,47 @@ 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) {
933
+ stdout.write(RED('lan/wan exposure requires a token. Run: hmh web start --exposure=' + exposure + ' --token-gen\n'));
934
+ stdout.write(DIM('(generates a random token, saves it to config.json web.token, and prints it once)\n'));
935
+ return;
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' && webToken) {
942
+ // print the ready-to-open URL once, so the user never has to assemble it
943
+ const osMod = await import('node:os');
944
+ const nets = osMod.networkInterfaces();
945
+ let lanIp = '';
946
+ for (const list of Object.values(nets)) {
947
+ for (const n of list ?? []) {
948
+ if (n.family === 'IPv4' && !n.internal) {
949
+ lanIp = lanIp || n.address;
950
+ }
951
+ }
952
+ }
953
+ const visUrl = (exposure === 'lan' && lanIp ? `http://${lanIp}` : 'http://<your-public-address>') + `:${port}/?key=${webToken}`;
954
+ stdout.write(YELLOW(`远程访问:${visUrl}\n`));
955
+ }
915
956
  const t = await uiStrings();
916
957
  const sub = rest.find((a) => !a.startsWith('-'));
917
958
  if (sub === 'stop') {
@@ -935,7 +976,16 @@ flags:
935
976
  return;
936
977
  }
937
978
  if (sub === 'start') {
938
- const r = startWebDaemon(Number.isFinite(port) ? port : 7788);
979
+ // forward remote-control flags to the daemon child so the exposure
980
+ // survives the respawn cycle (the child re-reads config.json too)
981
+ const passThrough = [];
982
+ const ex = rest.find((a) => a.startsWith('--exposure='));
983
+ if (ex)
984
+ passThrough.push(ex);
985
+ const tk = rest.find((a) => a.startsWith('--token='));
986
+ if (tk)
987
+ passThrough.push(tk);
988
+ const r = startWebDaemon(Number.isFinite(port) ? port : 7788, undefined, passThrough);
939
989
  // 2026-09-23: evolution runs silently alongside the web daemon - the
940
990
  // user never triggers `hmh evolve` manually (zero-config direction fix)
941
991
  try {
@@ -952,11 +1002,16 @@ flags:
952
1002
  }
953
1003
  return;
954
1004
  }
955
- // default: foreground server (handy for debugging)
1005
+ // default: foreground server (handy for debugging); foreground trusts the
1006
+ // config-file exposure (flags were persisted above when explicitly given)
956
1007
  const { startServer } = await import('@hmharness/web');
957
1008
  const { createRequire: cr } = await import('node:module');
958
1009
  const ver = cr(import.meta.url)('../package.json').version ?? '';
959
- await startServer({ port: Number.isFinite(port) ? port : 7788, host: '127.0.0.1', version: ver });
1010
+ await startServer({
1011
+ port: Number.isFinite(port) ? port : 7788,
1012
+ host: exposure === 'loopback' ? '127.0.0.1' : '0.0.0.0',
1013
+ version: ver,
1014
+ });
960
1015
  return; // startServer keeps the process alive
961
1016
  }
962
1017
  if (cmd === 'pipeline') {
@@ -1186,16 +1241,22 @@ flags:
1186
1241
  catch (err) {
1187
1242
  const msg = String(err);
1188
1243
  // live finding 2026-09-26: some accounts pass model validation for
1189
- // glm-4-flash/glm-4.5-air but the job-creation path 500s server-side -
1190
- // the entitlement is half-open (glm-5.3 answers the clean
1191
- // "联系客服开放" variant). The uploaded files stay valid, so record
1192
- // them: a retry after the entitlement opens must NOT re-upload 2.7M tokens.
1244
+ // glm-4-flash/glm-4.5-air but the job-creation path 500s server-side.
1245
+ // 2026-09-27 verdict: this persists after topping up - the API job
1246
+ // channel is effectively unusable; the web console is the only working
1247
+ // path (and console datasets do NOT see API-uploaded files - two
1248
+ // separate systems). The uploaded files stay valid, so record
1249
+ // them: a retry if the API channel ever opens must NOT re-upload.
1193
1250
  await CF.recordFineTuneJob(home, { id: 'staged-' + stamp, status: 'staged', model }, { trainFile: upTrain.id, evalFile: upEval?.id, pairs: rows.length, error: msg.slice(0, 200) });
1194
1251
  stdout.write(RED('任务创建失败:' + msg.slice(0, 160) + '\n'));
1195
1252
  if (/参数校验解析异常/.test(msg)) {
1196
- stdout.write(YELLOW('最常见原因(2026-09-27 实测确认):微调走开放平台按量付费通道,与 GLM Coding Plan 编码套餐互不通用——') + '\n');
1197
- stdout.write(YELLOW('编码套餐余额再足,开放平台账户没有充值/余额为 0 时,建任务就会在计费环节报这个 500。') + '\n');
1198
- stdout.write(DIM('解决:到 bigmodel.cn 控制台「财务/账户中心」给开放平台账户充值(glm-4-flash LoRA 约 0.025 元/千 tokens,4000 对×3 轮约 200-250 元),再重跑本命令。已上传文件无需重传。') + '\n');
1253
+ // 2026-09-27 实测定案:充值后该 500 依旧——智谱 API 建任务通道对
1254
+ // 微调实际不可用,且 API 上传的文件与控制台数据集是两套互不相通
1255
+ // 的体系。控制台网页(console/data-mgt + modelft/finetuning/create)
1256
+ // 是已验证可行的唯一通道;DPO 全参单价 0.04 元/千 tokens。
1257
+ stdout.write(YELLOW('实测结论(2026-09-27):该 API 通道建任务持续 500,充值无法解决;') + '\n');
1258
+ stdout.write(YELLOW('控制台网页是唯一可行通道,且 API 上传的文件不会出现在控制台数据集列表里(两套体系)。') + '\n');
1259
+ stdout.write(DIM('解决:到 bigmodel.cn 控制台「数据管理/微调数据」上传 JSONL 创建数据集,再到「模型微调」创建任务(DPO 全参 0.04 元/千 tokens)。命令行侧数据已备好,可直接联系维护者代操作。') + '\n');
1199
1260
  }
1200
1261
  else {
1201
1262
  stdout.write(DIM('上传的文件保留在云端可复用:' + upTrain.id + '\n'));
package/dist/tui.js CHANGED
@@ -1885,7 +1885,10 @@ export async function tui(yes, noWeb = false, opts = {}) {
1885
1885
  rt.addText(DIM(`✎ external editor (${editor}) → draft loaded (${edited.length} chars)`), 'dim');
1886
1886
  }
1887
1887
  catch (err) {
1888
+ // Recovery First (docx TUI 专项): external-editor failure suggests the
1889
+ // fallback explicitly - the draft is intact, nothing was lost
1888
1890
  rt.addText(String(err), 'err');
1891
+ rt.addText(DIM('✎ 编辑器打开失败——草稿仍在输入框中未丢失。可直接在 TUI 里继续编辑,或检查 EDITOR 环境变量。 / editor failed; your draft is intact in the input box.'), 'dim');
1889
1892
  }
1890
1893
  });
1891
1894
  // B14: remapped keys from config.json tui.keymap (applied at startup)
@@ -2053,6 +2056,9 @@ export async function tui(yes, noWeb = false, opts = {}) {
2053
2056
  rt.setBusy(false);
2054
2057
  currentInject = null;
2055
2058
  rt.addText(String(err), 'err');
2059
+ // Recovery First (docx TUI 专项): every task failure names the next step
2060
+ // instead of leaving a bare stack - retry is one up-arrow away
2061
+ rt.addText(DIM('↑ 重新运行:按 ↑ 调回刚才的输入;持续失败可用 /model 换路由或 /status 查看状态。 / press ↑ to retry, /model to switch route.'), 'dim');
2056
2062
  }
2057
2063
  finally {
2058
2064
  currentAbort = null;
@@ -2343,7 +2349,23 @@ export async function tui(yes, noWeb = false, opts = {}) {
2343
2349
  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
2350
  return ` ${a.padEnd(14)} ${pretty}`;
2345
2351
  });
2346
- rt.addText('keymap (defaults in parens):\n' + rows.join('\n') + '\n\n/keymap <action>=<key> — e.g. /keymap inject=ctrl+j', 'dim');
2352
+ 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');
2353
+ return;
2354
+ }
2355
+ // docx TUI 专项: "/keymap 修改后必须能恢复默认" - reset restores every
2356
+ // binding to the factory default in one shot (config + live TUI)
2357
+ if (arg === 'reset' || arg === 'default') {
2358
+ try {
2359
+ const { patchConfig } = await import('@hmharness/kernel');
2360
+ const merged = { ...(cfg.tui ?? {}), keymap: { ...KEYMAP_DEFAULTS } };
2361
+ const fresh = await patchConfig({ tui: merged });
2362
+ cfg = fresh;
2363
+ rt.setKeymap({ ...KEYMAP_DEFAULTS });
2364
+ rt.addText(GREEN('✓') + ' keymap reset to defaults', 'plain');
2365
+ }
2366
+ catch (err) {
2367
+ rt.addText(String(err), 'err');
2368
+ }
2347
2369
  return;
2348
2370
  }
2349
2371
  const eq = arg.indexOf('=');
@@ -2624,8 +2646,21 @@ export async function tui(yes, noWeb = false, opts = {}) {
2624
2646
  return;
2625
2647
  }
2626
2648
  }
2649
+ // docx TUI 专项: "SIGINT/SIGTERM/异常退出必须 cleanup" - Ctrl+C in raw mode
2650
+ // never generates SIGINT (the byte is just read), but external kills and
2651
+ // terminal-level signals do; destroy() is idempotent so double-call is safe
2652
+ const sigCleanup = () => { try {
2653
+ rt.destroy();
2654
+ }
2655
+ catch { /* best effort */ } };
2656
+ process.once('SIGINT', sigCleanup);
2657
+ process.once('SIGTERM', sigCleanup);
2658
+ process.once('SIGHUP', sigCleanup);
2627
2659
  await rt.waitExit();
2628
2660
  rt.destroy();
2661
+ process.off('SIGINT', sigCleanup);
2662
+ process.off('SIGTERM', sigCleanup);
2663
+ process.off('SIGHUP', sigCleanup);
2629
2664
  for (const c of clients)
2630
2665
  c.close();
2631
2666
  stdout.write('\n');
@@ -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
  };
@@ -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
- function spawnWebDaemon(port, entry = process.argv[1]) {
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.12",
3
+ "version": "0.18.14",
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",